updated docs
[sdlgit/SDL-Site.git] / pages / SDL-TTF.html-inc
index 394a88d..cff5ad1 100644 (file)
@@ -4,6 +4,7 @@
 
 <ul><li><a href="#NAME">NAME</a></li>
 <li><a href="#CATEGORY">CATEGORY</a></li>
+<li><a href="#CONSTANTS">CONSTANTS</a></li>
 <li><a href="#METHODS">METHODS</a>
 <ul><li><a href="#General_methods">General methods</a>
 <ul><li><a href="#linked_version">linked_version</a></li>
 </ul>
 </li>
 <li><a href="#Font_Rendering">Font Rendering</a>
+<ul><li><a href="#Solid">Solid</a>
 <ul><li><a href="#render_glyph_solid">render_glyph_solid</a></li>
-<li><a href="#render_glyph_shaded">render_glyph_shaded</a></li>
-<li><a href="#render_glyph_blended">render_glyph_blended</a></li>
 <li><a href="#render_text_solid">render_text_solid</a></li>
-<li><a href="#render_text_shaded">render_text_shaded</a></li>
-<li><a href="#render_text_blended">render_text_blended</a></li>
 <li><a href="#render_utf8_solid">render_utf8_solid</a></li>
-<li><a href="#render_utf8_shaded">render_utf8_shaded</a></li>
-<li><a href="#render_utf8_blended">render_utf8_blended</a></li>
 <li><a href="#render_unicode_solid">render_unicode_solid</a></li>
+</ul>
+</li>
+<li><a href="#Shaded">Shaded</a>
+<ul><li><a href="#render_glyph_shaded">render_glyph_shaded</a></li>
+<li><a href="#render_text_shaded">render_text_shaded</a></li>
+<li><a href="#render_utf8_shaded">render_utf8_shaded</a></li>
 <li><a href="#render_unicode_shaded">render_unicode_shaded</a></li>
+</ul>
+</li>
+<li><a href="#Blended">Blended</a>
+<ul><li><a href="#render_glyph_blended">render_glyph_blended</a></li>
+<li><a href="#render_text_blended">render_text_blended</a></li>
+<li><a href="#render_utf8_blended">render_utf8_blended</a></li>
 <li><a href="#render_unicode_blended">render_unicode_blended</a></li>
 </ul>
 </li>
 </ul>
 </li>
-<li><a href="#AUTHOR">AUTHOR</a></li>
+</ul>
+</li>
+<li><a href="#AUTHORS">AUTHORS</a></li>
 <li><a href="#SEE_ALSO">SEE ALSO</a>
 </li>
 </ul><hr />
 </div>
 <h1 id="CATEGORY">CATEGORY</h1><p><a href="#TOP" class="toplink">Top</a></p>
 <div id="CATEGORY_CONTENT">
-<p>TODO, TTF</p>
+<p>TTF</p>
+
+</div>
+<h1 id="CONSTANTS">CONSTANTS</h1><p><a href="#TOP" class="toplink">Top</a></p>
+<div id="CONSTANTS_CONTENT">
+<p>The constants are exported by default. You can avoid this by doing:</p>
+<pre> use SDL::TTF ();
+
+
+
+
+</pre>
+<p>and access them directly:</p>
+<pre> SDL::TTF::TTF_HINTING_NORMAL;
+
+</pre>
+<p>Available constants for &quot;hinting&quot;:</p>
+<ul>
+               <li>TTF_HINTING_NORMAL  </li>
+               <li>TTF_HINTING_LIGHT   </li>
+               <li>TTF_HINTING_MONO    </li>
+               <li>TTF_HINTING_NONE</li>
+</ul>
+
+<p>Available constants for &quot;style&quot;:</p>
+<ul>
+               <li>TTF_STYLE_NORMAL    </li>
+               <li>TTF_STYLE_BOLD      </li>
+               <li>TTF_STYLE_ITALIC    </li>
+               <li>TTF_STYLE_UNDERLINE </li>
+               <li>TTF_STYLE_STRIKETHROUGH</li>
+</ul>
+
 
 </div>
 <h1 id="METHODS">METHODS</h1><p><a href="#TOP" class="toplink">Top</a></p>
@@ -179,7 +221,7 @@ use the functionality again</p>
 <pre> use SDL::TTF;
  use SDL::TTF::Font;
 
- my $font = SDL::TTF::open_font('arial.ttf', '24);
+ my $font = SDL::TTF::open_font('arial.ttf', 24);
 
 </pre>
 
@@ -340,6 +382,7 @@ using smaller sized fonts. If the user is selecting a font, you may wish to let
 <p>Get the current kerning setting of the loaded font.</p>
 <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>
 <p><strong>Note</strong>: at least SDL_ttf 2.0.10 needed</p>
+<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>
 
 </div>
 <h4 id="set_font_kerning">set_font_kerning</h4>
@@ -378,7 +421,7 @@ 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, 'M') };
+<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 );
 
@@ -395,7 +438,7 @@ 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, 'M') };
+<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 );
 
@@ -468,11 +511,29 @@ in the font is the same width, thus you can assume that a rendered string's widt
 </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') };
+<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>
 
@@ -483,81 +544,257 @@ in the font is the same width, thus you can assume that a rendered string's widt
 </div>
 <h4 id="size_text">size_text</h4>
 <div id="size_text_CONTENT">
-<pre> my ($width, $height) = @{ SDL::TTF::size_text($font, 'Hallo World!') };
+<pre> my ($width, $height) = @{ SDL::TTF::size_text($font, $text) };
 
 </pre>
+<p>Calculate the resulting surface size of the LATIN1 encoded text rendered using <code>$font</code>. No actual rendering is done, however correct kerning 
+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>
 
 </div>
 <h4 id="size_utf8">size_utf8</h4>
 <div id="size_utf8_CONTENT">
-<pre> my ($width, $height) = @{ SDL::TTF::size_utf8($font, 'Hallo World!') };
+<pre> my ($width, $height) = @{ SDL::TTF::size_utf8($font, $text) };
+
+</pre>
+<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 
+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>
+<p>Note that the first example uses the same text as in the LATIN1 example, that is because plain ASCII is UTF8 compatible.</p>
+<p>Examples:</p>
+<pre> ($width, $height) = @{ SDL::TTF::size_utf8($font, 'Hallo World!') }; # plain text, if your script is in utf8 or ansi-format
+
+ # or
+
+ ($width, $height) = @{ SDL::TTF::size_utf8($font, &quot;\xE4\xBB\x8A\xE6\x97\xA5\xE3\x81\xAF&quot;) }; # utf8 hex-data
+
+ # or
+
+ use Unicode::String;
+ my $unicode       = utf8($data_from_somwhere);
+ ($width, $height) = @{ SDL::TTF::size_utf8($font, $unicode-&gt;utf8) }; # utf8 via Unicode::String
 
 </pre>
 
 </div>
 <h4 id="size_unicode">size_unicode</h4>
 <div id="size_unicode_CONTENT">
-<pre> my ($width, $height) = @{ SDL::TTF::size_unicode($font, 'Hallo World!') };
-
-</pre>
+<pre> my ($width, $height) = @{ SDL::TTF::size_unicode($font, $text) };
+
+</pre>
+<p>Calculate the resulting surface size of the UNICODE encoded text rendered using <code>$font</code>. No actual rendering is done, however correct kerning 
+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>
+<p><code>$text</code> has to be:</p>
+<dl>
+       <dt>UTF16BE without BOM</dt>
+       <dd>
+               <p>&quot;hallo&quot; will look like &quot;\0h\0a\0l\0l\0o&quot;</p>
+       </dd>
+       <dt>UTF16BE with BOM</dt>
+       <dd>
+               <p>&quot;hallo&quot; will look like &quot;\xFE\xFF\0h\0a\0l\0l\0o&quot;</p>
+       </dd>
+       <dt>UTF16LE with BOM</dt>
+       <dd>
+               <p>&quot;hallo&quot; will look like &quot;\xFF\xFEh\0a\0l\0l\0o\0&quot;</p>
+       </dd>
+</dl>
+<p>You may use Unicode::String for this.</p>
 
 </div>
 <h2 id="Font_Rendering">Font Rendering</h2>
 <div id="Font_Rendering_CONTENT">
 
 </div>
-<h3 id="render_glyph_solid">render_glyph_solid</h3>
+<h3 id="Solid">Solid</h3>
+<div id="Solid_CONTENT">
+
+</div>
+<h4 id="render_glyph_solid">render_glyph_solid</h4>
 <div id="render_glyph_solid_CONTENT">
+<pre> my $surface = SDL::TTF::render_glyph_solid($font, $char, $color);
+
+</pre>
+<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>
+<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>
+<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>
 
 </div>
-<h3 id="render_glyph_shaded">render_glyph_shaded</h3>
-<div id="render_glyph_shaded_CONTENT">
+<h4 id="render_text_solid">render_text_solid</h4>
+<div id="render_text_solid_CONTENT">
+<pre> my $surface = SDL::TTF::render_text_solid($font, $text, $color);
+
+</pre>
+<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>
+<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>
+<p>Example:</p>
+<pre>  use SDL;
+       use SDL::Rect;
+       use SDL::Video;
+       use SDL::Color;
+       use SDL::TTF;
+       use SDL::TTF::Font;
+
+       SDL::init(SDL_INIT_VIDEO);
+       SDL::TTF::init();
+       my $display = SDL::Video::set_video_mode(640, 480, 32, SDL_SWSURFACE);
+       my $font    = SDL::TTF::open_font('test/data/aircut3.ttf', '24');
+       die 'Coudnt make font '. SDL::get_error if !$font;
+       my $surface = SDL::TTF::render_text_solid($font, 'Hallo!', SDL::Color-&gt;new(0xFF,0xFF,0xFF));
+       SDL::Video::blit_surface($surface, SDL::Rect-&gt;new(0, 0, 640, 480), $display, SDL::Rect-&gt;new(10, 10, 640, 480));
+       SDL::Video::update_rect($display, 0, 0, 0, 0);
+       SDL::delay(5000);
+
+</pre>
 
 </div>
-<h3 id="render_glyph_blended">render_glyph_blended</h3>
-<div id="render_glyph_blended_CONTENT">
+<h4 id="render_utf8_solid">render_utf8_solid</h4>
+<div id="render_utf8_solid_CONTENT">
+<pre> my $surface = SDL::TTF::render_utf8_solid($font, $text, $color);
+
+</pre>
+<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>
+<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>
 
 </div>
-<h3 id="render_text_solid">render_text_solid</h3>
-<div id="render_text_solid_CONTENT">
-<p><strong>Note</strong>: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=374062</p>
+<h4 id="render_unicode_solid">render_unicode_solid</h4>
+<div id="render_unicode_solid_CONTENT">
+<pre> my $surface = SDL::TTF::render_unicode_solid($font, $text, $color);
+
+</pre>
+<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>
+<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>
+<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>
 
 </div>
-<h3 id="render_text_shaded">render_text_shaded</h3>
-<div id="render_text_shaded_CONTENT">
+<h3 id="Shaded">Shaded</h3>
+<div id="Shaded_CONTENT">
 
 </div>
-<h3 id="render_text_blended">render_text_blended</h3>
-<div id="render_text_blended_CONTENT">
+<h4 id="render_glyph_shaded">render_glyph_shaded</h4>
+<div id="render_glyph_shaded_CONTENT">
+<pre> my $surface = SDL::TTF::render_glyph_shaded($font, $char, $color, $background_color);
+
+</pre>
+<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 
+your display-surface.</p>
+<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>
 
 </div>
-<h3 id="render_utf8_solid">render_utf8_solid</h3>
-<div id="render_utf8_solid_CONTENT">
+<h4 id="render_text_shaded">render_text_shaded</h4>
+<div id="render_text_shaded_CONTENT">
+<pre> my $surface = SDL::TTF::render_text_shaded($font, $text, $color, $background_color);
+
+</pre>
+<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 
+your display-surface.</p>
+<p>Example:</p>
+<pre> use SDL;
+ use SDL::Video;
+ use SDL::Color;
+ use SDL::TTF;
+ use SDL::TTF::Font;
+
+ SDL::init(SDL_INIT_VIDEO);
+
+ SDL::TTF::init();
+
+ my $display = SDL::Video::set_video_mode(640, 480, 32, SDL_SWSURFACE);
+ my $font    = SDL::TTF::open_font('arial.ttf', '24');
+ my $white   = SDL::Color-&gt;new(0xFF, 0xFF, 0xFF);
+ my $black   = SDL::Color-&gt;new(0x00, 0x00, 0x00);
+ my $surface = SDL::TTF::render_text_solid($font, 'Hallo!', $white, $black);
+
+ SDL::Video::blit_surface($surface, SDL::Rect-&gt;new(0, 0, 640, 480), $display, SDL::Rect-&gt;new(10, 10, 640, 480));
+ SDL::Video::update_rect($display, 0, 0, 0, 0);
+
+ SDL::delay(5000);
+
+</pre>
 
 </div>
-<h3 id="render_utf8_shaded">render_utf8_shaded</h3>
+<h4 id="render_utf8_shaded">render_utf8_shaded</h4>
 <div id="render_utf8_shaded_CONTENT">
+<pre> my $surface = SDL::TTF::render_utf8_shaded($font, $text, $color, $background_color);
+
+</pre>
+<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 
+your display-surface.</p>
 
 </div>
-<h3 id="render_utf8_blended">render_utf8_blended</h3>
-<div id="render_utf8_blended_CONTENT">
+<h4 id="render_unicode_shaded">render_unicode_shaded</h4>
+<div id="render_unicode_shaded_CONTENT">
+<pre> my $surface = SDL::TTF::render_unicode_shaded($font, $text, $color, $background_color);
+
+</pre>
+<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 
+your display-surface.</p>
+<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>
 
 </div>
-<h3 id="render_unicode_solid">render_unicode_solid</h3>
-<div id="render_unicode_solid_CONTENT">
+<h3 id="Blended">Blended</h3>
+<div id="Blended_CONTENT">
 
 </div>
-<h3 id="render_unicode_shaded">render_unicode_shaded</h3>
-<div id="render_unicode_shaded_CONTENT">
+<h4 id="render_glyph_blended">render_glyph_blended</h4>
+<div id="render_glyph_blended_CONTENT">
+<pre> my $surface = SDL::TTF::render_glyph_blended($font, $char, $color);
+
+</pre>
+<p>Render the unicode encoded char onto a new surface. After that you can blit this surface to your display-surface.</p>
+<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>
 
 </div>
-<h3 id="render_unicode_blended">render_unicode_blended</h3>
+<h4 id="render_text_blended">render_text_blended</h4>
+<div id="render_text_blended_CONTENT">
+<pre> my $surface = SDL::TTF::render_text_blended($font, $text, $color);
+
+</pre>
+<p>Render the LATIN1 encoded text onto a new surface. After that you can blit this surface to your display-surface.</p>
+<p>Example:</p>
+<pre> use SDL;
+ use SDL::Video;
+ use SDL::Color;
+ use SDL::TTF;
+ use SDL::TTF::Font;
+
+ SDL::init(SDL_INIT_VIDEO);
+
+ SDL::TTF::init();
+
+ my $display = SDL::Video::set_video_mode(640, 480, 32, SDL_SWSURFACE);
+ my $font    = SDL::TTF::open_font('arial.ttf', '24');
+ my $surface = SDL::TTF::render_text_blended($font, 'Hallo!', SDL::Color-&gt;new(0xFF,0xFF,0xFF));
+
+ SDL::Video::blit_surface($surface, SDL::Rect-&gt;new(0, 0, 640, 480), $display, SDL::Rect-&gt;new(10, 10, 640, 480));
+ SDL::Video::update_rect($display, 0, 0, 0, 0);
+
+ SDL::delay(5000);
+
+</pre>
+
+</div>
+<h4 id="render_utf8_blended">render_utf8_blended</h4>
+<div id="render_utf8_blended_CONTENT">
+<pre> my $surface = SDL::TTF::render_utf8_blended($font, $text, $color);
+
+</pre>
+<p>Render the UTF8 encoded text onto a new surface. After that you can blit this surface to your display-surface.</p>
+
+</div>
+<h4 id="render_unicode_blended">render_unicode_blended</h4>
 <div id="render_unicode_blended_CONTENT">
+<pre> my $surface = SDL::TTF::render_unicode_blended($font, $text, $color);
+
+</pre>
+<p>Render the unicode encoded text onto a new surface. After that you can blit this surface to your display-surface.</p>
+<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>
 
 </div>
-<h1 id="AUTHOR">AUTHOR</h1><p><a href="#TOP" class="toplink">Top</a></p>
-<div id="AUTHOR_CONTENT">
-<p>Tobias Leich [FROGGS]</p>
+<h1 id="AUTHORS">AUTHORS</h1><p><a href="#TOP" class="toplink">Top</a></p>
+<div id="AUTHORS_CONTENT">
+<p>See <b>AUTHORS</b> in <cite>SDL</cite>.</p>
 
 </div>
 <h1 id="SEE_ALSO">SEE ALSO</h1><p><a href="#TOP" class="toplink">Top</a></p>