From e67e349a0bb0bb0514f1c90baecc44022c73a12b Mon Sep 17 00:00:00 2001
From: Werner Lemberg This is the first section of the FreeType 2 tutorial. It will
+ This is the first part of the FreeType 2 tutorial. It will
teach you to do the following: To include the main FreeType header file, simply say To include the main FreeType header file, say in your application code. Note that other files are available in the
FreeType include directory, most of them being included by
- freetype.h. They will be described later in this tutorial.
@@ -55,7 +55,7 @@
1. Header files
-
@@ -64,7 +64,8 @@
As you can see, the function returns an error code, like most others in the FreeType API. An error code of 0 always means that the operation was successful; otherwise, the value describes the error, - and library is set to NULL.
+ and library is set to NULL.- library + library |
- a handle to the FreeType library instance where the face + A handle to the FreeType library instance where the face object is created |
- filepathname + filepathname |
- the font file pathname (standard C string). +The font file pathname (a standard C string). |
- face_index + face_index |
Certain font formats allow several font faces to be embedded @@ -191,13 +192,13 @@ |
- face + face |
A pointer to the handle that will be set to describe the new face object. -It is set to NULL in case of error. +It is set to NULL in case of error. |
As you can see, FT_New_Memory_Face() simply takes a - pointer to the font file buffer and its size in bytes instead of a - file pathname. Other than that, it has exactly the same semantics as +
As you can see, FT_New_Memory_Face() takes a pointer to + the font file buffer and its size in bytes instead of a file pathname. + Other than that, it has exactly the same semantics as FT_New_Face().
There are cases where using a file pathname or preloading the file - in memory is simply not enough. With FreeType 2, it is possible - to provide your own implementation of i/o routines.
+ in memory is not sufficient. With FreeType 2, it is possible to + provide your own implementation of I/O routines.This is done through the FT_Open_Face() function, which 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 font driver when creating the object. We advise you to refer to the - FreeType 2 reference manual in order to learn how to use it.
+ FreeType 2 API reference in order to learn how to use it.Note that providing a custom stream might also be used to access a TrueType font embedded in a Postscript Type 42 wrapper.
@@ -267,7 +268,7 @@- face->num_glyphs + face->num_glyphs |
Gives the number of glyphs available in the font face. @@ -277,7 +278,7 @@ | |
- face->flags + face->flags |
A 32-bit integer containing bit flags used to describe some @@ -290,7 +291,7 @@ | |
- face->units_per_EM + face->units_per_EM |
This field is only valid for scalable formats (it is set @@ -300,7 +301,7 @@ | |
- face->num_fixed_sizes + face->num_fixed_sizes |
This field gives the number of embedded bitmap strikes @@ -313,7 +314,7 @@ | |
- face->fixed_sizes + face->fixed_sizes |
This is a pointer to an array of FT_Bitmap_Size @@ -376,7 +377,7 @@ error = FT_Set_Pixel_Sizes( - face, /* handle to face object */ - 0, /* pixel_width */ - 16 ); /* pixel_height */+ face, /* handle to face object */ + 0, /* pixel_width */ + 16 ); /* pixel_height */ This example will set the character pixel sizes to 16x16 pixels. @@ -421,7 +422,7 @@ 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 set the pixel size to a value that is not listed in the - face->fixed_sizes> array. + face->fixed_sizes array.@@ -436,7 +437,7 @@ Usually, an application wants to load a glyph image based on its character code, which is a unique value that defines the character for a given encoding. For example, the character - code 65 represents the `A' in ASCII encoding. + code 65 in ASCII encoding represents letter `A'.A face object contains one or more tables, called charmaps, that are used to convert character codes to glyph @@ -468,10 +469,10 @@ face. 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 - glyph image in the face, the value 0 is returned. By convention, - it always corresponds to a special glyph image called the missing - glyph, which usually is represented as a box or a space. + return an error code. If a given character code has no glyph image in + the face, the value 0 is returned. By convention, it always + corresponds to a special glyph image called the missing + glyph, which usually is represented as a box or a space.
b. Loading a glyph from the face
@@ -481,8 +482,8 @@
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.
Scalable formats like TrueType or Type 1 use vectorial shapes,
- named outlines to describe each glyph. Some formats may have
- even more exotic ways of representing glyph (e.g. MetaFont).
+ named outlines, to describe each glyph. Some formats may have
+ even more exotic ways of representing glyphs (e.g. MetaFont).
Fortunately, FreeType 2 is flexible enough to support any kind of
glyph format through a simple API.
@@ -513,10 +514,10 @@
If a bitmap is found for the corresponding glyph and pixel - size, it will be loaded into the slot (embedded bitmaps are always - favored over native image formats, because we assume that they are - higher-quality versions of the same glyph. This can be changed by - using the FT_LOAD_NO_BITMAP flag) + size, it will be loaded into the slot. Embedded bitmaps are + always favored over native image formats, because we assume that + they are higher-quality versions of the same glyph. This can be + changed by using the FT_LOAD_NO_BITMAP flag.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. It is positive to indicate an upwards distance. -The second part of the tutorial will describe the contents of a - glyph slot and how to access specific glyph information (including + The second part of the tutorial describes the contents of a glyph + slot and how to access specific glyph information (including metrics). @@ -563,18 +564,18 @@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 face->charmap. This field - is NULL if no charmap is selected, which typically happens when you - create a new FT_Face object from a font file that doesn't - contain an ASCII, Latin-1, or Unicode charmap (rare stuff). + is NULL if no charmap is selected, which typically happens + when you create a new FT_Face object from a font file that + doesn't contain an ASCII, Latin-1, or Unicode charmap (rare + stuff).There are two ways to select a different charmap with FreeType 2. The easiest is if the encoding you need already has - a corresponding enumeration defined in - <freetype/freetype.h>, as ft_encoding_big5. - In this case, you can simply call FT_Select_CharMap() as - in + a corresponding enumeration defined in freetype/freetype.h, + as ft_encoding_big5. In this case, you can simply call + FT_Select_CharMap() as inerror = FT_Select_CharMap( @@ -582,12 +583,12 @@ ft_encoding_big5 ); /* encoding */- Another way is to manually parse the list of charmaps for the face, + Another way is to manually parse the list of charmaps for the face; this is accessible through the fields num_charmaps and - charmaps (notice the final 's') of the face object. As you - could expect, the first is the number of charmaps in the face, while - the second is a table of pointers to the charmaps embedded in - the face. + charmaps (notice the final 's') of the face object. As + expected, the first is the number of charmaps in the face, while the + second is a table of pointers to the charmaps embedded in the + face.Each charmap has a few visible fields used to describe it more precisely. Mainly, one will look at charmap->platform_id and @@ -595,16 +596,20 @@ be used to describe the charmap in a rather generic way. 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 - the TrueType specification, but you can also use the file - <freetype/ftnameid.h> which defines several helpful - constants to deal with them. + pair (3,1) corresponds to Unicode (on the Windows platform). A list + of such pairs is defined in the TrueType specification, but you can + also use the file <freetype/ttnameid.h> which defines + several helpful constants to deal with them. + +Note that some pid/eid pairs are artificial; such values + have been created by FreeType to identify platforms resp. encodings + not covered by the original TrueType specification. To look up a specific encoding you need to find a corresponding - value pair in the specification, then look for it in the charmaps - list. Bear in mind that some encodings correspond to several values - pairs (yes, it's a real mess, but blame Apple and Microsoft on such - stupidity). Here some code to do it: + value pair in the specification, then look for it in the + charmaps list. Bear in mind that some encodings correspond + to several values pairs (yes, it's a real mess, but blame Apple and + Microsoft on such stupidity). Here some code to do it:@@ -654,26 +659,26 @@ This function will set the current transformation for a given face - object. Its second parameter is a pointer to a FT_Matrix - structure that describes a 2x2 affine matrix. The third parameter is - a pointer to a FT_Vector structure that describes a simple 2d - vector that is used to translate the glyph image after the - 2x2 transformation. + object. Its second parameter is a pointer to an FT_Matrix + structure that describes a 2x2 affine matrix. The third + parameter is a pointer to an FT_Vector structure that + describes a simple 2d vector that is used to translate the glyph + image after the 2x2 transformation. -Note that the matrix pointer can be set to NULL, in which case the - identity transformation will be used. Coefficients of the matrix are - otherwise in 16.16 fixed float units. +Note that the matrix pointer can be set to NULL, in which + case the identity transformation will be used. Coefficients of the + matrix are otherwise in 16.16 fixed float units. -The vector pointer can also be set to NULL in which case a delta - vector of (0,0) will be used. The vector coordinates are expressed in - 1/64th of a pixel (also known as 26.6 fixed floats). +The vector pointer can also be set to NULL in which case a + delta vector of (0,0) will be used. The vector coordinates are + expressed in 1/64th of a pixel (also known as 26.6 fixed floats). The transformation is applied to every glyph that is loaded through FT_Load_Glyph() and is completely independent of any hinting process. This means that you won't get the same results if you load a glyph at the size of 24 pixels, or a glyph at the size at 12 pixels scaled by 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). If you ever need to use a non-orthogonal transformation with @@ -692,9 +697,8 @@ 7. Simple text rendering - We will now present you with a very simple example used to render a - string of 8-bit Latin-1 text, assuming a face that contains a Unicode - charmap +We will now present a very simple example used to render a string of + 8-bit Latin-1 text, assuming a face that contains a Unicode charmap 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 @@ -764,9 +768,9 @@ truncated to integer pixels on each iteration. Note that you can also specify that you want a monochrome - bitmap instead by using the additional FT_LOAD_MONOCHROME - load flag. + bitmap by using the FT_LOAD_MONOCHROME load flag + instead.In this first section, you have learned the basics of - FreeType 2, as well as sufficient knowledge how to render rotated - text. +In this first section, you have learned the basics of FreeType 2 + as well as sufficient knowledge how to render rotated text. 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 - with scaling, hinting, kerning, etc. + you access glyph metrics and images directly, how to deal with scaling, + hinting, kerning, etc.The third part will discuss issues like modules, caching, and a few other advanced topics like how to use multiple size objects with a diff --git a/docs/tutorial/step2.html b/docs/tutorial/step2.html index 242546389..1c8c94d73 100644 --- a/docs/tutorial/step2.html +++ b/docs/tutorial/step2.html @@ -37,8 +37,8 @@ Introduction - This is the second section of the FreeType 2 tutorial. It will - teach you the following: +This is the second part of the FreeType 2 tutorial. It will teach + you the following:
Note that only a few font formats provide vertical metrics. You can test wether a given face object contains them by using the macro - FT_HAS_VERTICAL(face), which is true if has vertical - metrics. + FT_HAS_VERTICAL(face), which is true if vertical metrics are + available.Individual glyph metrics can be accessed by first loading the glyph in a face's glyph slot, then using the face->glyph->metrics @@ -85,7 +85,7 @@ |
This is the width of the glyph image's bounding box. It is - independent of layout direction. + independent of the layout direction. |
This is the height of the glyph image's bounding box. It is - independent of layout direction. + independent of the layout direction. | ||
- Which stands for "X Pixels Per EM"; this is the size in integer - pixels of the EM square, which also is the horizontal - character pixel size, called pixel_size_x in the - above example. + This is the size in integer pixels of the EM square, which also is + the horizontal character pixel size, called + pixel_size_x in the above example. x_ppem means + "x pixels per EM". | ||
- Which stands for "Y Pixels Per EM"; this is the size in integer - pixels of the EM square, which also is the vertical character - pixel size, called pixel_size_y in the above - example. + This is the size in integer pixels of the EM square, which also is + the vertical character pixel size, called + pixel_size_y in the above example. y_ppem means + "y pixels per EM". | ||
Basically, this means that you can scale a distance expressed in - font units to 26.6 pixels directly with the help of the - FT_MulFix() function, as in:
+You can scale a distance expressed in font units to 26.6 pixels + directly with the help of the FT_MulFix() function, as + in:
@@ -1567,12 +1569,12 @@ b. Accessing design metrics (glyph & global) -You can access glyph metrics in font units simply by specifying the +
You can access glyph metrics in font units by specifying the FT_LOAD_NO_SCALE bit flag in FT_Load_Glyph() or FT_Load_Char(). The metrics returned in face->glyph->metrics will then all be in font units.
-You can access unscaled kerning data using the +
Unscaled kerning data can be retrieved using the ft_kerning_mode_unscaled mode.
Finally, a few global metrics are available directly in font units @@ -1590,9 +1592,8 @@ render text much more intelligently (kerning, measuring, transforming & caching).
-You have now sufficient knowledge to build a pretty decent text - service on top of FreeType 2, and you could possibly stop there if - you want.
+With this knowledge you can build a pretty decent text service on top + of FreeType 2, and you could possibly stop there if you want.
The next section will deal with FreeType 2 internals (like modules, vector outlines, font drivers, renderers), as well as a few diff --git a/include/freetype/freetype.h b/include/freetype/freetype.h index d3ae75223..dc22eb992 100644 --- a/include/freetype/freetype.h +++ b/include/freetype/freetype.h @@ -359,9 +359,8 @@ /*
*/ /* face :: A handle to the parent face object. */ /* */ - /* flags :: A set of bit flags used to describe the charmap. */ - /* Each bit indicates that a given encoding is */ - /* supported. */ + /* encoding :: A tag which identifies the charmap. Use this with */ + /* FT_Select_Charmap(). */ /* */ /* platform_id :: An ID number describing the platform for the */ /* following encoding ID. This comes directly from */ diff --git a/include/freetype/ttnameid.h b/include/freetype/ttnameid.h index e76ff6190..6bd08158b 100644 --- a/include/freetype/ttnameid.h +++ b/include/freetype/ttnameid.h @@ -35,6 +35,9 @@ #define TT_PLATFORM_ISO 2 /* deprecated */ #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 + /*************************************************************************/ + /* */ + /* 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 */ diff --git a/src/base/ftobjs.c b/src/base/ftobjs.c index bfa440e61..f8121101d 100644 --- a/src/base/ftobjs.c +++ b/src/base/ftobjs.c @@ -2230,8 +2230,8 @@ /* decoding. */ /* */ /* */ - /* face :: A handle to the source face object. */ - /* charmap :: A handle to the selected charmap. */ + /* face :: A handle to the source face object. */ + /* charmap :: A handle to the selected charmap. */ /* */ /* */ /* FreeType error code. 0 means success. */