emav has asked for the wisdom of the Perl Monks concerning the following question:

I've been trying to test GD::Graph and Unicode using a code snippet from bioportal.weizmann.ac.il but either I'm doing something wrong or GD::Graph does not support Unicode. Hopefully, you can spot my mistake.
use utf8; use GD::Graph::linespoints; @data = ( ["1st","2nd","3rd","4th","5th","6th","7th", "8th", "9th"], [undef, 52, 53, 54, 55, 56, undef, 58, 59], [60, 61, 61, undef, 68, 66, 65, 61, undef], ); $my_graph = new GD::Graph::linespoints( ); $my_graph->set( x_label => 'X Label', y_label => 'Y label', title => 'A Lines and Points Graph', y_max_value => 80, y_tick_number => 6, y_label_skip => 2, markers => [ 1, 5 ], ); my $ustring1 = "\x{263A}"; my $ustring2 = "\x{263A}"; $my_graph->set_legend( $ustring1, $ustring2 ); my $gd = $my_graph->plot(\@data); open(IMG, '>uni.gif') or die $!; binmode IMG; print IMG $gd->gif; close IMG;

Replies are listed 'Best First'.
Re: GD::Graph and Unicode
by Khen1950fx (Canon) on Sep 26, 2006 at 09:06 UTC
    As far as I can tell, GD::Graph itself doesn't support Unicode; however, it appears that there is some limited support for Unicode in GD---but it's experimental. To quote the author:

    "The interaction between Perl, Unicode, and libgd is not clear to me, and you should experiment a bit if you want to use it."

    He was referring to the stringFT() method to load and render Truetype fonts. Specifically, the optional "charmap" hashkey. It can have a Unicode value. You can find more info on it in the GD docs under "Character and String Drawing". See:

    GD

      Problem solved. Just add the following lines after the new GD::Graph::linespoints object is created. The number next to the font defines the font-size property.

      Of course, unifont.ttf must be a TrueType font file supporting unicode.

      $unifont = "./unifont.ttf"; $my_graph->set_title_font($unifont, 18); $my_graph->set_legend_font($unifont, 12);
      For more methods, visit GD::Graph.
      Thanks for the hint, Khen1950fx!

      I'll look into it and post again here if I come up with a solution.

Re: GD::Graph and Unicode
by msk_0984 (Friar) on Sep 26, 2006 at 07:28 UTC
    Hi

    Actually i have just copied and run your program and i get the output perfectly i can see the Graph Plotted well. But i am sorry to say i don't know much about this "utf8". Which OS are you using and try to check out the GD::Graph module.

    Just try to tell us what problem you are facing and make it clear. So that we can help you out in a better way.

    Work Hard Party Harderrr!!
    Sushil Kumar
      Thanks for the reply, msk!

      The problem does not lie with the graph itself but with the unicode character (smiling face) which is supposed to appear below the graph. It's a unicode character but it appears as a Western European accented character.