< prev index next >

src/java.desktop/share/native/libfreetype/src/cff/cffobjs.c

Print this page


   1 /***************************************************************************/
   2 /*                                                                         */
   3 /*  cffobjs.c                                                              */
   4 /*                                                                         */
   5 /*    OpenType objects manager (body).                                     */
   6 /*                                                                         */
   7 /*  Copyright 1996-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 
  21 #include FT_INTERNAL_DEBUG_H
  22 #include FT_INTERNAL_CALC_H
  23 #include FT_INTERNAL_STREAM_H
  24 #include FT_ERRORS_H
  25 #include FT_TRUETYPE_IDS_H
  26 #include FT_TRUETYPE_TAGS_H
  27 #include FT_INTERNAL_SFNT_H
  28 #include FT_DRIVER_H
  29 
  30 #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
  31 #include FT_MULTIPLE_MASTERS_H
  32 #include FT_SERVICE_MULTIPLE_MASTERS_H
  33 #include FT_SERVICE_METRICS_VARIATIONS_H
  34 #endif
  35 
  36 #include FT_INTERNAL_CFF_OBJECTS_TYPES_H
  37 #include "cffobjs.h"
  38 #include "cffload.h"
  39 #include "cffcmap.h"
  40 #include "cffpic.h"
  41 
  42 #include "cfferrs.h"
  43 
  44 #include FT_INTERNAL_POSTSCRIPT_AUX_H
  45 #include FT_SERVICE_CFF_TABLE_LOAD_H
  46 
  47 
  48   /*************************************************************************/
  49   /*                                                                       */
  50   /* The macro FT_COMPONENT is used in trace mode.  It is an implicit      */
  51   /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log  */
  52   /* messages during execution.                                            */
  53   /*                                                                       */
  54 #undef  FT_COMPONENT
  55 #define FT_COMPONENT  trace_cffobjs
  56 
  57 
  58   /*************************************************************************/
  59   /*                                                                       */
  60   /*                            SIZE FUNCTIONS                             */
  61   /*                                                                       */
  62   /*************************************************************************/
  63 
  64 
  65   static PSH_Globals_Funcs
  66   cff_size_get_globals_funcs( CFF_Size  size )
  67   {
  68     CFF_Face          face     = (CFF_Face)size->root.face;
  69     CFF_Font          font     = (CFF_Font)face->extra.data;
  70     PSHinter_Service  pshinter = font->pshinter;
  71     FT_Module         module;
  72 
  73 
  74     module = FT_Get_Module( size->root.face->driver->root.library,
  75                             "pshinter" );
  76     return ( module && pshinter && pshinter->get_globals_funcs )
  77            ? pshinter->get_globals_funcs( module )
  78            : 0;
  79   }
  80 
  81 
  82   FT_LOCAL_DEF( void )


 324         if ( top_upm != sub_upm )
 325         {
 326           x_scale = FT_MulDiv( size->metrics.x_scale, top_upm, sub_upm );
 327           y_scale = FT_MulDiv( size->metrics.y_scale, top_upm, sub_upm );
 328         }
 329         else
 330         {
 331           x_scale = size->metrics.x_scale;
 332           y_scale = size->metrics.y_scale;
 333         }
 334 
 335         funcs->set_scale( internal->subfonts[i - 1],
 336                           x_scale, y_scale, 0, 0 );
 337       }
 338     }
 339 
 340     return FT_Err_Ok;
 341   }
 342 
 343 
 344   /*************************************************************************/
 345   /*                                                                       */
 346   /*                            SLOT  FUNCTIONS                            */
 347   /*                                                                       */
 348   /*************************************************************************/
 349 
 350   FT_LOCAL_DEF( void )
 351   cff_slot_done( FT_GlyphSlot  slot )
 352   {
 353     slot->internal->glyph_hints = NULL;
 354   }
 355 
 356 
 357   FT_LOCAL_DEF( FT_Error )
 358   cff_slot_init( FT_GlyphSlot  slot )
 359   {
 360     CFF_Face          face     = (CFF_Face)slot->face;
 361     CFF_Font          font     = (CFF_Font)face->extra.data;
 362     PSHinter_Service  pshinter = font->pshinter;
 363 
 364 
 365     if ( pshinter )
 366     {
 367       FT_Module  module;
 368 
 369 
 370       module = FT_Get_Module( slot->face->driver->root.library,
 371                               "pshinter" );
 372       if ( module )
 373       {
 374         T2_Hints_Funcs  funcs;
 375 
 376 
 377         funcs = pshinter->get_t2_funcs( module );
 378         slot->internal->glyph_hints = (void*)funcs;
 379       }
 380     }
 381 
 382     return FT_Err_Ok;
 383   }
 384 
 385 
 386   /*************************************************************************/
 387   /*                                                                       */
 388   /*                           FACE  FUNCTIONS                             */
 389   /*                                                                       */
 390   /*************************************************************************/
 391 
 392   static FT_String*
 393   cff_strcpy( FT_Memory         memory,
 394               const FT_String*  source )
 395   {
 396     FT_Error    error;
 397     FT_String*  result;
 398 
 399 
 400     (void)FT_STRDUP( result, source );
 401 
 402     FT_UNUSED( error );
 403 
 404     return result;
 405   }
 406 
 407 
 408   /* Strip all subset prefixes of the form `ABCDEF+'.  Usually, there */
 409   /* is only one, but font names like `APCOOG+JFABTD+FuturaBQ-Bold'   */
 410   /* have been seen in the wild.                                      */


 628       if ( face_index < 0 )
 629       {
 630         cffface->num_faces = (FT_Long)cff->num_faces;
 631         return FT_Err_Ok;
 632       }
 633 
 634       cff->pshinter = pshinter;
 635       cff->psnames  = psnames;
 636       cff->cffload  = cffload;
 637 
 638       cffface->face_index = face_index & 0xFFFF;
 639 
 640       /* Complement the root flags with some interesting information. */
 641       /* Note that this is only necessary for pure CFF and CEF fonts; */
 642       /* SFNT based fonts use the `name' table instead.               */
 643 
 644       cffface->num_glyphs = (FT_Long)cff->num_glyphs;
 645 
 646       dict = &cff->top_font.font_dict;
 647 
 648       /* we need the `PSNames' module for CFF and CEF formats */
 649       /* which aren't CID-keyed                               */
 650       if ( dict->cid_registry == 0xFFFFU && !psnames )
 651       {
 652         FT_ERROR(( "cff_face_init:"
 653                    " cannot open CFF & CEF fonts\n"
 654                    "              "
 655                    " without the `PSNames' module\n" ));
 656         error = FT_THROW( Missing_Module );
 657         goto Exit;
 658       }
 659 
 660 #ifdef FT_DEBUG_LEVEL_TRACE
 661       {
 662         FT_UInt     idx;
 663         FT_String*  s;
 664 
 665 
 666         FT_TRACE4(( "SIDs\n" ));
 667 
 668         /* dump string index, including default strings for convenience */
 669         for ( idx = 0; idx <= 390; idx++ )
 670         {
 671           s = cff_index_get_sid_string( cff, idx );
 672           if ( s )
 673             FT_TRACE4(( "  %5d %s\n", idx, s ));
 674         }
 675 


 948           }
 949         }
 950         else
 951         {
 952           char  *cid_font_name =
 953                    cff_index_get_sid_string( cff,
 954                                              dict->cid_font_name );
 955 
 956 
 957           /* do we have a `/FontName' for a CID-keyed font? */
 958           if ( cid_font_name )
 959             cffface->family_name = cff_strcpy( memory, cid_font_name );
 960         }
 961 
 962         if ( style_name )
 963           cffface->style_name = style_name;
 964         else
 965           /* assume "Regular" style if we don't know better */
 966           cffface->style_name = cff_strcpy( memory, (char *)"Regular" );
 967 
 968         /*******************************************************************/
 969         /*                                                                 */
 970         /* Compute face flags.                                             */
 971         /*                                                                 */
 972         flags = FT_FACE_FLAG_SCALABLE   | /* scalable outlines */
 973                 FT_FACE_FLAG_HORIZONTAL | /* horizontal data   */
 974                 FT_FACE_FLAG_HINTER;      /* has native hinter */
 975 
 976         if ( sfnt_format )
 977           flags |= FT_FACE_FLAG_SFNT;
 978 
 979         /* fixed width font? */
 980         if ( dict->is_fixed_pitch )
 981           flags |= FT_FACE_FLAG_FIXED_WIDTH;
 982 
 983   /* XXX: WE DO NOT SUPPORT KERNING METRICS IN THE GPOS TABLE FOR NOW */
 984 #if 0
 985         /* kerning available? */
 986         if ( face->kern_pairs )
 987           flags |= FT_FACE_FLAG_KERNING;
 988 #endif
 989 
 990         cffface->face_flags |= flags;
 991 
 992         /*******************************************************************/
 993         /*                                                                 */
 994         /* Compute style flags.                                            */
 995         /*                                                                 */
 996         flags = 0;
 997 
 998         if ( dict->italic_angle )
 999           flags |= FT_STYLE_FLAG_ITALIC;
1000 
1001         {
1002           char  *weight = cff_index_get_sid_string( cff,
1003                                                     dict->weight );
1004 
1005 
1006           if ( weight )
1007             if ( !ft_strcmp( weight, "Bold"  ) ||
1008                  !ft_strcmp( weight, "Black" ) )
1009               flags |= FT_STYLE_FLAG_BOLD;
1010         }
1011 
1012         /* double check */
1013         if ( !(flags & FT_STYLE_FLAG_BOLD) && cffface->style_name )
1014           if ( !ft_strncmp( cffface->style_name, "Bold", 4 )  ||
1015                !ft_strncmp( cffface->style_name, "Black", 5 ) )
1016             flags |= FT_STYLE_FLAG_BOLD;
1017 
1018         cffface->style_flags = flags;
1019       }
1020 
1021 #ifndef FT_CONFIG_OPTION_NO_GLYPH_NAMES
1022       /* CID-keyed CFF fonts don't have glyph names -- the SFNT loader */
1023       /* has unset this flag because of the 3.0 `post' table.          */
1024       if ( dict->cid_registry == 0xFFFFU )
1025         cffface->face_flags |= FT_FACE_FLAG_GLYPH_NAMES;
1026 #endif
1027 
1028       if ( dict->cid_registry != 0xFFFFU && pure_cff )
1029         cffface->face_flags |= FT_FACE_FLAG_CID_KEYED;
1030 
1031       /*******************************************************************/
1032       /*                                                                 */
1033       /* Compute char maps.                                              */
1034       /*                                                                 */
1035 
1036       /* Try to synthesize a Unicode charmap if there is none available */
1037       /* already.  If an OpenType font contains a Unicode "cmap", we    */
1038       /* will use it, whatever be in the CFF part of the file.          */
1039       {
1040         FT_CharMapRec  cmaprec;
1041         FT_CharMap     cmap;
1042         FT_UInt        nn;
1043         CFF_Encoding   encoding = &cff->encoding;
1044 
1045 
1046         for ( nn = 0; nn < (FT_UInt)cffface->num_charmaps; nn++ )
1047         {
1048           cmap = cffface->charmaps[nn];
1049 
1050           /* Windows Unicode? */
1051           if ( cmap->platform_id == TT_PLATFORM_MICROSOFT &&
1052                cmap->encoding_id == TT_MS_ID_UNICODE_CS   )
1053             goto Skip_Unicode;
1054 
1055           /* Apple Unicode platform id? */
1056           if ( cmap->platform_id == TT_PLATFORM_APPLE_UNICODE )
1057             goto Skip_Unicode; /* Apple Unicode */
1058         }
1059 
1060         /* since CID-keyed fonts don't contain glyph names, we can't */
1061         /* construct a cmap                                          */
1062         if ( pure_cff && cff->top_font.font_dict.cid_registry != 0xFFFFU )
1063           goto Exit;
1064 
1065         /* we didn't find a Unicode charmap -- synthesize one */
1066         cmaprec.face        = cffface;
1067         cmaprec.platform_id = TT_PLATFORM_MICROSOFT;
1068         cmaprec.encoding_id = TT_MS_ID_UNICODE_CS;
1069         cmaprec.encoding    = FT_ENCODING_UNICODE;
1070 
1071         nn = (FT_UInt)cffface->num_charmaps;
1072 
1073         error = FT_CMap_New( &CFF_CMAP_UNICODE_CLASS_REC_GET, NULL,
1074                              &cmaprec, NULL );
1075         if ( error                                      &&
1076              FT_ERR_NEQ( error, No_Unicode_Glyph_Name ) )

1077           goto Exit;
1078         error = FT_Err_Ok;
1079 
1080         /* if no Unicode charmap was previously selected, select this one */
1081         if ( !cffface->charmap && nn != (FT_UInt)cffface->num_charmaps )
1082           cffface->charmap = cffface->charmaps[nn];
1083 
1084       Skip_Unicode:
1085         if ( encoding->count > 0 )
1086         {
1087           FT_CMap_Class  clazz;
1088 
1089 
1090           cmaprec.face        = cffface;
1091           cmaprec.platform_id = TT_PLATFORM_ADOBE;  /* Adobe platform id */
1092 
1093           if ( encoding->offset == 0 )
1094           {
1095             cmaprec.encoding_id = TT_ADOBE_ID_STANDARD;
1096             cmaprec.encoding    = FT_ENCODING_ADOBE_STANDARD;
1097             clazz               = &CFF_CMAP_ENCODING_CLASS_REC_GET;
1098           }
1099           else if ( encoding->offset == 1 )
1100           {
1101             cmaprec.encoding_id = TT_ADOBE_ID_EXPERT;
1102             cmaprec.encoding    = FT_ENCODING_ADOBE_EXPERT;
1103             clazz               = &CFF_CMAP_ENCODING_CLASS_REC_GET;
1104           }
1105           else
1106           {
1107             cmaprec.encoding_id = TT_ADOBE_ID_CUSTOM;
1108             cmaprec.encoding    = FT_ENCODING_ADOBE_CUSTOM;
1109             clazz               = &CFF_CMAP_ENCODING_CLASS_REC_GET;
1110           }
1111 
1112           error = FT_CMap_New( clazz, NULL, &cmaprec, NULL );
1113         }
1114       }
1115     }
1116 
1117   Exit:
1118     return error;
1119   }
1120 
1121 
1122   FT_LOCAL_DEF( void )
1123   cff_face_done( FT_Face  cffface )         /* CFF_Face */
1124   {
1125     CFF_Face      face = (CFF_Face)cffface;
1126     FT_Memory     memory;
1127     SFNT_Service  sfnt;
1128 
1129 


   1 /****************************************************************************
   2  *
   3  * cffobjs.c
   4  *
   5  *   OpenType objects manager (body).
   6  *
   7  * Copyright (C) 1996-2019 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 
  21 #include FT_INTERNAL_DEBUG_H
  22 #include FT_INTERNAL_CALC_H
  23 #include FT_INTERNAL_STREAM_H
  24 #include FT_ERRORS_H
  25 #include FT_TRUETYPE_IDS_H
  26 #include FT_TRUETYPE_TAGS_H
  27 #include FT_INTERNAL_SFNT_H
  28 #include FT_DRIVER_H
  29 
  30 #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
  31 #include FT_MULTIPLE_MASTERS_H
  32 #include FT_SERVICE_MULTIPLE_MASTERS_H
  33 #include FT_SERVICE_METRICS_VARIATIONS_H
  34 #endif
  35 
  36 #include FT_INTERNAL_CFF_OBJECTS_TYPES_H
  37 #include "cffobjs.h"
  38 #include "cffload.h"
  39 #include "cffcmap.h"

  40 
  41 #include "cfferrs.h"
  42 
  43 #include FT_INTERNAL_POSTSCRIPT_AUX_H
  44 #include FT_SERVICE_CFF_TABLE_LOAD_H
  45 
  46 
  47   /**************************************************************************
  48    *
  49    * The macro FT_COMPONENT is used in trace mode.  It is an implicit
  50    * parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log
  51    * messages during execution.
  52    */
  53 #undef  FT_COMPONENT
  54 #define FT_COMPONENT  cffobjs
  55 
  56 
  57   /**************************************************************************
  58    *
  59    *                           SIZE FUNCTIONS
  60    *
  61    */
  62 
  63 
  64   static PSH_Globals_Funcs
  65   cff_size_get_globals_funcs( CFF_Size  size )
  66   {
  67     CFF_Face          face     = (CFF_Face)size->root.face;
  68     CFF_Font          font     = (CFF_Font)face->extra.data;
  69     PSHinter_Service  pshinter = font->pshinter;
  70     FT_Module         module;
  71 
  72 
  73     module = FT_Get_Module( size->root.face->driver->root.library,
  74                             "pshinter" );
  75     return ( module && pshinter && pshinter->get_globals_funcs )
  76            ? pshinter->get_globals_funcs( module )
  77            : 0;
  78   }
  79 
  80 
  81   FT_LOCAL_DEF( void )


 323         if ( top_upm != sub_upm )
 324         {
 325           x_scale = FT_MulDiv( size->metrics.x_scale, top_upm, sub_upm );
 326           y_scale = FT_MulDiv( size->metrics.y_scale, top_upm, sub_upm );
 327         }
 328         else
 329         {
 330           x_scale = size->metrics.x_scale;
 331           y_scale = size->metrics.y_scale;
 332         }
 333 
 334         funcs->set_scale( internal->subfonts[i - 1],
 335                           x_scale, y_scale, 0, 0 );
 336       }
 337     }
 338 
 339     return FT_Err_Ok;
 340   }
 341 
 342 
 343   /**************************************************************************
 344    *
 345    *                           SLOT  FUNCTIONS
 346    *
 347    */
 348 
 349   FT_LOCAL_DEF( void )
 350   cff_slot_done( FT_GlyphSlot  slot )
 351   {
 352     slot->internal->glyph_hints = NULL;
 353   }
 354 
 355 
 356   FT_LOCAL_DEF( FT_Error )
 357   cff_slot_init( FT_GlyphSlot  slot )
 358   {
 359     CFF_Face          face     = (CFF_Face)slot->face;
 360     CFF_Font          font     = (CFF_Font)face->extra.data;
 361     PSHinter_Service  pshinter = font->pshinter;
 362 
 363 
 364     if ( pshinter )
 365     {
 366       FT_Module  module;
 367 
 368 
 369       module = FT_Get_Module( slot->face->driver->root.library,
 370                               "pshinter" );
 371       if ( module )
 372       {
 373         T2_Hints_Funcs  funcs;
 374 
 375 
 376         funcs = pshinter->get_t2_funcs( module );
 377         slot->internal->glyph_hints = (void*)funcs;
 378       }
 379     }
 380 
 381     return FT_Err_Ok;
 382   }
 383 
 384 
 385   /**************************************************************************
 386    *
 387    *                          FACE  FUNCTIONS
 388    *
 389    */
 390 
 391   static FT_String*
 392   cff_strcpy( FT_Memory         memory,
 393               const FT_String*  source )
 394   {
 395     FT_Error    error;
 396     FT_String*  result;
 397 
 398 
 399     (void)FT_STRDUP( result, source );
 400 
 401     FT_UNUSED( error );
 402 
 403     return result;
 404   }
 405 
 406 
 407   /* Strip all subset prefixes of the form `ABCDEF+'.  Usually, there */
 408   /* is only one, but font names like `APCOOG+JFABTD+FuturaBQ-Bold'   */
 409   /* have been seen in the wild.                                      */


 627       if ( face_index < 0 )
 628       {
 629         cffface->num_faces = (FT_Long)cff->num_faces;
 630         return FT_Err_Ok;
 631       }
 632 
 633       cff->pshinter = pshinter;
 634       cff->psnames  = psnames;
 635       cff->cffload  = cffload;
 636 
 637       cffface->face_index = face_index & 0xFFFF;
 638 
 639       /* Complement the root flags with some interesting information. */
 640       /* Note that this is only necessary for pure CFF and CEF fonts; */
 641       /* SFNT based fonts use the `name' table instead.               */
 642 
 643       cffface->num_glyphs = (FT_Long)cff->num_glyphs;
 644 
 645       dict = &cff->top_font.font_dict;
 646 
 647       /* we need the `psnames' module for CFF and CEF formats */
 648       /* which aren't CID-keyed                               */
 649       if ( dict->cid_registry == 0xFFFFU && !psnames )
 650       {
 651         FT_ERROR(( "cff_face_init:"
 652                    " cannot open CFF & CEF fonts\n"
 653                    "              "
 654                    " without the `psnames' module\n" ));
 655         error = FT_THROW( Missing_Module );
 656         goto Exit;
 657       }
 658 
 659 #ifdef FT_DEBUG_LEVEL_TRACE
 660       {
 661         FT_UInt     idx;
 662         FT_String*  s;
 663 
 664 
 665         FT_TRACE4(( "SIDs\n" ));
 666 
 667         /* dump string index, including default strings for convenience */
 668         for ( idx = 0; idx <= 390; idx++ )
 669         {
 670           s = cff_index_get_sid_string( cff, idx );
 671           if ( s )
 672             FT_TRACE4(( "  %5d %s\n", idx, s ));
 673         }
 674 


 947           }
 948         }
 949         else
 950         {
 951           char  *cid_font_name =
 952                    cff_index_get_sid_string( cff,
 953                                              dict->cid_font_name );
 954 
 955 
 956           /* do we have a `/FontName' for a CID-keyed font? */
 957           if ( cid_font_name )
 958             cffface->family_name = cff_strcpy( memory, cid_font_name );
 959         }
 960 
 961         if ( style_name )
 962           cffface->style_name = style_name;
 963         else
 964           /* assume "Regular" style if we don't know better */
 965           cffface->style_name = cff_strcpy( memory, (char *)"Regular" );
 966 
 967         /********************************************************************
 968          *
 969          * Compute face flags.
 970          */
 971         flags = FT_FACE_FLAG_SCALABLE   | /* scalable outlines */
 972                 FT_FACE_FLAG_HORIZONTAL | /* horizontal data   */
 973                 FT_FACE_FLAG_HINTER;      /* has native hinter */
 974 
 975         if ( sfnt_format )
 976           flags |= FT_FACE_FLAG_SFNT;
 977 
 978         /* fixed width font? */
 979         if ( dict->is_fixed_pitch )
 980           flags |= FT_FACE_FLAG_FIXED_WIDTH;
 981 
 982   /* XXX: WE DO NOT SUPPORT KERNING METRICS IN THE GPOS TABLE FOR NOW */
 983 #if 0
 984         /* kerning available? */
 985         if ( face->kern_pairs )
 986           flags |= FT_FACE_FLAG_KERNING;
 987 #endif
 988 
 989         cffface->face_flags |= flags;
 990 
 991         /********************************************************************
 992          *
 993          * Compute style flags.
 994          */
 995         flags = 0;
 996 
 997         if ( dict->italic_angle )
 998           flags |= FT_STYLE_FLAG_ITALIC;
 999 
1000         {
1001           char  *weight = cff_index_get_sid_string( cff,
1002                                                     dict->weight );
1003 
1004 
1005           if ( weight )
1006             if ( !ft_strcmp( weight, "Bold"  ) ||
1007                  !ft_strcmp( weight, "Black" ) )
1008               flags |= FT_STYLE_FLAG_BOLD;
1009         }
1010 
1011         /* double check */
1012         if ( !(flags & FT_STYLE_FLAG_BOLD) && cffface->style_name )
1013           if ( !ft_strncmp( cffface->style_name, "Bold", 4 )  ||
1014                !ft_strncmp( cffface->style_name, "Black", 5 ) )
1015             flags |= FT_STYLE_FLAG_BOLD;
1016 
1017         cffface->style_flags = flags;
1018       }
1019 
1020 #ifndef FT_CONFIG_OPTION_NO_GLYPH_NAMES
1021       /* CID-keyed CFF fonts don't have glyph names -- the SFNT loader */
1022       /* has unset this flag because of the 3.0 `post' table.          */
1023       if ( dict->cid_registry == 0xFFFFU )
1024         cffface->face_flags |= FT_FACE_FLAG_GLYPH_NAMES;
1025 #endif
1026 
1027       if ( dict->cid_registry != 0xFFFFU && pure_cff )
1028         cffface->face_flags |= FT_FACE_FLAG_CID_KEYED;
1029 
1030       /********************************************************************
1031        *
1032        * Compute char maps.
1033        */
1034 
1035       /* Try to synthesize a Unicode charmap if there is none available */
1036       /* already.  If an OpenType font contains a Unicode "cmap", we    */
1037       /* will use it, whatever be in the CFF part of the file.          */
1038       {
1039         FT_CharMapRec  cmaprec;
1040         FT_CharMap     cmap;
1041         FT_UInt        nn;
1042         CFF_Encoding   encoding = &cff->encoding;
1043 
1044 
1045         for ( nn = 0; nn < (FT_UInt)cffface->num_charmaps; nn++ )
1046         {
1047           cmap = cffface->charmaps[nn];
1048 
1049           /* Windows Unicode? */
1050           if ( cmap->platform_id == TT_PLATFORM_MICROSOFT &&
1051                cmap->encoding_id == TT_MS_ID_UNICODE_CS   )
1052             goto Skip_Unicode;
1053 
1054           /* Apple Unicode platform id? */
1055           if ( cmap->platform_id == TT_PLATFORM_APPLE_UNICODE )
1056             goto Skip_Unicode; /* Apple Unicode */
1057         }
1058 
1059         /* since CID-keyed fonts don't contain glyph names, we can't */
1060         /* construct a cmap                                          */
1061         if ( pure_cff && cff->top_font.font_dict.cid_registry != 0xFFFFU )
1062           goto Exit;
1063 
1064         /* we didn't find a Unicode charmap -- synthesize one */
1065         cmaprec.face        = cffface;
1066         cmaprec.platform_id = TT_PLATFORM_MICROSOFT;
1067         cmaprec.encoding_id = TT_MS_ID_UNICODE_CS;
1068         cmaprec.encoding    = FT_ENCODING_UNICODE;
1069 
1070         nn = (FT_UInt)cffface->num_charmaps;
1071 
1072         error = FT_CMap_New( &cff_cmap_unicode_class_rec, NULL,
1073                              &cmaprec, NULL );
1074         if ( error                                      &&
1075              FT_ERR_NEQ( error, No_Unicode_Glyph_Name ) &&
1076              FT_ERR_NEQ( error, Unimplemented_Feature ) )
1077           goto Exit;
1078         error = FT_Err_Ok;
1079 
1080         /* if no Unicode charmap was previously selected, select this one */
1081         if ( !cffface->charmap && nn != (FT_UInt)cffface->num_charmaps )
1082           cffface->charmap = cffface->charmaps[nn];
1083 
1084       Skip_Unicode:
1085         if ( encoding->count > 0 )
1086         {
1087           FT_CMap_Class  clazz;
1088 
1089 
1090           cmaprec.face        = cffface;
1091           cmaprec.platform_id = TT_PLATFORM_ADOBE;  /* Adobe platform id */
1092 
1093           if ( encoding->offset == 0 )
1094           {
1095             cmaprec.encoding_id = TT_ADOBE_ID_STANDARD;
1096             cmaprec.encoding    = FT_ENCODING_ADOBE_STANDARD;
1097             clazz               = &cff_cmap_encoding_class_rec;
1098           }
1099           else if ( encoding->offset == 1 )
1100           {
1101             cmaprec.encoding_id = TT_ADOBE_ID_EXPERT;
1102             cmaprec.encoding    = FT_ENCODING_ADOBE_EXPERT;
1103             clazz               = &cff_cmap_encoding_class_rec;
1104           }
1105           else
1106           {
1107             cmaprec.encoding_id = TT_ADOBE_ID_CUSTOM;
1108             cmaprec.encoding    = FT_ENCODING_ADOBE_CUSTOM;
1109             clazz               = &cff_cmap_encoding_class_rec;
1110           }
1111 
1112           error = FT_CMap_New( clazz, NULL, &cmaprec, NULL );
1113         }
1114       }
1115     }
1116 
1117   Exit:
1118     return error;
1119   }
1120 
1121 
1122   FT_LOCAL_DEF( void )
1123   cff_face_done( FT_Face  cffface )         /* CFF_Face */
1124   {
1125     CFF_Face      face = (CFF_Face)cffface;
1126     FT_Memory     memory;
1127     SFNT_Service  sfnt;
1128 
1129 


< prev index next >