ref: f9ca2bb58a3c8e70cf5e0e0d2580c50385c48df0
parent: ac39ecdca8db98fcca49f56a615cd84d796bd9bc
author: David Turner <[email protected]>
date: Fri Jun 30 19:12:55 EDT 2000
managed to re-design entirely the API in <freetype/ftglyph.h> It is now really the "glyph factory" that Stefan was probably dreaming about.. fixed some recent formatting errors from Werner ;-) cleaned up the demonstration programs from most of the rust that they had, though I'm sure someone is going to re-format them really soon !! "ftstring" now uses the new ftglyph.h API, and is now faster and smaller.. yep..
--- a/demos/src/ftmulti.c
+++ b/demos/src/ftmulti.c
@@ -152,83 +152,51 @@
char bit_buffer[MAX_BUFFER];
- /* Render a single glyph with the "grays" component */
+ /* Render a single glyph with the `grays' component */
static
FT_Error Render_Glyph( int x_offset,
int y_offset )
{
- FT_Bitmap bit2;
- grBitmap bit3;
- int width, height, pitch, size;
- int left, right, top, bottom;
- int x_top, y_top;
-
- /* first, render the glyph into an intermediate buffer */
-
- left = FLOOR( glyph->metrics.horiBearingX );
- right = CEIL( glyph->metrics.horiBearingX + glyph->metrics.width );
- width = TRUNC( right - left );
-
- top = CEIL( glyph->metrics.horiBearingY );
- bottom = FLOOR( glyph->metrics.horiBearingY - glyph->metrics.height );
- height = TRUNC( top - bottom );
-
- if ( glyph->format == ft_glyph_format_outline )
+ grBitmap bit3;
+ FT_Pos x_top, y_top;
+
+ /* first, render the glyph image into a bitmap */
+ if (glyph->format != ft_glyph_format_bitmap)
{
- pitch = antialias ? ( width + 3 ) & -4
- : ( width + 7 ) >> 3;
- size = pitch * height;
-
- if ( size > MAX_BUFFER )
- return FT_Err_Out_Of_Memory;
-
- bit2.width = width;
- bit2.rows = height;
- bit2.pitch = pitch;
- bit2.pixel_mode = antialias ? ft_pixel_mode_grays : ft_pixel_mode_mono;
- bit2.buffer = bit_buffer;
-
- bit3.rows = bit2.rows;
- bit3.width = bit2.width;
- bit3.pitch = bit2.pitch;
- bit3.mode = antialias ? bit.mode : gr_pixel_mode_mono;
- bit3.buffer = bit_buffer;
- bit3.grays = 256;
-
- FT_Outline_Translate( &glyph->outline, -left, -bottom );
- memset( bit_buffer, 0, size );
-
- if ( low_prec )
- glyph->outline.flags &= ~ft_outline_high_precision;
-
- error = FT_Outline_Get_Bitmap( library, &glyph->outline, &bit2 );
+ error = FT_Render_Glyph( glyph, antialias ? ft_render_mode_normal : ft_render_mode_mono );
+ if (error) return error;
+
}
- else
+
+ /* now blit it to our display screen */
+ bit3.rows = glyph->bitmap.rows;
+ bit3.width = glyph->bitmap.width;
+ bit3.pitch = glyph->bitmap.pitch;
+ bit3.buffer = glyph->bitmap.buffer;
+
+ switch (glyph->bitmap.pixel_mode)
{
- bit3.rows = glyph->bitmap.rows;
- bit3.width = glyph->bitmap.width;
- bit3.pitch = glyph->bitmap.pitch;
- bit3.mode = gr_pixel_mode_mono;
- bit3.buffer = glyph->bitmap.buffer;
- bit3.grays = 0;
+ case ft_pixel_mode_mono:
+ bit3.mode = gr_pixel_mode_mono;
+ bit3.grays = 0;
+ break;
+
+ case ft_pixel_mode_grays:
+ bit3.mode = gr_pixel_mode_gray;
+ bit3.grays = glyph->bitmap.num_grays;
}
- /* then, blit the image to the target surface */
+ /* Then, blit the image to the target surface */
+ x_top = x_offset + glyph->bitmap_left;
+ y_top = y_offset - glyph->bitmap_top;
- x_top = x_offset + TRUNC( left );
- y_top = y_offset - TRUNC( top );
-
-#if 0
- if ( bit.pitch < 0 )
- y_top = bit.rows - y_top;
-#endif
-
grBlitGlyphToBitmap( &bit, &bit3, x_top, y_top, fore_color );
- return FT_Err_Ok;
+ return 0;
}
+
static
FT_Error Reset_Scale( int pointSize )
{
@@ -239,11 +207,6 @@
pointSize << 6,
res,
res );
- if ( error )
- {
- /* to be written */
- }
-
return FT_Err_Ok;
}
--- a/demos/src/ftstring.c
+++ b/demos/src/ftstring.c
@@ -209,10 +209,12 @@
if (!glyph->image) continue;
- x = glyph->pos.x >> 6;
- y = glyph->pos.y >> 6;
+ x = glyph->pos.x;
+ y = glyph->pos.y;
- FT_Glyph_Get_Box( glyph->image, &cbox );
+ FT_Glyph_Get_CBox( glyph->image,
+ ft_glyph_bbox_gridfit,
+ &cbox );
cbox.xMin += x;
cbox.yMin += y;
@@ -230,7 +232,7 @@
/**************************************************************
*
- * Layout a string of glyphs
+ * Layout a string of glyphs, the glyphs are untransformed..
*
*/
static void layout_glyphs( void )
@@ -261,9 +263,9 @@
{
FT_Vector kern;
- FT_Get_Kerning( face, prev_index, glyph->glyph_index, &kern );
- kern.x = FT_MulFix( kern.x, face->size->metrics.x_scale );
- if (hinted) kern.x = (kern.x+32) & -64;
+ FT_Get_Kerning( face, prev_index, glyph->glyph_index,
+ hinted ? ft_kerning_default : ft_kerning_unfitted,
+ &kern );
origin_x += kern.x;
}
@@ -273,28 +275,24 @@
origin.x = origin_x;
origin.y = 0;
- if (transform)
- FT_Vector_Transform( &origin, &trans_matrix );
-
/* clear existing image if there is one */
if (glyph->image)
FT_Done_Glyph(glyph->image);
- /* load the glyph image */
- /* for now, we take a monochrome glyph bitmap */
- error = FT_Get_Glyph_Bitmap( face, glyph->glyph_index,
- load_flags,
- num_grays,
- &origin,
- (FT_BitmapGlyph*)&glyph->image );
+ /* load the glyph image (in its native format) */
+ /* for now, we take a monochrome glyph bitmap */
+ error = FT_Load_Glyph( face, glyph->glyph_index,
+ hinted ? FT_LOAD_DEFAULT : FT_LOAD_NO_HINTING ) ||
+ FT_Get_Glyph ( face->glyph, &glyph->image );
if (error) continue;
glyph->pos = origin;
- origin_x += glyph->image->advance;
+ origin_x += face->glyph->advance.x;
}
string_center.x = origin_x / 2;
string_center.y = 0;
+
if (transform)
FT_Vector_Transform( &string_center, &trans_matrix );
}
@@ -309,62 +307,81 @@
PGlyph glyph = glyphs;
grBitmap bit3;
int n;
+ FT_Vector delta;
+ /* first of all, we must compute the general delta for the glyph */
+ /* set.. */
+ delta.x = (x << 6) - string_center.x;
+ delta.y = ((bit.rows-y) << 6) - string_center.y;
+
for ( n = 0; n < num_glyphs; n++, glyph++ )
{
+ FT_Glyph image;
+ FT_Vector vec;
+
if (!glyph->image)
continue;
- switch (glyph->image->glyph_type)
+ /* copy image */
+ error = FT_Glyph_Copy( glyph->image, &image );
+ if (error) continue;
+
+ /* transform it */
+ vec = glyph->pos;
+ FT_Vector_Transform( &vec, &trans_matrix );
+ vec.x += delta.x;
+ vec.y += delta.y;
+ error = FT_Glyph_Transform( image, &trans_matrix, &vec );
+ if (!error)
{
- case ft_glyph_type_bitmap:
+ FT_BBox bbox;
+
+ /* check bounding box, if it's not within the display surface, we */
+ /* don't need to render it.. */
+
+ FT_Glyph_Get_CBox( image, ft_glyph_bbox_pixels, &bbox );
+
+ if ( bbox.xMax > 0 && bbox.yMax > 0 &&
+ bbox.xMin < bit.width && bbox.yMin < bit.rows )
+ {
+ /* convert to a bitmap - destroy native image */
+ error = FT_Glyph_To_Bitmap( &image,
+ ft_render_mode_normal,
+ 0, 1 );
+ if (!error)
{
- /* this is a bitmap, we simply blit it to our target surface */
- FT_BitmapGlyph bitm = (FT_BitmapGlyph)glyph->image;
- FT_Bitmap* source = &bitm->bitmap;
+ FT_BitmapGlyph bitmap = (FT_BitmapGlyph)image;
+ FT_Bitmap* source = &bitmap->bitmap;
FT_Pos x_top, y_top;
-
+
bit3.rows = source->rows;
bit3.width = source->width;
bit3.pitch = source->pitch;
bit3.buffer = source->buffer;
-
+
switch (source->pixel_mode)
{
case ft_pixel_mode_mono:
bit3.mode = gr_pixel_mode_mono;
break;
-
+
case ft_pixel_mode_grays:
bit3.mode = gr_pixel_mode_gray;
bit3.grays = source->num_grays;
break;
-
+
default:
continue;
}
-
+
/* now render the bitmap into the display surface */
- x_top = x + (glyph->pos.x >> 6) + bitm->left;
- y_top = y - (glyph->pos.y >> 6) - bitm->top;
+ x_top = bitmap->left;
+ y_top = bit.rows - bitmap->top;
grBlitGlyphToBitmap( &bit, &bit3, x_top, y_top, fore_color );
}
- break;
-#if 0
- case ft_glyph_type_outline:
- {
- /* in the case of outlines, we directly render it into the */
- /* target surface with the smooth renderer.. */
- FT_OutlineGlyph out = (FT_OutlineGlyph)glyph->image;
-
- FT_Outline_Translate( (x+pen_pos[n]) << 6, (y+
- error = FT_Outline_Render(
- }
- break;
-#endif
- default:
- ;
+ }
}
+ FT_Done_Glyph( image );
}
}
@@ -407,8 +424,6 @@
trans_matrix.xy = -sinus;
trans_matrix.yx = sinus;
trans_matrix.yy = cosinus;
-
- FT_Set_Transform(face,&trans_matrix, 0);
}
/****************************************************************************/
@@ -723,8 +738,7 @@
reset_transform();
layout_glyphs();
compute_bbox( &bbox );
- render_string( (bit.width-(string_center.x >> 5))/2,
- (bit.rows +(string_center.y >> 5))/2 );
+ render_string( bit.width/2, bit.rows/2 );
}
sprintf( Header, "%s %s (file %s)",
--- a/demos/src/fttimer.c
+++ b/demos/src/fttimer.c
@@ -20,7 +20,7 @@
/****************************************************************************/
#include <freetype/freetype.h>
-#include <freetype/ftrender.h>
+#include <freetype/ftglyph.h>
#include <stdio.h>
#include <stdlib.h>
@@ -27,8 +27,6 @@
#include <string.h>
#include <time.h> /* for clock() */
-#include "graph.h"
-
/* SunOS 4.1.* does not define CLOCKS_PER_SEC, so include <sys/param.h> */
/* to get the HZ macro which is the equivalent. */
#if defined(__sun__) && !defined(SVR4) && !defined(__SVR4)
@@ -45,51 +43,28 @@
FT_Library library;
FT_Face face;
- FT_Size size;
- FT_GlyphSlot glyph;
- FT_Outline outline;
-
- FT_Pos* cur_x;
- FT_Pos* cur_y;
-
- unsigned short* cur_endContour;
- unsigned char* cur_touch;
-
- FT_Outline outlines[MAX_GLYPHS];
-
int num_glyphs;
+ FT_Glyph glyphs[MAX_GLYPHS];
+
int tab_glyphs;
int cur_glyph;
- int cur_point;
- unsigned short cur_contour;
int pixel_size = CHARSIZE;
int repeat_count = 1;
- int use_grays = 0;
- FT_Bitmap Bit;
- grBitmap bit;
-
int Fail;
int Num;
- int vio_Height, vio_Width;
-
- short visual; /* display glyphs while rendering */
- short antialias; /* smooth fonts with gray levels */
+ short antialias = 1; /* smooth fonts with gray levels */
short force_low;
-#define RASTER_BUFF_SIZE 128000
- char raster_buff[ RASTER_BUFF_SIZE ];
-
-
- static void Clear_Buffer();
-
- static void Panic( const char* message )
+ static
+ void Panic( const char* message )
{
- fprintf( stderr, "%s\n error code = 0x%04x\n", message, error );
+ fprintf( stderr, "%s\n", message );
+ exit(1);
}
/*******************************************************************/
@@ -106,46 +81,11 @@
}
-/*******************************************************************/
-/* */
-/* Init_Engine: */
-/* */
-/* Allocates bitmap, render pool and other structs... */
-/* */
-/*******************************************************************/
- void Init_Engine( void )
- {
- Bit.rows = bit.rows;
- Bit.width = bit.width;
- Bit.pitch = bit.pitch;
- Bit.buffer = bit.buffer;
- Bit.pixel_mode = antialias ? ft_pixel_mode_grays : ft_pixel_mode_mono;
- Bit.num_grays = bit.grays;
- Clear_Buffer();
- }
-
-
/*******************************************************************/
/* */
-/* Clear_Buffer: */
+/* LoadChar: */
/* */
-/* Clears current bitmap. */
-/* */
-/*******************************************************************/
-
- static void Clear_Buffer( void )
- {
- long size = Bit.rows * Bit.pitch;
-
- memset( Bit.buffer, 0, size );
- }
-
-
-/*******************************************************************/
-/* */
-/* LoadTrueTypeChar: */
-/* */
/* Loads a glyph into memory. */
/* */
/*******************************************************************/
@@ -152,60 +92,20 @@
FT_Error LoadChar( int idx )
{
- error = FT_Load_Glyph( face, idx, FT_LOAD_DEFAULT );
- if ( error )
- return error;
-
- glyph->outline.flags |= ft_outline_single_pass |
- ft_outline_ignore_dropouts;
-
- if (force_low)
- glyph->outline.flags &= ~ft_outline_high_precision;
-
- /* debugging */
-#if 0
- if ( idx == 0 && !visual )
+ FT_Glyph glyph;
+
+ /* loads the glyph in the glyph slot */
+ error = FT_Load_Glyph( face, idx, FT_LOAD_DEFAULT ) ||
+ FT_Get_Glyph ( face->glyph, &glyph );
+ if ( !error )
{
- printf( "points = %d\n", outline.points );
- for ( j = 0; j < outline.points; j++ )
- printf( "%02x (%01hx,%01hx)\n",
- j, outline.xCoord[j], outline.yCoord[j] );
- printf( "\n" );
+ glyphs[cur_glyph++] = glyph;
}
-#endif
-
- /* create a new outline */
- FT_Outline_New( library,
- glyph->outline.n_points,
- glyph->outline.n_contours,
- &outlines[cur_glyph] );
-
- /* copy the glyph outline into it */
- glyph->outline.flags |= ft_outline_single_pass;
- if (force_low)
- glyph->outline.flags &= ~ft_outline_high_precision;
-
- FT_Outline_Copy( &glyph->outline, &outlines[cur_glyph] );
-
- /* center outline around 0 */
- {
- FT_BBox bbox;
-
- FT_Outline_Get_CBox( &glyph->outline, &bbox );
- FT_Outline_Translate( &outlines[cur_glyph],
- - ( bbox.xMax - bbox.xMin )/2,
- - ( bbox.yMax - bbox.yMin )/2 );
- }
- /* translate it */
- FT_Outline_Translate( &outlines[cur_glyph],
- Bit.width * 32 ,
- Bit.rows * 32 );
- cur_glyph++;
-
- return FT_Err_Ok;
+ return error;
}
+
/*******************************************************************/
/* */
/* ConvertRaster: */
@@ -216,8 +116,19 @@
FT_Error ConvertRaster( int index )
{
- outlines[index].flags |= ~ft_outline_single_pass;
- return FT_Outline_Get_Bitmap( library, &outlines[index], &Bit );
+ FT_Glyph bitmap;
+ FT_Error error;
+
+ bitmap = glyphs[index];
+ error = FT_Glyph_To_Bitmap( &bitmap,
+ antialias ? ft_render_mode_normal
+ : ft_render_mode_mono,
+ 0,
+ 0 );
+ if (!error)
+ FT_Done_Glyph( bitmap );
+
+ return error;
}
@@ -229,8 +140,7 @@
fprintf( stderr, "options:\n");
fprintf( stderr, " -r : repeat count to be used (default is 1)\n" );
fprintf( stderr, " -s : character pixel size (default is 600)\n" );
- fprintf( stderr, " -v : display results..\n" );
- fprintf( stderr, " -g : render anti-aliased glyphs\n" );
+ fprintf( stderr, " -m : render monochrome glyphs (default is anti-aliased)\n" );
fprintf( stderr, " -a : use smooth anti-aliaser\n" );
fprintf( stderr, " -l : force low quality even at small sizes\n" );
exit(1);
@@ -243,7 +153,6 @@
char filename[128 + 4];
char alt_filename[128 + 4];
char* execname;
- grSurface* surface = 0;
long t, t0, tz0;
@@ -250,30 +159,21 @@
execname = argv[0];
- antialias = 0;
- visual = 0;
- force_low = 0;
+ antialias = 1;
+ force_low = 0;
while ( argc > 1 && argv[1][0] == '-' )
{
switch ( argv[1][1] )
{
- case 'g':
- antialias = 1;
+ case 'm':
+ antialias = 0;
break;
- case 'a':
- use_grays = 1;
- break;
-
case 'l':
force_low = 1;
break;
- case 'v':
- visual = 1;
- break;
-
case 's':
argc--;
argv++;
@@ -328,17 +228,6 @@
if ( (error = FT_Init_FreeType( &library )) )
Panic( "Error while initializing engine" );
- /* set-up smooth anti-aliaser */
- if (use_grays)
- {
- FT_Renderer smooth;
-
- smooth = (FT_Renderer)FT_Get_Module( library, "smooth renderer" );
- if (!smooth) Panic( "Could not initialize smooth anti-aliasing renderer" );
-
- FT_Set_Renderer( library, smooth, 0, 0 );
- }
-
/* Load face */
error = FT_New_Face( library, filename, 0, &face );
@@ -350,7 +239,6 @@
/* get face properties and allocate preload arrays */
num_glyphs = face->num_glyphs;
- glyph = face->glyph;
tab_glyphs = MAX_GLYPHS;
if ( tab_glyphs > num_glyphs )
@@ -361,32 +249,6 @@
error = FT_Set_Pixel_Sizes( face, pixel_size, pixel_size );
if ( error ) Panic( "Could not reset instance" );
- bit.mode = antialias ? gr_pixel_mode_gray : gr_pixel_mode_mono;
- bit.width = 640;
- bit.rows = 480;
- bit.grays = 128;
-
- if ( visual )
- {
- if ( !grInitDevices() )
- Panic( "Could not initialize graphics.\n" );
-
- surface = grNewSurface( 0, &bit );
- if (!surface)
- Panic( "Could not open graphics window/screen.\n" );
- }
- else
- {
- if ( grNewBitmap( bit.mode,
- bit.grays,
- bit.width,
- bit.rows,
- &bit ) )
- Panic( "Could not create rendering buffer.\n" );
- }
-
- Init_Engine();
-
Num = 0;
Fail = 0;
@@ -405,8 +267,6 @@
/* First, preload 'tab_glyphs' in memory */
cur_glyph = 0;
- cur_point = 0;
- cur_contour = 0;
printf( "loading %d glyphs", tab_glyphs );
@@ -440,14 +300,6 @@
else
{
rendered_glyphs ++;
-
- if ( Num == 0 && visual )
- {
- sprintf( Header, "Glyph: %5d", Num );
- grSetTitle( surface, Header );
- grRefreshSurface( surface );
- Clear_Buffer();
- }
}
}
}
@@ -461,7 +313,7 @@
/* Now free all loaded outlines */
for ( Num = 0; Num < cur_glyph; Num++ )
- FT_Outline_Done( library, &outlines[Num] );
+ FT_Done_Glyph( glyphs[Num] );
}
tz0 = Get_Time() - tz0;
--- a/demos/src/ftview.c
+++ b/demos/src/ftview.c
@@ -158,7 +158,7 @@
/* first, render the glyph image into a bitmap */
if (glyph->format != ft_glyph_format_bitmap)
{
- error = FT_Render_Glyph( glyph, antialias ? 1 : 0 );
+ error = FT_Render_Glyph( glyph, antialias ? ft_render_mode_normal : ft_render_mode_mono );
if (error) return error;
}
--- a/demos/src/memtest.c
+++ b/demos/src/memtest.c
@@ -1,16 +1,15 @@
/* memtest.c */
#include <freetype/freetype.h>
-#include <freetype/internal/ftobjs.h>
+#include <freetype/ftmodule.h>
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
FT_Error error;
FT_Library library;
FT_Face face;
- FT_Size size;
- FT_GlyphSlot slot;
unsigned int num_glyphs;
int ptsize;
@@ -18,7 +17,6 @@
int Fail;
int Num;
- extern void FT_Add_Default_Modules( FT_Library library );
--- a/include/freetype/freetype.h
+++ b/include/freetype/freetype.h
@@ -39,18 +39,7 @@
#define FREETYPE_MINOR 0
- /*************************************************************************/
- /* */
- /* To make freetype.h independent from configuration files we check */
- /* whether FT_EXPORT_DEF has been defined already. */
- /* */
- /* On some systems and compilers (Win32 mostly), an extra keyword is */
- /* necessary to compile the library as a DLL. */
- /* */
-#ifndef FT_EXPORT_DEF
-#define FT_EXPORT_DEF(x) extern x
-#endif
-
+#include <freetype/config/ftconfig.h> /* read configuration information */
#include <freetype/fterrors.h>
#include <freetype/fttypes.h>
@@ -335,7 +324,7 @@
typedef enum FT_Encoding_
{
ft_encoding_none = 0,
- ft_encoding_symbol = 0,
+ ft_encoding_symbol = FT_MAKE_TAG('s','y','m','b'),
ft_encoding_unicode = FT_MAKE_TAG('u','n','i','c'),
ft_encoding_latin_2 = FT_MAKE_TAG('l','a','t','2'),
ft_encoding_sjis = FT_MAKE_TAG('s','j','i','s'),
@@ -344,9 +333,9 @@
ft_encoding_wansung = FT_MAKE_TAG('w','a','n','s'),
ft_encoding_johab = FT_MAKE_TAG('j','o','h','a'),
- ft_encoding_adobe_standard = FT_MAKE_TAG('a','d','o','b'),
- ft_encoding_adobe_expert = FT_MAKE_TAG('a','d','b','e'),
- ft_encoding_adobe_custom = FT_MAKE_TAG('a','d','b','c'),
+ ft_encoding_adobe_standard = FT_MAKE_TAG('A','D','O','B'),
+ ft_encoding_adobe_expert = FT_MAKE_TAG('A','D','B','E'),
+ ft_encoding_adobe_custom = FT_MAKE_TAG('A','D','B','C'),
ft_encoding_apple_roman = FT_MAKE_TAG('a','r','m','n')
@@ -995,6 +984,9 @@
/* vectorial or bitmap/graymaps.. */
/* */
/* <Fields> */
+ /* library :: a handle to the FreeType library instance this slot */
+ /* belongs to. */
+ /* */
/* face :: A handle to the parent face object. */
/* */
/* next :: In some cases (like some font tools), several glyph */
@@ -1111,6 +1103,7 @@
typedef struct FT_GlyphSlotRec_
{
+ FT_Library library;
FT_Face face;
FT_GlyphSlot next;
FT_UInt flags;
@@ -1813,10 +1806,25 @@
/* glyph loader to use 'ft_render_mode_antialias' when calling */
/* FT_Render_Glyph. */
/* */
+ /* THIS IS NOW 0, AS ANTI-ALIASED RENDERING IS NOW THE DEFAULT.. */
/* */
-#define FT_LOAD_ANTI_ALIAS 4096
+#define FT_LOAD_ANTI_ALIAS 0 /* this is the default */
+ /*************************************************************************/
+ /* */
+ /* <Constant> */
+ /* FT_LOAD_MONOCHROME */
+ /* */
+ /* <Description> */
+ /* Only used with FT_LOAD_RENDER set, indicates that the returned */
+ /* glyph image should be 1-bit monochrome. This really tells the */
+ /* glyph loader to use 'ft_render_mode_mono' when calling */
+ /* FT_Render_Glyph. */
+ /* */
+ /* */
+#define FT_LOAD_MONOCHROME 0 /* this is the default */
+
/*************************************************************************/
/* */
/* <Constant> */
@@ -1867,6 +1875,11 @@
/* <Note> */
/* The transformation is only applied to scalable image formats. */
/* */
+ /* The transformation is simply applied to the glyph after it is */
+ /* loaded. It means that hinting is unaltered by the transform and */
+ /* is performed on the character size given in the last call to */
+ /* FT_Set_Char_Sizes or FT_Set_Pixel_Sizes */
+ /* */
FT_EXPORT_DEF( void ) FT_Set_Transform( FT_Face face,
FT_Matrix* matrix,
FT_Vector* delta );
@@ -1874,6 +1887,46 @@
/*************************************************************************
*
+ * <Enum>
+ * FT_Render_Mode
+ *
+ * <Description>
+ * An enumeration type that lists the render modes supported by the
+ * FreeType 2 renderer(s). A renderer is in charge of converting a
+ * glyph image into a bitmap..
+ *
+ * <Fields>
+ * ft_render_mode_normal :: this is the default render mode,
+ * it corresponds to 8-bit anti-aliased
+ * bitmaps, using 256 levels of gray.
+ *
+ * ft_render_mode_mono :: this render mode is used to produce
+ * 1-bit monochrome bitmaps
+ *
+ * <Note>
+ * There is no render mode to produce 8-bit "monochrome" bitmaps,
+ * you'll have to make the conversion yourself if you need such
+ * things (besides, FreeType is not a graphics library..)
+ *
+ * More modes might appear later for specific display modes (e.g.
+ * TV, LCDs, etc..). They will be supported through the simple
+ * addition of a renderer module, with no changes to the rest of
+ * the engine..
+ *
+ *
+ *************************************************************************/
+
+ typedef enum FT_Render_Mode_
+ {
+ ft_render_mode_normal = 0,
+ ft_render_mode_mono = 1
+
+ } FT_Render_Mode;
+
+
+
+ /*************************************************************************
+ *
* <Function>
* FT_Render_Glyph
*
@@ -1885,29 +1938,46 @@
* slot :: handle to the glyph slot containing the image to
* convert
*
- * render_mode :: a set of bit flags indicating which kind of bitmap
- * to render. For now, only 'ft_render_mode_anti_alias'
- * is supported by the available renderers, but others
- * could appear later (e.g. LCD or TV optimised)
+ * render_mode :: this is the render mode used to render the glyph image
+ * into a bitmap. See FT_Render_Mode for possible values.
*
* <Return>
* Error code. 0 means success.
*
- * <Note>
- * in case of success, the renderer will be used to convert glyph
- * images in the renderer's known format into bitmaps.
- *
- * This doesn't change the current renderer for other formats..
- *
- * The slot's native image should be considered lost after the
- * conversion..
- *
*************************************************************************/
FT_EXPORT_DEF(FT_Error) FT_Render_Glyph( FT_GlyphSlot slot,
FT_UInt render_mode );
-
+
+ /**************************************************************************
+ *
+ * <Enum>
+ * FT_Kerning_Mode
+ *
+ * <Description>
+ * A list of enumerations used to specify which kerning values to
+ * return in FT_Get_Kerning
+ *
+ * <Field>
+ * ft_kerning_default :: used to returned scaled and grid-fitted kerning
+ * distances. (value is 0)
+ *
+ * ft_kerning_unfitted :: used to returned scaled by un-grid-fitted
+ * kerning distances.
+ *
+ * ft_kerning_unscaled :: used to return the kerning vector in original
+ * font units..
+ *
+ **************************************************************************/
+ typedef enum FT_Kerning_Mode_
+ {
+ ft_kerning_default = 0,
+ ft_kerning_unfitted,
+ ft_kerning_unscaled
+
+ } FT_Kerning_Mode;
+
/*************************************************************************/
/* */
/* <Function> */
@@ -1923,6 +1993,9 @@
/* */
/* right_glyph :: The index of the right glyph in the kern pair. */
/* */
+ /* kern_mode :: see FT_Kerning_Mode for more info. Determines the */
+ /* scale/dimension of the returned kerning vector */
+ /* */
/* <Output> */
/* kerning :: The kerning vector. This is in font units for */
/* scalable formats, and in pixels for fixed-sizes */
@@ -1940,6 +2013,7 @@
FT_EXPORT_DEF(FT_Error) FT_Get_Kerning( FT_Face face,
FT_UInt left_glyph,
FT_UInt right_glyph,
+ FT_UInt kern_mode,
FT_Vector* kerning );
@@ -2120,468 +2194,6 @@
FT_Matrix* matrix );
- /*************************************************************************/
- /* */
- /* <Function> */
- /* FT_Outline_Get_Bitmap */
- /* */
- /* <Description> */
- /* Renders an outline within a bitmap. The outline's image is simply */
- /* or-ed to the target bitmap. */
- /* */
- /* */
- /* <Input> */
- /* library :: A handle to a FreeType library object. */
- /* outline :: A pointer to the source outline descriptor. */
- /* map :: A pointer to the target bitmap descriptor. */
- /* */
- /* <Return> */
- /* FreeType error code. 0 means success. */
- /* */
- /* <MT-Note> */
- /* YES. Rendering is synchronized, so that concurrent calls to the */
- /* scan-line converter will be serialized. */
- /* */
- /* <Note> */
- /* This function does NOT CREATE the bitmap, it only renders an */
- /* outline image within the one you pass to it! */
- /* */
- /* It will use the raster correponding to the default glyph format. */
- /* */
- FT_EXPORT_DEF(FT_Error) FT_Outline_Get_Bitmap( FT_Library library,
- FT_Outline* outline,
- FT_Bitmap* bitmap );
-
- /*************************************************************************/
- /* */
- /* <Function> */
- /* FT_Outline_Render */
- /* */
- /* <Description> */
- /* Renders an outline within a bitmap using the current scan-convert */
- /* This functions uses a FT_Raster_Params as argument, allowing */
- /* advanced features like direct composition/translucency, etc.. */
- /* */
- /* <Input> */
- /* library :: A handle to a FreeType library object. */
- /* outline :: A pointer to the source outline descriptor. */
- /* params :: A pointer to a FT_Raster_Params used to describe */
- /* the rendering operation */
- /* */
- /* <Return> */
- /* FreeType error code. 0 means success. */
- /* */
- /* <MT-Note> */
- /* YES. Rendering is synchronized, so that concurrent calls to the */
- /* scan-line converter will be serialized. */
- /* */
- /* <Note> */
- /* You should know what you're doing and the role of FT_Raster_Params */
- /* to use this function. */
- /* */
- /* the field "params.source" will be set to "outline" before the */
- /* scan converter is called, which means that the value you give it */
- /* is actually ignored.. */
- /* */
- FT_EXPORT_DEF(FT_Error) FT_Outline_Render( FT_Library library,
- FT_Outline* outline,
- FT_Raster_Params* params );
-
-
- /*************************************************************************/
- /* */
- /* <Function> */
- /* FT_Outline_Decompose */
- /* */
- /* <Description> */
- /* Walks over an outline's structure to decompose it into individual */
- /* segments and Bezier arcs. This function is also able to emit */
- /* `move to' and `close to' operations to indicate the start and end */
- /* of new contours in the outline. */
- /* */
- /* <Input> */
- /* outline :: A pointer to the source target. */
- /* */
- /* funcs :: A table of `emitters', i.e,. function pointers called */
- /* during decomposition to indicate path operations. */
- /* */
- /* user :: A typeless pointer which is passed to each emitter */
- /* during the decomposition. It can be used to store */
- /* the state during the decomposition. */
- /* */
- /* <Return> */
- /* FreeType error code. 0 means sucess. */
- /* */
- FT_EXPORT_DEF(FT_Error) FT_Outline_Decompose( FT_Outline* outline,
- FT_Outline_Funcs* funcs,
- void* user );
-
-
- /*************************************************************************/
- /* */
- /* <Function> */
- /* FT_Outline_New */
- /* */
- /* <Description> */
- /* Creates a new outline of a given size. */
- /* */
- /* <Input> */
- /* library :: A handle to the library object from where the */
- /* outline is allocated. Note however that the new */
- /* outline will NOT necessarily be FREED when */
- /* destroying the library, by FT_Done_FreeType(). */
- /* */
- /* numPoints :: The maximal number of points within the outline. */
- /* */
- /* numContours :: The maximal number of contours within the outline. */
- /* */
- /* <Output> */
- /* outline :: A handle to the new outline. NULL in case of */
- /* error. */
- /* */
- /* <Return> */
- /* FreeType error code. 0 means success. */
- /* */
- /* <MT-Note> */
- /* No. */
- /* */
- /* <Note> */
- /* The reason why this function takes a `library' parameter is simply */
- /* to use the library's memory allocator. You can copy the source */
- /* code of this function, replacing allocations with `malloc()' if */
- /* you want to control where the objects go. */
- /* */
- FT_EXPORT_DEF(FT_Error) FT_Outline_New( FT_Library library,
- FT_UInt numPoints,
- FT_Int numContours,
- FT_Outline* outline );
-
-
- /*************************************************************************/
- /* */
- /* <Function> */
- /* FT_Outline_Done */
- /* */
- /* <Description> */
- /* Destroys an outline created with FT_Outline_New(). */
- /* */
- /* <Input> */
- /* library :: A handle of the library object used to allocate the */
- /* outline. */
- /* */
- /* outline :: A pointer to the outline object to be discarded. */
- /* */
- /* <Return> */
- /* FreeType error code. 0 means success. */
- /* */
- /* <MT-Note> */
- /* No. */
- /* */
- /* <Note> */
- /* If the outline's `owner' field is not set, only the outline */
- /* descriptor will be released. */
- /* */
- /* The reason why this function takes an `outline' parameter is */
- /* simply to use FT_Alloc()/FT_Free(). You can copy the source code */
- /* of this function, replacing allocations with `malloc()' in your */
- /* application if you want something simpler. */
- /* */
- FT_EXPORT_DEF(FT_Error) FT_Outline_Done( FT_Library library,
- FT_Outline* outline );
-
- /*************************************************************************/
- /* */
- /* <Function> */
- /* FT_Outline_Get_CBox */
- /* */
- /* <Description> */
- /* Returns an outline's `control box'. The control box encloses all */
- /* the outline's points, including Bezier control points. Though it */
- /* coincides with the exact bounding box for most glyphs, it can be */
- /* slightly larger in some situations (like when rotating an outline */
- /* which contains Bezier outside arcs). */
- /* */
- /* Computing the control box is very fast, while getting the bounding */
- /* box can take much more time as it needs to walk over all segments */
- /* and arcs in the outline. To get the latter, you can use the */
- /* `ftbbox' component which is dedicated to this single task. */
- /* */
- /* <Input> */
- /* outline :: A pointer to the source outline descriptor. */
- /* */
- /* <Output> */
- /* cbox :: The outline's control box. */
- /* */
- /* <MT-Note> */
- /* Yes. */
- /* */
- FT_EXPORT_DEF(void) FT_Outline_Get_CBox( FT_Outline* outline,
- FT_BBox* cbox );
-
-
- /*************************************************************************/
- /* */
- /* <Function> */
- /* FT_Outline_Translate */
- /* */
- /* <Description> */
- /* Applies a simple translation to the points of an outline. */
- /* */
- /* <Input> */
- /* outline :: A pointer to the target outline descriptor. */
- /* xOffset :: The horizontal offset. */
- /* yOffset :: The vertical offset. */
- /* */
- /* <MT-Note> */
- /* Yes. */
- /* */
- FT_EXPORT_DEF(void) FT_Outline_Translate( FT_Outline* outline,
- FT_Pos xOffset,
- FT_Pos yOffset );
-
-
-#if 0
- /*************************************************************************/
- /* */
- /* <Function> */
- /* FT_Set_Raster */
- /* */
- /* <Description> */
- /* Register a given raster to the library. */
- /* */
- /* <Input> */
- /* library :: A handle to a target library object. */
- /* raster_funcs :: pointer to the raster's interface */
- /* */
- /* <Return> */
- /* Error code. 0 means success. */
- /* */
- /* <Note> */
- /* This function will do the following: */
- /* */
- /* - a new raster object is created through raster_func.raster_new */
- /* if this fails, then the function returns */
- /* */
- /* - if a raster is already registered for the glyph format */
- /* specified in raster_funcs, it will be destroyed */
- /* */
- /* - the new raster is registered for the glyph format */
- /* */
- FT_EXPORT_DEF(FT_Error) FT_Set_Raster( FT_Library library,
- FT_Raster_Funcs* raster_funcs );
-
-
- /*************************************************************************/
- /* */
- /* <Function> */
- /* FT_Unset_Raster */
- /* */
- /* <Description> */
- /* Removes a given raster from the library. */
- /* */
- /* <Input> */
- /* library :: A handle to a target library object. */
- /* raster_funcs :: pointer to the raster's interface */
- /* */
- /* <Return> */
- /* Error code. 0 means success. */
- /* */
- /* <Note> */
- /* This function should never be used by a normal client application */
- /* as FT_Set_Raster unregisters the previous raster for a given */
- /* glyph format.. */
- /* */
- FT_EXPORT_DEF(FT_Error) FT_Unset_Raster( FT_Library library,
- FT_Raster_Funcs* raster_funcs );
-
-
- /*************************************************************************
- *
- * <Function>
- * FT_Get_Raster
- *
- * <Description>
- * Return a pointer to the raster corresponding to a given glyph
- * format tag.
- *
- * <Input>
- * library :: handle to source library object
- * glyph_format :: glyph format tag
- *
- * <Output>
- * raster_funcs :: if this field is not 0, returns a pointer to the
- * raster's interface/descriptor..
- *
- * <Return>
- * a pointer to the corresponding raster object.
- *
- *************************************************************************/
-
- FT_EXPORT_DEF(FT_Raster) FT_Get_Raster( FT_Library library,
- FT_Glyph_Format glyph_format,
- FT_Raster_Funcs *raster_funcs );
-
-
- /*************************************************************************/
- /* */
- /* <Function> */
- /* FT_Set_Raster_Mode */
- /* */
- /* <Description> */
- /* Set a raster-specific mode. */
- /* */
- /* <Input> */
- /* library :: A handle to a target library object. */
- /* format :: the glyph format used to select the raster */
- /* mode :: the raster-specific mode descriptor */
- /* args :: the mode arguments */
- /* <Return> */
- /* Error code. 0 means success. */
- /* */
- FT_EXPORT_DEF(FT_Error) FT_Set_Raster_Mode( FT_Library library,
- FT_Glyph_Format format,
- unsigned long mode,
- void* args );
-#endif
-
- /***************************************************************************/
- /***************************************************************************/
- /***************************************************************************/
- /***** *****/
- /***** C O N V E N I E N C E F U N C T I O N S *****/
- /***** *****/
- /***** *****/
- /***** The following functions are provided as a convenience *****/
- /***** to client applications. However, their compilation might *****/
- /***** be discarded if FT_CONFIG_OPTION_NO_CONVENIENCE_FUNCS *****/
- /***** is defined in "config/ftoption.h". *****/
- /***** *****/
- /***************************************************************************/
- /***************************************************************************/
- /***************************************************************************/
-
- /*************************************************************************/
- /* */
- /* <Function> */
- /* FT_Outline_Copy */
- /* */
- /* <Description> */
- /* Copies an outline into another one. Both objects must have the */
- /* same sizes (number of points & number of contours) when this */
- /* function is called. */
- /* */
- /* <Input> */
- /* source :: A handle to the source outline. */
- /* target :: A handle to the target outline. */
- /* */
- /* <Return> */
- /* FreeType error code. 0 means success. */
- /* */
- FT_EXPORT_DEF(FT_Error) FT_Outline_Copy( FT_Outline* source,
- FT_Outline* target );
-
-
-
- /*************************************************************************/
- /* */
- /* <Function> */
- /* FT_Outline_Transform */
- /* */
- /* <Description> */
- /* Applies a simple 2x2 matrix to all of an outline's points. Useful */
- /* for applying rotations, slanting, flipping, etc. */
- /* */
- /* <Input> */
- /* outline :: A pointer to the target outline descriptor. */
- /* matrix :: A pointer to the transformation matrix. */
- /* */
- /* <MT-Note> */
- /* Yes. */
- /* */
- /* <Note> */
- /* You can use FT_Outline_Translate() if you need to translate the */
- /* outline's points. */
- /* */
- FT_EXPORT_DEF(void) FT_Outline_Transform( FT_Outline* outline,
- FT_Matrix* matrix );
-
- /*************************************************************************/
- /* */
- /* <Function> */
- /* FT_Outline_Reverse */
- /* */
- /* <Description> */
- /* Reverse the drawing direction of an outline. This is used to */
- /* ensure consistent fill conventions for mirrored glyphs.. */
- /* */
- /* <Input> */
- /* outline :: A pointer to the target outline descriptor. */
- /* */
- /* <Note> */
- /* This functions toggles the bit flag ft_outline_reverse_fill in */
- /* the outline's "flags" field.. */
- /* */
- /* It shouldn't be used by a normal client application, unless it */
- /* knows what it's doing.. */
- /* */
- FT_EXPORT_DEF(void) FT_Outline_Reverse( FT_Outline* outline );
-
-
-
-
- /*************************************************************************/
- /* */
- /* <Function> */
- /* FT_Matrix_Multiply */
- /* */
- /* <Description> */
- /* Performs the matrix operation `b = a*b'. */
- /* */
- /* <Input> */
- /* a :: A pointer to matrix `a'. */
- /* */
- /* <InOut> */
- /* b :: A pointer to matrix `b'. */
- /* */
- /* <MT-Note> */
- /* Yes. */
- /* */
- FT_EXPORT_DEF(void) FT_Matrix_Multiply( FT_Matrix* a,
- FT_Matrix* b );
-
-
- /*************************************************************************/
- /* */
- /* <Function> */
- /* FT_Matrix_Invert */
- /* */
- /* <Description> */
- /* Inverts a 2x2 matrix. Returns an error if it can't be inverted. */
- /* */
- /* <InOut> */
- /* matrix :: A pointer to the target matrix. Remains untouched in */
- /* case of error. */
- /* */
- /* <Return> */
- /* FreeType error code. 0 means success. */
- /* */
- /* <MT-Note> */
- /* Yes. */
- /* */
- FT_EXPORT_DEF(FT_Error) FT_Matrix_Invert( FT_Matrix* matrix );
-
- /*************************************************************************/
- /* */
- /* <Function> */
- /* FT_Default_Drivers */
- /* */
- /* <Description> */
- /* Adds the set of default drivers to a given library object. */
- /* */
- /* <InOut> */
- /* library :: A handle to a new library object. */
- /* */
- FT_EXPORT_DEF(void) FT_Default_Drivers( FT_Library library );
#ifdef __cplusplus
}
--- a/include/freetype/fterrors.h
+++ b/include/freetype/fterrors.h
@@ -54,7 +54,7 @@
FT_ERRORDEF( FT_Err_Invalid_Character_Code, 0x0013, "invalid character code" )
FT_ERRORDEF( FT_Err_Unimplemented_Feature, 0x0020, "unimplemented feature" )
- FT_ERRORDEF( FT_Err_Invalid_Glyph_Format, 0x0021, "invalid glyph image format" )
+ FT_ERRORDEF( FT_Err_Invalid_Glyph_Format, 0x0021, "unsupported glyph image format" )
FT_ERRORDEF( FT_Err_Cannot_Render_Glyph, 0x0022, "cannot render this glyph format" )
FT_ERRORDEF( FT_Err_Invalid_Library_Handle, 0x0030, "invalid library handle" )
--- a/include/freetype/ftglyph.h
+++ b/include/freetype/ftglyph.h
@@ -32,14 +32,9 @@
extern "C" {
#endif
- typedef enum {
+ /* forward declaration to a private type */
+ typedef struct FT_Glyph_Class_ FT_Glyph_Class;
- ft_glyph_type_none = 0,
- ft_glyph_type_bitmap = 1,
- ft_glyph_type_outline = 2
-
- } FT_GlyphType;
-
/***********************************************************************
*
* <Struct>
@@ -46,45 +41,23 @@
* FT_GlyphRec
*
* <Description>
- * The root glyph structure contains a given glyph image's metrics.
- * Note that the FT_Glyph type is a pointer to FT_GlyphRec
+ * The root glyph structure contains a given glyph image plus its
+ * advance width in 16.16 fixed float format..
*
* <Field>
- * memory :: a handle to the memory allocator that is used to
- * create/clone/destroy this glyph..
+ * library :: a handle to the FreeType library object.
+ * clazz :: a pointer to the glyph's class. Private.
+ * format :: the format of the glyph's image
+ * advance :: a 16.16 vector that gives the glyph's advance width
*
- * glyph_type :: the glyph type..
- *
- * height :: height of glyph image
- * width :: width of glyph image
- *
- * bearingX :: horizontal bearing, this is the distance from the
- * the current pen position to the left of the glyph
- *
- * bearingY :: vertical bearing, this is the distance from the
- * current pen position to the top of the glyph
- *
- * advance :: this is the horizontal or vertical advance for the
- * glyph
- *
- * <Note>
- * the distances expressed in the metrics are expressed in 26.6 fixed
- * float sub-pixels (i.e. 1/64th of pixels).
- *
- * the vertical bearing has a positive value when the glyph top is
- * above the baseline, and negative when it is under..
- *
***********************************************************************/
typedef struct FT_GlyphRec_
{
- FT_Memory memory;
- FT_GlyphType glyph_type;
- FT_Int height;
- FT_Int width;
- FT_Int bearingX;
- FT_Int bearingY;
- FT_Int advance;
+ FT_Library library;
+ const FT_Glyph_Class* clazz;
+ FT_Glyph_Format format;
+ FT_Vector advance;
} FT_GlyphRec, *FT_Glyph;
@@ -95,12 +68,11 @@
* FT_BitmapGlyphRec
*
* <Description>
- * A structure used to describe a bitmap glyph image..
- * Note that the FT_BitmapGlyph type is a pointer to FT_BitmapGlyphRec
+ * A structure used for bitmap glyph images.. This really is
+ * a "sub-class" of "FT_GlyphRec".
*
* <Field>
- * metrics :: the corresponding glyph metrics
- * bitmap :: a descriptor for the bitmap.
+ * root :: the root FT_Glyph fields
* left :: left-side bearing, i.e. the horizontal distance from
* the current pen position to the left border of the glyph
* bitmap.
@@ -107,29 +79,26 @@
* top :: top-side bearing, i.e. the vertical distance from the
* current pen position to the top border of the glyph bitmap
* this distance is positive for upwards-y !!
+ * bitmap :: a descriptor for the bitmap.
*
* <Note>
- * the "width" and "height" fields of the metrics are expressed in
- * 26.6 sub-pixels. However, the width and height in pixels can be
- * read directly from "bitmap.width" and "bitmap.height"
+ * You can typecast a FT_Glyph to FT_BitmapGlyph when you have
+ * glyph->format == ft_glyph_format_bitmap. This lets you access
+ * the bitmap's content easily..
*
- * this structure is used for both monochrome and anti-aliased
- * bitmaps (the bitmap descriptor contains field describing the
- * format of the pixel buffer)
- *
* the corresponding pixel buffer is always owned by the BitmapGlyph
- * and is thus creatde and destroyed with it..
+ * and is thus created and destroyed with it..
*
***********************************************************************/
typedef struct FT_BitmapGlyphRec_
{
- FT_GlyphRec metrics;
+ FT_GlyphRec root;
FT_Int left;
FT_Int top;
FT_Bitmap bitmap;
- } FT_BitmapGlyphRec_, *FT_BitmapGlyph;
+ } FT_BitmapGlyphRec, *FT_BitmapGlyph;
/***********************************************************************
@@ -138,189 +107,297 @@
* FT_OutlineGlyphRec
*
* <Description>
- * A structure used to describe a vectorial outline glyph image..
- * Note that the FT_OutlineGlyph type is a pointer to FT_OutlineGlyphRec
+ * A structure used for outline (vectorial) glyph images..
+ * This really is a "sub-class" of FT_GlyphRec.
*
* <Field>
- * metrics :: the corresponding glyph metrics
+ * root :: the root FT_Glyph fields.
* outline :: a descriptor for the outline
*
* <Note>
- * the "width" and "height" fields of the metrics are expressed in
- * 26.6 sub-pixels. However, the width and height in pixels can be
- * read directly from "bitmap.width" and "bitmap.rows"
+ * You can typecast a FT_Glyph to FT_OutlineGlyph when you have
+ * glyph->format == ft_glyph_format_outline. This lets you access
+ * the outline's content easily..
*
- * the corresponding outline points tables is always owned by the
- * object and are destroyed with it..
+ * As the outline is extracted from a glyph slot, its coordinates
+ * are expressed normally in 26.6 pixels, unless the flag
+ * FT_LOAD_NO_SCALE was used in FT_Load_Glyph / FT_Load_Char..
*
- * an OutlineGlyph can be used to generate a BitmapGlyph with the
- * function FT_OutlineGlyph_Render()
+ * the outline's tables are always owned by the object and are
+ * destroyed with it..
*
***********************************************************************/
typedef struct FT_OutlineGlyphRec_
{
- FT_GlyphRec metrics;
+ FT_GlyphRec root;
FT_Outline outline;
- } FT_OutlineGlyphRec_, *FT_OutlineGlyph;
+ } FT_OutlineGlyphRec, *FT_OutlineGlyph;
+
/***********************************************************************
*
* <Function>
- * FT_Get_Glyph_Bitmap
+ * FT_Get_Glyph
*
* <Description>
- * A function used to directly return a bitmap glyph image
- * from a face.
+ * A function used to extract one glyph image from a slot..
*
* <Input>
- * face :: handle to source face object
- * glyph_index :: glyph index in face
- * load_flags :: load flags, see FT_LOAD_FLAG_XXXX constants..
- * grays :: number of gray levels for anti-aliased bitmaps,
- * set to 0 if you want to render a monochrome bitmap
- * origin :: a pointer to the origin's position. Set to 0
- * if the current transform is the identity..
+ * slot :: handle to source glyph slot.
*
* <Output>
- * bitglyph :: pointer to the new bitmap glyph
+ * aglyph :: handle to the glyph object.
*
* <Return>
* Error code. 0 means success.
*
* <Note>
- * If the font contains glyph outlines, these will be automatically
- * converted to a bitmap according to the value of "grays"
*
- * If "grays" is set to 0, the result is a 1-bit monochrome bitmap
- * otherwise, it is an 8-bit gray-level bitmap
*
- * The number of gray levels in the result anti-aliased bitmap might
- * not be "grays", depending on the current scan-converter implementation
- *
- * Note that it is not possible to generate 8-bit monochrome bitmaps
- * with this function. Rather, use FT_Get_Glyph_Outline, then
- * FT_Glyph_Render_Outline and provide your own span callbacks..
- *
- * When the face doesn't contain scalable outlines, this function will
- * fail if the current transform is not the identity, or if the glyph
- * origin's phase to the pixel grid is not 0 in both directions !!
- *
***********************************************************************/
- FT_EXPORT_DEF(FT_Error) FT_Get_Glyph_Bitmap( FT_Face face,
- FT_UInt glyph_index,
- FT_UInt load_flags,
- FT_Int grays,
- FT_Vector* origin,
- FT_BitmapGlyph *abitglyph );
+ FT_EXPORT_DEF(FT_Error) FT_Get_Glyph( FT_GlyphSlot slot,
+ FT_Glyph *aglyph );
-
/***********************************************************************
*
* <Function>
- * FT_Get_Glyph_Outline
+ * FT_Glyph_Copy
*
* <Description>
- * A function used to directly return an outline glyph image from a
- * face. This is faster than calling FT_Load_Glyph+FT_Get_Outline_Bitmap..
+ * A function used to copy one glyph image.
*
* <Input>
- * face :: handle to source face object
- * glyph_index :: glyph index in face
- * load_flags :: load flags, see FT_LOAD_FLAG_XXXX constants..
+ * source :: handle to source glyph object
*
* <Output>
- * vecglyph :: pointer to the new outline glyph
+ * target :: handle to target glyph object. 0 in case of error
*
* <Return>
* Error code. 0 means success.
*
- * <Note>
- * If the glyph is not an outline in the face, this function will
- * fail..
- *
- * This function will fail if the load flags FT_LOAD_NO_OUTLINE and
- * FT_LOAD_NO_RECURSE are set..
- *
***********************************************************************/
- FT_EXPORT_DEF(FT_Error) FT_Get_Glyph_Outline( FT_Face face,
- FT_UInt glyph_index,
- FT_UInt load_flags,
- FT_OutlineGlyph *vecglyph );
+ FT_EXPORT_DEF(FT_Error) FT_Glyph_Copy( FT_Glyph source,
+ FT_Glyph *target );
/***********************************************************************
*
* <Function>
- * FT_Set_Transform
+ * FT_Glyph_Transform
*
* <Description>
- * A function used to set the transform that is applied to glyph images
- * just after they're loaded in the face's glyph slot, and before they're
- * returned by either FT_Get_Glyph_Bitmap or FT_Get_Glyph_Outline
+ * Transforms a glyph image, when it's format is scalable
*
* <Input>
- * face :: handle to source face object
- * matrix :: pointer to the transform's 2x2 matrix. 0 for identity
- * delta :: pointer to the transform's translation. 0 for null vector
+ * glyph :: handle to target glyph object
*
+ * matrix :: pointer to 2x2 matrix to apply
+ *
+ * delta :: pointer to a 2d vector to apply. coordinates are
+ * expressed in 1/64th of a pixel..
+ *
+ * <Return>
+ * error code (is not 0, the glyph format is not scalable).
+ *
* <Note>
- * The transform is only applied to glyph outlines when they are found
- * in a font face. It is unable to transform embedded glyph bitmaps
+ * the 2x2 transform matrix is also applied to the glyph's
+ * advance vector
*
***********************************************************************/
- FT_EXPORT_DEF(void) FT_Set_Transform( FT_Face face,
- FT_Matrix* matrix,
- FT_Vector* delta );
-
-
+ FT_EXPORT_DEF(FT_Error) FT_Glyph_Transform( FT_Glyph glyph,
+ FT_Matrix* matrix,
+ FT_Vector* delta );
+
/***********************************************************************
*
* <Function>
- * FT_Done_Glyph
+ * FT_Glyph_Get_CBox
*
* <Description>
- * Destroys a given glyph..
+ * Returns the glyph image's bounding box.
*
* <Input>
- * glyph :: handle to target glyph object
+ * glyph :: handle to source glyph object
+ * mode :: a set of bit flags that indicate how to interpret
+ * the meaning of the box's coordinates
*
+ * <Output>
+ * box :: the glyph bounding box. Coordinates are expressed in
+ * 1/64th of pixels, it is grid-fitted..
+ *
+ * <Note>
+ * Coordinates are relative to the glyph origin, using the Y-upwards
+ * convention..
+ *
+ * if 'ft_glyph_bbox_subpixels' is set in "mode", the bbox coordinates
+ * are returned in 26.6 pixels (i.e. 1/64th of pixels).
+ *
+ * otherwise, coordinates are in integer pixels.
+ *
+ * note that the maximum coordinates are exclusive, which means that
+ * once can compute the width and height of the glyph image (be it
+ * in integer or 26.6 pixels) as:
+ *
+ * width = bbox.xMax - bbox.xMin;
+ * height = bbox.yMax - bbox.yMin;
+ *
+ * Note also that for 26.6 coordinates, if the 'ft_glyph_bbox_gridfit'
+ * flag is set in "mode", the coordinates will also be grid-fitted,
+ * which corresponds to:
+ *
+ * bbox.xMin = FLOOR(bbox.xMin);
+ * bbox.yMin = FLOOR(bbox.yMin);
+ * bbox.xMax = CEILING(bbox.xMax);
+ * bbox.yMax = CEILING(bbox.yMax);
+ *
***********************************************************************/
- FT_EXPORT_DEF(void) FT_Done_Glyph( FT_Glyph glyph );
+ enum
+ {
+ ft_glyph_bbox_pixels = 0,
+ ft_glyph_bbox_subpixels = 1,
+ ft_glyph_bbox_gridfit = 2
+ };
+ FT_EXPORT_DEF(void) FT_Glyph_Get_CBox( FT_Glyph glyph,
+ FT_UInt bbox_mode,
+ FT_BBox *cbox );
+
/***********************************************************************
*
* <Function>
- * FT_Glyph_Get_Box
+ * FT_Glyph_To_Bitmap
*
* <Description>
- * Returns the glyph image's bounding box in pixels.
+ * converts a given glyph object to a bitmap glyph object
*
+ * <InOut>
+ * glyph :: pointer to a handle to the target glyph
+ *
* <Input>
- * glyph :: handle to target glyph object
+ * render_mode :: a set of bit flags that describe how
*
- * <Output>
- * box :: the glyph bounding box. Coordinates are expressed in
- * _integer_ pixels, with exclusive max bounds
+ * origin :: pointer to a vector used to translate the glyph image
+ * before rendering. Can be 0 (for no translation). The
+ * origin is expressed in 26.6 pixels..
*
+ * destroy :: a boolean that indicates that the original glyph image
+ * should be destroyed by this function. The glyph is
+ * never destroyed in case of error..
+ *
+ * <Return>
+ * Error code. 0 means success
+ *
* <Note>
- * Coordinates are relative to the glyph origin, using the Y-upwards
- * convention..
+ * the glyph image is translated with the "origin" vector before
+ * rendering.. In case of error, it it translated back to its original
+ * position and the glyph is untouched..
*
- * The width of the box in pixels is box.xMax-box.xMin
- * The height is box.yMax - box.yMin
+ * The first parameter is a pointer to a FT_Glyph handle, that
+ * will be replaced by this function. Typically, you would use:
*
+ * {
+ * FT_Glyph glyph;
+ * FT_BitmapGlyph glyph_bitmap;
+ *
+ * // load glyph
+ * error = FT_Load_Char( face, glyph_index, FT_LOAD_DEFAUT );
+ *
+ * // extract glyph image
+ * error = FT_Get_Glyph( face->glyph, &glyph );
+ *
+ * // convert to a bitmap (default render mode + destroy old)
+ * if (glyph->format != ft_glyph_format_bitmap)
+ * {
+ * error = FT_Glyph_To_Bitmap( &glyph, ft_render_mode_default, 0, 1 );
+ * if (error) // glyph unchanged..
+ * }
+ *
+ * // access bitmap content by typecasting
+ * glyph_bitmap = (FT_BitmapGlyph)glyph;
+ *
+ * // do funny stuff with it, like blitting/drawing
+ * ....
+ *
+ * // discard glyph image (bitmap or not)
+ * FT_Done_Glyph( glyph );
+ *
+ *
+ * This function will always fail if the glyph's format isn't scalable
+ *
***********************************************************************/
- FT_EXPORT_DEF(void) FT_Glyph_Get_Box( FT_Glyph glyph,
- FT_BBox *box );
+ FT_EXPORT_DEF(FT_Error) FT_Glyph_To_Bitmap( FT_Glyph *the_glyph,
+ FT_ULong render_mode,
+ FT_Vector* origin,
+ FT_Bool destroy );
+
+ /***********************************************************************
+ *
+ * <Function>
+ * FT_Done_Glyph
+ *
+ * <Description>
+ * Destroys a given glyph..
+ *
+ * <Input>
+ * glyph :: handle to target glyph object
+ *
+ ***********************************************************************/
+
+ FT_EXPORT_DEF(void) FT_Done_Glyph( FT_Glyph glyph );
+
+
+ /* other helpful functions */
+
+ /*************************************************************************/
+ /* */
+ /* <Function> */
+ /* FT_Matrix_Multiply */
+ /* */
+ /* <Description> */
+ /* Performs the matrix operation `b = a*b'. */
+ /* */
+ /* <Input> */
+ /* a :: A pointer to matrix `a'. */
+ /* */
+ /* <InOut> */
+ /* b :: A pointer to matrix `b'. */
+ /* */
+ /* <MT-Note> */
+ /* Yes. */
+ /* */
+ FT_EXPORT_DEF(void) FT_Matrix_Multiply( FT_Matrix* a,
+ FT_Matrix* b );
+
+
+ /*************************************************************************/
+ /* */
+ /* <Function> */
+ /* FT_Matrix_Invert */
+ /* */
+ /* <Description> */
+ /* Inverts a 2x2 matrix. Returns an error if it can't be inverted. */
+ /* */
+ /* <InOut> */
+ /* matrix :: A pointer to the target matrix. Remains untouched in */
+ /* case of error. */
+ /* */
+ /* <Return> */
+ /* FreeType error code. 0 means success. */
+ /* */
+ /* <MT-Note> */
+ /* Yes. */
+ /* */
+ FT_EXPORT_DEF(FT_Error) FT_Matrix_Invert( FT_Matrix* matrix );
+
#ifdef __cplusplus
}
--- a/include/freetype/ftmodule.h
+++ b/include/freetype/ftmodule.h
@@ -192,6 +192,93 @@
FT_Module module );
+ /*************************************************************************
+ *
+ * <Function>
+ * FT_New_Library
+ *
+ * <Description>
+ * Creates a new "virgin" library that uses a custom memory manager.
+ * The library has no registered driver, those can be added with a
+ * call to FT_Add_Default_Modules
+ *
+ * <Input>
+ * memory :: handle to custom memory manager
+ *
+ * <Output>
+ * library :: handle to fresh new library object
+ *
+ * <Return>
+ * Error code (module not listed)
+ *
+ *************************************************************************/
+
+ FT_EXPORT_DEF(FT_Error) FT_New_Library( FT_Memory memory,
+ FT_Library* library );
+
+
+ /*************************************************************************
+ *
+ * <Function>
+ * FT_Done_Library
+ *
+ * <Description>
+ * Destroys a given library, and all child objects, except the
+ * memory manager.
+ *
+ * <Input>
+ * library :: handle to target library object
+ *
+ * <Return>
+ * Error code (module not listed)
+ *
+ *************************************************************************/
+
+ FT_EXPORT_DEF(FT_Error) FT_Done_Library( FT_Library library );
+
+
+
+ /*************************************************************************
+ *
+ * <Function>
+ * FT_Set_Debug_Hook
+ *
+ * <Description>
+ * Used only by the TrueType debugger. This function is private and
+ * should never be called by normal applications..
+ *
+ * <Input>
+ * library :: handle to target library object
+ * hook_index :: hook index
+ * debug_hook :: debug hook functions
+ *
+ *************************************************************************/
+
+ typedef void (*FT_DebugHook_Func)( void* arg );
+
+ FT_EXPORT_DEF(void) FT_Set_Debug_Hook( FT_Library library,
+ FT_UInt hook_index,
+ FT_DebugHook_Func debug_hook );
+
+
+
+ /*************************************************************************/
+ /* */
+ /* <Function> */
+ /* FT_Add_Default_Modules */
+ /* */
+ /* <Description> */
+ /* Adds the set of default modules to a given library object. */
+ /* This is only useful when you create a library object with */
+ /* FT_New_Library (usually to plug a custom memory manager) */
+ /* */
+ /* <Input> */
+ /* library :: A handle to a new library object. */
+ /* */
+ FT_EXPORT_DEF(void) FT_Add_Default_Modules( FT_Library library );
+
+
+
#endif /* FTMODULE_H */
--- a/include/freetype/ftrender.h
+++ b/include/freetype/ftrender.h
@@ -19,7 +19,42 @@
#define FTRENDER_H
#include <freetype/ftmodule.h>
+#include <freetype/ftglyph.h>
+ /* create a new glyph object */
+ typedef FT_Error (*FT_Glyph_Init_Func)( FT_Glyph glyph,
+ FT_GlyphSlot slot );
+
+ /* destroys a given glyph object */
+ typedef void (*FT_Glyph_Done_Func)( FT_Glyph glyph );
+
+ typedef void (*FT_Glyph_Transform_Func)( FT_Glyph glyph,
+ FT_Matrix* matrix,
+ FT_Vector* delta );
+
+ typedef void (*FT_Glyph_BBox_Func)( FT_Glyph glyph,
+ FT_BBox *abbox );
+
+ typedef FT_Error (*FT_Glyph_Copy_Func)( FT_Glyph source,
+ FT_Glyph target );
+
+ typedef FT_Error (*FT_Glyph_Prepare_Func)( FT_Glyph glyph,
+ FT_GlyphSlot slot );
+
+ struct FT_Glyph_Class_
+ {
+ FT_UInt glyph_size;
+ FT_Glyph_Format glyph_format;
+ FT_Glyph_Init_Func glyph_init;
+ FT_Glyph_Done_Func glyph_done;
+ FT_Glyph_Copy_Func glyph_copy;
+ FT_Glyph_Transform_Func glyph_transform;
+ FT_Glyph_BBox_Func glyph_bbox;
+ FT_Glyph_Prepare_Func glyph_prepare;
+
+ };
+
+
/*************************************************************************
*
* <Struct>
@@ -80,11 +115,6 @@
} FT_Renderer_Class;
-
- enum
- {
- ft_render_mode_antialias = 1
- };
/*************************************************************************
*
--- a/include/freetype/internal/ftobjs.h
+++ b/include/freetype/internal/ftobjs.h
@@ -257,7 +257,10 @@
/*************************************************************************/
/*************************************************************************/
-#define FT_RENDERER(x) ((FT_Renderer)(x))
+#define FT_RENDERER(x) ((FT_Renderer)(x))
+#define FT_GLYPH(x) ((FT_Glyph)(x))
+#define FT_BITMAP_GLYPH(x) ((FT_BitmapGlyph)(x))
+#define FT_OUTLINE_GLYPH(x) ((FT_OutlineGlyph)(x))
typedef struct FT_RendererRec_
{
@@ -264,6 +267,7 @@
FT_ModuleRec root;
FT_Renderer_Class* clazz;
FT_Glyph_Format glyph_format;
+ const FT_Glyph_Class glyph_class;
FT_Raster raster;
FT_Raster_Render_Func raster_render;
@@ -384,7 +388,6 @@
/* */
/* */
/* */
- typedef void (*FT_DebugHook_Func)( void* arg );
typedef struct FT_LibraryRec_
@@ -408,19 +411,6 @@
} FT_LibraryRec;
- FT_EXPORT_DEF(FT_Error) FT_New_Library( FT_Memory memory,
- FT_Library* library );
-
-
- FT_EXPORT_DEF(FT_Error) FT_Done_Library( FT_Library library );
-
-
-
- FT_EXPORT_DEF(void) FT_Set_Debug_Hook( FT_Library library,
- FT_UInt hook_index,
- FT_DebugHook_Func debug_hook );
-
-
BASE_DEF(FT_Renderer) FT_Lookup_Renderer( FT_Library library,
FT_Glyph_Format format,
FT_ListNode *node );
@@ -428,7 +418,6 @@
BASE_DEF(FT_Error) FT_Render_Glyph_Internal( FT_Library library,
FT_GlyphSlot slot,
FT_UInt render_mode );
-
#ifndef FT_CONFIG_OPTION_NO_DEFAULT_SYSTEM
--- a/src/base/ftglyph.c
+++ b/src/base/ftglyph.c
@@ -29,6 +29,7 @@
#include <freetype/ftglyph.h>
+#include <freetype/ftoutln.h>
#include <freetype/internal/ftobjs.h>
@@ -41,32 +42,46 @@
#undef FT_COMPONENT
#define FT_COMPONENT trace_glyph
+ /*************************************************************************/
+ /*************************************************************************/
+ /**** ****/
+ /**** Convenience functions ****/
+ /**** ****/
+ /*************************************************************************/
+ /*************************************************************************/
- /* a helper function to avoid duplication of code */
- static
- void ft_prepare_glyph( FT_Glyph glyph,
- FT_Face face,
- FT_Bool vertical )
+
+
+ /*************************************************************************/
+ /* */
+ /* <Function> */
+ /* FT_Matrix_Multiply */
+ /* */
+ /* <Description> */
+ /* Performs the matrix operation `b = a*b'. */
+ /* */
+ /* <Input> */
+ /* a :: A pointer to matrix `a'. */
+ /* */
+ /* <InOut> */
+ /* b :: A pointer to matrix `b'. */
+ /* */
+ /* <MT-Note> */
+ /* Yes. */
+ /* */
+ FT_EXPORT_FUNC( void ) FT_Matrix_Multiply( FT_Matrix* a,
+ FT_Matrix* b )
{
- FT_Glyph_Metrics* metrics = &face->glyph->metrics;
+ FT_Fixed xx, xy, yx, yy;
- glyph->memory = face->memory;
- glyph->width = metrics->width;
- glyph->height = metrics->height;
+ xx = FT_MulFix( a->xx, b->xx ) + FT_MulFix( a->xy, b->yx );
+ xy = FT_MulFix( a->xx, b->xy ) + FT_MulFix( a->xy, b->yy );
+ yx = FT_MulFix( a->yx, b->xx ) + FT_MulFix( a->yy, b->yx );
+ yy = FT_MulFix( a->yx, b->xy ) + FT_MulFix( a->yy, b->yy );
- if ( vertical )
- {
- glyph->bearingX = metrics->vertBearingX;
- glyph->bearingY = metrics->vertBearingY;
- glyph->advance = metrics->vertAdvance;
- }
- else
- {
- glyph->bearingX = metrics->horiBearingX;
- glyph->bearingY = metrics->horiBearingY;
- glyph->advance = metrics->horiAdvance;
- }
+ b->xx = xx; b->xy = xy;
+ b->yx = yx; b->yy = yy;
}
@@ -73,416 +88,730 @@
/*************************************************************************/
/* */
/* <Function> */
- /* FT_Get_Glyph_Bitmap */
+ /* FT_Matrix_Invert */
/* */
/* <Description> */
- /* A function used to directly return a monochrome bitmap glyph image */
- /* from a face. */
+ /* Inverts a 2x2 matrix. Returns an error if it can't be inverted. */
/* */
- /* <Input> */
- /* face :: A handle to source face object. */
- /* glyph_index :: A glyph index into the face. */
- /* load_flags :: Load flags (see FT_LOAD_FLAG_XXXX constants). */
- /* grays :: The number of gray levels for anti-aliased bitmaps. */
- /* Set it to 0 if you want to render a monochrome */
- /* bitmap. */
- /* origin :: A pointer to the origin's position. Set it to 0 */
- /* if the current transform is the identity. */
+ /* <InOut> */
+ /* matrix :: A pointer to the target matrix. Remains untouched in */
+ /* case of error. */
/* */
- /* <Output> */
- /* abitglyph :: A pointer to the new bitmap glyph. */
- /* */
/* <Return> */
/* FreeType error code. 0 means success. */
/* */
- /* <Note> */
- /* If the font contains glyph outlines, these will be automatically */
- /* converted to a bitmap according to the value of `grays'. */
+ /* <MT-Note> */
+ /* Yes. */
/* */
- /* If `grays' is set to 0, the result is a 1-bit monochrome bitmap */
- /* otherwise, it is an 8-bit gray-level bitmap. */
- /* */
- /* The number of gray levels in the result anti-aliased bitmap might */
- /* not be `grays', depending on the current scan-converter */
- /* implementation. */
- /* */
- /* Note that it is not possible to generate 8-bit monochrome bitmaps */
- /* with this function. Rather, use FT_Get_Glyph_Outline(), then */
- /* FT_Glyph_Render_Outline(), and provide your own span callbacks. */
- /* */
- /* If the face doesn't contain scalable outlines, this function will */
- /* fail if the current transformation is not the identity, or if the */
- /* glyph origin's phase to the pixel grid is not 0 in both */
- /* directions! */
- /* */
- FT_EXPORT_FUNC( FT_Error ) FT_Get_Glyph_Bitmap(
- FT_Face face,
- FT_UInt glyph_index,
- FT_UInt load_flags,
- FT_Int grays,
- FT_Vector* origin,
- FT_BitmapGlyph* abitglyph )
+ FT_EXPORT_FUNC( FT_Error ) FT_Matrix_Invert( FT_Matrix* matrix )
{
- FT_Error error;
- FT_Memory memory;
+ FT_Pos delta, xx, yy;
- FT_BitmapGlyph bitglyph;
- FT_Glyph glyph;
- FT_Pos origin_x = 0;
- FT_Pos origin_y = 0;
+ /* compute discriminant */
+ delta = FT_MulFix( matrix->xx, matrix->yy ) -
+ FT_MulFix( matrix->xy, matrix->yx );
- if ( !face )
- return FT_Err_Invalid_Face_Handle;
+ if ( !delta )
+ return FT_Err_Invalid_Argument; /* matrix can't be inverted */
- if ( !abitglyph )
- return FT_Err_Invalid_Argument;
+ matrix->xy = - FT_DivFix( matrix->xy, delta );
+ matrix->yx = - FT_DivFix( matrix->yx, delta );
- *abitglyph = 0;
+ xx = matrix->xx;
+ yy = matrix->yy;
- if ( origin )
- {
- origin_x = origin->x & 63;
- origin_y = origin->y & 63;
- }
+ matrix->xx = FT_DivFix( yy, delta );
+ matrix->yy = FT_DivFix( xx, delta );
- /* check arguments whether the face's format is not scalable */
- if ( !( face->face_flags & FT_FACE_FLAG_SCALABLE ) &&
- face->transform_flags )
- {
- /* we can't transform bitmaps, so return an error */
- error = FT_Err_Unimplemented_Feature;
- goto Exit;
- }
+ return FT_Err_Ok;
+ }
- /* check that NO_SCALE and NO_RECURSE are not set */
- if ( load_flags & ( FT_LOAD_NO_SCALE | FT_LOAD_NO_RECURSE ) )
- {
- error = FT_Err_Invalid_Argument;
- goto Exit;
- }
- /* disable embedded bitmaps for transformed images */
- if ( face->face_flags & FT_FACE_FLAG_SCALABLE && face->transform_flags )
- load_flags |= FT_LOAD_NO_BITMAP;
+ /*************************************************************************/
+ /*************************************************************************/
+ /**** ****/
+ /**** FT_BitmapGlyph support ****/
+ /**** ****/
+ /*************************************************************************/
+ /*************************************************************************/
- error = FT_Load_Glyph( face, glyph_index, load_flags );
- if ( error )
- goto Exit;
+ static
+ FT_Error ft_bitmap_copy( FT_Memory memory,
+ FT_Bitmap* source,
+ FT_Bitmap* target )
+ {
+ FT_Error error;
+ FT_Int pitch = source->pitch;
+ FT_ULong size;
+
+ *target = *source;
+ if (pitch < 0) pitch = -pitch;
+ size = (FT_ULong)(pitch * source->rows);
+
+ if ( !ALLOC( target->buffer, size ) )
+ MEM_Copy( source->buffer, target->buffer, size );
+
+ return error;
+ }
- /* now, handle bitmap and outline glyph images */
- memory = face->memory;
- switch ( face->glyph->format )
+ static
+ FT_Error ft_bitmap_glyph_init( FT_BitmapGlyph glyph,
+ FT_GlyphSlot slot )
+ {
+ FT_Error error = FT_Err_Ok;
+ FT_Library library = FT_GLYPH(glyph)->library;
+ FT_Memory memory = library->memory;
+
+ if (slot->format != ft_glyph_format_bitmap)
{
- case ft_glyph_format_bitmap:
- {
- FT_Long size;
- FT_Bitmap* source;
+ error = FT_Err_Invalid_Glyph_Format;
+ goto Exit;
+ }
+
+ /* grab the bitmap in the slot - do lazy copying whenever possible */
+ glyph->bitmap = slot->bitmap;
+ glyph->left = slot->bitmap_left;
+ glyph->top = slot->bitmap_top;
+
+ if ( slot->flags & ft_glyph_own_bitmap )
+ {
+ slot->flags &= ~ft_glyph_own_bitmap;
+ }
+ else
+ {
+ /* copy the bitmap into a new buffer */
+ error = ft_bitmap_copy( memory, &slot->bitmap, &glyph->bitmap );
+ }
+
+ Exit:
+ return error;
+ }
- if ( ALLOC( bitglyph, sizeof ( *bitglyph ) ) )
- goto Exit;
+ static
+ FT_Error ft_bitmap_glyph_copy( FT_BitmapGlyph source,
+ FT_BitmapGlyph target )
+ {
+ FT_Memory memory = source->root.library->memory;
+
+ target->left = source->left;
+ target->top = source->top;
+
+ return ft_bitmap_copy( memory, &source->bitmap, &target->bitmap );
+ }
- glyph = (FT_Glyph)bitglyph;
- glyph->glyph_type = ft_glyph_type_bitmap;
- ft_prepare_glyph( glyph, face, 0 );
- source = &face->glyph->bitmap;
- size = source->rows * source->pitch;
- if ( size < 0 )
- size = -size;
+ static
+ void ft_bitmap_glyph_done( FT_BitmapGlyph glyph )
+ {
+ FT_Memory memory = FT_GLYPH(glyph)->library->memory;
+
+ FREE( glyph->bitmap.buffer );
+ }
- bitglyph->bitmap = *source;
- if ( ALLOC( bitglyph->bitmap.buffer, size ) )
- goto Fail;
- /* copy the content of the source glyph */
- MEM_Copy( bitglyph->bitmap.buffer, source->buffer, size );
- }
- break;
+ static
+ void ft_bitmap_glyph_bbox( FT_BitmapGlyph glyph,
+ FT_BBox *cbox )
+ {
+ cbox->xMin = glyph->left << 6;
+ cbox->xMax = cbox->xMin + (glyph->bitmap.width << 6);
+ cbox->yMax = glyph->top << 6;
+ cbox->yMin = cbox->xMax - (glyph->bitmap.rows << 6);
+ }
- case ft_glyph_format_outline:
- {
- FT_BBox cbox;
- FT_Int width, height, pitch;
- FT_Long size;
+ const FT_Glyph_Class ft_bitmap_glyph_class =
+ {
+ sizeof( FT_BitmapGlyphRec ),
+ ft_glyph_format_bitmap,
+ (FT_Glyph_Init_Func) ft_bitmap_glyph_init,
+ (FT_Glyph_Done_Func) ft_bitmap_glyph_done,
+ (FT_Glyph_Copy_Func) ft_bitmap_glyph_copy,
+ (FT_Glyph_Transform_Func) 0,
+ (FT_Glyph_BBox_Func) ft_bitmap_glyph_bbox,
+ (FT_Glyph_Prepare_Func) 0
+ };
- /* transform the outline -- note that the original metrics are NOT */
- /* transformed by this, only the outline points themselves... */
- FT_Outline_Translate( &face->glyph->outline,
- origin_x,
- origin_y );
+ /*************************************************************************/
+ /*************************************************************************/
+ /**** ****/
+ /**** FT_OutlineGlyph support ****/
+ /**** ****/
+ /*************************************************************************/
+ /*************************************************************************/
- /* compute the size in pixels of the outline */
- FT_Outline_Get_CBox( &face->glyph->outline, &cbox );
- cbox.xMin &= -64;
- cbox.yMin &= -64;
- cbox.xMax = ( cbox.xMax + 63 ) & -64;
- cbox.yMax = ( cbox.yMax + 63 ) & -64;
+
- width = ( cbox.xMax - cbox.xMin ) >> 6;
- height = ( cbox.yMax - cbox.yMin ) >> 6;
+ static
+ FT_Error ft_outline_glyph_init( FT_OutlineGlyph glyph,
+ FT_GlyphSlot slot )
+ {
+ FT_Error error = FT_Err_Ok;
+ FT_Library library = FT_GLYPH(glyph)->library;
+ FT_Outline* source = &slot->outline;
+ FT_Outline* target = &glyph->outline;
+
+ /* check format in glyph slot */
+ if (slot->format != ft_glyph_format_outline)
+ {
+ error = FT_Err_Invalid_Glyph_Format;
+ goto Exit;
+ }
+
+ /* allocate new outline */
+ error = FT_Outline_New( library, source->n_points, source->n_contours,
+ &glyph->outline );
+ if (error) goto Exit;
- /* allocate the pixel buffer for the glyph bitmap */
- if ( grays )
- /* some raster implementation need this */
- pitch = ( width + 3 ) & -4;
- else
- pitch = ( width + 7 ) >> 3;
+ /* copy it.. */
+ MEM_Copy( target->points, source->points,
+ source->n_points * sizeof ( FT_Vector ) );
- size = pitch * height;
- if ( ALLOC( bitglyph, sizeof ( *bitglyph ) ) )
- goto Exit;
+ MEM_Copy( target->tags, source->tags,
+ source->n_points * sizeof ( FT_Byte ) );
- glyph = (FT_Glyph)bitglyph;
- glyph->glyph_type = ft_glyph_type_bitmap;
- ft_prepare_glyph( glyph, face, 0 );
+ MEM_Copy( target->contours, source->contours,
+ source->n_contours * sizeof ( FT_Short ) );
- if ( ALLOC( bitglyph->bitmap.buffer, size ) )
- goto Fail;
+ /* copy all flags, except the `ft_outline_owner' one */
+ target->flags = source->flags | ft_outline_owner;
- bitglyph->bitmap.width = width;
- bitglyph->bitmap.rows = height;
- bitglyph->bitmap.pitch = pitch;
- bitglyph->bitmap.pixel_mode = grays ? ft_pixel_mode_grays
- : ft_pixel_mode_mono;
- bitglyph->bitmap.num_grays = (short)grays;
+ Exit:
+ return error;
+ }
- bitglyph->left = cbox.xMin >> 6;
- bitglyph->top = cbox.yMax >> 6;
+ static
+ void ft_outline_glyph_done( FT_OutlineGlyph glyph )
+ {
+ FT_Outline_Done( FT_GLYPH(glyph)->library, &glyph->outline );
+ }
- /* render the monochrome outline into the target buffer */
- FT_Outline_Translate( &face->glyph->outline,
- -cbox.xMin,
- -cbox.yMin );
- error = FT_Outline_Get_Bitmap( face->driver->root.library,
- &face->glyph->outline,
- &bitglyph->bitmap );
- if ( error )
- {
- FREE( bitglyph->bitmap.buffer );
- goto Fail;
- }
- }
- break;
- default:
- error = FT_Err_Invalid_Glyph_Index;
- goto Exit;
- }
-
- *abitglyph = bitglyph;
-
- Exit:
+ static
+ FT_Error ft_outline_glyph_copy( FT_OutlineGlyph source,
+ FT_OutlineGlyph target )
+ {
+ FT_Error error;
+ FT_Library library = FT_GLYPH(source)->library;
+
+ error = FT_Outline_New( library, source->outline.n_points,
+ source->outline.n_contours, &target->outline );
+ if (!error)
+ FT_Outline_Copy( &source->outline, &target->outline );
+
return error;
+ }
- Fail:
- FREE( glyph );
- goto Exit;
+ static
+ void ft_outline_glyph_transform( FT_OutlineGlyph glyph,
+ FT_Matrix* matrix,
+ FT_Vector* delta )
+ {
+ if (matrix)
+ FT_Outline_Transform( &glyph->outline, matrix );
+ if (delta)
+ FT_Outline_Translate( &glyph->outline, delta->x, delta->y );
}
+ static
+ void ft_outline_glyph_bbox( FT_OutlineGlyph glyph,
+ FT_BBox *bbox )
+ {
+ FT_Outline_Get_CBox( &glyph->outline, bbox );
+ }
- /*************************************************************************/
- /* */
- /* <Function> */
- /* FT_Get_Glyph_Outline */
- /* */
- /* <Description> */
- /* A function used to directly return a bitmap glyph image from a */
- /* face. This is faster than calling FT_Load_Glyph() + */
- /* FT_Get_Outline_Bitmap(). */
- /* */
- /* <Input> */
- /* face :: A handle to the source face object. */
- /* glyph_index :: A glyph index into face */
- /* load_flags :: Load flags (see FT_LOAD_FLAG_XXXX constants). */
- /* */
- /* <Output> */
- /* vecglyph :: A pointer to the new outline glyph. */
- /* */
- /* <Return> */
- /* FreeType error code. 0 means success. */
- /* */
- /* <Note> */
- /* This function will fail if the load flags FT_LOAD_NO_OUTLINE and */
- /* FT_LOAD_NO_RECURSE are set. */
- /* */
- FT_EXPORT_FUNC( FT_Error ) FT_Get_Glyph_Outline(
- FT_Face face,
- FT_UInt glyph_index,
- FT_UInt load_flags,
- FT_OutlineGlyph* vecglyph )
+ static
+ FT_Error ft_outline_glyph_prepare( FT_OutlineGlyph glyph,
+ FT_GlyphSlot slot )
{
- FT_Error error;
- FT_Memory memory;
- FT_OutlineGlyph glyph;
+ slot->format = ft_glyph_format_outline;
+ slot->outline = glyph->outline;
+ slot->outline.flags &= ~ft_outline_owner;
+ return FT_Err_Ok;
+ }
+ const FT_Glyph_Class ft_outline_glyph_class =
+ {
+ sizeof( FT_OutlineGlyphRec ),
+ ft_glyph_format_outline,
+ (FT_Glyph_Init_Func) ft_outline_glyph_init,
+ (FT_Glyph_Done_Func) ft_outline_glyph_done,
+ (FT_Glyph_Copy_Func) ft_outline_glyph_copy,
+ (FT_Glyph_Transform_Func) ft_outline_glyph_transform,
+ (FT_Glyph_BBox_Func) ft_outline_glyph_bbox,
+ (FT_Glyph_Prepare_Func) ft_outline_glyph_prepare
+ };
- /* test for valid `face' delayed to FT_Load_Glyph() */
+ /*************************************************************************/
+ /*************************************************************************/
+ /**** ****/
+ /**** FT_Glyph class and API ****/
+ /**** ****/
+ /*************************************************************************/
+ /*************************************************************************/
- if ( !vecglyph )
- return FT_Err_Invalid_Argument;
+ static
+ FT_Error ft_new_glyph( FT_Library library,
+ const FT_Glyph_Class* clazz,
+ FT_Glyph *aglyph )
+ {
+ FT_Memory memory = library->memory;
+ FT_Error error;
+ FT_Glyph glyph;
+
+ *aglyph = 0;
+ if ( !ALLOC( glyph, clazz->glyph_size ) )
+ {
+ glyph->library = library;
+ glyph->clazz = clazz;
+ glyph->format = clazz->glyph_format;
+
+ *aglyph = glyph;
+ }
+ return error;
+ }
- *vecglyph = 0;
- /* check that RENDER and NO_RECURSE are not set */
- if ( load_flags & ( FT_LOAD_RENDER | FT_LOAD_NO_RECURSE ) )
- {
- error = FT_Err_Invalid_Argument;
- goto Exit;
- }
+ /***********************************************************************
+ *
+ * <Function>
+ * FT_Glyph_Copy
+ *
+ * <Description>
+ * A function used to copy one glyph image.
+ *
+ * <Input>
+ * source :: handle to source glyph object
+ *
+ * <Output>
+ * target :: handle to target glyph object. 0 in case of error
+ *
+ * <Return>
+ * Error code. 0 means success.
+ *
+ ***********************************************************************/
- /* disable the loading of embedded bitmaps */
- load_flags |= FT_LOAD_NO_BITMAP;
+ FT_EXPORT_FUNC(FT_Error) FT_Glyph_Copy( FT_Glyph source,
+ FT_Glyph *target )
+ {
+ FT_Glyph copy;
+ FT_Error error;
+ const FT_Glyph_Class* clazz;
- error = FT_Load_Glyph( face, glyph_index, load_flags );
- if ( error )
- goto Exit;
-
- /* check that we really loaded an outline */
- if ( face->glyph->format != ft_glyph_format_outline )
+ *target = 0;
+
+ /* check arguments */
+ if (!source || !source->clazz)
{
- error = FT_Err_Invalid_Glyph_Index;
+ error = FT_Err_Invalid_Argument;
goto Exit;
}
+
+ clazz = source->clazz;
+ error = ft_new_glyph( source->library, clazz, © );
+ if (error) goto Exit;
- /* now, create a new outline glyph and copy everything */
- memory = face->memory;
- if ( ALLOC( glyph, sizeof ( *glyph ) ) )
- goto Exit;
+ if (clazz->glyph_copy)
+ error = clazz->glyph_copy( source, copy );
+
+ if (error)
+ FT_Done_Glyph( copy );
+ else
+ *target = copy;
+
+ Exit:
+ return error;
+ }
- ft_prepare_glyph( (FT_Glyph)glyph, face, 0 );
- glyph->metrics.glyph_type = ft_glyph_type_outline;
- error = FT_Outline_New( face->driver->root.library,
- face->glyph->outline.n_points,
- face->glyph->outline.n_contours,
- &glyph->outline );
- if ( !error )
- error = FT_Outline_Copy( &face->glyph->outline, &glyph->outline );
- if ( error )
- goto Fail;
+ /***********************************************************************
+ *
+ * <Function>
+ * FT_Get_Glyph
+ *
+ * <Description>
+ * A function used to extract one glyph image from a slot..
+ *
+ * <Input>
+ * slot :: handle to source glyph slot.
+ *
+ * <Output>
+ * aglyph :: handle to the glyph object.
+ *
+ * <Return>
+ * Error code. 0 means success.
+ *
+ * <Note>
+ *
+ *
+ ***********************************************************************/
- *vecglyph = glyph;
+ FT_EXPORT_FUNC(FT_Error) FT_Get_Glyph( FT_GlyphSlot slot,
+ FT_Glyph *aglyph )
+ {
+ FT_Library library = slot->library;
+ FT_Error error;
+ FT_Glyph glyph;
+
+ const FT_Glyph_Class* clazz = 0;
+
+ /* if it's a bitmap, that's easy :-) */
+ if (slot->format == ft_glyph_format_bitmap)
+ clazz = &ft_bitmap_glyph_class;
+ /* it it's an outline too */
+ else if (slot->format == ft_glyph_format_outline)
+ clazz = &ft_outline_glyph_class;
+
+ else
+ {
+ /* try to find a renderer that supports the glyph image format */
+ FT_Renderer render = FT_Lookup_Renderer( library, slot->format, 0 );
+ if (render)
+ clazz = &render->glyph_class;
+ }
+
+ if (!clazz)
+ {
+ error = FT_Err_Invalid_Glyph_Format;
+ goto Exit;
+ }
+
+ /* create FT_Glyph object */
+ error = ft_new_glyph( library, clazz, &glyph );
+ if (error) goto Exit;
+
+ /* copy advance while convert it to 16.16 format */
+ glyph->advance.x = slot->advance.x << 10;
+ glyph->advance.y = slot->advance.y << 10;
+
+ /* now import the image from the glyph slot */
+ error = clazz->glyph_init( glyph, slot );
+
+ /* if an error occured, destroy the glyph */
+ if (error)
+ FT_Done_Glyph( glyph );
+ else
+ *aglyph = glyph;
+
Exit:
return error;
+ }
- Fail:
- FREE( glyph );
- goto Exit;
- }
- /*************************************************************************/
- /* */
- /* <Function> */
- /* FT_Done_Glyph */
- /* */
- /* <Description> */
- /* Destroys a given glyph. */
- /* */
- /* <Input> */
- /* glyph :: A handle to the target glyph object. */
- /* */
- FT_EXPORT_FUNC( void ) FT_Done_Glyph( FT_Glyph glyph )
- {
- if ( glyph )
- {
- FT_Memory memory = glyph->memory;
+ /***********************************************************************
+ *
+ * <Function>
+ * FT_Glyph_Transform
+ *
+ * <Description>
+ * Transforms a glyph image, when it's format is scalable
+ *
+ * <Input>
+ * glyph :: handle to target glyph object
+ *
+ * matrix :: pointer to 2x2 matrix to apply
+ *
+ * delta :: pointer to a 2d vector to apply. coordinates are
+ * expressed in 1/64th of a pixel..
+ *
+ * <Return>
+ * error code (is not 0, the glyph format is not scalable).
+ *
+ * <Note>
+ * the 2x2 transform matrix is also applied to the glyph's
+ * advance vector
+ *
+ ***********************************************************************/
- if ( glyph->glyph_type == ft_glyph_type_bitmap )
+ FT_EXPORT_FUNC(FT_Error) FT_Glyph_Transform( FT_Glyph glyph,
+ FT_Matrix* matrix,
+ FT_Vector* delta )
+ {
+ const FT_Glyph_Class* clazz;
+ FT_Error error = FT_Err_Ok;
+
+ if (!glyph || !glyph->clazz)
+ error = FT_Err_Invalid_Argument;
+ else
+ {
+ clazz = glyph->clazz;
+ if (clazz->glyph_transform)
{
- FT_BitmapGlyph bit = (FT_BitmapGlyph)glyph;
-
-
- FREE( bit->bitmap.buffer );
+ /* transform glyph image */
+ clazz->glyph_transform( glyph, matrix, delta );
+
+ /* transform advance vector */
+ if (matrix)
+ FT_Vector_Transform( &glyph->advance, matrix );
}
- else if ( glyph->glyph_type == ft_glyph_type_outline )
- {
- FT_OutlineGlyph out = (FT_OutlineGlyph)glyph;
+ else
+ error = FT_Err_Invalid_Glyph_Format;
+ }
+ return error;
+ }
+
+ /***********************************************************************
+ *
+ * <Function>
+ * FT_Glyph_Get_CBox
+ *
+ * <Description>
+ * Returns the glyph image's bounding box.
+ *
+ * <Input>
+ * glyph :: handle to source glyph object
+ * mode :: a set of bit flags that indicate how to interpret
+ * the meaning of the box's coordinates
+ *
+ * <Output>
+ * box :: the glyph bounding box. Coordinates are expressed in
+ * 1/64th of pixels, it is grid-fitted..
+ *
+ * <Note>
+ * Coordinates are relative to the glyph origin, using the Y-upwards
+ * convention..
+ *
+ * if 'ft_glyph_bbox_subpixels' is set in "mode", the bbox coordinates
+ * are returned in 26.6 pixels (i.e. 1/64th of pixels).
+ *
+ * otherwise, coordinates are in integer pixels.
+ *
+ * note that the maximum coordinates are exclusive, which means that
+ * once can compute the width and height of the glyph image (be it
+ * in integer or 26.6 pixels) as:
+ *
+ * width = bbox.xMax - bbox.xMin;
+ * height = bbox.yMax - bbox.yMin;
+ *
+ * Note also that for 26.6 coordinates, if the 'ft_glyph_bbox_gridfit'
+ * flag is set in "mode", the coordinates will also be grid-fitted,
+ * which corresponds to:
+ *
+ * bbox.xMin = FLOOR(bbox.xMin);
+ * bbox.yMin = FLOOR(bbox.yMin);
+ * bbox.xMax = CEILING(bbox.xMax);
+ * bbox.yMax = CEILING(bbox.yMax);
+ *
+ ***********************************************************************/
-
- if ( out->outline.flags & ft_outline_owner )
+ FT_EXPORT_FUNC(void) FT_Glyph_Get_CBox( FT_Glyph glyph,
+ FT_UInt bbox_mode,
+ FT_BBox *cbox )
+ {
+ const FT_Glyph_Class* clazz;
+ FT_Error error = FT_Err_Ok;
+
+ if (!glyph || !glyph->clazz)
+ error = FT_Err_Invalid_Argument;
+ else
+ {
+ clazz = glyph->clazz;
+ if (!clazz->glyph_bbox)
+ error = FT_Err_Invalid_Glyph_Format;
+ else
+ {
+ /* retrieve bbox in 26.6 coordinates */
+ clazz->glyph_bbox( glyph, cbox );
+
+ /* perform grid fitting if needed */
+ if (bbox_mode & ft_glyph_bbox_gridfit)
{
- FREE( out->outline.points );
- FREE( out->outline.contours );
- FREE( out->outline.tags );
+ cbox->xMin &= -64;
+ cbox->yMin &= -64;
+ cbox->xMax = (cbox->xMax+63) & -64;
+ cbox->yMax = (cbox->yMax+63) & -64;
}
+ /* convert to integer pixels if needed */
+ if (!(bbox_mode & ft_glyph_bbox_subpixels))
+ {
+ cbox->xMin >>= 6;
+ cbox->yMin >>= 6;
+ cbox->xMax >>= 6;
+ cbox->yMax >>= 6;
+ }
}
-
- FREE( glyph );
}
+ return;
}
- /*************************************************************************/
- /* */
- /* <Function> */
- /* FT_Glyph_Get_Box */
- /* */
- /* <Description> */
- /* Returns the glyph image's bounding box in pixels. */
- /* */
- /* <Input> */
- /* glyph :: A handle to the target glyph object. */
- /* */
- /* <Output> */
- /* box :: The glyph bounding box. Coordinates are expressed in */
- /* _integer_ pixels, with exclusive maximal bounding values. */
- /* */
- /* <Note> */
- /* Coordinates are relative to the glyph origin, using the Y-upwards */
- /* convention. */
- /* */
- /* The width of the box in pixels is `box.xMax-box.xMin'; the height */
- /* is `box.yMax-box.yMin'. */
- /* */
- FT_EXPORT_FUNC( void ) FT_Glyph_Get_Box( FT_Glyph glyph,
- FT_BBox* box )
+ /***********************************************************************
+ *
+ * <Function>
+ * FT_Glyph_To_Bitmap
+ *
+ * <Description>
+ * converts a given glyph object to a bitmap glyph object
+ *
+ * <InOut>
+ * glyph :: pointer to a handle to the target glyph
+ *
+ * <Input>
+ * render_mode :: a set of bit flags that describe how
+ *
+ * origin :: pointer to a vector used to translate the glyph image
+ * before rendering. Can be 0 (for no translation). The
+ * origin is expressed in 26.6 pixels..
+ *
+ * destroy :: a boolean that indicates that the original glyph image
+ * should be destroyed by this function. The glyph is
+ * never destroyed in case of error..
+ *
+ * <Return>
+ * Error code. 0 means success
+ *
+ * <Note>
+ * the glyph image is translated with the "origin" vector before
+ * rendering.. In case of error, it it translated back to its original
+ * position and the glyph is untouched..
+ *
+ * The first parameter is a pointer to a FT_Glyph handle, that
+ * will be replaced by this function. Typically, you would use:
+ *
+ * {
+ * FT_Glyph glyph;
+ * FT_BitmapGlyph glyph_bitmap;
+ *
+ * // load glyph
+ * error = FT_Load_Char( face, glyph_index, FT_LOAD_DEFAUT );
+ *
+ * // extract glyph image
+ * error = FT_Get_Glyph( face->glyph, &glyph );
+ *
+ * // convert to a bitmap (default render mode + destroy old)
+ * if (glyph->format != ft_glyph_format_bitmap)
+ * {
+ * error = FT_Glyph_To_Bitmap( &glyph, ft_render_mode_default, 0, 1 );
+ * if (error) // glyph unchanged..
+ * }
+ *
+ * // access bitmap content by typecasting
+ * glyph_bitmap = (FT_BitmapGlyph)glyph;
+ *
+ * // do funny stuff with it, like blitting/drawing
+ * ....
+ *
+ * // discard glyph image (bitmap or not)
+ * FT_Done_Glyph( glyph );
+ *
+ *
+ * This function will always fail if the glyph's format isn't scalable
+ *
+ ***********************************************************************/
+
+ FT_EXPORT_FUNC(FT_Error) FT_Glyph_To_Bitmap( FT_Glyph *the_glyph,
+ FT_ULong render_mode,
+ FT_Vector* origin,
+ FT_Bool destroy )
{
- if ( !box )
- return;
+ FT_GlyphSlotRec dummy;
+ FT_Error error;
+ FT_Glyph glyph;
+ FT_BitmapGlyph bitmap;
+
+ const FT_Glyph_Class* clazz;
+
+ /* check arguments */
+ if (!the_glyph || !*the_glyph)
+ goto Bad;
+
+ /* we render the glyph into a glyph bitmap using a "dummy" glyph slot */
+ /* then calling FT_Render_Glyph_Internal.. */
+
+ glyph = *the_glyph;
+ if (!glyph)
+ goto Bad;
+
+ clazz = glyph->clazz;
+ if (!clazz || !clazz->glyph_prepare)
+ goto Bad;
+
+ MEM_Set( &dummy, 0, sizeof(dummy) );
+ dummy.library = glyph->library;
+ dummy.format = clazz->glyph_format;
+
+ /* if "origin" is set, translate the glyph image */
+ if (origin)
+ FT_Glyph_Transform( glyph, 0, origin );
- box->xMin = box->xMax = 0;
- box->yMin = box->yMax = 0;
+ /* create result bitmap glyph */
+ error = ft_new_glyph( glyph->library, &ft_bitmap_glyph_class,
+ (FT_Glyph*)&bitmap );
+ if (error) goto Exit;
+
+ /* prepare dummy slot for rendering */
+ error = clazz->glyph_prepare( glyph, &dummy ) ||
+ FT_Render_Glyph_Internal( glyph->library, &dummy, render_mode );
+
+ if (!destroy && origin)
+ {
+ FT_Vector v;
+
+ v.x = -origin->x;
+ v.y = -origin->y;
+ FT_Glyph_Transform( glyph, 0, &v );
+ }
- if ( glyph )
- switch ( glyph->glyph_type )
+ /* in case of succes, copy the bitmap to the glyph bitmap */
+ if (!error)
+ {
+ error = ft_bitmap_glyph_init( bitmap, &dummy );
+ if (error)
{
- case ft_glyph_type_bitmap:
- {
- FT_BitmapGlyph bit = (FT_BitmapGlyph)glyph;
+ /* thus should never happen, but let's be safe.. */
+ FT_Done_Glyph( FT_GLYPH(bitmap) );
+ goto Exit;
+ }
+
+ if (destroy)
+ FT_Done_Glyph( glyph );
+
+ *the_glyph = FT_GLYPH(bitmap);
+ }
+
+ Exit:
+ return error;
+
+ Bad:
+ error = FT_Err_Invalid_Argument;
+ goto Exit;
+ }
+ /***********************************************************************
+ *
+ * <Function>
+ * FT_Done_Glyph
+ *
+ * <Description>
+ * Destroys a given glyph..
+ *
+ * <Input>
+ * glyph :: handle to target glyph object
+ *
+ ***********************************************************************/
- box->xMin = bit->left;
- box->xMax = box->xMin + bit->bitmap.width;
- box->yMax = bit->top;
- box->yMin = box->yMax - bit->bitmap.rows;
- }
- break;
+ FT_EXPORT_FUNC(void) FT_Done_Glyph( FT_Glyph glyph )
+ {
+ if (glyph)
+ {
+ FT_Memory memory = glyph->library->memory;
+ const FT_Glyph_Class* clazz = glyph->clazz;
- case ft_glyph_type_outline:
- {
- FT_OutlineGlyph out = (FT_OutlineGlyph)glyph;
-
-
- FT_Outline_Get_CBox( &out->outline, box );
- box->xMin >>= 6;
- box->yMin >>= 6;
- box->xMax = ( box->xMax + 63 ) >> 6;
- box->yMax = ( box->yMax + 63 ) >> 6;
- }
- break;
-
- default:
- ;
- }
+ if (clazz->glyph_done)
+ clazz->glyph_done( glyph );
+
+ FREE( glyph );
+ }
}
+
+
/*************************************************************************/
/*************************************************************************/
--- a/src/base/ftobjs.c
+++ b/src/base/ftobjs.c
@@ -664,7 +664,8 @@
FT_Memory memory = driver->root.memory;
FT_Error error = FT_Err_Ok;
-
+ slot->library = driver->root.library;
+
if ( FT_DRIVER_USES_OUTLINES( driver ) )
error = FT_GlyphLoader_New( memory, &slot->loader );
@@ -1023,10 +1024,10 @@
load_flags & FT_LOAD_RENDER )
{
error = FT_Render_Glyph( slot,
- ( load_flags & FT_LOAD_ANTI_ALIAS )
- ? ft_render_mode_antialias
- : 0 );
- }
+ ( load_flags & FT_LOAD_MONOCHROME )
+ ? ft_render_mode_mono
+ : ft_render_mode_normal );
+ }
Exit:
return error;
@@ -2039,6 +2040,9 @@
/* */
/* right_glyph :: The index of the right glyph in the kern pair. */
/* */
+ /* kern_mode :: see FT_Kerning_Mode for more info. Determines the */
+ /* scale/dimension of the returned kerning vector */
+ /* */
/* <Output> */
/* kerning :: The kerning vector. This is in font units for */
/* scalable formats, and in pixels for fixed-sizes */
@@ -2053,16 +2057,16 @@
/* kernings, are out of the scope of this API function -- they can be */
/* implemented through format-specific interfaces. */
/* */
- FT_EXPORT_FUNC( FT_Error ) FT_Get_Kerning( FT_Face face,
- FT_UInt left_glyph,
- FT_UInt right_glyph,
- FT_Vector* kerning )
+ FT_EXPORT_FUNC(FT_Error) FT_Get_Kerning( FT_Face face,
+ FT_UInt left_glyph,
+ FT_UInt right_glyph,
+ FT_UInt kern_mode,
+ FT_Vector* kerning )
{
FT_Error error = FT_Err_Ok;
FT_Driver driver;
FT_Memory memory;
-
if ( !face )
return FT_Err_Invalid_Face_Handle;
@@ -2079,6 +2083,20 @@
right_glyph,
kerning );
}
+ if (!error)
+ {
+ if (kern_mode != ft_kerning_unscaled)
+ {
+ kerning->x = FT_MulFix( kerning->x, face->size->metrics.x_scale );
+ kerning->y = FT_MulFix( kerning->y, face->size->metrics.y_scale );
+
+ if (kern_mode != ft_kerning_unfitted)
+ {
+ kerning->x = (kerning->x+32) & -64;
+ kerning->y = (kerning->y+32) & -64;
+ }
+ }
+ }
else
{
kerning->x = 0;
@@ -2599,23 +2617,12 @@
/* slot :: A handle to the glyph slot containing the image to */
/* convert. */
/* */
- /* render_mode :: A set of bit flags indicating which kind of bitmap */
- /* to render. For now, only */
- /* `ft_render_mode_anti_alias' is supported by the */
- /* available renderers, but others could appear later */
- /* (e.g. optimized for TV or LCD). */
+ /* render_mode :: this is the render mode used to render the glyph */
+ /* image into a bitmap. See FT_Render_Mode for a list */
+ /* of possible values. */
/* */
/* <Return> */
/* FreeType error code. 0 means success. */
- /* */
- /* <Note> */
- /* In case of success, the renderer will be used to convert glyph */
- /* images in the renderer's known format into bitmaps. */
- /* */
- /* This doesn't change the current renderer for other formats. */
- /* */
- /* The slot's native image should be considered lost after the */
- /* conversion. */
/* */
FT_EXPORT_FUNC( FT_Error ) FT_Render_Glyph( FT_GlyphSlot slot,
FT_UInt render_mode )
--- a/src/base/ftoutln.c
+++ b/src/base/ftoutln.c
@@ -23,8 +23,7 @@
/*************************************************************************/
-#include <freetype/freetype.h>
-#include <freetype/config/ftconfig.h>
+#include <freetype/ftoutln.h>
#include <freetype/internal/ftobjs.h>
@@ -340,6 +339,57 @@
/*************************************************************************/
/* */
/* <Function> */
+ /* FT_Outline_Copy */
+ /* */
+ /* <Description> */
+ /* Copies an outline into another one. Both objects must have the */
+ /* same sizes (number of points & number of contours) when this */
+ /* function is called. */
+ /* */
+ /* <Input> */
+ /* source :: A handle to the source outline. */
+ /* */
+ /* <Output> */
+ /* target :: A handle to the target outline. */
+ /* */
+ /* <Return> */
+ /* FreeType error code. 0 means success. */
+ /* */
+ FT_EXPORT_FUNC( FT_Error ) FT_Outline_Copy( FT_Outline* source,
+ FT_Outline* target )
+ {
+ FT_Int is_owner;
+
+
+ if ( !source || !target ||
+ source->n_points != target->n_points ||
+ source->n_contours != target->n_contours )
+ return FT_Err_Invalid_Argument;
+
+ MEM_Copy( target->points, source->points,
+ source->n_points * sizeof ( FT_Vector ) );
+
+ MEM_Copy( target->tags, source->tags,
+ source->n_points * sizeof ( FT_Byte ) );
+
+ MEM_Copy( target->contours, source->contours,
+ source->n_contours * sizeof ( FT_Short ) );
+
+ /* copy all flags, except the `ft_outline_owner' one */
+ is_owner = target->flags & ft_outline_owner;
+ target->flags = source->flags;
+
+ target->flags &= ~ft_outline_owner;
+ target->flags |= is_owner;
+
+ return FT_Err_Ok;
+ }
+
+
+
+ /*************************************************************************/
+ /* */
+ /* <Function> */
/* FT_Outline_Done */
/* */
/* <Description> */
@@ -759,163 +809,14 @@
/* You can use FT_Outline_Translate() if you need to translate the */
/* outline's points. */
/* */
- BASE_FUNC( void ) FT_Outline_Transform( FT_Outline* outline,
- FT_Matrix* matrix )
+ FT_EXPORT_FUNC( void ) FT_Outline_Transform( FT_Outline* outline,
+ FT_Matrix* matrix )
{
FT_Vector* vec = outline->points;
FT_Vector* limit = vec + outline->n_points;
-
for ( ; vec < limit; vec++ )
FT_Vector_Transform( vec, matrix );
}
-
-
- /*************************************************************************/
- /*************************************************************************/
- /*************************************************************************/
- /**** ****/
- /**** The following functions are not used by the font drivers ****/
- /**** but they are provided as a convenience for client ****/
- /**** applications. ****/
- /**** ****/
- /**** Note that they will not be compiled if the configuration ****/
- /**** macro FT_CONFIG_OPTION_NO_CONVENIENCE_FUNCS is defined. ****/
- /**** ****/
- /*************************************************************************/
- /*************************************************************************/
- /*************************************************************************/
-
-
-#ifndef FT_CONFIG_OPTION_NO_CONVENIENCE_FUNCS
-
-
- /*************************************************************************/
- /* */
- /* <Function> */
- /* FT_Outline_Copy */
- /* */
- /* <Description> */
- /* Copies an outline into another one. Both objects must have the */
- /* same sizes (number of points & number of contours) when this */
- /* function is called. */
- /* */
- /* <Input> */
- /* source :: A handle to the source outline. */
- /* */
- /* <Output> */
- /* target :: A handle to the target outline. */
- /* */
- /* <Return> */
- /* FreeType error code. 0 means success. */
- /* */
- FT_EXPORT_FUNC( FT_Error ) FT_Outline_Copy( FT_Outline* source,
- FT_Outline* target )
- {
- FT_Int is_owner;
-
-
- if ( !source || !target ||
- source->n_points != target->n_points ||
- source->n_contours != target->n_contours )
- return FT_Err_Invalid_Argument;
-
- MEM_Copy( target->points, source->points,
- source->n_points * 2 * sizeof ( FT_Pos ) );
-
- MEM_Copy( target->tags, source->tags,
- source->n_points * sizeof ( FT_Byte ) );
-
- MEM_Copy( target->contours, source->contours,
- source->n_contours * sizeof ( FT_Short ) );
-
- /* copy all flags, except the `ft_outline_owner' one */
- is_owner = target->flags & ft_outline_owner;
- target->flags = source->flags;
-
- target->flags &= ~ft_outline_owner;
- target->flags |= is_owner;
-
- return FT_Err_Ok;
- }
-
-
- /*************************************************************************/
- /* */
- /* <Function> */
- /* FT_Matrix_Multiply */
- /* */
- /* <Description> */
- /* Performs the matrix operation `b = a*b'. */
- /* */
- /* <Input> */
- /* a :: A pointer to matrix `a'. */
- /* */
- /* <InOut> */
- /* b :: A pointer to matrix `b'. */
- /* */
- /* <MT-Note> */
- /* Yes. */
- /* */
- FT_EXPORT_FUNC( void ) FT_Matrix_Multiply( FT_Matrix* a,
- FT_Matrix* b )
- {
- FT_Fixed xx, xy, yx, yy;
-
-
- xx = FT_MulFix( a->xx, b->xx ) + FT_MulFix( a->xy, b->yx );
- xy = FT_MulFix( a->xx, b->xy ) + FT_MulFix( a->xy, b->yy );
- yx = FT_MulFix( a->yx, b->xx ) + FT_MulFix( a->yy, b->yx );
- yy = FT_MulFix( a->yx, b->xy ) + FT_MulFix( a->yy, b->yy );
-
- b->xx = xx; b->xy = xy;
- b->yx = yx; b->yy = yy;
- }
-
-
- /*************************************************************************/
- /* */
- /* <Function> */
- /* FT_Matrix_Invert */
- /* */
- /* <Description> */
- /* Inverts a 2x2 matrix. Returns an error if it can't be inverted. */
- /* */
- /* <InOut> */
- /* matrix :: A pointer to the target matrix. Remains untouched in */
- /* case of error. */
- /* */
- /* <Return> */
- /* FreeType error code. 0 means success. */
- /* */
- /* <MT-Note> */
- /* Yes. */
- /* */
- FT_EXPORT_FUNC( FT_Error ) FT_Matrix_Invert( FT_Matrix* matrix )
- {
- FT_Pos delta, xx, yy;
-
-
- /* compute discriminant */
- delta = FT_MulFix( matrix->xx, matrix->yy ) -
- FT_MulFix( matrix->xy, matrix->yx );
-
- if ( !delta )
- return FT_Err_Invalid_Argument; /* matrix can't be inverted */
-
- matrix->xy = - FT_DivFix( matrix->xy, delta );
- matrix->yx = - FT_DivFix( matrix->yx, delta );
-
- xx = matrix->xx;
- yy = matrix->yy;
-
- matrix->xx = FT_DivFix( yy, delta );
- matrix->yy = FT_DivFix( xx, delta );
-
- return FT_Err_Ok;
- }
-
-#endif /* FT_CONFIG_OPTION_NO_CONVENIENCE_FUNCS */
-
/* END */
--- a/src/cff/t2gload.c
+++ b/src/cff/t2gload.c
@@ -20,6 +20,7 @@
#include <freetype/internal/ftcalc.h>
#include <freetype/internal/ftstream.h>
#include <freetype/internal/sfnt.h>
+#include <freetype/ftoutln.h>
#include <freetype/tttags.h>
#include <t2load.h>
--- a/src/cff/t2parse.c
+++ b/src/cff/t2parse.c
@@ -583,7 +583,6 @@
*(FT_Int*)q = (FT_Int)val;
break;
#endif
-
default:
*(FT_Long*)q = val;
}
--- a/src/cid/cidgload.c
+++ b/src/cid/cidgload.c
@@ -20,8 +20,8 @@
#include <cidgload.h>
#include <freetype/internal/ftdebug.h>
#include <freetype/internal/ftstream.h>
+#include <freetype/ftoutln.h>
-
/*************************************************************************/
/* */
/* The macro FT_COMPONENT is used in trace mode. It is an implicit */
@@ -459,7 +459,7 @@
if ( bchar_index < 0 || achar_index < 0 )
{
- FT_ERROR(( "t1operator_seac: ));
+ FT_ERROR(( "t1operator_seac:" ));
FT_ERROR(( " invalid seac character code arguments\n" ));
return T1_Err_Syntax_Error;
}
@@ -862,7 +862,7 @@
if ( ip[0] != 12 || ip[1] != 17 )
{
FT_ERROR(( "CID_Parse_CharStrings:" ));
- FT_ERROR(( " `pop' expected, found (%d %d)\n",
+ FT_ERROR(( " 'pop' expected, found (%d %d)\n",
ip[0], ip[1] ));
goto Syntax_Error;
}
--- a/src/raster1/ftrend1.c
+++ b/src/raster1/ftrend1.c
@@ -1,4 +1,5 @@
#include <freetype/internal/ftobjs.h>
+#include <freetype/ftoutln.h>
#include <raster1.h>
#include <ftraster.h>
@@ -84,7 +85,7 @@
}
/* check rendering mode */
- if ( mode & ft_render_mode_antialias )
+ if ( mode != ft_render_mode_mono )
{
/* raster1 is only capable of producing monochrome bitmaps */
if (render->clazz == &ft_raster1_renderer_class)
@@ -124,7 +125,7 @@
}
/* allocate new one, depends on pixel format */
- if ( mode & ft_render_mode_antialias )
+ if (!(mode & ft_render_mode_mono))
{
/* we pad to 32 bits, only for backwards compatibility with FT 1.x */
pitch = (width+3) & -4;
--- a/src/smooth/ftgrays.c
+++ b/src/smooth/ftgrays.c
@@ -126,7 +126,7 @@
#include "ftgrays.h"
#include <freetype/internal/ftobjs.h> /* for UNUSED() */
#include <freetype/internal/ftdebug.h> /* for FT_TRACE() and FT_ERROR() */
-#include <freetype/freetype.h> /* for FT_Outline_Decompose() */
+#include <freetype/ftoutln.h> /* for FT_Outline_Decompose() */
#define ErrRaster_Invalid_Mode FT_Err_Cannot_Render_Glyph
--- a/src/smooth/ftsmooth.c
+++ b/src/smooth/ftsmooth.c
@@ -1,4 +1,5 @@
#include <freetype/internal/ftobjs.h>
+#include <freetype/ftoutln.h>
#include <ftsmooth.h>
#include <ftgrays.h>
@@ -51,8 +52,8 @@
/* return the glyph's control box */
static void ft_smooth_get_cbox( FT_Renderer render,
- FT_GlyphSlot slot,
- FT_BBox *cbox )
+ FT_GlyphSlot slot,
+ FT_BBox *cbox )
{
MEM_Set( cbox, 0, sizeof(*cbox) );
@@ -84,7 +85,7 @@
}
/* check mode */
- if ( mode != ft_render_mode_antialias )
+ if ( mode != ft_render_mode_normal )
return FT_Err_Cannot_Render_Glyph;
outline = &slot->outline;
@@ -104,7 +105,7 @@
width = (cbox.xMax - cbox.xMin) >> 6;
height = (cbox.yMax - cbox.yMin) >> 6;
bitmap = &slot->bitmap;
- memory = slot->face->memory;
+ memory = render->root.memory;
/* release old bitmap buffer */
if ((slot->flags & ft_glyph_own_bitmap))
--- a/src/truetype/ttgload.c
+++ b/src/truetype/ttgload.c
@@ -21,6 +21,7 @@
#include <freetype/internal/ftstream.h>
#include <freetype/internal/sfnt.h>
#include <freetype/tttags.h>
+#include <freetype/ftoutln.h>
#include <ttgload.h>
--- a/src/type1/t1gload.c
+++ b/src/type1/t1gload.c
@@ -19,6 +19,7 @@
#include <t1gload.h>
#include <freetype/internal/ftdebug.h>
#include <freetype/internal/ftstream.h>
+#include <freetype/ftoutln.h>
#ifndef T1_CONFIG_OPTION_DISABLE_HINTER
#include <t1hinter.h>
--- a/src/type1z/z1gload.c
+++ b/src/type1z/z1gload.c
@@ -18,6 +18,7 @@
#include <z1gload.h>
#include <freetype/internal/ftdebug.h>
#include <freetype/internal/ftstream.h>
+#include <freetype/ftoutln.h>
#undef FT_COMPONENT
#define FT_COMPONENT trace_t1gload