⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ttdriver.c

📁 Qt/Embedded是一个多平台的C++图形用户界面应用程序框架
💻 C
📖 第 1 页 / 共 2 页
字号:
/***************************************************************************//*                                                                         *//*  ttdriver.c                                                             *//*                                                                         *//*    TrueType font driver implementation (body).                          *//*                                                                         *//*  Copyright 1996-1999 by                                                 *//*  David Turner, Robert Wilhelm, and Werner Lemberg.                      *//*                                                                         *//*  This file is part of the FreeType project, and may only be used,       *//*  modified, and distributed under the terms of the FreeType project      *//*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     *//*  this file you indicate that you have read the license and              *//*  understand and accept it fully.                                        *//*                                                                         *//***************************************************************************/#include <ftdebug.h>#include <ftstream.h>#include <ttnameid.h>#include <sfnt.h>#include <ttdriver.h>#include <ttgload.h>#undef  FT_COMPONENT#define FT_COMPONENT  trace_ttdriver  /*************************************************************************/  /*************************************************************************/  /*************************************************************************/  /****                                                                 ****/  /****                                                                 ****/  /****                          F A C E S                              ****/  /****                                                                 ****/  /****                                                                 ****/  /*************************************************************************/  /*************************************************************************/  /*************************************************************************/ /******************************************************************  *  * <Function>  *    find_encoding  *  * <Description>  *    return the FT_Encoding corresponding to a given   *    (platform_id,encoding_id) pair, as found in TrueType charmaps  *  * <Input>  *   platform_id ::  *   encoding_id ::  *  * <Return>  *   the corresponding FT_Encoding tag. ft_encoding_none by default  *  *****************************************************************/    static  FT_Encoding   find_encoding( int  platform_id,                               int  encoding_id )  {    typedef struct  TEncoding    {      int          platform_id;      int          encoding_id;      FT_Encoding  encoding;      } TEncoding;    static    const TEncoding   tt_encodings[] =    {      { TT_PLATFORM_ISO,                         -1, ft_encoding_unicode },              { TT_PLATFORM_APPLE_UNICODE,               -1, ft_encoding_unicode },            { TT_PLATFORM_MACINTOSH,      TT_MAC_ID_ROMAN, ft_encoding_apple_roman },            { TT_PLATFORM_MICROSOFT,  TT_MS_ID_UNICODE_CS, ft_encoding_unicode },      { TT_PLATFORM_MICROSOFT,  TT_MS_ID_SJIS,       ft_encoding_sjis },      { TT_PLATFORM_MICROSOFT,  TT_MS_ID_BIG_5,      ft_encoding_big5 }    };        const TEncoding  *cur, *limit;       cur   = tt_encodings;    limit = cur + sizeof(tt_encodings)/sizeof(tt_encodings[0]);        for ( ; cur < limit; cur++ )    {      if (cur->platform_id == platform_id)      {        if (cur->encoding_id == encoding_id ||            cur->encoding_id == -1          )          return cur->encoding;      }    }    return ft_encoding_none;  }  /*************************************************************************/  /*                                                                       */  /* <Function>                                                            */  /*    Init_Face                                                          */  /*                                                                       */  /* <Description>                                                         */  /*    A driver method used to initialize a new TrueType face object.     */  /*                                                                       */  /* <Input>                                                               */  /*    resource       :: A handle to the source resource.                 */  /*                                                                       */  /*    typeface_index :: An index of the face in the font resource.  Used */  /*                      to access individual faces in font collections.  */  /*                                                                       */  /* <InOut>                                                               */  /*    face           :: A handle to the face object.                     */  /*                                                                       */  /* <Return>                                                              */  /*    FreeType error code.  0 means success.                             */  /*                                                                       */  /* <Note>                                                                */  /*    The `typeface_index' parameter field will be set to -1 if the      */  /*    engine only wants to test the format of the resource.  This means  */  /*    that font drivers should simply check the font format, then return */  /*    immediately with an error code of 0 (meaning success).  The field  */  /*    `num_faces' should be set.                                         */  /*                                                                       */  /*    Done_Face() will be called subsequently, whatever the result was.  */  /*                                                                       */  static  TT_Error  Init_Face( FT_Stream  stream,                       TT_Long    typeface_index,                       TT_Face    face )  {    TT_Error     error;    /* initialize the TrueType face object */    error = TT_Init_Face( stream, typeface_index, face );    /* now set up root fields */    if ( !error && typeface_index >= 0 )    {      FT_Face     root = &face->root;      FT_Int      flags;      TT_CharMap  charmap;      TT_Int      n;      FT_Memory   memory;      memory = root->memory;      /*****************************************************************/      /*                                                               */      /* Compute face flags.                                           */      /*                                                               */      flags = FT_FACE_FLAG_SCALABLE  |    /* scalable outlines */              FT_FACE_FLAG_SFNT      |    /* SFNT file format  */              FT_FACE_FLAG_HORIZONTAL;    /* horizontal data   */      /* fixed width font ? */      if ( face->postscript.isFixedPitch )        flags |= FT_FACE_FLAG_FIXED_WIDTH;      /* vertical information ? */      if ( face->vertical_info )        flags |= FT_FACE_FLAG_VERTICAL;      /* kerning available ? */      if ( face->kern_pairs )        flags |= FT_FACE_FLAG_KERNING;      root->face_flags = flags;      /*****************************************************************/      /*                                                               */      /* Compute style flags.                                          */      /*                                                               */      flags = 0;      if ( face->os2.version != 0xFFFF )      {        /* We have an OS/2 table, use the `fsSelection' field */        if ( face->os2.fsSelection & 1 )          flags |= FT_STYLE_FLAG_ITALIC;        if ( face->os2.fsSelection & 32 )          flags |= FT_STYLE_FLAG_BOLD;      }      else      {        /* This is an old Mac font, use the header field */        if ( face->header.Mac_Style & 1 )          flags |= FT_STYLE_FLAG_BOLD;        if ( face->header.Mac_Style & 2 )          flags |= FT_STYLE_FLAG_ITALIC;      }      face->root.style_flags = flags;      /*****************************************************************/      /*                                                               */      /* Polish the charmaps.                                          */      /*                                                               */      /*   Try to set the charmap encoding according to the platform & */      /*   encoding ID of each charmap.                                */      /*                                                               */      charmap            = face->charmaps;      root->num_charmaps = face->num_charmaps;      /* allocate table of pointers */      if ( ALLOC_ARRAY( root->charmaps, root->num_charmaps, FT_CharMap ) )        return error;      for ( n = 0; n < root->num_charmaps; n++, charmap++ )      {        FT_Int  platform = charmap->cmap.platformID;        FT_Int  encoding = charmap->cmap.platformEncodingID;        charmap->root.face        = (FT_Face)face;        charmap->root.platform_id = platform;        charmap->root.encoding_id = encoding;        charmap->root.encoding    = find_encoding(platform,encoding);        /* now, set root->charmap with a unicode charmap wherever available */        if (!root->charmap && charmap->root.encoding == ft_encoding_unicode)          root->charmap = (FT_CharMap)charmap;                root->charmaps[n] = (FT_CharMap)charmap;      }      root->num_fixed_sizes = 0;      root->available_sizes = 0;      /*****************************************************************/      /*                                                               */      /*  Set up metrics.                                              */      /*                                                               */      root->bbox.xMin    = face->header.xMin;      root->bbox.yMin    = face->header.yMin;      root->bbox.xMax    = face->header.xMax;      root->bbox.yMax    = face->header.yMax;      root->units_per_EM = face->header.Units_Per_EM;      /* The ascender/descender/height are computed from the OS/2 table   */      /* when found.  Otherwise, they're taken from the horizontal header */      if ( face->os2.version != 0xFFFF )      {        root->ascender  =  face->os2.sTypoAscender;        root->descender = -face->os2.sTypoDescender;        root->height    =  root->ascender + root->descender +                           face->os2.sTypoLineGap;      }      else      {        root->ascender  = face->horizontal.Ascender;        root->descender = face->horizontal.Descender;        root->height    = root->ascender + root->descender +                          face->horizontal.Line_Gap;      }      root->max_advance_width  = face->horizontal.advance_Width_Max;      root->max_advance_height = root->height;      if ( face->vertical_info )        root->max_advance_height = face->vertical.advance_Height_Max;      root->underline_position  = face->postscript.underlinePosition;      root->underline_thickness = face->postscript.underlineThickness;      /* root->max_points      - already set up */      /* root->max_contours    - already set up */    }    return error;  }#undef  PAIR_TAG#define PAIR_TAG( left, right )  ( ((TT_ULong)left << 16) | (TT_ULong)right )  /*************************************************************************/  /*                                                                       */  /* <Function>                                                            */  /*    Get_Kerning                                                        */  /*                                                                       */  /* <Description>                                                         */  /*    A driver method used to return the kerning vector between two      */  /*    glyphs of the same face.                                           */  /*                                                                       */  /* <Input>                                                               */  /*    face        :: A handle to the source face object.                 */  /*                                                                       */  /*    left_glyph  :: The index of the left glyph in the kern pair.       */  /*                                                                       */  /*    right_glyph :: The index of the right glyph in the kern pair.      */  /*                                                                       */  /* <Output>                                                              */  /*    kerning     :: The kerning vector.  This is in font units for      */  /*                   scalable formats, and in pixels for fixed-sizes     */  /*                   formats.                                            */  /*                                                                       */  /* <Return>                                                              */  /*    FreeType error code.  0 means success.                             */  /*                                                                       */  /* <Note>                                                                */  /*    Only horizontal layouts (left-to-right & right-to-left) are        */  /*    supported by this function.  Other layouts, or more sophisticated  */  /*    kernings are out of scope of this method (the basic driver         */  /*    interface is meant to be simple).                                  */  /*                                                                       */  /*    They can be implemented by format-specific interfaces.             */  /*                                                                       */  static  TT_Error  Get_Kerning( TT_Face     face,                         TT_UInt     left_glyph,                         TT_UInt     right_glyph,                         TT_Vector*  kerning )  {    TT_Kern_0_Pair*  pair;    if ( !face )      return TT_Err_Invalid_Face_Handle;    kerning->x = 0;    kerning->y = 0;    if ( face->kern_pairs )    {      /* there are some kerning pairs in this font file! */      TT_ULong  search_tag = PAIR_TAG( left_glyph, right_glyph );      TT_Long   left, right;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -