Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

GD::Text::Arc

by da (Friar)
on Jan 23, 2004 at 02:10 UTC ( [id://323405]=CUFP: print w/replies, xml ) Need Help??

FreeType fonts can easily be used to draw text at an arbitrary angle, but what do you do if you want to draw text on a curve? I wrote up a script to do that using GD and GD::Text; it worked well enough that I turned it into a module, which I call GD::Text::Arc .

Sample output is here.

It works with arbitrary GD graphics objects and TrueType fonts, tries to provide intelligent defaults, and the output doesn't look so bad.

This was also my first foray into writing tests while I wrote code; that was just as useful as everyone says it is, so I think I'm a convert. Of course, I'm sure I need way more than 46 tests, but it's an OK first draft.

Now that I'm all puffed up with releasing my first CPAN module and stuff, I'd love for people to pick it apart and tell me what I did badly. :-)

___ -DA $_='daniel@coder.com 519-575-3733 /Prescient Code Solutions/ coder.c +om ';s/-/ /g;s/([.@])/ $1/g;@y=(42*1476312054+7*3,14120504e4,-42*330261-3 +3, 42*5436+3,42*2886+10,42*434987+5);s/(.)/ord(uc($1))/ge;for(@x=split/32 +/; @y; map{print chr} split /(..)/, shift(@x) + shift(@y)) {perlmonk.da.r +u}

Replies are listed 'Best First'.
Re: GD::Text::Arc
by xenchu (Friar) on Jan 23, 2004 at 02:46 UTC

    Neato! A job well done! Congratulations!

    xenchu

    Update: I forgot to ask. Will it do spirals as well?


    The Needs of the World and my Talents run parallel to infinity.
      Hey, spirals. That would be neat. But no, it doesn't currently. If somebody can suggest an algorythm that works with my code, I could make it do spirals. I was getting a headache even trying to figure out how to make it do ovals (*)...

      Other items on my wish-list:

      • ovals;
      • left-aligned and right-aligned to a specific point, instead of centered;
      • specifying the (center/left/right) anchor point at some angle other than 12 o'clock and 6 o'clock;
      • maybe even some arbitrary spline-curve, given some points? (bearing in mind that I have no idea how splines work).

      (*) The complication giving me trouble is that I need to recalculate the position (or drawing-angle) for each letter, to account for the fact that GD draws TrueType characters from the lower-left corner, not the center.

      I could easily set a separate scaling factor for X and Y coordinates (to make ovals), just like I could vary the radius on-the-fly (to make a spiral) but the problem is that the letters will be angled oddly (as if they were supposed to be in a circle). Too much for this bear of little brain! But, if you have suggestions, I'm all ears.

      ___ -DA $_='daniel@coder.com 519-575-3733 /Prescient Code Solutions/ coder.c +om ';s/-/ /g;s/([.@])/ $1/g;@y=(42*1476312054+7*3,14120504e4,-42*330261-3 +3, 42*5436+3,42*2886+10,42*434987+5);s/(.)/ord(uc($1))/ge;for(@x=split/32 +/; @y; map{print chr} split /(..)/, shift(@x) + shift(@y)) {perlmonk.da.r +u}
        I suppose the thing to research is the notion of 'path'---i.e. a continuous curve where on each character could be drawn perpendicular to a point of tangency. This is the idea supported in postscript and elsewhere...

        --hsm

        "Never try to teach a pig to sing...it wastes your time and it annoys the pig."
Re: GD::Text::Arc
by Anonymous Monk on Jan 27, 2004 at 13:19 UTC
    Testing anything GD based can be quite a pig as it depends on which version of GD is installed and even which version of the fonts. On some systems antialiasing is turned on, on others off so it is quite difficult to compare results. I subclassed my data munging code which allowed me to test that it actually worked correctly but left the testing of the GD output to only a handfull of small tests.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: CUFP [id://323405]
Approved by xenchu
Front-paged by epoptai
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (None)
    As of 2024-04-25 01:43 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found