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.
This commit is contained in:
Werner Lemberg 2009-03-11 21:29:54 +00:00
parent 9318df0cad
commit 07e818170f
8 changed files with 273 additions and 10 deletions

View File

@ -1,3 +1,32 @@
2009-03-11 Michael Toftdal <toftdal@gmail.com>
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 <bramt@enfocus.be>
Fix Savannah bug #25597.

View File

@ -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.

View File

@ -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

View File

@ -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;
};
/* */

View File

@ -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 <ft2build.h>
#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 */

View File

@ -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
};

View File

@ -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, */

View File

@ -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
};