diff --git a/lib/freetype/docs/design/design-5.html b/lib/freetype/docs/design/design-5.html index 7ef5b4010..053621c41 100644 --- a/lib/freetype/docs/design/design-5.html +++ b/lib/freetype/docs/design/design-5.html @@ -343,7 +343,7 @@ - module_requires + module_interface

Most modules support one or more "interfaces", i.e. tables of diff --git a/lib/freetype/docs/glyphs/glyphs-5.html b/lib/freetype/docs/glyphs/glyphs-5.html index 4dbb7e7cc..65f2de441 100644 --- a/lib/freetype/docs/glyphs/glyphs-5.html +++ b/lib/freetype/docs/glyphs/glyphs-5.html @@ -102,7 +102,7 @@ Increment the pen position by the glyph's advance width in pixels.

  • - Start over at step 3 for each of the remaining glyphs. + Start over at step 3 for each of the remaining glyphs.
  • When all glyphs are done, set the text cursor to the new pen diff --git a/lib/freetype/docs/tutorial/example2.cpp b/lib/freetype/docs/tutorial/example2.cpp new file mode 100644 index 000000000..a29bc31b5 --- /dev/null +++ b/lib/freetype/docs/tutorial/example2.cpp @@ -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 +#include FT_FREETYPE_H +#include FT_STROKER_H + +#include +#include +#include + + +#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 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(¶ms, 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, ¶ms); +} + + +// 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(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 \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 */ diff --git a/lib/freetype/docs/tutorial/step1.html b/lib/freetype/docs/tutorial/step1.html index e10616f15..0691663b4 100644 --- a/lib/freetype/docs/tutorial/step1.html +++ b/lib/freetype/docs/tutorial/step1.html @@ -814,7 +814,7 @@

    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

    + 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 @@ -1094,7 +1094,7 @@ FreeType 2 Tutorial Step 2 -

    Last update: 03-May-2007

    +

    Last update: 08-Aug-2007

    diff --git a/lib/freetype/docs/tutorial/step2.html b/lib/freetype/docs/tutorial/step2.html index 2c6728673..d6f6503c6 100644 --- a/lib/freetype/docs/tutorial/step2.html +++ b/lib/freetype/docs/tutorial/step2.html @@ -47,9 +47,9 @@

    - © 2003, 2006, 2007 David Turner + © 2009 David Turner (david@freetype.org)
    - © 2003, 2006, 2007 The FreeType Development Team + © 2009 The FreeType Development Team (www.freetype.org)

    @@ -63,8 +63,8 @@ Introduction -

    This is the second section of the FreeType 2 tutorial. It describes - how to

    +

    This is the second section of the FreeType 2 tutorial. It + describes how to

    • retrieve glyph metrics
    • @@ -99,7 +99,7 @@

      Individual glyph metrics can be accessed by first loading the glyph in a face's glyph slot, then accessing them through the face->glyph->metrics structure, whose type is + href="../reference/ft2-base_interface.html#FT_Glyph_Metrics"> FT_Glyph_Metrics. We will discuss this in more detail below; for now, we only note that it contains the following fields:

      @@ -279,7 +279,7 @@ and even perform additional transformations and measures on it before converting it to a bitmap.

      -

      The FreeType 2 API has a specific extension which is capable of +

      The FreeType 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 @@ -465,7 +465,7 @@

      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 - FT_Glyph_To_Bitmap function. It is in charge of + FT_Glyph_To_Bitmap function. It is in charge of converting any glyph object into a bitmap, as in:

      @@ -605,12 +605,11 @@ - global_bbox + bbox

      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.

      + that can enclose all the glyphs in a font face.

      @@ -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 global_bbox.yMax.

      + it as being equal to bbox.yMax.

      @@ -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 global_bbox.yMin. This field is + it as being equal to bbox.yMin. This field is negative for values below the baseline.

      - text_height + height -

      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 +

      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 baselines when using this distance.

      @@ -672,8 +671,7 @@

      Same as max_advance_width but for vertical text - layout. It is only available in fonts providing vertical glyph - metrics.

      + layout.

      @@ -683,7 +681,7 @@

      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.

      @@ -712,7 +710,7 @@ the face->size->metrics structure.

      Note that these values correspond to scaled versions of the design - global metrics, with no rounding/grid-fitting performed. + global metrics, with no rounding or grid-fitting performed. 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.

      @@ -1347,7 +1345,7 @@ ... load glyph sequence ... - ... setup "matrix" and "delta" ... + ... set up "matrix" and "delta" ... /* transform glyphs */ for ( n = 0; n < num_glyphs; n++ ) @@ -1656,17 +1654,17 @@

      The next section will deal with FreeType 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 1 tables). [This section has not been written yet.]

      + Type 1 tables).

      - FreeType 2 Tutorial Step 1 + FreeType 2 Tutorial Step 3

      -

      Last update: 06-Feb-2007

      +

      Last update: 07-Mar-2009

      diff --git a/lib/freetype/docs/tutorial/step3.html b/lib/freetype/docs/tutorial/step3.html new file mode 100644 index 000000000..9935ca606 --- /dev/null +++ b/lib/freetype/docs/tutorial/step3.html @@ -0,0 +1,96 @@ + + + + + + + FreeType 2 Tutorial + + + + +

      + FreeType 2 Tutorial
      + Step 3 — handling internals +

      + +

      + © 2009 Werner Lemberg + (wl@gnu.org)
      + © 2009 The FreeType Development Team + (www.freetype.org) +

      + +
      + + +
      + +
      + +

      + Introduction +

      + +

      This is the third section of the FreeType 2 tutorial. It + describes how to deal with various internals of the library like

      + +
        +
      • the module interface
      • +
      • functions for manipulating vector outlines
      • +
      • font driver issues
      • +
      • interaction with renderers using callbacks
      • +
      • accessing font specific data, for example PostScript font + dictionaries and TrueType tables
      • +
      + +

      None of these items have been written yet. However, Erik Möller contributed a very nice C++ + example which shows renderer callbacks in action to draw a coloured glyph + with a differently coloured outline.

      + +

      The source code can be found here.

      + +
      +
      + +

      + FreeType 2 Tutorial Step 1 +

      + +

      Last update: 07-Mar-2009

      + + +