added docs for glyphs
[sdlgit/SDL-Site.git] / pages / SDL-TTF.html-inc
index 95fd772..9779aaa 100644 (file)
@@ -28,6 +28,8 @@
 <li><a href="#Font_style">Font style</a>
 <ul><li><a href="#get_font_style">get_font_style</a></li>
 <li><a href="#set_font_style">set_font_style</a></li>
+<li><a href="#get_font_outline">get_font_outline</a></li>
+<li><a href="#set_font_outline">set_font_outline</a></li>
 </ul>
 </li>
 <li><a href="#Font_settings">Font settings</a>
@@ -277,6 +279,24 @@ Still, sometimes the underline or strikethrough may be outside of the generated
 this case, you should probably turn off these styles and draw your own strikethroughs and underlines. </p>
 
 </div>
+<h4 id="get_font_outline">get_font_outline</h4>
+<div id="get_font_outline_CONTENT">
+<pre> my $outline = SDL::TTF::get_font_outline($font);
+
+</pre>
+<p>Get the current outline width of the font, in pixels.</p>
+<p><strong>Note</strong>: at least SDL_ttf 2.0.10 needed</p>
+
+</div>
+<h4 id="set_font_outline">set_font_outline</h4>
+<div id="set_font_outline_CONTENT">
+<pre> SDL::TTF::get_font_outline($font, $outline);
+
+</pre>
+<p>Set the outline pixel width of the loaded font. Use <code>0</code>(zero) to turn off outlining.</p>
+<p><strong>Note</strong>: at least SDL_ttf 2.0.10 needed</p>
+
+</div>
 <h3 id="Font_settings">Font settings</h3>
 <div id="Font_settings_CONTENT">
 
@@ -343,12 +363,24 @@ overlapping glyphs or abnormal spacing within words.</p>
 <pre> my $font_height = SDL::TTF::font_height($font);
 
 </pre>
+<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 
+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 
+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>
 
 </div>
 <h4 id="font_ascent">font_ascent</h4>
 <div id="font_ascent_CONTENT">
 <pre> my $font_ascent = SDL::TTF::font_ascent($font);
- like( $font_ascent,                                       '/^[-]?\d+$/',       &quot;[font_ascent] offset from the baseline to the top of the font is $font_ascent&quot; );
+
+</pre>
+<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 
+baseline.
+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 
+of the rectangle used when blitting the glyph on the screen.</p>
+<p>Example:</p>
+<pre> my ($minx, $maxx, $miny, $maxy, $advance) = @{ SDL::TTF::glyph_metrics($font, &quot;\0M&quot;) };
+
+ $rect-&gt;y( $top + SDL::TTF::font_ascent($font) - $maxy );
 
 </pre>
 
@@ -356,7 +388,16 @@ overlapping glyphs or abnormal spacing within words.</p>
 <h4 id="font_descent">font_descent</h4>
 <div id="font_descent_CONTENT">
 <pre> my $font_descent = SDL::TTF::font_descent($font);
- like( $font_descent,                                      '/^[-]?\d+$/',       &quot;[font_descent] offset from the baseline to the bottom of the font is $font_descent&quot; );
+
+</pre>
+<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 
+the font.
+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 
+of the rectangle used when blitting the glyph on the screen.</p>
+<p>Example:</p>
+<pre> my ($minx, $maxx, $miny, $maxy, $advance) = @{ SDL::TTF::glyph_metrics($font, &quot;\0M&quot;) };
+
+ $rect-&gt;y( $bottom - SDL::TTF::font_descent($font) - $maxy );
 
 </pre>
 
@@ -364,9 +405,10 @@ overlapping glyphs or abnormal spacing within words.</p>
 <h4 id="font_line_skip">font_line_skip</h4>
 <div id="font_line_skip_CONTENT">
 <pre> my $font_line_skip = SDL::TTF::font_line_skip($font);
- like( $font_line_skip,                                    '/^[-]?\d+$/',       &quot;[font_line_skip] recommended spacing between lines of text is $font_line_skip&quot; );
 
 </pre>
+<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 
+font.</p>
 
 </div>
 <h3 id="Face_attributes">Face attributes</h3>
@@ -375,26 +417,49 @@ overlapping glyphs or abnormal spacing within words.</p>
 </div>
 <h4 id="font_faces">font_faces</h4>
 <div id="font_faces_CONTENT">
-<p>my $font_faces = SDL::TTF::font_faces($font);
-ok( $font_faces,                                                               &quot;[font_faces] font has $font_faces faces&quot; );</p>
+<pre> my $font_faces = SDL::TTF::font_faces($font);
+
+</pre>
+<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 
+and other typographical features perhaps) contained in the font itself.</p>
 
 </div>
 <h4 id="font_face_is_fixed_width">font_face_is_fixed_width</h4>
 <div id="font_face_is_fixed_width_CONTENT">
-<p>my $font_face_is_fixed_width = SDL::TTF::font_face_is_fixed_width($font);
-like( $font_face_is_fixed_width,                          '/^[01]$/',          &quot;[font_face_is_fixed_width] is $font_face_is_fixed_width&quot; );</p>
+<pre> my $font_face_is_fixed_width = SDL::TTF::font_face_is_fixed_width($font);
+
+</pre>
+<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 
+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>
+<p>Returns: <code>&gt;0</code> if font is a fixed width font. <code>0</code> if not a fixed width font. </p>
 
 </div>
 <h4 id="font_face_family_name">font_face_family_name</h4>
 <div id="font_face_family_name_CONTENT">
-<p>my $font_face_family_name = SDL::TTF::font_face_family_name($font);
-ok( $font_face_family_name,                                                    &quot;[font_face_family_name] is $font_face_family_name&quot; );</p>
+<pre> my $font_face_family_name = SDL::TTF::font_face_family_name($font);
+
+</pre>
+<p>Get the current font face family name from the loaded font. This information is not for every font available.</p>
+<p>Example:</p>
+<pre> my $font = SDL::TTF::open_font('arialuni.ttf', 8);
+
+ printf(&quot;%s\n&quot;, SDL::TTF::font_face_family_name($font)); # will print &quot;Arial Unicode MS&quot;
+
+</pre>
 
 </div>
 <h4 id="font_face_style_name">font_face_style_name</h4>
 <div id="font_face_style_name_CONTENT">
-<p>my $font_face_style_name = SDL::TTF::font_face_style_name($font);
-ok( $font_face_style_name,                                                     &quot;[font_face_style_name] is $font_face_style_name&quot; );</p>
+<pre> my $font_face_style_name = SDL::TTF::font_face_style_name($font);
+
+</pre>
+<p>Get the current font face style name from the loaded font. This information is not for every font available. </p>
+<p>Example:</p>
+<pre> my $font = SDL::TTF::open_font('arialuni.ttf', 8);
+
+ printf(&quot;%s\n&quot;, SDL::TTF::font_face_style_name($font)); # will print &quot;Regular&quot;
+
+</pre>
 
 </div>
 <h3 id="Glyphs">Glyphs</h3>
@@ -403,12 +468,29 @@ ok( $font_face_style_name,                                                     &
 </div>
 <h4 id="glyph_is_provided">glyph_is_provided</h4>
 <div id="glyph_is_provided_CONTENT">
+<pre> my $glyph_is_provided = SDL::TTF::glyph_is_provided($font, $unicode_char);
+
+</pre>
+<p>Get the status of the availability of the glyph from the loaded font.</p>
+<p>Returns: the index of the glyph in font, or 0 for an undefined character code.</p>
+<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>
+<p><strong>Note</strong>: at least SDL_ttf 2.0.10 needed</p>
+<p>Example:</p>
+<pre> print(&quot;We have this char!\n&quot;) if SDL::TTF::glyph_is_provided($font, &quot;\0M&quot;);
+
+</pre>
 
 </div>
 <h4 id="glyph_metrics">glyph_metrics</h4>
 <div id="glyph_metrics_CONTENT">
-<pre> my @glyph_metrics = @{ SDL::TTF::glyph_metrics($font, 'M') };
-is( scalar @glyph_metrics,                                5,                   &quot;[glyph_metrics] (minx, maxx, miny, maxy, advance) = (&quot; . join(', ', @glyph_metrics) . &quot;)&quot; );
+<pre> my @glyph_metrics = @{ SDL::TTF::glyph_metrics($font, $unicode_char) };
+
+</pre>
+<p>Get desired glyph metrics of the UNICODE char from the loaded font.</p>
+<p>See also: <a href="http://freetype.sourceforge.net/freetype2/docs/tutorial/step2.html">The FreeType2 Documentation Tutorial</a></p>
+<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>
+<p>Example:</p>
+<pre> my ($minx, $maxx, $miny, $maxy, $advance) = @{ SDL::TTF::glyph_metrics($font, &quot;\0M&quot;) };
 
 </pre>