summaryrefslogtreecommitdiffstats
path: root/src/base/ftobjs.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/base/ftobjs.c')
-rw-r--r--src/base/ftobjs.c393
1 files changed, 197 insertions, 196 deletions
diff --git a/src/base/ftobjs.c b/src/base/ftobjs.c
index cc56105..9c3332c 100644
--- a/src/base/ftobjs.c
+++ b/src/base/ftobjs.c
@@ -4,7 +4,7 @@
/* */
/* The FreeType private base classes (body). */
/* */
-/* Copyright 1996-2014 by */
+/* Copyright 1996-2015 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@@ -158,7 +158,7 @@
FT_Stream stream = NULL;
- *astream = 0;
+ *astream = NULL;
if ( !library )
return FT_THROW( Invalid_Library_Handle );
@@ -178,7 +178,7 @@
/* create a memory-based stream */
FT_Stream_OpenMemory( stream,
(const FT_Byte*)args->memory_base,
- args->memory_size );
+ (FT_ULong)args->memory_size );
}
#ifndef FT_CONFIG_OPTION_DISABLE_STREAM_SUPPORT
@@ -353,10 +353,10 @@
slot->bitmap_left = 0;
slot->bitmap_top = 0;
slot->num_subglyphs = 0;
- slot->subglyphs = 0;
- slot->control_data = 0;
+ slot->subglyphs = NULL;
+ slot->control_data = NULL;
slot->control_len = 0;
- slot->other = 0;
+ slot->other = NULL;
slot->format = FT_GLYPH_FORMAT_NONE;
slot->linearHoriAdvance = 0;
@@ -387,7 +387,7 @@
if ( FT_DRIVER_USES_OUTLINES( driver ) )
{
FT_GlyphLoader_Done( slot->internal->loader );
- slot->internal->loader = 0;
+ slot->internal->loader = NULL;
}
FT_FREE( slot->internal );
@@ -408,7 +408,10 @@
FT_GlyphSlot slot = NULL;
- if ( !face || !face->driver )
+ if ( !face )
+ return FT_THROW( Invalid_Face_Handle );
+
+ if ( !face->driver )
return FT_THROW( Invalid_Argument );
driver = face->driver;
@@ -435,7 +438,7 @@
*aslot = slot;
}
else if ( aslot )
- *aslot = 0;
+ *aslot = NULL;
Exit:
@@ -508,6 +511,7 @@
internal->transform_matrix.xy = 0;
internal->transform_matrix.yx = 0;
internal->transform_matrix.yy = 0x10000L;
+
matrix = &internal->transform_matrix;
}
else
@@ -523,6 +527,7 @@
{
internal->transform_delta.x = 0;
internal->transform_delta.y = 0;
+
delta = &internal->transform_delta;
}
else
@@ -927,7 +932,7 @@
(FT_List_Destructor)destroy_size,
memory,
driver );
- face->size = 0;
+ face->size = NULL;
/* now discard client data */
if ( face->generic.finalizer )
@@ -945,7 +950,7 @@
face->stream,
( face->face_flags & FT_FACE_FLAG_EXTERNAL_STREAM ) != 0 );
- face->stream = 0;
+ face->stream = NULL;
/* get rid of it */
if ( face->internal )
@@ -963,10 +968,6 @@
(FT_List_Destructor)destroy_face,
driver->root.memory,
driver );
-
- /* check whether we need to drop the driver's glyph loader */
- if ( FT_DRIVER_USES_OUTLINES( driver ) )
- FT_GlyphLoader_Done( driver->glyph_loader );
}
@@ -1040,14 +1041,6 @@
( cur[0]->platform_id == TT_PLATFORM_APPLE_UNICODE &&
cur[0]->encoding_id == TT_APPLE_ID_UNICODE_32 ) )
{
-#ifdef FT_MAX_CHARMAP_CACHEABLE
- if ( cur - first > FT_MAX_CHARMAP_CACHEABLE )
- {
- FT_ERROR(( "find_unicode_charmap: UCS-4 cmap is found "
- "at too late position (%d)\n", cur - first ));
- continue;
- }
-#endif
face->charmap = cur[0];
return FT_Err_Ok;
}
@@ -1062,14 +1055,6 @@
{
if ( cur[0]->encoding == FT_ENCODING_UNICODE )
{
-#ifdef FT_MAX_CHARMAP_CACHEABLE
- if ( cur - first > FT_MAX_CHARMAP_CACHEABLE )
- {
- FT_ERROR(( "find_unicode_charmap: UCS-2 cmap is found "
- "at too late position (%d)\n", cur - first ));
- continue;
- }
-#endif
face->charmap = cur[0];
return FT_Err_Ok;
}
@@ -1111,17 +1096,7 @@
if ( cur[0]->platform_id == TT_PLATFORM_APPLE_UNICODE &&
cur[0]->encoding_id == TT_APPLE_ID_VARIANT_SELECTOR &&
FT_Get_CMap_Format( cur[0] ) == 14 )
- {
-#ifdef FT_MAX_CHARMAP_CACHEABLE
- if ( cur - first > FT_MAX_CHARMAP_CACHEABLE )
- {
- FT_ERROR(( "find_unicode_charmap: UVS cmap is found "
- "at too late position (%d)\n", cur - first ));
- continue;
- }
-#endif
return cur[0];
- }
}
return NULL;
@@ -1178,7 +1153,7 @@
int i;
- face->internal->incremental_interface = 0;
+ face->internal->incremental_interface = NULL;
for ( i = 0; i < num_params && !face->internal->incremental_interface;
i++ )
if ( params[i].tag == FT_PARAM_TAG_INCREMENTAL )
@@ -1220,7 +1195,7 @@
clazz->done_face( face );
FT_FREE( internal );
FT_FREE( face );
- *aface = 0;
+ *aface = NULL;
}
return error;
@@ -1243,7 +1218,7 @@
FT_Open_Args args;
- /* test for valid `library' and `aface' delayed to FT_Open_Face() */
+ /* test for valid `library' and `aface' delayed to `FT_Open_Face' */
if ( !pathname )
return FT_THROW( Invalid_Argument );
@@ -1269,7 +1244,7 @@
FT_Open_Args args;
- /* test for valid `library' and `face' delayed to FT_Open_Face() */
+ /* test for valid `library' and `face' delayed to `FT_Open_Face' */
if ( !file_base )
return FT_THROW( Invalid_Argument );
@@ -1323,8 +1298,8 @@
FT_FREE( stream->base );
stream->size = 0;
- stream->base = 0;
- stream->close = 0;
+ stream->base = NULL;
+ stream->close = NULL;
}
@@ -1348,7 +1323,7 @@
if ( !base )
return FT_THROW( Invalid_Argument );
- *astream = 0;
+ *astream = NULL;
memory = library->memory;
if ( FT_NEW( stream ) )
goto Exit;
@@ -1512,7 +1487,7 @@
FT_Error error;
FT_Memory memory = library->memory;
FT_ULong offset, length;
- FT_Long pos;
+ FT_ULong pos;
FT_Bool is_sfnt_cid;
FT_Byte* sfnt_ps = NULL;
@@ -1520,7 +1495,7 @@
FT_UNUSED( params );
- pos = FT_Stream_Pos( stream );
+ pos = FT_STREAM_POS();
error = ft_lookup_PS_in_sfnt_stream( stream,
face_index,
@@ -1583,9 +1558,9 @@
FT_Memory memory = library->memory;
FT_Byte* pfb_data = NULL;
int i, type, flags;
- FT_Long len;
- FT_Long pfb_len, pfb_pos, pfb_lenpos;
- FT_Long rlen, temp;
+ FT_ULong len;
+ FT_ULong pfb_len, pfb_pos, pfb_lenpos;
+ FT_ULong rlen, temp;
if ( face_index == -1 )
@@ -1598,14 +1573,37 @@
pfb_len = 0;
for ( i = 0; i < resource_cnt; ++i )
{
- error = FT_Stream_Seek( stream, offsets[i] );
+ error = FT_Stream_Seek( stream, (FT_ULong)offsets[i] );
if ( error )
goto Exit;
- if ( FT_READ_LONG( temp ) )
+ if ( FT_READ_ULONG( temp ) )
goto Exit;
+
+ /* FT2 allocator takes signed long buffer length,
+ * too large value causing overflow should be checked
+ */
+ FT_TRACE4(( " POST fragment #%d: length=0x%08x\n",
+ i, temp));
+ if ( 0x7FFFFFFFUL < temp || pfb_len + temp + 6 < pfb_len )
+ {
+ FT_TRACE2(( " too long fragment length makes"
+ " pfb_len confused: temp=0x%08x\n", temp ));
+ error = FT_THROW( Invalid_Offset );
+ goto Exit;
+ }
+
pfb_len += temp + 6;
}
+ FT_TRACE2(( " total buffer size to concatenate %d"
+ " POST fragments: 0x%08x\n",
+ resource_cnt, pfb_len + 2));
+ if ( pfb_len + 2 < 6 ) {
+ FT_TRACE2(( " too long fragment length makes"
+ " pfb_len confused: pfb_len=0x%08x\n", pfb_len ));
+ error = FT_THROW( Array_Too_Large );
+ goto Exit;
+ }
if ( FT_ALLOC( pfb_data, (FT_Long)pfb_len + 2 ) )
goto Exit;
@@ -1622,19 +1620,33 @@
type = 1;
for ( i = 0; i < resource_cnt; ++i )
{
- error = FT_Stream_Seek( stream, offsets[i] );
+ error = FT_Stream_Seek( stream, (FT_ULong)offsets[i] );
if ( error )
goto Exit2;
- if ( FT_READ_LONG( rlen ) )
- goto Exit;
+ if ( FT_READ_ULONG( rlen ) )
+ goto Exit2;
+
+ /* FT2 allocator takes signed long buffer length,
+ * too large fragment length causing overflow should be checked
+ */
+ if ( 0x7FFFFFFFUL < rlen )
+ {
+ error = FT_THROW( Invalid_Offset );
+ goto Exit2;
+ }
+
if ( FT_READ_USHORT( flags ) )
- goto Exit;
+ goto Exit2;
FT_TRACE3(( "POST fragment[%d]: offsets=0x%08x, rlen=0x%08x, flags=0x%04x\n",
i, offsets[i], rlen, flags ));
+ error = FT_ERR( Array_Too_Large );
/* postpone the check of rlen longer than buffer until FT_Stream_Read() */
if ( ( flags >> 8 ) == 0 ) /* Comment, should not be loaded */
+ {
+ FT_TRACE3(( " Skip POST fragment #%d because it is a comment\n", i ));
continue;
+ }
/* the flags are part of the resource, so rlen >= 2. */
/* but some fonts declare rlen = 0 for empty fragment */
@@ -1647,6 +1659,8 @@
len += rlen;
else
{
+ FT_TRACE3(( " Write POST fragment #%d header (4-byte) to buffer"
+ " 0x%p + 0x%08x\n", i, pfb_data, pfb_lenpos ));
if ( pfb_lenpos + 3 > pfb_len + 2 )
goto Exit2;
pfb_data[pfb_lenpos ] = (FT_Byte)( len );
@@ -1657,6 +1671,8 @@
if ( ( flags >> 8 ) == 5 ) /* End of font mark */
break;
+ FT_TRACE3(( " Write POST fragment #%d header (6-byte) to buffer"
+ " 0x%p + 0x%08x\n", i, pfb_data, pfb_pos ));
if ( pfb_pos + 6 > pfb_len + 2 )
goto Exit2;
pfb_data[pfb_pos++] = 0x80;
@@ -1672,16 +1688,18 @@
pfb_data[pfb_pos++] = 0;
}
- error = FT_ERR( Cannot_Open_Resource );
if ( pfb_pos > pfb_len || pfb_pos + rlen > pfb_len )
goto Exit2;
+ FT_TRACE3(( " Load POST fragment #%d (%d byte) to buffer"
+ " 0x%p + 0x%08x\n", i, rlen, pfb_data, pfb_pos ));
error = FT_Stream_Read( stream, (FT_Byte *)pfb_data + pfb_pos, rlen );
if ( error )
goto Exit2;
pfb_pos += rlen;
}
+ error = FT_ERR( Array_Too_Large );
if ( pfb_pos + 2 > pfb_len + 2 )
goto Exit2;
pfb_data[pfb_pos++] = 0x80;
@@ -1702,6 +1720,13 @@
aface );
Exit2:
+ if ( error == FT_ERR( Array_Too_Large ) )
+ FT_TRACE2(( " Abort due to too-short buffer to store"
+ " all POST fragments\n" ));
+ else if ( error == FT_ERR( Invalid_Offset ) )
+ FT_TRACE2(( " Abort due to invalid offset in a POST fragment\n" ));
+ if ( error )
+ error = FT_ERR( Cannot_Open_Resource );
FT_FREE( pfb_data );
Exit:
@@ -1725,7 +1750,7 @@
FT_Memory memory = library->memory;
FT_Byte* sfnt_data = NULL;
FT_Error error;
- FT_Long flag_offset;
+ FT_ULong flag_offset;
FT_Long rlen;
int is_cff;
FT_Long face_index_in_resource = 0;
@@ -1736,7 +1761,7 @@
if ( face_index >= resource_cnt )
return FT_THROW( Cannot_Open_Resource );
- flag_offset = offsets[face_index];
+ flag_offset = (FT_ULong)offsets[face_index];
error = FT_Stream_Seek( stream, flag_offset );
if ( error )
goto Exit;
@@ -1758,16 +1783,16 @@
if ( FT_Stream_Seek( stream, flag_offset + 4 ) )
goto Exit;
- if ( FT_ALLOC( sfnt_data, (FT_Long)rlen ) )
+ if ( FT_ALLOC( sfnt_data, rlen ) )
return error;
- error = FT_Stream_Read( stream, (FT_Byte *)sfnt_data, rlen );
+ error = FT_Stream_Read( stream, (FT_Byte *)sfnt_data, (FT_ULong)rlen );
if ( error )
goto Exit;
is_cff = rlen > 4 && !ft_memcmp( sfnt_data, "OTTO", 4 );
error = open_face_from_buffer( library,
sfnt_data,
- rlen,
+ (FT_ULong)rlen,
face_index_in_resource,
is_cff ? "cff" : "truetype",
aface );
@@ -1881,7 +1906,7 @@
rlen = ( header[0x57] << 24 ) |
( header[0x58] << 16 ) |
( header[0x59] << 8 ) |
- header[0x5a];
+ header[0x5A];
#endif /* 0 */
offset = 128 + ( ( dlen + 127 ) & ~127 );
@@ -1905,7 +1930,7 @@
FT_Memory memory = library->memory;
FT_Error error = FT_ERR( Unknown_File_Format );
- int i;
+ FT_UInt i;
char * file_names[FT_RACCESS_N_RULES];
FT_Long offsets[FT_RACCESS_N_RULES];
@@ -1913,7 +1938,7 @@
FT_Bool is_darwin_vfs, vfs_rfork_has_no_font = FALSE; /* not tested */
FT_Open_Args args2;
- FT_Stream stream2 = 0;
+ FT_Stream stream2 = NULL;
FT_Raccess_Guess( library, stream,
@@ -2049,8 +2074,7 @@
FT_Module* limit;
- /* test for valid `library' delayed to */
- /* FT_Stream_New() */
+ /* test for valid `library' delayed to `FT_Stream_New' */
if ( ( !aface && face_index >= 0 ) || !args )
return FT_THROW( Invalid_Argument );
@@ -2075,7 +2099,7 @@
if ( FT_MODULE_IS_DRIVER( driver ) )
{
FT_Int num_params = 0;
- FT_Parameter* params = 0;
+ FT_Parameter* params = NULL;
if ( args->flags & FT_OPEN_PARAMS )
@@ -2109,7 +2133,7 @@
if ( FT_MODULE_IS_DRIVER( cur[0] ) )
{
FT_Int num_params = 0;
- FT_Parameter* params = 0;
+ FT_Parameter* params = NULL;
driver = FT_DRIVER( cur[0] );
@@ -2297,7 +2321,7 @@
FT_Open_Args open;
- /* test for valid `face' delayed to FT_Attach_Stream() */
+ /* test for valid `face' delayed to `FT_Attach_Stream' */
if ( !filepathname )
return FT_THROW( Invalid_Argument );
@@ -2323,7 +2347,7 @@
FT_Driver_Class clazz;
- /* test for valid `parameters' delayed to FT_Stream_New() */
+ /* test for valid `parameters' delayed to `FT_Stream_New' */
if ( !face )
return FT_THROW( Invalid_Face_Handle );
@@ -2359,6 +2383,9 @@
FT_EXPORT_DEF( FT_Error )
FT_Reference_Face( FT_Face face )
{
+ if ( !face )
+ return FT_THROW( Invalid_Face_Handle );
+
face->internal->refcount++;
return FT_Err_Ok;
@@ -2417,20 +2444,20 @@
FT_Driver driver;
FT_Driver_Class clazz;
- FT_Size size = 0;
- FT_ListNode node = 0;
+ FT_Size size = NULL;
+ FT_ListNode node = NULL;
if ( !face )
return FT_THROW( Invalid_Face_Handle );
if ( !asize )
- return FT_THROW( Invalid_Size_Handle );
+ return FT_THROW( Invalid_Argument );
if ( !face->driver )
return FT_THROW( Invalid_Driver_Handle );
- *asize = 0;
+ *asize = NULL;
driver = face->driver;
clazz = driver->clazz;
@@ -2443,7 +2470,7 @@
size->face = face;
/* for now, do not use any internal fields in size objects */
- size->internal = 0;
+ size->internal = NULL;
if ( clazz->init_size )
error = clazz->init_size( size );
@@ -2501,7 +2528,7 @@
if ( face->size == size )
{
- face->size = 0;
+ face->size = NULL;
if ( face->sizes_list.head )
face->size = (FT_Size)(face->sizes_list.head->data);
}
@@ -2934,6 +2961,8 @@
FT_Size_RequestRec req;
+ /* check of `face' delayed to `FT_Request_Size' */
+
if ( !char_width )
char_width = char_height;
else if ( !char_height )
@@ -2972,6 +3001,8 @@
FT_Size_RequestRec req;
+ /* check of `face' delayed to `FT_Request_Size' */
+
if ( pixel_width == 0 )
pixel_width = pixel_height;
else if ( pixel_height == 0 )
@@ -2983,14 +3014,14 @@
pixel_height = 1;
/* use `>=' to avoid potential compiler warning on 16bit platforms */
- if ( pixel_width >= 0xFFFFU )
- pixel_width = 0xFFFFU;
+ if ( pixel_width >= 0xFFFFU )
+ pixel_width = 0xFFFFU;
if ( pixel_height >= 0xFFFFU )
pixel_height = 0xFFFFU;
req.type = FT_SIZE_REQUEST_TYPE_NOMINAL;
- req.width = pixel_width << 6;
- req.height = pixel_height << 6;
+ req.width = (FT_Long)( pixel_width << 6 );
+ req.height = (FT_Long)( pixel_height << 6 );
req.horiResolution = 0;
req.vertResolution = 0;
@@ -3122,15 +3153,6 @@
{
if ( cur[0]->encoding == encoding )
{
-#ifdef FT_MAX_CHARMAP_CACHEABLE
- if ( cur - face->charmaps > FT_MAX_CHARMAP_CACHEABLE )
- {
- FT_ERROR(( "FT_Select_Charmap: requested charmap is found (%d), "
- "but in too late position to cache\n",
- cur - face->charmaps ));
- continue;
- }
-#endif
face->charmap = cur[0];
return 0;
}
@@ -3154,8 +3176,9 @@
return FT_THROW( Invalid_Face_Handle );
cur = face->charmaps;
- if ( !cur )
+ if ( !cur || !charmap )
return FT_THROW( Invalid_CharMap_Handle );
+
if ( FT_Get_CMap_Format( charmap ) == 14 )
return FT_THROW( Invalid_Argument );
@@ -3165,19 +3188,11 @@
{
if ( cur[0] == charmap )
{
-#ifdef FT_MAX_CHARMAP_CACHEABLE
- if ( cur - face->charmaps > FT_MAX_CHARMAP_CACHEABLE )
- {
- FT_ERROR(( "FT_Set_Charmap: requested charmap is found (%d), "
- "but in too late position to cache\n",
- cur - face->charmaps ));
- continue;
- }
-#endif
face->charmap = cur[0];
- return 0;
+ return FT_Err_Ok;
}
}
+
return FT_THROW( Invalid_Argument );
}
@@ -3199,15 +3214,6 @@
FT_ASSERT( i < charmap->face->num_charmaps );
-#ifdef FT_MAX_CHARMAP_CACHEABLE
- if ( i > FT_MAX_CHARMAP_CACHEABLE )
- {
- FT_ERROR(( "FT_Get_Charmap_Index: requested charmap is found (%d), "
- "but in too late position to cache\n",
- i ));
- return -i;
- }
-#endif
return i;
}
@@ -3418,8 +3424,9 @@
FT_UInt result = 0;
- if ( face && face->charmap &&
- face->charmap->encoding == FT_ENCODING_UNICODE )
+ if ( face &&
+ face->charmap &&
+ face->charmap->encoding == FT_ENCODING_UNICODE )
{
FT_CharMap charmap = find_variant_selector_charmap( face );
FT_CMap ucmap = FT_CMAP( face->charmap );
@@ -3597,7 +3604,9 @@
FT_UInt result = 0;
- if ( face && FT_HAS_GLYPH_NAMES( face ) )
+ if ( face &&
+ FT_HAS_GLYPH_NAMES( face ) &&
+ glyph_name )
{
FT_Service_GlyphDict service;
@@ -3622,27 +3631,30 @@
FT_Pointer buffer,
FT_UInt buffer_max )
{
- FT_Error error = FT_ERR( Invalid_Argument );
+ FT_Error error;
+ FT_Service_GlyphDict service;
- /* clean up buffer */
- if ( buffer && buffer_max > 0 )
- ((FT_Byte*)buffer)[0] = 0;
+ if ( !face )
+ return FT_THROW( Invalid_Face_Handle );
- if ( face &&
- (FT_Long)glyph_index <= face->num_glyphs &&
- FT_HAS_GLYPH_NAMES( face ) )
- {
- FT_Service_GlyphDict service;
+ if ( !buffer || buffer_max == 0 )
+ return FT_THROW( Invalid_Argument );
+ /* clean up buffer */
+ ((FT_Byte*)buffer)[0] = '\0';
- FT_FACE_LOOKUP_SERVICE( face,
- service,
- GLYPH_DICT );
+ if ( (FT_Long)glyph_index >= face->num_glyphs )
+ return FT_THROW( Invalid_Glyph_Index );
- if ( service && service->get_name )
- error = service->get_name( face, glyph_index, buffer, buffer_max );
- }
+ if ( !FT_HAS_GLYPH_NAMES( face ) )
+ return FT_THROW( Invalid_Argument );
+
+ FT_FACE_LOOKUP_SERVICE( face, service, GLYPH_DICT );
+ if ( service && service->get_name )
+ error = service->get_name( face, glyph_index, buffer, buffer_max );
+ else
+ error = FT_THROW( Invalid_Argument );
return error;
}
@@ -3683,7 +3695,7 @@
FT_Get_Sfnt_Table( FT_Face face,
FT_Sfnt_Tag tag )
{
- void* table = 0;
+ void* table = NULL;
FT_Service_SFNT_Table service;
@@ -3733,6 +3745,8 @@
FT_ULong offset;
+ /* test for valid `length' delayed to `service->table_info' */
+
if ( !face || !FT_IS_SFNT( face ) )
return FT_THROW( Invalid_Face_Handle );
@@ -3800,12 +3814,12 @@
FT_Face face;
- if ( size == NULL )
- return FT_THROW( Invalid_Argument );
+ if ( !size )
+ return FT_THROW( Invalid_Size_Handle );
face = size->face;
- if ( face == NULL || face->driver == NULL )
- return FT_THROW( Invalid_Argument );
+ if ( !face || !face->driver )
+ return FT_THROW( Invalid_Face_Handle );
/* we don't need anything more complex than that; all size objects */
/* are already listed by the face */
@@ -3834,7 +3848,7 @@
FT_ListNode* node )
{
FT_ListNode cur;
- FT_Renderer result = 0;
+ FT_Renderer result = NULL;
if ( !library )
@@ -3846,7 +3860,7 @@
{
if ( *node )
cur = (*node)->next;
- *node = 0;
+ *node = NULL;
}
while ( cur )
@@ -3984,7 +3998,7 @@
FT_Get_Renderer( FT_Library library,
FT_Glyph_Format format )
{
- /* test for valid `library' delayed to FT_Lookup_Renderer() */
+ /* test for valid `library' delayed to `FT_Lookup_Renderer' */
return FT_Lookup_Renderer( library, format, 0 );
}
@@ -4001,12 +4015,26 @@
FT_ListNode node;
FT_Error error = FT_Err_Ok;
+ FT_Renderer_SetModeFunc set_mode;
+
if ( !library )
- return FT_THROW( Invalid_Library_Handle );
+ {
+ error = FT_THROW( Invalid_Library_Handle );
+ goto Exit;
+ }
if ( !renderer )
- return FT_THROW( Invalid_Argument );
+ {
+ error = FT_THROW( Invalid_Argument );
+ goto Exit;
+ }
+
+ if ( num_params > 0 && !parameters )
+ {
+ error = FT_THROW( Invalid_Argument );
+ goto Exit;
+ }
node = FT_List_Find( &library->renderers, renderer );
if ( !node )
@@ -4020,18 +4048,14 @@
if ( renderer->glyph_format == FT_GLYPH_FORMAT_OUTLINE )
library->cur_renderer = renderer;
- if ( num_params > 0 )
- {
- FT_Renderer_SetModeFunc set_mode = renderer->clazz->set_mode;
-
+ set_mode = renderer->clazz->set_mode;
- for ( ; num_params > 0; num_params-- )
- {
- error = set_mode( renderer, parameters->tag, parameters->data );
- if ( error )
- break;
- parameters++;
- }
+ for ( ; num_params > 0; num_params-- )
+ {
+ error = set_mode( renderer, parameters->tag, parameters->data );
+ if ( error )
+ break;
+ parameters++;
}
Exit:
@@ -4056,8 +4080,7 @@
default:
{
- FT_ListNode node = 0;
- FT_Bool update = 0;
+ FT_ListNode node = NULL;
/* small shortcut for the very common case */
@@ -4084,13 +4107,7 @@
/* now, look for another renderer that supports the same */
/* format. */
renderer = FT_Lookup_Renderer( library, slot->format, &node );
- update = 1;
}
-
- /* if we changed the current renderer for the glyph image format */
- /* we need to select it as the next current one */
- if ( !error && update && renderer )
- FT_Set_Renderer( library, renderer, 0, 0 );
}
}
@@ -4100,28 +4117,32 @@
#define FT_COMPONENT trace_bitmap
/* we convert to a single bitmap format for computing the checksum */
+ if ( !error )
{
FT_Bitmap bitmap;
FT_Error err;
- FT_Bitmap_New( &bitmap );
+ FT_Bitmap_Init( &bitmap );
+ /* this also converts the bitmap flow to `down' (i.e., pitch > 0) */
err = FT_Bitmap_Convert( library, &slot->bitmap, &bitmap, 1 );
if ( !err )
{
MD5_CTX ctx;
unsigned char md5[16];
int i;
+ unsigned int rows = bitmap.rows;
+ unsigned int pitch = (unsigned int)bitmap.pitch;
- MD5_Init( &ctx);
- MD5_Update( &ctx, bitmap.buffer, bitmap.rows * bitmap.pitch );
+ MD5_Init( &ctx );
+ MD5_Update( &ctx, bitmap.buffer, rows * pitch );
MD5_Final( md5, &ctx );
FT_TRACE3(( "MD5 checksum for %dx%d bitmap:\n"
" ",
- bitmap.rows, bitmap.pitch ));
+ rows, pitch ));
for ( i = 0; i < 16; i++ )
FT_TRACE3(( "%02X", md5[i] ));
FT_TRACE3(( "\n" ));
@@ -4194,7 +4215,7 @@
if ( library && library->auto_hinter == module )
- library->auto_hinter = 0;
+ library->auto_hinter = NULL;
/* if the module is a renderer */
if ( FT_MODULE_IS_RENDERER( module ) )
@@ -4290,17 +4311,10 @@
/* if the module is a font driver */
if ( FT_MODULE_IS_DRIVER( module ) )
{
- /* allocate glyph loader if needed */
FT_Driver driver = FT_DRIVER( module );
driver->clazz = (FT_Driver_Class)module->clazz;
- if ( FT_DRIVER_USES_OUTLINES( driver ) )
- {
- error = FT_GlyphLoader_New( memory, &driver->glyph_loader );
- if ( error )
- goto Fail;
- }
}
if ( clazz->module_init )
@@ -4317,15 +4331,6 @@
return error;
Fail:
- if ( FT_MODULE_IS_DRIVER( module ) )
- {
- FT_Driver driver = FT_DRIVER( module );
-
-
- if ( FT_DRIVER_USES_OUTLINES( driver ) )
- FT_GlyphLoader_Done( driver->glyph_loader );
- }
-
if ( FT_MODULE_IS_RENDERER( module ) )
{
FT_Renderer renderer = FT_RENDERER( module );
@@ -4348,7 +4353,7 @@
FT_Get_Module( FT_Library library,
const char* module_name )
{
- FT_Module result = 0;
+ FT_Module result = NULL;
FT_Module* cur;
FT_Module* limit;
@@ -4460,7 +4465,7 @@
cur[0] = cur[1];
cur++;
}
- limit[0] = 0;
+ limit[0] = NULL;
/* destroy the module */
Destroy_Module( module );
@@ -4603,6 +4608,9 @@
FT_EXPORT_DEF( FT_Error )
FT_Reference_Library( FT_Library library )
{
+ if ( !library )
+ return FT_THROW( Invalid_Library_Handle );
+
library->refcount++;
return FT_Err_Ok;
@@ -4619,7 +4627,7 @@
FT_Error error;
- if ( !memory )
+ if ( !memory || !alibrary )
return FT_THROW( Invalid_Argument );
#ifdef FT_DEBUG_LEVEL_ERROR
@@ -4640,12 +4648,9 @@
goto Fail;
#endif
- /* allocate the render pool */
- library->raster_pool_size = FT_RENDER_POOL_SIZE;
-#if FT_RENDER_POOL_SIZE > 0
- if ( FT_ALLOC( library->raster_pool, FT_RENDER_POOL_SIZE ) )
- goto Fail;
-#endif
+ /* we don't use raster_pool anymore. */
+ library->raster_pool_size = 0;
+ library->raster_pool = NULL;
library->version_major = FREETYPE_MAJOR;
library->version_minor = FREETYPE_MINOR;
@@ -4658,8 +4663,8 @@
return FT_Err_Ok;
- Fail:
#ifdef FT_CONFIG_OPTION_PIC
+ Fail:
ft_pic_container_destroy( library );
#endif
FT_FREE( library );
@@ -4788,16 +4793,12 @@
if ( module )
{
Destroy_Module( module );
- library->modules[n] = 0;
+ library->modules[n] = NULL;
}
}
}
#endif
- /* Destroy raster objects */
- FT_FREE( library->raster_pool );
- library->raster_pool_size = 0;
-
#ifdef FT_CONFIG_OPTION_PIC
/* Destroy pic container contents */
ft_pic_container_destroy( library );