From 930e9bf8f40f5d28b9441249e9cfe1f71e37c29f Mon Sep 17 00:00:00 2001 From: Werner Lemberg Date: Sat, 26 Nov 2011 13:38:26 +0100 Subject: [PATCH] Add new error code FT_Err_Missing_Module. Previously, FreeType misleadingly returned FT_Err_Unknown_File_Format if a module was missing (or a test was missing completely). * include/freetype/fterrdef.h (FT_Err_Missing_Module): Define. * src/cff/cffobjs.c (cff_face_init), src/cid/cidobjs.c (cid_face_init), src/sfnt/sfobjs.c (sfnt_init_face), src/truetype/ttobjs.c (tt_face_init), src/type1/t1objs.c (T1_Face_Init), src/type42/t42objs.c (T42_Face_Init, T42_Driver_Init): Updated. * src/type1/t1afm.c (T1_Read_Metrics), src/type/t1objs.c (T1_Face_Init), src/type42/t42objs.c (T42_Face_Init): Remove now redundant test for `psaux'. --- ChangeLog | 20 ++++++++++++++++++++ include/freetype/fterrdef.h | 4 +++- modules.cfg | 4 ++-- src/cff/cffobjs.c | 16 +++++++++------- src/cid/cidobjs.c | 9 ++++++++- src/sfnt/sfobjs.c | 5 ++++- src/truetype/ttobjs.c | 9 +++++++-- src/type1/t1afm.c | 5 ++--- src/type1/t1objs.c | 10 ++++++++-- src/type42/t42objs.c | 16 ++++++++++++++-- 10 files changed, 77 insertions(+), 21 deletions(-) diff --git a/ChangeLog b/ChangeLog index 51d4c7487..7e78351fb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,23 @@ +2011-11-26 Werner Lemberg + + Add new error code FT_Err_Missing_Module. + + Previously, FreeType misleadingly returned + FT_Err_Unknown_File_Format if a module was missing (or a test was + missing completely). + + * include/freetype/fterrdef.h (FT_Err_Missing_Module): Define. + + * src/cff/cffobjs.c (cff_face_init), src/cid/cidobjs.c + (cid_face_init), src/sfnt/sfobjs.c (sfnt_init_face), + src/truetype/ttobjs.c (tt_face_init), src/type1/t1objs.c + (T1_Face_Init), src/type42/t42objs.c (T42_Face_Init, + T42_Driver_Init): Updated. + + * src/type1/t1afm.c (T1_Read_Metrics), src/type/t1objs.c + (T1_Face_Init), src/type42/t42objs.c (T42_Face_Init): Remove now + redundant test for `psaux'. + 2011-11-25 Werner Lemberg [bdf] Add more error messages. diff --git a/include/freetype/fterrdef.h b/include/freetype/fterrdef.h index d4e7287f2..fb4b53bca 100644 --- a/include/freetype/fterrdef.h +++ b/include/freetype/fterrdef.h @@ -4,7 +4,7 @@ /* */ /* FreeType error codes (specification). */ /* */ -/* Copyright 2002, 2004, 2006, 2007, 2010 by */ +/* Copyright 2002, 2004, 2006, 2007, 2010-2011 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -54,6 +54,8 @@ "broken offset within table" ) FT_ERRORDEF_( Array_Too_Large, 0x0A, \ "array allocation size too large" ) + FT_ERRORDEF_( Missing_Module, 0x0B, \ + "missing module" ) /* glyph/character errors */ diff --git a/modules.cfg b/modules.cfg index 8d5b6b598..a85378ee7 100644 --- a/modules.cfg +++ b/modules.cfg @@ -1,6 +1,6 @@ # modules.cfg # -# Copyright 2005, 2006, 2007, 2009, 2010 by +# Copyright 2005-2007, 2009-2011 by # David Turner, Robert Wilhelm, and Werner Lemberg. # # This file is part of the FreeType project, and may only be used, modified, @@ -54,7 +54,7 @@ FONT_MODULES += pfr # PostScript Type 42 font driver. # -# This driver needs the `truetype' module. +# This driver needs the `truetype' and `psaux' modules. FONT_MODULES += type42 # Windows FONT/FNT font driver. See optional extension ftwinfnt.c below diff --git a/src/cff/cffobjs.c b/src/cff/cffobjs.c index 15707a2a3..feb5845d4 100644 --- a/src/cff/cffobjs.c +++ b/src/cff/cffobjs.c @@ -494,7 +494,11 @@ sfnt = (SFNT_Service)FT_Get_Module_Interface( library, "sfnt" ); if ( !sfnt ) - goto Bad_Format; + { + FT_ERROR(( "cff_face_init: cannot access `sfnt' module\n" )); + error = CFF_Err_Missing_Module; + goto Exit; + } FT_FACE_FIND_GLOBAL_SERVICE( face, psnames, POSTSCRIPT_CMAPS ); @@ -512,7 +516,8 @@ if ( face->format_tag != TTAG_OTTO ) /* `OTTO'; OpenType/CFF font */ { FT_TRACE2(( "[not a valid OpenType/CFF font]\n" )); - goto Bad_Format; + error = CFF_Err_Unknown_File_Format; + goto Exit; } /* if we are performing a simple font format check, exit immediately */ @@ -604,7 +609,8 @@ " cannot open CFF & CEF fonts\n" " " " without the `PSNames' module\n" )); - goto Bad_Format; + error = CFF_Err_Missing_Module; + goto Exit; } #ifdef FT_DEBUG_LEVEL_TRACE @@ -1014,10 +1020,6 @@ Exit: return error; - - Bad_Format: - error = CFF_Err_Unknown_File_Format; - goto Exit; } diff --git a/src/cid/cidobjs.c b/src/cid/cidobjs.c index eb8216888..17c851fd3 100644 --- a/src/cid/cidobjs.c +++ b/src/cid/cidobjs.c @@ -4,7 +4,7 @@ /* */ /* CID objects manager (body). */ /* */ -/* Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2008, 2010 by */ +/* Copyright 1996-2006, 2008, 2010-2011 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -299,6 +299,13 @@ psaux = (PSAux_Service)FT_Get_Module_Interface( FT_FACE_LIBRARY( face ), "psaux" ); + if ( !psaux ) + { + FT_ERROR(( "cid_face_init: cannot access `psaux' module\n" )); + error = CID_Err_Missing_Module; + goto Exit; + } + face->psaux = psaux; } diff --git a/src/sfnt/sfobjs.c b/src/sfnt/sfobjs.c index 44471f6b6..c86c34e83 100644 --- a/src/sfnt/sfobjs.c +++ b/src/sfnt/sfobjs.c @@ -452,7 +452,10 @@ { sfnt = (SFNT_Service)FT_Get_Module_Interface( library, "sfnt" ); if ( !sfnt ) - return SFNT_Err_Invalid_File_Format; + { + FT_ERROR(( "sfnt_init_face: cannot access `sfnt' module\n" )); + return SFNT_Err_Missing_Module; + } face->sfnt = sfnt; face->goto_table = sfnt->goto_table; diff --git a/src/truetype/ttobjs.c b/src/truetype/ttobjs.c index d77c3c421..f36b46fc1 100644 --- a/src/truetype/ttobjs.c +++ b/src/truetype/ttobjs.c @@ -494,9 +494,14 @@ library = ttface->driver->root.library; - sfnt = (SFNT_Service)FT_Get_Module_Interface( library, "sfnt" ); + + sfnt = (SFNT_Service)FT_Get_Module_Interface( library, "sfnt" ); if ( !sfnt ) - goto Bad_Format; + { + FT_ERROR(( "tt_face_init: cannot access `sfnt' module\n" )); + error = TT_Err_Missing_Module; + goto Exit; + } /* create input stream from resource */ if ( FT_STREAM_SEEK( 0 ) ) diff --git a/src/type1/t1afm.c b/src/type1/t1afm.c index 780ab33bf..1fff15d73 100644 --- a/src/type1/t1afm.c +++ b/src/type1/t1afm.c @@ -4,8 +4,7 @@ /* */ /* AFM support for Type 1 fonts (body). */ /* */ -/* Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, */ -/* 2010 by */ +/* Copyright 1996-2011 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -252,7 +251,7 @@ fi->Descender = t1_font->font_bbox.yMin; psaux = (PSAux_Service)( (T1_Face)t1_face )->psaux; - if ( psaux && psaux->afm_parser_funcs ) + if ( psaux->afm_parser_funcs ) { error = psaux->afm_parser_funcs->init( &parser, stream->memory, diff --git a/src/type1/t1objs.c b/src/type1/t1objs.c index 58632109c..5c8a7bcae 100644 --- a/src/type1/t1objs.c +++ b/src/type1/t1objs.c @@ -4,7 +4,7 @@ /* */ /* Type 1 objects manager (body). */ /* */ -/* Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 by */ +/* Copyright 1996-2009, 2011 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -313,6 +313,12 @@ face->psaux = FT_Get_Module_Interface( FT_FACE_LIBRARY( face ), "psaux" ); psaux = (PSAux_Service)face->psaux; + if ( !psaux ) + { + FT_ERROR(( "T1_Face_Init: cannot access `psaux' module\n" )); + error = T1_Err_Missing_Module; + goto Exit; + } face->pshinter = FT_Get_Module_Interface( FT_FACE_LIBRARY( face ), "pshinter" ); @@ -484,7 +490,7 @@ FT_Face root = &face->root; - if ( psnames && psaux ) + if ( psnames ) { FT_CharMapRec charmap; T1_CMap_Classes cmap_classes = psaux->t1_cmap_classes; diff --git a/src/type42/t42objs.c b/src/type42/t42objs.c index a5e0ee5e8..7cf8801f8 100644 --- a/src/type42/t42objs.c +++ b/src/type42/t42objs.c @@ -4,7 +4,7 @@ /* */ /* Type 42 objects manager (body). */ /* */ -/* Copyright 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 */ +/* Copyright 2002-2009, 2011 */ /* by Roberto Alameda. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -179,6 +179,12 @@ face->psaux = FT_Get_Module_Interface( FT_FACE_LIBRARY( face ), "psaux" ); psaux = (PSAux_Service)face->psaux; + if ( !psaux ) + { + FT_ERROR(( "T42_Face_Init: cannot access `psaux' module\n" )); + error = T42_Err_Missing_Module; + goto Exit; + } /* open the tokenizer, this will also check the font format */ error = T42_Open_Face( face ); @@ -321,7 +327,7 @@ root->face_flags |= FT_FACE_FLAG_VERTICAL; { - if ( psnames && psaux ) + if ( psnames ) { FT_CharMapRec charmap; T1_CMap_Classes cmap_classes = psaux->t1_cmap_classes; @@ -465,6 +471,12 @@ ttmodule = FT_Get_Module( FT_MODULE(driver)->library, "truetype" ); + if ( !ttmodule ) + { + FT_ERROR(( "T42_Driver_Init: cannot access `truetype' module\n" )); + return T42_Err_Missing_Module; + } + driver->ttclazz = (FT_Driver_Class)ttmodule->clazz; return T42_Err_Ok;