treasurehunting2/PySDL2-0.9.5/doc/html/modules/sdl2ext_font.html

261 lines
17 KiB
HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Text rendering routines &#8212; PySDL2 0.9.5 documentation</title>
<link rel="stylesheet" href="../_static/classic.css" type="text/css" />
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '../',
VERSION: '0.9.5',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="../_static/jquery.js"></script>
<script type="text/javascript" src="../_static/underscore.js"></script>
<script type="text/javascript" src="../_static/doctools.js"></script>
<link rel="top" title="PySDL2 0.9.5 documentation" href="../index.html" />
<link rel="up" title="sdl2.ext - Python extensions for SDL2" href="sdl2ext.html" />
<link rel="next" title="User interface elements" href="sdl2ext_gui.html" />
<link rel="prev" title="General purpose event handling routines" href="sdl2ext_events.html" />
</head>
<body role="document">
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="sdl2ext_gui.html" title="User interface elements"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="sdl2ext_events.html" title="General purpose event handling routines"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../index.html">PySDL2 0.9.5 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="index.html" >API reference</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="sdl2ext.html" accesskey="U">sdl2.ext - Python extensions for SDL2</a> &#187;</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<div class="section" id="text-rendering-routines">
<h1>Text rendering routines<a class="headerlink" href="#text-rendering-routines" title="Permalink to this headline"></a></h1>
<dl class="class">
<dt id="sdl2.ext.BitmapFont">
<em class="property">class </em><code class="descclassname">sdl2.ext.</code><code class="descname">BitmapFont</code><span class="sig-paren">(</span><em>surface : Sprite, size : iterable[, mapping=None</em><span class="sig-paren">)</span><a class="headerlink" href="#sdl2.ext.BitmapFont" title="Permalink to this definition"></a></dt>
<dd><p>A bitmap graphics to character mapping. The <a class="reference internal" href="#sdl2.ext.BitmapFont" title="sdl2.ext.BitmapFont"><code class="xref py py-class docutils literal"><span class="pre">BitmapFont</span></code></a> class
uses an image <em>surface</em> to find and render font character glyphs for
text. It requires a mapping table, which denotes the characters
available on the image.</p>
<p>The mapping table is a list of strings, where each string reflects a
<em>line</em> of characters on the image. Each character within each line
has the same size as specified by the size argument.</p>
<p>A typical mapping table might look like</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="p">[</span> <span class="s1">&#39;0123456789&#39;</span><span class="p">,</span>
<span class="s1">&#39;ABCDEFGHIJ&#39;</span><span class="p">,</span>
<span class="s1">&#39;KLMNOPQRST&#39;</span><span class="p">,</span>
<span class="s1">&#39;UVWXYZ &#39;</span><span class="p">,</span>
<span class="s1">&#39;abcdefghij&#39;</span><span class="p">,</span>
<span class="s1">&#39;klmnopqrst&#39;</span><span class="p">,</span>
<span class="s1">&#39;uvwxyz &#39;</span><span class="p">,</span>
<span class="s1">&#39;,;.:!?+-()&#39;</span> <span class="p">]</span>
</pre></div>
</div>
<dl class="attribute">
<dt id="sdl2.ext.BitmapFont.surface">
<code class="descname">surface</code><a class="headerlink" href="#sdl2.ext.BitmapFont.surface" title="Permalink to this definition"></a></dt>
<dd><p>The <code class="xref py py-class docutils literal"><span class="pre">sdl2.SDL_Surface</span></code> containing the character bitmaps.</p>
</dd></dl>
<dl class="attribute">
<dt id="sdl2.ext.BitmapFont.offsets">
<code class="descname">offsets</code><a class="headerlink" href="#sdl2.ext.BitmapFont.offsets" title="Permalink to this definition"></a></dt>
<dd><p>A dict containing the character offsets on the <a class="reference internal" href="#sdl2.ext.BitmapFont.surface" title="sdl2.ext.BitmapFont.surface"><code class="xref py py-attr docutils literal"><span class="pre">surface</span></code></a>.</p>
</dd></dl>
<dl class="attribute">
<dt id="sdl2.ext.BitmapFont.mapping">
<code class="descname">mapping</code><a class="headerlink" href="#sdl2.ext.BitmapFont.mapping" title="Permalink to this definition"></a></dt>
<dd><p>The character mapping table, a list of strings.</p>
</dd></dl>
<dl class="attribute">
<dt id="sdl2.ext.BitmapFont.size">
<code class="descname">size</code><a class="headerlink" href="#sdl2.ext.BitmapFont.size" title="Permalink to this definition"></a></dt>
<dd><p>The size of an individual glyph bitmap on the font.</p>
</dd></dl>
<dl class="method">
<dt id="sdl2.ext.BitmapFont.render">
<code class="descname">render</code><span class="sig-paren">(</span><em>text : string</em><span class="optional">[</span>, <em>bpp=None</em><span class="optional">]</span><span class="sig-paren">)</span> &rarr; Sprite<a class="headerlink" href="#sdl2.ext.BitmapFont.render" title="Permalink to this definition"></a></dt>
<dd><p>Renders the passed text on a new <a class="reference internal" href="sdl2ext_sprite.html#sdl2.ext.Sprite" title="sdl2.ext.Sprite"><code class="xref py py-class docutils literal"><span class="pre">Sprite</span></code></a> and returns it.
If no explicit <em>bpp</em> are provided, the bpp settings of the
<a class="reference internal" href="#sdl2.ext.BitmapFont.surface" title="sdl2.ext.BitmapFont.surface"><code class="xref py py-attr docutils literal"><span class="pre">surface</span></code></a> are used.</p>
</dd></dl>
<dl class="method">
<dt id="sdl2.ext.BitmapFont.render_on">
<code class="descname">render_on</code><span class="sig-paren">(</span><em>surface : Sprite, text : string[, offset=(0, 0)]) -&gt; (int, int, int, int</em><span class="sig-paren">)</span><a class="headerlink" href="#sdl2.ext.BitmapFont.render_on" title="Permalink to this definition"></a></dt>
<dd><p>Renders a text on the passed sprite, starting at a specific
offset. The top-left start position of the text will be the
passed <em>offset</em> and a 4-value tuple with the changed area will be
returned.</p>
</dd></dl>
<dl class="method">
<dt id="sdl2.ext.BitmapFont.contains">
<code class="descname">contains</code><span class="sig-paren">(</span><em>c : string</em><span class="sig-paren">)</span> &rarr; bool<a class="headerlink" href="#sdl2.ext.BitmapFont.contains" title="Permalink to this definition"></a></dt>
<dd><p>Checks, whether a certain character exists in the font.</p>
</dd></dl>
<dl class="method">
<dt id="sdl2.ext.BitmapFont.can_render">
<code class="descname">can_render</code><span class="sig-paren">(</span><em>text : string</em><span class="sig-paren">)</span> &rarr; bool<a class="headerlink" href="#sdl2.ext.BitmapFont.can_render" title="Permalink to this definition"></a></dt>
<dd><p>Checks, whether all characters in the passed <em>text</em> can be rendered.</p>
</dd></dl>
</dd></dl>
<dl class="class">
<dt id="sdl2.ext.FontManager">
<em class="property">class </em><code class="descclassname">sdl2.ext.</code><code class="descname">FontManager</code><span class="sig-paren">(</span><em>font_path : str</em><span class="optional">[</span>, <em>alias=None</em><span class="optional">[</span>, <em>size=16</em><span class="optional">[</span>, <em>color=Color(255</em>, <em>255</em>, <em>255)</em><span class="optional">[</span>, <em>bg_color=Color(0</em>, <em>0</em>, <em>0)</em><span class="optional">[</span>, <em>index=0</em><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#sdl2.ext.FontManager" title="Permalink to this definition"></a></dt>
<dd><p>Manage fonts and rendering of text.</p>
<p>One font path must be given to initialise the FontManager.
<a class="reference internal" href="#sdl2.ext.FontManager.default_font" title="sdl2.ext.FontManager.default_font"><code class="xref py py-attr docutils literal"><span class="pre">default_font</span></code></a> will be set to this font. <em>size</em> is the default
font size in pixels. <em>color</em> and <em>bg_color</em> will give the FontManager
a default color. <em>index</em> will select a specific font face from a file
containing multiple font faces. The first face is always at index 0. It can
be used for TTC (TrueType Font Collection) fonts.</p>
<dl class="attribute">
<dt id="sdl2.ext.FontManager.bg_color">
<code class="descname">bg_color</code><a class="headerlink" href="#sdl2.ext.FontManager.bg_color" title="Permalink to this definition"></a></dt>
<dd><p>The <a class="reference internal" href="sdl2ext_color.html#sdl2.ext.Color" title="sdl2.ext.Color"><code class="xref py py-class docutils literal"><span class="pre">sdl2.ext.Color</span></code></a> to be used as background color.</p>
</dd></dl>
<dl class="attribute">
<dt id="sdl2.ext.FontManager.color">
<code class="descname">color</code><a class="headerlink" href="#sdl2.ext.FontManager.color" title="Permalink to this definition"></a></dt>
<dd><p>The <a class="reference internal" href="sdl2ext_color.html#sdl2.ext.Color" title="sdl2.ext.Color"><code class="xref py py-class docutils literal"><span class="pre">sdl2.ext.Color</span></code></a> to be used for rendering text.</p>
</dd></dl>
<dl class="attribute">
<dt id="sdl2.ext.FontManager.default_font">
<code class="descname">default_font</code><a class="headerlink" href="#sdl2.ext.FontManager.default_font" title="Permalink to this definition"></a></dt>
<dd><p>Returns the name of the current default font being used by the
<a class="reference internal" href="#sdl2.ext.FontManager" title="sdl2.ext.FontManager"><code class="xref py py-class docutils literal"><span class="pre">FontManager</span></code></a>. On assigning <a class="reference internal" href="#sdl2.ext.FontManager.default_font" title="sdl2.ext.FontManager.default_font"><code class="xref py py-attr docutils literal"><span class="pre">default_font</span></code></a>,
the value must be a loaded font alias.</p>
</dd></dl>
<dl class="attribute">
<dt id="sdl2.ext.FontManager.size">
<code class="descname">size</code><a class="headerlink" href="#sdl2.ext.FontManager.size" title="Permalink to this definition"></a></dt>
<dd><p>The default font size in pixels.</p>
</dd></dl>
<dl class="method">
<dt id="sdl2.ext.FontManager.add">
<code class="descname">add</code><span class="sig-paren">(</span><em>font_path : str[, alias=None[, size=None[, index=0]]])</em><span class="sig-paren">)</span> &rarr; sdl2.sdlttf.TTF_Font<a class="headerlink" href="#sdl2.ext.FontManager.add" title="Permalink to this definition"></a></dt>
<dd><p>Add a font to the <a class="reference internal" href="#sdl2.ext.FontManager" title="sdl2.ext.FontManager"><code class="xref py py-class docutils literal"><span class="pre">FontManager</span></code></a>. <em>alias</em> is by default the
font name, any other name can be passed, <em>size</em> is the font size
in pixels and defaults to <a class="reference internal" href="#sdl2.ext.FontManager.size" title="sdl2.ext.FontManager.size"><code class="xref py py-attr docutils literal"><span class="pre">size</span></code></a>. <em>index</em> selects a specific font
face from a TTC (TrueType Font Collection) file. Returns the font pointer
stored in <code class="xref py py-attr docutils literal"><span class="pre">fonts</span></code>.</p>
</dd></dl>
<dl class="method">
<dt id="sdl2.ext.FontManager.close">
<code class="descname">close</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#sdl2.ext.FontManager.close" title="Permalink to this definition"></a></dt>
<dd><p>Closes all fonts used by the <a class="reference internal" href="#sdl2.ext.FontManager" title="sdl2.ext.FontManager"><code class="xref py py-class docutils literal"><span class="pre">FontManager</span></code></a>.</p>
</dd></dl>
<dl class="method">
<dt id="sdl2.ext.FontManager.render">
<code class="descname">render</code><span class="sig-paren">(</span><em>text : str</em><span class="optional">[</span>, <em>alias=None</em><span class="optional">[</span>, <em>size=None</em><span class="optional">[</span>, <em>width=None</em><span class="optional">[</span>, <em>color=None</em><span class="optional">[</span>, <em>bg_color=None</em><span class="optional">[</span>, <em>**kwargs</em><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span> &rarr; sdl2.SDL_Surface<a class="headerlink" href="#sdl2.ext.FontManager.render" title="Permalink to this definition"></a></dt>
<dd><p>Renders text to a surface. This method uses the font designated by
the passed <em>alias</em> or, if <em>alias</em> is omitted, by the set
<a class="reference internal" href="#sdl2.ext.FontManager.default_font" title="sdl2.ext.FontManager.default_font"><code class="xref py py-attr docutils literal"><span class="pre">default_font</span></code></a>. A <em>size</em> can be passed even if the font was
not loaded with this size. A <em>width</em> can be given for automatic line
wrapping. If no <em>bg_color</em> or <em>color</em> are given, it will default to
the FontManager&#8217;s <a class="reference internal" href="#sdl2.ext.FontManager.bg_color" title="sdl2.ext.FontManager.bg_color"><code class="xref py py-attr docutils literal"><span class="pre">bg_color</span></code></a> and <a class="reference internal" href="#sdl2.ext.FontManager.color" title="sdl2.ext.FontManager.color"><code class="xref py py-attr docutils literal"><span class="pre">color</span></code></a>.</p>
</dd></dl>
</dd></dl>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<h4>Previous topic</h4>
<p class="topless"><a href="sdl2ext_events.html"
title="previous chapter">General purpose event handling routines</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="sdl2ext_gui.html"
title="next chapter">User interface elements</a></p>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../_sources/modules/sdl2ext_font.txt"
rel="nofollow">Show Source</a></li>
</ul>
</div>
<div id="searchbox" style="display: none" role="search">
<h3>Quick search</h3>
<form class="search" action="../search.html" method="get">
<div><input type="text" name="q" /></div>
<div><input type="submit" value="Go" /></div>
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="sdl2ext_gui.html" title="User interface elements"
>next</a> |</li>
<li class="right" >
<a href="sdl2ext_events.html" title="General purpose event handling routines"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../index.html">PySDL2 0.9.5 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="index.html" >API reference</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="sdl2ext.html" >sdl2.ext - Python extensions for SDL2</a> &#187;</li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2013-2016, Marcus von Appen.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.4.6.
</div>
</body>
</html>