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

📄 winfnt.c

📁 qt-embedded-2.3.8.tar.gz源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/***************************************************************************//*                                                                         *//*  winfnt.c                                                               *//*                                                                         *//*    FreeType font driver for Windows FNT/FON files                       *//*                                                                         *//*  Copyright 1996-2000 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.                                        *//*                                                                         *//***************************************************************************/#ifdef FT_FLAT_COMPILE#include "winfnt.h"#else#include <winfonts/winfnt.h>#endif#include <freetype/fterrors.h>#include <freetype/internal/ftstream.h>#include <freetype/internal/ftdebug.h>#include <freetype/internal/ftobjs.h>#include <freetype/internal/fnttypes.h>  /*************************************************************************/  /*                                                                       */  /* The macro FT_COMPONENT is used in trace mode.  It is an implicit      */  /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log  */  /* messages during execution.                                            */  /*                                                                       */#undef  FT_COMPONENT#define FT_COMPONENT  trace_winfnt  static  const FT_Frame_Field  winmz_header_fields[] =  {#undef  FT_STRUCTURE#define FT_STRUCTURE  WinMZ_Header    FT_FRAME_START( 64 ),      FT_FRAME_USHORT_LE ( magic ),      FT_FRAME_SKIP_BYTES( 29 * 2 ),      FT_FRAME_ULONG_LE  ( lfanew ),    FT_FRAME_END  };  static  const FT_Frame_Field  winne_header_fields[] =  {#undef  FT_STRUCTURE#define FT_STRUCTURE  WinNE_Header    FT_FRAME_START( 40 ),      FT_FRAME_USHORT_LE ( magic ),      FT_FRAME_SKIP_BYTES( 34 ),      FT_FRAME_USHORT_LE ( resource_tab_offset ),      FT_FRAME_USHORT_LE ( rname_tab_offset ),    FT_FRAME_END  };  static  const FT_Frame_Field  winfnt_header_fields[] =  {#undef  FT_STRUCTURE#define FT_STRUCTURE  WinFNT_Header    FT_FRAME_START( 134 ),      FT_FRAME_USHORT_LE( version ),      FT_FRAME_ULONG_LE ( file_size ),      FT_FRAME_BYTES    ( copyright, 60 ),      FT_FRAME_USHORT_LE( file_type ),      FT_FRAME_USHORT_LE( nominal_point_size ),      FT_FRAME_USHORT_LE( vertical_resolution ),      FT_FRAME_USHORT_LE( horizontal_resolution ),      FT_FRAME_USHORT_LE( ascent ),      FT_FRAME_USHORT_LE( internal_leading ),      FT_FRAME_USHORT_LE( external_leading ),      FT_FRAME_BYTE     ( italic ),      FT_FRAME_BYTE     ( underline ),      FT_FRAME_BYTE     ( strike_out ),      FT_FRAME_USHORT_LE( weight ),      FT_FRAME_BYTE     ( charset ),      FT_FRAME_USHORT_LE( pixel_width ),      FT_FRAME_USHORT_LE( pixel_height ),      FT_FRAME_BYTE     ( pitch_and_family ),      FT_FRAME_USHORT_LE( avg_width ),      FT_FRAME_USHORT_LE( max_width ),      FT_FRAME_BYTE     ( first_char ),      FT_FRAME_BYTE     ( last_char ),      FT_FRAME_BYTE     ( default_char ),      FT_FRAME_BYTE     ( break_char ),      FT_FRAME_USHORT_LE( bytes_per_row ),      FT_FRAME_ULONG_LE ( device_offset ),      FT_FRAME_ULONG_LE ( face_name_offset ),      FT_FRAME_ULONG_LE ( bits_pointer ),      FT_FRAME_ULONG_LE ( bits_offset ),      FT_FRAME_BYTE     ( reserved ),      FT_FRAME_ULONG_LE ( flags ),      FT_FRAME_USHORT_LE( A_space ),      FT_FRAME_USHORT_LE( B_space ),      FT_FRAME_USHORT_LE( C_space ),      FT_FRAME_USHORT_LE( color_table_offset ),      FT_FRAME_BYTES    ( reserved, 4 ),    FT_FRAME_END  };  static  void  fnt_done_font( FT_Stream  stream,                       FNT_Font*  font )  {    if ( font->fnt_frame )      RELEASE_Frame( font->fnt_frame );    font->fnt_size  = 0;    font->fnt_frame = 0;  }  static  FT_Error  fnt_load_font( FT_Stream  stream,                           FNT_Font*  font )  {    FT_Error        error;    WinFNT_Header*  header = &font->header;    /* first of all, read the FNT header */    if ( FILE_Seek( font->offset )                   ||         READ_Fields( winfnt_header_fields, header ) )      goto Exit;    /* check header */    if ( header->version != 0x200 &&         header->version != 0x300 )    {      FT_TRACE2(( "[not a valid FNT file]\n" ));      error = FT_Err_Unknown_File_Format;      goto Exit;    }    if ( header->file_type & 1 )    {      FT_TRACE2(( "[can't handle vector FNT fonts]\n" ));      error = FT_Err_Unknown_File_Format;      goto Exit;    }    /* small fixup -- some fonts have the `pixel_width' field set to 0 */    if ( header->pixel_width == 0 )      header->pixel_width = header->pixel_height;    /* this is a FNT file/table, we now extract its frame */    if ( FILE_Seek( font->offset )                           ||         EXTRACT_Frame( header->file_size, font->fnt_frame ) )      goto Exit;  Exit:    return error;  }  static  void  fnt_done_fonts( FNT_Face  face )  {    FT_Memory  memory = FT_FACE(face)->memory;    FT_Stream  stream = FT_FACE(face)->stream;    FNT_Font*  cur    = face->fonts;    FNT_Font*  limit  = cur + face->num_fonts;    for ( ; cur < limit; cur++ )      fnt_done_font( stream, cur );    FREE( face->fonts );    face->num_fonts = 0;  }  static  FT_Error  fnt_get_dll_fonts( FNT_Face  face )  {    FT_Error      error;    FT_Stream     stream = FT_FACE(face)->stream;    FT_Memory     memory = FT_FACE(face)->memory;    WinMZ_Header  mz_header;    face->fonts     = 0;    face->num_fonts = 0;    /* does it begin with a MZ header? */    if ( FILE_Seek( 0 )                                 ||         READ_Fields( winmz_header_fields, &mz_header ) )      goto Exit;    error = FT_Err_Unknown_File_Format;    if ( mz_header.magic == WINFNT_MZ_MAGIC )    {      /* yes, now look for a NE header in the file */      WinNE_Header  ne_header;      if ( FILE_Seek( mz_header.lfanew )                  ||           READ_Fields( winne_header_fields, &ne_header ) )        goto Exit;      error = FT_Err_Unknown_File_Format;      if ( ne_header.magic == WINFNT_NE_MAGIC )      {        /* good, now look in the resource table for each FNT resource */        FT_ULong   res_offset = mz_header.lfanew +                                ne_header.resource_tab_offset;        FT_UShort  size_shift;        FT_UShort  font_count  = 0;        FT_ULong   font_offset = 0;        if ( FILE_Seek( res_offset ) ||             ACCESS_Frame( ne_header.rname_tab_offset -                           ne_header.resource_tab_offset ) )          goto Exit;        size_shift = GET_UShortLE();        for (;;)        {          FT_UShort  type_id, count;          type_id = GET_UShortLE();          if ( !type_id )            break;          count = GET_UShortLE();          if ( type_id == 0x8008 )          {            font_count  = count;            font_offset = FILE_Pos() + 4 + ( stream->cursor - stream->limit );            break;          }          stream->cursor += 4 + count * 12;        }        FORGET_Frame();        if ( !font_count || !font_offset )        {          FT_TRACE2(( "this file doesn't contain any FNT resources!\n" ));          error = FT_Err_Unknown_File_Format;          goto Exit;        }        if ( FILE_Seek( font_offset )                         ||             ALLOC_ARRAY( face->fonts, font_count, FNT_Font ) )          goto Exit;        face->num_fonts = font_count;        if ( ACCESS_Frame( (FT_Long)font_count * 12 ) )          goto Exit;        /* now read the offset and position of each FNT font */        {          FNT_Font*  cur   = face->fonts;          FNT_Font*  limit = cur + font_count;          for ( ; cur < limit; cur++ )          {            cur->offset     = (FT_ULong)GET_UShortLE() << size_shift;            cur->fnt_size   = (FT_ULong)GET_UShortLE() << size_shift;            cur->size_shift = size_shift;            stream->cursor += 8;          }        }        FORGET_Frame();        /* finally, try to load each font there */        {          FNT_Font*  cur   = face->fonts;          FNT_Font*  limit = cur + font_count;          for ( ; cur < limit; cur++ )          {            error = fnt_load_font( stream, cur );            if ( error )              goto Fail;          }        }      }    }  Fail:    if ( error )      fnt_done_fonts( face );  Exit:    return error;  }  static  void  FNT_Done_Face( FNT_Face  face )  {    FT_Memory  memory = FT_FACE_MEMORY( face );    fnt_done_fonts( face );    FREE( face->root.available_sizes );    face->root.num_fixed_sizes = 0;  }  static  FT_Error  FNT_Init_Face( FT_Stream      stream,

⌨️ 快捷键说明

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