Exemplo n.º 1
0
  /*
   * TT CMAP INFO
   *
   * If the charmap is a synthetic Unicode encoding cmap or
   * a Type 1 standard (or expert) encoding cmap, hide TT CMAP INFO
   * service defined in SFNT module.
   *
   * Otherwise call the service function in the sfnt module.
   *
   */
  static FT_Error
  cff_get_cmap_info( FT_CharMap    charmap,
                     TT_CMapInfo  *cmap_info )
  {
    FT_CMap   cmap  = FT_CMAP( charmap );
    FT_Error  error = CFF_Err_Ok;


    cmap_info->language = 0;

    if ( cmap->clazz != &cff_cmap_encoding_class_rec &&
         cmap->clazz != &cff_cmap_unicode_class_rec  )
    {
      FT_Face             face    = FT_CMAP_FACE( cmap );
      FT_Library          library = FT_FACE_LIBRARY( face );
      FT_Module           sfnt    = FT_Get_Module( library, "sfnt" );
      FT_Service_TTCMaps  service =
        (FT_Service_TTCMaps)ft_module_get_service( sfnt,
                                                   FT_SERVICE_ID_TT_CMAP );


      if ( service && service->get_cmap_info )
        error = service->get_cmap_info( charmap, cmap_info );
    }

    return error;
  }
Exemplo n.º 2
0
  static const char*
  cff_get_ps_name( CFF_Face  face )
  {
    CFF_Font      cff  = (CFF_Font)face->extra.data;
    SFNT_Service  sfnt = (SFNT_Service)face->sfnt;


    /* following the OpenType specification 1.7, we return the name stored */
    /* in the `name' table for a CFF wrapped into an SFNT container        */

    if ( FT_IS_SFNT( FT_FACE( face ) ) && sfnt )
    {
      FT_Library             library     = FT_FACE_LIBRARY( face );
      FT_Module              sfnt_module = FT_Get_Module( library, "sfnt" );
      FT_Service_PsFontName  service     =
        (FT_Service_PsFontName)ft_module_get_service(
                                 sfnt_module,
                                 FT_SERVICE_ID_POSTSCRIPT_FONT_NAME,
                                 0 );


      if ( service && service->get_ps_font_name )
        return service->get_ps_font_name( FT_FACE( face ) );
    }

    return (const char*)cff->font_name;
  }
Exemplo n.º 3
0
  /*
   * TT CMAP INFO
   *
   * If the charmap is a synthetic Unicode encoding cmap or
   * a Type 1 standard (or expert) encoding cmap, hide TT CMAP INFO
   * service defined in SFNT module.
   *
   * Otherwise call the service function in the sfnt module.
   *
   */
  static FT_Error
  cff_get_cmap_info( FT_CharMap    charmap,
                     TT_CMapInfo  *cmap_info )
  {
    FT_CMap   cmap  = FT_CMAP( charmap );
    FT_Error  error = CFF_Err_Ok;
    FT_Face    face    = FT_CMAP_FACE( cmap );
    FT_Library library = FT_FACE_LIBRARY( face );


    cmap_info->language = 0;
    cmap_info->format   = 0;

    if ( cmap->clazz != &FT_CFF_CMAP_ENCODING_CLASS_REC_GET &&
         cmap->clazz != &FT_CFF_CMAP_UNICODE_CLASS_REC_GET  )
    {
      FT_Module           sfnt    = FT_Get_Module( library, "sfnt" );
      FT_Service_TTCMaps  service =
        (FT_Service_TTCMaps)ft_module_get_service( sfnt,
                                                   FT_SERVICE_ID_TT_CMAP );


      if ( service && service->get_cmap_info )
        error = service->get_cmap_info( charmap, cmap_info );
    }

    return error;
  }
Exemplo n.º 4
0
  T1_Decoder_Init( T1_Decoder           decoder,
                   FT_Face              face,
                   FT_Size              size,
                   FT_GlyphSlot         slot,
                   FT_Byte**            glyph_names,
                   PS_Blend             blend,
                   FT_Bool              hinting,
                   T1_Decoder_Callback  parse_callback )
  {
    FT_MEM_SET( decoder, 0, sizeof ( *decoder ) );

    /* retrieve PSNames interface from list of current modules */
    {
      PSNames_Service  psnames = 0;


      psnames = (PSNames_Service)FT_Get_Module_Interface(
                  FT_FACE_LIBRARY(face), "psnames" );
      if ( !psnames )
      {
        FT_ERROR(( "T1_Decoder_Init: " ));
        FT_ERROR(( "the `psnames' module is not available\n" ));
        return PSaux_Err_Unimplemented_Feature;
      }

      decoder->psnames = psnames;
    }

    T1_Builder_Init( &decoder->builder, face, size, slot, hinting );

    decoder->num_glyphs     = face->num_glyphs;
    decoder->glyph_names    = glyph_names;
    decoder->blend          = blend;
    decoder->parse_callback = parse_callback;

    decoder->funcs          = t1_decoder_funcs;

    return 0;
  }
Exemplo n.º 5
0
T1_Face_Init( FT_Stream      stream,
              FT_Face        t1face,          /* T1_Face */
              FT_Int         face_index,
              FT_Int         num_params,
              FT_Parameter*  params )
{
    T1_Face             face = (T1_Face)t1face;
    FT_Error            error;
    FT_Service_PsCMaps  psnames;
    PSAux_Service       psaux;
    T1_Font             type1 = &face->type1;
    PS_FontInfo         info = &type1->font_info;

    FT_UNUSED( num_params );
    FT_UNUSED( params );
    FT_UNUSED( stream );


    face->root.num_faces = 1;

    FT_FACE_FIND_GLOBAL_SERVICE( face, psnames, POSTSCRIPT_CMAPS );
    face->psnames = psnames;

    face->psaux = FT_Get_Module_Interface( FT_FACE_LIBRARY( face ),
                                           "psaux" );
    psaux = (PSAux_Service)face->psaux;
    if ( !psaux )
    {
        FT_ERROR(( "T1_Face_Init: cannot access `psaux' module\n" ));
        error = FT_THROW( Missing_Module );
        goto Exit;
    }

    face->pshinter = FT_Get_Module_Interface( FT_FACE_LIBRARY( face ),
                     "pshinter" );

    FT_TRACE2(( "Type 1 driver\n" ));

    /* open the tokenizer; this will also check the font format */
    error = T1_Open_Face( face );
    if ( error )
        goto Exit;

    /* if we just wanted to check the format, leave successfully now */
    if ( face_index < 0 )
        goto Exit;

    /* check the face index */
    if ( face_index > 0 )
    {
        FT_ERROR(( "T1_Face_Init: invalid face index\n" ));
        error = FT_THROW( Invalid_Argument );
        goto Exit;
    }

    /* now load the font program into the face object */

    /* initialize the face object fields */

    /* set up root face fields */
    {
        FT_Face  root = (FT_Face)&face->root;


        root->num_glyphs = type1->num_glyphs;
        root->face_index = 0;

        root->face_flags |= FT_FACE_FLAG_SCALABLE    |
                            FT_FACE_FLAG_HORIZONTAL  |
                            FT_FACE_FLAG_GLYPH_NAMES |
                            FT_FACE_FLAG_HINTER;

        if ( info->is_fixed_pitch )
            root->face_flags |= FT_FACE_FLAG_FIXED_WIDTH;

        if ( face->blend )
            root->face_flags |= FT_FACE_FLAG_MULTIPLE_MASTERS;

        /* XXX: TODO -- add kerning with .afm support */


        /* The following code to extract the family and the style is very   */
        /* simplistic and might get some things wrong.  For a full-featured */
        /* algorithm you might have a look at the whitepaper given at       */
        /*                                                                  */
        /*   http://blogs.msdn.com/text/archive/2007/04/23/wpf-font-selection-model.aspx */

        /* get style name -- be careful, some broken fonts only */
        /* have a `/FontName' dictionary entry!                 */
        root->family_name = info->family_name;
        root->style_name  = NULL;

        if ( root->family_name )
        {
            char*  full   = info->full_name;
            char*  family = root->family_name;


            if ( full )
            {
                FT_Bool  the_same = TRUE;


                while ( *full )
                {
                    if ( *full == *family )
                    {
                        family++;
                        full++;
                    }
                    else
                    {
                        if ( *full == ' ' || *full == '-' )
                            full++;
                        else if ( *family == ' ' || *family == '-' )
                            family++;
                        else
                        {
                            the_same = FALSE;

                            if ( !*family )
                                root->style_name = full;
                            break;
                        }
                    }
                }

                if ( the_same )
                    root->style_name = (char *)"Regular";
            }
        }
        else
        {
            /* do we have a `/FontName'? */
            if ( type1->font_name )
                root->family_name = type1->font_name;
        }

        if ( !root->style_name )
        {
            if ( info->weight )
                root->style_name = info->weight;
            else
                /* assume `Regular' style because we don't know better */
                root->style_name = (char *)"Regular";
        }

        /* compute style flags */
        root->style_flags = 0;
        if ( info->italic_angle )
            root->style_flags |= FT_STYLE_FLAG_ITALIC;
        if ( info->weight )
        {
            if ( !ft_strcmp( info->weight, "Bold"  ) ||
                    !ft_strcmp( info->weight, "Black" ) )
                root->style_flags |= FT_STYLE_FLAG_BOLD;
        }

        /* no embedded bitmap support */
        root->num_fixed_sizes = 0;
        root->available_sizes = 0;

        root->bbox.xMin =   type1->font_bbox.xMin            >> 16;
        root->bbox.yMin =   type1->font_bbox.yMin            >> 16;
        /* no `U' suffix here to 0xFFFF! */
        root->bbox.xMax = ( type1->font_bbox.xMax + 0xFFFF ) >> 16;
        root->bbox.yMax = ( type1->font_bbox.yMax + 0xFFFF ) >> 16;

        /* Set units_per_EM if we didn't set it in t1_parse_font_matrix. */
        if ( !root->units_per_EM )
            root->units_per_EM = 1000;

        root->ascender  = (FT_Short)( root->bbox.yMax );
        root->descender = (FT_Short)( root->bbox.yMin );

        root->height = (FT_Short)( ( root->units_per_EM * 12 ) / 10 );
        if ( root->height < root->ascender - root->descender )
            root->height = (FT_Short)( root->ascender - root->descender );

        /* now compute the maximum advance width */
        root->max_advance_width =
            (FT_Short)( root->bbox.xMax );
        {
            FT_Pos  max_advance;


            error = T1_Compute_Max_Advance( face, &max_advance );

            /* in case of error, keep the standard width */
            if ( !error )
                root->max_advance_width = (FT_Short)FIXED_TO_INT( max_advance );
            else
                error = FT_Err_Ok;   /* clear error */
        }

        root->max_advance_height = root->height;

        root->underline_position  = (FT_Short)info->underline_position;
        root->underline_thickness = (FT_Short)info->underline_thickness;
    }

    {
        FT_Face  root = &face->root;


        if ( psnames )
        {
            FT_CharMapRec    charmap;
            T1_CMap_Classes  cmap_classes = psaux->t1_cmap_classes;
            FT_CMap_Class    clazz;


            charmap.face = root;

            /* first of all, try to synthesize a Unicode charmap */
            charmap.platform_id = TT_PLATFORM_MICROSOFT;
            charmap.encoding_id = TT_MS_ID_UNICODE_CS;
            charmap.encoding    = FT_ENCODING_UNICODE;

            error = FT_CMap_New( cmap_classes->unicode, NULL, &charmap, NULL );
            if ( error                                      &&
                    FT_ERR_NEQ( error, No_Unicode_Glyph_Name ) )
                goto Exit;
            error = FT_Err_Ok;

            /* now, generate an Adobe Standard encoding when appropriate */
            charmap.platform_id = TT_PLATFORM_ADOBE;
            clazz               = NULL;

            switch ( type1->encoding_type )
            {
            case T1_ENCODING_TYPE_STANDARD:
                charmap.encoding    = FT_ENCODING_ADOBE_STANDARD;
                charmap.encoding_id = TT_ADOBE_ID_STANDARD;
                clazz               = cmap_classes->standard;
                break;

            case T1_ENCODING_TYPE_EXPERT:
                charmap.encoding    = FT_ENCODING_ADOBE_EXPERT;
                charmap.encoding_id = TT_ADOBE_ID_EXPERT;
                clazz               = cmap_classes->expert;
                break;

            case T1_ENCODING_TYPE_ARRAY:
                charmap.encoding    = FT_ENCODING_ADOBE_CUSTOM;
                charmap.encoding_id = TT_ADOBE_ID_CUSTOM;
                clazz               = cmap_classes->custom;
                break;

            case T1_ENCODING_TYPE_ISOLATIN1:
                charmap.encoding    = FT_ENCODING_ADOBE_LATIN_1;
                charmap.encoding_id = TT_ADOBE_ID_LATIN_1;
                clazz               = cmap_classes->unicode;
                break;

            default:
                ;
            }

            if ( clazz )
                error = FT_CMap_New( clazz, NULL, &charmap, NULL );

#if 0
            /* Select default charmap */
            if (root->num_charmaps)
                root->charmap = root->charmaps[0];
#endif
        }
    }

Exit:
    return error;
}
Exemplo n.º 6
0
  FT_LOCAL_DEF FT_Error
  T1_Face_Init( FT_Stream      stream,
                T1_Face        face,
                FT_Int         face_index,
                FT_Int         num_params,
                FT_Parameter*  params )
  {
    FT_Error             error;
    PSNames_Interface*   psnames;
    PSAux_Interface*     psaux;
    PSHinter_Interface*  pshinter;

    FT_UNUSED( num_params );
    FT_UNUSED( params );
    FT_UNUSED( face_index );
    FT_UNUSED( stream );


    face->root.num_faces = 1;

    psnames = (PSNames_Interface*)face->psnames;
    if ( !psnames )
    {
      psnames = (PSNames_Interface*)
                FT_Get_Module_Interface( FT_FACE_LIBRARY( face ), "psnames" );

      face->psnames = psnames;
    }

    psaux = (PSAux_Interface*)face->psaux;
    if ( !psaux )
    {
      psaux = (PSAux_Interface*)
              FT_Get_Module_Interface( FT_FACE_LIBRARY( face ), "psaux" );

      face->psaux = psaux;
    }
    
    pshinter = (PSHinter_Interface*)face->pshinter;
    if ( !pshinter )
    {
      pshinter = (PSHinter_Interface*)
                 FT_Get_Module_Interface( FT_FACE_LIBRARY( face ), "pshinter" );

      face->pshinter = pshinter;
    }

    /* open the tokenizer, this will also check the font format */
    error = T1_Open_Face( face );
    if ( error )
      goto Exit;

    /* if we just wanted to check the format, leave successfully now */
    if ( face_index < 0 )
      goto Exit;

    /* check the face index */
    if ( face_index != 0 )
    {
      FT_ERROR(( "T1_Face_Init: invalid face index\n" ));
      error = T1_Err_Invalid_Argument;
      goto Exit;
    }

    /* Now, load the font program into the face object */

    /* Init the face object fields */
    /* Now set up root face fields */
    {
      FT_Face  root = (FT_Face)&face->root;


      root->num_glyphs   = face->type1.num_glyphs;
      root->num_charmaps = 1;

      root->face_index = face_index;
      root->face_flags = FT_FACE_FLAG_SCALABLE;

      root->face_flags |= FT_FACE_FLAG_HORIZONTAL;

      root->face_flags |= FT_FACE_FLAG_GLYPH_NAMES;

      if ( face->type1.font_info.is_fixed_pitch )
        root->face_flags |= FT_FACE_FLAG_FIXED_WIDTH;

      if ( face->blend )
        root->face_flags |= FT_FACE_FLAG_MULTIPLE_MASTERS;

      /* XXX: TODO -- add kerning with .afm support */

      /* get style name -- be careful, some broken fonts only */
      /* have a `/FontName' dictionary entry!                 */
      root->family_name = face->type1.font_info.family_name;
      if ( root->family_name )
      {
        char*  full   = face->type1.font_info.full_name;
        char*  family = root->family_name;

        if ( full )
        {
          while ( *family && *full == *family )
          {
            family++;
            full++;
          }
  
          root->style_name = ( *full == ' ' ? full + 1
                                            : (char *)"Regular" );
        }
        else
          root->style_name = (char *)"Regular";
      }
      else
      {
        /* do we have a `/FontName'? */
        if ( face->type1.font_name )
        {
          root->family_name = face->type1.font_name;
          root->style_name  = (char *)"Regular";
        }
      }

      /* compute style flags */
      root->style_flags = 0;
      if ( face->type1.font_info.italic_angle )
        root->style_flags |= FT_STYLE_FLAG_ITALIC;
      if ( face->type1.font_info.weight )
      {
        if ( !strcmp( face->type1.font_info.weight, "Bold"  ) ||
             !strcmp( face->type1.font_info.weight, "Black" ) )
          root->style_flags |= FT_STYLE_FLAG_BOLD;
      }

      /* no embedded bitmap support */
      root->num_fixed_sizes = 0;
      root->available_sizes = 0;

      root->bbox = face->type1.font_bbox;

      /* Set units_per_EM if we didn't set it in parse_font_matrix. */
      if ( !root->units_per_EM )
        root->units_per_EM = 1000;

      root->ascender  = (FT_Short)( face->type1.font_bbox.yMax >> 16 );
      root->descender = (FT_Short)( face->type1.font_bbox.yMin >> 16 );
      root->height    = (FT_Short)(
                          ( ( root->ascender - root->descender ) * 12 ) / 10 );

      /* now compute the maximum advance width */
      root->max_advance_width =
        (FT_Short)( face->type1.font_bbox.xMax >> 16 );
      {
        FT_Int  max_advance;


        error = T1_Compute_Max_Advance( face, &max_advance );

        /* in case of error, keep the standard width */
        if ( !error )
          root->max_advance_width = (FT_Short)max_advance;
        else
          error = 0;   /* clear error */
      }

      root->max_advance_height = root->height;

      root->underline_position  = face->type1.font_info.underline_position;
      root->underline_thickness = face->type1.font_info.underline_thickness;

      root->internal->max_points   = 0;
      root->internal->max_contours = 0;
    }

    /* charmap support -- synthetize unicode charmap if possible */
    {
      FT_Face     root    = &face->root;
      FT_CharMap  charmap = face->charmaprecs;


      /* synthesize a Unicode charmap if there is support in the `PSNames' */
      /* module                                                            */
      if ( psnames )
      {
        if ( psnames->unicode_value )
        {
          error = psnames->build_unicodes(
                    root->memory,
                    face->type1.num_glyphs,
                    (const char**)face->type1.glyph_names,
                    &face->unicode_map );
          if ( !error )
          {
            root->charmap        = charmap;
            charmap->face        = (FT_Face)face;
            charmap->encoding    = ft_encoding_unicode;
            charmap->platform_id = 3;
            charmap->encoding_id = 1;
            charmap++;
          }

          /* simply clear the error in case of failure (which really) */
          /* means that out of memory or no unicode glyph names       */
          error = T1_Err_Ok;
        }
      }

      /* now, support either the standard, expert, or custom encoding */
      charmap->face        = (FT_Face)face;
      charmap->platform_id = 7;  /* a new platform id for Adobe fonts? */

      switch ( face->type1.encoding_type )
      {
      case t1_encoding_standard:
        charmap->encoding    = ft_encoding_adobe_standard;
        charmap->encoding_id = 0;
        break;

      case t1_encoding_expert:
        charmap->encoding    = ft_encoding_adobe_expert;
        charmap->encoding_id = 1;
        break;

      default:
        charmap->encoding    = ft_encoding_adobe_custom;
        charmap->encoding_id = 2;
        break;
      }

      root->charmaps     = face->charmaps;
      root->num_charmaps = charmap - face->charmaprecs + 1;
      face->charmaps[0]  = &face->charmaprecs[0];
      face->charmaps[1]  = &face->charmaprecs[1];
    }

  Exit:
    return error;
  }
Exemplo n.º 7
0
  cid_face_init( FT_Stream      stream,
                 FT_Face        cidface,        /* CID_Face */
                 FT_Int         face_index,
                 FT_Int         num_params,
                 FT_Parameter*  params )
  {
    CID_Face          face = (CID_Face)cidface;
    FT_Error          error;
    PSAux_Service     psaux;
    PSHinter_Service  pshinter;

    FT_UNUSED( num_params );
    FT_UNUSED( params );
    FT_UNUSED( stream );


    cidface->num_faces = 1;

    psaux = (PSAux_Service)face->psaux;
    if ( !psaux )
    {
      psaux = (PSAux_Service)FT_Get_Module_Interface(
                FT_FACE_LIBRARY( face ), "psaux" );

      face->psaux = psaux;
    }

    pshinter = (PSHinter_Service)face->pshinter;
    if ( !pshinter )
    {
      pshinter = (PSHinter_Service)FT_Get_Module_Interface(
                   FT_FACE_LIBRARY( face ), "pshinter" );

      face->pshinter = pshinter;
    }

    /* open the tokenizer; this will also check the font format */
    if ( FT_STREAM_SEEK( 0 ) )
      goto Exit;

    error = cid_face_open( face, face_index );
    if ( error )
      goto Exit;

    /* if we just wanted to check the format, leave successfully now */
    if ( face_index < 0 )
      goto Exit;

    /* check the face index */
    /* XXX: handle CID fonts with more than a single face */
    if ( face_index != 0 )
    {
      FT_ERROR(( "cid_face_init: invalid face index\n" ));
      error = CID_Err_Invalid_Argument;
      goto Exit;
    }

    /* now load the font program into the face object */

    /* initialize the face object fields */

    /* set up root face fields */
    {
      CID_FaceInfo  cid  = &face->cid;
      PS_FontInfo   info = &cid->font_info;


      cidface->num_glyphs   = cid->cid_count;
      cidface->num_charmaps = 0;

      cidface->face_index = face_index;
      cidface->face_flags = FT_FACE_FLAG_SCALABLE   | /* scalable outlines */
                            FT_FACE_FLAG_HORIZONTAL | /* horizontal data   */
                            FT_FACE_FLAG_HINTER;      /* has native hinter */

      if ( info->is_fixed_pitch )
        cidface->face_flags |= FT_FACE_FLAG_FIXED_WIDTH;

      /* XXX: TODO: add kerning with .afm support */

      /* get style name -- be careful, some broken fonts only */
      /* have a /FontName dictionary entry!                   */
      cidface->family_name = info->family_name;
      /* assume "Regular" style if we don't know better */
      cidface->style_name = (char *)"Regular";
      if ( cidface->family_name )
      {
        char*  full   = info->full_name;
        char*  family = cidface->family_name;


        if ( full )
        {
          while ( *full )
          {
            if ( *full == *family )
            {
              family++;
              full++;
            }
            else
            {
              if ( *full == ' ' || *full == '-' )
                full++;
              else if ( *family == ' ' || *family == '-' )
                family++;
              else
              {
                if ( !*family )
                  cidface->style_name = full;
                break;
              }
            }
          }
        }
      }
      else
      {
        /* do we have a `/FontName'? */
        if ( cid->cid_font_name )
          cidface->family_name = cid->cid_font_name;
      }

      /* compute style flags */
      cidface->style_flags = 0;
      if ( info->italic_angle )
        cidface->style_flags |= FT_STYLE_FLAG_ITALIC;
      if ( info->weight )
      {
        if ( !ft_strcmp( info->weight, "Bold"  ) ||
             !ft_strcmp( info->weight, "Black" ) )
          cidface->style_flags |= FT_STYLE_FLAG_BOLD;
      }

      /* no embedded bitmap support */
      cidface->num_fixed_sizes = 0;
      cidface->available_sizes = 0;

      cidface->bbox.xMin =   cid->font_bbox.xMin             >> 16;
      cidface->bbox.yMin =   cid->font_bbox.yMin             >> 16;
      cidface->bbox.xMax = ( cid->font_bbox.xMax + 0xFFFFU ) >> 16;
      cidface->bbox.yMax = ( cid->font_bbox.yMax + 0xFFFFU ) >> 16;

      if ( !cidface->units_per_EM )
        cidface->units_per_EM = 1000;

      cidface->ascender  = (FT_Short)( cidface->bbox.yMax );
      cidface->descender = (FT_Short)( cidface->bbox.yMin );

      cidface->height = (FT_Short)( ( cidface->units_per_EM * 12 ) / 10 );
      if ( cidface->height < cidface->ascender - cidface->descender )
        cidface->height = (FT_Short)( cidface->ascender - cidface->descender );

      cidface->underline_position  = (FT_Short)info->underline_position;
      cidface->underline_thickness = (FT_Short)info->underline_thickness;
    }

  Exit:
    return error;
  }
Exemplo n.º 8
0
  T42_Face_Init( FT_Stream      stream,
                 T42_Face       face,
                 FT_Int         face_index,
                 FT_Int         num_params,
                 FT_Parameter*  params )
  {
    FT_Error            error;
    FT_Service_PsCMaps  psnames;
    PSAux_Service       psaux;
    FT_Face             root  = (FT_Face)&face->root;
    T1_Font             type1 = &face->type1;
    PS_FontInfo         info  = &type1->font_info;

    FT_UNUSED( num_params );
    FT_UNUSED( params );
    FT_UNUSED( face_index );
    FT_UNUSED( stream );


    face->ttf_face       = NULL;
    face->root.num_faces = 1;

    FT_FACE_FIND_GLOBAL_SERVICE( face, psnames, POSTSCRIPT_CMAPS );
    face->psnames = psnames;

    face->psaux = FT_Get_Module_Interface( FT_FACE_LIBRARY( face ),
                                           "psaux" );
    psaux = (PSAux_Service)face->psaux;

    /* open the tokenizer, this will also check the font format */
    error = T42_Open_Face( face );
    if ( error )
      goto Exit;

    /* if we just wanted to check the format, leave successfully now */
    if ( face_index < 0 )
      goto Exit;

    /* check the face index */
    if ( face_index > 0 )
    {
      FT_ERROR(( "T42_Face_Init: invalid face index\n" ));
      error = T42_Err_Invalid_Argument;
      goto Exit;
    }

    /* Now load the font program into the face object */

    /* Init the face object fields */
    /* Now set up root face fields */

    root->num_glyphs   = type1->num_glyphs;
    root->num_charmaps = 0;
    root->face_index   = 0;

    root->face_flags = FT_FACE_FLAG_SCALABLE    |
                       FT_FACE_FLAG_HORIZONTAL  |
                       FT_FACE_FLAG_GLYPH_NAMES;

    if ( info->is_fixed_pitch )
      root->face_flags |= FT_FACE_FLAG_FIXED_WIDTH;

    /* We only set this flag if we have the patented bytecode interpreter. */
    /* There are no known `tricky' Type42 fonts that could be loaded with  */
    /* the unpatented interpreter.                                         */
#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER
    root->face_flags |= FT_FACE_FLAG_HINTER;
#endif

    /* XXX: TODO -- add kerning with .afm support */

    /* get style name -- be careful, some broken fonts only */
    /* have a `/FontName' dictionary entry!                 */
    root->family_name = info->family_name;
    /* assume "Regular" style if we don't know better */
    root->style_name = (char *)"Regular";
    if ( root->family_name )
    {
      char*  full   = info->full_name;
      char*  family = root->family_name;


      if ( full )
      {
        while ( *full )
        {
          if ( *full == *family )
          {
            family++;
            full++;
          }
          else
          {
            if ( *full == ' ' || *full == '-' )
              full++;
            else if ( *family == ' ' || *family == '-' )
              family++;
            else
            {
              if ( !*family )
                root->style_name = full;
              break;
            }
          }
        }
      }
    }
    else
    {
      /* do we have a `/FontName'? */
      if ( type1->font_name )
        root->family_name = type1->font_name;
    }

    /* no embedded bitmap support */
    root->num_fixed_sizes = 0;
    root->available_sizes = 0;

    /* Load the TTF font embedded in the T42 font */
    {
      FT_Open_Args  args;


      args.flags       = FT_OPEN_MEMORY;
      args.memory_base = face->ttf_data;
      args.memory_size = face->ttf_size;

      if ( num_params )
      {
        args.flags     |= FT_OPEN_PARAMS;
        args.num_params = num_params;
        args.params     = params;
      }

      error = FT_Open_Face( FT_FACE_LIBRARY( face ),
                            &args, 0, &face->ttf_face );
    }

    if ( error )
      goto Exit;

    FT_Done_Size( face->ttf_face->size );

    /* Ignore info in FontInfo dictionary and use the info from the  */
    /* loaded TTF font.  The PostScript interpreter also ignores it. */
    root->bbox         = face->ttf_face->bbox;
    root->units_per_EM = face->ttf_face->units_per_EM;

    root->ascender  = face->ttf_face->ascender;
    root->descender = face->ttf_face->descender;
    root->height    = face->ttf_face->height;

    root->max_advance_width  = face->ttf_face->max_advance_width;
    root->max_advance_height = face->ttf_face->max_advance_height;

    root->underline_position  = (FT_Short)info->underline_position;
    root->underline_thickness = (FT_Short)info->underline_thickness;

    /* compute style flags */
    root->style_flags = 0;
    if ( info->italic_angle )
      root->style_flags |= FT_STYLE_FLAG_ITALIC;

    if ( face->ttf_face->style_flags & FT_STYLE_FLAG_BOLD )
      root->style_flags |= FT_STYLE_FLAG_BOLD;

    if ( face->ttf_face->face_flags & FT_FACE_FLAG_VERTICAL )
      root->face_flags |= FT_FACE_FLAG_VERTICAL;

    {
      if ( psnames && psaux )
      {
        FT_CharMapRec    charmap;
        T1_CMap_Classes  cmap_classes = psaux->t1_cmap_classes;
        FT_CMap_Class    clazz;


        charmap.face = root;

        /* first of all, try to synthesize a Unicode charmap */
        charmap.platform_id = 3;
        charmap.encoding_id = 1;
        charmap.encoding    = FT_ENCODING_UNICODE;

        FT_CMap_New( cmap_classes->unicode, NULL, &charmap, NULL );

        /* now, generate an Adobe Standard encoding when appropriate */
        charmap.platform_id = 7;
        clazz               = NULL;

        switch ( type1->encoding_type )
        {
        case T1_ENCODING_TYPE_STANDARD:
          charmap.encoding    = FT_ENCODING_ADOBE_STANDARD;
          charmap.encoding_id = 0;
          clazz               = cmap_classes->standard;
          break;

        case T1_ENCODING_TYPE_EXPERT:
          charmap.encoding    = FT_ENCODING_ADOBE_EXPERT;
          charmap.encoding_id = 1;
          clazz               = cmap_classes->expert;
          break;

        case T1_ENCODING_TYPE_ARRAY:
          charmap.encoding    = FT_ENCODING_ADOBE_CUSTOM;
          charmap.encoding_id = 2;
          clazz               = cmap_classes->custom;
          break;

        case T1_ENCODING_TYPE_ISOLATIN1:
          charmap.encoding    = FT_ENCODING_ADOBE_LATIN_1;
          charmap.encoding_id = 3;
          clazz               = cmap_classes->unicode;
          break;

        default:
          ;
        }

        if ( clazz )
          FT_CMap_New( clazz, NULL, &charmap, NULL );

#if 0
        /* Select default charmap */
        if ( root->num_charmaps )
          root->charmap = root->charmaps[0];
#endif
      }
    }
  Exit:
    return error;
  }
Exemplo n.º 9
0
  static FT_UInt
  cff_get_name_index( CFF_Face    face,
                      FT_String*  glyph_name )
  {
    CFF_Font            cff;
    CFF_Charset         charset;
    FT_Service_PsCMaps  psnames;
    FT_String*          name;
    FT_UShort           sid;
    FT_UInt             i;


    cff     = (CFF_FontRec *)face->extra.data;
    charset = &cff->charset;

    /* CFF2 table does not have glyph names; */
    /* we need to use `post' table method    */
    if ( cff->version_major == 2 )
    {
      FT_Library            library     = FT_FACE_LIBRARY( face );
      FT_Module             sfnt_module = FT_Get_Module( library, "sfnt" );
      FT_Service_GlyphDict  service     =
        (FT_Service_GlyphDict)ft_module_get_service(
                                 sfnt_module,
                                 FT_SERVICE_ID_GLYPH_DICT,
                                 0 );


      if ( service && service->name_index )
        return service->name_index( FT_FACE( face ), glyph_name );
      else
      {
        FT_ERROR(( "cff_get_name_index:"
                   " cannot get glyph index from a CFF2 font\n"
                   "                   "
                   " without the `psnames' module\n" ));
        return 0;
      }
    }

    FT_FACE_FIND_GLOBAL_SERVICE( face, psnames, POSTSCRIPT_CMAPS );
    if ( !psnames )
      return 0;

    for ( i = 0; i < cff->num_glyphs; i++ )
    {
      sid = charset->sids[i];

      if ( sid > 390 )
        name = cff_index_get_string( cff, sid - 391 );
      else
        name = (FT_String *)psnames->adobe_std_strings( sid );

      if ( !name )
        continue;

      if ( !ft_strcmp( glyph_name, name ) )
        return i;
    }

    return 0;
  }
Exemplo n.º 10
0
  static FT_Error
  cff_get_glyph_name( CFF_Face    face,
                      FT_UInt     glyph_index,
                      FT_Pointer  buffer,
                      FT_UInt     buffer_max )
  {
    CFF_Font    font   = (CFF_Font)face->extra.data;
    FT_String*  gname;
    FT_UShort   sid;
    FT_Error    error;


    /* CFF2 table does not have glyph names; */
    /* we need to use `post' table method    */
    if ( font->version_major == 2 )
    {
      FT_Library            library     = FT_FACE_LIBRARY( face );
      FT_Module             sfnt_module = FT_Get_Module( library, "sfnt" );
      FT_Service_GlyphDict  service     =
        (FT_Service_GlyphDict)ft_module_get_service(
                                 sfnt_module,
                                 FT_SERVICE_ID_GLYPH_DICT,
                                 0 );


      if ( service && service->get_name )
        return service->get_name( FT_FACE( face ),
                                  glyph_index,
                                  buffer,
                                  buffer_max );
      else
      {
        FT_ERROR(( "cff_get_glyph_name:"
                   " cannot get glyph name from a CFF2 font\n"
                   "                   "
                   " without the `psnames' module\n" ));
        error = FT_THROW( Missing_Module );
        goto Exit;
      }
    }

    if ( !font->psnames )
    {
      FT_ERROR(( "cff_get_glyph_name:"
                 " cannot get glyph name from CFF & CEF fonts\n"
                 "                   "
                 " without the `psnames' module\n" ));
      error = FT_THROW( Missing_Module );
      goto Exit;
    }

    /* first, locate the sid in the charset table */
    sid = font->charset.sids[glyph_index];

    /* now, lookup the name itself */
    gname = cff_index_get_sid_string( font, sid );

    if ( gname )
      FT_STRCPYN( buffer, gname, buffer_max );

    error = FT_Err_Ok;

  Exit:
    return error;
  }
Exemplo n.º 11
0
CID_Face_Init( FT_Stream      stream,
               CID_Face       face,
               FT_Int         face_index,
               FT_Int         num_params,
               FT_Parameter*  params )
{
    FT_Error          error;
    PSNames_Service   psnames;
    PSAux_Service     psaux;
    PSHinter_Service  pshinter;

    FT_UNUSED( num_params );
    FT_UNUSED( params );
    FT_UNUSED( face_index );
    FT_UNUSED( stream );


    face->root.num_faces = 1;

    psnames = (PSNames_Service)face->psnames;
    if ( !psnames )
    {
        psnames = (PSNames_Service)FT_Get_Module_Interface(
                      FT_FACE_LIBRARY( face ), "psnames" );

        face->psnames = psnames;
    }

    psaux = (PSAux_Service)face->psaux;
    if ( !psaux )
    {
        psaux = (PSAux_Service)FT_Get_Module_Interface(
                    FT_FACE_LIBRARY( face ), "psaux" );

        face->psaux = psaux;
    }

    pshinter = (PSHinter_Service)face->pshinter;
    if ( !pshinter )
    {
        pshinter = (PSHinter_Service)FT_Get_Module_Interface(
                       FT_FACE_LIBRARY( face ), "pshinter" );

        face->pshinter = pshinter;
    }

    /* open the tokenizer; this will also check the font format */
    if ( FT_STREAM_SEEK( 0 ) )
        goto Exit;

    error = CID_Open_Face( face );
    if ( error )
        goto Exit;

    /* if we just wanted to check the format, leave successfully now */
    if ( face_index < 0 )
        goto Exit;

    /* check the face index */
    if ( face_index != 0 )
    {
        FT_ERROR(( "CID_Face_Init: invalid face index\n" ));
        error = CID_Err_Invalid_Argument;
        goto Exit;
    }

    /* Now, load the font program into the face object */
    {
        /* Init the face object fields */
        /* Now set up root face fields */
        {
            FT_Face  root = (FT_Face)&face->root;


            root->num_glyphs   = face->cid.cid_count;
            root->num_charmaps = 0;

            root->face_index = face_index;
            root->face_flags = FT_FACE_FLAG_SCALABLE;

            root->face_flags |= FT_FACE_FLAG_HORIZONTAL;

            if ( face->cid.font_info.is_fixed_pitch )
                root->face_flags |= FT_FACE_FLAG_FIXED_WIDTH;

            /* XXX: TODO: add kerning with .afm support */

            /* get style name -- be careful, some broken fonts only */
            /* have a /FontName dictionary entry!                   */
            root->family_name = face->cid.font_info.family_name;
            if ( root->family_name )
            {
                char*  full   = face->cid.font_info.full_name;
                char*  family = root->family_name;

                while ( *family && *full == *family )
                {
                    family++;
                    full++;
                }

                root->style_name = ( *full == ' ' ) ? full + 1
                                   : (char *)"Regular";
            }
            else
            {
                /* do we have a `/FontName'? */
                if ( face->cid.cid_font_name )
                {
                    root->family_name = face->cid.cid_font_name;
                    root->style_name  = (char *)"Regular";
                }
            }

            /* no embedded bitmap support */
            root->num_fixed_sizes = 0;
            root->available_sizes = 0;

            root->bbox.xMin =   face->cid.font_bbox.xMin             >> 16;
            root->bbox.yMin =   face->cid.font_bbox.yMin             >> 16;
            root->bbox.xMax = ( face->cid.font_bbox.xMax + 0xFFFFU ) >> 16;
            root->bbox.yMax = ( face->cid.font_bbox.yMax + 0xFFFFU ) >> 16;

            if ( !root->units_per_EM )
                root->units_per_EM  = 1000;

            root->ascender  = (FT_Short)( root->bbox.yMax );
            root->descender = (FT_Short)( root->bbox.yMin );
            root->height    = (FT_Short)(
                                  ( ( root->ascender + root->descender ) * 12 ) / 10 );

            root->underline_position  = face->cid.font_info.underline_position;
            root->underline_thickness = face->cid.font_info.underline_thickness;

            root->internal->max_points   = 0;
            root->internal->max_contours = 0;
        }
    }

Exit:
    return error;
}
Exemplo n.º 12
0
  T1_Face_Init( FT_Stream      stream,
                T1_Face        face,
                FT_Int         face_index,
                FT_Int         num_params,
                FT_Parameter*  params )
  {
    FT_Error            error;
    FT_Service_PsCMaps  psnames;
    PSAux_Service       psaux;
    T1_Font             type1 = &face->type1;
    PS_FontInfo         info = &type1->font_info;

    FT_UNUSED( num_params );
    FT_UNUSED( params );
    FT_UNUSED( face_index );
    FT_UNUSED( stream );


    face->root.num_faces = 1;

    FT_FACE_FIND_GLOBAL_SERVICE( face, psnames, POSTSCRIPT_CMAPS );
    face->psnames = psnames;

    face->psaux = FT_Get_Module_Interface( FT_FACE_LIBRARY( face ),
                                           "psaux" );
    psaux = (PSAux_Service)face->psaux;

    face->pshinter = FT_Get_Module_Interface( FT_FACE_LIBRARY( face ),
                                              "pshinter" );

    /* open the tokenizer; this will also check the font format */
    error = T1_Open_Face( face );
    if ( error )
      goto Exit;

    /* if we just wanted to check the format, leave successfully now */
    if ( face_index < 0 )
      goto Exit;

    /* check the face index */
    if ( face_index != 0 )
    {
      FT_ERROR(( "T1_Face_Init: invalid face index\n" ));
      error = T1_Err_Invalid_Argument;
      goto Exit;
    }

    /* now load the font program into the face object */

    /* initialize the face object fields */

    /* set up root face fields */
    {
      FT_Face  root = (FT_Face)&face->root;


      root->num_glyphs = type1->num_glyphs;
      root->face_index = face_index;

      root->face_flags  = FT_FACE_FLAG_SCALABLE;
      root->face_flags |= FT_FACE_FLAG_HORIZONTAL;
      root->face_flags |= FT_FACE_FLAG_GLYPH_NAMES;

      if ( info->is_fixed_pitch )
        root->face_flags |= FT_FACE_FLAG_FIXED_WIDTH;

      if ( face->blend )
        root->face_flags |= FT_FACE_FLAG_MULTIPLE_MASTERS;

      /* XXX: TODO -- add kerning with .afm support */

      /* get style name -- be careful, some broken fonts only */
      /* have a `/FontName' dictionary entry!                 */
      root->family_name = info->family_name;
      /* assume "Regular" style if we don't know better */
      root->style_name = (char *)"Regular";
      if ( root->family_name )
      {
        char*  full   = info->full_name;
        char*  family = root->family_name;


        if ( full )
        {
          while ( *full )
          {
            if ( *full == *family )
            {
              family++;
              full++;
            }
            else
            {
              if ( *full == ' ' || *full == '-' )
                full++;
              else if ( *family == ' ' || *family == '-' )
                family++;
              else
              {
                if ( !*family )
                  root->style_name = full;
                break;
              }
            }
          }
        }
      }
      else
      {
        /* do we have a `/FontName'? */
        if ( type1->font_name )
          root->family_name = type1->font_name;
      }

      /* compute style flags */
      root->style_flags = 0;
      if ( info->italic_angle )
        root->style_flags |= FT_STYLE_FLAG_ITALIC;
      if ( info->weight )
      {
        if ( !ft_strcmp( info->weight, "Bold"  ) ||
             !ft_strcmp( info->weight, "Black" ) )
          root->style_flags |= FT_STYLE_FLAG_BOLD;
      }

      /* no embedded bitmap support */
      root->num_fixed_sizes = 0;
      root->available_sizes = 0;

      root->bbox.xMin =   type1->font_bbox.xMin             >> 16;
      root->bbox.yMin =   type1->font_bbox.yMin             >> 16;
      root->bbox.xMax = ( type1->font_bbox.xMax + 0xFFFFU ) >> 16;
      root->bbox.yMax = ( type1->font_bbox.yMax + 0xFFFFU ) >> 16;

      /* Set units_per_EM if we didn't set it in parse_font_matrix. */
      if ( !root->units_per_EM )
        root->units_per_EM = 1000;

      root->ascender  = (FT_Short)( root->bbox.yMax );
      root->descender = (FT_Short)( root->bbox.yMin );
      root->height    = (FT_Short)(
        ( ( root->ascender - root->descender ) * 12 ) / 10 );

      /* now compute the maximum advance width */
      root->max_advance_width =
        (FT_Short)( root->bbox.xMax );
      {
        FT_Pos  max_advance;


        error = T1_Compute_Max_Advance( face, &max_advance );

        /* in case of error, keep the standard width */
        if ( !error )
          root->max_advance_width = (FT_Short)max_advance;
        else
          error = 0;   /* clear error */
      }

      root->max_advance_height = root->height;

      root->underline_position  = (FT_Short)info->underline_position;
      root->underline_thickness = (FT_Short)info->underline_thickness;

      root->internal->max_points   = 0;
      root->internal->max_contours = 0;
    }

    {
      FT_Face  root = &face->root;


      if ( psnames && psaux )
      {
        FT_CharMapRec    charmap;
        T1_CMap_Classes  cmap_classes = psaux->t1_cmap_classes;
        FT_CMap_Class    clazz;


        charmap.face = root;

        /* first of all, try to synthetize a Unicode charmap */
        charmap.platform_id = 3;
        charmap.encoding_id = 1;
        charmap.encoding    = FT_ENCODING_UNICODE;

        FT_CMap_New( cmap_classes->unicode, NULL, &charmap, NULL );

        /* now, generate an Adobe Standard encoding when appropriate */
        charmap.platform_id = 7;
        clazz               = NULL;

        switch ( type1->encoding_type )
        {
        case T1_ENCODING_TYPE_STANDARD:
          charmap.encoding    = FT_ENCODING_ADOBE_STANDARD;
          charmap.encoding_id = TT_ADOBE_ID_STANDARD;
          clazz               = cmap_classes->standard;
          break;

        case T1_ENCODING_TYPE_EXPERT:
          charmap.encoding    = FT_ENCODING_ADOBE_EXPERT;
          charmap.encoding_id = TT_ADOBE_ID_EXPERT;
          clazz               = cmap_classes->expert;
          break;

        case T1_ENCODING_TYPE_ARRAY:
          charmap.encoding    = FT_ENCODING_ADOBE_CUSTOM;
          charmap.encoding_id = TT_ADOBE_ID_CUSTOM;
          clazz               = cmap_classes->custom;
          break;

        case T1_ENCODING_TYPE_ISOLATIN1:
          charmap.encoding    = FT_ENCODING_ADOBE_LATIN_1;
          charmap.encoding_id = TT_ADOBE_ID_LATIN_1;
          clazz               = cmap_classes->unicode;
          break;

        default:
          ;
        }

        if ( clazz )
          FT_CMap_New( clazz, NULL, &charmap, NULL );

#if 0
        /* Select default charmap */
        if (root->num_charmaps)
          root->charmap = root->charmaps[0];
#endif
      }
    }

  Exit:
    return error;
  }
Exemplo n.º 13
0
  T42_Face_Init( FT_Stream      stream,
                 T42_Face       face,
                 FT_Int         face_index,
                 FT_Int         num_params,
                 FT_Parameter*  params)
  {
    FT_Error          error;
    PSNames_Service   psnames;
    PSAux_Service     psaux;
    FT_Face           root    = (FT_Face)&face->root;

    FT_UNUSED( num_params );
    FT_UNUSED( params );
    FT_UNUSED( face_index );
    FT_UNUSED( stream );


    face->ttf_face       = NULL;
    face->root.num_faces = 1;

    face->psnames = FT_Get_Module_Interface( FT_FACE_LIBRARY( face ),
                                             "psnames" );
    psnames = (PSNames_Service)face->psnames;

    face->psaux = FT_Get_Module_Interface( FT_FACE_LIBRARY( face ),
                                           "psaux" );
    psaux = (PSAux_Service)face->psaux;

    /* open the tokenizer, this will also check the font format */
    error = T42_Open_Face( face );
    if ( error )
      goto Exit;

    /* if we just wanted to check the format, leave successfully now */
    if ( face_index < 0 )
      goto Exit;

    /* check the face index */
    if ( face_index != 0 )
    {
      FT_ERROR(( "T42_Face_Init: invalid face index\n" ));
      error = T42_Err_Invalid_Argument;
      goto Exit;
    }

    /* Now, load the font program into the face object */

    /* Init the face object fields */
    /* Now set up root face fields */

    root->num_glyphs   = face->type1.num_glyphs;
    root->num_charmaps = 0;
    root->face_index   = face_index;

    root->face_flags  = FT_FACE_FLAG_SCALABLE;
    root->face_flags |= FT_FACE_FLAG_HORIZONTAL;
    root->face_flags |= FT_FACE_FLAG_GLYPH_NAMES;

    if ( face->type1.font_info.is_fixed_pitch )
      root->face_flags |= FT_FACE_FLAG_FIXED_WIDTH;

    /* XXX: TODO -- add kerning with .afm support */

    /* get style name -- be careful, some broken fonts only */
    /* have a `/FontName' dictionary entry!                 */
    root->family_name = face->type1.font_info.family_name;
    if ( root->family_name )
    {
      char*  full   = face->type1.font_info.full_name;
      char*  family = root->family_name;


      if ( full )
      {
        while ( *family && *full == *family )
        {
          family++;
          full++;
        }

        root->style_name = ( *full == ' ' ? full + 1
                                          : (char *)"Regular" );
      }
      else
        root->style_name = (char *)"Regular";
    }
    else
    {
      /* do we have a `/FontName'? */
      if ( face->type1.font_name )
      {
        root->family_name = face->type1.font_name;
        root->style_name  = (char *)"Regular";
      }
    }

    /* no embedded bitmap support */
    root->num_fixed_sizes = 0;
    root->available_sizes = 0;

    /* Load the TTF font embedded in the T42 font */
    error = FT_New_Memory_Face( FT_FACE_LIBRARY( face ),
                                face->ttf_data,
                                face->ttf_size,
                                0,
                                &face->ttf_face );
    if ( error )
      goto Exit;

    FT_Done_Size( face->ttf_face->size );

    /* Ignore info in FontInfo dictionary and use the info from the  */
    /* loaded TTF font.  The PostScript interpreter also ignores it. */
    root->bbox         = face->ttf_face->bbox;
    root->units_per_EM = face->ttf_face->units_per_EM;

    root->ascender  = face->ttf_face->ascender;
    root->descender = face->ttf_face->descender;
    root->height    = face->ttf_face->height;

    root->max_advance_width  = face->ttf_face->max_advance_width;
    root->max_advance_height = face->ttf_face->max_advance_height;

    root->underline_position  = face->type1.font_info.underline_position;
    root->underline_thickness = face->type1.font_info.underline_thickness;

    root->internal->max_points   = 0;
    root->internal->max_contours = 0;

    /* compute style flags */
    root->style_flags = 0;
    if ( face->type1.font_info.italic_angle )
      root->style_flags |= FT_STYLE_FLAG_ITALIC;

    if ( face->ttf_face->style_flags & FT_STYLE_FLAG_BOLD )
      root->style_flags |= FT_STYLE_FLAG_BOLD;

    if ( face->ttf_face->face_flags & FT_FACE_FLAG_VERTICAL )
      root->face_flags |= FT_FACE_FLAG_VERTICAL;

#ifdef FT_CONFIG_OPTION_USE_CMAPS

    {
      if ( psnames && psaux )
      {
        FT_CharMapRec    charmap;
        T1_CMap_Classes  cmap_classes = psaux->t1_cmap_classes;
        FT_CMap_Class    clazz;


        charmap.face = root;

        /* first of all, try to synthetize a Unicode charmap */
        charmap.platform_id = 3;
        charmap.encoding_id = 1;
        charmap.encoding    = ft_encoding_unicode;

        FT_CMap_New( cmap_classes->unicode, NULL, &charmap, NULL );

        /* now, generate an Adobe Standard encoding when appropriate */
        charmap.platform_id = 7;
        clazz               = NULL;

        switch ( face->type1.encoding_type )
        {
        case T1_ENCODING_TYPE_STANDARD:
          charmap.encoding    = ft_encoding_adobe_standard;
          charmap.encoding_id = 0;
          clazz               = cmap_classes->standard;
          break;

        case T1_ENCODING_TYPE_EXPERT:
          charmap.encoding    = ft_encoding_adobe_expert;
          charmap.encoding_id = 1;
          clazz               = cmap_classes->expert;
          break;

        case T1_ENCODING_TYPE_ARRAY:
          charmap.encoding    = ft_encoding_adobe_custom;
          charmap.encoding_id = 2;
          clazz               = cmap_classes->custom;
          break;

        case T1_ENCODING_TYPE_ISOLATIN1:
          charmap.encoding    = ft_encoding_latin_1;
          charmap.encoding_id = 3;
          clazz               = cmap_classes->unicode;
          break;

        default:
          ;
        }

        if ( clazz )
          FT_CMap_New( clazz, NULL, &charmap, NULL );

        /* Select default charmap */
        if (root->num_charmaps)
          root->charmap = root->charmaps[0];
      }
    }

#else /* !FT_CONFIG_OPTION_USE_CMAPS */

    /* charmap support -- synthetize unicode charmap if possible */
    {
      FT_CharMap  charmap = face->charmaprecs;

      
      /* synthesize a Unicode charmap if there is support in the `PSNames' */
      /* module                                                            */
      if ( psnames && psnames->unicode_value )
      {
        error = psnames->build_unicodes( root->memory,
                                         face->type1.num_glyphs,
                                         (const char**)face->type1.glyph_names,
                                         &face->unicode_map );
        if ( !error )
        {
          root->charmap        = charmap;
          charmap->face        = (FT_Face)face;
          charmap->encoding    = ft_encoding_unicode;
          charmap->platform_id = 3;
          charmap->encoding_id = 1;
          charmap++;
        }
        
        /* XXX: Is the following code correct?  It is used in t1objs.c */
        
        /* simply clear the error in case of failure (which really) */
        /* means that out of memory or no unicode glyph names       */
        error = T42_Err_Ok;
      }
      
      /* now, support either the standard, expert, or custom encoding */
      charmap->face        = (FT_Face)face;
      charmap->platform_id = 7;  /* a new platform id for Adobe fonts? */
      
      switch ( face->type1.encoding_type )
      {
      case T1_ENCODING_TYPE_STANDARD:
        charmap->encoding    = ft_encoding_adobe_standard;
        charmap->encoding_id = 0;
        break;
        
      case T1_ENCODING_TYPE_EXPERT:
        charmap->encoding    = ft_encoding_adobe_expert;
        charmap->encoding_id = 1;
        break;
        
      case T1_ENCODING_TYPE_ARRAY:
        charmap->encoding    = ft_encoding_adobe_custom;
        charmap->encoding_id = 2;
        break;
        
      case T1_ENCODING_TYPE_ISOLATIN1:
        charmap->encoding    = ft_encoding_latin_1;
        charmap->encoding_id = 3;
        break;
        
      default:
        FT_ERROR(( "T42_Face_Init: invalid encoding\n" ));
        error = T42_Err_Invalid_File_Format;
        goto Exit;
      }
      
      root->charmaps     = face->charmaps;
      root->num_charmaps = charmap - face->charmaprecs + 1;
      face->charmaps[0]  = &face->charmaprecs[0];
      face->charmaps[1]  = &face->charmaprecs[1];
    }

#endif /* !FT_CONFIG_OPTION_USE_CMAPS */

  Exit:
    return error;
  }
Exemplo n.º 14
0
  T42_Face_Init( FT_Stream      stream,
                 T42_Face       face,
                 FT_Int         face_index,
                 FT_Int         num_params,
                 FT_Parameter*  params )
  {
    FT_Error          error;
    PSNames_Service   psnames;
    PSAux_Service     psaux;
    FT_Face           root    = (FT_Face)&face->root;

    FT_UNUSED( num_params );
    FT_UNUSED( params );
    FT_UNUSED( face_index );
    FT_UNUSED( stream );


    face->ttf_face       = NULL;
    face->root.num_faces = 1;

    face->psnames = FT_Get_Module_Interface( FT_FACE_LIBRARY( face ),
                                             "psnames" );
    psnames = (PSNames_Service)face->psnames;

    face->psaux = FT_Get_Module_Interface( FT_FACE_LIBRARY( face ),
                                           "psaux" );
    psaux = (PSAux_Service)face->psaux;

    /* open the tokenizer, this will also check the font format */
    error = T42_Open_Face( face );
    if ( error )
      goto Exit;

    /* if we just wanted to check the format, leave successfully now */
    if ( face_index < 0 )
      goto Exit;

    /* check the face index */
    if ( face_index != 0 )
    {
      FT_ERROR(( "T42_Face_Init: invalid face index\n" ));
      error = T42_Err_Invalid_Argument;
      goto Exit;
    }

    /* Now, load the font program into the face object */

    /* Init the face object fields */
    /* Now set up root face fields */

    root->num_glyphs   = face->type1.num_glyphs;
    root->num_charmaps = 0;
    root->face_index   = face_index;

    root->face_flags  = FT_FACE_FLAG_SCALABLE;
    root->face_flags |= FT_FACE_FLAG_HORIZONTAL;
    root->face_flags |= FT_FACE_FLAG_GLYPH_NAMES;

    if ( face->type1.font_info.is_fixed_pitch )
      root->face_flags |= FT_FACE_FLAG_FIXED_WIDTH;

    /* XXX: TODO -- add kerning with .afm support */

    /* get style name -- be careful, some broken fonts only */
    /* have a `/FontName' dictionary entry!                 */
    root->family_name = face->type1.font_info.family_name;
    if ( root->family_name )
    {
      char*  full   = face->type1.font_info.full_name;
      char*  family = root->family_name;


      if ( full )
      {
        while ( *family && *full == *family )
        {
          family++;
          full++;
        }

        root->style_name = ( *full == ' ' ? full + 1
                                          : (char *)"Regular" );
      }
      else
        root->style_name = (char *)"Regular";
    }
    else
    {
      /* do we have a `/FontName'? */
      if ( face->type1.font_name )
      {
        root->family_name = face->type1.font_name;
        root->style_name  = (char *)"Regular";
      }
    }

    /* no embedded bitmap support */
    root->num_fixed_sizes = 0;
    root->available_sizes = 0;

    /* Load the TTF font embedded in the T42 font */
    error = FT_New_Memory_Face( FT_FACE_LIBRARY( face ),
                                face->ttf_data,
                                face->ttf_size,
                                0,
                                &face->ttf_face );
    if ( error )
      goto Exit;

    FT_Done_Size( face->ttf_face->size );

    /* Ignore info in FontInfo dictionary and use the info from the  */
    /* loaded TTF font.  The PostScript interpreter also ignores it. */
    root->bbox         = face->ttf_face->bbox;
    root->units_per_EM = face->ttf_face->units_per_EM;

    root->ascender  = face->ttf_face->ascender;
    root->descender = face->ttf_face->descender;
    root->height    = face->ttf_face->height;

    root->max_advance_width  = face->ttf_face->max_advance_width;
    root->max_advance_height = face->ttf_face->max_advance_height;

    root->underline_position  = face->type1.font_info.underline_position;
    root->underline_thickness = face->type1.font_info.underline_thickness;

    root->internal->max_points   = 0;
    root->internal->max_contours = 0;

    /* compute style flags */
    root->style_flags = 0;
    if ( face->type1.font_info.italic_angle )
      root->style_flags |= FT_STYLE_FLAG_ITALIC;

    if ( face->ttf_face->style_flags & FT_STYLE_FLAG_BOLD )
      root->style_flags |= FT_STYLE_FLAG_BOLD;

    if ( face->ttf_face->face_flags & FT_FACE_FLAG_VERTICAL )
      root->face_flags |= FT_FACE_FLAG_VERTICAL;

    {
      if ( psnames && psaux )
      {
        FT_CharMapRec    charmap;
        T1_CMap_Classes  cmap_classes = psaux->t1_cmap_classes;
        FT_CMap_Class    clazz;


        charmap.face = root;

        /* first of all, try to synthetize a Unicode charmap */
        charmap.platform_id = 3;
        charmap.encoding_id = 1;
        charmap.encoding    = FT_ENCODING_UNICODE;

        FT_CMap_New( cmap_classes->unicode, NULL, &charmap, NULL );

        /* now, generate an Adobe Standard encoding when appropriate */
        charmap.platform_id = 7;
        clazz               = NULL;

        switch ( face->type1.encoding_type )
        {
        case T1_ENCODING_TYPE_STANDARD:
          charmap.encoding    = FT_ENCODING_ADOBE_STANDARD;
          charmap.encoding_id = 0;
          clazz               = cmap_classes->standard;
          break;

        case T1_ENCODING_TYPE_EXPERT:
          charmap.encoding    = FT_ENCODING_ADOBE_EXPERT;
          charmap.encoding_id = 1;
          clazz               = cmap_classes->expert;
          break;

        case T1_ENCODING_TYPE_ARRAY:
          charmap.encoding    = FT_ENCODING_ADOBE_CUSTOM;
          charmap.encoding_id = 2;
          clazz               = cmap_classes->custom;
          break;

        case T1_ENCODING_TYPE_ISOLATIN1:
          charmap.encoding    = FT_ENCODING_ADOBE_LATIN_1;
          charmap.encoding_id = 3;
          clazz               = cmap_classes->unicode;
          break;

        default:
          ;
        }

        if ( clazz )
          FT_CMap_New( clazz, NULL, &charmap, NULL );

#if 0
        /* Select default charmap */
        if (root->num_charmaps)
          root->charmap = root->charmaps[0];
#endif
      }
    }
  Exit:
    return error;
  }