<?xml version='1.0' encoding='UTF-8'?> 
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
                "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd" [
<!ENTITY version SYSTEM "version.xml">
]>
<refentry id="cairo-ft-font">
<refmeta>
<refentrytitle role="top_of_page" id="cairo-ft-font.top_of_page">FreeType Fonts</refentrytitle>
<manvolnum>3</manvolnum>
<refmiscinfo>CAIRO Library</refmiscinfo>
</refmeta>

<refnamediv>
<refname>FreeType Fonts</refname>
<refpurpose>Font support for FreeType</refpurpose>
</refnamediv>

<refsynopsisdiv id="cairo-ft-font.synopsis" role="synopsis">
<title role="synopsis.title">Synopsis</title>

<synopsis>
#define             <link linkend="CAIRO-HAS-FT-FONT--CAPS">CAIRO_HAS_FT_FONT</link>
<link linkend="cairo-font-face-t">cairo_font_face_t</link> * <link linkend="cairo-ft-font-face-create-for-ft-face">cairo_ft_font_face_create_for_ft_face</link>
                                                        (<link linkend="FT-Face">FT_Face</link> face,
                                                         <link linkend="int">int</link> load_flags);
<link linkend="cairo-font-face-t">cairo_font_face_t</link> * <link linkend="cairo-ft-font-face-create-for-pattern">cairo_ft_font_face_create_for_pattern</link>
                                                        (<link linkend="FcPattern">FcPattern</link> *pattern);
<link linkend="void">void</link>                <link linkend="cairo-ft-font-options-substitute">cairo_ft_font_options_substitute</link>    (const <link linkend="cairo-font-options-t">cairo_font_options_t</link> *options,
                                                         <link linkend="FcPattern">FcPattern</link> *pattern);
<link linkend="FT-Face">FT_Face</link>             <link linkend="cairo-ft-scaled-font-lock-face">cairo_ft_scaled_font_lock_face</link>      (<link linkend="cairo-scaled-font-t">cairo_scaled_font_t</link> *scaled_font);
<link linkend="void">void</link>                <link linkend="cairo-ft-scaled-font-unlock-face">cairo_ft_scaled_font_unlock_face</link>    (<link linkend="cairo-scaled-font-t">cairo_scaled_font_t</link> *scaled_font);
</synopsis>
</refsynopsisdiv>









<refsect1 id="cairo-ft-font.description" role="desc">
<title role="desc.title">Description</title>
<para>
The FreeType font backend is primarily used to render text on GNU/Linux
systems, but can be used on other platforms too.
</para>
</refsect1>

<refsect1 id="cairo-ft-font.details" role="details">
<title role="details.title">Details</title>
<refsect2 id="CAIRO-HAS-FT-FONT--CAPS" role="macro">
<title>CAIRO_HAS_FT_FONT</title>
<indexterm zone="CAIRO-HAS-FT-FONT--CAPS"><primary sortas="CAIRO_HAS_FT_FONT">CAIRO_HAS_FT_FONT</primary></indexterm><programlisting>#define CAIRO_HAS_FT_FONT 1
</programlisting>
<para>
Defined if the FreeType font backend is available.
This macro can be used to conditionally compile backend-specific code.
</para></refsect2>
<refsect2 id="cairo-ft-font-face-create-for-ft-face" role="function">
<title>cairo_ft_font_face_create_for_ft_face ()</title>
<indexterm zone="cairo-ft-font-face-create-for-ft-face"><primary sortas="cairo_ft_font_face_create_for_ft_face">cairo_ft_font_face_create_for_ft_face</primary></indexterm><programlisting><link linkend="cairo-font-face-t">cairo_font_face_t</link> * cairo_ft_font_face_create_for_ft_face
                                                        (<link linkend="FT-Face">FT_Face</link> face,
                                                         <link linkend="int">int</link> load_flags);</programlisting>
<para>
Creates a new font face for the FreeType font backend from a
pre-opened FreeType face. This font can then be used with
<link linkend="cairo-set-font-face"><function>cairo_set_font_face()</function></link> or <link linkend="cairo-scaled-font-create"><function>cairo_scaled_font_create()</function></link>. The
<link linkend="cairo-scaled-font-t"><type>cairo_scaled_font_t</type></link> returned from <link linkend="cairo-scaled-font-create"><function>cairo_scaled_font_create()</function></link> is
also for the FreeType backend and can be used with functions such
as <link linkend="cairo-ft-scaled-font-lock-face"><function>cairo_ft_scaled_font_lock_face()</function></link>. 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 <link linkend="FT-Done-Face"><function>FT_Done_Face()</function></link> before the last reference to the
<link linkend="cairo-font-face-t"><type>cairo_font_face_t</type></link> has been dropped.
</para>
<para>
As an example, below is how one might correctly couple the lifetime of
the FreeType face object to the <link linkend="cairo-font-face-t"><type>cairo_font_face_t</type></link>.
</para>
<para>
<informalexample><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;
}
</programlisting></informalexample></para>
<para>
</para><variablelist role="params">
<varlistentry><term><parameter>face</parameter>&#160;:</term>
<listitem><simpara> 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
  <link linkend="cairo-destroy-func-t"><type>cairo_destroy_func_t</type></link> to <link linkend="cairo-font-face-set-user-data"><function>cairo_font_face_set_user_data()</function></link>
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>load_flags</parameter>&#160;:</term>
<listitem><simpara> 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 <link linkend="cairo-font-options-t"><type>cairo_font_options_t</type></link> passed
  to <link linkend="cairo-scaled-font-create"><function>cairo_scaled_font_create()</function></link>, so only a few values such
  as <link linkend="FT-LOAD-VERTICAL-LAYOUT--CAPS"><literal>FT_LOAD_VERTICAL_LAYOUT</literal></link>, and <link linkend="FT-LOAD-FORCE-AUTOHINT--CAPS"><literal>FT_LOAD_FORCE_AUTOHINT</literal></link>
  are useful. You should not pass any of the flags affecting
  the load target, such as <link linkend="FT-LOAD-TARGET-LIGHT--CAPS"><literal>FT_LOAD_TARGET_LIGHT</literal></link>.
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis>&#160;:</term><listitem><simpara> a newly created <link linkend="cairo-font-face-t"><type>cairo_font_face_t</type></link>. Free with
 <link linkend="cairo-font-face-destroy"><function>cairo_font_face_destroy()</function></link> when you are done using it.
</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2 id="cairo-ft-font-face-create-for-pattern" role="function">
<title>cairo_ft_font_face_create_for_pattern ()</title>
<indexterm zone="cairo-ft-font-face-create-for-pattern"><primary sortas="cairo_ft_font_face_create_for_pattern">cairo_ft_font_face_create_for_pattern</primary></indexterm><programlisting><link linkend="cairo-font-face-t">cairo_font_face_t</link> * cairo_ft_font_face_create_for_pattern
                                                        (<link linkend="FcPattern">FcPattern</link> *pattern);</programlisting>
<para>
Creates a new font face for the FreeType font backend based on a
fontconfig pattern. This font can then be used with
<link linkend="cairo-set-font-face"><function>cairo_set_font_face()</function></link> or <link linkend="cairo-scaled-font-create"><function>cairo_scaled_font_create()</function></link>. The
<link linkend="cairo-scaled-font-t"><type>cairo_scaled_font_t</type></link> returned from <link linkend="cairo-scaled-font-create"><function>cairo_scaled_font_create()</function></link> is
also for the FreeType backend and can be used with functions such
as <link linkend="cairo-ft-scaled-font-lock-face"><function>cairo_ft_scaled_font_lock_face()</function></link>.
</para>
<para>
Font rendering options are represented both here and when you
call <link linkend="cairo-scaled-font-create"><function>cairo_scaled_font_create()</function></link>. Font options that have a representation
in a <link linkend="FcPattern"><type>FcPattern</type></link> must be passed in here; to modify <link linkend="FcPattern"><type>FcPattern</type></link>
appropriately to reflect the options in a <link linkend="cairo-font-options-t"><type>cairo_font_options_t</type></link>, call
<link linkend="cairo-ft-font-options-substitute"><function>cairo_ft_font_options_substitute()</function></link>.
</para>
<para>
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 <parameter>pattern</parameter> are
used to load a font face from file.
</para>
<para>
If the FC_FT_FACE element of <parameter>pattern</parameter> is set, the user is responsible
for making sure that the referenced FT_Face remains valid for the life
time of the returned <link linkend="cairo-font-face-t"><type>cairo_font_face_t</type></link>.  See
<link linkend="cairo-ft-font-face-create-for-ft-face"><function>cairo_ft_font_face_create_for_ft_face()</function></link> for an exmaple of how to couple
the life time of the FT_Face to that of the cairo font-face.</para>
<para>
</para><variablelist role="params">
<varlistentry><term><parameter>pattern</parameter>&#160;:</term>
<listitem><simpara> A fully resolved fontconfig
  pattern. A pattern can be resolved, by, among other things, calling
  <link linkend="FcConfigSubstitute"><function>FcConfigSubstitute()</function></link>, <link linkend="FcDefaultSubstitute"><function>FcDefaultSubstitute()</function></link>, then
  <link linkend="FcFontMatch"><function>FcFontMatch()</function></link>. Cairo will call <link linkend="FcPatternReference"><function>FcPatternReference()</function></link> on this
  pattern, so you should not further modify the pattern, but you can
  release your reference to the pattern with <link linkend="FcPatternDestroy"><function>FcPatternDestroy()</function></link> if
  you no longer need to access it.
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis>&#160;:</term><listitem><simpara> a newly created <link linkend="cairo-font-face-t"><type>cairo_font_face_t</type></link>. Free with
 <link linkend="cairo-font-face-destroy"><function>cairo_font_face_destroy()</function></link> when you are done using it.
</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2 id="cairo-ft-font-options-substitute" role="function">
<title>cairo_ft_font_options_substitute ()</title>
<indexterm zone="cairo-ft-font-options-substitute"><primary sortas="cairo_ft_font_options_substitute">cairo_ft_font_options_substitute</primary></indexterm><programlisting><link linkend="void">void</link>                cairo_ft_font_options_substitute    (const <link linkend="cairo-font-options-t">cairo_font_options_t</link> *options,
                                                         <link linkend="FcPattern">FcPattern</link> *pattern);</programlisting>
<para>
Add options to a <link linkend="FcPattern"><type>FcPattern</type></link> based on a <link linkend="cairo-font-options-t"><type>cairo_font_options_t</type></link> font
options object. Options that are already in the pattern, are not overridden,
so you should call this function after calling <link linkend="FcConfigSubstitute"><function>FcConfigSubstitute()</function></link> (the
user's settings should override options based on the surface type), but
before calling <link linkend="FcDefaultSubstitute"><function>FcDefaultSubstitute()</function></link>.</para>
<para>
</para><variablelist role="params">
<varlistentry><term><parameter>options</parameter>&#160;:</term>
<listitem><simpara> a <link linkend="cairo-font-options-t"><type>cairo_font_options_t</type></link> object
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>pattern</parameter>&#160;:</term>
<listitem><simpara> an existing <link linkend="FcPattern"><type>FcPattern</type></link>
</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2 id="cairo-ft-scaled-font-lock-face" role="function">
<title>cairo_ft_scaled_font_lock_face ()</title>
<indexterm zone="cairo-ft-scaled-font-lock-face"><primary sortas="cairo_ft_scaled_font_lock_face">cairo_ft_scaled_font_lock_face</primary></indexterm><programlisting><link linkend="FT-Face">FT_Face</link>             cairo_ft_scaled_font_lock_face      (<link linkend="cairo-scaled-font-t">cairo_scaled_font_t</link> *scaled_font);</programlisting>
<para>
<link linkend="cairo-ft-scaled-font-lock-face"><function>cairo_ft_scaled_font_lock_face()</function></link> gets the <link linkend="FT-Face"><type>FT_Face</type></link> object from a FreeType
backend font and scales it appropriately for the font. You must
release the face with <link linkend="cairo-ft-scaled-font-unlock-face"><function>cairo_ft_scaled_font_unlock_face()</function></link>
when you are done using it.  Since the <link linkend="FT-Face"><type>FT_Face</type></link> object can be
shared between multiple <link linkend="cairo-scaled-font-t"><type>cairo_scaled_font_t</type></link> objects, you must not
lock any other font objects until you unlock this one. A count is
kept of the number of times <link linkend="cairo-ft-scaled-font-lock-face"><function>cairo_ft_scaled_font_lock_face()</function></link> is
called. <link linkend="cairo-ft-scaled-font-unlock-face"><function>cairo_ft_scaled_font_unlock_face()</function></link> must be called the same number
of times.
</para>
<para>
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).</para>
<para>
</para><variablelist role="params">
<varlistentry><term><parameter>scaled_font</parameter>&#160;:</term>
<listitem><simpara> A <link linkend="cairo-scaled-font-t"><type>cairo_scaled_font_t</type></link> from the FreeType font backend. Such an
  object can be created by calling <link linkend="cairo-scaled-font-create"><function>cairo_scaled_font_create()</function></link> on a
  FreeType backend font face (see <link linkend="cairo-ft-font-face-create-for-pattern"><function>cairo_ft_font_face_create_for_pattern()</function></link>,
  <link linkend="cairo-ft-font-face-create-for-ft-face"><function>cairo_ft_font_face_create_for_ft_face()</function></link>).
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis>&#160;:</term><listitem><simpara> The <link linkend="FT-Face"><type>FT_Face</type></link> object for <parameter>font</parameter>, scaled appropriately,
or <link linkend="NULL--CAPS"><literal>NULL</literal></link> if <parameter>scaled_font</parameter> is in an error state (see
<link linkend="cairo-scaled-font-status"><function>cairo_scaled_font_status()</function></link>) or there is insufficient memory.
</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2 id="cairo-ft-scaled-font-unlock-face" role="function">
<title>cairo_ft_scaled_font_unlock_face ()</title>
<indexterm zone="cairo-ft-scaled-font-unlock-face"><primary sortas="cairo_ft_scaled_font_unlock_face">cairo_ft_scaled_font_unlock_face</primary></indexterm><programlisting><link linkend="void">void</link>                cairo_ft_scaled_font_unlock_face    (<link linkend="cairo-scaled-font-t">cairo_scaled_font_t</link> *scaled_font);</programlisting>
<para>
Releases a face obtained with <link linkend="cairo-ft-scaled-font-lock-face"><function>cairo_ft_scaled_font_lock_face()</function></link>.</para>
<para>
</para><variablelist role="params">
<varlistentry><term><parameter>scaled_font</parameter>&#160;:</term>
<listitem><simpara> A <link linkend="cairo-scaled-font-t"><type>cairo_scaled_font_t</type></link> from the FreeType font backend. Such an
  object can be created by calling <link linkend="cairo-scaled-font-create"><function>cairo_scaled_font_create()</function></link> on a
  FreeType backend font face (see <link linkend="cairo-ft-font-face-create-for-pattern"><function>cairo_ft_font_face_create_for_pattern()</function></link>,
  <link linkend="cairo-ft-font-face-create-for-ft-face"><function>cairo_ft_font_face_create_for_ft_face()</function></link>).
</simpara></listitem></varlistentry>
</variablelist></refsect2>

</refsect1>



<refsect1 id="cairo-ft-font.see-also">
<title>See Also</title>
<para>
<itemizedlist>
<listitem><link linkend="cairo-font-face-t"><type>cairo_font_face_t</type></link></listitem>
</itemizedlist>
</para>
</refsect1>

</refentry>
