fixed url-generator
[sdlgit/SDL-Site.git] / pages / SDL-TTF.html-inc
1 <div class="pod">
2 <!-- INDEX START -->
3 <h3 id="TOP">Index</h3>
4
5 <ul><li><a href="#NAME">NAME</a></li>
6 <li><a href="#CATEGORY">CATEGORY</a></li>
7 <li><a href="#METHODS">METHODS</a>
8 <ul><li><a href="#General_methods">General methods</a>
9 <ul><li><a href="#linked_version">linked_version</a></li>
10 <li><a href="#compile_time_version">compile_time_version</a></li>
11 <li><a href="#init">init</a></li>
12 <li><a href="#was_init">was_init</a></li>
13 <li><a href="#quit">quit</a></li>
14 </ul>
15 </li>
16 <li><a href="#Management_functions">Management functions</a>
17 <ul><li><a href="#open_font">open_font</a></li>
18 <li><a href="#open_font_index">open_font_index</a></li>
19 <li><a href="#open_font_RW">open_font_RW</a></li>
20 <li><a href="#open_font_index_RW">open_font_index_RW</a></li>
21 </ul>
22 </li>
23 <li><a href="#Attributes">Attributes</a>
24 <ul><li><a href="#Global_attributes">Global attributes</a>
25 <ul><li><a href="#byte_swapped_unicode">byte_swapped_unicode</a></li>
26 </ul>
27 </li>
28 <li><a href="#Font_style">Font style</a>
29 <ul><li><a href="#get_font_style">get_font_style</a></li>
30 <li><a href="#set_font_style">set_font_style</a></li>
31 </ul>
32 </li>
33 <li><a href="#Font_settings">Font settings</a>
34 <ul><li><a href="#get_font_hinting">get_font_hinting</a></li>
35 <li><a href="#set_font_hinting">set_font_hinting</a></li>
36 <li><a href="#get_font_kerning">get_font_kerning</a></li>
37 <li><a href="#set_font_kerning">set_font_kerning</a></li>
38 </ul>
39 </li>
40 <li><a href="#Font_metrics">Font metrics</a>
41 <ul><li><a href="#font_height">font_height</a></li>
42 <li><a href="#font_ascent">font_ascent</a></li>
43 <li><a href="#font_descent">font_descent</a></li>
44 <li><a href="#font_line_skip">font_line_skip</a></li>
45 </ul>
46 </li>
47 <li><a href="#Face_attributes">Face attributes</a>
48 <ul><li><a href="#font_faces">font_faces</a></li>
49 <li><a href="#font_face_is_fixed_width">font_face_is_fixed_width</a></li>
50 <li><a href="#font_face_family_name">font_face_family_name</a></li>
51 <li><a href="#font_face_style_name">font_face_style_name</a></li>
52 </ul>
53 </li>
54 <li><a href="#Glyphs">Glyphs</a>
55 <ul><li><a href="#glyph_is_provided">glyph_is_provided</a></li>
56 <li><a href="#glyph_metrics">glyph_metrics</a></li>
57 </ul>
58 </li>
59 <li><a href="#Text_metrics">Text metrics</a>
60 <ul><li><a href="#size_text">size_text</a></li>
61 <li><a href="#size_utf8">size_utf8</a></li>
62 <li><a href="#size_unicode">size_unicode</a></li>
63 </ul>
64 </li>
65 </ul>
66 </li>
67 <li><a href="#Font_Rendering">Font Rendering</a>
68 <ul><li><a href="#render_glyph_solid">render_glyph_solid</a></li>
69 <li><a href="#render_glyph_shaded">render_glyph_shaded</a></li>
70 <li><a href="#render_glyph_blended">render_glyph_blended</a></li>
71 <li><a href="#render_text_solid">render_text_solid</a></li>
72 <li><a href="#render_text_shaded">render_text_shaded</a></li>
73 <li><a href="#render_text_blended">render_text_blended</a></li>
74 <li><a href="#render_utf8_solid">render_utf8_solid</a></li>
75 <li><a href="#render_utf8_shaded">render_utf8_shaded</a></li>
76 <li><a href="#render_utf8_blended">render_utf8_blended</a></li>
77 <li><a href="#render_unicode_solid">render_unicode_solid</a></li>
78 <li><a href="#render_unicode_shaded">render_unicode_shaded</a></li>
79 <li><a href="#render_unicode_blended">render_unicode_blended</a></li>
80 </ul>
81 </li>
82 </ul>
83 </li>
84 <li><a href="#AUTHOR">AUTHOR</a></li>
85 <li><a href="#SEE_ALSO">SEE ALSO</a>
86 </li>
87 </ul><hr />
88 <!-- INDEX END -->
89
90 <h1 id="NAME">NAME</h1><p><a href="#TOP" class="toplink">Top</a></p>
91 <div id="NAME_CONTENT">
92 <p>SDL::TTF - True Type Font functions (libfreetype)</p>
93
94 </div>
95 <h1 id="CATEGORY">CATEGORY</h1><p><a href="#TOP" class="toplink">Top</a></p>
96 <div id="CATEGORY_CONTENT">
97 <p>TODO, TTF</p>
98
99 </div>
100 <h1 id="METHODS">METHODS</h1><p><a href="#TOP" class="toplink">Top</a></p>
101 <div id="METHODS_CONTENT">
102
103 </div>
104 <h2 id="General_methods">General methods</h2>
105 <div id="General_methods_CONTENT">
106
107 </div>
108 <h3 id="linked_version">linked_version</h3>
109 <div id="linked_version_CONTENT">
110 <pre> my $version = SDL::TTF::linked_version();
111
112 </pre>
113 <p>This gives you the SDL::Version object which SDL_ttf lib is used on the system.
114 No prior initialization needs to be done before these function is called. </p>
115 <p>Example:</p>
116 <pre> use SDL::TTF;
117  use SDL::Version;
118
119  my $version = SDL::TTF::linked_version();
120
121  printf(&quot;got version: %d.%d.%d\n&quot;, $version-&gt;major, $version-&gt;minor, $version-&gt;patch);
122
123 </pre>
124
125 </div>
126 <h3 id="compile_time_version">compile_time_version</h3>
127 <div id="compile_time_version_CONTENT">
128 <pre> my $version = SDL::TTF::compile_time_version();
129
130 </pre>
131 <p>This gives you the SDL::Version object which SDL_ttf was present at compile time.</p>
132
133 </div>
134 <h3 id="init">init</h3>
135 <div id="init_CONTENT">
136 <pre> my $success = SDL::TTF::init();
137
138 </pre>
139 <p>Initialize the truetype font API.
140 This must be called before using other functions in this library, except <a href="/SDL-TTF.html#was_init">SDL::TTF::was_init</a> and <a href="/SDL-TTF.html#linked_version">SDL::TTF::linked_version</a>.
141 SDL does not have to be initialized before this call.</p>
142 <p>Returns: <code>0</code> on success, <code>-1</code> on any error.</p>
143
144 </div>
145 <h3 id="was_init">was_init</h3>
146 <div id="was_init_CONTENT">
147 <pre> my $was_init = SDL::TTF::was_init();
148
149 </pre>
150 <p>Query the initilization status of the truetype font API.
151 You may, of course, use this before <a href="/SDL-TTF.html#init">SDL::TTF::init</a> to avoid initializing twice in a row. Or use this to determine if you need to call 
152 <a href="/SDL-TTF.html#quit">SDL::TTF::quit</a>.</p>
153
154 </div>
155 <h3 id="quit">quit</h3>
156 <div id="quit_CONTENT">
157 <pre> SDL::TTF::quit();
158
159 </pre>
160 <p>Shutdown and cleanup the truetype font API.
161 After calling this the SDL::TTF functions should not be used, excepting <a href="/SDL-TTF.html#was_init">SDL::TTF::was_init</a>. You may, of course, use <a href="/SDL-TTF.html#init">SDL::TTF::init</a> to 
162 use the functionality again</p>
163
164 </div>
165 <h2 id="Management_functions">Management functions</h2>
166 <div id="Management_functions_CONTENT">
167
168 </div>
169 <h3 id="open_font">open_font</h3>
170 <div id="open_font_CONTENT">
171 <pre> my $font = SDL::TTF::open_font($font_file, $point_size);
172
173 </pre>
174 <p>Load file for use as a font, at the given size. This is actually <code>SDL::TTF::open_font_index(..., ..., $index = 0)</code>. This can load TTF and FON files.</p>
175 <p>Returns: a <a href="SDL-TTF-Font.html">SDL::TTF::Font</a> object. <code>undef</code> is returned on errors.</p>
176 <p>Example:</p>
177 <pre> use SDL::TTF;
178  use SDL::TTF::Font;
179
180  my $font = SDL::TTF::open_font('arial.ttf', '24);
181
182 </pre>
183
184 </div>
185 <h3 id="open_font_index">open_font_index</h3>
186 <div id="open_font_index_CONTENT">
187 <pre> my $font = SDL::TTF::open_font($font_file, $point_size, $face_index);
188
189 </pre>
190 <p>This is the same as <a href="/SDL-TTF.html#open_font">SDL::TTF::open_font</a>, except you can specify the face index of a font file containing multiple faces. 
191 This can load TTF and FON files. </p>
192
193 </div>
194 <h3 id="open_font_RW">open_font_RW</h3>
195 <div id="open_font_RW_CONTENT">
196 <pre> my $font = SDL::TTF::open_font_RW($rwops_object, $free, $point_size);
197
198 </pre>
199 <p>This is the same as <a href="/SDL-TTF.html#open_font">SDL::TTF::open_font</a>, except you can pass an <a href="SDL-RWOps.html">SDL::RWOps</a>-object. If you pass true as <code>$free</code>, the <a href="SDL-RWOps.html">SDL::RWOps</a>-object
200 will be freed by SDL_ttf library. Don't do this, perl will free this object for you.</p>
201 <p>Example:</p>
202 <pre> my $font = SDL::TTF::open_font_RW(SDL::RWOps-&gt;new_file($font_file, 'r'), 0, 24);
203
204 </pre>
205
206 </div>
207 <h3 id="open_font_index_RW">open_font_index_RW</h3>
208 <div id="open_font_index_RW_CONTENT">
209 <pre> my $font = SDL::TTF::open_font_index_RW($rwops_object, $free, $point_size, $face_index);
210
211 </pre>
212 <p>This is the same as <a href="/SDL-TTF.html#open_font_index">SDL::TTF::open_font_index</a>, except you can pass an <a href="SDL-RWOps.html">SDL::RWOps</a>-object. If you pass true as <code>$free</code>, the 
213 <a href="SDL-RWOps.html">SDL::RWOps</a>-object will be freed by SDL_ttf library. Don't do this, perl will free this object for you.</p>
214
215 </div>
216 <h2 id="Attributes">Attributes</h2>
217 <div id="Attributes_CONTENT">
218
219 </div>
220 <h3 id="Global_attributes">Global attributes</h3>
221 <div id="Global_attributes_CONTENT">
222
223 </div>
224 <h4 id="byte_swapped_unicode">byte_swapped_unicode</h4>
225 <div id="byte_swapped_unicode_CONTENT">
226 <pre> SDL::TTF::byte_swapped_unicode( $bool );
227
228 </pre>
229 <p>This function tells SDL_ttf whether UNICODE (2 bytes per character) text is generally byteswapped. A <code>UNICODE_BOM_NATIVE</code> or 
230 <code>UNICODE_BOM_SWAPPED</code> character in a string will temporarily override this setting for the remainder of that string, however this setting 
231 will be restored for the next one. The default mode is non-swapped, native endianness of the CPU.</p>
232
233 </div>
234 <h3 id="Font_style">Font style</h3>
235 <div id="Font_style_CONTENT">
236
237 </div>
238 <h4 id="get_font_style">get_font_style</h4>
239 <div id="get_font_style_CONTENT">
240 <pre> SDL::TTF::get_font_style($font);
241
242 </pre>
243 <p>Returns: The style as a bitmask composed of the following masks:</p>
244 <ul>
245                 <li>TTF_STYLE_NORMAL    </li>
246                 <li>TTF_STYLE_BOLD      </li>
247                 <li>TTF_STYLE_ITALIC    </li>
248                 <li>TTF_STYLE_UNDERLINE </li>
249                 <li>TTF_STYLE_STRIKETHROUGH (since SDL_ttf 2.0.10)</li>
250 </ul>
251
252 <p>Example:</p>
253 <pre> my $style = SDL::TTF::get_font_style($font);
254
255  print(&quot;normal\n&quot;)        if $style == TTF_STYLE_NORMAL;
256  print(&quot;bold\n&quot;)          if $style  &amp; TTF_STYLE_BOLD;
257  print(&quot;italic\n&quot;)        if $style  &amp; TTF_STYLE_ITALIC;
258  print(&quot;underline\n&quot;)     if $style  &amp; TTF_STYLE_UNDERLINE;
259  print(&quot;strikethrough\n&quot;) if $style  &amp; TTF_STYLE_STRIKETHROUGH;
260
261 </pre>
262
263 </div>
264 <h4 id="set_font_style">set_font_style</h4>
265 <div id="set_font_style_CONTENT">
266 <pre> SDL::TTF::set_font_style($font, $style);
267
268 </pre>
269 <p>Set the rendering style of the loaded font.</p>
270 <p><strong>Note</strong>: <code>TTF_STYLE_UNDERLINE</code> may cause surfaces created by <code>SDL::TTF::render_glyph_*</code> functions to be extended vertically, downward only, 
271 to encompass the underline if the original glyph metrics didn't allow for the underline to be drawn below. This does not change the math used 
272 to place a glyph using glyph metrics.
273 On the other hand <code>TTF_STYLE_STRIKETHROUGH</code> doesn't extend the glyph, since this would invalidate the metrics used to position the glyph when 
274 blitting, because they would likely be extended vertically upward. There is perhaps a workaround, but it would require programs to be smarter 
275 about glyph blitting math than they are currently designed for.
276 Still, sometimes the underline or strikethrough may be outside of the generated surface, and thus not visible when blitted to the screen. In 
277 this case, you should probably turn off these styles and draw your own strikethroughs and underlines. </p>
278
279 </div>
280 <h3 id="Font_settings">Font settings</h3>
281 <div id="Font_settings_CONTENT">
282
283 </div>
284 <h4 id="get_font_hinting">get_font_hinting</h4>
285 <div id="get_font_hinting_CONTENT">
286 <pre> my $hinting = SDL::TTF::get_font_hinting($font);
287
288 </pre>
289 <p>Get the current hinting setting of the loaded font.</p>
290 <p><strong>Note</strong>: at least SDL_ttf 2.0.10 needed</p>
291 <p>Returns the hinting type matching one of the following defined values:</p>
292 <ul>
293                 <li>TTF_HINTING_NORMAL  </li>
294                 <li>TTF_HINTING_LIGHT   </li>
295                 <li>TTF_HINTING_MONO    </li>
296                 <li>TTF_HINTING_NONE</li>
297 </ul>
298
299
300 </div>
301 <h4 id="set_font_hinting">set_font_hinting</h4>
302 <div id="set_font_hinting_CONTENT">
303 <pre> SDL::TTF::set_font_hinting($font, $hinting);
304
305 </pre>
306 <p>Set the hinting of the loaded font. You should experiment with this setting if you know which font you are using beforehand, especially when 
307 using smaller sized fonts. If the user is selecting a font, you may wish to let them select the hinting mode for that font as well.</p>
308 <p><strong>Note</strong>: at least SDL_ttf 2.0.10 needed</p>
309 <p>Example:</p>
310 <pre> SDL::TTF::set_font_hinting($font, TTF_HINTING_LIGHT);
311
312 </pre>
313
314 </div>
315 <h4 id="get_font_kerning">get_font_kerning</h4>
316 <div id="get_font_kerning_CONTENT">
317 <pre> my $kerning_enabled = SDL::TTF::get_font_kerning($font);
318
319 </pre>
320 <p>Get the current kerning setting of the loaded font.</p>
321 <p>Returns: <code>0</code>(zero) if kerning is disabled. A non-zero value is returned when enabled. The default for a newly loaded font is enabled(<code>1</code>). </p>
322 <p><strong>Note</strong>: at least SDL_ttf 2.0.10 needed</p>
323
324 </div>
325 <h4 id="set_font_kerning">set_font_kerning</h4>
326 <div id="set_font_kerning_CONTENT">
327 <pre> SDL::TTF::set_font_kerning($font, $kerning_enabled);
328
329 </pre>
330 <p>Set whether to use kerning when rendering the loaded font. This has no effect on individual glyphs, but rather when rendering whole strings of 
331 characters, at least a word at a time. Perhaps the only time to disable this is when kerning is not working for a specific font, resulting in 
332 overlapping glyphs or abnormal spacing within words.</p>
333 <p>Pass <code>0</code> to disable kerning, 1 to enable.</p>
334 <p><strong>Note</strong>: at least SDL_ttf 2.0.10 needed</p>
335
336 </div>
337 <h3 id="Font_metrics">Font metrics</h3>
338 <div id="Font_metrics_CONTENT">
339
340 </div>
341 <h4 id="font_height">font_height</h4>
342 <div id="font_height_CONTENT">
343 <pre> my $font_height = SDL::TTF::font_height($font);
344
345 </pre>
346
347 </div>
348 <h4 id="font_ascent">font_ascent</h4>
349 <div id="font_ascent_CONTENT">
350 <pre> my $font_ascent = SDL::TTF::font_ascent($font);
351  like( $font_ascent,                                       '/^[-]?\d+$/',       &quot;[font_ascent] offset from the baseline to the top of the font is $font_ascent&quot; );
352
353 </pre>
354
355 </div>
356 <h4 id="font_descent">font_descent</h4>
357 <div id="font_descent_CONTENT">
358 <pre> my $font_descent = SDL::TTF::font_descent($font);
359  like( $font_descent,                                      '/^[-]?\d+$/',       &quot;[font_descent] offset from the baseline to the bottom of the font is $font_descent&quot; );
360
361 </pre>
362
363 </div>
364 <h4 id="font_line_skip">font_line_skip</h4>
365 <div id="font_line_skip_CONTENT">
366 <pre> my $font_line_skip = SDL::TTF::font_line_skip($font);
367  like( $font_line_skip,                                    '/^[-]?\d+$/',       &quot;[font_line_skip] recommended spacing between lines of text is $font_line_skip&quot; );
368
369 </pre>
370
371 </div>
372 <h3 id="Face_attributes">Face attributes</h3>
373 <div id="Face_attributes_CONTENT">
374
375 </div>
376 <h4 id="font_faces">font_faces</h4>
377 <div id="font_faces_CONTENT">
378 <p>my $font_faces = SDL::TTF::font_faces($font);
379 ok( $font_faces,                                                               &quot;[font_faces] font has $font_faces faces&quot; );</p>
380
381 </div>
382 <h4 id="font_face_is_fixed_width">font_face_is_fixed_width</h4>
383 <div id="font_face_is_fixed_width_CONTENT">
384 <p>my $font_face_is_fixed_width = SDL::TTF::font_face_is_fixed_width($font);
385 like( $font_face_is_fixed_width,                          '/^[01]$/',          &quot;[font_face_is_fixed_width] is $font_face_is_fixed_width&quot; );</p>
386
387 </div>
388 <h4 id="font_face_family_name">font_face_family_name</h4>
389 <div id="font_face_family_name_CONTENT">
390 <p>my $font_face_family_name = SDL::TTF::font_face_family_name($font);
391 ok( $font_face_family_name,                                                    &quot;[font_face_family_name] is $font_face_family_name&quot; );</p>
392
393 </div>
394 <h4 id="font_face_style_name">font_face_style_name</h4>
395 <div id="font_face_style_name_CONTENT">
396 <p>my $font_face_style_name = SDL::TTF::font_face_style_name($font);
397 ok( $font_face_style_name,                                                     &quot;[font_face_style_name] is $font_face_style_name&quot; );</p>
398
399 </div>
400 <h3 id="Glyphs">Glyphs</h3>
401 <div id="Glyphs_CONTENT">
402
403 </div>
404 <h4 id="glyph_is_provided">glyph_is_provided</h4>
405 <div id="glyph_is_provided_CONTENT">
406
407 </div>
408 <h4 id="glyph_metrics">glyph_metrics</h4>
409 <div id="glyph_metrics_CONTENT">
410 <pre> my @glyph_metrics = @{ SDL::TTF::glyph_metrics($font, 'M') };
411 is( scalar @glyph_metrics,                                5,                   &quot;[glyph_metrics] (minx, maxx, miny, maxy, advance) = (&quot; . join(', ', @glyph_metrics) . &quot;)&quot; );
412
413 </pre>
414
415 </div>
416 <h3 id="Text_metrics">Text metrics</h3>
417 <div id="Text_metrics_CONTENT">
418
419 </div>
420 <h4 id="size_text">size_text</h4>
421 <div id="size_text_CONTENT">
422 <pre> my ($width, $height) = @{ SDL::TTF::size_text($font, 'Hallo World!') };
423
424 </pre>
425
426 </div>
427 <h4 id="size_utf8">size_utf8</h4>
428 <div id="size_utf8_CONTENT">
429 <pre> my ($width, $height) = @{ SDL::TTF::size_utf8($font, 'Hallo World!') };
430
431 </pre>
432
433 </div>
434 <h4 id="size_unicode">size_unicode</h4>
435 <div id="size_unicode_CONTENT">
436 <pre> my ($width, $height) = @{ SDL::TTF::size_unicode($font, 'Hallo World!') };
437
438 </pre>
439
440 </div>
441 <h2 id="Font_Rendering">Font Rendering</h2>
442 <div id="Font_Rendering_CONTENT">
443
444 </div>
445 <h3 id="render_glyph_solid">render_glyph_solid</h3>
446 <div id="render_glyph_solid_CONTENT">
447
448 </div>
449 <h3 id="render_glyph_shaded">render_glyph_shaded</h3>
450 <div id="render_glyph_shaded_CONTENT">
451
452 </div>
453 <h3 id="render_glyph_blended">render_glyph_blended</h3>
454 <div id="render_glyph_blended_CONTENT">
455
456 </div>
457 <h3 id="render_text_solid">render_text_solid</h3>
458 <div id="render_text_solid_CONTENT">
459 <p><strong>Note</strong>: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=374062</p>
460
461 </div>
462 <h3 id="render_text_shaded">render_text_shaded</h3>
463 <div id="render_text_shaded_CONTENT">
464
465 </div>
466 <h3 id="render_text_blended">render_text_blended</h3>
467 <div id="render_text_blended_CONTENT">
468
469 </div>
470 <h3 id="render_utf8_solid">render_utf8_solid</h3>
471 <div id="render_utf8_solid_CONTENT">
472
473 </div>
474 <h3 id="render_utf8_shaded">render_utf8_shaded</h3>
475 <div id="render_utf8_shaded_CONTENT">
476
477 </div>
478 <h3 id="render_utf8_blended">render_utf8_blended</h3>
479 <div id="render_utf8_blended_CONTENT">
480
481 </div>
482 <h3 id="render_unicode_solid">render_unicode_solid</h3>
483 <div id="render_unicode_solid_CONTENT">
484
485 </div>
486 <h3 id="render_unicode_shaded">render_unicode_shaded</h3>
487 <div id="render_unicode_shaded_CONTENT">
488
489 </div>
490 <h3 id="render_unicode_blended">render_unicode_blended</h3>
491 <div id="render_unicode_blended_CONTENT">
492
493 </div>
494 <h1 id="AUTHOR">AUTHOR</h1><p><a href="#TOP" class="toplink">Top</a></p>
495 <div id="AUTHOR_CONTENT">
496 <p>Tobias Leich [FROGGS]</p>
497
498 </div>
499 <h1 id="SEE_ALSO">SEE ALSO</h1><p><a href="#TOP" class="toplink">Top</a></p>
500 <div id="SEE_ALSO_CONTENT">
501 <p><a href="SDL-TTF-Font.html">SDL::TTF::Font</a>, <a href="http://search.cpan.org/perldoc?Unicode::String">Unicode::String</a>, <a href="SDL-Video.html">SDL::Video</a>, <a href="SDL-Surface.html">SDL::Surface</a></p>
502
503 </div>
504 </div>