From 91a67478ec4a8ef0a7363f4728dd6c06be1ca92f Mon Sep 17 00:00:00 2001 From: Werner Lemberg Date: Wed, 17 Dec 2003 14:28:22 +0000 Subject: [PATCH] Add new function FT_Get_CMap_Language_ID to extract the language ID for TrueType/sfnt fonts. * include/freetype/internal/services/svttcmap.h: New file. * include/freetype/internal/ftserv.h (FT_SERVICE_TT_CMAP_H): Add svttcmap.h. * src/sfnt/sfdriver.c: Include ttcmap0.h. (tt_service_get_cmap_info): New service. (sfnt_services): Updated. * src/sfnt/ttcmap0.c (tt_cmap*_get_info): New functions. (tt_cmap*_class_rec): Add tt_cmap*_get_info members. (tt_get_cmap_info): New function. * src/sfnt/ttcmap0.h: Include FT_SERVICE_TT_CMAP_H. (TT_CMap_ClassRec): New field `get_cmap_info'. (tt_get_cmap_info): New declaration. * src/base/ftobjs.c: Include FT_SERVICE_TT_CMAP_H. (FT_Get_CMap_Language_ID): New function implementation. * include/freetype/tttables.h (FT_Get_CMap_Language_ID): New function declaration. --- ChangeLog | 29 ++++- include/freetype/internal/ftserv.h | 1 + include/freetype/internal/services/svttcmap.h | 77 +++++++++++ include/freetype/tttables.h | 21 +++ src/base/ftobjs.c | 23 ++++ src/sfnt/sfdriver.c | 13 ++ src/sfnt/ttcmap0.c | 123 +++++++++++++++++- src/sfnt/ttcmap0.h | 8 +- 8 files changed, 285 insertions(+), 10 deletions(-) create mode 100644 include/freetype/internal/services/svttcmap.h diff --git a/ChangeLog b/ChangeLog index dbd042332..9028eae9b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,28 @@ +2003-12-17 Masatake YAMATO + + Add new function FT_Get_CMap_Language_ID to extract the language ID + for TrueType/sfnt fonts. + + * include/freetype/internal/services/svttcmap.h: New file. + * include/freetype/internal/ftserv.h (FT_SERVICE_TT_CMAP_H): Add + svttcmap.h. + + * src/sfnt/sfdriver.c: Include ttcmap0.h. + (tt_service_get_cmap_info): New service. + (sfnt_services): Updated. + + * src/sfnt/ttcmap0.c (tt_cmap*_get_info): New functions. + (tt_cmap*_class_rec): Add tt_cmap*_get_info members. + (tt_get_cmap_info): New function. + * src/sfnt/ttcmap0.h: Include FT_SERVICE_TT_CMAP_H. + (TT_CMap_ClassRec): New field `get_cmap_info'. + (tt_get_cmap_info): New declaration. + + * src/base/ftobjs.c: Include FT_SERVICE_TT_CMAP_H. + (FT_Get_CMap_Language_ID): New function implementation. + * include/freetype/tttables.h (FT_Get_CMap_Language_ID): New + function declaration. + 2003-12-16 Werner Lemberg * src/sfnt/ttcmap.c, src/sfnt/ttcmap.h: Removed. Obsolete. @@ -15,7 +40,7 @@ TT_CMapDirRec, TT_CMapDirEntryRec, TT_CMap0, TT_CMap2SubHeaderRec, TT_CMap2Rec, TT_CMap4Segment, TT_CMap4Rec, TT_CMap6, TT_CMapGroupRec, TT_CMap8_12Rec, TT_CMap10Rec, TT_CharMap_Func, - TT_CharNext_Func, TT_CMapTableRec, TT_CharMapRec): Removed. + TT_CharNext_Func, TT_CMapTableRec, TT_CharMapRec): Removed. Obsolete. * src/cff/cffobjs.h (CFF_CharMapRec): Removed. Obsolete. @@ -6038,7 +6063,7 @@ (html_format): Replaced with ... (html_quote): New function. (html_quote0): New function. - (DocCode::dump_html: Small improvement. + (DocCode::dump_html): Small improvement. (DocParagraph::dump, DocBlock::html): Use html_quote0 and html_quote. * include/freetype/config/ftoption.h: Setting default options for diff --git a/include/freetype/internal/ftserv.h b/include/freetype/internal/ftserv.h index d77e1d5fa..e5ed8895b 100644 --- a/include/freetype/internal/ftserv.h +++ b/include/freetype/internal/ftserv.h @@ -248,6 +248,7 @@ FT_BEGIN_HEADER #define FT_SERVICE_SFNT_H #define FT_SERVICE_PFR_H #define FT_SERVICE_WINFNT_H +#define FT_SERVICE_TT_CMAP_H /* */ diff --git a/include/freetype/internal/services/svttcmap.h b/include/freetype/internal/services/svttcmap.h new file mode 100644 index 000000000..f92fcd0e2 --- /dev/null +++ b/include/freetype/internal/services/svttcmap.h @@ -0,0 +1,77 @@ +/***************************************************************************/ +/* */ +/* svsttcmap.h */ +/* */ +/* The FreeType TrueType/sfnt cmap extra information service. */ +/* */ +/* Copyright 2003 by */ +/* Masatake YAMATO, Redhat K.K. */ +/* */ +/* Copyright 2003 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + +/* Development of this service is support of + Information-technology Promotion Agency, Japan. */ + +#ifndef __SVTTCMAP_H__ +#define __SVTTCMAP_H__ + +#include FT_INTERNAL_SERVICE_H +#include FT_TRUETYPE_TABLES_H + + +FT_BEGIN_HEADER + + +#define FT_SERVICE_ID_TT_CMAP "tt-cmaps" + + + /*************************************************************************/ + /* */ + /* */ + /* TT_CMapInfo */ + /* */ + /* */ + /* A structure used to store TrueType/sfnt specific cmap information */ + /* which is not covered by the generic @FT_CharMap structure. This */ + /* structure can be accessed with the @FT_Get_TT_CMap_Info function. */ + /* */ + /* */ + /* language :: */ + /* The language ID used in Mac fonts. Definitions of values are in */ + /* freetype/ttnameid.h. */ + /* */ + typedef struct TT_CMapInfo_ + { + FT_ULong language; + + } TT_CMapInfo; + + + typedef FT_Error + (*TT_CMap_Info_GetFunc)( FT_CharMap charmap, + TT_CMapInfo *cmap_info ); + + + FT_DEFINE_SERVICE( TTCMaps ) + { + TT_CMap_Info_GetFunc get_cmap_info; + }; + + /* */ + + +FT_END_HEADER + +#endif /* __SVTTCMAP_H__ */ + + +/* END */ diff --git a/include/freetype/tttables.h b/include/freetype/tttables.h index 32f78be6d..22247913e 100644 --- a/include/freetype/tttables.h +++ b/include/freetype/tttables.h @@ -663,6 +663,27 @@ FT_BEGIN_HEADER FT_Byte* buffer, FT_ULong* length ); + + /*************************************************************************/ + /* */ + /* */ + /* FT_Get_CMap_Language_ID */ + /* */ + /* */ + /* Return TrueType/sfnt specific cmap language ID. Definitions of */ + /* language ID values are in freetype/ttnameid.h. */ + /* */ + /* */ + /* charmap :: */ + /* The target charmap. */ + /* */ + /* */ + /* The language ID of `charmap'. If `charmap' doesn't belong to a */ + /* TrueType/sfnt face, just return 0 as the default value. */ + /* */ + FT_EXPORT( FT_ULong ) + FT_Get_CMap_Language_ID( FT_CharMap charmap ); + /* */ diff --git a/src/base/ftobjs.c b/src/base/ftobjs.c index 70453c6ae..b84a37123 100644 --- a/src/base/ftobjs.c +++ b/src/base/ftobjs.c @@ -30,6 +30,7 @@ #include FT_SERVICE_SFNT_H #include FT_SERVICE_POSTSCRIPT_NAME_H #include FT_SERVICE_GLYPH_DICT_H +#include FT_SERVICE_TT_CMAP_H FT_BASE_DEF( FT_Pointer ) @@ -2508,6 +2509,28 @@ } + FT_EXPORT_DEF( FT_ULong ) + FT_Get_CMap_Language_ID( FT_CharMap charmap ) + { + FT_Service_TTCMaps service; + FT_Face face; + TT_CMapInfo cmap_info; + + + if ( !charmap || !charmap->face ) + return 0; + + face = charmap->face; + FT_FACE_FIND_SERVICE( face, service, TT_CMAP ); + if ( service == NULL ) + return 0; + if ( service->get_cmap_info( charmap, &cmap_info )) + return 0; + + return cmap_info.language; + } + + FT_EXPORT_DEF( FT_Error ) FT_Activate_Size( FT_Size size ) { diff --git a/src/sfnt/sfdriver.c b/src/sfnt/sfdriver.c index 685a3c6b0..c2bf948c7 100644 --- a/src/sfnt/sfdriver.c +++ b/src/sfnt/sfdriver.c @@ -34,9 +34,12 @@ #include "ttpost.h" #endif +#include "ttcmap0.h" + #include FT_SERVICE_GLYPH_DICT_H #include FT_SERVICE_POSTSCRIPT_NAME_H #include FT_SERVICE_SFNT_H +#include FT_SERVICE_TT_CMAP_H /* @@ -260,6 +263,15 @@ }; + /* + * TT CMAP INFO + * + */ + static const FT_Service_TTCMapsRec tt_service_get_cmap_info = + { + (TT_CMap_Info_GetFunc)tt_get_cmap_info + }; + /* * SERVICE LIST @@ -273,6 +285,7 @@ #ifdef TT_CONFIG_OPTION_POSTSCRIPT_NAMES { FT_SERVICE_ID_GLYPH_DICT, &sfnt_service_glyph_dict }, #endif + { FT_SERVICE_ID_TT_CMAP, &tt_service_get_cmap_info }, { NULL, NULL } }; diff --git a/src/sfnt/ttcmap0.c b/src/sfnt/ttcmap0.c index 4c9dadfbb..35f653262 100644 --- a/src/sfnt/ttcmap0.c +++ b/src/sfnt/ttcmap0.c @@ -144,6 +144,19 @@ } + FT_CALLBACK_DEF( FT_Error ) + tt_cmap0_get_info( TT_CMap cmap, + TT_CMapInfo *cmap_info ) + { + FT_Byte* p = cmap->data + 4; + + + cmap_info->language = (FT_ULong)TT_PEEK_USHORT( p ); + + return FT_Err_Ok; + } + + FT_CALLBACK_TABLE_DEF const TT_CMap_ClassRec tt_cmap0_class_rec = { @@ -156,7 +169,8 @@ (FT_CMap_CharNextFunc) tt_cmap0_char_next }, 0, - (TT_CMap_ValidateFunc) tt_cmap0_validate + (TT_CMap_ValidateFunc) tt_cmap0_validate, + (TT_CMap_Info_GetFunc) tt_cmap0_get_info }; #endif /* TT_CONFIG_CMAP_FORMAT_0 */ @@ -497,6 +511,19 @@ } + FT_CALLBACK_DEF( FT_Error ) + tt_cmap2_get_info( TT_CMap cmap, + TT_CMapInfo *cmap_info ) + { + FT_Byte* p = cmap->data + 4; + + + cmap_info->language = (FT_ULong)TT_PEEK_USHORT( p ); + + return FT_Err_Ok; + } + + FT_CALLBACK_TABLE_DEF const TT_CMap_ClassRec tt_cmap2_class_rec = { @@ -509,7 +536,8 @@ (FT_CMap_CharNextFunc) tt_cmap2_char_next }, 2, - (TT_CMap_ValidateFunc) tt_cmap2_validate + (TT_CMap_ValidateFunc) tt_cmap2_validate, + (TT_CMap_Info_GetFunc) tt_cmap2_get_info }; #endif /* TT_CONFIG_CMAP_FORMAT_2 */ @@ -1058,6 +1086,19 @@ } + FT_CALLBACK_DEF( FT_Error ) + tt_cmap4_get_info( TT_CMap cmap, + TT_CMapInfo *cmap_info ) + { + FT_Byte* p = cmap->data + 4; + + + cmap_info->language = (FT_ULong)TT_PEEK_USHORT( p ); + + return FT_Err_Ok; + } + + FT_CALLBACK_TABLE_DEF const TT_CMap_ClassRec tt_cmap4_class_rec = { @@ -1070,7 +1111,8 @@ (FT_CMap_CharNextFunc) tt_cmap4_char_next }, 4, - (TT_CMap_ValidateFunc) tt_cmap4_validate + (TT_CMap_ValidateFunc) tt_cmap4_validate, + (TT_CMap_Info_GetFunc) tt_cmap4_get_info }; #endif /* TT_CONFIG_CMAP_FORMAT_4 */ @@ -1202,6 +1244,19 @@ } + FT_CALLBACK_DEF( FT_Error ) + tt_cmap6_get_info( TT_CMap cmap, + TT_CMapInfo *cmap_info ) + { + FT_Byte* p = cmap->data + 4; + + + cmap_info->language = (FT_ULong)TT_PEEK_USHORT( p ); + + return FT_Err_Ok; + } + + FT_CALLBACK_TABLE_DEF const TT_CMap_ClassRec tt_cmap6_class_rec = { @@ -1214,7 +1269,8 @@ (FT_CMap_CharNextFunc) tt_cmap6_char_next }, 6, - (TT_CMap_ValidateFunc) tt_cmap6_validate + (TT_CMap_ValidateFunc) tt_cmap6_validate, + (TT_CMap_Info_GetFunc) tt_cmap6_get_info }; #endif /* TT_CONFIG_CMAP_FORMAT_6 */ @@ -1439,6 +1495,18 @@ } + FT_CALLBACK_DEF( FT_Error ) + tt_cmap8_get_info( TT_CMap cmap, + TT_CMapInfo *cmap_info ) + { + FT_Byte* p = cmap->data + 8; + + + cmap_info->language = (FT_ULong)TT_PEEK_ULONG( p ); + return FT_Err_Ok; + } + + FT_CALLBACK_TABLE_DEF const TT_CMap_ClassRec tt_cmap8_class_rec = { @@ -1451,7 +1519,8 @@ (FT_CMap_CharNextFunc) tt_cmap8_char_next }, 8, - (TT_CMap_ValidateFunc) tt_cmap8_validate + (TT_CMap_ValidateFunc) tt_cmap8_validate, + (TT_CMap_Info_GetFunc) tt_cmap8_get_info }; #endif /* TT_CONFIG_CMAP_FORMAT_8 */ @@ -1571,6 +1640,19 @@ } + FT_CALLBACK_DEF( FT_Error ) + tt_cmap10_get_info( TT_CMap cmap, + TT_CMapInfo *cmap_info ) + { + FT_Byte* p = cmap->data + 8; + + + cmap_info->language = (FT_ULong)TT_PEEK_ULONG( p ); + + return FT_Err_Ok; + } + + FT_CALLBACK_TABLE_DEF const TT_CMap_ClassRec tt_cmap10_class_rec = { @@ -1583,7 +1665,8 @@ (FT_CMap_CharNextFunc) tt_cmap10_char_next }, 10, - (TT_CMap_ValidateFunc) tt_cmap10_validate + (TT_CMap_ValidateFunc) tt_cmap10_validate, + (TT_CMap_Info_GetFunc) tt_cmap10_get_info }; #endif /* TT_CONFIG_CMAP_FORMAT_10 */ @@ -1741,6 +1824,19 @@ } + FT_CALLBACK_DEF( FT_Error ) + tt_cmap12_get_info( TT_CMap cmap, + TT_CMapInfo *cmap_info ) + { + FT_Byte* p = cmap->data + 8; + + + cmap_info->language = (FT_ULong)TT_PEEK_ULONG( p ); + + return FT_Err_Ok; + } + + FT_CALLBACK_TABLE_DEF const TT_CMap_ClassRec tt_cmap12_class_rec = { @@ -1753,7 +1849,8 @@ (FT_CMap_CharNextFunc) tt_cmap12_char_next }, 12, - (TT_CMap_ValidateFunc) tt_cmap12_validate + (TT_CMap_ValidateFunc) tt_cmap12_validate, + (TT_CMap_Info_GetFunc) tt_cmap12_get_info }; @@ -1875,4 +1972,16 @@ } + FT_LOCAL( FT_Error ) + tt_get_cmap_info( FT_CharMap charmap, + TT_CMapInfo *cmap_info ) + { + FT_CMap cmap = (FT_CMap)charmap; + TT_CMap_Class clazz = (TT_CMap_Class)cmap->clazz; + + + return clazz->get_cmap_info( charmap, cmap_info ); + } + + /* END */ diff --git a/src/sfnt/ttcmap0.h b/src/sfnt/ttcmap0.h index ff1276e09..28f5bac62 100644 --- a/src/sfnt/ttcmap0.h +++ b/src/sfnt/ttcmap0.h @@ -23,7 +23,7 @@ #include #include FT_INTERNAL_TRUETYPE_TYPES_H #include FT_INTERNAL_OBJECTS_H - +#include FT_SERVICE_TT_CMAP_H FT_BEGIN_HEADER @@ -46,6 +46,7 @@ FT_BEGIN_HEADER FT_CMap_ClassRec clazz; FT_UInt format; TT_CMap_ValidateFunc validate; + TT_CMap_Info_GetFunc get_cmap_info; } TT_CMap_ClassRec; @@ -65,6 +66,11 @@ FT_BEGIN_HEADER FT_LOCAL( FT_Error ) tt_face_build_cmaps( TT_Face face ); + /* used in tt-cmaps service */ + FT_LOCAL( FT_Error ) + tt_get_cmap_info( FT_CharMap charmap, + TT_CMapInfo *cmap_info ); + FT_END_HEADER