update
[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="#CONSTANTS">CONSTANTS</a></li>
8 <li><a href="#METHODS">METHODS</a>
9 <ul><li><a href="#General_methods">General methods</a>
10 <ul><li><a href="#linked_version">linked_version</a></li>
11 <li><a href="#compile_time_version">compile_time_version</a></li>
12 <li><a href="#init">init</a></li>
13 <li><a href="#was_init">was_init</a></li>
14 <li><a href="#quit">quit</a></li>
15 </ul>
16 </li>
17 <li><a href="#Management_functions">Management functions</a>
18 <ul><li><a href="#open_font">open_font</a></li>
19 <li><a href="#open_font_index">open_font_index</a></li>
20 <li><a href="#open_font_RW">open_font_RW</a></li>
21 <li><a href="#open_font_index_RW">open_font_index_RW</a></li>
22 </ul>
23 </li>
24 <li><a href="#Attributes">Attributes</a>
25 <ul><li><a href="#Global_attributes">Global attributes</a>
26 <ul><li><a href="#byte_swapped_unicode">byte_swapped_unicode</a></li>
27 </ul>
28 </li>
29 <li><a href="#Font_style">Font style</a>
30 <ul><li><a href="#get_font_style">get_font_style</a></li>
31 <li><a href="#set_font_style">set_font_style</a></li>
32 <li><a href="#get_font_outline">get_font_outline</a></li>
33 <li><a href="#set_font_outline">set_font_outline</a></li>
34 </ul>
35 </li>
36 <li><a href="#Font_settings">Font settings</a>
37 <ul><li><a href="#get_font_hinting">get_font_hinting</a></li>
38 <li><a href="#set_font_hinting">set_font_hinting</a></li>
39 <li><a href="#get_font_kerning">get_font_kerning</a></li>
40 <li><a href="#set_font_kerning">set_font_kerning</a></li>
41 </ul>
42 </li>
43 <li><a href="#Font_metrics">Font metrics</a>
44 <ul><li><a href="#font_height">font_height</a></li>
45 <li><a href="#font_ascent">font_ascent</a></li>
46 <li><a href="#font_descent">font_descent</a></li>
47 <li><a href="#font_line_skip">font_line_skip</a></li>
48 </ul>
49 </li>
50 <li><a href="#Face_attributes">Face attributes</a>
51 <ul><li><a href="#font_faces">font_faces</a></li>
52 <li><a href="#font_face_is_fixed_width">font_face_is_fixed_width</a></li>
53 <li><a href="#font_face_family_name">font_face_family_name</a></li>
54 <li><a href="#font_face_style_name">font_face_style_name</a></li>
55 </ul>
56 </li>
57 <li><a href="#Glyphs">Glyphs</a>
58 <ul><li><a href="#glyph_is_provided">glyph_is_provided</a></li>
59 <li><a href="#glyph_metrics">glyph_metrics</a></li>
60 </ul>
61 </li>
62 <li><a href="#Text_metrics">Text metrics</a>
63 <ul><li><a href="#size_text">size_text</a></li>
64 <li><a href="#size_utf8">size_utf8</a></li>
65 <li><a href="#size_unicode">size_unicode</a></li>
66 </ul>
67 </li>
68 </ul>
69 </li>
70 <li><a href="#Font_Rendering">Font Rendering</a>
71 <ul><li><a href="#Solid">Solid</a>
72 <ul><li><a href="#render_glyph_solid">render_glyph_solid</a></li>
73 <li><a href="#render_text_solid">render_text_solid</a></li>
74 <li><a href="#render_utf8_solid">render_utf8_solid</a></li>
75 <li><a href="#render_unicode_solid">render_unicode_solid</a></li>
76 </ul>
77 </li>
78 <li><a href="#Shaded">Shaded</a>
79 <ul><li><a href="#render_glyph_shaded">render_glyph_shaded</a></li>
80 <li><a href="#render_text_shaded">render_text_shaded</a></li>
81 <li><a href="#render_utf8_shaded">render_utf8_shaded</a></li>
82 <li><a href="#render_unicode_shaded">render_unicode_shaded</a></li>
83 </ul>
84 </li>
85 <li><a href="#Blended">Blended</a>
86 <ul><li><a href="#render_glyph_blended">render_glyph_blended</a></li>
87 <li><a href="#render_text_blended">render_text_blended</a></li>
88 <li><a href="#render_utf8_blended">render_utf8_blended</a></li>
89 <li><a href="#render_unicode_blended">render_unicode_blended</a></li>
90 </ul>
91 </li>
92 </ul>
93 </li>
94 </ul>
95 </li>
96 <li><a href="#AUTHOR">AUTHOR</a></li>
97 <li><a href="#SEE_ALSO">SEE ALSO</a>
98 </li>
99 </ul><hr />
100 <!-- INDEX END -->
101
102 <h1 id="NAME">NAME</h1><p><a href="#TOP" class="toplink">Top</a></p>
103 <div id="NAME_CONTENT">
104 <p>SDL::TTF - True Type Font functions (libfreetype)</p>
105
106 </div>
107 <h1 id="CATEGORY">CATEGORY</h1><p><a href="#TOP" class="toplink">Top</a></p>
108 <div id="CATEGORY_CONTENT">
109 <p>TTF</p>
110
111 </div>
112 <h1 id="CONSTANTS">CONSTANTS</h1><p><a href="#TOP" class="toplink">Top</a></p>
113 <div id="CONSTANTS_CONTENT">
114 <p>The constants are exported by default. You can avoid this by doing:</p>
115 <pre> use SDL::TTF ();
116
117
118
119
120 </pre>
121 <p>and access them directly:</p>
122 <pre> SDL::TTF::TTF_HINTING_NORMAL;
123
124 </pre>
125 <p>Available constants for &quot;hinting&quot;:</p>
126 <ul>
127                 <li>TTF_HINTING_NORMAL  </li>
128                 <li>TTF_HINTING_LIGHT   </li>
129                 <li>TTF_HINTING_MONO    </li>
130                 <li>TTF_HINTING_NONE</li>
131 </ul>
132
133 <p>Available constants for &quot;style&quot;:</p>
134 <ul>
135                 <li>TTF_STYLE_NORMAL    </li>
136                 <li>TTF_STYLE_BOLD      </li>
137                 <li>TTF_STYLE_ITALIC    </li>
138                 <li>TTF_STYLE_UNDERLINE </li>
139                 <li>TTF_STYLE_STRIKETHROUGH</li>
140 </ul>
141
142
143 </div>
144 <h1 id="METHODS">METHODS</h1><p><a href="#TOP" class="toplink">Top</a></p>
145 <div id="METHODS_CONTENT">
146
147 </div>
148 <h2 id="General_methods">General methods</h2>
149 <div id="General_methods_CONTENT">
150
151 </div>
152 <h3 id="linked_version">linked_version</h3>
153 <div id="linked_version_CONTENT">
154 <pre> my $version = SDL::TTF::linked_version();
155
156 </pre>
157 <p>This gives you the SDL::Version object which SDL_ttf lib is used on the system.
158 No prior initialization needs to be done before these function is called. </p>
159 <p>Example:</p>
160 <pre> use SDL::TTF;
161  use SDL::Version;
162
163  my $version = SDL::TTF::linked_version();
164
165  printf(&quot;got version: %d.%d.%d\n&quot;, $version-&gt;major, $version-&gt;minor, $version-&gt;patch);
166
167 </pre>
168
169 </div>
170 <h3 id="compile_time_version">compile_time_version</h3>
171 <div id="compile_time_version_CONTENT">
172 <pre> my $version = SDL::TTF::compile_time_version();
173
174 </pre>
175 <p>This gives you the SDL::Version object which SDL_ttf was present at compile time.</p>
176
177 </div>
178 <h3 id="init">init</h3>
179 <div id="init_CONTENT">
180 <pre> my $success = SDL::TTF::init();
181
182 </pre>
183 <p>Initialize the truetype font API.
184 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>.
185 SDL does not have to be initialized before this call.</p>
186 <p>Returns: <code>0</code> on success, <code>-1</code> on any error.</p>
187
188 </div>
189 <h3 id="was_init">was_init</h3>
190 <div id="was_init_CONTENT">
191 <pre> my $was_init = SDL::TTF::was_init();
192
193 </pre>
194 <p>Query the initilization status of the truetype font API.
195 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 
196 <a href="/SDL-TTF.html#quit">SDL::TTF::quit</a>.</p>
197
198 </div>
199 <h3 id="quit">quit</h3>
200 <div id="quit_CONTENT">
201 <pre> SDL::TTF::quit();
202
203 </pre>
204 <p>Shutdown and cleanup the truetype font API.
205 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 
206 use the functionality again</p>
207
208 </div>
209 <h2 id="Management_functions">Management functions</h2>
210 <div id="Management_functions_CONTENT">
211
212 </div>
213 <h3 id="open_font">open_font</h3>
214 <div id="open_font_CONTENT">
215 <pre> my $font = SDL::TTF::open_font($font_file, $point_size);
216
217 </pre>
218 <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>
219 <p>Returns: a <a href="SDL-TTF-Font.html">SDL::TTF::Font</a> object. <code>undef</code> is returned on errors.</p>
220 <p>Example:</p>
221 <pre> use SDL::TTF;
222  use SDL::TTF::Font;
223
224  my $font = SDL::TTF::open_font('arial.ttf', 24);
225
226 </pre>
227
228 </div>
229 <h3 id="open_font_index">open_font_index</h3>
230 <div id="open_font_index_CONTENT">
231 <pre> my $font = SDL::TTF::open_font($font_file, $point_size, $face_index);
232
233 </pre>
234 <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. 
235 This can load TTF and FON files. </p>
236
237 </div>
238 <h3 id="open_font_RW">open_font_RW</h3>
239 <div id="open_font_RW_CONTENT">
240 <pre> my $font = SDL::TTF::open_font_RW($rwops_object, $free, $point_size);
241
242 </pre>
243 <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
244 will be freed by SDL_ttf library. Don't do this, perl will free this object for you.</p>
245 <p>Example:</p>
246 <pre> my $font = SDL::TTF::open_font_RW(SDL::RWOps-&gt;new_file($font_file, 'r'), 0, 24);
247
248 </pre>
249
250 </div>
251 <h3 id="open_font_index_RW">open_font_index_RW</h3>
252 <div id="open_font_index_RW_CONTENT">
253 <pre> my $font = SDL::TTF::open_font_index_RW($rwops_object, $free, $point_size, $face_index);
254
255 </pre>
256 <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 
257 <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>
258
259 </div>
260 <h2 id="Attributes">Attributes</h2>
261 <div id="Attributes_CONTENT">
262
263 </div>
264 <h3 id="Global_attributes">Global attributes</h3>
265 <div id="Global_attributes_CONTENT">
266
267 </div>
268 <h4 id="byte_swapped_unicode">byte_swapped_unicode</h4>
269 <div id="byte_swapped_unicode_CONTENT">
270 <pre> SDL::TTF::byte_swapped_unicode( $bool );
271
272 </pre>
273 <p>This function tells SDL_ttf whether UNICODE (2 bytes per character) text is generally byteswapped. A <code>UNICODE_BOM_NATIVE</code> or 
274 <code>UNICODE_BOM_SWAPPED</code> character in a string will temporarily override this setting for the remainder of that string, however this setting 
275 will be restored for the next one. The default mode is non-swapped, native endianness of the CPU.</p>
276
277 </div>
278 <h3 id="Font_style">Font style</h3>
279 <div id="Font_style_CONTENT">
280
281 </div>
282 <h4 id="get_font_style">get_font_style</h4>
283 <div id="get_font_style_CONTENT">
284 <pre> SDL::TTF::get_font_style($font);
285
286 </pre>
287 <p>Returns: The style as a bitmask composed of the following masks:</p>
288 <ul>
289                 <li>TTF_STYLE_NORMAL    </li>
290                 <li>TTF_STYLE_BOLD      </li>
291                 <li>TTF_STYLE_ITALIC    </li>
292                 <li>TTF_STYLE_UNDERLINE </li>
293                 <li>TTF_STYLE_STRIKETHROUGH (since SDL_ttf 2.0.10)</li>
294 </ul>
295
296 <p>Example:</p>
297 <pre> my $style = SDL::TTF::get_font_style($font);
298
299  print(&quot;normal\n&quot;)        if $style == TTF_STYLE_NORMAL;
300  print(&quot;bold\n&quot;)          if $style  &amp; TTF_STYLE_BOLD;
301  print(&quot;italic\n&quot;)        if $style  &amp; TTF_STYLE_ITALIC;
302  print(&quot;underline\n&quot;)     if $style  &amp; TTF_STYLE_UNDERLINE;
303  print(&quot;strikethrough\n&quot;) if $style  &amp; TTF_STYLE_STRIKETHROUGH;
304
305 </pre>
306
307 </div>
308 <h4 id="set_font_style">set_font_style</h4>
309 <div id="set_font_style_CONTENT">
310 <pre> SDL::TTF::set_font_style($font, $style);
311
312 </pre>
313 <p>Set the rendering style of the loaded font.</p>
314 <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, 
315 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 
316 to place a glyph using glyph metrics.
317 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 
318 blitting, because they would likely be extended vertically upward. There is perhaps a workaround, but it would require programs to be smarter 
319 about glyph blitting math than they are currently designed for.
320 Still, sometimes the underline or strikethrough may be outside of the generated surface, and thus not visible when blitted to the screen. In 
321 this case, you should probably turn off these styles and draw your own strikethroughs and underlines. </p>
322
323 </div>
324 <h4 id="get_font_outline">get_font_outline</h4>
325 <div id="get_font_outline_CONTENT">
326 <pre> my $outline = SDL::TTF::get_font_outline($font);
327
328 </pre>
329 <p>Get the current outline width of the font, in pixels.</p>
330 <p><strong>Note</strong>: at least SDL_ttf 2.0.10 needed</p>
331
332 </div>
333 <h4 id="set_font_outline">set_font_outline</h4>
334 <div id="set_font_outline_CONTENT">
335 <pre> SDL::TTF::get_font_outline($font, $outline);
336
337 </pre>
338 <p>Set the outline pixel width of the loaded font. Use <code>0</code>(zero) to turn off outlining.</p>
339 <p><strong>Note</strong>: at least SDL_ttf 2.0.10 needed</p>
340
341 </div>
342 <h3 id="Font_settings">Font settings</h3>
343 <div id="Font_settings_CONTENT">
344
345 </div>
346 <h4 id="get_font_hinting">get_font_hinting</h4>
347 <div id="get_font_hinting_CONTENT">
348 <pre> my $hinting = SDL::TTF::get_font_hinting($font);
349
350 </pre>
351 <p>Get the current hinting setting of the loaded font.</p>
352 <p><strong>Note</strong>: at least SDL_ttf 2.0.10 needed</p>
353 <p>Returns the hinting type matching one of the following defined values:</p>
354 <ul>
355                 <li>TTF_HINTING_NORMAL  </li>
356                 <li>TTF_HINTING_LIGHT   </li>
357                 <li>TTF_HINTING_MONO    </li>
358                 <li>TTF_HINTING_NONE</li>
359 </ul>
360
361
362 </div>
363 <h4 id="set_font_hinting">set_font_hinting</h4>
364 <div id="set_font_hinting_CONTENT">
365 <pre> SDL::TTF::set_font_hinting($font, $hinting);
366
367 </pre>
368 <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 
369 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>
370 <p><strong>Note</strong>: at least SDL_ttf 2.0.10 needed</p>
371 <p>Example:</p>
372 <pre> SDL::TTF::set_font_hinting($font, TTF_HINTING_LIGHT);
373
374 </pre>
375
376 </div>
377 <h4 id="get_font_kerning">get_font_kerning</h4>
378 <div id="get_font_kerning_CONTENT">
379 <pre> my $kerning_enabled = SDL::TTF::get_font_kerning($font);
380
381 </pre>
382 <p>Get the current kerning setting of the loaded font.</p>
383 <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>
384 <p><strong>Note</strong>: at least SDL_ttf 2.0.10 needed</p>
385 <p><strong>Note</strong>: This function returns wrong values: See <a href="http://bugzilla.libsdl.org/show_bug.cgi?id=973">http://bugzilla.libsdl.org/show_bug.cgi?id=973</a></p>
386
387 </div>
388 <h4 id="set_font_kerning">set_font_kerning</h4>
389 <div id="set_font_kerning_CONTENT">
390 <pre> SDL::TTF::set_font_kerning($font, $kerning_enabled);
391
392 </pre>
393 <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 
394 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 
395 overlapping glyphs or abnormal spacing within words.</p>
396 <p>Pass <code>0</code> to disable kerning, 1 to enable.</p>
397 <p><strong>Note</strong>: at least SDL_ttf 2.0.10 needed</p>
398
399 </div>
400 <h3 id="Font_metrics">Font metrics</h3>
401 <div id="Font_metrics_CONTENT">
402
403 </div>
404 <h4 id="font_height">font_height</h4>
405 <div id="font_height_CONTENT">
406 <pre> my $font_height = SDL::TTF::font_height($font);
407
408 </pre>
409 <p>Get the maximum pixel height of all glyphs of the loaded font. You may use this height for rendering text as close together vertically as 
410 possible, though adding at least one pixel height to it will space it so they can't touch. Remember that SDL_ttf doesn't handle multiline 
411 printing, so you are responsible for line spacing, see the <a href="/SDL-TTF.html#font_line_skip">SDL::TTF::font_line_skip</a> as well.</p>
412
413 </div>
414 <h4 id="font_ascent">font_ascent</h4>
415 <div id="font_ascent_CONTENT">
416 <pre> my $font_ascent = SDL::TTF::font_ascent($font);
417
418 </pre>
419 <p>Get the maximum pixel ascent of all glyphs of the loaded font. This can also be interpreted as the distance from the top of the font to the 
420 baseline.
421 It could be used when drawing an individual glyph relative to a top point, by combining it with the glyph's <code>maxy</code> metric to resolve the top 
422 of the rectangle used when blitting the glyph on the screen.</p>
423 <p>Example:</p>
424 <pre> my ($minx, $maxx, $miny, $maxy, $advance) = @{ SDL::TTF::glyph_metrics($font, &quot;\0M&quot;) };
425
426  $rect-&gt;y( $top + SDL::TTF::font_ascent($font) - $maxy );
427
428 </pre>
429
430 </div>
431 <h4 id="font_descent">font_descent</h4>
432 <div id="font_descent_CONTENT">
433 <pre> my $font_descent = SDL::TTF::font_descent($font);
434
435 </pre>
436 <p>Get the maximum pixel descent of all glyphs of the loaded font. This can also be interpreted as the distance from the baseline to the bottom of 
437 the font.
438 It could be used when drawing an individual glyph relative to a bottom point, by combining it with the glyph's <code>maxy</code> metric to resolve the top 
439 of the rectangle used when blitting the glyph on the screen.</p>
440 <p>Example:</p>
441 <pre> my ($minx, $maxx, $miny, $maxy, $advance) = @{ SDL::TTF::glyph_metrics($font, &quot;\0M&quot;) };
442
443  $rect-&gt;y( $bottom - SDL::TTF::font_descent($font) - $maxy );
444
445 </pre>
446
447 </div>
448 <h4 id="font_line_skip">font_line_skip</h4>
449 <div id="font_line_skip_CONTENT">
450 <pre> my $font_line_skip = SDL::TTF::font_line_skip($font);
451
452 </pre>
453 <p>Get the recommended pixel height of a rendered line of text of the loaded font. This is usually larger than the <a href="/SDL-TTF.html#font_height">SDL::TTF::font_height</a> of the 
454 font.</p>
455
456 </div>
457 <h3 id="Face_attributes">Face attributes</h3>
458 <div id="Face_attributes_CONTENT">
459
460 </div>
461 <h4 id="font_faces">font_faces</h4>
462 <div id="font_faces_CONTENT">
463 <pre> my $font_faces = SDL::TTF::font_faces($font);
464
465 </pre>
466 <p>Get the number of faces (&quot;sub-fonts&quot;) available in the loaded font. This is a count of the number of specific fonts (based on size and style 
467 and other typographical features perhaps) contained in the font itself.</p>
468
469 </div>
470 <h4 id="font_face_is_fixed_width">font_face_is_fixed_width</h4>
471 <div id="font_face_is_fixed_width_CONTENT">
472 <pre> my $font_face_is_fixed_width = SDL::TTF::font_face_is_fixed_width($font);
473
474 </pre>
475 <p>Test if the current font face of the loaded font is a fixed width font. Fixed width fonts are monospace, meaning every character that exists 
476 in the font is the same width, thus you can assume that a rendered string's width is going to be the result of <code>glyph_width * string_length</code>.</p>
477 <p>Returns: <code>&gt;0</code> if font is a fixed width font. <code>0</code> if not a fixed width font. </p>
478
479 </div>
480 <h4 id="font_face_family_name">font_face_family_name</h4>
481 <div id="font_face_family_name_CONTENT">
482 <pre> my $font_face_family_name = SDL::TTF::font_face_family_name($font);
483
484 </pre>
485 <p>Get the current font face family name from the loaded font. This information is not for every font available.</p>
486 <p>Example:</p>
487 <pre> my $font = SDL::TTF::open_font('arialuni.ttf', 8);
488
489  printf(&quot;%s\n&quot;, SDL::TTF::font_face_family_name($font)); # will print &quot;Arial Unicode MS&quot;
490
491 </pre>
492
493 </div>
494 <h4 id="font_face_style_name">font_face_style_name</h4>
495 <div id="font_face_style_name_CONTENT">
496 <pre> my $font_face_style_name = SDL::TTF::font_face_style_name($font);
497
498 </pre>
499 <p>Get the current font face style name from the loaded font. This information is not for every font available. </p>
500 <p>Example:</p>
501 <pre> my $font = SDL::TTF::open_font('arialuni.ttf', 8);
502
503  printf(&quot;%s\n&quot;, SDL::TTF::font_face_style_name($font)); # will print &quot;Regular&quot;
504
505 </pre>
506
507 </div>
508 <h3 id="Glyphs">Glyphs</h3>
509 <div id="Glyphs_CONTENT">
510
511 </div>
512 <h4 id="glyph_is_provided">glyph_is_provided</h4>
513 <div id="glyph_is_provided_CONTENT">
514 <pre> my $glyph_is_provided = SDL::TTF::glyph_is_provided($font, $unicode_char);
515
516 </pre>
517 <p>Get the status of the availability of the glyph from the loaded font.</p>
518 <p>Returns: the index of the glyph in font, or 0 for an undefined character code.</p>
519 <p><strong>Note</strong>: You have to pass this unicode character either as UTF16/UCS-2 big endian without BOM, or with BOM as UTF16/UCS-2 big/little endian.</p>
520 <p><strong>Note</strong>: at least SDL_ttf 2.0.10 needed</p>
521 <p>Example:</p>
522 <pre> print(&quot;We have this char!\n&quot;) if SDL::TTF::glyph_is_provided($font, &quot;\0M&quot;);
523
524 </pre>
525
526 </div>
527 <h4 id="glyph_metrics">glyph_metrics</h4>
528 <div id="glyph_metrics_CONTENT">
529 <pre> my @glyph_metrics = @{ SDL::TTF::glyph_metrics($font, $unicode_char) };
530
531 </pre>
532 <p>Get desired glyph metrics of the UNICODE char from the loaded font.</p>
533 <p>See also: <a href="http://freetype.sourceforge.net/freetype2/docs/tutorial/step2.html">The FreeType2 Documentation Tutorial</a></p>
534 <p><strong>Note</strong>: You have to pass this unicode character either as UTF16/UCS-2 big endian without BOM, or with BOM as UTF16/UCS-2 big/little endian.</p>
535 <p>Example:</p>
536 <pre> my ($minx, $maxx, $miny, $maxy, $advance) = @{ SDL::TTF::glyph_metrics($font, &quot;\0M&quot;) };
537
538 </pre>
539
540 </div>
541 <h3 id="Text_metrics">Text metrics</h3>
542 <div id="Text_metrics_CONTENT">
543
544 </div>
545 <h4 id="size_text">size_text</h4>
546 <div id="size_text_CONTENT">
547 <pre> my ($width, $height) = @{ SDL::TTF::size_text($font, $text) };
548
549 </pre>
550 <p>Calculate the resulting surface size of the LATIN1 encoded text rendered using <code>$font</code>. No actual rendering is done, however correct kerning 
551 is done to get the actual width. The height returned is the same as you can get using <a href="/SDL-TTF.html#font_height">SDL::TTF::font_height</a>.</p>
552
553 </div>
554 <h4 id="size_utf8">size_utf8</h4>
555 <div id="size_utf8_CONTENT">
556 <pre> my ($width, $height) = @{ SDL::TTF::size_utf8($font, $text) };
557
558 </pre>
559 <p>Calculate the resulting surface size of the UTF8 encoded text rendered using <code>$font</code>. No actual rendering is done, however correct kerning is 
560 done to get the actual width. The height returned in h is the same as you can get using <a href="/SDL-TTF.html#font_height">SDL::TTF::font_height</a>.</p>
561 <p>Note that the first example uses the same text as in the LATIN1 example, that is because plain ASCII is UTF8 compatible.</p>
562 <p>Examples:</p>
563 <pre> ($width, $height) = @{ SDL::TTF::size_utf8($font, 'Hallo World!') }; # plain text, if your script is in utf8 or ansi-format
564
565  # or
566
567  ($width, $height) = @{ SDL::TTF::size_utf8($font, &quot;\xE4\xBB\x8A\xE6\x97\xA5\xE3\x81\xAF&quot;) }; # utf8 hex-data
568
569  # or
570
571  use Unicode::String;
572  my $unicode       = utf8($data_from_somwhere);
573  ($width, $height) = @{ SDL::TTF::size_utf8($font, $unicode-&gt;utf8) }; # utf8 via Unicode::String
574
575 </pre>
576
577 </div>
578 <h4 id="size_unicode">size_unicode</h4>
579 <div id="size_unicode_CONTENT">
580 <pre> my ($width, $height) = @{ SDL::TTF::size_unicode($font, $text) };
581
582 </pre>
583 <p>Calculate the resulting surface size of the UNICODE encoded text rendered using <code>$font</code>. No actual rendering is done, however correct kerning 
584 is done to get the actual width. The height returned in h is the same as you can get using <a href="/SDL-TTF.html#font_height">SDL::TTF::font_height</a>.</p>
585 <p><code>$text</code> has to be:</p>
586 <dl>
587         <dt>UTF16BE without BOM</dt>
588         <dd>
589                 <p>&quot;hallo&quot; will look like &quot;\0h\0a\0l\0l\0o&quot;</p>
590         </dd>
591         <dt>UTF16BE with BOM</dt>
592         <dd>
593                 <p>&quot;hallo&quot; will look like &quot;\xFE\xFF\0h\0a\0l\0l\0o&quot;</p>
594         </dd>
595         <dt>UTF16LE with BOM</dt>
596         <dd>
597                 <p>&quot;hallo&quot; will look like &quot;\xFF\xFEh\0a\0l\0l\0o\0&quot;</p>
598         </dd>
599 </dl>
600 <p>You may use Unicode::String for this.</p>
601
602 </div>
603 <h2 id="Font_Rendering">Font Rendering</h2>
604 <div id="Font_Rendering_CONTENT">
605
606 </div>
607 <h3 id="Solid">Solid</h3>
608 <div id="Solid_CONTENT">
609
610 </div>
611 <h4 id="render_glyph_solid">render_glyph_solid</h4>
612 <div id="render_glyph_solid_CONTENT">
613 <pre> my $surface = SDL::TTF::render_glyph_solid($font, $char, $color);
614
615 </pre>
616 <p>Render the unicode encoded char onto a new surface, using the Solid mode. After that you can blit this surface to your display-surface.</p>
617 <p><strong>Note</strong>: The unicode char has to be passed exactly like for <a href="/SDL-TTF.html#size_unicode">SDL::TTF::size_unicode</a>.</p>
618 <p><strong>Note</strong>: <a href="http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=374062">See space-character bug</a>. You have to upgrade libfreetype2 to at least version 2.3.5</p>
619
620 </div>
621 <h4 id="render_text_solid">render_text_solid</h4>
622 <div id="render_text_solid_CONTENT">
623 <pre> my $surface = SDL::TTF::render_text_solid($font, $text, $color);
624
625 </pre>
626 <p>Render the LATIN1 encoded text onto a new surface, using the Solid mode. After that you can blit this surface to your display-surface.</p>
627 <p><strong>Note</strong>: <a href="http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=374062">See space-character bug</a>. You have to upgrade libfreetype2 to at least 
628 version 2.3.5</p>
629 <p>Example:</p>
630 <pre>   use SDL;
631         use SDL::Rect;
632         use SDL::Video;
633         use SDL::Color;
634         use SDL::TTF;
635         use SDL::TTF::Font;
636
637         SDL::init(SDL_INIT_VIDEO);
638         SDL::TTF::init();
639         my $display = SDL::Video::set_video_mode(640, 480, 32, SDL_SWSURFACE);
640         my $font    = SDL::TTF::open_font('test/data/aircut3.ttf', '24');
641         die 'Coudnt make font '. SDL::get_error if !$font;
642         my $surface = SDL::TTF::render_text_solid($font, 'Hallo!', SDL::Color-&gt;new(0xFF,0xFF,0xFF));
643         SDL::Video::blit_surface($surface, SDL::Rect-&gt;new(0, 0, 640, 480), $display, SDL::Rect-&gt;new(10, 10, 640, 480));
644         SDL::Video::update_rect($display, 0, 0, 0, 0);
645         SDL::delay(5000);
646
647 </pre>
648
649 </div>
650 <h4 id="render_utf8_solid">render_utf8_solid</h4>
651 <div id="render_utf8_solid_CONTENT">
652 <pre> my $surface = SDL::TTF::render_utf8_solid($font, $text, $color);
653
654 </pre>
655 <p>Render the UTF8 encoded text onto a new surface, using the Solid mode. After that you can blit this surface to your display-surface.</p>
656 <p><strong>Note</strong>: <a href="http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=374062">See space-character bug</a>. You have to upgrade libfreetype2 to at least 
657 version 2.3.5</p>
658
659 </div>
660 <h4 id="render_unicode_solid">render_unicode_solid</h4>
661 <div id="render_unicode_solid_CONTENT">
662 <pre> my $surface = SDL::TTF::render_unicode_solid($font, $text, $color);
663
664 </pre>
665 <p>Render the unicode encoded text onto a new surface, using the Solid mode. After that you can blit this surface to your display-surface.</p>
666 <p><strong>Note</strong>: The unicode test has to be passed exactly like for <a href="/SDL-TTF.html#size_unicode">SDL::TTF::size_unicode</a>.</p>
667 <p><strong>Note</strong>: <a href="http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=374062">See space-character bug</a>. You have to upgrade libfreetype2 to at least 
668 version 2.3.5</p>
669
670 </div>
671 <h3 id="Shaded">Shaded</h3>
672 <div id="Shaded_CONTENT">
673
674 </div>
675 <h4 id="render_glyph_shaded">render_glyph_shaded</h4>
676 <div id="render_glyph_shaded_CONTENT">
677 <pre> my $surface = SDL::TTF::render_glyph_shaded($font, $char, $color, $background_color);
678
679 </pre>
680 <p>Render the unicode encoded char onto a new surface. The surface is filled with <code>$background_color</code>. After that you can blit this surface to 
681 your display-surface.</p>
682 <p><strong>Note</strong>: The unicode char has to be passed exactly like for <a href="/SDL-TTF.html#size_unicode">SDL::TTF::size_unicode</a>.</p>
683
684 </div>
685 <h4 id="render_text_shaded">render_text_shaded</h4>
686 <div id="render_text_shaded_CONTENT">
687 <pre> my $surface = SDL::TTF::render_text_shaded($font, $text, $color, $background_color);
688
689 </pre>
690 <p>Render the LATIN1 encoded text onto a new surface. The surface is filled with <code>$background_color</code>. After that you can blit this surface to 
691 your display-surface.</p>
692 <p>Example:</p>
693 <pre> use SDL;
694  use SDL::Video;
695  use SDL::Color;
696  use SDL::TTF;
697  use SDL::TTF::Font;
698
699  SDL::init(SDL_INIT_VIDEO);
700
701  SDL::TTF::init();
702
703  my $display = SDL::Video::set_video_mode(640, 480, 32, SDL_SWSURFACE);
704  my $font    = SDL::TTF::open_font('arial.ttf', '24');
705  my $white   = SDL::Color-&gt;new(0xFF, 0xFF, 0xFF);
706  my $black   = SDL::Color-&gt;new(0x00, 0x00, 0x00);
707  my $surface = SDL::TTF::render_text_solid($font, 'Hallo!', $white, $black);
708
709  SDL::Video::blit_surface($surface, SDL::Rect-&gt;new(0, 0, 640, 480), $display, SDL::Rect-&gt;new(10, 10, 640, 480));
710  SDL::Video::update_rect($display, 0, 0, 0, 0);
711
712  SDL::delay(5000);
713
714 </pre>
715
716 </div>
717 <h4 id="render_utf8_shaded">render_utf8_shaded</h4>
718 <div id="render_utf8_shaded_CONTENT">
719 <pre> my $surface = SDL::TTF::render_utf8_shaded($font, $text, $color, $background_color);
720
721 </pre>
722 <p>Render the UTF8 encoded text onto a new surface. The surface is filled with <code>$background_color</code>. After that you can blit this surface to 
723 your display-surface.</p>
724
725 </div>
726 <h4 id="render_unicode_shaded">render_unicode_shaded</h4>
727 <div id="render_unicode_shaded_CONTENT">
728 <pre> my $surface = SDL::TTF::render_unicode_shaded($font, $text, $color, $background_color);
729
730 </pre>
731 <p>Render the unicode encoded text onto a new surface. The surface is filled with <code>$background_color</code>. After that you can blit this surface to 
732 your display-surface.</p>
733 <p><strong>Note</strong>: The unicode text has to be passed exactly like for <a href="/SDL-TTF.html#size_unicode">SDL::TTF::size_unicode</a>.</p>
734
735 </div>
736 <h3 id="Blended">Blended</h3>
737 <div id="Blended_CONTENT">
738
739 </div>
740 <h4 id="render_glyph_blended">render_glyph_blended</h4>
741 <div id="render_glyph_blended_CONTENT">
742 <pre> my $surface = SDL::TTF::render_glyph_blended($font, $char, $color);
743
744 </pre>
745 <p>Render the unicode encoded char onto a new surface. After that you can blit this surface to your display-surface.</p>
746 <p><strong>Note</strong>: The unicode char has to be passed exactly like for <a href="/SDL-TTF.html#size_unicode">SDL::TTF::size_unicode</a>.</p>
747
748 </div>
749 <h4 id="render_text_blended">render_text_blended</h4>
750 <div id="render_text_blended_CONTENT">
751 <pre> my $surface = SDL::TTF::render_text_blended($font, $text, $color);
752
753 </pre>
754 <p>Render the LATIN1 encoded text onto a new surface. After that you can blit this surface to your display-surface.</p>
755 <p>Example:</p>
756 <pre> use SDL;
757  use SDL::Video;
758  use SDL::Color;
759  use SDL::TTF;
760  use SDL::TTF::Font;
761
762  SDL::init(SDL_INIT_VIDEO);
763
764  SDL::TTF::init();
765
766  my $display = SDL::Video::set_video_mode(640, 480, 32, SDL_SWSURFACE);
767  my $font    = SDL::TTF::open_font('arial.ttf', '24');
768  my $surface = SDL::TTF::render_text_blended($font, 'Hallo!', SDL::Color-&gt;new(0xFF,0xFF,0xFF));
769
770  SDL::Video::blit_surface($surface, SDL::Rect-&gt;new(0, 0, 640, 480), $display, SDL::Rect-&gt;new(10, 10, 640, 480));
771  SDL::Video::update_rect($display, 0, 0, 0, 0);
772
773  SDL::delay(5000);
774
775 </pre>
776
777 </div>
778 <h4 id="render_utf8_blended">render_utf8_blended</h4>
779 <div id="render_utf8_blended_CONTENT">
780 <pre> my $surface = SDL::TTF::render_utf8_blended($font, $text, $color);
781
782 </pre>
783 <p>Render the UTF8 encoded text onto a new surface. After that you can blit this surface to your display-surface.</p>
784
785 </div>
786 <h4 id="render_unicode_blended">render_unicode_blended</h4>
787 <div id="render_unicode_blended_CONTENT">
788 <pre> my $surface = SDL::TTF::render_unicode_blended($font, $text, $color);
789
790 </pre>
791 <p>Render the unicode encoded text onto a new surface. After that you can blit this surface to your display-surface.</p>
792 <p><strong>Note</strong>: The unicode char has to be passed exactly like for <a href="/SDL-TTF.html#size_unicode">SDL::TTF::size_unicode</a>.</p>
793
794 </div>
795 <h1 id="AUTHOR">AUTHOR</h1><p><a href="#TOP" class="toplink">Top</a></p>
796 <div id="AUTHOR_CONTENT">
797 <p>Tobias Leich [FROGGS]</p>
798
799 </div>
800 <h1 id="SEE_ALSO">SEE ALSO</h1><p><a href="#TOP" class="toplink">Top</a></p>
801 <div id="SEE_ALSO_CONTENT">
802 <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>
803
804 </div>
805 </div>