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

Good Morning,
I am currently working on a project where I write times in a postscript file. The position of the times varies. Their format is hh mm 1/2 where the 1/2 is optional if there are between 15 and 44 seconds to any minute.
I wanted to use the character representing halfes, but it did not print as such on my PS files. Currently I am shifting the text a bit to the left and insert a 1 a line and a 2 in a different font size. This unfortunately bloats the filesize as I need to redefine the fonts so often. This looks simplified as:
$p->text( {align => 'center'}, - 0.75, $line_height * $out_line, $tim +e); $p->setfont("Arial", 4); $p->setlinewidth(0.05); $p->text( {align => 'center'}, 2.5 , 0.7 - $line_height * $out_line, " +1"); $p->line( 2.7, $line_height * $out_line, 2.7 + 0.4, $line_height * $out_line ); $p->text( {align => 'center'}, 3.2, 0.25 - $line_height * $out_line, " +2");
New restrictions limit the time format even further. Variations are lots and fixed relation placing of the halves would not fit anymore. I am looking for a way to either directly add a half in the string, or to get the width of the printed string in mm, so I know where it ends, ... .

I am currently using PostScript::Simple and would prefer to use it in future yet I am open for other packages if this is not possible. My Perl is AS Perl 5.8.4 on Win XP.

Thank You for any help.

Replies are listed 'Best First'.
Re: Special characters and PostScript::Simple
by davis (Vicar) on Aug 17, 2004 at 12:55 UTC

    Select a font that includes the ½ symbol, then include the PostScript escape code for that symbol (275 in the normal encoding). The escape codes are defined in the PostScript Language Reference Manual Appendix E

    #!/usr/bin/perl use warnings; use strict; use PostScript::Simple; my $p = new PostScript::Simple(papersize => "A4", colour => 1, eps => 0, units => "in"); $p->setcolour("black"); $p->setfont("Times-Roman-iso", 20); $p->text(1,1, "Chee\275se"); $p->output("file.ps");

    Incidentally, the code you provided was of little use – it doesn't run by itself, and the user is required to guess values for $line_height and $out_line. I'd never used PostScript::Simple before, and this didn't make a lot of sense straight away. Anyway, the question was interesting.

    Cheers


    davis
    It wasn't easy to juggle a pregnant wife and a troubled child, but somehow I managed to fit in eight hours of TV a day.
      Thanks that works great.

      The revolution of the world will not be stopped anytime soon!>