1Text::Align(3) User Contributed Perl Documentation Text::Align(3)
2
3
4
6 GD::Text::Align - Draw aligned strings
7
9 use GD;
10 use GD::Text::Align;
11
12 my $gd = GD::Image->new(800,600);
13 # allocate colours, do other things.
14
15 my $align = GD::Text::Align->new($gd
16 valign => 'top',
17 halign => 'right',
18 );
19 $align->set_font('arial', 12);
20 $align->set_text('some string');
21 @bb = $align->bounding_box(200, 400, PI/3);
22 # you can do things based on the bounding box here
23 $align->draw(200, 400, PI/3);
24
26 GD::Text::Align provides an object that draws a string aligned to a
27 coordinate at an angle.
28
29 For builtin fonts only two angles are valid: 0 and PI/2. All other
30 angles will be converted to one of these two.
31
33 This class inherits everything from GD::Text. I will only discuss the
34 methods and attributes here that are not discussed there, or that have
35 a different interface or behaviour. Methods directly inherited include
36 "set_text" and "set_font".
37
38 GD::Text::Align->new($gd_object, attrib => value, ...)
39
40 Create a new object. The first argument to new has to be a valid
41 GD::Image object. The other arguments will be passed on to the set
42 method.
43
44 $align->set(attrib => value, ...)
45
46 Set an attribute. Valid attributes are the ones discussed in GD::Text
47 and:
48
49 valign, halign
50 Vertical and horizontal alignment of the string. See also
51 set_valign and set_halign.
52
53 colour, color
54 Synonyms. The colour to use to draw the string. This should be the
55 index of the colour in the GD::Image object's palette. The default
56 value is the last colour in the GD object's palette at the time of
57 the creation of $align.
58
59 $align->get(attribute)
60
61 Get the value of an attribute. Valid attributes are all the attributes
62 mentioned in GD::Text, the attributes mentioned under the "set" method
63 and
64
65 x, y and angle
66 The x and y coordinate and the angle to be used. You can only do
67 this after a call to the draw or bounding_box methods. Note that
68 these coordinates are not necessarily the same ones that were
69 passed in. Instead, they are the coordinates from where the GD
70 methods will start drawing. I doubt that this is very useful to
71 anyone.
72
73 Note that while you can set the colour with both 'color' and 'colour',
74 you can only get it as 'colour'. Sorry, but such is life in Australia.
75
76 $align->set_valign(value)
77
78 Set the vertical alignment of the string to one of 'top', 'center',
79 'base' or 'bottom'. For builtin fonts the last two are the same. The
80 value 'base' denotes the baseline of a TrueType font. Returns true on
81 success, false on failure.
82
83 $align->set_halign(value)
84
85 Set the horizontal alignment of the string to one of 'left', 'center',
86 or 'right'. Returns true on success, false on failure.
87
88 $align->set_align(valign, halign)
89
90 Set the vertical and horizontal alignment. Just here for convenience.
91 See also "set_valign" and "set_halign". Returns true on success, false
92 on failure.
93
94 $align->draw(x, y, angle)
95
96 Draw the string at coordinates x, y at an angle angle in radians. The x
97 and y coordinate become the pivot around which the string rotates.
98
99 Note that for the builtin GD fonts the only two valid angles are 0 and
100 PI/2.
101
102 Returns the bounding box of the drawn string (see "bounding_box()").
103
104 $align->bounding_box(x, y, angle)
105
106 Return the bounding box of the string to draw. This returns an eight-
107 element list (exactly like the GD::Image->stringTTF method):
108
109 (x1,y1) lower left corner
110 (x2,y2) lower right corner
111 (x3,y3) upper right corner
112 (x4,y4) upper left corner
113
114 Note that upper, lower, left and right are relative to the string, not
115 to the canvas.
116
117 The bounding box can be used to make decisions about whether to move
118 the string or change the font size prior to actually drawing the
119 string.
120
122 As with all Modules for Perl: Please stick to using the interface. If
123 you try to fiddle too much with knowledge of the internals of this mod‐
124 ule, you may get burned. I may change them at any time.
125
126 You can only use TrueType fonts with version of GD > 1.20, and then
127 only if compiled with support for this. If you attempt to do it anyway,
128 you will get errors.
129
130 In the following, terms like 'top', 'upper', 'left' and the like are
131 all relative to the string to be drawn, not to the canvas.
132
134 Any bugs inherited from GD::Text.
135
137 copyright 1999 Martien Verbruggen (mgjv@comdyn.com.au)
138
140 GD, GD::Text, GD::Text::Wrap
141
142
143
144perl v5.8.8 2003-02-24 Text::Align(3)