#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2011
    Posts
    23
    Rep Power
    0

    Strangeness in PostScript::Simple


    I'm storing a string in a database with non-ASCII characters encoded in hex (trademark, \xd4). I want to pass this string on to PostScript::Simple in the text method to build a file that will be converted to PDF. When it comes out of the database there is only on \ and, according to the code in the module if it starts with \x and has two valid hex digits it's supposed to be converted to octal. But instead the \ is escaped with another \ and my PDF now has \xd4 instead of the trade mark symbol. I copied the substitution code:
    Code:
    $text =~ s|([\\\(\)])|\\$1|g;
    $text =~ s/([\x00-\x1f\x7f-\xff])/sprintf('\\%03o',ord($1))/ge;
    out of the module and put it in a separate file and it works, \xd4 is converted to \324 as expected.

    Any idea what's going on?

    I'm using Perl v5.14.2 and PostScript::Simple v0.07 under Cygwin on WinXP Pro.
  2. #2
  3. kill 9, $$;
    Devshed Supreme Being (6500+ posts)

    Join Date
    Sep 2001
    Location
    Shanghai, An tSín
    Posts
    6,898
    Rep Power
    3887
    Can you post a sample of the text you're trying to process also?
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2011
    Posts
    23
    Rep Power
    0
    Some example code:

    Code:
    #!/usr/bin/perl -w
    use strict;
    
    my $text = "Fuzzie Slippers\xd4 are great!";
    $text =~ s|([\\\(\)])|\\$1|g;
    $text =~ s/([\x00-\x1f\x7f-\xff])/sprintf('\\%03o',ord($1))/ge;
    print "$text\n";
    and the output is:

    Code:
    Fuzzie Slippers\324 are great!
    how ever, if I use the PostScript::Simple text method:

    Code:
    $p->text({align => center}, 4.25, 5.5, $text);
    the line in the PostScript file would look like this:

    Code:
    (Fuzzie Slippers\\xd4 are great!)   dup stringwidth pop 2 div neg 0 rmoveto show

IMN logo majestic logo threadwatch logo seochat tools logo