Пример #1
0
  static FT_Error
  FNT_Size_Set_Pixels( FNT_Size  size )
  {
    /* look up a font corresponding to the current pixel size */
    FNT_Face   face  = (FNT_Face)FT_SIZE_FACE( size );
    FNT_Font*  cur   = face->fonts;
    FNT_Font*  limit = cur + face->num_fonts;


    size->font = 0;
    for ( ; cur < limit; cur++ )
    {
      /* we only compare the character height, as fonts used some strange */
      /* values                                                           */
      if ( cur->header.pixel_height == size->root.metrics.y_ppem )
      {
        size->font = cur;

        size->root.metrics.ascender  = cur->header.ascent * 64;
        size->root.metrics.descender = ( cur->header.pixel_height -
                                           cur->header.ascent ) * 64;
        size->root.metrics.height    = cur->header.pixel_height * 64;
        break;
      }
    }

    return ( size->font ? FNT_Err_Ok : FNT_Err_Invalid_Pixel_Size );
  }
Пример #2
0
  static FT_Error
  PCF_Set_Pixel_Size( FT_Size  size )
  {
    PCF_Face face = (PCF_Face)FT_SIZE_FACE( size );


    FT_TRACE4(( "rec %d - pres %d\n", size->metrics.y_ppem,
                                      face->root.available_sizes->height ));

    if ( size->metrics.y_ppem == face->root.available_sizes->height )
    {
      size->metrics.ascender    = face->accel.fontAscent << 6;
      size->metrics.descender   = face->accel.fontDescent * (-64);
#if 0
      size->metrics.height      = face->accel.maxbounds.ascent << 6;
#endif
      size->metrics.height      = size->metrics.ascender -
                                  size->metrics.descender;

      size->metrics.max_advance = face->accel.maxbounds.characterWidth << 6;

      return PCF_Err_Ok;
    }
    else
    {
      FT_TRACE4(( "size WRONG\n" ));
      return PCF_Err_Invalid_Pixel_Size;
    }
  }
Пример #3
0
static FT_Error
FNT_Size_Set_Pixels( FT_Size  size )
{
    FNT_Face  face = (FNT_Face)FT_SIZE_FACE( size );
    FT_Face   root = FT_FACE( face );


    if ( size->metrics.y_ppem == root->available_sizes->height )
    {
        FNT_Font  font = face->font;


        size->metrics.ascender    = font->header.ascent * 64;
        size->metrics.descender   = ( font->header.pixel_height -
                                      font->header.ascent ) * 64;
        size->metrics.height      = font->header.pixel_height * 64;
        size->metrics.max_advance = font->header.max_width * 64;

        return FNT_Err_Ok;
    }
    else
        return FNT_Err_Invalid_Pixel_Size;
}
Пример #4
0
  static FT_Error
  PCF_Glyph_Load( FT_GlyphSlot  slot,
                  FT_Size       size,
                  FT_UInt       glyph_index,
                  FT_Int32      load_flags )
  {
    PCF_Face    face   = (PCF_Face)FT_SIZE_FACE( size );
    FT_Stream   stream = face->root.stream;
    FT_Error    error  = PCF_Err_Ok;
    FT_Bitmap*  bitmap = &slot->bitmap;
    PCF_Metric  metric;
    int         bytes;

    FT_UNUSED( load_flags );


    FT_TRACE4(( "load_glyph %d ---", glyph_index ));

    if ( !face )
    {
      error = PCF_Err_Invalid_Argument;
      goto Exit;
    }

    if ( glyph_index > 0 )
      glyph_index--;

    metric = face->metrics + glyph_index;

    bitmap->rows       = metric->ascent + metric->descent;
    bitmap->width      = metric->rightSideBearing - metric->leftSideBearing;
    bitmap->num_grays  = 1;
    bitmap->pixel_mode = FT_PIXEL_MODE_MONO;

    FT_TRACE6(( "BIT_ORDER %d ; BYTE_ORDER %d ; GLYPH_PAD %d\n",
                  PCF_BIT_ORDER( face->bitmapsFormat ),
                  PCF_BYTE_ORDER( face->bitmapsFormat ),
                  PCF_GLYPH_PAD( face->bitmapsFormat ) ));

    switch ( PCF_GLYPH_PAD( face->bitmapsFormat ) )
    {
    case 1:
      bitmap->pitch = ( bitmap->width + 7 ) >> 3;
      break;

    case 2:
      bitmap->pitch = ( ( bitmap->width + 15 ) >> 4 ) << 1;
      break;

    case 4:
      bitmap->pitch = ( ( bitmap->width + 31 ) >> 5 ) << 2;
      break;

    case 8:
      bitmap->pitch = ( ( bitmap->width + 63 ) >> 6 ) << 3;
      break;

    default:
      return PCF_Err_Invalid_File_Format;
    }

    /* XXX: to do: are there cases that need repadding the bitmap? */
    bytes = bitmap->pitch * bitmap->rows;

    error = ft_glyphslot_alloc_bitmap( slot, bytes );
    if ( error )
      goto Exit;

    if ( FT_STREAM_SEEK( metric->bits )          ||
         FT_STREAM_READ( bitmap->buffer, bytes ) )
      goto Exit;

    if ( PCF_BIT_ORDER( face->bitmapsFormat ) != MSBFirst )
      BitOrderInvert( bitmap->buffer, bytes );

    if ( ( PCF_BYTE_ORDER( face->bitmapsFormat ) !=
           PCF_BIT_ORDER( face->bitmapsFormat )  ) )
    {
      switch ( PCF_SCAN_UNIT( face->bitmapsFormat ) )
      {
      case 1:
        break;

      case 2:
        TwoByteSwap( bitmap->buffer, bytes );
        break;

      case 4:
        FourByteSwap( bitmap->buffer, bytes );
        break;
      }
    }

    slot->bitmap_left = metric->leftSideBearing;
    slot->bitmap_top  = metric->ascent;

    slot->metrics.horiAdvance  = metric->characterWidth << 6;
    slot->metrics.horiBearingX = metric->leftSideBearing << 6;
    slot->metrics.horiBearingY = metric->ascent << 6;
    slot->metrics.width        = ( metric->rightSideBearing -
                                   metric->leftSideBearing ) << 6;
    slot->metrics.height       = bitmap->rows << 6;

    slot->linearHoriAdvance = (FT_Fixed)bitmap->width << 16;
    slot->format            = FT_GLYPH_FORMAT_BITMAP;

    FT_TRACE4(( " --- ok\n" ));

  Exit:
    return error;
  }
Пример #5
0
static FT_Error
FNT_Load_Glyph( FT_GlyphSlot  slot,
                FT_Size       size,
                FT_UInt       glyph_index,
                FT_Int32      load_flags )
{
    FNT_Face    face   = (FNT_Face)FT_SIZE_FACE( size );
    FNT_Font    font   = face->font;
    FT_Error    error  = FNT_Err_Ok;
    FT_Byte*    p;
    FT_Int      len;
    FT_Bitmap*  bitmap = &slot->bitmap;
    FT_ULong    offset;
    FT_Bool     new_format;

    FT_UNUSED( load_flags );


    if ( !face || !font )
    {
        error = FNT_Err_Invalid_Argument;
        goto Exit;
    }

    if ( glyph_index > 0 )
        glyph_index--;                           /* revert to real index */
    else
        glyph_index = font->header.default_char; /* the .notdef glyph */

    new_format = FT_BOOL( font->header.version == 0x300 );
    len        = new_format ? 6 : 4;

    /* jump to glyph entry */
    p = font->fnt_frame + ( new_format ? 146 : 118 ) + len * glyph_index;

    bitmap->width = FT_NEXT_SHORT_LE( p );

    if ( new_format )
        offset = FT_NEXT_ULONG_LE( p );
    else
        offset = FT_NEXT_USHORT_LE( p );

    /* jump to glyph data */
    p = font->fnt_frame + /* font->header.bits_offset */ + offset;

    /* allocate and build bitmap */
    {
        FT_Memory  memory = FT_FACE_MEMORY( slot->face );
        FT_Int     pitch  = ( bitmap->width + 7 ) >> 3;
        FT_Byte*   column;
        FT_Byte*   write;


        bitmap->pitch      = pitch;
        bitmap->rows       = font->header.pixel_height;
        bitmap->pixel_mode = FT_PIXEL_MODE_MONO;

        /* note: since glyphs are stored in columns and not in rows we */
        /*       can't use ft_glyphslot_set_bitmap                     */
        if ( FT_ALLOC( bitmap->buffer, pitch * bitmap->rows ) )
            goto Exit;

        column = (FT_Byte*)bitmap->buffer;

        for ( ; pitch > 0; pitch--, column++ )
        {
            FT_Byte*  limit = p + bitmap->rows;


            for ( write = column; p < limit; p++, write += bitmap->pitch )
                *write = *p;
        }
    }

    slot->internal->flags = FT_GLYPH_OWN_BITMAP;
    slot->bitmap_left     = 0;
    slot->bitmap_top      = font->header.ascent;
    slot->format          = FT_GLYPH_FORMAT_BITMAP;

    /* now set up metrics */
    slot->metrics.horiAdvance  = bitmap->width << 6;
    slot->metrics.horiBearingX = 0;
    slot->metrics.horiBearingY = slot->bitmap_top << 6;

    slot->linearHoriAdvance    = (FT_Fixed)bitmap->width << 16;
    slot->format               = FT_GLYPH_FORMAT_BITMAP;

Exit:
    return error;
}