/src/compiler/android-ndk/jni/freetype/src/cff/cffcmap.c

http://ftk.googlecode.com/ · C · 219 lines · 127 code · 60 blank · 32 comment · 7 complexity · fc1c9f3af1e21f94bf9252732c4c7977 MD5 · raw file

  1. /***************************************************************************/
  2. /* */
  3. /* cffcmap.c */
  4. /* */
  5. /* CFF character mapping table (cmap) support (body). */
  6. /* */
  7. /* Copyright 2002, 2003, 2004, 2005, 2006, 2007 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 "cffcmap.h"
  18. #include "cffload.h"
  19. #include "cfferrs.h"
  20. /*************************************************************************/
  21. /*************************************************************************/
  22. /***** *****/
  23. /***** CFF STANDARD (AND EXPERT) ENCODING CMAPS *****/
  24. /***** *****/
  25. /*************************************************************************/
  26. /*************************************************************************/
  27. FT_CALLBACK_DEF( FT_Error )
  28. cff_cmap_encoding_init( CFF_CMapStd cmap )
  29. {
  30. TT_Face face = (TT_Face)FT_CMAP_FACE( cmap );
  31. CFF_Font cff = (CFF_Font)face->extra.data;
  32. CFF_Encoding encoding = &cff->encoding;
  33. cmap->gids = encoding->codes;
  34. return 0;
  35. }
  36. FT_CALLBACK_DEF( void )
  37. cff_cmap_encoding_done( CFF_CMapStd cmap )
  38. {
  39. cmap->gids = NULL;
  40. }
  41. FT_CALLBACK_DEF( FT_UInt )
  42. cff_cmap_encoding_char_index( CFF_CMapStd cmap,
  43. FT_UInt32 char_code )
  44. {
  45. FT_UInt result = 0;
  46. if ( char_code < 256 )
  47. result = cmap->gids[char_code];
  48. return result;
  49. }
  50. FT_CALLBACK_DEF( FT_UInt32 )
  51. cff_cmap_encoding_char_next( CFF_CMapStd cmap,
  52. FT_UInt32 *pchar_code )
  53. {
  54. FT_UInt result = 0;
  55. FT_UInt32 char_code = *pchar_code;
  56. *pchar_code = 0;
  57. if ( char_code < 255 )
  58. {
  59. FT_UInt code = (FT_UInt)(char_code + 1);
  60. for (;;)
  61. {
  62. if ( code >= 256 )
  63. break;
  64. result = cmap->gids[code];
  65. if ( result != 0 )
  66. {
  67. *pchar_code = code;
  68. break;
  69. }
  70. code++;
  71. }
  72. }
  73. return result;
  74. }
  75. FT_DEFINE_CMAP_CLASS(cff_cmap_encoding_class_rec,
  76. sizeof ( CFF_CMapStdRec ),
  77. (FT_CMap_InitFunc) cff_cmap_encoding_init,
  78. (FT_CMap_DoneFunc) cff_cmap_encoding_done,
  79. (FT_CMap_CharIndexFunc)cff_cmap_encoding_char_index,
  80. (FT_CMap_CharNextFunc) cff_cmap_encoding_char_next,
  81. NULL, NULL, NULL, NULL, NULL
  82. )
  83. /*************************************************************************/
  84. /*************************************************************************/
  85. /***** *****/
  86. /***** CFF SYNTHETIC UNICODE ENCODING CMAP *****/
  87. /***** *****/
  88. /*************************************************************************/
  89. /*************************************************************************/
  90. FT_CALLBACK_DEF( const char* )
  91. cff_sid_to_glyph_name( TT_Face face,
  92. FT_UInt idx )
  93. {
  94. CFF_Font cff = (CFF_Font)face->extra.data;
  95. CFF_Charset charset = &cff->charset;
  96. FT_Service_PsCMaps psnames = (FT_Service_PsCMaps)cff->psnames;
  97. FT_UInt sid = charset->sids[idx];
  98. return cff_index_get_sid_string( &cff->string_index, sid, psnames );
  99. }
  100. FT_CALLBACK_DEF( void )
  101. cff_sid_free_glyph_name( TT_Face face,
  102. const char* gname )
  103. {
  104. FT_Memory memory = FT_FACE_MEMORY( face );
  105. FT_FREE( gname );
  106. }
  107. FT_CALLBACK_DEF( FT_Error )
  108. cff_cmap_unicode_init( PS_Unicodes unicodes )
  109. {
  110. TT_Face face = (TT_Face)FT_CMAP_FACE( unicodes );
  111. FT_Memory memory = FT_FACE_MEMORY( face );
  112. CFF_Font cff = (CFF_Font)face->extra.data;
  113. CFF_Charset charset = &cff->charset;
  114. FT_Service_PsCMaps psnames = (FT_Service_PsCMaps)cff->psnames;
  115. /* can't build Unicode map for CID-keyed font */
  116. if ( !charset->sids )
  117. return CFF_Err_Invalid_Argument;
  118. return psnames->unicodes_init( memory,
  119. unicodes,
  120. cff->num_glyphs,
  121. (PS_GetGlyphNameFunc)&cff_sid_to_glyph_name,
  122. (PS_FreeGlyphNameFunc)&cff_sid_free_glyph_name,
  123. (FT_Pointer)face );
  124. }
  125. FT_CALLBACK_DEF( void )
  126. cff_cmap_unicode_done( PS_Unicodes unicodes )
  127. {
  128. FT_Face face = FT_CMAP_FACE( unicodes );
  129. FT_Memory memory = FT_FACE_MEMORY( face );
  130. FT_FREE( unicodes->maps );
  131. unicodes->num_maps = 0;
  132. }
  133. FT_CALLBACK_DEF( FT_UInt )
  134. cff_cmap_unicode_char_index( PS_Unicodes unicodes,
  135. FT_UInt32 char_code )
  136. {
  137. TT_Face face = (TT_Face)FT_CMAP_FACE( unicodes );
  138. CFF_Font cff = (CFF_Font)face->extra.data;
  139. FT_Service_PsCMaps psnames = (FT_Service_PsCMaps)cff->psnames;
  140. return psnames->unicodes_char_index( unicodes, char_code );
  141. }
  142. FT_CALLBACK_DEF( FT_UInt32 )
  143. cff_cmap_unicode_char_next( PS_Unicodes unicodes,
  144. FT_UInt32 *pchar_code )
  145. {
  146. TT_Face face = (TT_Face)FT_CMAP_FACE( unicodes );
  147. CFF_Font cff = (CFF_Font)face->extra.data;
  148. FT_Service_PsCMaps psnames = (FT_Service_PsCMaps)cff->psnames;
  149. return psnames->unicodes_char_next( unicodes, pchar_code );
  150. }
  151. FT_DEFINE_CMAP_CLASS(cff_cmap_unicode_class_rec,
  152. sizeof ( PS_UnicodesRec ),
  153. (FT_CMap_InitFunc) cff_cmap_unicode_init,
  154. (FT_CMap_DoneFunc) cff_cmap_unicode_done,
  155. (FT_CMap_CharIndexFunc)cff_cmap_unicode_char_index,
  156. (FT_CMap_CharNextFunc) cff_cmap_unicode_char_next,
  157. NULL, NULL, NULL, NULL, NULL
  158. )
  159. /* END */