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

📄 ttsbit.c

📁 Qt/Embedded是一个多平台的C++图形用户界面应用程序框架
💻 C
📖 第 1 页 / 共 4 页
字号:
      TT_Byte*  limit;      TT_Byte   mask;      line  = (TT_Byte*)map->buffer + (right >> 3);      limit = line + rows*line_len;      mask  = 0x80 >> (right & 7);      for ( ; line < limit; line += line_len )        if ( line[0] & mask )          goto Found_Right;      /* crop the whole glyph to the right */      map->width--;      metrics->width--;    } while ( map->width > 0 );  Found_Right:    /* all right, the bitmap was cropped */    return;  Empty_Bitmap:    map->width      = 0;    map->rows       = 0;    map->pitch      = 0;    map->pixel_mode = ft_pixel_mode_mono;  }  static  TT_Error Load_SBit_Single( FT_Bitmap*        map,                             TT_Int            x_offset,                             TT_Int            y_offset,                             TT_Int            pix_bits,                             TT_UShort         image_format,                             TT_SBit_Metrics*  metrics,                             FT_Stream         stream )  {    TT_Error  error;    /* check that the source bitmap fits into the target pixmap */    if ( x_offset < 0 || x_offset + metrics->width  > map->width ||         y_offset < 0 || y_offset + metrics->height > map->rows  )    {      error = TT_Err_Invalid_Argument;      goto Exit;    }    {      TT_Int  glyph_width  = metrics->width;      TT_Int  glyph_height = metrics->height;      TT_Int  glyph_size;      TT_Int  line_bits    = pix_bits * glyph_width;      TT_Bool pad_bytes    = 0;      /* compute size of glyph image */      switch ( image_format )      {      case 1:  /* byte-padded formats */      case 6:        {          TT_Int  line_length;          switch ( pix_bits )          {          case 1:  line_length = (glyph_width+7) >> 3;   break;          case 2:  line_length = (glyph_width+3) >> 2;   break;          case 4:  line_length = (glyph_width+1) >> 1;   break;          default: line_length =  glyph_width;          }          glyph_size = glyph_height * line_length;          pad_bytes  = 1;        }        break;      case 2:      case 5:      case 7:        line_bits  =  glyph_width * pix_bits;        glyph_size = (glyph_height * line_bits + 7) >> 3;        break;      default:  /* invalid format */        return TT_Err_Invalid_File_Format;      }      /* Now read data and draw glyph into target pixmap       */      if ( ACCESS_Frame( glyph_size ) )        goto Exit;      /* don't forget to multiply `x_offset' by `map->pix_bits' as */      /* the sbit blitter doesn't make a difference between pixmap */      /* depths.                                                   */      blit_sbit( map, stream->cursor, line_bits, pad_bytes,                 x_offset * pix_bits, y_offset );      FORGET_Frame();    }  Exit:    return error;  }  static  TT_Error Load_SBit_Image( TT_SBit_Strike*   strike,                            TT_SBit_Range*    range,                            TT_ULong          ebdt_pos,                            TT_ULong          glyph_offset,                            FT_Bitmap*        map,                            TT_Int            x_offset,                            TT_Int            y_offset,                            FT_Stream         stream,                            TT_SBit_Metrics*  metrics )  {    FT_Memory            memory = stream->memory;    TT_Error             error;    /* place stream at beginning of glyph data and read metrics */    if ( FILE_Seek( ebdt_pos + glyph_offset ) )      goto Exit;    error = Load_SBit_Metrics( stream, range, metrics );    if ( error )      goto Exit;    /* this function is recursive.  At the top-level call, the */    /* field map.buffer is NULL.  We thus begin by finding the */    /* dimensions of the higher-level glyph to allocate the    */    /* final pixmap buffer                                     */    if ( map->buffer == 0 )    {      TT_Long  size;      map->width    = metrics->width;      map->rows     = metrics->height;      switch ( strike->bit_depth )      {      case 1:        map->pixel_mode = ft_pixel_mode_mono;         map->pitch      = (map->width+7) >> 3;        break;      case 2:        map->pixel_mode = ft_pixel_mode_pal2;         map->pitch      = (map->width+3) >> 2;        break;      case 4:        map->pixel_mode = ft_pixel_mode_pal4;         map->pitch      = (map->width+1) >> 1;        break;      case 8:        map->pixel_mode = ft_pixel_mode_grays;         map->pitch      = map->width;        break;      default:        return TT_Err_Invalid_File_Format;      }      size = map->rows * map->pitch;      /* check that there is no empty image */      if ( size == 0 )        goto Exit;     /* exit successfully! */      if ( ALLOC( map->buffer, size ) )        goto Exit;    }    switch ( range->image_format )    {    case 1:  /* single sbit image - load it */    case 2:    case 5:    case 6:    case 7:      return Load_SBit_Single( map, x_offset, y_offset, strike->bit_depth,                               range->image_format, metrics, stream );    case 8:  /* compound format */    case 9:      break;    default: /* invalid image format */      return TT_Err_Invalid_File_Format;    }    /* All right, we're in a compound format.  First of all, read */    /* the array of elements                                      */    {      TT_SBit_Component*  components;      TT_SBit_Component*  comp;      TT_UShort           num_components, count;      if ( READ_UShort( num_components )                                ||           ALLOC_ARRAY( components, num_components, TT_SBit_Component ) )        goto Exit;      count = num_components;      if ( ACCESS_Frame( 4L * num_components ) )        goto Fail_Memory;      for ( comp = components; count > 0; count--, comp++ )      {        comp->glyph_code = GET_UShort();        comp->x_offset   = GET_Char();        comp->y_offset   = GET_Char();      }      FORGET_Frame();      /* Now recursively load each element glyph */      count = num_components;      comp  = components;      for ( ; count > 0; count--, comp++ )      {        TT_SBit_Range*   elem_range;        TT_SBit_Metrics  elem_metrics;        TT_ULong         elem_offset;        /* find the range for this element */        error = Find_SBit_Range( comp->glyph_code,                                 strike,                                 &elem_range,                                 &elem_offset );        if ( error )          goto Fail_Memory;        /* now load the element, recursively */        error = Load_SBit_Image( strike,                                 elem_range,                                 ebdt_pos,                                 elem_offset,                                 map,                                 x_offset + comp->x_offset,                                 y_offset + comp->y_offset,                                 stream,                                 &elem_metrics );        if ( error )          goto Fail_Memory;      }    Fail_Memory:      FREE( components );    }  Exit:    return error;  }  /*************************************************************************/  /*                                                                       */  /* <Function>                                                            */  /*    TT_Load_SBit_Image                                                 */  /*                                                                       */  /* <Description>                                                         */  /*    Loads a given glyph sbit image from the font resource.  This also  */  /*    returns its metrics.                                               */  /*                                                                       */  /* <Input>                                                               */  /*    face        :: The target face object.                             */  /*                                                                       */  /*    x_ppem      :: The horizontal resolution in points per EM.         */  /*                                                                       */  /*    y_ppem      :: The vertical resolution in points per EM.           */  /*                                                                       */  /*    glyph_index :: The current glyph index.                            */  /*                                                                       */  /*    stream      :: The input stream.                                   */  /*                                                                       */  /* <Output>                                                              */  /*    map         :: The target pixmap.                                  */  /*    metrics     :: A big sbit metrics structure for the glyph image.   */  /*                                                                       */  /* <Return>                                                              */  /*    TrueType error code.  0 means success.  Returns an error if no     */  /*    glyph sbit exists for the index.                                   */  /*                                                                       */  /*  <Note>                                                               */  /*    The `map.buffer' field is always freed before the glyph is loaded. */  /*                                                                       */  LOCAL_FUNC  TT_Error  TT_Load_SBit_Image( TT_Face           face,                                TT_Int            x_ppem,                                TT_Int            y_ppem,                                TT_UInt           glyph_index,                                FT_Stream         stream,                                FT_Bitmap*        map,                                TT_SBit_Metrics*  metrics )  {    TT_Error         error;    FT_Memory        memory = stream->memory;    TT_ULong         ebdt_pos, glyph_offset;    TT_SBit_Strike*  strike;    TT_SBit_Range*   range;    /* Check whether there is a glyph sbit for the current index */    error = Find_SBit_Image( face, glyph_index, x_ppem, y_ppem,                             &range, &strike, &glyph_offset );    if ( error )      goto Exit;    /* now, find the location of the `EBDT' table in */    /* the font file                                 */    error = face->goto_table( face, TTAG_EBDT, stream, 0 );    if (error) goto Exit;        ebdt_pos = FILE_Pos();    /* clear the bitmap & load the bitmap */    FREE( map->buffer );    map->rows = map->pitch = map->width = 0;    error = Load_SBit_Image( strike, range, ebdt_pos, glyph_offset,                             map, 0, 0, stream, metrics );    if ( error )      goto Exit;    /* setup vertical metrics if needed */    if ( strike->flags & 1 )    {      /* in case of a horizontal strike only */      FT_Int  advance;      FT_Int  top;      advance = strike->hori.ascender - strike->hori.descender;      top     = advance / 10;      metrics->vertBearingX = -metrics->width / 2;      metrics->vertBearingY =  advance / 10;      metrics->vertAdvance  =  advance * 12 / 10;    }    /* Crop the bitmap now */    Crop_Bitmap( map, metrics );  Exit:    return error;  }/* END */

⌨️ 快捷键说明

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