Index: image_captcha/image_captcha.admin.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/captcha/image_captcha/image_captcha.admin.inc,v
retrieving revision 1.28
diff -u -b -u -p -r1.28 image_captcha.admin.inc
--- image_captcha/image_captcha.admin.inc	23 Sep 2009 21:23:00 -0000	1.28
+++ image_captcha/image_captcha.admin.inc	9 Dec 2009 00:23:54 -0000
@@ -87,12 +87,12 @@ function image_captcha_settings_form() {
     '#title' => t('Font settings'),
   );
   $available_fonts = _image_captcha_available_fonts();
-  list($default_font, $errno) = _image_captcha_get_font();
-  $form['image_captcha_font_settings']['image_captcha_font'] = array(
-    '#type' => 'select',
-    '#title' => t('Font'),
-    '#default_value' => $default_font,
-    '#description' => t('Select the font to use for the text in the image CAPTCHA. Apart from the provided defaults, you can also use your own TrueType fonts (filename extension .ttf) by putting them in the Drupal "files" directory (directory %filesdir), %fonts_library_general or %fonts_library_specific.',
+  list($default_fonts, $errno) = _image_captcha_get_fonts();
+  $form['image_captcha_font_settings']['image_captcha_fonts'] = array(
+    '#type' => 'checkboxes',
+    '#title' => t('Fonts'),
+    '#default_value' => $default_fonts,
+    '#description' => t('Select the fonts to use for the text in the image CAPTCHA. Apart from the provided defaults, you can also use your own TrueType fonts (filename extension .ttf) by putting them in the Drupal "files" directory (directory %filesdir), %fonts_library_general or %fonts_library_specific.',
       array('%filesdir' => file_directory_path(),
         '%fonts_library_general' => 'sites/all/libraries/fonts',
         '%fonts_library_specific' => conf_path() .'/libraries/fonts',
@@ -101,6 +101,7 @@ function image_captcha_settings_form() {
     '#options' => $available_fonts,
   );
 
+
   // add a prerender procedure for checking that a font should be set.
   $form['#pre_render'] = array('image_captcha_settings_form_pre_render');
   // font size
@@ -123,6 +124,7 @@ function image_captcha_settings_form() {
     );
   }
   // Disable some options when there is no TTF support
+  // TODO: change this for the multi select font scheme.
   if ($image_captcha_setup_errno & IMAGE_CAPTCHA_ERROR_NO_TTF_SUPPORT) {
     $form['image_captcha_font_settings']['image_captcha_font']['#disabled'] = TRUE;
     $form['image_captcha_font_settings']['image_captcha_font']['#default_value'] = 'BUILTIN';
@@ -248,8 +250,16 @@ function image_captcha_settings_form() {
     ),
     '#default_value' => (int) variable_get('image_captcha_noise_level', 5),
   );
+
+  // Add a validation handler.
   $form['#validate'] = array('image_captcha_settings_form_validate');
-  return system_settings_form($form);
+
+  // Make it a settings form.
+  $form = system_settings_form($form);
+  // But also do some custom submission handling.
+  $form['#submit'][] = 'image_captcha_settings_form_submit';
+
+  return $form;
 }
 
 /**
@@ -265,6 +275,7 @@ function image_captcha_settings_form_pre
       'warning'
     );
   }
+  // TODO: rework this for the multiple font scheme
   elseif ($form['image_captcha_font_settings']['image_captcha_font']['#default_value'] == 'BUILTIN') {
     drupal_set_message(t('The usage of the built-in bitmap font it is not recommended because of its small size and missing UTF-8 support.'), 'warning');
   }
@@ -279,19 +290,21 @@ function image_captcha_settings_form_val
   if (preg_match('/\s/', $form_state['values']['image_captcha_image_allowed_chars'])) {
     form_set_error('image_captcha_image_allowed_chars', t('The list of characters to use should not contain spaces.'));
   }
-  // Check font.
-  $font = $form_state['values']['image_captcha_font'];
-  if ($font == '0') {
-    form_set_error('image_captcha_font', t('You need to select a font'));
+  // Check the selected fonts.
+  // Filter the image_captcha fonts array to pick out the selected ones.
+  $fonts = array_filter($form_state['values']['image_captcha_fonts']);
+  if (count($fonts) < 1) {
+    form_set_error('image_captcha_fonts', t('You need to select at least one font.'));
   }
-  elseif ($font == 'BUILTIN') {
+  if ($form_state['values']['image_captcha_fonts']['BUILTIN']) {
     // With the built in font, only latin2 characters should be used.
     if (preg_match('/[^a-zA-Z0-9]/', $form_state['values']['image_captcha_image_allowed_chars'])) {
       form_set_error('image_captcha_image_allowed_chars', t('The built-in font only supports Latin2 characters. Only use "a" to "z" and numbers.'));
     }
   }
-  elseif ($font != 'BUILTIN' && (!is_file($font) || !is_readable($font))) {
-    form_set_error('image_captcha_font', t('Font does not exist or is not readable.'));
+  list($readable_fonts, $problem_fonts) = _image_captcha_check_fonts($fonts);
+  if (count($problem_fonts) > 0) {
+    form_set_error('image_captcha_fonts', t('The following fonts are not readable: %fonts.', array('%fonts' => implode(', ', $problem_fonts))));
   }
 
   // check color settings
@@ -302,3 +315,12 @@ function image_captcha_settings_form_val
     form_set_error('image_captcha_foreground_color', t('Text color is not a valid hexadecimal color value.'));
   }
 }
+
+/**
+ * Submit function for image_captcha configuration form.
+ */
+function image_captcha_settings_form_submit($form, &$form_state) {
+  // Filter the image_captcha fonts array to pick out the selected ones.
+  $fonts = array_filter($form_state['values']['image_captcha_fonts']);
+  variable_set('image_captcha_fonts', $fonts);
+}
Index: image_captcha/image_captcha.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/captcha/image_captcha/image_captcha.module,v
retrieving revision 1.32
diff -u -b -u -p -r1.32 image_captcha.module
--- image_captcha/image_captcha.module	8 Dec 2009 22:25:19 -0000	1.32
+++ image_captcha/image_captcha.module	9 Dec 2009 00:23:54 -0000
@@ -59,13 +59,51 @@ function image_captcha_menu() {
  * Helper function for getting the font setting.
  * @return array($font, $errno)
  */
-function _image_captcha_get_font() {
-  $font = variable_get('image_captcha_font', drupal_get_path('module', 'image_captcha') .'/fonts/Tesox/tesox.ttf');
-  $errno = 0;
+//function _image_captcha_get_font() {
+//  $font = variable_get('image_captcha_font', drupal_get_path('module', 'image_captcha') .'/fonts/Tesox/tesox.ttf');
+//  $errno = 0;
+//  if ($font != 'BUILTIN' && (!is_file($font) || !is_readable($font))) {
+//    $errno = IMAGE_CAPTCHA_ERROR_TTF_FILE_READ_PROBLEM;
+//  }
+//  return array($font, $errno);
+//}
+
+/**
+ * Helper function for getting the fonts to use in the image CAPTCHA.
+ *
+ * TODO: this still feels unelegant. remove errno?
+ * add an option to return all fonts/only readable fonts?
+ *
+ * @return array($fonts, $errno) with $fonts a list of font paths
+ *   and $errno will be non zero if there is a problem with one of the fonts.
+ */
+function _image_captcha_get_fonts() {
+  # Get the image_captcha_fonts variable.
+  $fonts = variable_get('image_captcha_fonts', array(drupal_get_path('module', 'image_captcha') .'/fonts/Tesox/tesox.ttf'));
+  # Check the fonts.
+  list($readable_fonts, $problem_fonts) = _image_captcha_check_fonts($fonts);
+  $errno = (count($problem_fonts) == 0) ? 0 : IMAGE_CAPTCHA_ERROR_TTF_FILE_READ_PROBLEM;
+  return array($fonts, $errno);
+}
+
+/**
+ * Helper function for checking if the specified fonts are available.
+ *
+ * @param $fonts paths of fonts to check.
+ * @return list($readable_fonts, $problem_fonts)
+ */
+function _image_captcha_check_fonts($fonts) {
+  $readable_fonts = array();
+  $problem_fonts = array();
+  foreach ($fonts as $font) {
   if ($font != 'BUILTIN' && (!is_file($font) || !is_readable($font))) {
-    $errno = IMAGE_CAPTCHA_ERROR_TTF_FILE_READ_PROBLEM;
+      $problem_fonts[] = $font;
+    }
+    else {
+      $readable_fonts[] = $font;
+    }
   }
-  return array($font, $errno);
+  return array($readable_fonts, $problem_fonts);
 }
 
 /**
@@ -117,7 +155,7 @@ function _image_captcha_check_setup() {
     return IMAGE_CAPTCHA_ERROR_NO_TTF_SUPPORT;
   }
   // Check font settings.
-  list($font, $errno) = _image_captcha_get_font();
+  list($font, $errno) = _image_captcha_get_fonts();
   if ($errno && IMAGE_CAPTCHA_ERROR_TTF_FILE_READ_PROBLEM) {
     return IMAGE_CAPTCHA_ERROR_TTF_FILE_READ_PROBLEM;
   }
Index: image_captcha/image_captcha.user.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/captcha/image_captcha/image_captcha.user.inc,v
retrieving revision 1.21
diff -u -b -u -p -r1.21 image_captcha.user.inc
--- image_captcha/image_captcha.user.inc	22 Sep 2009 22:51:00 -0000	1.21
+++ image_captcha/image_captcha.user.inc	9 Dec 2009 00:23:54 -0000
@@ -68,9 +68,10 @@ function _image_captcha_hex_to_rgb($hex)
  */
 function _image_captcha_generate_image($code) {
   // Get font.
-  list($font, $errno) = _image_captcha_get_font();
+  list($fonts, $errno) = _image_captcha_get_fonts();
+
   if ($errno != 0) {
-    watchdog('CAPTCHA', 'Could not find or read the configured font ("%font") for the image CAPTCHA.', array('%font' => $font), WATCHDOG_ERROR);
+    watchdog('CAPTCHA', 'Could not find or read the configured font  for the image CAPTCHA.', array('%font' => $font), WATCHDOG_ERROR);
     exit();
   }
   // get other settings
@@ -98,7 +99,7 @@ function _image_captcha_generate_image($
   imagefilledrectangle($image, 0, 0, $width, $height, $background_color);
 
   // draw text
-  $result = _image_captcha_image_generator_print_string($image, $width, $height, $font, $font_size, $code);
+  $result = _image_captcha_image_generator_print_string($image, $width, $height, $fonts, $font_size, $code);
   if (!$result) {
     return FALSE;
   }
@@ -231,18 +232,11 @@ function _image_captcha_image_generator_
 /**
  * Helper function for drawing text on the image.
  */
-function _image_captcha_image_generator_print_string(&$image, $width, $height, $font, $font_size, $text) {
+function _image_captcha_image_generator_print_string(&$image, $width, $height, $fonts, $font_size, $text) {
   // get characters
   $characters = _image_captcha_utf8_split($text);
   $character_quantity = count($characters);
 
-  // get character width for builtin font
-  if ($font == 'BUILTIN') {
-    $character_width = imagefontwidth(5);
-    $character_height = imagefontheight(5);
-    $bbox = array(0, $character_height, $character_width, $character_height, $character_width, 0, 0, 0);
-  }
-
   // get colors
   $background_rgb = _image_captcha_hex_to_rgb(variable_get('image_captcha_background_color', '#ffffff'));
   $foreground_rgb = _image_captcha_hex_to_rgb(variable_get('image_captcha_foreground_color', '#000000'));
@@ -270,10 +264,20 @@ function _image_captcha_image_generator_
     $center_x = ($c + 0.5) * $ccage_width;
     $center_y = 0.5 * $height;
 
+
+    // Pick a random font from the list.
+    $font = array_rand($fonts);
+
+
     // get character dimensions for ttf fonts
     if ($font != 'BUILTIN') {
       $bbox = imagettfbbox($font_size, 0, realpath($font), $character);
     }
+    else {
+      $character_width = imagefontwidth(5);
+      $character_height = imagefontheight(5);
+      $bbox = array(0, $character_height, $character_width, $character_height, $character_width, 0, 0, 0);
+    }
 
     // determine print position: at what coordinate should the character be
     // printed so that the bounding box would be nicely centered in the cage?
