More fixes to the tutorial.

Added artificial Type 1 pid/eid paors to ttnameid.h.
This commit is contained in:
Werner Lemberg 2000-10-13 21:00:36 +00:00
parent 0b7b23edfd
commit e67e349a0b
5 changed files with 204 additions and 185 deletions

View File

@ -37,7 +37,7 @@
Introduction Introduction
</h2> </h2>
<p>This is the first section of the FreeType&nbsp;2 tutorial. It will <p>This is the first part of the FreeType&nbsp;2 tutorial. It will
teach you to do the following:</p> teach you to do the following:</p>
<ul> <ul>
@ -55,7 +55,7 @@
1. Header files 1. Header files
</h3> </h3>
<p>To include the main FreeType header file, simply say</p> <p>To include the main FreeType header file, say</p>
<font color="blue"> <font color="blue">
<pre> <pre>
@ -64,7 +64,8 @@
<p>in your application code. Note that other files are available in the <p>in your application code. Note that other files are available in the
FreeType include directory, most of them being included by FreeType include directory, most of them being included by
<tt>freetype.h</tt>. They will be described later in this tutorial.</p> <tt>freetype.h</tt> and other (internal) files. Some of them will be
described later in this tutorial.</p>
<hr> <hr>
@ -104,15 +105,15 @@
<li> <li>
Load each module that FreeType knows about in the library. This Load each module that FreeType knows about in the library. This
means that by default, your new <tt>library</tt> object is able to means that by default, your new <tt>library</tt> object is able to
handle TrueType, Type&nbsp;1, CID-keyed & OpenType/CFF fonts handle TrueType, Type&nbsp;1, Windows FON, CID-keyed & OpenType/CFF
gracefully. fonts gracefully.
</li> </li>
</ul> </ul>
<p>As you can see, the function returns an error code, like most others <p>As you can see, the function returns an error code, like most others
in the FreeType API. An error code of&nbsp;0 <em>always</em> means that in the FreeType API. An error code of&nbsp;0 <em>always</em> means that
the operation was successful; otherwise, the value describes the error, the operation was successful; otherwise, the value describes the error,
and <tt>library</tt> is set to NULL.</p> and <tt>library</tt> is set to <tt>NULL</tt>.</p>
<hr> <hr>
@ -150,7 +151,7 @@
else if ( error ) else if ( error )
{ {
... another error code means that the font file could not ... another error code means that the font file could not
... be opened or read, or simply that it is broken ... be opened or read, or that it is broken
}</pre> }</pre>
</font> </font>
@ -160,24 +161,24 @@
<table cellpadding=5> <table cellpadding=5>
<tr valign="top"> <tr valign="top">
<td> <td>
<tt><b>library</b></tt> <tt>library</tt>
</td> </td>
<td> <td>
<p>a handle to the FreeType library instance where the face <p>A handle to the FreeType library instance where the face
object is created</p> object is created</p>
</td> </td>
</tr> </tr>
<tr valign="top"> <tr valign="top">
<td> <td>
<tt><b>filepathname</b></tt> <tt>filepathname</tt>
</td> </td>
<td> <td>
<p>the font file pathname (standard C string).</p> <p>The font file pathname (a standard C string).</p>
</td> </td>
</tr> </tr>
<tr valign="top"> <tr valign="top">
<td> <td>
<tt><b>face_index</b></tt> <tt>face_index</tt>
</td> </td>
<td> <td>
<p>Certain font formats allow several font faces to be embedded <p>Certain font formats allow several font faces to be embedded
@ -191,13 +192,13 @@
</tr> </tr>
<tr valign="top"> <tr valign="top">
<td> <td>
<tt><b>face</b></tt> <tt>face</tt>
</td> </td>
<td> <td>
<p>A <em>pointer</em> to the handle that will be set to describe <p>A <em>pointer</em> to the handle that will be set to describe
the new face object.</p> the new face object.</p>
<p>It is set to NULL in case of error.</p> <p>It is set to <tt>NULL</tt> in case of error.</p>
</td> </td>
</tr> </tr>
</table> </table>
@ -232,9 +233,9 @@
if ( error ) { ... }</pre> if ( error ) { ... }</pre>
</font> </font>
<p>As you can see, <tt>FT_New_Memory_Face()</tt> simply takes a <p>As you can see, <tt>FT_New_Memory_Face()</tt> takes a pointer to
pointer to the font file buffer and its size in bytes instead of a the font file buffer and its size in bytes instead of a file pathname.
file pathname. Other than that, it has exactly the same semantics as Other than that, it has exactly the same semantics as
<tt>FT_New_Face()</tt>.</p> <tt>FT_New_Face()</tt>.</p>
<h4> <h4>
@ -242,14 +243,14 @@
</h4> </h4>
<p>There are cases where using a file pathname or preloading the file <p>There are cases where using a file pathname or preloading the file
in memory is simply not enough. With FreeType&nbsp;2, it is possible in memory is not sufficient. With FreeType&nbsp;2, it is possible to
to provide your own implementation of i/o&nbsp;routines.</p> provide your own implementation of I/O&nbsp;routines.</p>
<p>This is done through the <tt>FT_Open_Face()</tt> function, which <p>This is done through the <tt>FT_Open_Face()</tt> function, which
can be used to open a new font face with a custom input stream, select can be used to open a new font face with a custom input stream, select
a specific driver for opening, or even pass extra parameters to the a specific driver for opening, or even pass extra parameters to the
font driver when creating the object. We advise you to refer to the font driver when creating the object. We advise you to refer to the
FreeType&nbsp;2 reference manual in order to learn how to use it.</p> FreeType&nbsp;2 API reference in order to learn how to use it.</p>
<p>Note that providing a custom stream might also be used to access a <p>Note that providing a custom stream might also be used to access a
TrueType font embedded in a Postscript Type&nbsp;42 wrapper.</p> TrueType font embedded in a Postscript Type&nbsp;42 wrapper.</p>
@ -267,7 +268,7 @@
<table cellpadding=5> <table cellpadding=5>
<tr valign="top"> <tr valign="top">
<td> <td>
<tt><b>face->num_glyphs</b></tt> <tt>face->num_glyphs</tt>
</td> </td>
<td> <td>
<p>Gives the number of <em>glyphs</em> available in the font face. <p>Gives the number of <em>glyphs</em> available in the font face.
@ -277,7 +278,7 @@
</tr> </tr>
<tr valign="top"> <tr valign="top">
<td> <td>
<tt><b>face->flags</b></tt> <tt>face->flags</tt>
</td> </td>
<td> <td>
<p>A 32-bit integer containing bit flags used to describe some <p>A 32-bit integer containing bit flags used to describe some
@ -290,7 +291,7 @@
</tr> </tr>
<tr valign="top"> <tr valign="top">
<td> <td>
<tt><b>face->units_per_EM</b></tt> <tt>face->units_per_EM</tt>
</td> </td>
<td> <td>
<p>This field is only valid for scalable formats (it is set <p>This field is only valid for scalable formats (it is set
@ -300,7 +301,7 @@
</tr> </tr>
<tr valign="top"> <tr valign="top">
<td> <td>
<tt><b>face->num_fixed_sizes</b></tt> <tt>face->num_fixed_sizes</tt>
</td> </td>
<td> <td>
<p>This field gives the number of embedded bitmap <em>strikes</em> <p>This field gives the number of embedded bitmap <em>strikes</em>
@ -313,7 +314,7 @@
</tr> </tr>
<tr valign="top"> <tr valign="top">
<td> <td>
<tt><b>face->fixed_sizes</b></tt> <tt>face->fixed_sizes</tt>
</td> </td>
<td> <td>
<p>This is a pointer to an array of <tt>FT_Bitmap_Size</tt> <p>This is a pointer to an array of <tt>FT_Bitmap_Size</tt>
@ -376,7 +377,7 @@
<li> <li>
The character width and heights are specified in 1/64th of points. The character width and heights are specified in 1/64th of points.
A point is a <em>physical</em> distance, equaling 1/72th of an inch; A point is a <em>physical</em> distance, equaling 1/72th of an inch;
it's not a pixel. it is not a pixel.
</li> </li>
<li> <li>
Horizontal and vertical device resolutions are expressed in Horizontal and vertical device resolutions are expressed in
@ -397,7 +398,7 @@
</li> </li>
<li> <li>
The first argument is a handle to a face object, not a size object. The first argument is a handle to a face object, not a size object.
That's normal, and must be seen as a convenience. This behaviour must be seen as a convenience.
</li> </li>
</ul> </ul>
@ -409,9 +410,9 @@
<font color="blue"> <font color="blue">
<pre> <pre>
error = FT_Set_Pixel_Sizes( error = FT_Set_Pixel_Sizes(
face, /* handle to face object */ face, /* handle to face object */
0, /* pixel_width */ 0, /* pixel_width */
16 ); /* pixel_height */</pre> 16 ); /* pixel_height */</pre>
</font> </font>
<p>This example will set the character pixel sizes to 16x16&nbsp;pixels. <p>This example will set the character pixel sizes to 16x16&nbsp;pixels.
@ -421,7 +422,7 @@
<p>Note that both functions return an error code. Usually, an error <p>Note that both functions return an error code. Usually, an error
occurs with a fixed-size font format (like FNT or PCF) when trying to occurs with a fixed-size font format (like FNT or PCF) when trying to
set the pixel size to a value that is not listed in the set the pixel size to a value that is not listed in the
<tt>face->fixed_sizes></tt> array.</p> <tt>face->fixed_sizes</tt> array.</p>
<hr> <hr>
@ -436,7 +437,7 @@
<p>Usually, an application wants to load a glyph image based on its <p>Usually, an application wants to load a glyph image based on its
<em>character code</em>, which is a unique value that defines the <em>character code</em>, which is a unique value that defines the
character for a given <em>encoding</em>. For example, the character character for a given <em>encoding</em>. For example, the character
code&nbsp;65 represents the `A' in ASCII encoding.</p> code&nbsp;65 in ASCII encoding represents letter `A'.</p>
<p>A face object contains one or more tables, called <p>A face object contains one or more tables, called
<em>charmaps</em>, that are used to convert character codes to glyph <em>charmaps</em>, that are used to convert character codes to glyph
@ -468,10 +469,10 @@
face. face.
<p>Note that this is one of the rare FreeType functions that do not <p>Note that this is one of the rare FreeType functions that do not
return an error code. However, when a given character code has no return an error code. If a given character code has no glyph image in
glyph image in the face, the value&nbsp;0 is returned. By convention, the face, the value&nbsp;0 is returned. By convention, it always
it always corresponds to a special glyph image called the <b>missing corresponds to a special glyph image called the <em>missing
glyph</b>, which usually is represented as a box or a space.</p> glyph</em>, which usually is represented as a box or a space.</p>
<h4> <h4>
b. Loading a glyph from the face b. Loading a glyph from the face
@ -481,8 +482,8 @@
image. The latter can be stored in various formats within the font image. The latter can be stored in various formats within the font
file. For fixed-size formats like FNT or PCF, each image is a bitmap. file. For fixed-size formats like FNT or PCF, each image is a bitmap.
Scalable formats like TrueType or Type&nbsp;1 use vectorial shapes, Scalable formats like TrueType or Type&nbsp;1 use vectorial shapes,
named <em>outlines</em> to describe each glyph. Some formats may have named <em>outlines</em>, to describe each glyph. Some formats may have
even more exotic ways of representing glyph (e.g. MetaFont). even more exotic ways of representing glyphs (e.g. MetaFont).
Fortunately, FreeType&nbsp;2 is flexible enough to support any kind of Fortunately, FreeType&nbsp;2 is flexible enough to support any kind of
glyph format through a simple API.</p> glyph format through a simple API.</p>
@ -513,10 +514,10 @@
<ul> <ul>
<li> <li>
<p>If a bitmap is found for the corresponding glyph and pixel <p>If a bitmap is found for the corresponding glyph and pixel
size, it will be loaded into the slot (embedded bitmaps are always size, it will be loaded into the slot. Embedded bitmaps are
favored over native image formats, because we assume that they are always favored over native image formats, because we assume that
higher-quality versions of the same glyph. This can be changed by they are higher-quality versions of the same glyph. This can be
using the <tt>FT_LOAD_NO_BITMAP</tt> flag)</p> changed by using the <tt>FT_LOAD_NO_BITMAP</tt> flag.</p>
</li> </li>
<li> <li>
<p>Otherwise, a native image for the glyph will be loaded. It <p>Otherwise, a native image for the glyph will be loaded. It
@ -554,8 +555,8 @@
position (on the baseline) to the top-most border of the glyph bitmap. position (on the baseline) to the top-most border of the glyph bitmap.
<em>It is positive to indicate an upwards distance</em>.</p> <em>It is positive to indicate an upwards distance</em>.</p>
<p>The second part of the tutorial will describe the contents of a <p>The second part of the tutorial describes the contents of a glyph
glyph slot and how to access specific glyph information (including slot and how to access specific glyph information (including
metrics).</p> metrics).</p>
<h4> <h4>
@ -563,18 +564,18 @@
</h4> </h4>
<p>As said before, when a new face object is created, it will look for <p>As said before, when a new face object is created, it will look for
a Unicode, Latin-1, or ASCII charmap and select it. The currently a Unicode, Latin-1, or ASCII charmap and select it. The currently
selected charmap is accessed via <tt>face->charmap</tt>. This field selected charmap is accessed via <tt>face->charmap</tt>. This field
is NULL if no charmap is selected, which typically happens when you is <tt>NULL</tt> if no charmap is selected, which typically happens
create a new <tt>FT_Face</tt> object from a font file that doesn't when you create a new <tt>FT_Face</tt> object from a font file that
contain an ASCII, Latin-1, or Unicode charmap (rare stuff).</p> doesn't contain an ASCII, Latin-1, or Unicode charmap (rare
stuff).</p>
<p>There are two ways to select a different charmap with <p>There are two ways to select a different charmap with
FreeType&nbsp;2. The easiest is if the encoding you need already has FreeType&nbsp;2. The easiest is if the encoding you need already has
a corresponding enumeration defined in a corresponding enumeration defined in <tt>freetype/freetype.h</tt>,
<tt>&lt;freetype/freetype.h&gt;</tt>, as <tt>ft_encoding_big5</tt>. as <tt>ft_encoding_big5</tt>. In this case, you can simply call
In this case, you can simply call <tt>FT_Select_CharMap()</tt> as <tt>FT_Select_CharMap()</tt> as in</p>
in</p>
<font color="blue"><pre> <font color="blue"><pre>
error = FT_Select_CharMap( error = FT_Select_CharMap(
@ -582,12 +583,12 @@
ft_encoding_big5 ); /* encoding */</pre> ft_encoding_big5 ); /* encoding */</pre>
</font> </font>
<p>Another way is to manually parse the list of charmaps for the face, <p>Another way is to manually parse the list of charmaps for the face;
this is accessible through the fields <tt>num_charmaps</tt> and this is accessible through the fields <tt>num_charmaps</tt> and
<tt>charmaps</tt> (notice the final 's') of the face object. As you <tt>charmaps</tt> (notice the final 's') of the face object. As
could expect, the first is the number of charmaps in the face, while expected, the first is the number of charmaps in the face, while the
the second is <em>a table of pointers to the charmaps</em> embedded in second is <em>a table of pointers to the charmaps</em> embedded in the
the face.</p> face.</p>
<p>Each charmap has a few visible fields used to describe it more <p>Each charmap has a few visible fields used to describe it more
precisely. Mainly, one will look at <tt>charmap->platform_id</tt> and precisely. Mainly, one will look at <tt>charmap->platform_id</tt> and
@ -595,16 +596,20 @@
be used to describe the charmap in a rather generic way.</p> be used to describe the charmap in a rather generic way.</p>
<p>Each value pair corresponds to a given encoding. For example, the <p>Each value pair corresponds to a given encoding. For example, the
pair (3,1) corresponds to Unicode. A list of such pairs is defined in pair (3,1) corresponds to Unicode (on the Windows platform). A list
the TrueType specification, but you can also use the file of such pairs is defined in the TrueType specification, but you can
<tt>&lt;freetype/ftnameid.h&gt;</tt> which defines several helpful also use the file <tt>&lt;freetype/ttnameid.h&gt;</tt> which defines
constants to deal with them.</p> several helpful constants to deal with them.</p>
<p>Note that some pid/eid pairs are <em>artificial</em>; such values
have been created by FreeType to identify platforms resp. encodings
not covered by the original TrueType specification.</p>
<p>To look up a specific encoding you need to find a corresponding <p>To look up a specific encoding you need to find a corresponding
value pair in the specification, then look for it in the charmaps value pair in the specification, then look for it in the
list. Bear in mind that some encodings correspond to several values <tt>charmaps</tt> list. Bear in mind that some encodings correspond
pairs (yes, it's a real mess, but blame Apple and Microsoft on such to several values pairs (yes, it's a real mess, but blame Apple and
stupidity). Here some code to do it:</p> Microsoft on such stupidity). Here some code to do it:</p>
<font color="blue"> <font color="blue">
<pre> <pre>
@ -654,26 +659,26 @@
</font> </font>
<p>This function will set the current transformation for a given face <p>This function will set the current transformation for a given face
object. Its second parameter is a pointer to a <tt>FT_Matrix</tt> object. Its second parameter is a pointer to an <tt>FT_Matrix</tt>
structure that describes a 2x2 affine matrix. The third parameter is structure that describes a 2x2&nbsp;affine matrix. The third
a pointer to a <tt>FT_Vector</tt> structure that describes a simple 2d parameter is a pointer to an <tt>FT_Vector</tt> structure that
vector that is used to translate the glyph image <em>after</em> the describes a simple 2d&nbsp;vector that is used to translate the glyph
2x2 transformation.</p> image <em>after</em> the 2x2&nbsp;transformation.</p>
<p>Note that the matrix pointer can be set to NULL, in which case the <p>Note that the matrix pointer can be set to <tt>NULL</tt>, in which
identity transformation will be used. Coefficients of the matrix are case the identity transformation will be used. Coefficients of the
otherwise in 16.16 fixed float units.</p> matrix are otherwise in 16.16 fixed float units.</p>
<p>The vector pointer can also be set to NULL in which case a delta <p>The vector pointer can also be set to <tt>NULL</tt> in which case a
vector of (0,0) will be used. The vector coordinates are expressed in delta vector of (0,0) will be used. The vector coordinates are
1/64th of a pixel (also known as 26.6 fixed floats).</p> expressed in 1/64th of a pixel (also known as 26.6 fixed floats).</p>
<p><em>The transformation is applied to every glyph that is loaded <p><em>The transformation is applied to every glyph that is loaded
through <tt>FT_Load_Glyph()</tt> and is <b>completely independent of through <tt>FT_Load_Glyph()</tt> and is <b>completely independent of
any hinting process.</b> This means that you won't get the same any hinting process.</b> This means that you won't get the same
results if you load a glyph at the size of 24&nbsp;pixels, or a glyph results if you load a glyph at the size of 24&nbsp;pixels, or a glyph
at the size at 12&nbsp;pixels scaled by&nbsp;2 through a at the size at 12&nbsp;pixels scaled by&nbsp;2 through a
transformation, because the hints will have been computed differently transformation, because hints will have been computed differently
(unless hints have been disabled, of course).</em></p> (unless hints have been disabled, of course).</em></p>
<p>If you ever need to use a non-orthogonal transformation with <p>If you ever need to use a non-orthogonal transformation with
@ -692,9 +697,8 @@
7. Simple text rendering 7. Simple text rendering
</h3> </h3>
<p>We will now present you with a very simple example used to render a <p>We will now present a very simple example used to render a string of
string of 8-bit Latin-1 text, assuming a face that contains a Unicode 8-bit Latin-1 text, assuming a face that contains a Unicode charmap</p>
charmap</p>
<p>The idea is to create a loop that will, on each iteration, load one <p>The idea is to create a loop that will, on each iteration, load one
glyph image, convert it to an anti-aliased bitmap, draw it on the target glyph image, convert it to an anti-aliased bitmap, draw it on the target
@ -764,9 +768,9 @@
truncated to integer pixels on each iteration. truncated to integer pixels on each iteration.
</li> </li>
<li> <li>
The function <tt>my_draw_bitmap()</tt> is not part of FreeType, The function <tt>my_draw_bitmap()</tt> is not part of FreeType but
but must be provided by the application to draw the bitmap to the must be provided by the application to draw the bitmap to the
target surface. In this example, it takes a pointer to a target surface. In this example, it takes a pointer to an
<tt>FT_Bitmap</tt> descriptor and the position of its top-left <tt>FT_Bitmap</tt> descriptor and the position of its top-left
corner as arguments. corner as arguments.
</li> </li>
@ -834,8 +838,8 @@
equivalent.</p> equivalent.</p>
<p>Note that you can also specify that you want a monochrome <p>Note that you can also specify that you want a monochrome
bitmap instead by using the additional <tt>FT_LOAD_MONOCHROME</tt> bitmap by using the <tt>FT_LOAD_MONOCHROME</tt> load flag
load flag.</p> instead.</p>
</li> </li>
</ul> </ul>
@ -850,7 +854,7 @@
FT_Matrix matrix; /* transformation matrix */ FT_Matrix matrix; /* transformation matrix */
FT_UInt glyph_index; FT_UInt glyph_index;
FT_Vector pen; /* untransformed origin */ FT_Vector pen; /* untransformed origin */
int pen_x, pen_y, n; int n;
.. initialize library .. .. initialize library ..
@ -896,8 +900,8 @@
multiplication. The position is expressed in cartesian space. multiplication. The position is expressed in cartesian space.
</li> </li>
<li> <li>
Glyph images are always loaded, transformed, and described in the In FreeType, glyph images are always loaded, transformed, and
cartesian coordinate system in FreeType (which means that described in the cartesian coordinate system (which means that
increasing&nbsp;Y corresponds to upper scanlines), unlike the increasing&nbsp;Y corresponds to upper scanlines), unlike the
system typically used for bitmaps (where the top-most scanline has system typically used for bitmaps (where the top-most scanline has
coordinate&nbsp;0). We must thus convert between the two systems coordinate&nbsp;0). We must thus convert between the two systems
@ -905,8 +909,8 @@
position of the bitmap. position of the bitmap.
</li> </li>
<li> <li>
We set the transformation on each glyph to indicate the rotation We apply the transformation matrix on each glyph to indicate
matrix, as well as a delta vector that will move the transformed rotation as well as a delta vector that will move the transformed
image to the current pen position (in cartesian space, not bitmap image to the current pen position (in cartesian space, not bitmap
space). space).
</li> </li>
@ -931,13 +935,12 @@
Conclusion Conclusion
</h3> </h3>
<p>In this first section, you have learned the basics of <p>In this first section, you have learned the basics of FreeType&nbsp;2
FreeType&nbsp;2, as well as sufficient knowledge how to render rotated as well as sufficient knowledge how to render rotated text.</p>
text.</p>
<p>The next part will dive into more details of the API in order to let <p>The next part will dive into more details of the API in order to let
you access glyph metrics and images directly, as well as how to deal you access glyph metrics and images directly, how to deal with scaling,
with scaling, hinting, kerning, etc.</p> hinting, kerning, etc.</p>
<p>The third part will discuss issues like modules, caching, and a few <p>The third part will discuss issues like modules, caching, and a few
other advanced topics like how to use multiple size objects with a other advanced topics like how to use multiple size objects with a

View File

@ -37,8 +37,8 @@
Introduction Introduction
</h2> </h2>
<p>This is the second section of the FreeType&nbsp;2 tutorial. It will <p>This is the second part of the FreeType&nbsp;2 tutorial. It will teach
teach you the following:</p> you the following:</p>
<ul> <ul>
<li>how to retrieve glyph metrics</li> <li>how to retrieve glyph metrics</li>
@ -69,8 +69,8 @@
<p>Note that only a few font formats provide vertical metrics. You can <p>Note that only a few font formats provide vertical metrics. You can
test wether a given face object contains them by using the macro test wether a given face object contains them by using the macro
<tt>FT_HAS_VERTICAL(face)</tt>, which is true if has vertical <tt>FT_HAS_VERTICAL(face)</tt>, which is true if vertical metrics are
metrics.</p> available.</p>
<p>Individual glyph metrics can be accessed by first loading the glyph <p>Individual glyph metrics can be accessed by first loading the glyph
in a face's glyph slot, then using the <tt>face->glyph->metrics</tt> in a face's glyph slot, then using the <tt>face->glyph->metrics</tt>
@ -85,7 +85,7 @@
</td> </td>
<td> <td>
This is the width of the glyph image's bounding box. It is This is the width of the glyph image's bounding box. It is
independent of layout direction. independent of the layout direction.
</td> </td>
</tr> </tr>
<tr valign=top> <tr valign=top>
@ -94,7 +94,7 @@
</td> </td>
<td> <td>
This is the height of the glyph image's bounding box. It is This is the height of the glyph image's bounding box. It is
independent of layout direction. independent of the layout direction.
</td> </td>
</tr> </tr>
<tr valign=top> <tr valign=top>
@ -165,8 +165,8 @@
should not be considered reliable if <tt>FT_HAS_VERTICAL(face)</tt> is should not be considered reliable if <tt>FT_HAS_VERTICAL(face)</tt> is
false.</em></p> false.</em></p>
<p>The following graphics illustrate the metrics more clearly. First, <p>The following graphics illustrate the metrics more clearly. First
for horizontal metrics, where the baseline is the horizontal axis:</p> horizontal metrics, where the baseline is the horizontal axis:</p>
<center> <center>
<img src="metrics.png" <img src="metrics.png"
@ -221,7 +221,7 @@
multiple of&nbsp;64) by the font driver used to load the glyph multiple of&nbsp;64) by the font driver used to load the glyph
image. <tt>linearHoriAdvance</tt> is a 16.16 fixed float number image. <tt>linearHoriAdvance</tt> is a 16.16 fixed float number
that gives the value of the original glyph advance width in that gives the value of the original glyph advance width in
1/65536th of pixels. It can be use to perform pseudo 1/65536th of pixels. It can be used to perform pseudo
device-independent text layouts. device-independent text layouts.
</td> </td>
</tr> </tr>
@ -250,9 +250,9 @@
glyph image, the previous one is erased from the glyph slot.</p> glyph image, the previous one is erased from the glyph slot.</p>
<p>There are times, however, where you may need to extract this image <p>There are times, however, where you may need to extract this image
from the glyph slot, in order to cache it within your application, and from the glyph slot. For example, you want to cache images within your
even perform additional transformations and measures on it before application, or you want to apply additional transformations and
converting it to a bitmap.</p> measures on it before converting it to a bitmap.</p>
<p>The FreeType&nbsp;2 API has a specific extension which is capable of <p>The FreeType&nbsp;2 API has a specific extension which is capable of
dealing with glyph images in a flexible and generic way. To use it, you dealing with glyph images in a flexible and generic way. To use it, you
@ -297,11 +297,11 @@
<li> <li>
loaded the glyph image normally in the face's glyph slot. We did loaded the glyph image normally in the face's glyph slot. We did
not use <tt>FT_LOAD_RENDER</tt> because we want to grab a scalable not use <tt>FT_LOAD_RENDER</tt> because we want to grab a scalable
glyph image, in order to transform it later, glyph image in order to transform it later,
</li> </li>
<li> <li>
copied the glyph image from the slot into a new <tt>FT_Glyph</tt> copied the glyph image from the slot into a new <tt>FT_Glyph</tt>
object, by calling <tt>FT_Get_Glyph()</tt>. This function returns object by calling <tt>FT_Get_Glyph()</tt>. This function returns
an error code and sets <tt>glyph</tt>. an error code and sets <tt>glyph</tt>.
</li> </li>
</ul> </ul>
@ -313,25 +313,25 @@
<p>You can access the field <tt>glyph->format</tt> if you want to know <p>You can access the field <tt>glyph->format</tt> if you want to know
exactly how the glyph is modeled and stored. A new glyph object can exactly how the glyph is modeled and stored. A new glyph object can
be destroyed with a call to <tt>FT_Done_Glyph</tt>.</p> be destroyed with a call to <tt>FT_Done_Glyph()</tt>.</p>
<p>The glyph object contains exactly one glyph image and a 2d vector <p>The glyph object contains exactly one glyph image and a
representing the glyph's advance in 16.16 fixed float coordinates. 2d&nbsp;vector representing the glyph's advance in 16.16 fixed float
The latter can be accessed directly as <tt>glyph->advance</tt>.</p> coordinates. The latter can be accessed directly as
<tt>glyph->advance</tt>.</p>
<p><em>Note that unlike other FreeType objects, the library doesn't <p><em>Note that unlike other FreeType objects, the library doesn't
keep a list of all allocated glyph objects. This means you will need keep a list of all allocated glyph objects. This means you will need
to destroy them yourself, instead of relying on to destroy them yourself, instead of relying on
<tt>FT_Done_FreeType()</tt> doing all the clean-up.</em></p> <tt>FT_Done_FreeType()</tt> to do all the clean-up.</em></p>
<h4> <h4>
b. Transforming & copying the glyph image b. Transforming & copying the glyph image
</h4> </h4>
<p>If the glyph image is scalable (i.e., if <tt>glyph->format</tt> is <p>If the glyph image is scalable (i.e., if <tt>glyph->format</tt> is
not equal to <tt>ft_glyph_format_bitmap</tt>), it is possible to not <tt>ft_glyph_format_bitmap</tt>), it is possible to transform the
transform the image anytime by a call to image anytime by a call to <tt>FT_Glyph_Transform()</tt>.</p>
<tt>FT_Glyph_Transform()</tt>.</p>
<p>You can also copy a single glyph image with <p>You can also copy a single glyph image with
<tt>FT_Glyph_Copy()</tt>. Here some example code:</p> <tt>FT_Glyph_Copy()</tt>. Here some example code:</p>
@ -362,18 +362,20 @@
matrix.yx = 0.12 * 0x10000L; matrix.yx = 0.12 * 0x10000L;
matrix.yy = 0x10000L; matrix.yy = 0x10000L;
FT_Glyph_Transform( glyph2, &amplmatrix, 0 );</pre> FT_Glyph_Transform( glyph2, &amp;matrix, 0 );</pre>
</font> </font>
<p>Note that the 2x2 transform matrix is always applied to the 16.16 <p>Note that the 2x2&nbsp;transformation matrix is always applied to
advance vector in the glyph; you thus don't need to recompute it.</p> the 16.16 advance vector in the glyph; you thus don't need to
recompute it.</p>
<h4> <h4>
c. Measuring the glyph image c. Measuring the glyph image
</h4> </h4>
<p>You can also retrieve the control (bounding) box of any glyph image <p>You can also retrieve the control (bounding) box of any glyph image
(scalable or not), using the <tt>FT_Glyph_Get_CBox</tt> function:</p> (scalable or not), using the <tt>FT_Glyph_Get_CBox()</tt>
function:</p>
<font color="blue"> <font color="blue">
<pre> <pre>
@ -386,8 +388,8 @@
<p>Coordinates are relative to the glyph origin, i.e. (0,0), using the <p>Coordinates are relative to the glyph origin, i.e. (0,0), using the
Y&nbsp;upwards convention. This function takes a special argument, Y&nbsp;upwards convention. This function takes a special argument,
the <em>bbox mode</em>, to indicate how box coordinates are expressed. <tt>bbox_mode</tt>, to indicate how box coordinates are expressed. If
If <tt>bbox_mode</tt> is set to <tt>ft_glyph_bbox_subpixels</tt>, the <tt>bbox_mode</tt> is set to <tt>ft_glyph_bbox_subpixels</tt>, the
coordinates are returned in 26.6 pixels (i.e. 1/64th of pixels). coordinates are returned in 26.6 pixels (i.e. 1/64th of pixels).
<p>Note that the box's maximum coordinates are exclusive, which means <p>Note that the box's maximum coordinates are exclusive, which means
@ -412,10 +414,10 @@
bbox.yMax = CEILING(bbox.yMax)</pre> bbox.yMax = CEILING(bbox.yMax)</pre>
</font> </font>
<p>The default value for the bbox mode is <p>The default value for <tt>bbox_mode</tt> is
<tt>ft_glyph_bbox_pixels</tt> (i.e. integer, grid-fitted pixel <tt>ft_glyph_bbox_pixels</tt> (i.e. integer, grid-fitted pixel
coordinates). Please check the API reference for coordinates). Please check the API reference of
<tt>FT_Glyph_Get_CBox()</tt> other possible values</p> <tt>FT_Glyph_Get_CBox()</tt> for other possible values.</p>
<h4> <h4>
d. Converting the glyph image to a bitmap d. Converting the glyph image to a bitmap
@ -430,7 +432,7 @@
FT_Vector origin; FT_Vector origin;
origin.x = 32; /* 1/2 pixel in 26.26 format */ origin.x = 32; /* 1/2 pixel in 26.6 format */
origin.y = 0; origin.y = 0;
error = FT_Glyph_To_Bitmap( &amp;glyph, error = FT_Glyph_To_Bitmap( &amp;glyph,
@ -455,12 +457,12 @@
or <tt>ft_render_mode_mono</tt> for a 1-bit monochrome bitmap. or <tt>ft_render_mode_mono</tt> for a 1-bit monochrome bitmap.
</li> </li>
<li> <li>
The third parameter is a pointer to a 2d vector that is used to The third parameter is a pointer to a 2d&nbsp;vector that is used
translate the source glyph image before the conversion. Note that to translate the source glyph image before the conversion. Note
the source image will be translated back to its original position that the source image will be translated back to its original
(and will thus be left unchanged) after the call. If you do not position (and will thus be left unchanged) after the call. If you
need to translate the source glyph before rendering, set this do not need to translate the source glyph before rendering, set
pointer to&nbsp;0. this pointer to&nbsp;0.
</li> </li>
<li> <li>
The last parameter is a Boolean to indicate whether the source The last parameter is a Boolean to indicate whether the source
@ -530,13 +532,12 @@
<p>For scalable formats, all global metrics are expressed in font <p>For scalable formats, all global metrics are expressed in font
units in order to be later scaled to device space, according to the units in order to be later scaled to device space, according to the
rules described in the last chapter of this part of the tutorial. You rules described in the last chapter of this part of the tutorial. You
can access them directly as simple fields of a <tt>FT_Face</tt> can access them directly as fields of an <tt>FT_Face</tt> handle.</p>
handle.</p>
<p>However, you need to check that the font face's format is scalable <p>However, you need to check that the font face's format is scalable
before using them. One can do it by using the macro before using them. This can be done with the macro
<tt>FT_IS_SCALABLE(face)</tt> which returns true if we have a <tt>FT_IS_SCALABLE(face)</tt> which returns true if we have a scalable
scalable format.</p> format.</p>
<p>In this case, you can access the global design metrics as</p> <p>In this case, you can access the global design metrics as</p>
@ -659,7 +660,7 @@
b. Scaled global metrics b. Scaled global metrics
</h4> </h4>
<p>Each size object also contains a scaled versions of some of the <p>Each size object also contains scaled versions of some of the
global metrics described above. They can be accessed directly through global metrics described above. They can be accessed directly through
the <tt>face->size->metrics</tt> structure.</p> the <tt>face->size->metrics</tt> structure.</p>
@ -749,7 +750,10 @@
if ( error ) { ... } if ( error ) { ... }
error = FT_Attach_File( face, "/usr/shared/fonts/cour.afm" ); error = FT_Attach_File( face, "/usr/shared/fonts/cour.afm" );
if ( error ) { .. could not read kerning and additional metrics .. }</pre> if ( error )
{
.. could not read kerning and additional metrics ..
}</pre>
</font> </font>
<p>Note that <tt>FT_Attach_Stream()</tt> is similar to <p>Note that <tt>FT_Attach_Stream()</tt> is similar to
@ -785,10 +789,9 @@
a pointer to a destination vector that receives the corresponding a pointer to a destination vector that receives the corresponding
distances.</p> distances.</p>
<p>The kerning mode is very similar to the <em>bbox mode</em> <p>The kerning mode is very similar to <tt>bbox_mode</tt> described in
described in a previous part. It is an enumeration value that a previous part. It is an enumeration value that indicates how the
indicates how the kerning distances are expressed in the target kerning distances are expressed in the target vector.</p>
vector.</p>
<p>The default value <tt>ft_kerning_mode_default</tt> (which has <p>The default value <tt>ft_kerning_mode_default</tt> (which has
value&nbsp;0) corresponds to kerning distances expressed in 26.6 value&nbsp;0) corresponds to kerning distances expressed in 26.6
@ -808,8 +811,8 @@
<p>Note that the "left" and "right" positions correspond to the <p>Note that the "left" and "right" positions correspond to the
<em>visual order</em> of the glyphs in the string of text. This is <em>visual order</em> of the glyphs in the string of text. This is
important for bi-directional text, or simply when writing important for bidirectional text, or when writing right-to-left
right-to-left text.</p> text.</p>
<hr> <hr>
@ -817,10 +820,9 @@
4. Simple text rendering: kerning + centering 4. Simple text rendering: kerning + centering
</h3> </h3>
<p>In order to show off what we have just learned, we will now show how <p>In order to show off what we have just learned, we will now modify
to modify the example code that was provided in the first part to render the example code that was provided in the first part to render a string
a string of text, and enhance it to support kerning and delayed of text, and enhance it to support kerning and delayed rendering.</p>
rendering.</p>
<h4> <h4>
a. Kerning support a. Kerning support
@ -828,9 +830,9 @@
<p>Adding support for kerning to our code is trivial, as long as we <p>Adding support for kerning to our code is trivial, as long as we
consider that we are still dealing with a left-to-right script like consider that we are still dealing with a left-to-right script like
Latin. We simply need to retrieve the kerning distance between two Latin. We need to retrieve the kerning distance between two glyphs in
glyphs in order to alter the pen position appropriately. The code order to alter the pen position appropriately. The code looks
looks like</p> like</p>
<font color="blue"> <font color="blue">
<pre> <pre>
@ -913,7 +915,7 @@
<li> <li>
We do not check the error code returned by We do not check the error code returned by
<tt>FT_Get_Kerning()</tt>. This is because the function always <tt>FT_Get_Kerning()</tt>. This is because the function always
set the content of <tt>delta</tt> to (0,0) when an error occurs. set <tt>delta</tt> to (0,0) when an error occurs.
</li> </li>
</ul> </ul>
@ -1000,7 +1002,7 @@
}</pre> }</pre>
</font> </font>
<p>As you see, this is a very simple variation of our previous code <p>As you see, this is a very slight variation of our previous code
where we extract each glyph image from the slot, and store it, along where we extract each glyph image from the slot, and store it, along
with the corresponding position, in our tables.</p> with the corresponding position, in our tables.</p>
@ -1020,7 +1022,7 @@
bbox.xMax = bbox.yMax = -32000; bbox.xMax = bbox.yMax = -32000;
/* for each glyph image, compute its bounding box, */ /* for each glyph image, compute its bounding box, */
/* translateit, and grow the string bbox */ /* translate it, and grow the string bbox */
for ( n = 0; n &lt; num_glyphs; n++ ) for ( n = 0; n &lt; num_glyphs; n++ )
{ {
FT_BBox glyph_bbox; FT_BBox glyph_bbox;
@ -1111,7 +1113,7 @@
We call <tt>FT_Glyph_To_Bitmap()</tt> with the <tt>destroy</tt> We call <tt>FT_Glyph_To_Bitmap()</tt> with the <tt>destroy</tt>
parameter set to&nbsp;0 (false), in order to avoid destroying the parameter set to&nbsp;0 (false), in order to avoid destroying the
original glyph image. The new glyph bitmap is accessed through original glyph image. The new glyph bitmap is accessed through
<tt>image</tt> after the call and is typecasted to a <tt>image</tt> after the call and is typecast to an
<tt>FT_BitmapGlyph</tt>. <tt>FT_BitmapGlyph</tt>.
</li> </li>
<li> <li>
@ -1304,7 +1306,7 @@
</h4> </h4>
<p>However, directly transforming the glyphs in our sequence is not a <p>However, directly transforming the glyphs in our sequence is not a
useful idea if we want to re-use them in order to draw the text string useful idea if we want to reuse them in order to draw the text string
with various angles or transforms. It is better to perform the affine with various angles or transforms. It is better to perform the affine
transformation just before the glyph is rendered, as in the following transformation just before the glyph is rendered, as in the following
code:</p> code:</p>
@ -1403,8 +1405,8 @@
</ul> </ul>
<p>It is possible to call this function several times to render the <p>It is possible to call this function several times to render the
string width different angles, or even change the way <tt>start</tt> string with different angles, or even change the way <tt>start</tt>
is computed in order to move it to different place.</p> is computed in order to move it to a different place.</p>
<p>This code is the basis of the FreeType&nbsp;2 demonstration program <p>This code is the basis of the FreeType&nbsp;2 demonstration program
named <tt>ftstring.c</tt>. It could be easily extended to perform named <tt>ftstring.c</tt>. It could be easily extended to perform
@ -1421,15 +1423,15 @@
<hr> <hr>
<h3> <h3>
6. Accessing metrics in design font units, and scaling them 6. Accessing metrics in design font units and scaling them
</h3> </h3>
<p>Scalable font formats usually store a single vectorial image, called <p>Scalable font formats usually store a single vectorial image, called
an <em>outline</em>, for each in a face. Each outline is defined in an an <em>outline</em>, for each glyph in a face. Each outline is defined
abstract grid called the <em>design space</em>, with coordinates in an abstract grid called the <em>design space</em>, with coordinates
expressed in nominal <em>font units</em>. When a glyph image is loaded, expressed in nominal <em>font units</em>. When a glyph image is loaded,
the font driver usually scales the outline to device space according to the font driver usually scales the outline to device space according to
the current character pixel size found in a <tt>FT_Size</tt> object. the current character pixel size found in a <tt>FT_Size</tt> object.
The driver may also modify the scaled outline in order to significantly The driver may also modify the scaled outline in order to significantly
improve its appearance on a pixel-based surface (a process known as improve its appearance on a pixel-based surface (a process known as
<em>hinting</em> or <em>grid-fitting</em>).</p> <em>hinting</em> or <em>grid-fitting</em>).</p>
@ -1494,10 +1496,10 @@
<tt>x_ppem</t> <tt>x_ppem</t>
</td> </td>
<td> <td>
Which stands for "X Pixels Per EM"; this is the size in integer This is the size in integer pixels of the EM square, which also is
pixels of the EM square, which also is the <em>horizontal the <em>horizontal character pixel size</em>, called
character pixel size</em>, called <tt>pixel_size_x</tt> in the <tt>pixel_size_x</tt> in the above example. <tt>x_ppem</tt> means
above example. "x&nbsp;pixels per EM".
</td> </td>
</tr> </tr>
<tr valign=top> <tr valign=top>
@ -1505,10 +1507,10 @@
<tt>y_ppem</tt> <tt>y_ppem</tt>
</td> </td>
<td> <td>
Which stands for "Y Pixels Per EM"; this is the size in integer This is the size in integer pixels of the EM square, which also is
pixels of the EM square, which also is the <em>vertical character the <em>vertical character pixel size</em>, called
pixel size</em>, called <tt>pixel_size_y</tt> in the above <tt>pixel_size_y</tt> in the above example. <tt>y_ppem</tt> means
example. "y&nbsp;pixels per EM".
</td> </td>
</tr> </tr>
<tr valign=top> <tr valign=top>
@ -1532,9 +1534,9 @@
</table> </table>
</center> </center>
<p>Basically, this means that you can scale a distance expressed in <p>You can scale a distance expressed in font units to 26.6 pixels
font units to 26.6 pixels directly with the help of the directly with the help of the <tt>FT_MulFix()</tt> function, as
<tt>FT_MulFix()</tt> function, as in:</p> in:</p>
<font color="blue"> <font color="blue">
<pre> <pre>
@ -1567,12 +1569,12 @@
b. Accessing design metrics (glyph & global) b. Accessing design metrics (glyph & global)
</h4> </h4>
<p>You can access glyph metrics in font units simply by specifying the <p>You can access glyph metrics in font units by specifying the
<tt>FT_LOAD_NO_SCALE</tt> bit flag in <tt>FT_Load_Glyph()</tt> or <tt>FT_LOAD_NO_SCALE</tt> bit flag in <tt>FT_Load_Glyph()</tt> or
<tt>FT_Load_Char()</tt>. The metrics returned in <tt>FT_Load_Char()</tt>. The metrics returned in
<tt>face->glyph->metrics</tt> will then all be in font units.</p> <tt>face->glyph->metrics</tt> will then all be in font units.</p>
<p>You can access unscaled kerning data using the <p>Unscaled kerning data can be retrieved using the
<tt>ft_kerning_mode_unscaled</tt> mode.</p> <tt>ft_kerning_mode_unscaled</tt> mode.</p>
<p>Finally, a few global metrics are available directly in font units <p>Finally, a few global metrics are available directly in font units
@ -1590,9 +1592,8 @@
render text much more intelligently (kerning, measuring, transforming render text much more intelligently (kerning, measuring, transforming
& caching).</p> & caching).</p>
<p>You have now sufficient knowledge to build a pretty decent text <p>With this knowledge you can build a pretty decent text service on top
service on top of FreeType&nbsp;2, and you could possibly stop there if of FreeType&nbsp;2, and you could possibly stop there if you want.</p>
you want.</p>
<p>The next section will deal with FreeType&nbsp;2 internals (like <p>The next section will deal with FreeType&nbsp;2 internals (like
modules, vector outlines, font drivers, renderers), as well as a few modules, vector outlines, font drivers, renderers), as well as a few

View File

@ -359,9 +359,8 @@
/* <Fields> */ /* <Fields> */
/* face :: A handle to the parent face object. */ /* face :: A handle to the parent face object. */
/* */ /* */
/* flags :: A set of bit flags used to describe the charmap. */ /* encoding :: A tag which identifies the charmap. Use this with */
/* Each bit indicates that a given encoding is */ /* FT_Select_Charmap(). */
/* supported. */
/* */ /* */
/* platform_id :: An ID number describing the platform for the */ /* platform_id :: An ID number describing the platform for the */
/* following encoding ID. This comes directly from */ /* following encoding ID. This comes directly from */

View File

@ -35,6 +35,9 @@
#define TT_PLATFORM_ISO 2 /* deprecated */ #define TT_PLATFORM_ISO 2 /* deprecated */
#define TT_PLATFORM_MICROSOFT 3 #define TT_PLATFORM_MICROSOFT 3
/* artificial values defined ad-hoc by FreeType */
#define TT_PLATFORM_ADOBE 7
/*************************************************************************/ /*************************************************************************/
/* */ /* */
@ -118,6 +121,19 @@
#define TT_MS_ID_JOHAB 6 #define TT_MS_ID_JOHAB 6
/*************************************************************************/
/* */
/* possible values of the platform specific encoding identifier field in */
/* the name records of the TTF `name' table if the `platform' identifier */
/* code is TT_PLATFORM_ADOBE. */
/* */
/* These are artificial values defined ad-hoc by FreeType. */
/* */
#define TT_ADOBE_ID_STANDARD 0
#define TT_ADOBE_ID_EXPERT 1
#define TT_ADOBE_ID_CUSTOM 2
/*************************************************************************/ /*************************************************************************/
/* */ /* */
/* Possible values of the language identifier field in the name records */ /* Possible values of the language identifier field in the name records */

View File

@ -2230,8 +2230,8 @@
/* decoding. */ /* decoding. */
/* */ /* */
/* <Input> */ /* <Input> */
/* face :: A handle to the source face object. */ /* face :: A handle to the source face object. */
/* charmap :: A handle to the selected charmap. */ /* charmap :: A handle to the selected charmap. */
/* */ /* */
/* <Return> */ /* <Return> */
/* FreeType error code. 0 means success. */ /* FreeType error code. 0 means success. */