Index: include/freetype/ftbitmap.h =================================================================== RCS file: /home/cvs/freetype2/include/freetype/ftbitmap.h,v retrieving revision 1.1.1.1 diff -u -r1.1.1.1 ftbitmap.h --- include/freetype/ftbitmap.h 15 May 2005 07:10:28 -0000 1.1.1.1 +++ include/freetype/ftbitmap.h 16 May 2005 02:34:47 -0000 @@ -69,6 +69,29 @@ /*************************************************************************/ /* */ /* */ + /* FT_Bitmap_Copy */ + /* */ + /* */ + /* Copies an bitmap into another one. */ + /* */ + /* */ + /* source :: A handle to the source bitmap. */ + /* */ + /* */ + /* target :: A handle to the target bitmap. */ + /* */ + /* */ + /* FreeType error code. 0 means success. */ + /* */ + FT_EXPORT_DEF( FT_Error ) + FT_Bitmap_Copy( FT_Library library, + const FT_Bitmap *source, + FT_Bitmap *target); + + + /*************************************************************************/ + /* */ + /* */ /* FT_Bitmap_Convert */ /* */ /* */ Index: src/base/ftbitmap.c =================================================================== RCS file: /home/cvs/freetype2/src/base/ftbitmap.c,v retrieving revision 1.1.1.1 diff -u -r1.1.1.1 ftbitmap.c --- src/base/ftbitmap.c 15 May 2005 07:10:28 -0000 1.1.1.1 +++ src/base/ftbitmap.c 16 May 2005 02:41:24 -0000 @@ -18,8 +18,7 @@ #include -#include FT_FREETYPE_H -#include FT_IMAGE_H +#include FT_BITMAP_H #include FT_INTERNAL_OBJECTS_H @@ -39,6 +38,65 @@ /* documentation is in ftbitmap.h */ FT_EXPORT_DEF( FT_Error ) + FT_Bitmap_Copy( FT_Library library, + const FT_Bitmap *source, + FT_Bitmap *target) + { + FT_Memory memory = library->memory; + FT_Error error = FT_Err_Ok; + FT_Int pitch = source->pitch; + FT_ULong size; + + + if ( source == target ) + return FT_Err_Ok; + + if ( source->buffer == NULL ) + { + *target = *source; + + return FT_Err_Ok; + } + + if ( pitch < 0 ) + pitch = -pitch; + size = (FT_ULong)( pitch * source->rows ); + + if ( target->buffer ) + { + FT_Int target_pitch = target->pitch; + FT_ULong target_size; + + + if ( target_pitch < 0 ) + target_pitch = -target_pitch; + target_size = (FT_ULong)( target_pitch * target->rows ); + + if ( target_size != size ) + FT_QREALLOC( target->buffer, target_size, size ); + } + else + FT_QALLOC( target->buffer, size ); + + if ( !error ) + { + unsigned char *p; + + + p = target->buffer; + *target = *source; + target->buffer = p; + + FT_MEM_COPY( target->buffer, source->buffer, size ); + } + + return error; + } + + + /* documentation is in ftbitmap.h */ + + FT_EXPORT_DEF( FT_Error ) FT_Bitmap_Convert( FT_Library library, const FT_Bitmap *source, FT_Bitmap *target, Index: src/base/ftglyph.c =================================================================== RCS file: /home/cvs/freetype2/src/base/ftglyph.c,v retrieving revision 1.1.1.1 diff -u -r1.1.1.1 ftglyph.c --- src/base/ftglyph.c 15 May 2005 07:10:28 -0000 1.1.1.1 +++ src/base/ftglyph.c 16 May 2005 02:38:28 -0000 @@ -31,6 +31,7 @@ #include #include FT_GLYPH_H #include FT_OUTLINE_H +#include FT_BITMAP_H #include FT_INTERNAL_OBJECTS_H @@ -114,30 +115,6 @@ /*************************************************************************/ /*************************************************************************/ - 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 ( !FT_ALLOC( target->buffer, size ) ) - FT_MEM_COPY( target->buffer, source->buffer, size ); - - return error; - } - - FT_CALLBACK_DEF( FT_Error ) ft_bitmap_glyph_init( FT_Glyph bitmap_glyph, FT_GlyphSlot slot ) @@ -145,7 +122,6 @@ FT_BitmapGlyph glyph = (FT_BitmapGlyph)bitmap_glyph; 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 ) @@ -154,17 +130,19 @@ goto Exit; } - /* grab the bitmap in the slot - do lazy copying whenever possible */ - glyph->bitmap = slot->bitmap; glyph->left = slot->bitmap_left; glyph->top = slot->bitmap_top; + /* do lazy copying whenever possible */ if ( slot->internal->flags & FT_GLYPH_OWN_BITMAP ) + { + glyph->bitmap = slot->bitmap; slot->internal->flags &= ~FT_GLYPH_OWN_BITMAP; + } else { - /* copy the bitmap into a new buffer */ - error = ft_bitmap_copy( memory, &slot->bitmap, &glyph->bitmap ); + FT_Bitmap_New( &glyph->bitmap ); + error = FT_Bitmap_Copy( library, &slot->bitmap, &glyph->bitmap ); } Exit: @@ -176,26 +154,26 @@ ft_bitmap_glyph_copy( FT_Glyph bitmap_source, FT_Glyph bitmap_target ) { - FT_BitmapGlyph source = (FT_BitmapGlyph)bitmap_source; - FT_BitmapGlyph target = (FT_BitmapGlyph)bitmap_target; - FT_Memory memory = bitmap_source->library->memory; + FT_Library library = bitmap_source->library; + FT_BitmapGlyph source = (FT_BitmapGlyph)bitmap_source; + FT_BitmapGlyph target = (FT_BitmapGlyph)bitmap_target; target->left = source->left; target->top = source->top; - return ft_bitmap_copy( memory, &source->bitmap, &target->bitmap ); + return FT_Bitmap_Copy( library, &source->bitmap, &target->bitmap ); } FT_CALLBACK_DEF( void ) ft_bitmap_glyph_done( FT_Glyph bitmap_glyph ) { - FT_BitmapGlyph glyph = (FT_BitmapGlyph)bitmap_glyph; - FT_Memory memory = FT_GLYPH( glyph )->library->memory; + FT_BitmapGlyph glyph = (FT_BitmapGlyph)bitmap_glyph; + FT_Library library = FT_GLYPH( glyph )->library; - FT_FREE( glyph->bitmap.buffer ); + FT_Bitmap_Done( library, &glyph->bitmap ); } @@ -261,15 +239,7 @@ if ( error ) goto Exit; - /* copy it */ - FT_ARRAY_COPY( target->points, source->points, source->n_points ); - - FT_ARRAY_COPY( target->tags, source->tags, source->n_points ); - - FT_ARRAY_COPY( target->contours, source->contours, source->n_contours ); - - /* copy all flags, except the `FT_OUTLINE_OWNER' one */ - target->flags = source->flags | FT_OUTLINE_OWNER; + FT_Outline_Copy( source, target ); Exit: return error; Index: src/base/ftoutln.c =================================================================== RCS file: /home/cvs/freetype2/src/base/ftoutln.c,v retrieving revision 1.1.1.1 diff -u -r1.1.1.1 ftoutln.c --- src/base/ftoutln.c 15 May 2005 07:10:28 -0000 1.1.1.1 +++ src/base/ftoutln.c 16 May 2005 02:33:21 -0000 @@ -358,6 +358,9 @@ source->n_contours != target->n_contours ) return FT_Err_Invalid_Argument; + if ( source == target ) + return FT_Err_Ok; + FT_ARRAY_COPY( target->points, source->points, source->n_points ); FT_ARRAY_COPY( target->tags, source->tags, source->n_points ); @@ -379,7 +382,7 @@ FT_Outline_Done_Internal( FT_Memory memory, FT_Outline* outline ) { - if ( outline ) + if ( memory && outline ) { if ( outline->flags & FT_OUTLINE_OWNER ) { @@ -472,6 +475,9 @@ FT_Vector* vec = outline->points; + if ( !outline ) + return; + for ( n = 0; n < outline->n_points; n++ ) { vec->x += xOffset; @@ -490,6 +496,9 @@ FT_Int first, last; + if ( !outline ) + return; + first = 0; for ( n = 0; n < outline->n_contours; n++ ) @@ -553,7 +562,7 @@ if ( !library ) return FT_Err_Invalid_Library_Handle; - if ( !params ) + if ( !outline || !params ) return FT_Err_Invalid_Argument; renderer = library->cur_renderer; @@ -644,9 +653,15 @@ FT_Outline_Transform( FT_Outline* outline, const FT_Matrix* matrix ) { - FT_Vector* vec = outline->points; - FT_Vector* limit = vec + outline->n_points; + FT_Vector* vec; + FT_Vector* limit; + + + if ( !outline || !matrix ) + return; + vec = outline->points; + limit = vec + outline->n_points; for ( ; vec < limit; vec++ ) FT_Vector_Transform( vec, matrix );