Edit

kc3-lang/freetype/src/cff/cffcmap.c

Branch :

  • Show log

    Commit

  • Author : Werner Lemberg
    Date : 2007-10-15 17:21:32
    Hash : 9a966b7d
    Message : Add support for cmap type 14. * devel/ftoption.h, include/freetype/config/ftoption.h (TT_CONFIG_CMAP_FORMAT_14): New macro. * include/freetype/internal/ftobjs.h (FT_CMap_CharVarIndexFunc, FT_CMap_CharVarIsDefaultFunc, FT_CMap_VariantListFunc, FT_CMap_CharVariantListFunc, FT_CMap_VariantCharListFunc): New support function prototypes. (FT_CMap_ClassRec): Add them. Update all users. * include/freetype/ttnameid.h (TT_APPLE_ID_VARIANT_SELECTOR): New macro. * include/freetype/freetype.h (FT_Get_Char_Variant_Index, FT_Get_Char_Variant_IsDefault, FT_Get_Variant_Selectors, FT_Get_Variants_Of_Char, FT_Get_Chars_Of_Variant): New API functions. * src/base/ftobjs.c (find_variant_selector_charmap): New auxiliary function. (FT_Set_Charmap): Disallow cmaps of type 14. (FT_Get_Char_Variant_Index, FT_Get_Char_Variant_IsDefault, FT_Get_Variant_Selectors, FT_Get_Variants_Of_Char, FT_Get_Chars_Of_Variant): New API functions. * src/sfnt/ttcmap.c (TT_PEEK_UINT24, TT_NEXT_UINT24): New macros. (TT_CMap14Rec, tt_cmap14_init, tt_cmap14_validate, tt_cmap14_char_index, tt_cmap14_char_next, tt_cmap14_get_info, tt_cmap14_char_map_def_binary, tt_cmap14_char_map_nondef_binary, tt_cmap14_find_variant, tt_cmap14_char_var_index, tt_cmap14_char_var_isdefault, tt_cmap14_variants, tt_cmap14_char_variants, tt_cmap14_def_char_count, tt_cmap14_get_def_chars, tt_cmap14_get_nondef_chars, tt_cmap14_variant_chars, tt_cmap14_class_rec): New functions and structures for cmap 14 support. (tt_cmap_classes): Register tt_cmap14_class_rec. (tt_face_build_cmaps): One more error message. * docs/CHANGES: Mention cmap 14 support.

  • src/cff/cffcmap.c
  • /***************************************************************************/
    /*                                                                         */
    /*  cffcmap.c                                                              */
    /*                                                                         */
    /*    CFF character mapping table (cmap) support (body).                   */
    /*                                                                         */
    /*  Copyright 2002, 2003, 2004, 2005, 2006, 2007 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.                                        */
    /*                                                                         */
    /***************************************************************************/
    
    
    #include "cffcmap.h"
    #include "cffload.h"
    
    #include "cfferrs.h"
    
    
      /*************************************************************************/
      /*************************************************************************/
      /*****                                                               *****/
      /*****           CFF STANDARD (AND EXPERT) ENCODING CMAPS            *****/
      /*****                                                               *****/
      /*************************************************************************/
      /*************************************************************************/
    
      FT_CALLBACK_DEF( FT_Error )
      cff_cmap_encoding_init( CFF_CMapStd  cmap )
      {
        TT_Face       face     = (TT_Face)FT_CMAP_FACE( cmap );
        CFF_Font      cff      = (CFF_Font)face->extra.data;
        CFF_Encoding  encoding = &cff->encoding;
    
    
        cmap->gids  = encoding->codes;
    
        return 0;
      }
    
    
      FT_CALLBACK_DEF( void )
      cff_cmap_encoding_done( CFF_CMapStd  cmap )
      {
        cmap->gids  = NULL;
      }
    
    
      FT_CALLBACK_DEF( FT_UInt )
      cff_cmap_encoding_char_index( CFF_CMapStd  cmap,
                                    FT_UInt32    char_code )
      {
        FT_UInt  result = 0;
    
    
        if ( char_code < 256 )
          result = cmap->gids[char_code];
    
        return result;
      }
    
    
      FT_CALLBACK_DEF( FT_UInt )
      cff_cmap_encoding_char_next( CFF_CMapStd   cmap,
                                   FT_UInt32    *pchar_code )
      {
        FT_UInt    result    = 0;
        FT_UInt32  char_code = *pchar_code;
    
    
        *pchar_code = 0;
    
        if ( char_code < 255 )
        {
          FT_UInt  code = (FT_UInt)(char_code + 1);
    
    
          for (;;)
          {
            if ( code >= 256 )
              break;
    
            result = cmap->gids[code];
            if ( result != 0 )
            {
              *pchar_code = code;
              break;
            }
    
            code++;
          }
        }
        return result;
      }
    
    
      FT_CALLBACK_TABLE_DEF const FT_CMap_ClassRec
      cff_cmap_encoding_class_rec =
      {
        sizeof ( CFF_CMapStdRec ),
    
        (FT_CMap_InitFunc)     cff_cmap_encoding_init,
        (FT_CMap_DoneFunc)     cff_cmap_encoding_done,
        (FT_CMap_CharIndexFunc)cff_cmap_encoding_char_index,
        (FT_CMap_CharNextFunc) cff_cmap_encoding_char_next,
    
        NULL, NULL, NULL, NULL, NULL
      };
    
    
      /*************************************************************************/
      /*************************************************************************/
      /*****                                                               *****/
      /*****              CFF SYNTHETIC UNICODE ENCODING CMAP              *****/
      /*****                                                               *****/
      /*************************************************************************/
      /*************************************************************************/
    
      FT_CALLBACK_DEF( const char* )
      cff_sid_to_glyph_name( TT_Face   face,
                             FT_UInt   idx )
      {
        CFF_Font            cff     = (CFF_Font)face->extra.data;
        CFF_Charset         charset = &cff->charset;
        FT_Service_PsCMaps  psnames = (FT_Service_PsCMaps)cff->psnames;
        FT_UInt             sid     = charset->sids[idx];
    
    
        return cff_index_get_sid_string( &cff->string_index, sid, psnames );
      }
    
    
      FT_CALLBACK_DEF( void )
      cff_sid_free_glyph_name( TT_Face      face,
                               const char*  gname )
      {
        FT_Memory  memory = FT_FACE_MEMORY( face );
    
    
        FT_FREE( gname );
      }
    
    
      FT_CALLBACK_DEF( FT_Error )
      cff_cmap_unicode_init( PS_Unicodes  unicodes )
      {
        TT_Face             face    = (TT_Face)FT_CMAP_FACE( unicodes );
        FT_Memory           memory  = FT_FACE_MEMORY( face );
        CFF_Font            cff     = (CFF_Font)face->extra.data;
        CFF_Charset         charset = &cff->charset;
        FT_Service_PsCMaps  psnames = (FT_Service_PsCMaps)cff->psnames;
    
    
        /* can't build Unicode map for CID-keyed font */
        if ( !charset->sids )
          return CFF_Err_Invalid_Argument;
    
        return psnames->unicodes_init( memory,
                                       unicodes,
                                       cff->num_glyphs,
                                       (PS_GetGlyphNameFunc)&cff_sid_to_glyph_name,
                                       (PS_FreeGlyphNameFunc)&cff_sid_free_glyph_name,
                                       (FT_Pointer)face );
      }
    
    
      FT_CALLBACK_DEF( void )
      cff_cmap_unicode_done( PS_Unicodes  unicodes )
      {
        FT_Face    face   = FT_CMAP_FACE( unicodes );
        FT_Memory  memory = FT_FACE_MEMORY( face );
    
    
        FT_FREE( unicodes->maps );
        unicodes->num_maps = 0;
      }
    
    
      FT_CALLBACK_DEF( FT_UInt )
      cff_cmap_unicode_char_index( PS_Unicodes  unicodes,
                                   FT_UInt32    char_code )
      {
        TT_Face             face    = (TT_Face)FT_CMAP_FACE( unicodes );
        CFF_Font            cff     = (CFF_Font)face->extra.data;
        FT_Service_PsCMaps  psnames = (FT_Service_PsCMaps)cff->psnames;
    
    
        return psnames->unicodes_char_index( unicodes, char_code );
      }
    
    
      FT_CALLBACK_DEF( FT_UInt )
      cff_cmap_unicode_char_next( PS_Unicodes  unicodes,
                                  FT_UInt32   *pchar_code )
      {
        TT_Face             face    = (TT_Face)FT_CMAP_FACE( unicodes );
        CFF_Font            cff     = (CFF_Font)face->extra.data;
        FT_Service_PsCMaps  psnames = (FT_Service_PsCMaps)cff->psnames;
    
    
        return psnames->unicodes_char_next( unicodes, pchar_code );
      }
    
    
      FT_CALLBACK_TABLE_DEF const FT_CMap_ClassRec
      cff_cmap_unicode_class_rec =
      {
        sizeof ( PS_UnicodesRec ),
    
        (FT_CMap_InitFunc)     cff_cmap_unicode_init,
        (FT_CMap_DoneFunc)     cff_cmap_unicode_done,
        (FT_CMap_CharIndexFunc)cff_cmap_unicode_char_index,
        (FT_CMap_CharNextFunc) cff_cmap_unicode_char_next,
    
        NULL, NULL, NULL, NULL, NULL
      };
    
    
    /* END */