示例#1
0
  static
  FT_UInt  Get_Char_Index( FT_CharMap  charmap,
                           FT_Long     charcode )
  {
    T1_Face             face;
    FT_UInt             result = 0;
    PSNames_Interface*  psnames;


    face    = (T1_Face)charmap->face;
    psnames = (PSNames_Interface*)face->psnames;
    if ( psnames )
      switch ( charmap->encoding )
      {
        /*******************************************************************/
        /*                                                                 */
        /* Unicode encoding support                                        */
        /*                                                                 */
      case ft_encoding_unicode:
        /* use the `PSNames' module to synthetize the Unicode charmap */
        result = psnames->lookup_unicode( &face->unicode_map,
                                          (FT_ULong)charcode );

        /* the function returns 0xFFFF if the Unicode charcode has */
        /* no corresponding glyph                                  */
        if ( result == 0xFFFF )
          result = 0;
        goto Exit;

        /*******************************************************************/
        /*                                                                 */
        /* Custom Type 1 encoding                                          */
        /*                                                                 */
      case ft_encoding_adobe_custom:
        {
          T1_Encoding*  encoding = &face->type1.encoding;


          if ( charcode >= encoding->code_first &&
               charcode <= encoding->code_last  )
            result = encoding->char_index[charcode];
          goto Exit;
        }

        /*******************************************************************/
        /*                                                                 */
        /* Adobe Standard & Expert encoding support                        */
        /*                                                                 */
      default:
        if ( charcode < 256 )
        {
          FT_UInt      code;
          FT_Int       n;
          const char*  glyph_name;


          code = psnames->adobe_std_encoding[charcode];
          if ( charmap->encoding == ft_encoding_adobe_expert )
            code = psnames->adobe_expert_encoding[charcode];

          glyph_name = psnames->adobe_std_strings( code );
          if ( !glyph_name )
            break;

          for ( n = 0; n < face->type1.num_glyphs; n++ )
          {
            const char*  gname = face->type1.glyph_names[n];


            if ( gname && gname[0] == glyph_name[0] &&
                 strcmp( gname, glyph_name ) == 0   )
            {
              result = n;
              break;
            }
          }
        }
      }
  Exit:
    return result;
  }
示例#2
0
文件: t1objs.c 项目: Skiles/aseprite
  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;
  }
示例#3
0
  static FT_Long
  CID_Get_Next_Char( FT_CharMap  charmap,
                     FT_Long     charcode )
  {
    T1_Face             face;
    PSNames_Interface*  psnames;


    face    = (T1_Face)charmap->face;
    psnames = (PSNames_Interface*)face->psnames;

    if ( psnames )
      switch ( charmap->encoding )
      {
        /*******************************************************************/
        /*                                                                 */
        /* Unicode encoding support                                        */
        /*                                                                 */
      case ft_encoding_unicode:
        /* use the `PSNames' module to synthetize the Unicode charmap */
        return psnames->next_unicode (&face->unicode_map,
                                      (FT_ULong)charcode );

        /*******************************************************************/
        /*                                                                 */
        /* Custom Type 1 encoding                                          */
        /*                                                                 */
      case ft_encoding_adobe_custom:
        {
          T1_Encoding*  encoding = &face->type1.encoding;


          charcode++;
          if ( charcode < encoding->code_first )
            charcode = encoding->code_first;
          while ( charcode <= encoding->code_last )
          {
            if ( encoding->char_index[charcode] )
              return charcode;
            charcode++;
          }
        }
        break;

        /*******************************************************************/
        /*                                                                 */
        /* Adobe Standard & Expert encoding support                        */
        /*                                                                 */
      default:
        while ( ++charcode < 256 )
        {
          FT_UInt      code;
          FT_Int       n;
          const char*  glyph_name;


          code = psnames->adobe_std_encoding[charcode];
          if ( charmap->encoding == ft_encoding_adobe_expert )
            code = psnames->adobe_expert_encoding[charcode];

          glyph_name = psnames->adobe_std_strings( code );
          if ( !glyph_name )
            continue;

          for ( n = 0; n < face->type1.num_glyphs; n++ )
          {
            const char*  gname = face->type1.glyph_names[n];


            if ( gname && gname[0] == glyph_name[0] &&
                 strcmp( gname, glyph_name ) == 0   )
            {
              return charcode;
            }
          }
        }
      }

    return 0;
  }