From: Pasi Kallinen Date: Wed, 3 Jul 2013 05:19:38 +0000 (+0300) Subject: Make Clark Kent write out UTF-8 files. X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=refs%2Fheads%2Fuser%2Fpaxed%2Fclark-kent-utf8;p=working%2FEvergreen.git Make Clark Kent write out UTF-8 files. Allow giving a font -parameter to change the default GD font for the graphs. Default to a TTF font, so UTF-8 characters work. Signed-off-by: Pasi Kallinen --- diff --git a/Open-ILS/src/reporter/clark-kent.pl b/Open-ILS/src/reporter/clark-kent.pl index 29b067dad4..866c332ce2 100755 --- a/Open-ILS/src/reporter/clark-kent.pl +++ b/Open-ILS/src/reporter/clark-kent.pl @@ -28,6 +28,7 @@ use Email::Send; use open ':utf8'; +my $font_file = '/usr/share/fonts/truetype/freefont/FreeSans.ttf'; my ($count, $config, $sleep_interval, $lockfile, $daemon) = (1, 'SYSCONFDIR/opensrf_core.xml', 10, '/tmp/reporter-LOCK'); @@ -37,6 +38,7 @@ GetOptions( "concurrency=i" => \$count, "bootstrap|boostrap=s" => \$config, "lockfile=s" => \$lockfile, + "font" => \$font_file, ); if (-e $lockfile) { @@ -354,6 +356,17 @@ if ($daemon) { #------------------------------------------------------------------- +sub set_gd_fonts { + my $pic = shift; + return if (! -e $font_file); + $pic->set_title_font($font_file, 14); + $pic->set_legend_font($font_file, 8); + $pic->set_x_axis_font($font_file, 8); + $pic->set_x_label_font($font_file, 10); + $pic->set_y_axis_font($font_file, 8); + $pic->set_y_label_font($font_file, 8); +} + sub send_success { my $r = shift; open F, $success_template or die "Cannot read '$success_template'"; @@ -408,6 +421,7 @@ sub build_csv { return unless ($csv); my $f = new FileHandle (">$file") or die "Cannot write to '$file'"; + binmode($f, ':utf8'); $csv->print($f, $r->{column_labels}); $csv->print($f, $_) for (@{$r->{data}}); @@ -438,6 +452,7 @@ sub build_html { my $r = shift; my $index = new FileHandle (">$file") or die "Cannot write to '$file'"; + binmode($index, ':utf8'); # index header print $index <<" HEADER"; @@ -475,6 +490,7 @@ sub build_html { push @links, "Debugging Info"; my $debug = new FileHandle (">$file.debug.html") or die "Cannot write to '$file.debug.html'"; + binmode($debug, ':utf8'); print $debug "DEBUG: $$r{report}{name}"; { no warnings; @@ -497,6 +513,7 @@ sub build_html { if ($r->{html_format}) { # create the raw output html file my $raw = new FileHandle (">$file.raw.html") or die "Cannot write to '$file.raw.html'"; + binmode($raw, ':utf8'); print $raw "$$r{report}{name}"; print $raw <<' CSS'; @@ -595,7 +612,7 @@ sub draw_pie { } my $pic = new GD::Graph::pie; - + set_gd_fonts($pic); $pic->set( label => $r->{column_labels}->[$vcol], start_angle => 180, @@ -712,7 +729,7 @@ sub draw_bars { $h = 0 if ($h < 0); my $pic = new GD::Graph::bars3d ($w + 250, $h + 500); - + set_gd_fonts($pic); $pic->set( title => $r->{report}{name}, x_labels_vertical => 1, @@ -819,7 +836,7 @@ sub draw_lines { $h = 0 if ($h < 0); my $pic = new GD::Graph::lines3d ($w + 250, $h + 500); - + set_gd_fonts($pic); $pic->set( title => $r->{report}{name}, x_labels_vertical => 1,