diff --git a/image_captcha/image_captcha-rtl.css b/image_captcha/image_captcha-rtl.css new file mode 100644 index 0000000..ff4c95c --- /dev/null +++ b/image_captcha/image_captcha-rtl.css @@ -0,0 +1,14 @@ +/* $Id$ */ + +/** + * Styling of the font selection list (with previews) + * on the Image CAPTCHA settings page. + */ + +/** + * Float the fonts with preview (with a fixed width) + * to create a multi-column layout. + */ +.image_captcha_admin_font_preview { + float: right; +} \ No newline at end of file diff --git a/image_captcha/image_captcha.admin.inc b/image_captcha/image_captcha.admin.inc index b972bb0..b45df8d 100644 --- a/image_captcha/image_captcha.admin.inc +++ b/image_captcha/image_captcha.admin.inc @@ -59,6 +59,16 @@ function image_captcha_settings_form() { '#default_value' => (int) variable_get('image_captcha_code_length', 5), '#description' => t('The code length influences the size of the image. Note that larger values make the image generation more CPU intensive.'), ); + // RTL support option (only show this option when there are RTL languages). + $languages = language_list('direction'); + if ($languages[1]) { + $form['image_captcha_code_settings']['image_captcha_rtl_support'] = array( + '#type' => 'checkbox', + '#title' => t('RTL support'), + '#default_value' => variable_get('image_captcha_rtl_support', 0), + '#description' => t('Enable this option to render the code from right to left for right to left languages.'), + ); + } // Font related stuff. $form['image_captcha_font_settings'] = _image_captcha_settings_form_font_section(); diff --git a/image_captcha/image_captcha.user.inc b/image_captcha/image_captcha.user.inc index e604443..a6a79b5 100644 --- a/image_captcha/image_captcha.user.inc +++ b/image_captcha/image_captcha.user.inc @@ -96,9 +96,12 @@ function _image_captcha_generate_image($code) { imagecolortransparent($image, $background_color); } imagefilledrectangle($image, 0, 0, $width, $height, $background_color); + // Do we need to draw in RTL mode? + global $language; + $rtl = $language->direction && ((bool) variable_get('image_captcha_rtl_support', 0)); // draw text - $result = _image_captcha_image_generator_print_string($image, $width, $height, $fonts, $font_size, $code); + $result = _image_captcha_image_generator_print_string($image, $width, $height, $fonts, $font_size, $code, $rtl); if (!$result) { return FALSE; } @@ -231,7 +234,7 @@ function _image_captcha_image_generator_add_dots(&$image, $width, $height, $colo /** * Helper function for drawing text on the image. */ -function _image_captcha_image_generator_print_string(&$image, $width, $height, $fonts, $font_size, $text) { +function _image_captcha_image_generator_print_string(&$image, $width, $height, $fonts, $font_size, $text, $rtl = FALSE) { // get characters $characters = _image_captcha_utf8_split($text); $character_quantity = count($characters); @@ -261,6 +264,9 @@ function _image_captcha_image_generator_print_string(&$image, $width, $height, $ foreach ($characters as $c => $character) { // initial position of character: in the center of its cage $center_x = ($c + 0.5) * $ccage_width; + if ($rtl) { + $center_x = $width - $center_x; + } $center_y = 0.5 * $height; // Pick a random font from the list.