cairo-ft-font.html   [plain text]


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>FreeType Fonts</title>
<meta name="generator" content="DocBook XSL Stylesheets V1.73.2">
<link rel="start" href="index.html" title="Cairo: A Vector Graphics Library">
<link rel="up" href="cairo-fonts.html" title="Fonts">
<link rel="prev" href="cairo-font-options.html" title="cairo_font_options_t">
<link rel="next" href="cairo-win32-font.html" title="Win32 Fonts">
<meta name="generator" content="GTK-Doc V1.11 (XML mode)">
<link rel="stylesheet" href="style.css" type="text/css">
<link rel="chapter" href="cairo-drawing.html" title="Drawing">
<link rel="chapter" href="cairo-fonts.html" title="Fonts">
<link rel="chapter" href="cairo-surfaces.html" title="Surfaces">
<link rel="chapter" href="cairo-support.html" title="Utilities">
<link rel="index" href="index-all.html" title="Index">
<link rel="index" href="index-1.2.html" title="Index of new symbols in 1.2">
<link rel="index" href="index-1.4.html" title="Index of new symbols in 1.4">
<link rel="index" href="index-1.6.html" title="Index of new symbols in 1.6">
<link rel="index" href="index-1.8.html" title="Index of new symbols in 1.8">
<link rel="appendix" href="language-bindings.html" title="Appendix A. Creating a language binding for cairo">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2">
<tr valign="middle">
<td><a accesskey="p" href="cairo-font-options.html"><img src="left.png" width="24" height="24" border="0" alt="Prev"></a></td>
<td><a accesskey="u" href="cairo-fonts.html"><img src="up.png" width="24" height="24" border="0" alt="Up"></a></td>
<td><a accesskey="h" href="index.html"><img src="home.png" width="24" height="24" border="0" alt="Home"></a></td>
<th width="100%" align="center">Cairo: A Vector Graphics Library</th>
<td><a accesskey="n" href="cairo-win32-font.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></a></td>
</tr>
<tr><td colspan="5" class="shortcuts">
<a href="#cairo-ft-font.synopsis" class="shortcut">Top</a>
                 | 
                <a href="#cairo-ft-font.description" class="shortcut">Description</a>
</td></tr>
</table>
<div class="refentry" lang="en">
<a name="cairo-ft-font"></a><div class="titlepage"></div>
<div class="refnamediv"><table width="100%"><tr>
<td valign="top">
<h2><span class="refentrytitle"><a name="cairo-ft-font.top_of_page"></a>FreeType Fonts</span></h2>
<p>FreeType Fonts — Font support for FreeType</p>
</td>
<td valign="top" align="right"></td>
</tr></table></div>
<div class="refsynopsisdiv">
<a name="cairo-ft-font.synopsis"></a><h2>Synopsis</h2>
<pre class="synopsis">
#define             <a class="link" href="cairo-ft-font.html#CAIRO-HAS-FT-FONT--CAPS" title="CAIRO_HAS_FT_FONT">CAIRO_HAS_FT_FONT</a>
<a class="link" href="cairo-font-face.html#cairo-font-face-t" title="cairo_font_face_t">cairo_font_face_t</a> * <a class="link" href="cairo-ft-font.html#cairo-ft-font-face-create-for-ft-face" title="cairo_ft_font_face_create_for_ft_face ()">cairo_ft_font_face_create_for_ft_face</a>
                                                        (FT_Face face,
                                                         int load_flags);
<a class="link" href="cairo-font-face.html#cairo-font-face-t" title="cairo_font_face_t">cairo_font_face_t</a> * <a class="link" href="cairo-ft-font.html#cairo-ft-font-face-create-for-pattern" title="cairo_ft_font_face_create_for_pattern ()">cairo_ft_font_face_create_for_pattern</a>
                                                        (FcPattern *pattern);
void                <a class="link" href="cairo-ft-font.html#cairo-ft-font-options-substitute" title="cairo_ft_font_options_substitute ()">cairo_ft_font_options_substitute</a>    (const <a class="link" href="cairo-font-options.html#cairo-font-options-t" title="cairo_font_options_t">cairo_font_options_t</a> *options,
                                                         FcPattern *pattern);
FT_Face             <a class="link" href="cairo-ft-font.html#cairo-ft-scaled-font-lock-face" title="cairo_ft_scaled_font_lock_face ()">cairo_ft_scaled_font_lock_face</a>      (<a class="link" href="cairo-scaled-font.html#cairo-scaled-font-t" title="cairo_scaled_font_t">cairo_scaled_font_t</a> *scaled_font);
void                <a class="link" href="cairo-ft-font.html#cairo-ft-scaled-font-unlock-face" title="cairo_ft_scaled_font_unlock_face ()">cairo_ft_scaled_font_unlock_face</a>    (<a class="link" href="cairo-scaled-font.html#cairo-scaled-font-t" title="cairo_scaled_font_t">cairo_scaled_font_t</a> *scaled_font);
</pre>
</div>
<div class="refsect1" lang="en">
<a name="cairo-ft-font.description"></a><h2>Description</h2>
<p>
The FreeType font backend is primarily used to render text on GNU/Linux
systems, but can be used on other platforms too.
</p>
</div>
<div class="refsect1" lang="en">
<a name="cairo-ft-font.details"></a><h2>Details</h2>
<div class="refsect2" lang="en">
<a name="CAIRO-HAS-FT-FONT--CAPS"></a><h3>CAIRO_HAS_FT_FONT</h3>
<pre class="programlisting">#define CAIRO_HAS_FT_FONT 1
</pre>
<p>
Defined if the FreeType font backend is available.
This macro can be used to conditionally compile backend-specific code.
</p>
</div>
<hr>
<div class="refsect2" lang="en">
<a name="cairo-ft-font-face-create-for-ft-face"></a><h3>cairo_ft_font_face_create_for_ft_face ()</h3>
<pre class="programlisting"><a class="link" href="cairo-font-face.html#cairo-font-face-t" title="cairo_font_face_t">cairo_font_face_t</a> * cairo_ft_font_face_create_for_ft_face
                                                        (FT_Face face,
                                                         int load_flags);</pre>
<p>
Creates a new font face for the FreeType font backend from a
pre-opened FreeType face. This font can then be used with
<a class="link" href="cairo-text.html#cairo-set-font-face" title="cairo_set_font_face ()"><code class="function">cairo_set_font_face()</code></a> or <a class="link" href="cairo-scaled-font.html#cairo-scaled-font-create" title="cairo_scaled_font_create ()"><code class="function">cairo_scaled_font_create()</code></a>. The
<a class="link" href="cairo-scaled-font.html#cairo-scaled-font-t" title="cairo_scaled_font_t"><span class="type">cairo_scaled_font_t</span></a> returned from <a class="link" href="cairo-scaled-font.html#cairo-scaled-font-create" title="cairo_scaled_font_create ()"><code class="function">cairo_scaled_font_create()</code></a> is
also for the FreeType backend and can be used with functions such
as <a class="link" href="cairo-ft-font.html#cairo-ft-scaled-font-lock-face" title="cairo_ft_scaled_font_lock_face ()"><code class="function">cairo_ft_scaled_font_lock_face()</code></a>. Note that Cairo may keep a reference
to the FT_Face alive in a font-cache and the exact lifetime of the reference
depends highly upon the exact usage pattern and is subject to external
factors. You must not call <code class="function">FT_Done_Face()</code> before the last reference to the
<a class="link" href="cairo-font-face.html#cairo-font-face-t" title="cairo_font_face_t"><span class="type">cairo_font_face_t</span></a> has been dropped.
</p>
<p>
As an example, below is how one might correctly couple the lifetime of
the FreeType face object to the <a class="link" href="cairo-font-face.html#cairo-font-face-t" title="cairo_font_face_t"><span class="type">cairo_font_face_t</span></a>.
</p>
<p>
</p>
<div class="informalexample"><pre class="programlisting">
static const cairo_user_data_key_t key;

font_face = cairo_ft_font_face_create_for_ft_face (ft_face, 0);
status = cairo_font_face_set_user_data (font_face, &amp;key,
                               ft_face, (cairo_destroy_func_t) FT_Done_Face);
if (status) {
   cairo_font_face_destroy (font_face);
   FT_Done_Face (ft_face);
   return ERROR;
}
</pre></div>
<p>
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>face</code></em> :</span></p></td>
<td> A FreeType face object, already opened. This must
  be kept around until the face's ref_count drops to
  zero and it is freed. Since the face may be referenced
  internally to Cairo, the best way to determine when it
  is safe to free the face is to pass a
  <a class="link" href="cairo-types.html#cairo-destroy-func-t" title="cairo_destroy_func_t ()"><span class="type">cairo_destroy_func_t</span></a> to <a class="link" href="cairo-font-face.html#cairo-font-face-set-user-data" title="cairo_font_face_set_user_data ()"><code class="function">cairo_font_face_set_user_data()</code></a>
</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>load_flags</code></em> :</span></p></td>
<td> flags to pass to FT_Load_Glyph when loading
  glyphs from the font. These flags are OR'ed together with
  the flags derived from the <a class="link" href="cairo-font-options.html#cairo-font-options-t" title="cairo_font_options_t"><span class="type">cairo_font_options_t</span></a> passed
  to <a class="link" href="cairo-scaled-font.html#cairo-scaled-font-create" title="cairo_scaled_font_create ()"><code class="function">cairo_scaled_font_create()</code></a>, so only a few values such
  as <code class="literal">FT_LOAD_VERTICAL_LAYOUT</code>, and <code class="literal">FT_LOAD_FORCE_AUTOHINT</code>
  are useful. You should not pass any of the flags affecting
  the load target, such as <code class="literal">FT_LOAD_TARGET_LIGHT</code>.
</td>
</tr>
<tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
<td> a newly created <a class="link" href="cairo-font-face.html#cairo-font-face-t" title="cairo_font_face_t"><span class="type">cairo_font_face_t</span></a>. Free with
 <a class="link" href="cairo-font-face.html#cairo-font-face-destroy" title="cairo_font_face_destroy ()"><code class="function">cairo_font_face_destroy()</code></a> when you are done using it.
</td>
</tr>
</tbody>
</table></div>
</div>
<hr>
<div class="refsect2" lang="en">
<a name="cairo-ft-font-face-create-for-pattern"></a><h3>cairo_ft_font_face_create_for_pattern ()</h3>
<pre class="programlisting"><a class="link" href="cairo-font-face.html#cairo-font-face-t" title="cairo_font_face_t">cairo_font_face_t</a> * cairo_ft_font_face_create_for_pattern
                                                        (FcPattern *pattern);</pre>
<p>
Creates a new font face for the FreeType font backend based on a
fontconfig pattern. This font can then be used with
<a class="link" href="cairo-text.html#cairo-set-font-face" title="cairo_set_font_face ()"><code class="function">cairo_set_font_face()</code></a> or <a class="link" href="cairo-scaled-font.html#cairo-scaled-font-create" title="cairo_scaled_font_create ()"><code class="function">cairo_scaled_font_create()</code></a>. The
<a class="link" href="cairo-scaled-font.html#cairo-scaled-font-t" title="cairo_scaled_font_t"><span class="type">cairo_scaled_font_t</span></a> returned from <a class="link" href="cairo-scaled-font.html#cairo-scaled-font-create" title="cairo_scaled_font_create ()"><code class="function">cairo_scaled_font_create()</code></a> is
also for the FreeType backend and can be used with functions such
as <a class="link" href="cairo-ft-font.html#cairo-ft-scaled-font-lock-face" title="cairo_ft_scaled_font_lock_face ()"><code class="function">cairo_ft_scaled_font_lock_face()</code></a>.
</p>
<p>
Font rendering options are represented both here and when you
call <a class="link" href="cairo-scaled-font.html#cairo-scaled-font-create" title="cairo_scaled_font_create ()"><code class="function">cairo_scaled_font_create()</code></a>. Font options that have a representation
in a <span class="type">FcPattern</span> must be passed in here; to modify <span class="type">FcPattern</span>
appropriately to reflect the options in a <a class="link" href="cairo-font-options.html#cairo-font-options-t" title="cairo_font_options_t"><span class="type">cairo_font_options_t</span></a>, call
<a class="link" href="cairo-ft-font.html#cairo-ft-font-options-substitute" title="cairo_ft_font_options_substitute ()"><code class="function">cairo_ft_font_options_substitute()</code></a>.
</p>
<p>
The pattern's FC_FT_FACE element is inspected first and if that is set,
that will be the FreeType font face associated with the returned cairo
font face.  Otherwise the FC_FILE and FC_INDEX elements of <em class="parameter"><code>pattern</code></em> are
used to load a font face from file.
</p>
<p>
If the FC_FT_FACE element of <em class="parameter"><code>pattern</code></em> is set, the user is responsible
for making sure that the referenced FT_Face remains valid for the life
time of the returned <a class="link" href="cairo-font-face.html#cairo-font-face-t" title="cairo_font_face_t"><span class="type">cairo_font_face_t</span></a>.  See
<a class="link" href="cairo-ft-font.html#cairo-ft-font-face-create-for-ft-face" title="cairo_ft_font_face_create_for_ft_face ()"><code class="function">cairo_ft_font_face_create_for_ft_face()</code></a> for an exmaple of how to couple
the life time of the FT_Face to that of the cairo font-face.</p>
<p>
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>pattern</code></em> :</span></p></td>
<td> A fully resolved fontconfig
  pattern. A pattern can be resolved, by, among other things, calling
  <code class="function">FcConfigSubstitute()</code>, <code class="function">FcDefaultSubstitute()</code>, then
  <code class="function">FcFontMatch()</code>. Cairo will call <code class="function">FcPatternReference()</code> on this
  pattern, so you should not further modify the pattern, but you can
  release your reference to the pattern with <code class="function">FcPatternDestroy()</code> if
  you no longer need to access it.
</td>
</tr>
<tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
<td> a newly created <a class="link" href="cairo-font-face.html#cairo-font-face-t" title="cairo_font_face_t"><span class="type">cairo_font_face_t</span></a>. Free with
 <a class="link" href="cairo-font-face.html#cairo-font-face-destroy" title="cairo_font_face_destroy ()"><code class="function">cairo_font_face_destroy()</code></a> when you are done using it.
</td>
</tr>
</tbody>
</table></div>
</div>
<hr>
<div class="refsect2" lang="en">
<a name="cairo-ft-font-options-substitute"></a><h3>cairo_ft_font_options_substitute ()</h3>
<pre class="programlisting">void                cairo_ft_font_options_substitute    (const <a class="link" href="cairo-font-options.html#cairo-font-options-t" title="cairo_font_options_t">cairo_font_options_t</a> *options,
                                                         FcPattern *pattern);</pre>
<p>
Add options to a <span class="type">FcPattern</span> based on a <a class="link" href="cairo-font-options.html#cairo-font-options-t" title="cairo_font_options_t"><span class="type">cairo_font_options_t</span></a> font
options object. Options that are already in the pattern, are not overridden,
so you should call this function after calling <code class="function">FcConfigSubstitute()</code> (the
user's settings should override options based on the surface type), but
before calling <code class="function">FcDefaultSubstitute()</code>.</p>
<p>
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>options</code></em> :</span></p></td>
<td> a <a class="link" href="cairo-font-options.html#cairo-font-options-t" title="cairo_font_options_t"><span class="type">cairo_font_options_t</span></a> object
</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>pattern</code></em> :</span></p></td>
<td> an existing <span class="type">FcPattern</span>
</td>
</tr>
</tbody>
</table></div>
</div>
<hr>
<div class="refsect2" lang="en">
<a name="cairo-ft-scaled-font-lock-face"></a><h3>cairo_ft_scaled_font_lock_face ()</h3>
<pre class="programlisting">FT_Face             cairo_ft_scaled_font_lock_face      (<a class="link" href="cairo-scaled-font.html#cairo-scaled-font-t" title="cairo_scaled_font_t">cairo_scaled_font_t</a> *scaled_font);</pre>
<p>
<a class="link" href="cairo-ft-font.html#cairo-ft-scaled-font-lock-face" title="cairo_ft_scaled_font_lock_face ()"><code class="function">cairo_ft_scaled_font_lock_face()</code></a> gets the <span class="type">FT_Face</span> object from a FreeType
backend font and scales it appropriately for the font. You must
release the face with <a class="link" href="cairo-ft-font.html#cairo-ft-scaled-font-unlock-face" title="cairo_ft_scaled_font_unlock_face ()"><code class="function">cairo_ft_scaled_font_unlock_face()</code></a>
when you are done using it.  Since the <span class="type">FT_Face</span> object can be
shared between multiple <a class="link" href="cairo-scaled-font.html#cairo-scaled-font-t" title="cairo_scaled_font_t"><span class="type">cairo_scaled_font_t</span></a> objects, you must not
lock any other font objects until you unlock this one. A count is
kept of the number of times <a class="link" href="cairo-ft-font.html#cairo-ft-scaled-font-lock-face" title="cairo_ft_scaled_font_lock_face ()"><code class="function">cairo_ft_scaled_font_lock_face()</code></a> is
called. <a class="link" href="cairo-ft-font.html#cairo-ft-scaled-font-unlock-face" title="cairo_ft_scaled_font_unlock_face ()"><code class="function">cairo_ft_scaled_font_unlock_face()</code></a> must be called the same number
of times.
</p>
<p>
You must be careful when using this function in a library or in a
threaded application, because freetype's design makes it unsafe to
call freetype functions simultaneously from multiple threads, (even
if using distinct FT_Face objects). Because of this, application
code that acquires an FT_Face object with this call must add it's
own locking to protect any use of that object, (and which also must
protect any other calls into cairo as almost any cairo function
might result in a call into the freetype library).</p>
<p>
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>scaled_font</code></em> :</span></p></td>
<td> A <a class="link" href="cairo-scaled-font.html#cairo-scaled-font-t" title="cairo_scaled_font_t"><span class="type">cairo_scaled_font_t</span></a> from the FreeType font backend. Such an
  object can be created by calling <a class="link" href="cairo-scaled-font.html#cairo-scaled-font-create" title="cairo_scaled_font_create ()"><code class="function">cairo_scaled_font_create()</code></a> on a
  FreeType backend font face (see <a class="link" href="cairo-ft-font.html#cairo-ft-font-face-create-for-pattern" title="cairo_ft_font_face_create_for_pattern ()"><code class="function">cairo_ft_font_face_create_for_pattern()</code></a>,
  <a class="link" href="cairo-ft-font.html#cairo-ft-font-face-create-for-ft-face" title="cairo_ft_font_face_create_for_ft_face ()"><code class="function">cairo_ft_font_face_create_for_ft_face()</code></a>).
</td>
</tr>
<tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
<td> The <span class="type">FT_Face</span> object for <em class="parameter"><code>font</code></em>, scaled appropriately,
or <a
href="/usr/share/gtk-doc/html/glib/glib-Standard-Macros.html#NULL--CAPS"
><code class="literal">NULL</code></a> if <em class="parameter"><code>scaled_font</code></em> is in an error state (see
<a class="link" href="cairo-scaled-font.html#cairo-scaled-font-status" title="cairo_scaled_font_status ()"><code class="function">cairo_scaled_font_status()</code></a>) or there is insufficient memory.
</td>
</tr>
</tbody>
</table></div>
</div>
<hr>
<div class="refsect2" lang="en">
<a name="cairo-ft-scaled-font-unlock-face"></a><h3>cairo_ft_scaled_font_unlock_face ()</h3>
<pre class="programlisting">void                cairo_ft_scaled_font_unlock_face    (<a class="link" href="cairo-scaled-font.html#cairo-scaled-font-t" title="cairo_scaled_font_t">cairo_scaled_font_t</a> *scaled_font);</pre>
<p>
Releases a face obtained with <a class="link" href="cairo-ft-font.html#cairo-ft-scaled-font-lock-face" title="cairo_ft_scaled_font_lock_face ()"><code class="function">cairo_ft_scaled_font_lock_face()</code></a>.</p>
<p>
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody><tr>
<td><p><span class="term"><em class="parameter"><code>scaled_font</code></em> :</span></p></td>
<td> A <a class="link" href="cairo-scaled-font.html#cairo-scaled-font-t" title="cairo_scaled_font_t"><span class="type">cairo_scaled_font_t</span></a> from the FreeType font backend. Such an
  object can be created by calling <a class="link" href="cairo-scaled-font.html#cairo-scaled-font-create" title="cairo_scaled_font_create ()"><code class="function">cairo_scaled_font_create()</code></a> on a
  FreeType backend font face (see <a class="link" href="cairo-ft-font.html#cairo-ft-font-face-create-for-pattern" title="cairo_ft_font_face_create_for_pattern ()"><code class="function">cairo_ft_font_face_create_for_pattern()</code></a>,
  <a class="link" href="cairo-ft-font.html#cairo-ft-font-face-create-for-ft-face" title="cairo_ft_font_face_create_for_ft_face ()"><code class="function">cairo_ft_font_face_create_for_ft_face()</code></a>).
</td>
</tr></tbody>
</table></div>
</div>
</div>
<div class="refsect1" lang="en">
<a name="cairo-ft-font.see-also"></a><h2>See Also</h2>
<p>
</p>
<div class="itemizedlist"><ul type="disc"><li><a class="link" href="cairo-font-face.html#cairo-font-face-t" title="cairo_font_face_t"><span class="type">cairo_font_face_t</span></a></li></ul></div>
<p>
</p>
</div>
</div>
<div class="footer">
<hr>
          Generated by GTK-Doc V1.11</div>
</body>
</html>