/src/freetype/src/psaux/t1cmap.c

https://bitbucket.org/cabalistic/ogredeps/ · C · 341 lines · 210 code · 91 blank · 40 comment · 16 complexity · dde05c830cfb768b621720d6de284ace MD5 · raw file

  1. /***************************************************************************/
  2. /* */
  3. /* t1cmap.c */
  4. /* */
  5. /* Type 1 character map support (body). */
  6. /* */
  7. /* Copyright 2002, 2003, 2006, 2007, 2012 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. #include "t1cmap.h"
  18. #include FT_INTERNAL_DEBUG_H
  19. #include "psauxerr.h"
  20. /*************************************************************************/
  21. /*************************************************************************/
  22. /***** *****/
  23. /***** TYPE1 STANDARD (AND EXPERT) ENCODING CMAPS *****/
  24. /***** *****/
  25. /*************************************************************************/
  26. /*************************************************************************/
  27. static void
  28. t1_cmap_std_init( T1_CMapStd cmap,
  29. FT_Int is_expert )
  30. {
  31. T1_Face face = (T1_Face)FT_CMAP_FACE( cmap );
  32. FT_Service_PsCMaps psnames = (FT_Service_PsCMaps)face->psnames;
  33. cmap->num_glyphs = face->type1.num_glyphs;
  34. cmap->glyph_names = (const char* const*)face->type1.glyph_names;
  35. cmap->sid_to_string = psnames->adobe_std_strings;
  36. cmap->code_to_sid = is_expert ? psnames->adobe_expert_encoding
  37. : psnames->adobe_std_encoding;
  38. FT_ASSERT( cmap->code_to_sid != NULL );
  39. }
  40. FT_CALLBACK_DEF( void )
  41. t1_cmap_std_done( T1_CMapStd cmap )
  42. {
  43. cmap->num_glyphs = 0;
  44. cmap->glyph_names = NULL;
  45. cmap->sid_to_string = NULL;
  46. cmap->code_to_sid = NULL;
  47. }
  48. FT_CALLBACK_DEF( FT_UInt )
  49. t1_cmap_std_char_index( T1_CMapStd cmap,
  50. FT_UInt32 char_code )
  51. {
  52. FT_UInt result = 0;
  53. if ( char_code < 256 )
  54. {
  55. FT_UInt code, n;
  56. const char* glyph_name;
  57. /* convert character code to Adobe SID string */
  58. code = cmap->code_to_sid[char_code];
  59. glyph_name = cmap->sid_to_string( code );
  60. /* look for the corresponding glyph name */
  61. for ( n = 0; n < cmap->num_glyphs; n++ )
  62. {
  63. const char* gname = cmap->glyph_names[n];
  64. if ( gname && gname[0] == glyph_name[0] &&
  65. ft_strcmp( gname, glyph_name ) == 0 )
  66. {
  67. result = n;
  68. break;
  69. }
  70. }
  71. }
  72. return result;
  73. }
  74. FT_CALLBACK_DEF( FT_UInt32 )
  75. t1_cmap_std_char_next( T1_CMapStd cmap,
  76. FT_UInt32 *pchar_code )
  77. {
  78. FT_UInt result = 0;
  79. FT_UInt32 char_code = *pchar_code + 1;
  80. while ( char_code < 256 )
  81. {
  82. result = t1_cmap_std_char_index( cmap, char_code );
  83. if ( result != 0 )
  84. goto Exit;
  85. char_code++;
  86. }
  87. char_code = 0;
  88. Exit:
  89. *pchar_code = char_code;
  90. return result;
  91. }
  92. FT_CALLBACK_DEF( FT_Error )
  93. t1_cmap_standard_init( T1_CMapStd cmap )
  94. {
  95. t1_cmap_std_init( cmap, 0 );
  96. return 0;
  97. }
  98. FT_CALLBACK_TABLE_DEF const FT_CMap_ClassRec
  99. t1_cmap_standard_class_rec =
  100. {
  101. sizeof ( T1_CMapStdRec ),
  102. (FT_CMap_InitFunc) t1_cmap_standard_init,
  103. (FT_CMap_DoneFunc) t1_cmap_std_done,
  104. (FT_CMap_CharIndexFunc)t1_cmap_std_char_index,
  105. (FT_CMap_CharNextFunc) t1_cmap_std_char_next,
  106. NULL, NULL, NULL, NULL, NULL
  107. };
  108. FT_CALLBACK_DEF( FT_Error )
  109. t1_cmap_expert_init( T1_CMapStd cmap )
  110. {
  111. t1_cmap_std_init( cmap, 1 );
  112. return 0;
  113. }
  114. FT_CALLBACK_TABLE_DEF const FT_CMap_ClassRec
  115. t1_cmap_expert_class_rec =
  116. {
  117. sizeof ( T1_CMapStdRec ),
  118. (FT_CMap_InitFunc) t1_cmap_expert_init,
  119. (FT_CMap_DoneFunc) t1_cmap_std_done,
  120. (FT_CMap_CharIndexFunc)t1_cmap_std_char_index,
  121. (FT_CMap_CharNextFunc) t1_cmap_std_char_next,
  122. NULL, NULL, NULL, NULL, NULL
  123. };
  124. /*************************************************************************/
  125. /*************************************************************************/
  126. /***** *****/
  127. /***** TYPE1 CUSTOM ENCODING CMAP *****/
  128. /***** *****/
  129. /*************************************************************************/
  130. /*************************************************************************/
  131. FT_CALLBACK_DEF( FT_Error )
  132. t1_cmap_custom_init( T1_CMapCustom cmap )
  133. {
  134. T1_Face face = (T1_Face)FT_CMAP_FACE( cmap );
  135. T1_Encoding encoding = &face->type1.encoding;
  136. cmap->first = encoding->code_first;
  137. cmap->count = (FT_UInt)( encoding->code_last - cmap->first );
  138. cmap->indices = encoding->char_index;
  139. FT_ASSERT( cmap->indices != NULL );
  140. FT_ASSERT( encoding->code_first <= encoding->code_last );
  141. return 0;
  142. }
  143. FT_CALLBACK_DEF( void )
  144. t1_cmap_custom_done( T1_CMapCustom cmap )
  145. {
  146. cmap->indices = NULL;
  147. cmap->first = 0;
  148. cmap->count = 0;
  149. }
  150. FT_CALLBACK_DEF( FT_UInt )
  151. t1_cmap_custom_char_index( T1_CMapCustom cmap,
  152. FT_UInt32 char_code )
  153. {
  154. FT_UInt result = 0;
  155. if ( ( char_code >= cmap->first ) &&
  156. ( char_code < ( cmap->first + cmap->count ) ) )
  157. result = cmap->indices[char_code];
  158. return result;
  159. }
  160. FT_CALLBACK_DEF( FT_UInt32 )
  161. t1_cmap_custom_char_next( T1_CMapCustom cmap,
  162. FT_UInt32 *pchar_code )
  163. {
  164. FT_UInt result = 0;
  165. FT_UInt32 char_code = *pchar_code;
  166. ++char_code;
  167. if ( char_code < cmap->first )
  168. char_code = cmap->first;
  169. for ( ; char_code < ( cmap->first + cmap->count ); char_code++ )
  170. {
  171. result = cmap->indices[char_code];
  172. if ( result != 0 )
  173. goto Exit;
  174. }
  175. char_code = 0;
  176. Exit:
  177. *pchar_code = char_code;
  178. return result;
  179. }
  180. FT_CALLBACK_TABLE_DEF const FT_CMap_ClassRec
  181. t1_cmap_custom_class_rec =
  182. {
  183. sizeof ( T1_CMapCustomRec ),
  184. (FT_CMap_InitFunc) t1_cmap_custom_init,
  185. (FT_CMap_DoneFunc) t1_cmap_custom_done,
  186. (FT_CMap_CharIndexFunc)t1_cmap_custom_char_index,
  187. (FT_CMap_CharNextFunc) t1_cmap_custom_char_next,
  188. NULL, NULL, NULL, NULL, NULL
  189. };
  190. /*************************************************************************/
  191. /*************************************************************************/
  192. /***** *****/
  193. /***** TYPE1 SYNTHETIC UNICODE ENCODING CMAP *****/
  194. /***** *****/
  195. /*************************************************************************/
  196. /*************************************************************************/
  197. FT_CALLBACK_DEF( const char * )
  198. psaux_get_glyph_name( T1_Face face,
  199. FT_UInt idx )
  200. {
  201. return face->type1.glyph_names[idx];
  202. }
  203. FT_CALLBACK_DEF( FT_Error )
  204. t1_cmap_unicode_init( PS_Unicodes unicodes )
  205. {
  206. T1_Face face = (T1_Face)FT_CMAP_FACE( unicodes );
  207. FT_Memory memory = FT_FACE_MEMORY( face );
  208. FT_Service_PsCMaps psnames = (FT_Service_PsCMaps)face->psnames;
  209. return psnames->unicodes_init( memory,
  210. unicodes,
  211. face->type1.num_glyphs,
  212. (PS_GetGlyphNameFunc)&psaux_get_glyph_name,
  213. (PS_FreeGlyphNameFunc)NULL,
  214. (FT_Pointer)face );
  215. }
  216. FT_CALLBACK_DEF( void )
  217. t1_cmap_unicode_done( PS_Unicodes unicodes )
  218. {
  219. FT_Face face = FT_CMAP_FACE( unicodes );
  220. FT_Memory memory = FT_FACE_MEMORY( face );
  221. FT_FREE( unicodes->maps );
  222. unicodes->num_maps = 0;
  223. }
  224. FT_CALLBACK_DEF( FT_UInt )
  225. t1_cmap_unicode_char_index( PS_Unicodes unicodes,
  226. FT_UInt32 char_code )
  227. {
  228. T1_Face face = (T1_Face)FT_CMAP_FACE( unicodes );
  229. FT_Service_PsCMaps psnames = (FT_Service_PsCMaps)face->psnames;
  230. return psnames->unicodes_char_index( unicodes, char_code );
  231. }
  232. FT_CALLBACK_DEF( FT_UInt32 )
  233. t1_cmap_unicode_char_next( PS_Unicodes unicodes,
  234. FT_UInt32 *pchar_code )
  235. {
  236. T1_Face face = (T1_Face)FT_CMAP_FACE( unicodes );
  237. FT_Service_PsCMaps psnames = (FT_Service_PsCMaps)face->psnames;
  238. return psnames->unicodes_char_next( unicodes, pchar_code );
  239. }
  240. FT_CALLBACK_TABLE_DEF const FT_CMap_ClassRec
  241. t1_cmap_unicode_class_rec =
  242. {
  243. sizeof ( PS_UnicodesRec ),
  244. (FT_CMap_InitFunc) t1_cmap_unicode_init,
  245. (FT_CMap_DoneFunc) t1_cmap_unicode_done,
  246. (FT_CMap_CharIndexFunc)t1_cmap_unicode_char_index,
  247. (FT_CMap_CharNextFunc) t1_cmap_unicode_char_next,
  248. NULL, NULL, NULL, NULL, NULL
  249. };
  250. /* END */