dlangui/docs/fonts.html

365 lines
13 KiB
HTML

<html><head>
<META http-equiv="content-type" content="text/html; charset=utf-8">
<title>dlangui.graphics.fonts</title>
</head><body>
<h1>dlangui.graphics.fonts</h1>
<!-- Generated by Ddoc from src/dlangui/graphics/fonts.d -->
DLANGUI library.
<br><br>
This module contains base <u>fonts</u> access interface and common implementation.
<br><br>
Font - base class for <u>fonts</u>.
<br><br>
FontManager - base class for font managers - provides access to available <u>fonts</u>.
<br><br>
<br><br>
Actual implementation is:
<br><br>
dlangui.graphics.ftfonts - FreeType based font manager.
<br><br>
dlangui.platforms.windows.w32fonts - Win32 API based font manager.
<br><br>
<br><br>
To enable OpenGL support, build with version(USE_OPENGL);
<br><br>
<b>See Also:</b><br>
dlangui.graphics.drawbuf, DrawBuf, drawbuf, drawbuf.html
<br><br>
<br><br>
<br><br>
<b>Synopsis:</b><br>
<pre class="d_code"><font color=blue>import</font> dlangui.graphics.<u>fonts</u>;
<font color=green>// find suitable font of size 25, normal, preferrable Arial, or, if not available, any SansSerif font
</font>FontRef font = FontManager.instance.getFont(25, FontWeight.Normal, <font color=blue>false</font>, FontFamily.SansSerif, <font color=red>"Arial"</font>);
dstring sampleText = <font color=red>"Sample text to draw"d</font>;
<font color=green>// measure text string width and height (one line)
</font>Point sz = font.textSize(sampleText);
<font color=green>// draw red text at center of DrawBuf buf
</font>font.drawText(buf, buf.width / 2 - sz.x/2, buf.height / 2 - sz.y / 2, sampleText, 0xFF0000);
</pre>
<br><br>
<b>License:</b><br>
Boost License 1.0
<br><br>
<b>Authors:</b><br>
Vadim Lopatin, coolreader.org@gmail.com<br><br>
<dl><dt><big><a name="FontFamily"></a>enum <u>FontFamily</u>: ubyte;
</big></dt>
<dd>font families enum<br><br>
<dl><dt><big><a name="FontFamily.Unspecified"></a><u>Unspecified</u></big></dt>
<dd>Unknown / not set / does not matter<br><br>
</dd>
<dt><big><a name="FontFamily.SansSerif"></a><u>SansSerif</u></big></dt>
<dd>Sans Serif font, e.g. Arial<br><br>
</dd>
<dt><big><a name="FontFamily.Serif"></a><u>Serif</u></big></dt>
<dd><u>Serif</u> font, e.g. Times New Roman<br><br>
</dd>
<dt><big><a name="FontFamily.Fantasy"></a><u>Fantasy</u></big></dt>
<dd><u>Fantasy</u> font<br><br>
</dd>
<dt><big><a name="FontFamily.Cursive"></a><u>Cursive</u></big></dt>
<dd><u>Cursive</u> font<br><br>
</dd>
<dt><big><a name="FontFamily.MonoSpace"></a><u>MonoSpace</u></big></dt>
<dd>Monospace font (fixed pitch font), e.g. Courier New<br><br>
</dd>
</dl>
</dd>
<dt><big><a name="FontWeight"></a>enum <u>FontWeight</u>: int;
</big></dt>
<dd>font weight constants (0..1000)<br><br>
<dl><dt><big><a name="FontWeight.Normal"></a><u>Normal</u></big></dt>
<dd>normal font weight<br><br>
</dd>
<dt><big><a name="FontWeight.Bold"></a><u>Bold</u></big></dt>
<dd>bold font<br><br>
</dd>
</dl>
</dd>
<dt><big><a name="glyphDestroyCallback"></a>@property void function(uint id) <u>glyphDestroyCallback</u>();
</big></dt>
<dd>get glyph destroy callback (to cleanup OpenGL caches)
<br><br>
Used for resource management. Usually you don't have to call it manually.<br><br>
</dd>
<dt><big><a name="glyphDestroyCallback"></a>@property void <u>glyphDestroyCallback</u>(void function(uint id) <i>callback</i>);
</big></dt>
<dd>Set glyph destroy <i>callback</i> (to cleanup OpenGL caches)
This <i>callback</i> is used to tell OpenGL glyph cache that glyph is not more used - to let OpenGL glyph cache delete texture if all glyphs in it are no longer used.
<br><br>
Used for resource management. Usually you don't have to call it manually.<br><br>
</dd>
<dt><big><a name="nextGlyphId"></a>uint <u>nextGlyphId</u>();
</big></dt>
<dd>ID generator for glyphs
<br><br>
Generates next glyph ID. Unique IDs are being used to control OpenGL glyph cache items lifetime.
<br><br>
Used for resource management. Usually you don't have to call it manually.<br><br>
</dd>
<dt><big><a name="MAX_WIDTH_UNSPECIFIED"></a>immutable int <u>MAX_WIDTH_UNSPECIFIED</u>;
</big></dt>
<dd>constant for measureText maxWidth paramenter - to tell that all characters of text string should be measured.<br><br>
</dd>
<dt><big><a name="Font"></a>abstract class <u>Font</u>: dlangui.core.types.RefCountedObject;
</big></dt>
<dd>Instance of font with specific size, weight, face, etc.
<br><br>
Allows to measure text string and draw it on DrawBuf
<br><br>
Use FontManager.instance.getFont() to retrieve font instance.<br><br>
<dl><dt><big><a name="Font.size"></a>abstract @property int <u>size</u>();
</big></dt>
<dd>returns font <u>size</u> (as requested from font engine)<br><br>
</dd>
<dt><big><a name="Font.height"></a>abstract @property int <u>height</u>();
</big></dt>
<dd>returns actual font <u>height</u> including interline space<br><br>
</dd>
<dt><big><a name="Font.weight"></a>abstract @property int <u>weight</u>();
</big></dt>
<dd>returns font <u>weight</u><br><br>
</dd>
<dt><big><a name="Font.baseline"></a>abstract @property int <u>baseline</u>();
</big></dt>
<dd>returns <u>baseline</u> offset<br><br>
</dd>
<dt><big><a name="Font.italic"></a>abstract @property bool <u>italic</u>();
</big></dt>
<dd>returns <b>true</b> if font is <u>italic</u><br><br>
</dd>
<dt><big><a name="Font.face"></a>abstract @property string <u>face</u>();
</big></dt>
<dd>returns font <u>face</u> name<br><br>
</dd>
<dt><big><a name="Font.family"></a>abstract @property FontFamily <u>family</u>();
</big></dt>
<dd>returns font <u>family</u><br><br>
</dd>
<dt><big><a name="Font.isNull"></a>abstract @property bool <u>isNull</u>();
</big></dt>
<dd>returns <b>true</b> if font object is not yet initialized / loaded<br><br>
</dd>
<dt><big><a name="Font.isFixed"></a>@property bool <u>isFixed</u>();
</big></dt>
<dd>returns <b>true</b> if font has fixed pitch (all characters have equal width)<br><br>
</dd>
<dt><big><a name="Font.spaceWidth"></a>@property int <u>spaceWidth</u>();
</big></dt>
<dd>returns <b>true</b> if font is fixed<br><br>
</dd>
<dt><big><a name="Font.charWidth"></a>int <u>charWidth</u>(dchar <i>ch</i>);
</big></dt>
<dd>returns character width<br><br>
</dd>
<dt><big><a name="Font.measureText"></a>int <u>measureText</u>(const dchar[] <i>text</i>, ref int[] <i>widths</i>, int <i>maxWidth</i> = MAX_WIDTH_UNSPECIFIED, int <i>tabSize</i> = 4, int <i>tabOffset</i> = 0, uint <i>textFlags</i> = 0);
</big></dt>
<dd>Measure <i>text</i> string, return accumulated <i>widths</i>[] (distance to end of n-th character), returns number of measured chars.
<br><br>
Supports Tab character processing and processing of menu item labels like '&File'.
<br><br>
<b>Params:</b><br>
<table><tr><td>dchar[] <i>text</i></td>
<td><i>text</i> string to measure</td></tr>
<tr><td>int[] <i>widths</i></td>
<td>output buffer to put measured <i>widths</i> (<i>widths</i>[i] will be set to cumulative <i>widths</i> <i>text</i>[0..i])</td></tr>
<tr><td>int <i>maxWidth</i></td>
<td>maximum width to measure - measure is stopping if max width is reached (pass MAX_WIDTH_UNSPECIFIED to measure all characters)</td></tr>
<tr><td>int <i>tabSize</i></td>
<td>tabulation size, in number of spaces</td></tr>
<tr><td>int <i>tabOffset</i></td>
<td>when string is drawn not from left position, use to move tab stops left/right</td></tr>
<tr><td>uint <i>textFlags</i></td>
<td>TextFlag bit set - to control underline, hotkey label processing, etc...</td></tr>
</table><br>
<b>Returns:</b><br>
number of characters measured (may be less than <i>text</i>.length if <i>maxWidth</i> is reached)<br><br>
</dd>
<dt><big><a name="Font.textSize"></a>Point <u>textSize</u>(const dchar[] <i>text</i>, int <i>maxWidth</i> = MAX_WIDTH_UNSPECIFIED, int <i>tabSize</i> = 4, int <i>tabOffset</i> = 0, uint <i>textFlags</i> = 0);
</big></dt>
<dd>Measure <i>text</i> string as single line, returns width and height
<br><br>
<b>Params:</b><br>
<table><tr><td>dchar[] <i>text</i></td>
<td><i>text</i> string to measure</td></tr>
<tr><td>int <i>maxWidth</i></td>
<td>maximum width - measure is stopping if max width is reached</td></tr>
<tr><td>int <i>tabSize</i></td>
<td>tabulation size, in number of spaces</td></tr>
<tr><td>int <i>tabOffset</i></td>
<td>when string is drawn not from left position, use to move tab stops left/right</td></tr>
<tr><td>uint <i>textFlags</i></td>
<td>TextFlag bit set - to control underline, hotkey label processing, etc...</td></tr>
</table><br>
</dd>
<dt><big><a name="Font.drawText"></a>void <u>drawText</u>(DrawBuf <i>buf</i>, int <i>x</i>, int <i>y</i>, const dchar[] <i>text</i>, uint <i>color</i>, int <i>tabSize</i> = 4, int <i>tabOffset</i> = 0, uint <i>textFlags</i> = 0);
</big></dt>
<dd>Draw <i>text</i> string to buffer.
<br><br>
<b>Params:</b><br>
<table><tr><td>DrawBuf <i>buf</i></td>
<td>graphics buffer to draw <i>text</i> to</td></tr>
<tr><td>int <i>x</i></td>
<td><i>x</i> coordinate to draw first character at</td></tr>
<tr><td>int <i>y</i></td>
<td><i>y</i> coordinate to draw first character at</td></tr>
<tr><td>dchar[] <i>text</i></td>
<td><i>text</i> string to draw</td></tr>
<tr><td>uint <i>color</i></td>
<td><i>color</i> for drawing of glyphs</td></tr>
<tr><td>int <i>tabSize</i></td>
<td>tabulation size, in number of spaces</td></tr>
<tr><td>int <i>tabOffset</i></td>
<td>when string is drawn not from left position, use to move tab stops left/right</td></tr>
<tr><td>uint <i>textFlags</i></td>
<td>set of TextFlag bit fields</td></tr>
</table><br>
</dd>
<dt><big><a name="Font.getCharGlyph"></a>abstract Glyph* <u>getCharGlyph</u>(dchar <i>ch</i>, bool <i>withImage</i> = true);
</big></dt>
<dd>get character glyph information<br><br>
</dd>
<dt><big><a name="Font.checkpoint"></a>abstract void <u>checkpoint</u>();
</big></dt>
<dd>clear usage flags for all entries<br><br>
</dd>
<dt><big><a name="Font.cleanup"></a>abstract void <u>cleanup</u>();
</big></dt>
<dd>removes entries not used after last call of checkpoint() or <u>cleanup</u>()<br><br>
</dd>
</dl>
</dd>
<dt><big><a name="FontList"></a>struct <u>FontList</u>;
</big></dt>
<dd>font instance collection - utility class, for font manager implementations<br><br>
</dd>
<dt><big><a name="FontManager"></a>abstract class <u>FontManager</u>;
</big></dt>
<dd>Access points to fonts.<br><br>
<dl><dt><big><a name="FontManager.instance"></a>static @property void <u>instance</u>(FontManager <i>manager</i>);
</big></dt>
<dd>sets new font <i>manager</i> singleton <u>instance</u><br><br>
</dd>
<dt><big><a name="FontManager.instance"></a>static @property FontManager <u>instance</u>();
</big></dt>
<dd>returns font manager singleton <u>instance</u><br><br>
</dd>
<dt><big><a name="FontManager.getFont"></a>abstract ref FontRef <u>getFont</u>(int <i>size</i>, int <i>weight</i>, bool <i>italic</i>, FontFamily <i>family</i>, string <i>face</i>);
</big></dt>
<dd>get font instance best matched specified parameters<br><br>
</dd>
<dt><big><a name="FontManager.checkpoint"></a>abstract void <u>checkpoint</u>();
</big></dt>
<dd>clear usage flags for all entries -- for cleanup of unused fonts<br><br>
</dd>
<dt><big><a name="FontManager.cleanup"></a>abstract void <u>cleanup</u>();
</big></dt>
<dd>removes entries not used after last call of checkpoint() or <u>cleanup</u>()<br><br>
</dd>
</dl>
</dd>
<dt><big><a name="GlyphCache"></a>struct <u>GlyphCache</u>;
</big></dt>
<dd>Glyph image cache
<br><br>
Recently used glyphs are marked with glyph.lastUsage = 1
<br><br>
checkpoint() call clears usage marks
<br><br>
cleanup() removes all items not accessed since last checkpoint()<br><br>
<dl><dt><big><a name="GlyphCache.find"></a>Glyph* <u>find</u>(dchar <i>ch</i>);
</big></dt>
<dd>try to <u>find</u> glyph for character in cache, returns <b>null</b> if not found<br><br>
</dd>
<dt><big><a name="GlyphCache.put"></a>Glyph* <u>put</u>(dchar <i>ch</i>, Glyph* <i>glyph</i>);
</big></dt>
<dd><u>put</u> character <i>glyph</i> to cache<br><br>
</dd>
<dt><big><a name="GlyphCache.cleanup"></a>void <u>cleanup</u>();
</big></dt>
<dd>removes entries not used after last call of checkpoint() or <u>cleanup</u>()<br><br>
</dd>
<dt><big><a name="GlyphCache.checkpoint"></a>void <u>checkpoint</u>();
</big></dt>
<dd>clear usage flags for all entries<br><br>
</dd>
<dt><big><a name="GlyphCache.clear"></a>void <u>clear</u>();
</big></dt>
<dd>removes all entries (when built with USE_OPENGL version, notify OpenGL cache about removed glyphs)<br><br>
</dd>
</dl>
</dd>
</dl>
<hr><small>Page generated by <a href="http://dlang.org/ddoc.html">Ddoc</a>. Vadim Lopatin, 2014
</small>
</body></html>