Not really a Perl solution, but maybe it helps...  Also, this is limited to PostScript fonts (well, not strictly, but with other font types, things would get much more involved).

The real work is being done by the PostScript interpreter (gs in this case). Perl is just writing the PS commands to a temp file and then running the PS interpreter (which could of course be done equally well with a simple shell script — but as this is a Perl forum ... :)

The example would produce a 1000x500 pixel PNG file showing the word "Perl" in big letters being rendered in a blue dotted outline.

If you want to use any non-standard PS fonts, you have to include the respective .pfa or .pfb font files at the beginning of the PS code (where indicated). If you don't want PNG output, you can simply choose a different driver and specify it via -sDEVICE=... ("gs -h" for a list of available devices).

#!/usr/bin/perl my $tmpfile = "demo.ps"; my $outfile = "demo.png"; open my $ps, ">", $tmpfile or die "Cannot create temp file '$tmpfile': + $!"; print $ps <<'EOF'; %!PS % (include any non-standard fonts here...) /Times-Roman findfont 300 scalefont setfont 10 10 moveto % position (Perl) true charpath % charpath makes outline 5 setlinewidth 1 setlinejoin 1 setlinecap [.1 6] 0 setdash % dotted line 0 0 0.5 setrgbcolor % in dark blue stroke showpage EOF close $ps; system "gs -q -dBATCH -dNOPAUSE -sDEVICE=pngalpha -r140 -g1000x500 -sO +utputFile=$outfile $tmpfile";

(For this to work, you of course need to have GhostScript (gs) installed.)


In reply to Re: Draw Font Outline (PS solution) by almut
in thread Draw Font Outline by avo

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.