| 1 | /***************************************************************************/ | 
|---|
| 2 | /*                                                                         */ | 
|---|
| 3 | /*  cffcmap.c                                                              */ | 
|---|
| 4 | /*                                                                         */ | 
|---|
| 5 | /*    CFF character mapping table (cmap) support (body).                   */ | 
|---|
| 6 | /*                                                                         */ | 
|---|
| 7 | /*  Copyright 2002-2018 by                                                 */ | 
|---|
| 8 | /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */ | 
|---|
| 9 | /*                                                                         */ | 
|---|
| 10 | /*  This file is part of the FreeType project, and may only be used,       */ | 
|---|
| 11 | /*  modified, and distributed under the terms of the FreeType project      */ | 
|---|
| 12 | /*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */ | 
|---|
| 13 | /*  this file you indicate that you have read the license and              */ | 
|---|
| 14 | /*  understand and accept it fully.                                        */ | 
|---|
| 15 | /*                                                                         */ | 
|---|
| 16 | /***************************************************************************/ | 
|---|
| 17 |  | 
|---|
| 18 |  | 
|---|
| 19 | #include <ft2build.h> | 
|---|
| 20 | #include FT_INTERNAL_DEBUG_H | 
|---|
| 21 | #include "cffcmap.h" | 
|---|
| 22 | #include "cffload.h" | 
|---|
| 23 |  | 
|---|
| 24 | #include "cfferrs.h" | 
|---|
| 25 |  | 
|---|
| 26 |  | 
|---|
| 27 | /*************************************************************************/ | 
|---|
| 28 | /*************************************************************************/ | 
|---|
| 29 | /*****                                                               *****/ | 
|---|
| 30 | /*****           CFF STANDARD (AND EXPERT) ENCODING CMAPS            *****/ | 
|---|
| 31 | /*****                                                               *****/ | 
|---|
| 32 | /*************************************************************************/ | 
|---|
| 33 | /*************************************************************************/ | 
|---|
| 34 |  | 
|---|
| 35 | FT_CALLBACK_DEF( FT_Error ) | 
|---|
| 36 | cff_cmap_encoding_init( CFF_CMapStd  cmap, | 
|---|
| 37 | FT_Pointer   pointer ) | 
|---|
| 38 | { | 
|---|
| 39 | TT_Face       face     = (TT_Face)FT_CMAP_FACE( cmap ); | 
|---|
| 40 | CFF_Font      cff      = (CFF_Font)face->extra.data; | 
|---|
| 41 | CFF_Encoding  encoding = &cff->encoding; | 
|---|
| 42 |  | 
|---|
| 43 | FT_UNUSED( pointer ); | 
|---|
| 44 |  | 
|---|
| 45 |  | 
|---|
| 46 | cmap->gids  = encoding->codes; | 
|---|
| 47 |  | 
|---|
| 48 | return 0; | 
|---|
| 49 | } | 
|---|
| 50 |  | 
|---|
| 51 |  | 
|---|
| 52 | FT_CALLBACK_DEF( void ) | 
|---|
| 53 | cff_cmap_encoding_done( CFF_CMapStd  cmap ) | 
|---|
| 54 | { | 
|---|
| 55 | cmap->gids  = NULL; | 
|---|
| 56 | } | 
|---|
| 57 |  | 
|---|
| 58 |  | 
|---|
| 59 | FT_CALLBACK_DEF( FT_UInt ) | 
|---|
| 60 | cff_cmap_encoding_char_index( CFF_CMapStd  cmap, | 
|---|
| 61 | FT_UInt32    char_code ) | 
|---|
| 62 | { | 
|---|
| 63 | FT_UInt  result = 0; | 
|---|
| 64 |  | 
|---|
| 65 |  | 
|---|
| 66 | if ( char_code < 256 ) | 
|---|
| 67 | result = cmap->gids[char_code]; | 
|---|
| 68 |  | 
|---|
| 69 | return result; | 
|---|
| 70 | } | 
|---|
| 71 |  | 
|---|
| 72 |  | 
|---|
| 73 | FT_CALLBACK_DEF( FT_UInt32 ) | 
|---|
| 74 | cff_cmap_encoding_char_next( CFF_CMapStd   cmap, | 
|---|
| 75 | FT_UInt32    *pchar_code ) | 
|---|
| 76 | { | 
|---|
| 77 | FT_UInt    result    = 0; | 
|---|
| 78 | FT_UInt32  char_code = *pchar_code; | 
|---|
| 79 |  | 
|---|
| 80 |  | 
|---|
| 81 | *pchar_code = 0; | 
|---|
| 82 |  | 
|---|
| 83 | if ( char_code < 255 ) | 
|---|
| 84 | { | 
|---|
| 85 | FT_UInt  code = (FT_UInt)(char_code + 1); | 
|---|
| 86 |  | 
|---|
| 87 |  | 
|---|
| 88 | for (;;) | 
|---|
| 89 | { | 
|---|
| 90 | if ( code >= 256 ) | 
|---|
| 91 | break; | 
|---|
| 92 |  | 
|---|
| 93 | result = cmap->gids[code]; | 
|---|
| 94 | if ( result != 0 ) | 
|---|
| 95 | { | 
|---|
| 96 | *pchar_code = code; | 
|---|
| 97 | break; | 
|---|
| 98 | } | 
|---|
| 99 |  | 
|---|
| 100 | code++; | 
|---|
| 101 | } | 
|---|
| 102 | } | 
|---|
| 103 | return result; | 
|---|
| 104 | } | 
|---|
| 105 |  | 
|---|
| 106 |  | 
|---|
| 107 | FT_DEFINE_CMAP_CLASS( | 
|---|
| 108 | cff_cmap_encoding_class_rec, | 
|---|
| 109 |  | 
|---|
| 110 | sizeof ( CFF_CMapStdRec ), | 
|---|
| 111 |  | 
|---|
| 112 | (FT_CMap_InitFunc)     cff_cmap_encoding_init,        /* init       */ | 
|---|
| 113 | (FT_CMap_DoneFunc)     cff_cmap_encoding_done,        /* done       */ | 
|---|
| 114 | (FT_CMap_CharIndexFunc)cff_cmap_encoding_char_index,  /* char_index */ | 
|---|
| 115 | (FT_CMap_CharNextFunc) cff_cmap_encoding_char_next,   /* char_next  */ | 
|---|
| 116 |  | 
|---|
| 117 | (FT_CMap_CharVarIndexFunc)    NULL,  /* char_var_index   */ | 
|---|
| 118 | (FT_CMap_CharVarIsDefaultFunc)NULL,  /* char_var_default */ | 
|---|
| 119 | (FT_CMap_VariantListFunc)     NULL,  /* variant_list     */ | 
|---|
| 120 | (FT_CMap_CharVariantListFunc) NULL,  /* charvariant_list */ | 
|---|
| 121 | (FT_CMap_VariantCharListFunc) NULL   /* variantchar_list */ | 
|---|
| 122 | ) | 
|---|
| 123 |  | 
|---|
| 124 |  | 
|---|
| 125 | /*************************************************************************/ | 
|---|
| 126 | /*************************************************************************/ | 
|---|
| 127 | /*****                                                               *****/ | 
|---|
| 128 | /*****              CFF SYNTHETIC UNICODE ENCODING CMAP              *****/ | 
|---|
| 129 | /*****                                                               *****/ | 
|---|
| 130 | /*************************************************************************/ | 
|---|
| 131 | /*************************************************************************/ | 
|---|
| 132 |  | 
|---|
| 133 | FT_CALLBACK_DEF( const char* ) | 
|---|
| 134 | cff_sid_to_glyph_name( TT_Face  face, | 
|---|
| 135 | FT_UInt  idx ) | 
|---|
| 136 | { | 
|---|
| 137 | CFF_Font     cff     = (CFF_Font)face->extra.data; | 
|---|
| 138 | CFF_Charset  charset = &cff->charset; | 
|---|
| 139 | FT_UInt      sid     = charset->sids[idx]; | 
|---|
| 140 |  | 
|---|
| 141 |  | 
|---|
| 142 | return cff_index_get_sid_string( cff, sid ); | 
|---|
| 143 | } | 
|---|
| 144 |  | 
|---|
| 145 |  | 
|---|
| 146 | FT_CALLBACK_DEF( FT_Error ) | 
|---|
| 147 | cff_cmap_unicode_init( PS_Unicodes  unicodes, | 
|---|
| 148 | FT_Pointer   pointer ) | 
|---|
| 149 | { | 
|---|
| 150 | TT_Face             face    = (TT_Face)FT_CMAP_FACE( unicodes ); | 
|---|
| 151 | FT_Memory           memory  = FT_FACE_MEMORY( face ); | 
|---|
| 152 | CFF_Font            cff     = (CFF_Font)face->extra.data; | 
|---|
| 153 | CFF_Charset         charset = &cff->charset; | 
|---|
| 154 | FT_Service_PsCMaps  psnames = (FT_Service_PsCMaps)cff->psnames; | 
|---|
| 155 |  | 
|---|
| 156 | FT_UNUSED( pointer ); | 
|---|
| 157 |  | 
|---|
| 158 |  | 
|---|
| 159 | /* can't build Unicode map for CID-keyed font */ | 
|---|
| 160 | /* because we don't know glyph names.         */ | 
|---|
| 161 | if ( !charset->sids ) | 
|---|
| 162 | return FT_THROW( No_Unicode_Glyph_Name ); | 
|---|
| 163 |  | 
|---|
| 164 | return psnames->unicodes_init( memory, | 
|---|
| 165 | unicodes, | 
|---|
| 166 | cff->num_glyphs, | 
|---|
| 167 | (PS_GetGlyphNameFunc)&cff_sid_to_glyph_name, | 
|---|
| 168 | (PS_FreeGlyphNameFunc)NULL, | 
|---|
| 169 | (FT_Pointer)face ); | 
|---|
| 170 | } | 
|---|
| 171 |  | 
|---|
| 172 |  | 
|---|
| 173 | FT_CALLBACK_DEF( void ) | 
|---|
| 174 | cff_cmap_unicode_done( PS_Unicodes  unicodes ) | 
|---|
| 175 | { | 
|---|
| 176 | FT_Face    face   = FT_CMAP_FACE( unicodes ); | 
|---|
| 177 | FT_Memory  memory = FT_FACE_MEMORY( face ); | 
|---|
| 178 |  | 
|---|
| 179 |  | 
|---|
| 180 | FT_FREE( unicodes->maps ); | 
|---|
| 181 | unicodes->num_maps = 0; | 
|---|
| 182 | } | 
|---|
| 183 |  | 
|---|
| 184 |  | 
|---|
| 185 | FT_CALLBACK_DEF( FT_UInt ) | 
|---|
| 186 | cff_cmap_unicode_char_index( PS_Unicodes  unicodes, | 
|---|
| 187 | FT_UInt32    char_code ) | 
|---|
| 188 | { | 
|---|
| 189 | TT_Face             face    = (TT_Face)FT_CMAP_FACE( unicodes ); | 
|---|
| 190 | CFF_Font            cff     = (CFF_Font)face->extra.data; | 
|---|
| 191 | FT_Service_PsCMaps  psnames = (FT_Service_PsCMaps)cff->psnames; | 
|---|
| 192 |  | 
|---|
| 193 |  | 
|---|
| 194 | return psnames->unicodes_char_index( unicodes, char_code ); | 
|---|
| 195 | } | 
|---|
| 196 |  | 
|---|
| 197 |  | 
|---|
| 198 | FT_CALLBACK_DEF( FT_UInt32 ) | 
|---|
| 199 | cff_cmap_unicode_char_next( PS_Unicodes  unicodes, | 
|---|
| 200 | FT_UInt32   *pchar_code ) | 
|---|
| 201 | { | 
|---|
| 202 | TT_Face             face    = (TT_Face)FT_CMAP_FACE( unicodes ); | 
|---|
| 203 | CFF_Font            cff     = (CFF_Font)face->extra.data; | 
|---|
| 204 | FT_Service_PsCMaps  psnames = (FT_Service_PsCMaps)cff->psnames; | 
|---|
| 205 |  | 
|---|
| 206 |  | 
|---|
| 207 | return psnames->unicodes_char_next( unicodes, pchar_code ); | 
|---|
| 208 | } | 
|---|
| 209 |  | 
|---|
| 210 |  | 
|---|
| 211 | FT_DEFINE_CMAP_CLASS( | 
|---|
| 212 | cff_cmap_unicode_class_rec, | 
|---|
| 213 |  | 
|---|
| 214 | sizeof ( PS_UnicodesRec ), | 
|---|
| 215 |  | 
|---|
| 216 | (FT_CMap_InitFunc)     cff_cmap_unicode_init,        /* init       */ | 
|---|
| 217 | (FT_CMap_DoneFunc)     cff_cmap_unicode_done,        /* done       */ | 
|---|
| 218 | (FT_CMap_CharIndexFunc)cff_cmap_unicode_char_index,  /* char_index */ | 
|---|
| 219 | (FT_CMap_CharNextFunc) cff_cmap_unicode_char_next,   /* char_next  */ | 
|---|
| 220 |  | 
|---|
| 221 | (FT_CMap_CharVarIndexFunc)    NULL,  /* char_var_index   */ | 
|---|
| 222 | (FT_CMap_CharVarIsDefaultFunc)NULL,  /* char_var_default */ | 
|---|
| 223 | (FT_CMap_VariantListFunc)     NULL,  /* variant_list     */ | 
|---|
| 224 | (FT_CMap_CharVariantListFunc) NULL,  /* charvariant_list */ | 
|---|
| 225 | (FT_CMap_VariantCharListFunc) NULL   /* variantchar_list */ | 
|---|
| 226 | ) | 
|---|
| 227 |  | 
|---|
| 228 |  | 
|---|
| 229 | /* END */ | 
|---|
| 230 |  | 
|---|