update to freetype-docs 2.3.9

This commit is contained in:
matthieu 2009-03-26 07:36:34 +00:00
parent 8a907a311b
commit 703afbb0a2
6 changed files with 524 additions and 30 deletions

View File

@ -343,7 +343,7 @@
</tr>
<tr valign=top>
<td>
<tt>module_requires</tt>
<tt>module_interface</tt>
</td>
<td>
<p>Most modules support one or more "interfaces", i.e. tables of

View File

@ -102,7 +102,7 @@
Increment the pen position by the glyph's advance width in pixels.
</li>
<li>
Start over at step&nbsp3 for each of the remaining glyphs.
Start over at step&nbsp;3 for each of the remaining glyphs.
</li>
<li>
When all glyphs are done, set the text cursor to the new pen

View File

@ -0,0 +1,400 @@
// example2.cpp
// This file demonstrates how to render a coloured glyph with a differently
// coloured outline.
//
// Written Feb. 2009 by Erik Möller,
// with slight modifications by Werner Lemberg
//
// Public domain.
//
// Eric uses similar code in real applications; see
//
// http://www.timetrap.se
// http://www.emberwind.se
//
// for more.
#include <ft2build.h>
#include FT_FREETYPE_H
#include FT_STROKER_H
#include <vector>
#include <fstream>
#include <iostream>
#ifdef _MSC_VER
#define MIN __min
#define MAX __max
#else
#define MIN std::min
#define MAX std::max
#endif
// Define some fixed size types.
typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned int uint32;
// Try to figure out what endian this machine is using. Note that the test
// below might fail for cross compilation; additionally, multi-byte
// characters are implementation-defined in C preprocessors.
#if (('1234' >> 24) == '1')
#elif (('4321' >> 24) == '1')
#define BIG_ENDIAN
#else
#error "Couldn't determine the endianness!"
#endif
// A simple 32-bit pixel.
union Pixel32
{
Pixel32()
: integer(0) { }
Pixel32(uint8 bi, uint8 gi, uint8 ri, uint8 ai = 255)
{
b = bi;
g = gi;
r = ri;
a = ai;
}
uint32 integer;
struct
{
#ifdef BIG_ENDIAN
uint8 a, r, g, b;
#else // BIG_ENDIAN
uint8 b, g, r, a;
#endif // BIG_ENDIAN
};
};
struct Vec2
{
Vec2() { }
Vec2(float a, float b)
: x(a), y(b) { }
float x, y;
};
struct Rect
{
Rect() { }
Rect(float left, float top, float right, float bottom)
: xmin(left), xmax(right), ymin(top), ymax(bottom) { }
void Include(const Vec2 &r)
{
xmin = MIN(xmin, r.x);
ymin = MIN(ymin, r.y);
xmax = MAX(xmax, r.x);
ymax = MAX(ymax, r.y);
}
float Width() const { return xmax - xmin + 1; }
float Height() const { return ymax - ymin + 1; }
float xmin, xmax, ymin, ymax;
};
// TGA Header struct to make it simple to dump a TGA to disc.
#if defined(_MSC_VER) || defined(__GNUC__)
#pragma pack(push, 1)
#pragma pack(1) // Dont pad the following struct.
#endif
struct TGAHeader
{
uint8 idLength, // Length of optional identification sequence.
paletteType, // Is a palette present? (1=yes)
imageType; // Image data type (0=none, 1=indexed, 2=rgb,
// 3=grey, +8=rle packed).
uint16 firstPaletteEntry, // First palette index, if present.
numPaletteEntries; // Number of palette entries, if present.
uint8 paletteBits; // Number of bits per palette entry.
uint16 x, // Horiz. pixel coord. of lower left of image.
y, // Vert. pixel coord. of lower left of image.
width, // Image width in pixels.
height; // Image height in pixels.
uint8 depth, // Image color depth (bits per pixel).
descriptor; // Image attribute flags.
};
#if defined(_MSC_VER) || defined(__GNUC__)
#pragma pack(pop)
#endif
bool
WriteTGA(const std::string &filename,
const Pixel32 *pxl,
uint16 width,
uint16 height)
{
std::ofstream file(filename.c_str(), std::ios::binary);
if (file)
{
TGAHeader header;
memset(&header, 0, sizeof(TGAHeader));
header.imageType = 2;
header.width = width;
header.height = height;
header.depth = 32;
header.descriptor = 0x20;
file.write((const char *)&header, sizeof(TGAHeader));
file.write((const char *)pxl, sizeof(Pixel32) * width * height);
return true;
}
return false;
}
// A horizontal pixel span generated by the FreeType renderer.
struct Span
{
Span() { }
Span(int _x, int _y, int _width, int _coverage)
: x(_x), y(_y), width(_width), coverage(_coverage) { }
int x, y, width, coverage;
};
typedef std::vector<Span> Spans;
// Each time the renderer calls us back we just push another span entry on
// our list.
void
RasterCallback(const int y,
const int count,
const FT_Span * const spans,
void * const user)
{
Spans *sptr = (Spans *)user;
for (int i = 0; i < count; ++i)
sptr->push_back(Span(spans[i].x, y, spans[i].len, spans[i].coverage));
}
// Set up the raster parameters and render the outline.
void
RenderSpans(FT_Library &library,
FT_Outline * const outline,
Spans *spans)
{
FT_Raster_Params params;
memset(&params, 0, sizeof(params));
params.flags = FT_RASTER_FLAG_AA | FT_RASTER_FLAG_DIRECT;
params.gray_spans = RasterCallback;
params.user = spans;
FT_Outline_Render(library, outline, &params);
}
// Render the specified character as a colored glyph with a colored outline
// and dump it to a TGA.
void
WriteGlyphAsTGA(FT_Library &library,
const std::string &fileName,
wchar_t ch,
FT_Face &face,
int size,
const Pixel32 &fontCol,
const Pixel32 outlineCol,
float outlineWidth)
{
// Set the size to use.
if (FT_Set_Char_Size(face, size << 6, size << 6, 90, 90) == 0)
{
// Load the glyph we are looking for.
FT_UInt gindex = FT_Get_Char_Index(face, ch);
if (FT_Load_Glyph(face, gindex, FT_LOAD_NO_BITMAP) == 0)
{
// Need an outline for this to work.
if (face->glyph->format == FT_GLYPH_FORMAT_OUTLINE)
{
// Render the basic glyph to a span list.
Spans spans;
RenderSpans(library, &face->glyph->outline, &spans);
// Next we need the spans for the outline.
Spans outlineSpans;
// Set up a stroker.
FT_Stroker stroker;
FT_Stroker_New(library, &stroker);
FT_Stroker_Set(stroker,
(int)(outlineWidth * 64),
FT_STROKER_LINECAP_ROUND,
FT_STROKER_LINEJOIN_ROUND,
0);
FT_Glyph glyph;
if (FT_Get_Glyph(face->glyph, &glyph) == 0)
{
FT_Glyph_StrokeBorder(&glyph, stroker, 0, 1);
// Again, this needs to be an outline to work.
if (glyph->format == FT_GLYPH_FORMAT_OUTLINE)
{
// Render the outline spans to the span list
FT_Outline *o =
&reinterpret_cast<FT_OutlineGlyph>(glyph)->outline;
RenderSpans(library, o, &outlineSpans);
}
// Clean up afterwards.
FT_Stroker_Done(stroker);
FT_Done_Glyph(glyph);
// Now we need to put it all together.
if (!spans.empty())
{
// Figure out what the bounding rect is for both the span lists.
Rect rect(spans.front().x,
spans.front().y,
spans.front().x,
spans.front().y);
for (Spans::iterator s = spans.begin();
s != spans.end(); ++s)
{
rect.Include(Vec2(s->x, s->y));
rect.Include(Vec2(s->x + s->width - 1, s->y));
}
for (Spans::iterator s = outlineSpans.begin();
s != outlineSpans.end(); ++s)
{
rect.Include(Vec2(s->x, s->y));
rect.Include(Vec2(s->x + s->width - 1, s->y));
}
#if 0
// This is unused in this test but you would need this to draw
// more than one glyph.
float bearingX = face->glyph->metrics.horiBearingX >> 6;
float bearingY = face->glyph->metrics.horiBearingY >> 6;
float advance = face->glyph->advance.x >> 6;
#endif
// Get some metrics of our image.
int imgWidth = rect.Width(),
imgHeight = rect.Height(),
imgSize = imgWidth * imgHeight;
// Allocate data for our image and clear it out to transparent.
Pixel32 *pxl = new Pixel32[imgSize];
memset(pxl, 0, sizeof(Pixel32) * imgSize);
// Loop over the outline spans and just draw them into the
// image.
for (Spans::iterator s = outlineSpans.begin();
s != outlineSpans.end(); ++s)
for (int w = 0; w < s->width; ++w)
pxl[(int)((imgHeight - 1 - (s->y - rect.ymin)) * imgWidth
+ s->x - rect.xmin + w)] =
Pixel32(outlineCol.r, outlineCol.g, outlineCol.b,
s->coverage);
// Then loop over the regular glyph spans and blend them into
// the image.
for (Spans::iterator s = spans.begin();
s != spans.end(); ++s)
for (int w = 0; w < s->width; ++w)
{
Pixel32 &dst =
pxl[(int)((imgHeight - 1 - (s->y - rect.ymin)) * imgWidth
+ s->x - rect.xmin + w)];
Pixel32 src = Pixel32(fontCol.r, fontCol.g, fontCol.b,
s->coverage);
dst.r = (int)(dst.r + ((src.r - dst.r) * src.a) / 255.0f);
dst.g = (int)(dst.g + ((src.g - dst.g) * src.a) / 255.0f);
dst.b = (int)(dst.b + ((src.b - dst.b) * src.a) / 255.0f);
dst.a = MIN(255, dst.a + src.a);
}
// Dump the image to disk.
WriteTGA(fileName, pxl, imgWidth, imgHeight);
delete [] pxl;
}
}
}
}
}
}
int
main(int argc,
char **argv)
{
if (argc != 3)
{
std::cerr << "Render letter `B' of given font as a TGA image.\n";
std::cerr << "\n";
std::cerr << "usage: example2 <font> <TGA-file>\n";
return 1;
}
// Initialize FreeType.
FT_Library library;
FT_Init_FreeType(&library);
// Open up a font file.
std::ifstream fontFile(argv[1], std::ios::binary);
if (fontFile)
{
// Read the entire file to a memory buffer.
fontFile.seekg(0, std::ios::end);
std::fstream::pos_type fontFileSize = fontFile.tellg();
fontFile.seekg(0);
unsigned char *fontBuffer = new unsigned char[fontFileSize];
fontFile.read((char *)fontBuffer, fontFileSize);
// Create a face from a memory buffer. Be sure not to delete the memory
// buffer until you are done using that font as FreeType will reference
// it directly.
FT_Face face;
FT_New_Memory_Face(library, fontBuffer, fontFileSize, 0, &face);
// Dump out a single glyph to a tga.
WriteGlyphAsTGA(library,
argv[2],
L'B',
face,
100,
Pixel32(255, 90, 30),
Pixel32(255, 255, 255),
3.0f);
// Now that we are done it is safe to delete the memory.
delete [] fontBuffer;
}
// Clean up the library
FT_Done_FreeType(library);
return 1;
}
/* EOF */

View File

@ -814,7 +814,7 @@
</h3>
<p>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</p>
8-bit Latin-1 text, assuming a face that contains a Unicode charmap.</p>
<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
@ -1094,7 +1094,7 @@
<a href="step2.html">FreeType&nbsp;2 Tutorial Step&nbsp;2</a>
</h3>
<p><font size=-3>Last update: 03-May-2007</font></p>
<p><font size=-3>Last update: 08-Aug-2007</font></p>
</body>
</html>

View File

@ -47,9 +47,9 @@
</h1>
<h3 align=center>
&copy; 2003, 2006, 2007 David Turner
&copy; 2009 David Turner
(<a href="mailto:david@freetype.org">david@freetype.org</a>)<br>
&copy; 2003, 2006, 2007 The FreeType Development Team
&copy; 2009 The FreeType Development Team
(<a href="http://www.freetype.org">www.freetype.org</a>)
</h3>
@ -63,8 +63,8 @@
Introduction
</h2>
<p>This is the second section of the FreeType 2 tutorial. It describes
how to</p>
<p>This is the second section of the FreeType&nbsp;2 tutorial. It
describes how to</p>
<ul>
<li>retrieve glyph metrics</li>
@ -99,7 +99,7 @@
<p>Individual glyph metrics can be accessed by first loading the glyph
in a face's glyph slot, then accessing them through the
<tt>face-&gt;glyph-&gt;metrics</tt> structure, whose type is <a
[A href="../reference/ft2-base_interface.html#FT_Glyph_Metrics">
href="../reference/ft2-base_interface.html#FT_Glyph_Metrics">
<tt>FT_Glyph_Metrics</tt></a>. We will discuss this in more detail
below; for now, we only note that it contains the following fields:</p>
@ -279,7 +279,7 @@
and even perform additional transformations and measures on it before
converting it to a bitmap.</p>
<p>The FreeType 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
first need to include the <a
href="../reference/ft2-header_file_macros.html#FT_GLYPH_H">
@ -465,7 +465,7 @@
<p>You may need to convert the glyph object to a bitmap once you have
conveniently cached or transformed it. This can be done easily with
the <a href="../reference/ft2-glyph_management.html">
<tt>FT_Glyph_To_Bitmap</tt></a> function. It is in charge of
<tt>FT_Glyph_To_Bitmap</tt></a> function. It is in charge of
converting any glyph object into a bitmap, as in:</p>
<div class="pre">
@ -605,12 +605,11 @@
</tr>
<tr valign=top>
<td>
<tt>global_bbox</tt>
<tt>bbox</tt>
</td>
<td>
<p>The global bounding box is defined as the largest rectangle
that can enclose all the glyphs in a font face. It is defined for
horizontal layouts only.</p>
that can enclose all the glyphs in a font face.</p>
</td>
</tr>
<tr valign=top>
@ -624,7 +623,7 @@
differently. For some, it represents the ascent of all capital
latin characters (without accents), for others it is the ascent of
the highest accented character, and finally, other formats define
it as being equal to <tt>global_bbox.yMax</tt>.</p>
it as being equal to <tt>bbox.yMax</tt>.</p>
</td>
</tr>
<tr valign=top>
@ -638,20 +637,20 @@
differently. For some, it represents the descent of all capital
latin characters (without accents), for others it is the ascent of
the lowest accented character, and finally, other formats define
it as being equal to <tt>global_bbox.yMin</tt>. This field is
it as being equal to <tt>bbox.yMin</tt>. This field is
negative for values below the baseline.</p>
</td>
</tr>
<tr valign=top>
<td>
<tt>text_height</tt>
<tt>height</tt>
</td>
<td>
<p>This field is simply used to compute a default line spacing
(i.e., the baseline-to-baseline distance) when writing text with
this font. Note that it usually is larger than the sum of the
ascender and descender taken as absolute values. There is also no
guarantee that no glyphs extend above or below subsequent
<p>This field is simply used to compute a <i>default</i> line
spacing (i.e., the baseline-to-baseline distance) when writing
text with this font. Note that it usually is larger than the sum
of the ascender and descender taken as absolute values. There is
also no guarantee that no glyphs extend above or below subsequent
baselines when using this distance.</p>
</td>
</tr>
@ -672,8 +671,7 @@
</td>
<td>
<p>Same as <tt>max_advance_width</tt> but for vertical text
layout. It is only available in fonts providing vertical glyph
metrics.</p>
layout.</p>
</td>
</tr>
<tr valign=top>
@ -683,7 +681,7 @@
<td>
<p>When displaying or rendering underlined text, this value
corresponds to the vertical position, relative to the baseline, of
the underline bar. It is negative if it is below the
the underline bar's center. It is negative if it is below the
baseline.</p>
</td>
</tr>
@ -712,7 +710,7 @@
the <tt>face-&gt;size-&gt;metrics</tt> structure.</p>
<p>Note that these values correspond to scaled versions of the design
global metrics, <em>with no rounding/grid-fitting performed</em>.
global metrics, <em>with no rounding or grid-fitting performed</em>.
They are also completely independent of any hinting process. In other
words, don't rely on them to get exact metrics at the pixel level.
They are expressed in 26.6 pixel format.</p>
@ -1347,7 +1345,7 @@
... load glyph sequence ...
... setup "matrix" and "delta" ...
... set up "matrix" and "delta" ...
<span class="comment">/* transform glyphs */</span>
for ( n = 0; n &lt; num_glyphs; n++ )
@ -1656,17 +1654,17 @@
<p>The next section will deal with FreeType&nbsp;2 internals (like
modules, vector outlines, font drivers, renderers), as well as a few
font format specific issues (mainly, how to access certain TrueType or
Type&nbsp;1 tables). [This section has not been written yet.]</p>
Type&nbsp;1 tables).</p>
</td></tr>
</table>
</center>
<h3 align=center>
<a href="step1.html">FreeType&nbsp;2 Tutorial Step&nbsp;1</a>
<a href="step3.html">FreeType&nbsp;2 Tutorial Step&nbsp;3</a>
</h3>
<p><font size=-3>Last update: 06-Feb-2007</font></p>
<p><font size=-3>Last update: 07-Mar-2009</font></p>
</body>
</html>

View File

@ -0,0 +1,96 @@
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<style type="text/css">
body { font-family: Verdana, Geneva, Arial, Helvetica, serif;
color: #000000;
background: #FFFFFF; }
p { text-align: justify; }
h1 { text-align: center; }
li { text-align: justify; }
td { padding: 0 0.5em 0 0.5em; }
a:link { color: #0000EF; }
a:visited { color: #51188E; }
a:hover { color: #FF0000; }
div.pre { font-family: monospace;
text-align: left;
white-space: pre;
color: blue; }
div.example { font-family: monospace;
text-align: left;
white-space: pre;
color: purple; }
span.comment { color: gray; }
</style>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<meta name="Author"
content="David Turner">
<title>FreeType 2 Tutorial</title>
</head>
<body text="#000000"
bgcolor="#FFFFFF"
link="#0000EF"
vlink="#51188E"
alink="#FF0000">
<h1 align=center>
FreeType&nbsp;2 Tutorial<br>
Step&nbsp;3 &mdash; handling internals
</h1>
<h3 align=center>
&copy; 2009 Werner Lemberg
(<a href="mailto:wl@gnu.org">wl@gnu.org</a>)<br>
&copy; 2009 The FreeType Development Team
(<a href="http://www.freetype.org">www.freetype.org</a>)
</h3>
<center>
<table width="70%">
<tr><td>
<hr>
<h2>
Introduction
</h2>
<p>This is the third section of the FreeType&nbsp;2 tutorial. It
describes how to deal with various internals of the library like</p>
<ul>
<li>the module interface</li>
<li>functions for manipulating vector outlines</li>
<li>font driver issues</li>
<li>interaction with renderers using callbacks</li>
<li>accessing font specific data, for example PostScript font
dictionaries and TrueType tables</li>
</ul>
<p>None of these items have been written yet. However, <a
href="mailto:erik@timetrap.se">Erik Möller</a> contributed a very nice C++
example which shows renderer callbacks in action to draw a coloured glyph
with a differently coloured outline.</p>
<p>The source code can be found <a href="example2.cpp">here</a>.</p>
</td></tr>
</table>
</center>
<h3 align=center>
<a href="step1.html">FreeType&nbsp;2 Tutorial Step&nbsp;1</a>
</h3>
<p><font size=-3>Last update: 07-Mar-2009</font></p>
</body>
</html>