Index: /other-projects/trunk/image-generation/annotate.pl
===================================================================
--- /other-projects/trunk/image-generation/annotate.pl	(revision 14155)
+++ /other-projects/trunk/image-generation/annotate.pl	(revision 14155)
@@ -0,0 +1,215 @@
+#!/usr/bin/perl
+
+
+BEGIN {
+    die "GSDLHOME not set\n" unless defined $ENV{'GSDLHOME'};
+    unshift (@INC, "$ENV{'GSDLHOME'}/perllib");
+}
+
+
+use Image::Magick;
+use parsargv;
+
+
+sub main
+{
+    # Parse command line arguments
+    if (!parsargv::parse(\@ARGV,
+			 'background_image/.*/xc:white', \$background_image,
+			 'image_width/^\d+$/', \$image_width,
+			 'image_height/^\d+$/', \$image_height,
+			 'stretchable_width', \$stretchable_width,
+			 'stretchable_height', \$stretchable_height,
+			 'note_if_stretched', \$note_if_stretched,
+			 'no_text_height_warnings', \$no_text_height_warnings,
+			 'h_align/.*/center', \$h_align,
+			 'v_align/.*/bottom', \$v_align,
+			 'padding_left/^\d+$/1', \$padding_left,
+			 'padding_right/^\d+$/1', \$padding_right,
+			 'padding_top/^(\\\-)?\d+$/0', \$padding_top,
+			 'padding_bottom/^(\\\-)?\d+$/0', \$padding_bottom,
+			 'baseline_offset/^(\\\-)?\d+$/0', \$baseline_offset,
+			 'font/.*/', \$font,
+			 'font_size/^\d+$/10', \$font_size,
+			 'text/.*/', \$text,
+			 'text_colour/.*/black', \$text_colour,
+			 'output_file/.*/', \$output_file,
+			 'verbose', \$verbose)) {
+	print STDERR "Error: Bad command line arguments...\n";
+	die "\n";
+    }
+
+
+    # Create a new image, basing it on the background image
+    my $image = Image::Magick->new(font => $font, pointsize => $font_size);
+    $res = $image->Read($background_image);
+    die "$res" if $res;
+
+    # Check required parameter values are set
+    if (!$image_width) {
+	$image_width = $image->Get('width');
+    }
+    if (!$image_height) {
+	$image_height = $image->Get('height');
+    }
+    if ($h_align ne "left" && $h_align ne "center" && $h_align ne "right") {
+	die "Error: Bad h_align $h_align...\n";
+    }
+    if ($v_align ne "top" && $v_align ne "center" && $v_align ne "bottom") {
+	die "Error: Bad v_align $v_align...\n";
+    }
+
+    # Negative padding values (only top and bottom make sense) must be parsed specially
+    if ($padding_top =~ /^\\\-(\d+)$/) {
+	$padding_top = -$1;
+    }
+    if ($padding_bottom =~ /^\\\-(\d+)$/) {
+	$padding_bottom = -$1;
+    }
+
+    # The baseline offset may be negative also...
+    if ($baseline_offset =~ /^\\\-(\d+)$/) {
+	$baseline_offset = -$1;
+    }
+
+    if (!$font) {
+	die "Error: Font not specified...\n";
+    }
+    if (!$text) {
+	die "Error: Text not specified...\n";
+    }
+    if (!$output_file) {
+	die "Error: Output file not specified...\n";
+    }
+
+    $output_file =~ /\/([^\/]+)$/;
+    my $output_file_name = $1;
+
+    # Calculate the usable image area
+    my $usable_image_width = $image_width - $padding_left - $padding_right;
+    my $usable_image_height = $image_height - $padding_top - $padding_bottom;
+
+    if ($verbose) {
+	print STDERR "\nGenerating: $output_file\n";
+	print STDERR "Pasting \"$text\" ($text_colour) in font $font ($font_size pt) onto $background_image\n";
+	print STDERR "Basic size of $image_width x $image_height minus padding (LRTB: $padding_left $padding_right $padding_top $padding_bottom) gives usable area $usable_image_width x $usable_image_height\n";
+    }
+
+    # Resize the image to the desired size (it may be increased later)
+    $res = $image->Resize(width => $image_width, height => $image_height);
+    die "$res" if $res;
+
+    # Convert the (escaped) text string into a Unicode string
+    my $text_unicode = $text;
+    $text_unicode =~ s/\\(0x([0-9A-F]){4})/chr(oct($1))/ieg;
+
+    # Determine the space required to display the text
+    my $text_width = 0;
+    my $text_height = 0;
+    foreach $line (split(/\\n/, $text_unicode)) {
+	($x_ppem, $y_ppem, $ascender, $descender, $line_width, $line_height, $max_advance) =
+	    $image->QueryFontMetrics(text => $line);
+	$line_height = $line_height - $baseline_offset;
+
+	# Use the longest line as the text width
+	if ($line_width > $text_width) {
+	    $text_width = $line_width;
+	}
+	$text_height += $line_height;
+    }
+    print STDERR "Text size is $text_width x $text_height\n" if $verbose;
+
+    # If necessary, expand the image horizontally to fit the text...
+    if ($text_width > $usable_image_width) {
+	# ...provided that 'stretchable_width' has been specified
+	if ($stretchable_width) {
+	    $usable_image_width = $text_width;
+	    $image_width = $usable_image_width + $padding_left + $padding_right;
+	    $res = $image->Resize(width => $image_width);
+	    die "$res" if $res;
+
+	    if ($note_if_stretched) {
+		print STDERR "NOTE: Image width of $output_file_name was stretched to $image_width...\n";
+	    }
+	}
+	else {
+	    print STDERR "WARNING: Text width ($text_width) is greater than usable image width ($usable_image_width) for $output_file_name...\n";
+	}
+    }
+
+    # If necessary, expand the image vertically to fit the text...
+    if ($text_height > $usable_image_height) {
+	# ...provided that 'stretchable_height' has been specified
+	if ($stretchable_height) {
+	    $usable_image_height = $text_height;
+	    $image_height = $usable_image_height + $padding_top + $padding_bottom;
+	    $res = $image->Resize(height => $image_height);
+	    die "$res" if $res;
+
+	    if ($note_if_stretched) {
+		print STDERR "NOTE: Image height of $output_file_name was stretched to $image_height...\n";
+	    }
+	}
+	else {
+	    print STDERR "WARNING: Text height ($text_height) is greater than usable image height ($usable_image_height) for $output_file_name...\n" unless $no_text_height_warnings;
+	}
+    }
+
+    # Determine where the text should be placed in the y dimension, based on v_align
+    if ($v_align eq "top") {
+	$ypos = $font_size - 1;
+    }
+    elsif ($v_align eq "center") {
+	$ypos = (($usable_image_height - $text_height) / 2) + $font_size - 1;
+    }
+    elsif ($v_align eq "bottom") {
+	$ypos = $usable_image_height - $text_height + $font_size - 1;
+    }
+    $ypos = $ypos + $padding_top;
+
+    # Draw each line of the text onto the image
+    foreach $line (split(/\\n/, $text_unicode)) {
+	($x_ppem, $y_ppem, $ascender, $descender, $line_width, $line_height, $max_advance) =
+	    $image->QueryFontMetrics(text => $line);
+	$line_height = $line_height - $baseline_offset;
+
+	# Determine where the text should be placed in the x dimension, based on h_align
+	if ($h_align eq "left") {
+	    $xpos = 0;
+	}
+	elsif ($h_align eq "center") {
+	    $xpos = ($usable_image_width - $line_width) / 2;
+	}
+	elsif ($h_align eq "right") {
+	    $xpos = $usable_image_width - $line_width;
+	}
+	$xpos = $xpos + $padding_left;
+
+	if ($xpos < 0) {
+	    $xpos = 0;
+	}
+
+	# print STDERR "Line coordinates: ($xpos, $ypos)\n";
+
+	# Why, why, oh why it is necessary to do this under Windows?
+	# if ($ENV{'GSDLOS'} =~ /windows/i) {
+	# $res = $image->Annotate(text => $line, encoding => 'UTF-8', fill => $text_colour,
+	# 			x => -$xpos, y => -$ypos, undercolor => 'white');
+	# die "$res" if $res;
+	# }
+
+	# Draw the line text onto the image
+	$res = $image->Annotate(text => $line, encoding => 'UTF-8', fill => $text_colour,
+				x => $xpos, y => $ypos);
+	die "$res" if $res;
+
+	$ypos = $ypos + $line_height;
+    }
+
+    # Save the image to file
+    $res = $image->Write($output_file);
+    die "$res" if $res;
+}
+
+
+&main();
Index: /other-projects/trunk/image-generation/cgi-bin/make-classifier-images.cgi
===================================================================
--- /other-projects/trunk/image-generation/cgi-bin/make-classifier-images.cgi	(revision 14155)
+++ /other-projects/trunk/image-generation/cgi-bin/make-classifier-images.cgi	(revision 14155)
@@ -0,0 +1,134 @@
+#!/usr/bin/perl -w
+
+use CGI qw(:standard);
+
+my $image_generation_code_directory = "/research/mdewsnip/greenstone/image-generation";
+my $images_directory = "/home/mdewsnip/public_html/greenstone/temp-images";
+my $images_directory_url = "http://www.cs.waikato.ac.nz/~mdewsnip/greenstone/temp-images";
+
+print "Content-Type: text/html; charset=utf-8\n\n";
+print start_html("Greenstone classifier image generation");
+print "<h2>Greenstone classifier image generation</h2>";
+print hr();
+
+# Language code and macrofile name
+my $language = param("l") || "en.english";
+
+# Macro name (ASCII characters only)
+my $macro_name = param("macro");
+$macro_name =~ tr/a-zA-Z0-9//cd;
+
+# Image filename (ASCII characters only)
+my $image_name = param("image");
+$image_name =~ tr/a-zA-Z0-9//cd;
+
+my $text_unicode = param("text");
+if (defined $macro_name && $macro_name ne "" && defined $image_name && $image_name ne "" && defined $text_unicode && $text_unicode ne "") {
+    my $language_code = (split(/\./, $language))[0];
+    my $macrofile_name = (split(/\./, $language))[1];
+
+    my $language_modifier = "";
+    my $language_modifier_one = "";
+    my $image_directory = "";
+    my $translate_this = "";
+    unless ($language_code eq "en") {
+	$language_modifier = "[l=$language_code]";
+	$language_modifier_one = "l=$language_code,";
+	$image_directory = "$language_code/";
+	$translate_this = "# <b>Translate this!</b>";
+    }
+
+    # Write a temporary macrofile containing the text for the images
+    $text_unicode_raw = $text_unicode;  # May contain "\n" to split the green_title text
+    $text_unicode =~ s/\\n/ /g;  # Replace any "\n" with " " for standard use
+    open(MACROFILE, ">$image_generation_code_directory/web-images.dm") || (print "Error: Could not open web-images.dm for writing.", end_html() && die);
+    print MACROFILE "\#\# \"" . $text_unicode . "\" \#\# nav_bar_button \#\# t$image_name \#\#\n\n";
+    print MACROFILE "\#\# \"" . $text_unicode_raw . "\" \#\# green_title \#\# h_$image_name \#\#\n\n";
+    close(MACROFILE);
+
+    # Use ImageMagick via image generation scripts to make the images
+    `cd ..; source setup.bash; cd $image_generation_code_directory; make-images.pl -language_symbol $language_code -image_dir $images_directory web-images.dm; rm web-images.*`;
+
+    # Get width of nav_bar_buttons
+    my $nav_bar_button_width = 87;
+    my $nav_bar_button_identification = `identify $images_directory/t${image_name}on.gif 2>&1`;
+    if ($nav_bar_button_identification =~ /t${image_name}on.gif \w+ (\d+)x(\d+)/) {
+	$nav_bar_button_width = $1;
+    }
+
+    # Get width of green_titles
+    my $green_title_width = 200;
+    my $green_title_identification = `identify $images_directory/h_$image_name.gif 2>&1`;
+    if ($green_title_identification =~ /h_$image_name.gif \w+ (\d+)x(\d+)/) {
+	$green_title_width = $1;
+    }
+
+    # Output result HTML
+    print "<p>Greenstone classifier images with text \"" . $text_unicode_raw . "\":";
+    print "<p><a href=\"$images_directory_url/t${image_name}on.gif\"><img src=\"$images_directory_url/t${image_name}on.gif\" border=\"0\" width=\"$nav_bar_button_width\" height=\"17\"></a>";
+    print "<p><a href=\"$images_directory_url/t${image_name}of.gif\"><img src=\"$images_directory_url/t${image_name}of.gif\" border=\"0\" width=\"$nav_bar_button_width\" height=\"17\"></a>";
+    print "<p><a href=\"$images_directory_url/t${image_name}gr.gif\"><img src=\"$images_directory_url/t${image_name}gr.gif\" border=\"0\" width=\"$nav_bar_button_width\" height=\"17\"></a>";
+    print "<p><a href=\"$images_directory_url/h_$image_name.gif\" style=\"color: #000000\"><img src=\"$images_directory_url/h_$image_name.gif\" border=\"1\" width=\"$green_title_width\" height=\"57\"></a>";
+    print "<p>\n";
+    print "These images should be put in the images/$image_directory folder of your Greenstone installation.\n";
+    print "<p>\n";
+    print "To get Greenstone to use the new images, some macros must be defined. Copy all the following text and paste it into the extra.dm file in Greenstone's \"macros\" directory:\n";
+    print "<p>\n";
+    print "<tt>\n";
+
+    # base.dm macros
+    print "# <i>The following macros usually live in base.dm</i>\n";
+    print "<br>package Global\n";
+    print "<br>\n";
+    print "<br>_" . $macro_name . "width_ $language_modifier {_widtht" . $image_name . "x_ }\n";
+    print "<br>_image" . $macro_name . "_ $language_modifier {_gsimage_(_httpbrowse" . $macro_name . "_,_httpicont" . $image_name . "of_,_httpicont" . $image_name . "on_,$text_unicode,_textimage" . $macro_name . "_)}\n";
+    print "<br>_icontab" . $macro_name . "green_ $language_modifier {&lt;img src=\"_httpicont" . $image_name . "gr_\" width=_widtht" . $image_name . "x_ border=0&gt;}\n";
+    print "<br>_icontab" . $macro_name . "green_ [$language_modifier_one" . "v=1] {_texticontab" . $macro_name . "green_ }\n";
+    print "<p>\n";
+
+    # document.dm macros
+    print "# <i>The following macros usually live in document.dm</i>\n";
+    print "<br>package document\n";
+    print "<br>\n";
+    print "<br>_text" . $macro_name . "page_ $language_modifier {_texticonh" . $image_name . "_}\n";
+    print "<br>_icon" . $macro_name . "page_ $language_modifier {&lt;img src=\"_httpiconh" . $image_name . "_\" width=\"_widthh" . $image_name . "_\" height=\"_heighth" . $image_name . "_\"&gt;}\n";
+    print "<br>_icon" . $macro_name . "page_ [$language_modifier_one" . "v=1] {&lt;h2&gt;_texticonh" . $image_name . "_&lt;/h2&gt;}\n";
+    print "<p>\n";
+
+    # <language>.dm macros
+    print "# <i>The following macros usually live in $macrofile_name.dm</i>\n";
+    print "<br>package Global\n";
+    print "<br>\n";
+    print "<br>_textimage" . $macro_name . "_ $language_modifier {Browse by " . $text_unicode . "} $translate_this\n";
+    print "<br>_texticontab" . $macro_name . "green_ $language_modifier {\u$text_unicode}\n";
+    print "<br>\n";
+    print "<br>## \"$text_unicode\" ## nav_bar_button ## t" . $image_name . " ##\n";
+    print "<br>_httpicont" . $image_name . "gr_ $language_modifier {_httpimg_/$image_directory" . "t" . $image_name . "gr.gif}\n";
+    print "<br>_httpicont" . $image_name . "of_ $language_modifier {_httpimg_/$image_directory" . "t" . $image_name . "of.gif}\n";
+    print "<br>_httpicont" . $image_name . "on_ $language_modifier {_httpimg_/$image_directory" . "t" . $image_name . "on.gif}\n";
+    print "<br>_widtht" . $image_name . "x_ $language_modifier {$nav_bar_button_width}\n";
+
+    print "<br>\n";
+    print "<br>package document\n";
+    print "<br>\n";
+    print "<br>_texticonh" . $image_name . "_ $language_modifier {\u$text_unicode}\n";
+    print "<br>\n";
+    print "<br>## \"$text_unicode\" ## green_title ## h_" . $image_name . " ##\n";
+    print "<br>_httpiconh" . $image_name . "_ $language_modifier {_httpimg_/$image_directory" . "h_" . $image_name . ".gif}\n";
+    print "<br>_widthh" . $image_name . "_ $language_modifier {$green_title_width}\n";
+    print "<br>_heighth" . $image_name . "_ $language_modifier {57}\n";
+
+    print "<br>\n";
+    print "<br>package help\n";
+    print "<br>\n";
+    print "<br>_text" . $macro_name . "short_ $language_modifier {access publications by $text_unicode} $translate_this\n";
+    print "<br>_text" . $macro_name . "long_ $language_modifier {&lt;p&gt;You can &lt;i&gt;access publications by $text_unicode&lt;/i&gt; by pressing the &lt;i&gt;" . $text_unicode . "&lt;/i&gt; button. This brings up a list of " . $text_unicode . ". } $translate_this\n";
+    print "<br>\n";
+
+    print "</tt>\n";
+}
+else {
+    print "<p>Error: parameter not defined.";
+}
+
+print end_html();
Index: /other-projects/trunk/image-generation/cgi-bin/make-collection-images.cgi
===================================================================
--- /other-projects/trunk/image-generation/cgi-bin/make-collection-images.cgi	(revision 14155)
+++ /other-projects/trunk/image-generation/cgi-bin/make-collection-images.cgi	(revision 14155)
@@ -0,0 +1,59 @@
+#!/usr/bin/perl -w
+
+use CGI qw(:standard);
+
+my $image_generation_code_directory = "/research/mdewsnip/greenstone/image-generation";
+my $images_directory = "/home/mdewsnip/public_html/greenstone/temp-images";
+my $images_directory_url = "http://www.cs.waikato.ac.nz/~mdewsnip/greenstone/temp-images";
+
+print "Content-Type: text/html; charset=utf-8\n\n";
+print start_html("Greenstone collection image generation");
+print "<h2>Greenstone collection image generation</h2>";
+print hr();
+
+# Language code and macrofile name
+my $language = param("l") || "en.english";
+
+# Collection name (ASCII characters only)
+my $collection_name = param("collection");
+$collection_name =~ tr/a-zA-Z0-9//cd;
+
+my $text_unicode = param("text");
+if (defined $text_unicode && $text_unicode ne "") {
+    my $language_code = (split(/\./, $language))[0];
+
+    my $language_modifier = "";
+    my $image_directory = "";
+    unless ($language_code eq "en") {
+	$language_modifier = "[l=$language_code]";
+	$image_directory = "$language_code/";
+    }
+
+    # Write a temporary macrofile containing the text for the images
+    $text_unicode_raw = $text_unicode;  # May contain "\n" to split the green_title text
+    open(MACROFILE, ">$image_generation_code_directory/web-images.dm") || (print "Error: Could not open web-images.dm for writing.", end_html() && die);
+    print MACROFILE "\#\# \"" . $text_unicode_raw . "\" \#\# collection_icon \#\# $collection_name \#\#\n\n";
+    close(MACROFILE);
+
+    `cd ..; source setup.bash; cd $image_generation_code_directory; make-images.pl -language_symbol $language_code -image_dir $images_directory web-images.dm; rm web-images.*`;
+
+    print "<p>Greenstone collection images with text \"" . $text_unicode_raw . "\":";
+    print "<p><a href=\"$images_directory_url/${collection_name}_sm.gif\" style=\"color: #000000\"><img src=\"$images_directory_url/${collection_name}_sm.gif\" width=\"150\" height=\"44\" border=\"1\"></a>";
+    print "<p><a href=\"$images_directory_url/$collection_name.gif\" style=\"color: #000000\"><img src=\"$images_directory_url/$collection_name.gif\" width=\"225\" height=\"66\" border=\"1\"></a>";
+    print "<p>\n";
+    print "These images should be put in the collect/$collection_name/images/$image_directory folder of your Greenstone installation.\n";
+    print "<p>\n";
+    print "To get Greenstone to use the new images, you need to specify them in your collection configuration. If you're using the GLI, open your collection, switch to the Design -> General view, and use the Browse buttons to select your images. The 'about page' image is $collection_name.gif, and the 'home page' image is ${collection_name}_sm.gif.\n";
+    print "<p>\n";
+    print "Alternatively, edit your collection's collect.cfg file manually and add:\n";
+    print "<p>\n";
+    print "<tt>\n";
+    print "collectionmeta iconcollectionsmall $language_modifier \"_httpprefix_/collect/$collection_name/images/$image_directory" . "${collection_name}_sm.gif\"\n<br>";
+    print "collectionmeta iconcollection $language_modifier \"_httpprefix_/collect/$collection_name/images/$image_directory" . "$collection_name.gif\"\n";
+    print "</tt>\n";
+}
+else {
+    print "<p>Error: parameter not defined.";
+}
+
+print end_html();
Index: /other-projects/trunk/image-generation/examples.dm
===================================================================
--- /other-projects/trunk/image-generation/examples.dm	(revision 14155)
+++ /other-projects/trunk/image-generation/examples.dm	(revision 14155)
@@ -0,0 +1,32 @@
+
+## "DSpace example" ## documented_example_collection_icon ## dspace_en ##
+
+## "Exemple\nDSpace" ## documented_example_collection_icon ## dspace_fr ##
+
+## "ColecciÃ³n de\nmuestra DSpace" ## documented_example_collection_icon ## dspace_es ##
+
+## "ÐÑÐžÐŒÐµÑ DSpace" ## documented_example_collection_icon ## dspace_ru ##
+
+## "greenstone translator\ninterface" ## collection_icon ## gti ##
+
+## "online resources" ## green_bar_left_aligned ## kea-online ##
+
+## "how kea works" ## green_bar_left_aligned ## kea-how ##
+
+## "how kea-4.0 works" ## green_bar_left_aligned ## kea-4.0-how ##
+
+## "kea-3.0 examples" ## green_bar_left_aligned ## kea-3.0-examples ##
+
+## "kea-4.0 examples" ## green_bar_left_aligned ## kea-4.0-examples ##
+
+## "publications" ## green_bar_left_aligned ## kea-publications ##
+
+## "download kea" ## green_bar_left_aligned ## kea-download ##
+
+## "contact us" ## green_bar_left_aligned ## kea-contact ##
+
+## "greenstone\ndocumentation" ## toki_collection_icon ## gsdocs ##
+
+## "nzdl\npublications" ## toki_collection_icon ## nzpubl ##
+
+## "greenstone\narchives" ## toki_collection_icon ## gsarch ##
Index: /other-projects/trunk/image-generation/html/make-images.html
===================================================================
--- /other-projects/trunk/image-generation/html/make-images.html	(revision 14155)
+++ /other-projects/trunk/image-generation/html/make-images.html	(revision 14155)
@@ -0,0 +1,168 @@
+<?xml version="1.0" encoding="iso-8859-1"?>
+<!DOCTYPE html
+	PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+	 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-US">
+<head>
+<title>Greenstone image generation</title>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+</head>
+<body background="images/chalk.gif">
+
+<table border="0" cellpadding="0" cellspacing="0">
+<tr><td><img src="spacer.gif" width="80"></td>
+<td>
+
+<form name="ClassifierImageForm" method="get" action="http://www.greenstone.org/make-images/make-classifier-images.cgi">
+<table cellspacing="10">
+<tr>
+<td colspan="2"><h3>Greenstone classifier image generation</h3></td>
+<td>e.g. <img src="tsubjon.gif"></td>
+</tr>
+<tr>
+<td width="45%">Language interface: </td>
+<td width="25%">
+<select name="l">
+<option value="ar.arabic">Arabic</option>
+<option value="hy.armenian">Armenian</option>
+<option value="id.indo">Bahasa Indonesia (Indonesian)</option>
+<option value="ca.catalan">CatalÃ  (Catalan)</option>
+<option value="hr.croatian">Croatian</option>
+<option value="de.german">Deutsch (German)</option>
+<option value="en.english" selected>English</option>
+<option value="es.spanish">EspaÃ±ol (Spanish)</option>
+<option value="fa.farsi">Farsi</option>
+<option value="fi.finnish">Finnish</option>
+<option value="fr.french">FranÃ§ais (French)</option>
+<option value="gl.galician">Galician</option>
+<option value="ka.georgian">Georgian</option>
+<option value="he.hebrew">Hebrew</option>
+<!-- <option value="hi.hindi">Hindi</option> No images generated for this language yet -->
+<option value="it.italian">Italiano</option>
+<!-- <option value="kn.kannada">Kannada</option> No images generated for this language yet -->
+<option value="lv.latvian">Latvian</option>
+<option value="mi.maori">MÄori</option>
+<option value="nl.dutch">Netherlands (Dutch)</option>
+<option value="sr.serbian">Serbian</option>
+<!-- <option value="th.thai">Thai</option> Not possible with current Freetype -->
+<option value="vi.vietnamese">Tiáº¿ng Viá»t (Vietnamese)</option>
+<option value="tr.turkish">Turkish</option>
+<option value="uk.ukrainian">Ukrainian</option>
+<option value="pl.polish">polski (Polish)</option>
+<option value="pt-br.port-br">portuguÃªs (Brasil)</option>
+<option value="pt-pt.port-pt">portuguÃªs (Portugal)</option>
+<option value="cs.czech">Äesky (Czech)</option>
+<option value="el.greek">ÎÎ»Î»Î·ÎœÎ¹ÎºÎ¬ (Greek)</option>
+<option value="ky.kirghiz">ÐÑÑÐ³ÑÐ·ÑÐ° (Kirghiz)</option>
+<option value="mn.mongolian">ÐÐŸÐœÐ³ÐŸÐ» (Mongolian)</option>
+<option value="ru.russian">Ð ÑÑÑÐºÐŸ (Russian)</option>
+<option value="kk.kazakh">ÒÐ°Ð·Ð°Ò (Kazakh)</option>
+<option value="bn.bengali">àŠ¬àŠŸàŠàŠ²àŠŸ (Bengali)</option>
+<option value="ja.japanese">æ¥æ¬èª (Japanese)</option>
+<option value="zh.chinese">ç®äœäž­æ (Simplified Chinese)</option>
+<option value="zh-tr.chinese-trad">ç¹é«äž­æ (Traditional Chinese)</option>
+</select>
+</td>
+<td></td>
+</tr>
+<tr>
+<td valign="top">Classifier buttonname argument:<br><font size="-1">(ASCII characters only)</font></td>
+<td valign="top"><input type="text" name="macro" size="30"/></td>
+<td valign="top">e.g. Subject</td>
+</tr>
+<tr>
+<td valign="top">Image name:<br><font size="-1">(ASCII characters only)</font></td>
+<td valign="top"><input type="text" name="image" size="30"/></td>
+<td valign="top">e.g. subj</td>
+</tr>
+<tr>
+<td valign="top">Text to appear on classifier button: </td>
+<td valign="top"><input type="text" name="text" size="30"/></td>
+<td valign="top">e.g. subjects</td>
+</tr>
+<tr>
+<td></td>
+<td><center><input type="submit" value="Go"/></center></td>
+<td></td>
+</tr>
+</table>
+</form>
+
+<hr>
+
+<form name="CollectionImageForm" method="get" action="http://www.greenstone.org/make-images/make-collection-images.cgi">
+<table cellspacing="10">
+<tr>
+<td colspan="2"><h3>Greenstone collection image generation</h3></td>
+<td>e.g. <img src="demo_sm.gif" border="1"></td>
+</tr>
+<tr>
+<td width="45%">Language interface: </td>
+<td width="25%">
+<select name="l">
+<option value="ar.arabic">Arabic</option>
+<option value="hy.armenian">Armenian</option>
+<option value="id.indo">Bahasa Indonesia (Indonesian)</option>
+<option value="ca.catalan">CatalÃ  (Catalan)</option>
+<option value="hr.croatian">Croatian</option>
+<option value="de.german">Deutsch (German)</option>
+<option value="en.english" selected>English</option>
+<option value="es.spanish">EspaÃ±ol (Spanish)</option>
+<option value="fa.farsi">Farsi</option>
+<option value="fi.finnish">Finnish</option>
+<option value="fr.french">FranÃ§ais (French)</option>
+<option value="gl.galician">Galician</option>
+<option value="ka.georgian">Georgian</option>
+<option value="he.hebrew">Hebrew</option>
+<!-- <option value="hi.hindi">Hindi</option> No images generated for this language yet -->
+<option value="it.italian">Italiano</option>
+<!-- <option value="kn.kannada">Kannada</option> No images generated for this language yet -->
+<option value="lv.latvian">Latvian</option>
+<option value="mi.maori">MÄori</option>
+<option value="nl.dutch">Netherlands (Dutch)</option>
+<option value="sr.serbian">Serbian</option>
+<!-- <option value="th.thai">Thai</option> Not possible with current Freetype -->
+<option value="vi.vietnamese">Tiáº¿ng Viá»t (Vietnamese)</option>
+<option value="tr.turkish">Turkish</option>
+<option value="uk.ukrainian">Ukrainian</option>
+<option value="pl.polish">polski (Polish)</option>
+<option value="pt-br.port-br">portuguÃªs (Brasil)</option>
+<option value="pt-pt.port-pt">portuguÃªs (Portugal)</option>
+<option value="cs.czech">Äesky (Czech)</option>
+<option value="el.greek">ÎÎ»Î»Î·ÎœÎ¹ÎºÎ¬ (Greek)</option>
+<option value="ky.kirghiz">ÐÑÑÐ³ÑÐ·ÑÐ° (Kyrgyz)</option>
+<option value="mn.mongolian">ÐÐŸÐœÐ³ÐŸÐ» (Mongolian)</option>
+<option value="ru.russian">Ð ÑÑÑÐºÐŸ (Russian)</option>
+<option value="kk.kazakh">ÒÐ°Ð·Ð°Ò (Kazakh)</option>
+<option value="bn.bengali">àŠ¬àŠŸàŠàŠ²àŠŸ (Bengali)</option>
+<option value="ja.japanese">æ¥æ¬èª (Japanese)</option>
+<option value="zh.chinese">ç®äœäž­æ (Simplified Chinese)</option>
+<option value="zh-tr.chinese-trad">ç¹é«äž­æ (Traditional Chinese)</option>
+</select>
+</td>
+<td></td>
+</tr>
+<tr>
+<td valign="top">Collection internal name:<br><font size="-1">(max 8 ASCII characters)</font></td>
+<td valign="top"><input type="text" name="collection" size="30"/></td>
+<td valign="top">e.g. demo</td>
+</tr>
+<tr>
+<td valign="top">Text to appear on collection icons:<br><font size="-1">(Use "\n" for a newline)</font></td>
+<td valign="top"><input type="text" name="text" size="30"/></td>
+<td valign="top">e.g. Greenstone\ndemo</td>
+</tr>
+<tr>
+<td></td>
+<td><center><input type="submit" value="Go"/></center></td>
+<td></td>
+</tr>
+</table>
+</form>
+
+</td>
+</tr></table>
+
+</body>
+</html>
Index: /other-projects/trunk/image-generation/make-images.pl
===================================================================
--- /other-projects/trunk/image-generation/make-images.pl	(revision 14155)
+++ /other-projects/trunk/image-generation/make-images.pl	(revision 14155)
@@ -0,0 +1,599 @@
+#!/usr/bin/perl
+
+###########################################################################
+#
+# make-images.pl
+#
+# A component of the Greenstone digital library software
+# from the New Zealand Digital Library Project at the 
+# University of Waikato, New Zealand.
+#
+# Copyright (C) 2005 New Zealand Digital Library Project
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+#
+# --------------------------------------------------------------------------
+#
+# This script is an alternative to translate.pl that uses ImageMagick
+# instead of Gimp to generate the button images. The advantage of using
+# ImageMagick is that it supports Unicode (and other multibyte encodings).
+#
+# This script requires the following components installed:
+#
+#  - A recent version of ImageMagick, and the PerlMagick extensions.
+#      (http://www.imagemagick.org)
+#
+#  - The FreeType libraries (http://freetype.sourceforge.net)
+#
+# The script reads through the macrofile specified at the command line,
+# and generates images for each of the image macros. It does this by
+# 'pasting' the button text onto a set of pre-generated images, using the
+# annotate.pl script. The background images used, and the arguments to
+# annotate.pl, depend on the type of image (eg. nav_bar_button) being
+# generated.
+#
+###########################################################################
+
+
+BEGIN {
+    die "GSDLHOME not set\n" unless defined $ENV{'GSDLHOME'};
+    unshift (@INC, "$ENV{'GSDLHOME'}/perllib");
+}
+
+
+use parsargv;
+use unicode;
+use util;
+
+
+my $fribidi_path = "/home/mdewsnip/packages/fribidi-0.10.4/bin";
+
+
+# -------------------------------------------------------------------------
+#    This script can use any TrueType font (the 'font' argument).
+#
+#    The base font size should be a reasonable size for nav_bar_buttons.
+#  A value of 15 is likely to be a good starting point for most fonts. The
+#  baseline offset value (a fraction) should be set if the text for the
+#  language is displayed too high or too low.
+#
+#    ARIALBD.TTF font: partial Unicode support, bold
+#      font size = 15 (calculated so text_height = 17)
+#
+#    ARIALUNI.TTF font: complete Unicode 2.0 support, but no bold
+#      font size = 11 (calculated so text_height = 17)
+#
+#    Available options:
+#
+#      font                                        (default ARIALBD.TTF)
+#      base_font_size                              (default 15)
+#      baseline_offset_factor (moves text down)    (default 0.0)
+#      right_to_left                               (default false)
+#      no_nav_bar_button_text_height_warnings      (default false)
+#      document_button_font_size
+#      document_button_width                       (default 66)
+#      document_button_height                      (default 30)
+#      collector_bar_button_width                  (default 77)
+#      collector_bar_button_height                 (default 28)
+#      home_page_button_width                      (default 100)
+#
+# -------------------------------------------------------------------------
+%language_specifications = 
+    (
+     # Arabic
+     "ar", { 'base_font_size' => "16",
+	     'right_to_left' => 1,
+	     'no_nav_bar_button_text_height_warnings' => 1 },
+
+     # Bengali
+     "bn", { 'font' => "ARIALUNI.TTF",
+	     'base_font_size' => "16",
+	     'baseline_offset_factor' => (1/5),
+	     'no_nav_bar_button_text_height_warnings' => 1 },
+
+     # Catalan
+     "ca", { 'document_button_width' => "67",
+	     'collector_bar_button_width' => "80" },
+
+     # Czech
+     "cs", { 'document_button_width' => "79" },
+
+     # German
+     "de", { 'document_button_width' => "108" },
+
+     # Greek
+     "el", { 'document_button_width' => "100" },
+
+     # English
+     "en", { },
+
+     # Spanish
+     "es", { 'document_button_width' => "67",
+	     'collector_bar_button_width' => "106" },
+
+     # Farsi
+     "fa", { 'base_font_size' => "16",
+	     'right_to_left' => 1,
+	     'no_nav_bar_button_text_height_warnings' => 1 },
+
+     # Finnish
+     "fi", { 'document_button_width' => "81" },
+
+     # French
+     "fr", { 'document_button_width' => "107",
+	     'collector_bar_button_width' => "92" },
+
+     # Galician
+     "gl", { 'document_button_width' => "71",
+	     'collector_bar_button_width' => "103" },
+
+     # Hebrew
+     "he", { },
+
+     # Hindi -- not tried yet
+     # "hi", { },
+
+     # Croatian
+     "hr", { 'document_button_width' => "87" },
+
+     # Armenian
+     "hy", { 'font' => "ARIALUNI.TTF",
+	     'base_font_size' => "18",
+	     'baseline_offset_factor' => (1/9),
+	     'no_nav_bar_button_text_height_warnings' => 1,
+	     'document_button_font_size' => "11",
+	     'document_button_width' => "108" },
+
+     # Indonesian
+     "id", { 'document_button_width' => "80" },
+
+     # Italian
+     "it", { 'document_button_width' => "76",
+	     'collector_bar_button_width' => "89" },
+
+     # Japanese
+     "ja", { 'font' => "ARIALUNI.TTF",
+	     'base_font_size' => "15",
+	     'baseline_offset_factor' => (1/5) },
+
+     # Georgian
+     "ka", { 'font' => "ARIALUNI.TTF",
+	     'base_font_size' => "15",
+	     'baseline_offset_factor' => (1/15),
+	     'no_nav_bar_button_text_height_warnings' => 1,
+	     'document_button_width' => "100",
+	     'collector_bar_button_width' => "87",
+	     'collector_bar_button_height' => "45" },
+
+     # Kazakh
+     "kk", { 'document_button_width' => "101",
+	     'collector_bar_button_width' => "103",
+	     'home_page_button_width' => "106" },
+
+     # Kannada -- not tried yet
+     # "kn", { },
+
+     # Kirghiz
+     "ky", { },
+
+     # Latvian
+     "lv", { },
+
+     # Maori
+     "mi", { 'document_button_width' => "97",
+	     'document_button_height' => "42" },
+
+     # Mongolian
+     "mn", { 'document_button_width' => "95",
+	     'collector_bar_button_width' => "84",
+	     'collector_bar_button_height' => "42",
+	     'home_page_button_width' => "109" },
+
+     # Dutch
+     "nl", { 'document_button_width' => "86" },
+
+     # Polish
+     "pl", { 'document_button_width' => "83" },
+
+     # Portuguese (Brazil)
+     "pt-br", { },
+
+     # Portuguese (Portugal)
+     "pt-pt", { },
+
+     # Russian
+     "ru", { 'document_button_width' => "69",
+	     'collector_bar_button_width' => "91",
+	     'home_page_button_width' => "113" },
+
+     # Serbian (Latin version)
+     "sr", { 'document_button_width' => "87" },
+
+     # Thai -- not supported because Freetype doesn't support combining characters!
+     # "th", { 'font' => "ARIALUNI.TTF" },
+
+     # Turkish
+     "tr", { 'document_button_width' => "75" },
+
+     # Ukrainian
+     "uk", { 'document_button_width' => "81" },
+
+     # Vietnamese
+     "vi", { },
+
+     # Chinese (Simplified)
+     "zh", { 'font' => "ARIALUNI.TTF",
+	     'base_font_size' => "15",
+	     'baseline_offset_factor' => (4/15) },
+
+     # Chinese (Traditional)
+     "zh-tr", { 'font' => "ARIALUNI.TTF",
+	        'base_font_size' => "16",
+	        'baseline_offset_factor' => (1/4),
+	        'document_button_width' => "67",
+		'collector_bar_button_width' => "103",
+	        'home_page_button_width' => "106" },
+
+     );
+
+
+sub print_usage
+{
+    print STDERR "\n";
+    print STDERR "mkimages.pl: Uses ImageMagick to generate images required by a\n";
+    print STDERR "              Greenstone macro file.\n\n";
+    print STDERR "  usage: $0 [options] macrofile\n\n";
+    print STDERR "  options:\n";
+    print STDERR "   -language_symbol      ISO abbreviation of language (e.g. German=de,\n";
+    print STDERR "                         French=fr, Maori=mi)\n";
+    print STDERR "   -image_dir directory  full path to directory in which to create images\n";
+    print STDERR "                         (defaults to images)\n\n";
+}
+
+
+sub main
+{
+    # Parse command line arguments
+    if (!parsargv::parse(\@ARGV, 
+			 'verbose', \$verbose,
+			 'language_symbol/.*', \$language_symbol,
+			 'image_dir/.*/images', \$image_dir)) {
+	&print_usage();
+	die "\n";
+    }
+
+    if (!defined $ARGV[0]) {
+	print STDERR "Error: No macro file supplied\n";
+	&print_usage();
+	die "\n";
+    }
+    my $macrofile = $ARGV[0];
+    die "\nError: Macrofile $macrofile does not exist\n\n" unless -e $macrofile;
+
+    if (!-e $image_dir) {
+	mkdir ($image_dir, 511) || die "\nError: Couldn't create image_dir $image_dir\n\n";
+    }
+
+    if (!$language_specifications{$language_symbol}) {
+	die "\nError: No specification exists for this language.\n\n";
+    }
+
+    open(INPUT, $macrofile) || die "\nError: Couldn't open $macrofile for reading.\n\n";
+    open(OUTPUT, ">$macrofile.new") || die "\nError: Couldn't open temporary file $macrofile.new for writing\n\n";
+
+    &parse_file(INPUT, OUTPUT);
+
+    close(OUTPUT);
+    close(INPUT);
+
+    &util::cp($macrofile, "$macrofile.orig");
+    &util::mv("$macrofile.new", $macrofile);
+}
+
+
+sub parse_file
+{
+    my ($input, $output) = @_;
+
+    undef $/;
+    my $dmfile = <$input>;
+    $/ = "\n";
+
+    # Process all the images in the macrofile
+    $dmfile =~ s/(?:^|\n)\#\#\s*\"([^\"]*)\"\s*\#\#\s*([^\s\#]*)\s*\#\#\s*([^\s\#]*)\s*\#\#(.*?)(?=(\n\#|\s*\Z))/&process_image ($1, $2, $3, $4)/esg;
+
+    # Add the language parameters to each macro
+    $dmfile =~ s/(\n\s*)(_[^_]*_)\s*(\[[^\]]*\])?\s*\{/$1 . &add_language_param ($2, $3)/esg;
+    print $output $dmfile;
+}
+
+
+sub process_image
+{
+    my ($text, $image_type, $image_name, $image_macros) = @_;
+
+    my $font = $language_specifications{$language_symbol}{"font"} || "ARIALBD.TTF";
+    my $base_font_size = $language_specifications{$language_symbol}{"base_font_size"} || "15";
+    my $baseline_offset_factor = $language_specifications{$language_symbol}{"baseline_offset_factor"} || "0.0";
+
+    # Convert all "\n" strings in the text into the newline character
+    my $text_internal = $text;
+    $text_internal =~ s/\\n/\n/g;
+
+    # Most languages have left-to-right text
+    my $h_align_flush = "left";
+
+    # A couple of extra steps are necessary for right-to-left text (Arabic, Farsi)
+    if (defined($language_specifications{$language_symbol}{"right_to_left"})) {
+	# Write the text string out to a file for shape_arabic.pl to work on
+	open(STRING_FILE, ">string.raw");
+	print STRING_FILE $text_internal;
+	close(STRING_FILE);
+
+	# Use shape_arabic.pl to "join" the characters correctly and fribidi to reverse the characters properly
+	$text_internal = `perl -S shape_arabic.pl -file string.raw | $fribidi_path/fribidi`;
+
+	# Remove the extra space fribidi adds before the reversed string
+	$text_internal =~ s/(^|\n)\s*/$1/g;
+
+	# Remove the temporary text file
+	&util::rm("string.raw");
+
+	# Text aligned "flush" will now be at the right 
+	$h_align_flush = "right";
+    }
+
+    my $text_unicode = &unicode::utf82unicode($text_internal);
+
+    # Edit image macros
+    unless ($language_symbol eq "en") {
+	$image_macros =~ s/(_httpimg_\/)(?:[^\/\}]*\/)?([^\}]*\.(?:gif|jpe?g|png))/$1$language_symbol\/$2/gs;
+    }
+
+    # Generate top_nav_button images (eg. "preferences")
+    if ($image_type eq "top_nav_button") {
+	my $font_size = $base_font_size;
+
+	my $tnb_options = "-image_width 40 -stretchable_width -image_height 20";
+	$tnb_options .= " -padding_left 2 -padding_right 2";
+	$tnb_options .= " -baseline_offset " . &round($font_size * $baseline_offset_factor);
+	$tnb_options .= " -font $font -font_size $font_size";
+
+	# Generate on and off images
+	&annotate_image("tnb_ylon.gif", $tnb_options, $text_unicode, "${image_name}on.gif");
+	&annotate_image("tnb_ylof.gif", $tnb_options, $text_unicode, "${image_name}of.gif");
+    }
+
+    # Generate nav_bar_button images (eg. "search", classifier buttons)
+    elsif ($image_type eq "nav_bar_button") {
+	my $font_size = $base_font_size;
+
+	my $nbb_options = "-image_width 87 -image_height 17 -stretchable_width";
+	$nbb_options .= " -baseline_offset " . &round($font_size * $baseline_offset_factor);
+	$nbb_options .= " -font $font -font_size $font_size";
+	$nbb_options .= " -no_text_height_warnings" if $language_specifications{$language_symbol}{"no_nav_bar_button_text_height_warnings"};
+
+	# Generate on and off images, and green image
+	&annotate_image("nbb_ylon.gif", $nbb_options, $text_unicode, "${image_name}on.gif");
+	&annotate_image("nbb_ylof.gif", $nbb_options, $text_unicode, "${image_name}of.gif");
+	&annotate_image("nbb_gron.gif", $nbb_options, $text_unicode, "${image_name}gr.gif");
+    }
+
+    # Generate document_button images (eg. "expand text")
+    elsif ($image_type eq "document_button") {
+	my $font_size = $language_specifications{$language_symbol}{"document_button_font_size"} || &round(($base_font_size * 4) / 5);
+
+	my $document_button_width = $language_specifications{$language_symbol}{"document_button_width"} || "66";
+	my $document_button_height = $language_specifications{$language_symbol}{"document_button_height"} || "30";
+
+	my $db_options = "-image_width $document_button_width -image_height $document_button_height";
+	$db_options .= " -baseline_offset " . &round($font_size * $baseline_offset_factor);
+	$db_options .= " -font $font -font_size $font_size"; 
+
+	# Generate on and off images
+	&annotate_image("db_ylon.gif", $db_options, $text_unicode, "${image_name}on.gif");
+	&annotate_image("db_ylof.gif", $db_options, $text_unicode, "${image_name}of.gif");
+    }
+
+    # Generate collector_bar_button images (eg. "source data")
+    elsif ($image_type eq "collector_bar_button") {
+	my $font_size = &round(($base_font_size * 4) / 5);
+
+	my $collector_bar_button_width = $language_specifications{$language_symbol}{"collector_bar_button_width"} || "77";
+	my $collector_bar_button_height = $language_specifications{$language_symbol}{"collector_bar_button_height"} || "28";
+
+	my $cbb_options = "-image_width $collector_bar_button_width -image_height $collector_bar_button_height";
+	$cbb_options .= " -baseline_offset " . &round($font_size * $baseline_offset_factor);
+	$cbb_options .= " -font $font -font_size $font_size";
+
+	# Generate on and off images (yellow), on and off images (green), and grey image
+	&annotate_image("cbb_ylon.gif", $cbb_options, $text_unicode, "yc${image_name}on.gif");
+	&annotate_image("cbb_ylof.gif", $cbb_options, $text_unicode, "yc${image_name}of.gif");
+	&annotate_image("cbb_gron.gif", $cbb_options, $text_unicode, "gc${image_name}on.gif");
+	&annotate_image("cbb_grof.gif", $cbb_options, $text_unicode, "gc${image_name}of.gif");
+	&annotate_image("cbb_gyof.gif", $cbb_options . " -text_colour \"#a0a0a0\"", $text_unicode, "nc${image_name}of.gif");
+    }
+
+    # Generate green_bar_left_aligned images (eg. "results" bar)
+    elsif ($image_type eq "green_bar_left_aligned") {
+	my $font_size = $base_font_size;
+
+	my $lgb_options = "-image_width 537 -image_height 17";
+	$lgb_options .= " -h_align $h_align_flush -padding_left 15 -padding_right 15";
+	$lgb_options .= " -baseline_offset " . &round($font_size * $baseline_offset_factor);
+	$lgb_options .= " -font $font -font_size $font_size";
+	$lgb_options .= " -no_text_height_warnings" if $language_specifications{$language_symbol}{"no_nav_bar_button_text_height_warnings"};
+
+	# Generate on image only
+	&annotate_image("nbb_gron.gif", $lgb_options, $text_unicode, "${image_name}.gif");
+    }
+
+    # Generate green_title images (eg. "about", classifier titles)
+    elsif ($image_type eq "green_title") {
+	my $font_size = ($base_font_size * 2);
+
+	my $gt_options = "-image_width 200 -image_height 57 -stretchable_width -stretchable_height -note_if_stretched";
+	$gt_options .= " -h_align right -padding_left 5 -padding_right 5 -padding_bottom 5 -v_align top";
+	if ($text_internal =~ /\n/) {
+	    $gt_options .= " -baseline_offset " . &round($font_size * $baseline_offset_factor);
+	}
+	$gt_options .= " -font $font -font_size $font_size";
+
+	# Generate green title image
+	&annotate_image("gt.gif", $gt_options, $text_unicode, "${image_name}.gif");
+    }
+
+    # Generate plain collection_icons
+    elsif ($image_type eq "collection_icon") {
+	my $font_size = &round(($base_font_size * 6) / 5);
+
+	my $ci_options = "-image_width 150 -image_height 44 -stretchable_height";
+	$ci_options .= " -h_align $h_align_flush -padding_left 2 -padding_right 2 -v_align top";
+	$ci_options .= " -font $font -font_size $font_size";
+
+	# Generate collection icon (small)
+	&annotate_image("cism.gif", $ci_options, $text_unicode, "${image_name}_sm.gif");
+
+	$font_size = &round(($font_size * 3) / 2);
+
+	$ci_options = "-image_width 225 -image_height 66 -stretchable_height";
+	$ci_options .= " -h_align $h_align_flush -padding_left 4 -padding_right 4 -v_align top";
+	$ci_options .= " -font $font -font_size $font_size";
+
+	# Generate collection icon
+	&annotate_image("cism.gif", $ci_options, $text_unicode, "${image_name}.gif");
+    }
+
+    # Generate documented_example_collection_icons (cog-wheel images)
+    elsif ($image_type eq "documented_example_collection_icon") {
+	my $font_size = &round(($base_font_size * 6) / 5);
+
+	my $dec_options = "-image_width 150 -image_height 88";
+	$dec_options .= " -h_align $h_align_flush -padding_left 1 -padding_right 1 -v_align top";
+	$dec_options .= " -font $font -font_size $font_size";
+
+	# Generate documented example collection icon
+	&annotate_image("dec.gif", $dec_options, $text_unicode, "${image_name}.gif");
+    }
+
+    # Generate toki_collection_icons
+    elsif ($image_type eq "toki_collection_icon") {
+	my $font_size = &round(($base_font_size * 6) / 5);
+
+	my $toki_options = "-image_width 150 -image_height 110";
+	$toki_options .= " -h_align $h_align_flush -padding_left 6 -padding_right 1 -v_align bottom -padding_bottom 20";
+	$toki_options .= " -font $font -font_size $font_size";
+
+	# Generate documented example collection icon
+	&annotate_image("toki.gif", $toki_options, $text_unicode, "${image_name}.gif");
+    }
+
+    # Generate home_page_button images (eg. "administration", "documentation")
+    elsif ($image_type eq "home_page_button") {
+	my $font_size = &round(($base_font_size * 4) / 5);
+
+	my $home_page_button_width = $language_specifications{$language_symbol}{"home_page_button_width"} || "100";
+
+	my $hpb_options = "-image_width $home_page_button_width -image_height 30 -stretchable_height";
+	$hpb_options .= " -baseline_offset " . &round($font_size * $baseline_offset_factor);
+	$hpb_options .= " -v_align center -padding_top 2";
+	$hpb_options .= " -font $font -font_size $font_size";
+
+	# Generate on and off images
+	&annotate_image("hpb_ylon.gif", $hpb_options, $text_unicode, "${image_name}on.gif");
+	&annotate_image("hpb_ylof.gif", $hpb_options, $text_unicode, "${image_name}of.gif");
+    }
+
+    # ...and that's all we know how to generate
+    else {
+	print STDERR "WARNING: Unknown image type found ($image_type)\n";
+    }
+
+    return "\n\#\# \"$text\" \#\# $image_type \#\# $image_name \#\#$image_macros";
+}
+
+
+sub annotate_image
+{
+    my ($background_image, $options, $text_unicode, $output_name) = @_;
+
+    # Convert the text to the form ImageMagick requires
+    my $text_imagick = "";
+    foreach $character (@$text_unicode) {
+	if ($character == 0x0A) {
+	    # Newline character
+	    $text_imagick .= "\\n";
+	}
+	elsif ($character < 0x80) {
+	    # Normal ascii character
+	    $text_imagick .= chr($character);
+	}
+	else {
+	    # Unicode character (convert to a four digit hexadecimal value)
+	    my $hex_val = sprintf("%lx", $character);
+	    $text_imagick .= "\\0x" . '0' x (4 - length($hex_val)) . $hex_val;
+	}
+    }
+
+    # Use the annotate.pl script to paste the text onto the background image
+    my $output_file = &util::filename_cat($image_dir, $output_name);
+    my $verbose_option = "";
+    $verbose_option = "-verbose" if $verbose;
+    print "\nRunning: annotate.pl -background_image $background_image $options -text \"$text_imagick\" -output_file $output_file\n" if $verbose;
+    `perl -S annotate.pl -background_image $background_image $options -text \"$text_imagick\" -output_file $output_file $verbose_option`;
+}
+
+
+sub round
+{
+    my ($fp_number) = @_;
+    if ($fp_number < 0.0) {
+	return int($fp_number - 0.5);
+    }
+    else {
+	return int($fp_number + 0.5);
+    }
+}
+
+
+sub add_language_param {
+    my ($macroname, $paramlist) = @_;
+
+    if ($language_symbol eq "en") { 
+	return "$macroname {";
+    }
+
+    my $first = 1;
+    if (defined $paramlist) {
+	$paramlist =~ s/^\[//;
+	$paramlist =~ s/\]$//;
+	my @params = split /\,/, $paramlist;
+	$paramlist = "";
+	foreach $param (@params) {
+	    # remove any existing language parameter
+	    if ($param !~ /^l=/) {
+		$paramlist .= "," unless $first;
+		$paramlist .= $param;
+		$first = 0;
+	    }
+	}
+    }
+    $paramlist .= "," unless $first;
+    $paramlist .= "l=" . $language_symbol;
+    return "$macroname [$paramlist] {";
+}
+
+
+&main(@ARGV);
Index: /other-projects/trunk/image-generation/shape_arabic.pl
===================================================================
--- /other-projects/trunk/image-generation/shape_arabic.pl	(revision 14155)
+++ /other-projects/trunk/image-generation/shape_arabic.pl	(revision 14155)
@@ -0,0 +1,387 @@
+#!/usr/bin/perl
+# -*-Perl-*-
+
+#---
+# $Id$
+#
+# ------------
+# Description:
+# ------------
+#  Perl script that does arabic utf-8 shaping
+#
+#  - Note how easy shaping really is.
+#  - This should be used an a learning tool for those interested
+#    in Arabic and in perl (its a learning medium).
+#
+# -----------------
+# Revision Details:    (Updated by Revision Control System)
+# -----------------
+#  $Date$
+#  $Author$
+#  $Revision$
+#  $Source$
+#
+# (www.arabeyes.org - under GPL license)
+#---
+
+# Point to and use Perl version 5.8 (or greater)
+use 5.8.0;
+
+# Try to be clean in variable usage, etc
+use strict;
+
+# Enable full UTF-8 support
+use utf8;
+use open ':utf8';
+binmode(STDOUT, ":utf8");
+
+# Enable Automatic command-line parsing
+require "newgetopt.pl";
+
+my (
+    $this_script,
+    $opt_debug,
+    $opt_file,
+    $out_line,
+   );
+
+# Specify global variable values and init some Variables
+$this_script    = $0;
+$this_script    =~ s|^.*/([^/]*)|$1|;
+
+# Process the command line
+&get_args();
+
+if (! $opt_file )
+{
+    print "ERROR($this_script): Specify input file to process with '-file' option\n";
+    &usage(1);
+}
+
+open (INFILE, "< $opt_file") or die "Can't open $opt_file - $! \n";
+
+while (<INFILE>)
+{
+    $out_line .= &shape_line($_);
+}
+print $out_line;
+
+exit(0);
+
+       ###        ###
+######## Procedures ########
+       ###        ###
+
+##
+# Do the actual Arabic Shaping
+sub shape_line
+{
+    my ($line)		= @_;
+
+    use constant ISOLATED	=> 0;
+    use constant INITIAL	=> 1;
+    use constant MEDIAL		=> 2;
+    use constant FINAL		=> 3;
+
+    my (
+	@char,
+	$cur,
+	$prev,
+	$next,
+	$index,
+	$prev_index,
+	$next_index,
+	$out,
+	$str,
+       );
+
+    # Hex values noted for all entries.
+    #          iso-8859-6	=>	[     s,      i,      m,      f]
+    my %map	= (
+		   "621"	=>	["FE80",      0,      0,      0],	# HAMZA
+		   "622"	=>	["FE81",      0,      0, "FE82"],	# ALEF_MADDA
+		   "623"	=>	["FE83",      0,      0, "FE84"],	# ALEF_HAMZA_ABOVE
+		   "624"	=>	["FE85",      0,      0, "FE86"],	# WAW_HAMZA
+		   "625"	=>	["FE87",      0,      0, "FE88"],	# ALEF_HAMZA_BELOW
+		   "626"	=>	["FE89", "FE8B", "FE8C", "FE8A"],	# YEH_HAMZA
+		   "627"	=>	["FE8D",      0,      0, "FE8E"],	# ALEF
+		   "628"	=>	["FE8F", "FE91", "FE92", "FE90"],	# BEH
+		   "629"	=>	["FE93",      0,      0, "FE94"],	# TEH_MARBUTA
+		   "62A"	=>	["FE95", "FE97", "FE98", "FE96"],	# TEH
+		   "62B"	=>	["FE99", "FE9B", "FE9C", "FE9A"],	# THEH
+		   "62C"	=>	["FE9D", "FE9F", "FEA0", "FE9E"],	# JEEM
+		   "62D"	=>	["FEA1", "FEA3", "FEA4", "FEA2"],	# HAH
+		   "62E"	=>	["FEA5", "FEA7", "FEA8", "FEA6"],	# KHAH
+		   "62F"	=>	["FEA9",      0,      0, "FEAA"],	# DAL
+		   "630"	=>	["FEAB",      0,      0, "FEAC"],	# THAL
+		   "631"	=>	["FEAD",      0,      0, "FEAE"],	# REH
+		   "632"	=>	["FEAF",      0,      0, "FEB0"],	# ZAIN
+		   "633"	=>	["FEB1", "FEB3", "FEB4", "FEB2"],	# SEEN
+		   "634"	=>	["FEB5", "FEB7", "FEB8", "FEB6"],	# SHEEN
+		   "635"	=>	["FEB9", "FEBB", "FEBC", "FEBA"],	# SAD
+		   "636"	=>	["FEBD", "FEBF", "FEC0", "FEBE"],	# DAD
+		   "637"	=>	["FEC1", "FEC3", "FEC4", "FEC2"],	# TAH
+		   "638"	=>	["FEC5", "FEC7", "FEC8", "FEC6"],	# ZAH
+		   "639"	=>	["FEC9", "FECB", "FECC", "FECA"],	# AIN
+		   "63A"	=>	["FECD", "FECF", "FED0", "FECE"],	# GHAIN
+		   "640"	=>	[ "640",      0,      0,      0],	# TATWEEL
+		   "641"	=>	["FED1", "FED3", "FED4", "FED2"],	# FEH
+		   "642"	=>	["FED5", "FED7", "FED8", "FED6"],	# QAF
+		   "643"	=>	["FED9", "FEDB", "FEDC", "FEDA"],	# KAF
+		   "644"	=>	["FEDD", "FEDF", "FEE0", "FEDE"],	# LAM
+		   "645"	=>	["FEE1", "FEE3", "FEE4", "FEE2"],	# MEEM
+		   "646"	=>	["FEE5", "FEE7", "FEE8", "FEE6"],	# NOON
+		   "647"	=>	["FEE9", "FEEB", "FEEC", "FEEA"],	# HEH
+		   "648"	=>	["FEED",      0,      0, "FEEE"],	# WAW
+		   "649"	=>	["FEEF",      0,      0, "FEF0"],	# ALEF_MAKSURA
+		   "64A"	=>	["FEF1", "FEF3", "FEF4", "FEF2"],	# YEH
+		   # exceptions
+		   "644622"	=>	["FEF5",      0,      0, "FEF6"],	# LAM_ALEF_MADDA
+		   "644623"	=>	["FEF7",      0,      0, "FEF8"],	# LAM_ALEF_HAMZA_ABOVE
+		   "644625"	=>	["FEF9",      0,      0, "FEFA"],	# LAM_ALEF_HAMZA_BELOW
+		   "644627"	=>	["FEFB",      0,      0, "FEFC"],	# LAM_ALEF
+
+		   ## ---- My additions for Farsi ----
+		   # I think there is a bug in this script which causes an initial "Peh"
+		   # to be treated as isolated. This is why the isolated value for "Peh"
+		   # is set to the initial value.
+		   "67E"        =>     [ "FB58", "FB58", "FB59", "FB57" ],      # FARSI PEH
+		   "686"        =>     [ "FB7A", "FB7C", "FB7D", "FB7B" ],      # FARSI TCHEH
+		   "6AF"        =>     [ "FB92", "FB94", "FB95", "FB93" ],      # FARSI GAF
+		   "6CC"        =>     [ "FBFC", "FBFE", "FBFF", "FBFD" ],      # FARSI YEH
+		  );
+
+    my %special_is_next		= ( "640" => 1 );
+    my %special_is_comb1	= ( "644" => 1 );
+    my %special_is_comb2	= ( 
+				    "622" => 1,
+				    "623" => 1,
+				    "625" => 1,
+				    "627" => 1,
+				  );
+
+    my %special_is_composing	= (
+				    "64B" => 1,		# FATHATAN
+				    "64C" => 1,		# DAMMATAN
+				    "64D" => 1,		# KASRATAN
+				    "64E" => 1,		# FATHA
+				    "64F" => 1,		# DAMMA
+				    "650" => 1,		# KASRA
+				    "651" => 1,		# SHADDA
+				    "652" => 1,		# SUKUN
+				    "653" => 1,		# MADDAH ABOVE
+				    "654" => 1,		# HAMZA ABOVE
+				    "655" => 1,		# HAMZA BELOW
+				    "670" => 1,		# SUPERSCRIPT ALEF 
+				    "6D6" => 1,		# HIGH LIG. SAD WITH LAM WITH ALEF MAKSURA
+				    "6D7" => 1,		# HIGH LIG. QAF WITH LAM WITH ALEF MAKSURA
+				    "6D8" => 1,		# HIGH MEEM INITIAL FORM
+				    "6D9" => 1,		# HIGH LAM ALEF
+				    "6DA" => 1,		# HIGH JEEM
+				    "6DB" => 1,		# HIGH THREE DOTS
+				    "6DC" => 1,		# HIGH SEEN
+# The 2 entires below should not be here - contact unicode.org !!
+# 				    "6DD" => 1,		# END OF AYAH
+#				    "6DE" => 1,		# START OF RUB EL HIZB
+				    "6DF" => 1,		# HIGH ROUNDED ZERO
+				    "6E0" => 1,		# HIGH UPRIGHT RECTANGULAR ZERO
+				    "6E1" => 1,		# HIGH DOTLESS HEAD OF KHAH
+				    "6E2" => 1,		# HIGH MEEM ISOLATED FORM
+				    "6E3" => 1,		# LOW SEEN
+				    "6E4" => 1,		# HIGH MADDA
+				    "6E7" => 1,		# HIGH YEH
+				    "6E8" => 1,		# HIGH NOON
+				    "6EA" => 1,		# EMPTY CENTRE LOW STOP
+				    "6EB" => 1,		# EMPTY CENTRE HIGH STOP
+				    "6EC" => 1,		# HIGH STOP WITH FILLED CENTRE
+				    "6ED" => 1,		# LOW MEEM
+				  );
+
+    @char = split ("", $line);
+
+    for ($index = 0; $index <= $#char; $index++)
+    {
+	$cur = unpack("U", $char[$index]);
+	$cur = sprintf "\U%x\E", $cur;
+	if ( $opt_debug )
+	{
+	    print "---- $index ----\n";
+	    print "NOW - $cur \n";
+	}
+	if ( defined $map{$cur} )
+	{
+	    # Previous character status
+	    $prev_index = $index;
+
+	  PREV_CHECK:
+	    {
+		$prev_index--;
+		$prev = unpack("U", $char[$prev_index]);
+		$prev = sprintf "\U%x\E", $prev;
+		if ( $opt_debug )
+		{
+		    print "prev - $prev \n";
+		}
+
+		# Get rid of all previous composers
+		if ( $special_is_composing{$prev} )
+		{
+		    redo PREV_CHECK;
+		}
+	    }
+	    
+	    if (
+		($index == 0)	       ||
+		!defined $map{$prev}   ||
+		(!$map{$prev}[INITIAL] &&
+		 !$map{$prev}[MEDIAL]
+		)
+	       )
+	    {
+		# Don't have a 'prev'
+		if ( $opt_debug )
+		{
+		    print "prev not defined \n";
+		}
+		undef $prev;
+	    }
+
+	    # Next     character status
+	    $next_index = $index;
+
+	    NEXT_CHECK:
+	    {
+		$next_index++;
+		$next = unpack("U", $char[$next_index]);
+		$next = sprintf "\U%x\E", $next;
+		if ( $opt_debug )
+		{
+		    print "next - $next \n";
+		}
+
+		# Get rid of all next composers
+		if ( $special_is_composing{$next} )
+		{
+		    redo NEXT_CHECK;
+		}
+	    }
+
+	    if (
+		($index == $#char)	||
+		!defined $map{$next}	||
+		(!$map{$next}[MEDIAL]	&&
+		 !$map{$next}[FINAL]	&&
+		 !$special_is_next{$next}
+		)
+	       )
+	    {
+		# Don't have a 'next'
+		if ( $opt_debug )
+		{
+		    print "next not defined \n";
+		}
+		undef $next;
+	    }
+
+	    # Shape the special combinational characters
+	    if ( $special_is_comb1{$cur} )
+	    {
+		if (defined $next )
+		{
+		    if ( $special_is_comb2{$next} )
+		    {
+			$out = ( (defined $prev) ? $map{"$cur$next"}[FINAL] : $map{"$cur$next"}[ISOLATED] );
+			$str .= pack("U", hex($out));
+			if ( $opt_debug )
+			{
+			    print "Got me a complex - use $out ($str)\n";
+			}
+			$index++;
+			next;
+		    }
+		}
+	    }
+
+	    # Medial
+	    if ( (defined $prev) && (defined $next) )
+	    {
+		# In case there is no medial, move to next :-)
+		if ( $out = $map{$cur}[MEDIAL] )
+		{
+		    $str .= pack("U", hex($out));
+		    if ( $opt_debug )
+		    {
+			print "Got prev & next - use $out ($str)\n";
+		    }
+		    next;
+		}
+	    }
+
+	    # Final
+	    if ( (defined $prev) )
+	    {
+		if ( $out = $map{$cur}[FINAL] )
+		{
+		    $str .= pack("U", hex($out));
+		    if ( $opt_debug )
+		    {
+			print "Got prev - use $out ($str)\n";
+		    }
+		    next;
+		}
+	    }
+
+	    # Initial
+	    if ( (defined $next) )
+	    {
+		if ( $out = $map{$cur}[INITIAL] )
+		{
+		    $str .= pack("U", hex($out));
+		    if ( $opt_debug )
+		    {
+			print "Got next - use $out ($str)\n";
+		    }
+		    next;
+		}
+	    }
+
+	    # Isolated/Seperated (Stand-alone)
+	    $out = $map{$cur}[ISOLATED];
+	    $str .= pack("U", hex($out));
+	    if ( $opt_debug )
+	    {
+		print "Got nothing - use $out ($str)\n";
+	    }
+	}
+	else
+	{
+	    $str .= pack("U", hex($cur));
+	}
+    }
+
+    if ( $opt_debug )
+    {
+	print "return - $str \n";
+    }
+    return ($str);
+}
+
+##
+# Print the simple usage
+sub usage
+{
+    my ($die_after)	= @_;
+
+    print "Usage: $this_script <-file filename>  [-debug] \n";
+    if ( $die_after ) { exit(5); }
+}
+
+##
+# Get the command line arguments
+sub get_args
+{
+  &NGetOpt (
+	    "debug"	=> 	\$opt_debug,			# enable the printing of debug output
+            "file=s"	=>	\$opt_file,			# specify a filename to process
+           ) || ( $? = 257, die "Invalid argument\n" );
+}
