cffcmap.c

Go to the documentation of this file.
00001 /***************************************************************************/
00002 /*                                                                         */
00003 /*  cffcmap.c                                                              */
00004 /*                                                                         */
00005 /*    CFF character mapping table (cmap) support (body).                   */
00006 /*                                                                         */
00007 /*  Copyright 2002, 2003, 2004, 2005, 2006, 2007 by                        */
00008 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
00009 /*                                                                         */
00010 /*  This file is part of the FreeType project, and may only be used,       */
00011 /*  modified, and distributed under the terms of the FreeType project      */
00012 /*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
00013 /*  this file you indicate that you have read the license and              */
00014 /*  understand and accept it fully.                                        */
00015 /*                                                                         */
00016 /***************************************************************************/
00017 
00018 
00019 #include "cffcmap.h"
00020 #include "cffload.h"
00021 
00022 #include "cfferrs.h"
00023 
00024 
00025   /*************************************************************************/
00026   /*************************************************************************/
00027   /*****                                                               *****/
00028   /*****           CFF STANDARD (AND EXPERT) ENCODING CMAPS            *****/
00029   /*****                                                               *****/
00030   /*************************************************************************/
00031   /*************************************************************************/
00032 
00033   FT_CALLBACK_DEF( FT_Error )
00034   cff_cmap_encoding_init( CFF_CMapStd  cmap )
00035   {
00036     TT_Face       face     = (TT_Face)FT_CMAP_FACE( cmap );
00037     CFF_Font      cff      = (CFF_Font)face->extra.data;
00038     CFF_Encoding  encoding = &cff->encoding;
00039 
00040 
00041     cmap->gids  = encoding->codes;
00042 
00043     return 0;
00044   }
00045 
00046 
00047   FT_CALLBACK_DEF( void )
00048   cff_cmap_encoding_done( CFF_CMapStd  cmap )
00049   {
00050     cmap->gids  = NULL;
00051   }
00052 
00053 
00054   FT_CALLBACK_DEF( FT_UInt )
00055   cff_cmap_encoding_char_index( CFF_CMapStd  cmap,
00056                                 FT_UInt32    char_code )
00057   {
00058     FT_UInt  result = 0;
00059 
00060 
00061     if ( char_code < 256 )
00062       result = cmap->gids[char_code];
00063 
00064     return result;
00065   }
00066 
00067 
00068   FT_CALLBACK_DEF( FT_UInt32 )
00069   cff_cmap_encoding_char_next( CFF_CMapStd   cmap,
00070                                FT_UInt32    *pchar_code )
00071   {
00072     FT_UInt    result    = 0;
00073     FT_UInt32  char_code = *pchar_code;
00074 
00075 
00076     *pchar_code = 0;
00077 
00078     if ( char_code < 255 )
00079     {
00080       FT_UInt  code = (FT_UInt)(char_code + 1);
00081 
00082 
00083       for (;;)
00084       {
00085         if ( code >= 256 )
00086           break;
00087 
00088         result = cmap->gids[code];
00089         if ( result != 0 )
00090         {
00091           *pchar_code = code;
00092           break;
00093         }
00094 
00095         code++;
00096       }
00097     }
00098     return result;
00099   }
00100 
00101 
00102   FT_DEFINE_CMAP_CLASS(cff_cmap_encoding_class_rec,
00103     sizeof ( CFF_CMapStdRec ),
00104 
00105     (FT_CMap_InitFunc)     cff_cmap_encoding_init,
00106     (FT_CMap_DoneFunc)     cff_cmap_encoding_done,
00107     (FT_CMap_CharIndexFunc)cff_cmap_encoding_char_index,
00108     (FT_CMap_CharNextFunc) cff_cmap_encoding_char_next,
00109 
00110     NULL, NULL, NULL, NULL, NULL
00111   )
00112 
00113 
00114   /*************************************************************************/
00115   /*************************************************************************/
00116   /*****                                                               *****/
00117   /*****              CFF SYNTHETIC UNICODE ENCODING CMAP              *****/
00118   /*****                                                               *****/
00119   /*************************************************************************/
00120   /*************************************************************************/
00121 
00122   FT_CALLBACK_DEF( const char* )
00123   cff_sid_to_glyph_name( TT_Face   face,
00124                          FT_UInt   idx )
00125   {
00126     CFF_Font            cff     = (CFF_Font)face->extra.data;
00127     CFF_Charset         charset = &cff->charset;
00128     FT_Service_PsCMaps  psnames = (FT_Service_PsCMaps)cff->psnames;
00129     FT_UInt             sid     = charset->sids[idx];
00130 
00131 
00132     return cff_index_get_sid_string( &cff->string_index, sid, psnames );
00133   }
00134 
00135 
00136   FT_CALLBACK_DEF( void )
00137   cff_sid_free_glyph_name( TT_Face      face,
00138                            const char*  gname )
00139   {
00140     FT_Memory  memory = FT_FACE_MEMORY( face );
00141 
00142 
00143     FT_FREE( gname );
00144   }
00145 
00146 
00147   FT_CALLBACK_DEF( FT_Error )
00148   cff_cmap_unicode_init( PS_Unicodes  unicodes )
00149   {
00150     TT_Face             face    = (TT_Face)FT_CMAP_FACE( unicodes );
00151     FT_Memory           memory  = FT_FACE_MEMORY( face );
00152     CFF_Font            cff     = (CFF_Font)face->extra.data;
00153     CFF_Charset         charset = &cff->charset;
00154     FT_Service_PsCMaps  psnames = (FT_Service_PsCMaps)cff->psnames;
00155 
00156 
00157     /* can't build Unicode map for CID-keyed font */
00158     if ( !charset->sids )
00159       return CFF_Err_Invalid_Argument;
00160 
00161     return psnames->unicodes_init( memory,
00162                                    unicodes,
00163                                    cff->num_glyphs,
00164                                    (PS_GetGlyphNameFunc)&cff_sid_to_glyph_name,
00165                                    (PS_FreeGlyphNameFunc)&cff_sid_free_glyph_name,
00166                                    (FT_Pointer)face );
00167   }
00168 
00169 
00170   FT_CALLBACK_DEF( void )
00171   cff_cmap_unicode_done( PS_Unicodes  unicodes )
00172   {
00173     FT_Face    face   = FT_CMAP_FACE( unicodes );
00174     FT_Memory  memory = FT_FACE_MEMORY( face );
00175 
00176 
00177     FT_FREE( unicodes->maps );
00178     unicodes->num_maps = 0;
00179   }
00180 
00181 
00182   FT_CALLBACK_DEF( FT_UInt )
00183   cff_cmap_unicode_char_index( PS_Unicodes  unicodes,
00184                                FT_UInt32    char_code )
00185   {
00186     TT_Face             face    = (TT_Face)FT_CMAP_FACE( unicodes );
00187     CFF_Font            cff     = (CFF_Font)face->extra.data;
00188     FT_Service_PsCMaps  psnames = (FT_Service_PsCMaps)cff->psnames;
00189 
00190 
00191     return psnames->unicodes_char_index( unicodes, char_code );
00192   }
00193 
00194 
00195   FT_CALLBACK_DEF( FT_UInt32 )
00196   cff_cmap_unicode_char_next( PS_Unicodes  unicodes,
00197                               FT_UInt32   *pchar_code )
00198   {
00199     TT_Face             face    = (TT_Face)FT_CMAP_FACE( unicodes );
00200     CFF_Font            cff     = (CFF_Font)face->extra.data;
00201     FT_Service_PsCMaps  psnames = (FT_Service_PsCMaps)cff->psnames;
00202 
00203 
00204     return psnames->unicodes_char_next( unicodes, pchar_code );
00205   }
00206 
00207 
00208   FT_DEFINE_CMAP_CLASS(cff_cmap_unicode_class_rec,
00209     sizeof ( PS_UnicodesRec ),
00210 
00211     (FT_CMap_InitFunc)     cff_cmap_unicode_init,
00212     (FT_CMap_DoneFunc)     cff_cmap_unicode_done,
00213     (FT_CMap_CharIndexFunc)cff_cmap_unicode_char_index,
00214     (FT_CMap_CharNextFunc) cff_cmap_unicode_char_next,
00215 
00216     NULL, NULL, NULL, NULL, NULL
00217   )
00218 
00219 /* END */

Generated on Tue Jul 5 14:13:46 2011 for ROOT_528-00b_version by  doxygen 1.5.1