From f9ca2bb58a3c8e70cf5e0e0d2580c50385c48df0 Mon Sep 17 00:00:00 2001 From: David Turner Date: Fri, 30 Jun 2000 23:12:55 +0000 Subject: [PATCH] managed to re-design entirely the API in 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.. --- demos/src/ftmulti.c | 97 +-- demos/src/ftstring.c | 112 +-- demos/src/fttimer.c | 222 +----- demos/src/ftview.c | 2 +- demos/src/memtest.c | 6 +- include/freetype/freetype.h | 598 +++------------- include/freetype/fterrors.h | 2 +- include/freetype/ftglyph.h | 369 ++++++---- include/freetype/ftmodule.h | 87 +++ include/freetype/ftrender.h | 40 +- include/freetype/internal/ftobjs.h | 21 +- src/base/ftglyph.c | 1041 ++++++++++++++++++---------- src/base/ftobjs.c | 55 +- src/base/ftoutln.c | 207 ++---- src/cff/t2gload.c | 1 + src/cff/t2parse.c | 1 - src/cid/cidgload.c | 6 +- src/raster1/ftrend1.c | 5 +- src/smooth/ftgrays.c | 2 +- src/smooth/ftsmooth.c | 9 +- src/truetype/ttgload.c | 1 + src/type1/t1gload.c | 1 + src/type1z/z1gload.c | 1 + 23 files changed, 1375 insertions(+), 1511 deletions(-) diff --git a/demos/src/ftmulti.c b/demos/src/ftmulti.c index ebc19dcfb..7cca05303 100644 --- 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 */ - - 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 + /* Then, blit the image to the target surface */ + x_top = x_offset + glyph->bitmap_left; + y_top = y_offset - glyph->bitmap_top; 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; } diff --git a/demos/src/ftstring.c b/demos/src/ftstring.c index 3478f5cbd..61c7c7579 100644 --- 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)", diff --git a/demos/src/fttimer.c b/demos/src/fttimer.c index 77d1367a5..b8a5ed1ad 100644 --- a/demos/src/fttimer.c +++ b/demos/src/fttimer.c @@ -20,15 +20,13 @@ /****************************************************************************/ #include -#include +#include #include #include #include #include /* for clock() */ -#include "graph.h" - /* SunOS 4.1.* does not define CLOCKS_PER_SEC, so include */ /* 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,45 +81,10 @@ } -/*******************************************************************/ -/* */ -/* 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: */ -/* */ -/* Clears current bitmap. */ -/* */ -/*******************************************************************/ - - static void Clear_Buffer( void ) - { - long size = Bit.rows * Bit.pitch; - - memset( Bit.buffer, 0, size ); - } - - -/*******************************************************************/ -/* */ -/* LoadTrueTypeChar: */ +/* LoadChar: */ /* */ /* 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 ) - { - 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" ); - } -#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_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 ) { - 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 ); + glyphs[cur_glyph++] = glyph; } - /* 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,37 +153,27 @@ char filename[128 + 4]; char alt_filename[128 + 4]; char* execname; - grSurface* surface = 0; long t, t0, tz0; 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; - break; - - case 'a': - use_grays = 1; + case 'm': + antialias = 0; 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; diff --git a/demos/src/ftview.c b/demos/src/ftview.c index e1e2690a5..074a62a5f 100644 --- 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; } diff --git a/demos/src/memtest.c b/demos/src/memtest.c index b37afb7c9..ad600598c 100644 --- a/demos/src/memtest.c +++ b/demos/src/memtest.c @@ -1,16 +1,15 @@ /* memtest.c */ #include -#include +#include #include #include +#include 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 ); diff --git a/include/freetype/freetype.h b/include/freetype/freetype.h index 884089a64..bc101caaf 100644 --- 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 /* read configuration information */ #include #include @@ -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.. */ /* */ /* */ + /* 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,8 +1806,23 @@ /* 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 0 /* this is the default */ + + /*************************************************************************/ + /* */ + /* */ + /* FT_LOAD_MONOCHROME */ + /* */ + /* */ + /* 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_ANTI_ALIAS 4096 +#define FT_LOAD_MONOCHROME 0 /* this is the default */ /*************************************************************************/ @@ -1867,11 +1875,56 @@ /* */ /* 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 ); + /************************************************************************* + * + * + * FT_Render_Mode + * + * + * 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.. + * + * + * 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 + * + * + * 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; + + + /************************************************************************* * * @@ -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. * * * Error code. 0 means success. * - * - * 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 ); - + + /************************************************************************** + * + * + * FT_Kerning_Mode + * + * + * A list of enumerations used to specify which kerning values to + * return in FT_Get_Kerning + * + * + * 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; + /*************************************************************************/ /* */ /* */ @@ -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 */ + /* */ /* */ /* 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 ); - /*************************************************************************/ - /* */ - /* */ - /* FT_Outline_Get_Bitmap */ - /* */ - /* */ - /* Renders an outline within a bitmap. The outline's image is simply */ - /* or-ed to the target bitmap. */ - /* */ - /* */ - /* */ - /* library :: A handle to a FreeType library object. */ - /* outline :: A pointer to the source outline descriptor. */ - /* map :: A pointer to the target bitmap descriptor. */ - /* */ - /* */ - /* FreeType error code. 0 means success. */ - /* */ - /* */ - /* YES. Rendering is synchronized, so that concurrent calls to the */ - /* scan-line converter will be serialized. */ - /* */ - /* */ - /* 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 ); - - /*************************************************************************/ - /* */ - /* */ - /* FT_Outline_Render */ - /* */ - /* */ - /* 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.. */ - /* */ - /* */ - /* 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 */ - /* */ - /* */ - /* FreeType error code. 0 means success. */ - /* */ - /* */ - /* YES. Rendering is synchronized, so that concurrent calls to the */ - /* scan-line converter will be serialized. */ - /* */ - /* */ - /* 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 ); - - - /*************************************************************************/ - /* */ - /* */ - /* FT_Outline_Decompose */ - /* */ - /* */ - /* 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. */ - /* */ - /* */ - /* 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. */ - /* */ - /* */ - /* FreeType error code. 0 means sucess. */ - /* */ - FT_EXPORT_DEF(FT_Error) FT_Outline_Decompose( FT_Outline* outline, - FT_Outline_Funcs* funcs, - void* user ); - - - /*************************************************************************/ - /* */ - /* */ - /* FT_Outline_New */ - /* */ - /* */ - /* Creates a new outline of a given size. */ - /* */ - /* */ - /* 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. */ - /* */ - /* */ - /* outline :: A handle to the new outline. NULL in case of */ - /* error. */ - /* */ - /* */ - /* FreeType error code. 0 means success. */ - /* */ - /* */ - /* No. */ - /* */ - /* */ - /* 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 ); - - - /*************************************************************************/ - /* */ - /* */ - /* FT_Outline_Done */ - /* */ - /* */ - /* Destroys an outline created with FT_Outline_New(). */ - /* */ - /* */ - /* library :: A handle of the library object used to allocate the */ - /* outline. */ - /* */ - /* outline :: A pointer to the outline object to be discarded. */ - /* */ - /* */ - /* FreeType error code. 0 means success. */ - /* */ - /* */ - /* No. */ - /* */ - /* */ - /* 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 ); - - /*************************************************************************/ - /* */ - /* */ - /* FT_Outline_Get_CBox */ - /* */ - /* */ - /* 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. */ - /* */ - /* */ - /* outline :: A pointer to the source outline descriptor. */ - /* */ - /* */ - /* cbox :: The outline's control box. */ - /* */ - /* */ - /* Yes. */ - /* */ - FT_EXPORT_DEF(void) FT_Outline_Get_CBox( FT_Outline* outline, - FT_BBox* cbox ); - - - /*************************************************************************/ - /* */ - /* */ - /* FT_Outline_Translate */ - /* */ - /* */ - /* Applies a simple translation to the points of an outline. */ - /* */ - /* */ - /* outline :: A pointer to the target outline descriptor. */ - /* xOffset :: The horizontal offset. */ - /* yOffset :: The vertical offset. */ - /* */ - /* */ - /* Yes. */ - /* */ - FT_EXPORT_DEF(void) FT_Outline_Translate( FT_Outline* outline, - FT_Pos xOffset, - FT_Pos yOffset ); - - -#if 0 - /*************************************************************************/ - /* */ - /* */ - /* FT_Set_Raster */ - /* */ - /* */ - /* Register a given raster to the library. */ - /* */ - /* */ - /* library :: A handle to a target library object. */ - /* raster_funcs :: pointer to the raster's interface */ - /* */ - /* */ - /* Error code. 0 means success. */ - /* */ - /* */ - /* 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 ); - - - /*************************************************************************/ - /* */ - /* */ - /* FT_Unset_Raster */ - /* */ - /* */ - /* Removes a given raster from the library. */ - /* */ - /* */ - /* library :: A handle to a target library object. */ - /* raster_funcs :: pointer to the raster's interface */ - /* */ - /* */ - /* Error code. 0 means success. */ - /* */ - /* */ - /* 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 ); - - - /************************************************************************* - * - * - * FT_Get_Raster - * - * - * Return a pointer to the raster corresponding to a given glyph - * format tag. - * - * - * library :: handle to source library object - * glyph_format :: glyph format tag - * - * - * raster_funcs :: if this field is not 0, returns a pointer to the - * raster's interface/descriptor.. - * - * - * 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 ); - - - /*************************************************************************/ - /* */ - /* */ - /* FT_Set_Raster_Mode */ - /* */ - /* */ - /* Set a raster-specific mode. */ - /* */ - /* */ - /* 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 */ - /* */ - /* 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". *****/ - /***** *****/ - /***************************************************************************/ - /***************************************************************************/ - /***************************************************************************/ - - /*************************************************************************/ - /* */ - /* */ - /* FT_Outline_Copy */ - /* */ - /* */ - /* Copies an outline into another one. Both objects must have the */ - /* same sizes (number of points & number of contours) when this */ - /* function is called. */ - /* */ - /* */ - /* source :: A handle to the source outline. */ - /* target :: A handle to the target outline. */ - /* */ - /* */ - /* FreeType error code. 0 means success. */ - /* */ - FT_EXPORT_DEF(FT_Error) FT_Outline_Copy( FT_Outline* source, - FT_Outline* target ); - - - - /*************************************************************************/ - /* */ - /* */ - /* FT_Outline_Transform */ - /* */ - /* */ - /* Applies a simple 2x2 matrix to all of an outline's points. Useful */ - /* for applying rotations, slanting, flipping, etc. */ - /* */ - /* */ - /* outline :: A pointer to the target outline descriptor. */ - /* matrix :: A pointer to the transformation matrix. */ - /* */ - /* */ - /* Yes. */ - /* */ - /* */ - /* 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 ); - - /*************************************************************************/ - /* */ - /* */ - /* FT_Outline_Reverse */ - /* */ - /* */ - /* Reverse the drawing direction of an outline. This is used to */ - /* ensure consistent fill conventions for mirrored glyphs.. */ - /* */ - /* */ - /* outline :: A pointer to the target outline descriptor. */ - /* */ - /* */ - /* 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 ); - - - - - /*************************************************************************/ - /* */ - /* */ - /* FT_Matrix_Multiply */ - /* */ - /* */ - /* Performs the matrix operation `b = a*b'. */ - /* */ - /* */ - /* a :: A pointer to matrix `a'. */ - /* */ - /* */ - /* b :: A pointer to matrix `b'. */ - /* */ - /* */ - /* Yes. */ - /* */ - FT_EXPORT_DEF(void) FT_Matrix_Multiply( FT_Matrix* a, - FT_Matrix* b ); - - - /*************************************************************************/ - /* */ - /* */ - /* FT_Matrix_Invert */ - /* */ - /* */ - /* Inverts a 2x2 matrix. Returns an error if it can't be inverted. */ - /* */ - /* */ - /* matrix :: A pointer to the target matrix. Remains untouched in */ - /* case of error. */ - /* */ - /* */ - /* FreeType error code. 0 means success. */ - /* */ - /* */ - /* Yes. */ - /* */ - FT_EXPORT_DEF(FT_Error) FT_Matrix_Invert( FT_Matrix* matrix ); - - /*************************************************************************/ - /* */ - /* */ - /* FT_Default_Drivers */ - /* */ - /* */ - /* Adds the set of default drivers to a given library object. */ - /* */ - /* */ - /* library :: A handle to a new library object. */ - /* */ - FT_EXPORT_DEF(void) FT_Default_Drivers( FT_Library library ); #ifdef __cplusplus } diff --git a/include/freetype/fterrors.h b/include/freetype/fterrors.h index 3c7c76052..078babe0b 100644 --- a/include/freetype/fterrors.h +++ b/include/freetype/fterrors.h @@ -54,7 +54,7 @@ FT_ERROR_START_LIST 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" ) diff --git a/include/freetype/ftglyph.h b/include/freetype/ftglyph.h index c44122464..51cb1cc19 100644 --- a/include/freetype/ftglyph.h +++ b/include/freetype/ftglyph.h @@ -32,13 +32,8 @@ extern "C" { #endif - typedef enum { - - ft_glyph_type_none = 0, - ft_glyph_type_bitmap = 1, - ft_glyph_type_outline = 2 - - } FT_GlyphType; + /* forward declaration to a private type */ + typedef struct FT_Glyph_Class_ FT_Glyph_Class; /*********************************************************************** * @@ -46,45 +41,23 @@ * FT_GlyphRec * * - * 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.. * * - * memory :: a handle to the memory allocator that is used to - * create/clone/destroy this glyph.. - * - * 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 - * - * - * 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.. + * 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 * ***********************************************************************/ 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,41 +68,37 @@ * FT_BitmapGlyphRec * * - * 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". * * - * 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. * 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. * * - * 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" - * - * this structure is used for both monochrome and anti-aliased - * bitmaps (the bitmap descriptor contains field describing the - * format of the pixel buffer) + * 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.. * * 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 * * - * 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. * * - * metrics :: the corresponding glyph metrics + * root :: the root FT_Glyph fields. * outline :: a descriptor for the outline * * - * 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; + /*********************************************************************** * * - * FT_Get_Glyph_Bitmap + * FT_Get_Glyph * * - * A function used to directly return a bitmap glyph image - * from a face. + * A function used to extract one glyph image from a slot.. * * - * 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. * * - * bitglyph :: pointer to the new bitmap glyph + * aglyph :: handle to the glyph object. * * * Error code. 0 means success. * * - * 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 ); /*********************************************************************** * * - * FT_Get_Glyph_Outline + * FT_Glyph_Copy * * - * 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. * * - * 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 * * - * vecglyph :: pointer to the new outline glyph + * target :: handle to target glyph object. 0 in case of error * * * Error code. 0 means success. * - * - * 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 ); /*********************************************************************** * * - * FT_Set_Transform + * FT_Glyph_Transform * * - * 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 * * - * 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.. + * + * + * error code (is not 0, the glyph format is not scalable). * * - * 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 ); + /*********************************************************************** * * - * FT_Done_Glyph + * FT_Glyph_Get_CBox * * - * Destroys a given glyph.. + * Returns the glyph image's bounding box. * * - * 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 + * + * + * box :: the glyph bounding box. Coordinates are expressed in + * 1/64th of pixels, it is grid-fitted.. + * + * + * 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 ); /*********************************************************************** * * - * FT_Glyph_Get_Box + * FT_Glyph_To_Bitmap * * - * Returns the glyph image's bounding box in pixels. + * converts a given glyph object to a bitmap glyph object + * + * + * glyph :: pointer to a handle to the target glyph * * - * glyph :: handle to target glyph object + * render_mode :: a set of bit flags that describe how * - * - * 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.. + * + * + * Error code. 0 means success * * - * 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 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; * - * The width of the box in pixels is box.xMax-box.xMin - * The height is box.yMax - box.yMin + * // 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(FT_Error) FT_Glyph_To_Bitmap( FT_Glyph *the_glyph, + FT_ULong render_mode, + FT_Vector* origin, + FT_Bool destroy ); + + /*********************************************************************** + * + * + * FT_Done_Glyph + * + * + * Destroys a given glyph.. + * + * + * glyph :: handle to target glyph object * ***********************************************************************/ - FT_EXPORT_DEF(void) FT_Glyph_Get_Box( FT_Glyph glyph, - FT_BBox *box ); + FT_EXPORT_DEF(void) FT_Done_Glyph( FT_Glyph glyph ); + + + /* other helpful functions */ + + /*************************************************************************/ + /* */ + /* */ + /* FT_Matrix_Multiply */ + /* */ + /* */ + /* Performs the matrix operation `b = a*b'. */ + /* */ + /* */ + /* a :: A pointer to matrix `a'. */ + /* */ + /* */ + /* b :: A pointer to matrix `b'. */ + /* */ + /* */ + /* Yes. */ + /* */ + FT_EXPORT_DEF(void) FT_Matrix_Multiply( FT_Matrix* a, + FT_Matrix* b ); + + + /*************************************************************************/ + /* */ + /* */ + /* FT_Matrix_Invert */ + /* */ + /* */ + /* Inverts a 2x2 matrix. Returns an error if it can't be inverted. */ + /* */ + /* */ + /* matrix :: A pointer to the target matrix. Remains untouched in */ + /* case of error. */ + /* */ + /* */ + /* FreeType error code. 0 means success. */ + /* */ + /* */ + /* Yes. */ + /* */ + FT_EXPORT_DEF(FT_Error) FT_Matrix_Invert( FT_Matrix* matrix ); + #ifdef __cplusplus } diff --git a/include/freetype/ftmodule.h b/include/freetype/ftmodule.h index 6175b2a0e..2e611bc4f 100644 --- a/include/freetype/ftmodule.h +++ b/include/freetype/ftmodule.h @@ -192,6 +192,93 @@ FT_Module module ); + /************************************************************************* + * + * + * FT_New_Library + * + * + * 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 + * + * + * memory :: handle to custom memory manager + * + * + * library :: handle to fresh new library object + * + * + * Error code (module not listed) + * + *************************************************************************/ + + FT_EXPORT_DEF(FT_Error) FT_New_Library( FT_Memory memory, + FT_Library* library ); + + + /************************************************************************* + * + * + * FT_Done_Library + * + * + * Destroys a given library, and all child objects, except the + * memory manager. + * + * + * library :: handle to target library object + * + * + * Error code (module not listed) + * + *************************************************************************/ + + FT_EXPORT_DEF(FT_Error) FT_Done_Library( FT_Library library ); + + + + /************************************************************************* + * + * + * FT_Set_Debug_Hook + * + * + * Used only by the TrueType debugger. This function is private and + * should never be called by normal applications.. + * + * + * 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 ); + + + + /*************************************************************************/ + /* */ + /* */ + /* FT_Add_Default_Modules */ + /* */ + /* */ + /* 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) */ + /* */ + /* */ + /* library :: A handle to a new library object. */ + /* */ + FT_EXPORT_DEF(void) FT_Add_Default_Modules( FT_Library library ); + + + #endif /* FTMODULE_H */ diff --git a/include/freetype/ftrender.h b/include/freetype/ftrender.h index f7d629587..2853927ec 100644 --- a/include/freetype/ftrender.h +++ b/include/freetype/ftrender.h @@ -19,6 +19,41 @@ #define FTRENDER_H #include +#include + + /* 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; + + }; + /************************************************************************* * @@ -81,11 +116,6 @@ } FT_Renderer_Class; - enum - { - ft_render_mode_antialias = 1 - }; - /************************************************************************* * * diff --git a/include/freetype/internal/ftobjs.h b/include/freetype/internal/ftobjs.h index bb8c24c9a..187596c58 100644 --- a/include/freetype/internal/ftobjs.h +++ b/include/freetype/internal/ftobjs.h @@ -257,13 +257,17 @@ /*************************************************************************/ /*************************************************************************/ -#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_ { 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 ); @@ -430,7 +420,6 @@ FT_UInt render_mode ); - #ifndef FT_CONFIG_OPTION_NO_DEFAULT_SYSTEM FT_EXPORT_DEF(FT_Error) FT_New_Stream( const char* filepathname, diff --git a/src/base/ftglyph.c b/src/base/ftglyph.c index 7d9f44342..e25dbe7d4 100644 --- a/src/base/ftglyph.c +++ b/src/base/ftglyph.c @@ -29,6 +29,7 @@ #include +#include #include @@ -41,449 +42,777 @@ #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 ) + + + /*************************************************************************/ + /* */ + /* */ + /* FT_Matrix_Multiply */ + /* */ + /* */ + /* Performs the matrix operation `b = a*b'. */ + /* */ + /* */ + /* a :: A pointer to matrix `a'. */ + /* */ + /* */ + /* b :: A pointer to matrix `b'. */ + /* */ + /* */ + /* 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; } /*************************************************************************/ /* */ /* */ - /* FT_Get_Glyph_Bitmap */ + /* FT_Matrix_Invert */ /* */ /* */ - /* 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. */ /* */ - /* */ - /* 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. */ - /* */ - /* */ - /* abitglyph :: A pointer to the new bitmap glyph. */ + /* */ + /* matrix :: A pointer to the target matrix. Remains untouched in */ + /* case of error. */ /* */ /* */ /* FreeType error code. 0 means success. */ /* */ - /* */ - /* 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. */ + /* */ + /* Yes. */ /* */ - /* 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; + + matrix->xx = FT_DivFix( yy, delta ); + matrix->yy = FT_DivFix( xx, delta ); + + return FT_Err_Ok; + } + + + /*************************************************************************/ + /*************************************************************************/ + /**** ****/ + /**** FT_BitmapGlyph support ****/ + /**** ****/ + /*************************************************************************/ + /*************************************************************************/ + + 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; + } - if ( origin ) - { - origin_x = origin->x & 63; - origin_y = origin->y & 63; - } - /* check arguments whether the face's format is not scalable */ - if ( !( face->face_flags & FT_FACE_FLAG_SCALABLE ) && - face->transform_flags ) + 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) { - /* we can't transform bitmaps, so return an error */ - error = FT_Err_Unimplemented_Feature; + error = FT_Err_Invalid_Glyph_Format; goto Exit; } - - /* check that NO_SCALE and NO_RECURSE are not set */ - if ( load_flags & ( FT_LOAD_NO_SCALE | FT_LOAD_NO_RECURSE ) ) + + /* 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 ) { - error = FT_Err_Invalid_Argument; - goto Exit; + 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; + } - /* disable embedded bitmaps for transformed images */ - if ( face->face_flags & FT_FACE_FLAG_SCALABLE && face->transform_flags ) - load_flags |= FT_LOAD_NO_BITMAP; - - error = FT_Load_Glyph( face, glyph_index, load_flags ); - if ( error ) - goto Exit; - /* now, handle bitmap and outline glyph images */ - memory = face->memory; + 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 ); + } - switch ( face->glyph->format ) - { - case ft_glyph_format_bitmap: - { - FT_Long size; - FT_Bitmap* source; + static + void ft_bitmap_glyph_done( FT_BitmapGlyph glyph ) + { + FT_Memory memory = FT_GLYPH(glyph)->library->memory; + + FREE( glyph->bitmap.buffer ); + } - if ( ALLOC( bitglyph, sizeof ( *bitglyph ) ) ) - goto Exit; - glyph = (FT_Glyph)bitglyph; - glyph->glyph_type = ft_glyph_type_bitmap; - ft_prepare_glyph( glyph, face, 0 ); + 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); + } - source = &face->glyph->bitmap; - size = source->rows * source->pitch; - if ( size < 0 ) - size = -size; - bitglyph->bitmap = *source; - if ( ALLOC( bitglyph->bitmap.buffer, size ) ) - goto Fail; + 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 + }; - /* copy the content of the source glyph */ - MEM_Copy( bitglyph->bitmap.buffer, source->buffer, size ); - } - break; + /*************************************************************************/ + /*************************************************************************/ + /**** ****/ + /**** FT_OutlineGlyph support ****/ + /**** ****/ + /*************************************************************************/ + /*************************************************************************/ - case ft_glyph_format_outline: - { - FT_BBox cbox; - FT_Int width, height, pitch; - FT_Long size; - - - /* 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 ); - - /* 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; - - /* allocate the pixel buffer for the glyph bitmap */ - if ( grays ) - /* some raster implementation need this */ - pitch = ( width + 3 ) & -4; - else - pitch = ( width + 7 ) >> 3; - - size = pitch * height; - if ( ALLOC( bitglyph, sizeof ( *bitglyph ) ) ) - goto Exit; - - glyph = (FT_Glyph)bitglyph; - glyph->glyph_type = ft_glyph_type_bitmap; - ft_prepare_glyph( glyph, face, 0 ); - - if ( ALLOC( bitglyph->bitmap.buffer, size ) ) - goto Fail; - - 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; - - bitglyph->left = cbox.xMin >> 6; - bitglyph->top = cbox.yMax >> 6; - - /* 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; + 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; + + /* copy it.. */ + MEM_Copy( target->points, source->points, + source->n_points * sizeof ( FT_Vector ) ); - *abitglyph = bitglyph; + 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 */ + target->flags = source->flags | ft_outline_owner; Exit: return error; + } - Fail: - FREE( glyph ); - goto Exit; + static + void ft_outline_glyph_done( FT_OutlineGlyph glyph ) + { + FT_Outline_Done( FT_GLYPH(glyph)->library, &glyph->outline ); } - /*************************************************************************/ - /* */ - /* */ - /* FT_Get_Glyph_Outline */ - /* */ - /* */ - /* 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(). */ - /* */ - /* */ - /* 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). */ - /* */ - /* */ - /* vecglyph :: A pointer to the new outline glyph. */ - /* */ - /* */ - /* FreeType error code. 0 means success. */ - /* */ - /* */ - /* 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_copy( FT_OutlineGlyph source, + FT_OutlineGlyph target ) { - FT_Error error; - FT_Memory memory; - FT_OutlineGlyph glyph; + 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; + } + 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 ); + } - /* test for valid `face' delayed to FT_Load_Glyph() */ + static + void ft_outline_glyph_bbox( FT_OutlineGlyph glyph, + FT_BBox *bbox ) + { + FT_Outline_Get_CBox( &glyph->outline, bbox ); + } + + static + FT_Error ft_outline_glyph_prepare( FT_OutlineGlyph glyph, + FT_GlyphSlot slot ) + { + slot->format = ft_glyph_format_outline; + slot->outline = glyph->outline; + slot->outline.flags &= ~ft_outline_owner; + return FT_Err_Ok; + } - if ( !vecglyph ) - return FT_Err_Invalid_Argument; + 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 + }; - *vecglyph = 0; + /*************************************************************************/ + /*************************************************************************/ + /**** ****/ + /**** FT_Glyph class and API ****/ + /**** ****/ + /*************************************************************************/ + /*************************************************************************/ - /* check that RENDER and NO_RECURSE are not set */ - if ( load_flags & ( FT_LOAD_RENDER | FT_LOAD_NO_RECURSE ) ) + 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; + } + + + /*********************************************************************** + * + * + * FT_Glyph_Copy + * + * + * A function used to copy one glyph image. + * + * + * source :: handle to source glyph object + * + * + * target :: handle to target glyph object. 0 in case of error + * + * + * Error code. 0 means success. + * + ***********************************************************************/ + + 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; + + *target = 0; + + /* check arguments */ + if (!source || !source->clazz) { error = FT_Err_Invalid_Argument; goto Exit; } - - /* disable the loading of embedded bitmaps */ - load_flags |= FT_LOAD_NO_BITMAP; - - 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 ) + + clazz = source->clazz; + error = ft_new_glyph( source->library, clazz, © ); + if (error) 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_Get_Glyph + * + * + * A function used to extract one glyph image from a slot.. + * + * + * slot :: handle to source glyph slot. + * + * + * aglyph :: handle to the glyph object. + * + * + * Error code. 0 means success. + * + * + * + * + ***********************************************************************/ + + 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 { - error = FT_Err_Invalid_Glyph_Index; - goto Exit; + /* 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; } - - /* now, create a new outline glyph and copy everything */ - memory = face->memory; - if ( ALLOC( glyph, sizeof ( *glyph ) ) ) + + if (!clazz) + { + error = FT_Err_Invalid_Glyph_Format; goto Exit; - - 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; - - *vecglyph = glyph; - + } + + /* 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; - } - - - /*************************************************************************/ - /* */ - /* */ - /* FT_Done_Glyph */ - /* */ - /* */ - /* Destroys a given glyph. */ - /* */ - /* */ - /* glyph :: A handle to the target glyph object. */ - /* */ - FT_EXPORT_FUNC( void ) FT_Done_Glyph( FT_Glyph glyph ) + } + + + + + /*********************************************************************** + * + * + * FT_Glyph_Transform + * + * + * Transforms a glyph image, when it's format is scalable + * + * + * 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.. + * + * + * error code (is not 0, the glyph format is not scalable). + * + * + * the 2x2 transform matrix is also applied to the glyph's + * advance vector + * + ***********************************************************************/ + + FT_EXPORT_FUNC(FT_Error) FT_Glyph_Transform( FT_Glyph glyph, + FT_Matrix* matrix, + FT_Vector* delta ) { - if ( glyph ) + const FT_Glyph_Class* clazz; + FT_Error error = FT_Err_Ok; + + if (!glyph || !glyph->clazz) + error = FT_Err_Invalid_Argument; + else { - FT_Memory memory = glyph->memory; - - - if ( glyph->glyph_type == ft_glyph_type_bitmap ) + 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 ) + else + error = FT_Err_Invalid_Glyph_Format; + } + return error; + } + + /*********************************************************************** + * + * + * FT_Glyph_Get_CBox + * + * + * Returns the glyph image's bounding box. + * + * + * glyph :: handle to source glyph object + * mode :: a set of bit flags that indicate how to interpret + * the meaning of the box's coordinates + * + * + * box :: the glyph bounding box. Coordinates are expressed in + * 1/64th of pixels, it is grid-fitted.. + * + * + * 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_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 { - FT_OutlineGlyph out = (FT_OutlineGlyph)glyph; - - - if ( out->outline.flags & ft_outline_owner ) + /* retrieve bbox in 26.6 coordinates */ + clazz->glyph_bbox( glyph, cbox ); + + /* perform grid fitting if needed */ + if (bbox_mode & ft_glyph_bbox_gridfit) + { + 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)) { - FREE( out->outline.points ); - FREE( out->outline.contours ); - FREE( out->outline.tags ); + cbox->xMin >>= 6; + cbox->yMin >>= 6; + cbox->xMax >>= 6; + cbox->yMax >>= 6; } } - - FREE( glyph ); } + return; } - /*************************************************************************/ - /* */ - /* */ - /* FT_Glyph_Get_Box */ - /* */ - /* */ - /* Returns the glyph image's bounding box in pixels. */ - /* */ - /* */ - /* glyph :: A handle to the target glyph object. */ - /* */ - /* */ - /* box :: The glyph bounding box. Coordinates are expressed in */ - /* _integer_ pixels, with exclusive maximal bounding values. */ - /* */ - /* */ - /* 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 ) + /*********************************************************************** + * + * + * FT_Glyph_To_Bitmap + * + * + * converts a given glyph object to a bitmap glyph object + * + * + * glyph :: pointer to a handle to the target glyph + * + * + * 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.. + * + * + * Error code. 0 means success + * + * + * 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; - - box->xMin = box->xMax = 0; - box->yMin = box->yMax = 0; + 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 ); + + /* 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; - - - box->xMin = bit->left; - box->xMax = box->xMin + bit->bitmap.width; - box->yMax = bit->top; - box->yMin = box->yMax - bit->bitmap.rows; - } - break; - - 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: - ; + /* 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; + } + + /*********************************************************************** + * + * + * FT_Done_Glyph + * + * + * Destroys a given glyph.. + * + * + * glyph :: handle to target glyph object + * + ***********************************************************************/ + + 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; + + if (clazz->glyph_done) + clazz->glyph_done( glyph ); + + FREE( glyph ); + } } + + /*************************************************************************/ /*************************************************************************/ /**** ****/ diff --git a/src/base/ftobjs.c b/src/base/ftobjs.c index e64236db4..cd2ca4aa7 100644 --- 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 */ + /* */ /* */ /* 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,24 +2617,13 @@ /* 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. */ /* */ /* */ /* FreeType error code. 0 means success. */ /* */ - /* */ - /* 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 ) { diff --git a/src/base/ftoutln.c b/src/base/ftoutln.c index 008a07b25..e22e2cc81 100644 --- a/src/base/ftoutln.c +++ b/src/base/ftoutln.c @@ -23,8 +23,7 @@ /*************************************************************************/ -#include -#include +#include #include @@ -337,6 +336,57 @@ } + /*************************************************************************/ + /* */ + /* */ + /* FT_Outline_Copy */ + /* */ + /* */ + /* Copies an outline into another one. Both objects must have the */ + /* same sizes (number of points & number of contours) when this */ + /* function is called. */ + /* */ + /* */ + /* source :: A handle to the source outline. */ + /* */ + /* */ + /* target :: A handle to the target outline. */ + /* */ + /* */ + /* 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; + } + + + /*************************************************************************/ /* */ /* */ @@ -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 - - - /*************************************************************************/ - /* */ - /* */ - /* FT_Outline_Copy */ - /* */ - /* */ - /* Copies an outline into another one. Both objects must have the */ - /* same sizes (number of points & number of contours) when this */ - /* function is called. */ - /* */ - /* */ - /* source :: A handle to the source outline. */ - /* */ - /* */ - /* target :: A handle to the target outline. */ - /* */ - /* */ - /* 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; - } - - - /*************************************************************************/ - /* */ - /* */ - /* FT_Matrix_Multiply */ - /* */ - /* */ - /* Performs the matrix operation `b = a*b'. */ - /* */ - /* */ - /* a :: A pointer to matrix `a'. */ - /* */ - /* */ - /* b :: A pointer to matrix `b'. */ - /* */ - /* */ - /* 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; - } - - - /*************************************************************************/ - /* */ - /* */ - /* FT_Matrix_Invert */ - /* */ - /* */ - /* Inverts a 2x2 matrix. Returns an error if it can't be inverted. */ - /* */ - /* */ - /* matrix :: A pointer to the target matrix. Remains untouched in */ - /* case of error. */ - /* */ - /* */ - /* FreeType error code. 0 means success. */ - /* */ - /* */ - /* 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 */ diff --git a/src/cff/t2gload.c b/src/cff/t2gload.c index dfde78b14..f1a5a8de7 100644 --- a/src/cff/t2gload.c +++ b/src/cff/t2gload.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include diff --git a/src/cff/t2parse.c b/src/cff/t2parse.c index 53f15e08f..1af97957b 100644 --- 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; } diff --git a/src/cid/cidgload.c b/src/cid/cidgload.c index 3a38545e1..39c34daf4 100644 --- a/src/cid/cidgload.c +++ b/src/cid/cidgload.c @@ -20,7 +20,7 @@ #include #include #include - +#include /*************************************************************************/ /* */ @@ -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; } diff --git a/src/raster1/ftrend1.c b/src/raster1/ftrend1.c index 84fe38a12..67938103f 100644 --- a/src/raster1/ftrend1.c +++ b/src/raster1/ftrend1.c @@ -1,4 +1,5 @@ #include +#include #include #include @@ -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; diff --git a/src/smooth/ftgrays.c b/src/smooth/ftgrays.c index 06cdab975..458b0455e 100644 --- a/src/smooth/ftgrays.c +++ b/src/smooth/ftgrays.c @@ -126,7 +126,7 @@ #include "ftgrays.h" #include /* for UNUSED() */ #include /* for FT_TRACE() and FT_ERROR() */ -#include /* for FT_Outline_Decompose() */ +#include /* for FT_Outline_Decompose() */ #define ErrRaster_Invalid_Mode FT_Err_Cannot_Render_Glyph diff --git a/src/smooth/ftsmooth.c b/src/smooth/ftsmooth.c index 7cd4929d9..eed9246e0 100644 --- a/src/smooth/ftsmooth.c +++ b/src/smooth/ftsmooth.c @@ -1,4 +1,5 @@ #include +#include #include #include @@ -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)) diff --git a/src/truetype/ttgload.c b/src/truetype/ttgload.c index 7ca8077e8..9f72cee86 100644 --- a/src/truetype/ttgload.c +++ b/src/truetype/ttgload.c @@ -21,6 +21,7 @@ #include #include #include +#include #include diff --git a/src/type1/t1gload.c b/src/type1/t1gload.c index aa728a55b..1b86b3f21 100644 --- a/src/type1/t1gload.c +++ b/src/type1/t1gload.c @@ -19,6 +19,7 @@ #include #include #include +#include #ifndef T1_CONFIG_OPTION_DISABLE_HINTER #include diff --git a/src/type1z/z1gload.c b/src/type1z/z1gload.c index 44d7d2ba1..a65fc1602 100644 --- a/src/type1z/z1gload.c +++ b/src/type1z/z1gload.c @@ -18,6 +18,7 @@ #include #include #include +#include #undef FT_COMPONENT #define FT_COMPONENT trace_t1gload