From 07e818170f146053c876f6138e492ee79614e000 Mon Sep 17 00:00:00 2001 From: Werner Lemberg Date: Wed, 11 Mar 2009 21:29:54 +0000 Subject: [PATCH] Extend CID service functions to handle CID-keyed CFFs as CID fonts. * include/freetype/ftcid.h (FT_Get_CID_Is_Internally_CID_keyed, FT_Get_CID_From_Glyph_Index): New functions. * include/freetype/internal/services/svcid.h (FT_CID_GetIsInternallyCIDKeyedFunc, FT_CID_GetCIDFromGlyphIndexFunc): New function typedefs. (CID Service): Use them. * src/base/ftcid.c: Include FT_CID_H. (FT_Get_CID_Is_Internally_CID_keyed, FT_Get_CID_From_Glyph_Index): New functions. * src/cff/cffdrivr.c (cff_get_is_cid, cff_get_cid_from_glyph_index): New functions. (cff_service_cid_info): Add them. * src/cff/cffload.c (cff_font_load): Don't free `font->charset.sids' -- it is needed for access as a CID-keyed font. It gets deleted later on. * src/cid/cidriver.c (cid_get_is_cid, cid_get_cid_from_glyph_index): New functions. (cid_service_cid_info): Add them. * docs/CHANGES: Updated. --- ChangeLog | 29 +++++++++ docs/CHANGES | 10 +++- include/freetype/ftcid.h | 70 +++++++++++++++++++++- include/freetype/internal/services/svcid.h | 11 +++- src/base/ftcid.c | 56 ++++++++++++++++- src/cff/cffdrivr.c | 67 ++++++++++++++++++++- src/cff/cffload.c | 5 +- src/cid/cidriver.c | 35 ++++++++++- 8 files changed, 273 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index 08b4a3c7e..33a7a8d2e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,32 @@ +2009-03-11 Michael Toftdal + + Extend CID service functions to handle CID-keyed CFFs as CID fonts. + + * include/freetype/ftcid.h (FT_Get_CID_Is_Internally_CID_keyed, + FT_Get_CID_From_Glyph_Index): New functions. + + * include/freetype/internal/services/svcid.h + (FT_CID_GetIsInternallyCIDKeyedFunc, + FT_CID_GetCIDFromGlyphIndexFunc): New function typedefs. + (CID Service): Use them. + + * src/base/ftcid.c: Include FT_CID_H. + (FT_Get_CID_Is_Internally_CID_keyed, FT_Get_CID_From_Glyph_Index): + New functions. + + * src/cff/cffdrivr.c (cff_get_is_cid, cff_get_cid_from_glyph_index): + New functions. + (cff_service_cid_info): Add them. + * src/cff/cffload.c (cff_font_load): Don't free `font->charset.sids' + -- it is needed for access as a CID-keyed font. It gets deleted + later on. + + * src/cid/cidriver.c (cid_get_is_cid, cid_get_cid_from_glyph_index): + New functions. + (cid_service_cid_info): Add them. + + * docs/CHANGES: Updated. + 2009-03-11 Bram Tassyns Fix Savannah bug #25597. diff --git a/docs/CHANGES b/docs/CHANGES index d8b722d3b..9eb68c292 100644 --- a/docs/CHANGES +++ b/docs/CHANGES @@ -39,7 +39,15 @@ CHANGES BETWEEN 2.3.9 and 2.3.8 - Composite SFNT bitmaps are now handled correctly. - II. MISCELLANEOUS + II. IMPORTANT CHANGES + + - The new functions `FT_Get_CID_Is_Internally_CID_keyed' and + `FT_Get_CID_From_Glyph_Index' can be used to access CID-keyed + CFF fonts via CID values. This code has been contributed by + Michael Toftdal. + + + III. MISCELLANEOUS - `FT_Outline_Get_InsideBorder' returns FT_STROKER_BORDER_RIGHT for empty outlines. This was incorrectly documented. diff --git a/include/freetype/ftcid.h b/include/freetype/ftcid.h index 02df2a035..b38e5d2bc 100644 --- a/include/freetype/ftcid.h +++ b/include/freetype/ftcid.h @@ -4,7 +4,7 @@ /* */ /* FreeType API for accessing CID font information (specification). */ /* */ -/* Copyright 2007 by Dereg Clegg. */ +/* Copyright 2007, 2009 by Dereg Clegg, Michael Toftdal. */ /* */ /* This file is part of the FreeType project, and may only be used, */ /* modified, and distributed under the terms of the FreeType project */ @@ -88,6 +88,74 @@ FT_BEGIN_HEADER const char* *ordering, FT_Int *supplement); + + /********************************************************************** + * + * @function: + * FT_Get_CID_Is_Internally_CID_Keyed + * + * @description: + * Retrieve the type of the input face, CID keyed or not. In + * constrast to the @FT_IS_CID_KEYED macro this function returns + * successfully also for CID-keyed fonts in an SNFT wrapper. + * + * @input: + * face :: + * A handle to the input face. + * + * @output: + * is_cid :: + * The type of the face as an @FT_Bool. + * + * @return: + * FreeType error code. 0~means success. + * + * @note: + * This function only works with CID faces and OpenType fonts, + * returning an error otherwise. + * + * @since: + * 2.3.9 + */ + FT_EXPORT( FT_Error ) + FT_Get_CID_Is_Internally_CID_Keyed( FT_Face face, + FT_Bool *is_cid ); + + + /********************************************************************** + * + * @function: + * FT_Get_CID_From_Glyph_Index + * + * @description: + * Retrieve the CID of the input glyph index. + * + * @input: + * face :: + * A handle to the input face. + * + * glyph_index :: + * The input glyph index. + * + * @output: + * cid :: + * The CID as an FT_UInt. + * + * @return: + * FreeType error code. 0~means success. + * + * @note: + * This function only works with CID faces and OpenType fonts, + * returning an error otherwise. + * + * @since: + * 2.3.9 + */ + FT_EXPORT( FT_Error ) + FT_Get_CID_From_Glyph_Index( FT_Face face, + FT_UInt glyph_index, + FT_UInt *cid ); + /* */ FT_END_HEADER diff --git a/include/freetype/internal/services/svcid.h b/include/freetype/internal/services/svcid.h index 47fef62ed..2e391f288 100644 --- a/include/freetype/internal/services/svcid.h +++ b/include/freetype/internal/services/svcid.h @@ -4,7 +4,7 @@ /* */ /* The FreeType CID font services (specification). */ /* */ -/* Copyright 2007 by Derek Clegg. */ +/* Copyright 2007, 2009 by Derek Clegg, Michael Toftdal. */ /* */ /* This file is part of the FreeType project, and may only be used, */ /* modified, and distributed under the terms of the FreeType project */ @@ -31,10 +31,19 @@ FT_BEGIN_HEADER const char* *registry, const char* *ordering, FT_Int *supplement ); + typedef FT_Error + (*FT_CID_GetIsInternallyCIDKeyedFunc)( FT_Face face, + FT_Bool *is_cid ); + typedef FT_Error + (*FT_CID_GetCIDFromGlyphIndexFunc)( FT_Face face, + FT_UInt glyph_index, + FT_UInt *cid ); FT_DEFINE_SERVICE( CID ) { FT_CID_GetRegistryOrderingSupplementFunc get_ros; + FT_CID_GetIsInternallyCIDKeyedFunc get_is_cid; + FT_CID_GetCIDFromGlyphIndexFunc get_cid_from_glyph_index; }; /* */ diff --git a/src/base/ftcid.c b/src/base/ftcid.c index 5a8b50ff2..733aae147 100644 --- a/src/base/ftcid.c +++ b/src/base/ftcid.c @@ -4,7 +4,7 @@ /* */ /* FreeType API for accessing CID font information. */ /* */ -/* Copyright 2007 by Derek Clegg. */ +/* Copyright 2007, 2009 by Derek Clegg, Michael Toftdal. */ /* */ /* This file is part of the FreeType project, and may only be used, */ /* modified, and distributed under the terms of the FreeType project */ @@ -16,6 +16,7 @@ #include +#include FT_CID_H #include FT_INTERNAL_OBJECTS_H #include FT_SERVICE_CID_H @@ -60,4 +61,57 @@ } + FT_EXPORT_DEF( FT_Error ) + FT_Get_CID_Is_Internally_CID_Keyed( FT_Face face, + FT_Bool *is_cid ) + { + FT_Error error = FT_Err_Invalid_Argument; + FT_Bool ic = 0; + + + if ( face ) + { + FT_Service_CID service; + + + FT_FACE_FIND_SERVICE( face, service, CID ); + + if ( service && service->get_is_cid ) + error = service->get_is_cid( face, &ic); + } + + if ( is_cid ) + *is_cid = ic; + + return error; + } + + + FT_EXPORT_DEF( FT_Error ) + FT_Get_CID_From_Glyph_Index( FT_Face face, + FT_UInt glyph_index, + FT_UInt *cid ) + { + FT_Error error = FT_Err_Invalid_Argument; + FT_UInt c = 0; + + + if ( face ) + { + FT_Service_CID service; + + + FT_FACE_FIND_SERVICE( face, service, CID ); + + if ( service && service->get_cid_from_glyph_index ) + error = service->get_cid_from_glyph_index( face, glyph_index, &c); + } + + if ( cid ) + *cid = c; + + return error; + } + + /* END */ diff --git a/src/cff/cffdrivr.c b/src/cff/cffdrivr.c index 286c0b332..8d385f7fa 100644 --- a/src/cff/cffdrivr.c +++ b/src/cff/cffdrivr.c @@ -506,9 +506,74 @@ } + static FT_Error + cff_get_is_cid( CFF_Face face, + FT_Bool *is_cid ) + { + FT_Error error = CFF_Err_Ok; + CFF_Font cff = (CFF_Font)face->extra.data; + + + *is_cid = 0; + + if ( cff ) + { + CFF_FontRecDict dict = &cff->top_font.font_dict; + + + if ( dict->cid_registry != 0xFFFFU ) + *is_cid = 1; + } + + return error; + } + + + static FT_Error + cff_get_cid_from_glyph_index( CFF_Face face, + FT_UInt glyph_index, + FT_UInt *cid ) + { + FT_Error error = CFF_Err_Ok; + CFF_Font cff; + + + cff = (CFF_Font)face->extra.data; + + if ( cff ) + { + FT_UInt c; + CFF_FontRecDict dict = &cff->top_font.font_dict; + + + if ( dict->cid_registry == 0xFFFFU ) + { + error = CFF_Err_Invalid_Argument; + goto Fail; + } + + if ( glyph_index > cff->num_glyphs ) + { + error = CFF_Err_Invalid_Argument; + goto Fail; + } + + c = cff->charset.sids[glyph_index]; + + if ( cid ) + *cid = c; + } + + Fail: + return error; + } + + static const FT_Service_CIDRec cff_service_cid_info = { - (FT_CID_GetRegistryOrderingSupplementFunc)cff_get_ros + (FT_CID_GetRegistryOrderingSupplementFunc)cff_get_ros, + (FT_CID_GetIsInternallyCIDKeyedFunc) cff_get_is_cid, + (FT_CID_GetCIDFromGlyphIndexFunc) cff_get_cid_from_glyph_index }; diff --git a/src/cff/cffload.c b/src/cff/cffload.c index 0178c8180..4a58189ca 100644 --- a/src/cff/cffload.c +++ b/src/cff/cffload.c @@ -4,7 +4,7 @@ /* */ /* OpenType and CFF data/program tables loader (body). */ /* */ -/* Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 by */ +/* Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -1540,9 +1540,6 @@ if ( error ) goto Exit; } - else - /* CID-keyed fonts only need CIDs */ - FT_FREE( font->charset.sids ); } /* get the font name (/CIDFontName for CID-keyed fonts, */ diff --git a/src/cid/cidriver.c b/src/cid/cidriver.c index f650ee1d9..b41d5d6f0 100644 --- a/src/cid/cidriver.c +++ b/src/cid/cidriver.c @@ -122,9 +122,42 @@ } + static FT_Error + cid_get_is_cid( CID_Face face, + FT_Bool *is_cid ) + { + FT_Error error = CID_Err_Ok; + FT_UNUSED( face ); + + + if ( is_cid ) + *is_cid = 1; /* cid driver is only used for CID keyed fonts */ + + return error; + } + + + static FT_Error + cid_get_cid_from_glyph_index( CID_Face face, + FT_UInt glyph_index, + FT_UInt *cid ) + { + FT_Error error = CID_Err_Ok; + FT_UNUSED( face ); + + + if ( cid ) + *cid = glyph_index; /* identity mapping */ + + return error; + } + + static const FT_Service_CIDRec cid_service_cid_info = { - (FT_CID_GetRegistryOrderingSupplementFunc)cid_get_ros + (FT_CID_GetRegistryOrderingSupplementFunc)cid_get_ros, + (FT_CID_GetIsInternallyCIDKeyedFunc) cid_get_is_cid, + (FT_CID_GetCIDFromGlyphIndexFunc) cid_get_cid_from_glyph_index };