fixed the sbit loader (src/base/sfnt/ttsbit.c)

introduced a new load flag (FT_LOAD_CROP_BITMAP) used
to indicate that we want embedded bitmaps to be cropped..

Thanks a lot to Yamano-uchi, Hidetoshi
This commit is contained in:
David Turner 2000-05-17 23:35:37 +00:00
parent 3475e7fba3
commit 109fcf6086
8 changed files with 107 additions and 51 deletions

View File

@ -1,5 +1,10 @@
LATEST_CHANGES LATEST_CHANGES
- fixed some bugs in the sbit loader (src/base/sfnt/ttsbit.c) + added
a new flag, FT_LOAD_CROP_BITMAP to query that bitmaps be cropped when
loaded from a file (maybe I should move the bitmap cropper to the
base layer ??).
- changed the default number of gray levels of the smooth renderer to - changed the default number of gray levels of the smooth renderer to
256 (instead of the previous 128). Of course, the human eye can't 256 (instead of the previous 128). Of course, the human eye can't
see any difference ;-) see any difference ;-)

View File

@ -1529,6 +1529,20 @@
/* */ /* */
#define FT_LOAD_FORCE_AUTOHINT 32 #define FT_LOAD_FORCE_AUTOHINT 32
/*************************************************************************/
/* */
/* <Constant> */
/* FT_LOAD_CROP_BITMAP */
/* */
/* <Description> */
/* A bit-field constant, used with FT_Load_Glyph() to indicate that */
/* the font driver should try to crop the bitmap (i.e. remove all */
/* space around its black bits) when loading it. For now, this */
/* really only works with Embedded Bitmaps in TrueType fonts.. */
/* */
/* */
#define FT_LOAD_CROP_BITMAP 64
/*************************************************************************/ /*************************************************************************/
/* */ /* */
/* <Constant> */ /* <Constant> */

View File

@ -166,6 +166,7 @@
TT_Int x_ppem, TT_Int x_ppem,
TT_Int y_ppem, TT_Int y_ppem,
TT_UInt glyph_index, TT_UInt glyph_index,
TT_UInt load_flags,
FT_Stream stream, FT_Stream stream,
FT_Bitmap* map, FT_Bitmap* map,
TT_SBit_Metrics* metrics ); TT_SBit_Metrics* metrics );

View File

@ -58,7 +58,7 @@
/* */ /* */
static static
void blit_sbit( FT_Bitmap* target, void blit_sbit( FT_Bitmap* target,
char* source, FT_Byte* source,
FT_Int line_bits, FT_Int line_bits,
FT_Bool byte_padded, FT_Bool byte_padded,
FT_Int x_offset, FT_Int x_offset,
@ -115,19 +115,19 @@
/* ensure that there are at least 8 bits in the accumulator */ /* ensure that there are at least 8 bits in the accumulator */
if ( loaded < 8 ) if ( loaded < 8 )
{ {
acc |= ((FT_UShort)*source++) << (8 - loaded); acc |= (FT_UShort)*source++ << (8 - loaded);
loaded += 8; loaded += 8;
} }
/* now write one byte */ /* now write one byte */
val = (FT_Byte)(acc >> 8); val = (FT_Byte)(acc >> 8);
if (shift) if (shift)
{ {
cur[0] |= val >> shift; cur[0] |= val >> shift;
cur[1] |= val << space; cur[1] |= val << space;
} }
else else
cur[0] = val; cur[0] |= val;
cur++; cur++;
acc <<= 8; /* remove bits from accumulator */ acc <<= 8; /* remove bits from accumulator */
@ -150,7 +150,7 @@
/* ensure that there are at least `count' bits in the accumulator */ /* ensure that there are at least `count' bits in the accumulator */
if ( loaded < count ) if ( loaded < count )
{ {
acc |= ((FT_UShort)*source++) << (8 - loaded); acc |= (FT_UShort)*source++ << (8 - loaded);
loaded += 8; loaded += 8;
} }
@ -464,6 +464,7 @@
TT_ULong num_strikes; TT_ULong num_strikes;
TT_ULong table_base; TT_ULong table_base;
face->num_sbit_strikes = 0;
/* this table is optional */ /* this table is optional */
error = face->goto_table( face, TTAG_EBLC, stream, 0 ); error = face->goto_table( face, TTAG_EBLC, stream, 0 );
@ -724,7 +725,7 @@
else else
*aglyph_offset = range->image_offset + *aglyph_offset = range->image_offset +
n * range->image_size; n * range->image_size;
break; goto Found;
} }
} }
} }
@ -734,9 +735,9 @@
goto Fail; goto Fail;
} }
Found:
/* return successfully! */ /* return successfully! */
*arange = range; *arange = range;
return 0; return 0;
} }
} }
@ -851,54 +852,55 @@
TT_Error error = TT_Err_Ok; TT_Error error = TT_Err_Ok;
switch ( range->index_format ) switch ( range->image_format )
{ {
case 1: /* variable metrics */ case 1:
case 3: case 2:
case 4: case 8:
{ /* variable small metrics */
switch ( range->image_format )
{ {
case 1: /* small metrics */ TT_SBit_Small_Metrics smetrics;
case 2:
case 8:
{
TT_SBit_Small_Metrics smetrics;
/* read small metrics */
/* read small metrics */ if ( ACCESS_Frame( 5L ) )
if ( ACCESS_Frame( 5L ) )
goto Exit;
TT_Load_Small_SBit_Metrics( &smetrics, stream );
FORGET_Frame();
/* convert it to a big metrics */
metrics->height = smetrics.height;
metrics->width = smetrics.width;
metrics->horiBearingX = smetrics.bearingX;
metrics->horiBearingY = smetrics.bearingY;
metrics->horiAdvance = smetrics.advance;
/* these metrics are made up at a higher level when */
/* needed. */
metrics->vertBearingX = 0;
metrics->vertBearingY = 0;
metrics->vertAdvance = 0;
}
break;
default: /* big metrics */
if ( ACCESS_Frame( 8L ) )
goto Exit; goto Exit;
TT_Load_SBit_Metrics( metrics, stream ); TT_Load_Small_SBit_Metrics( &smetrics, stream );
FORGET_Frame(); FORGET_Frame();
/* convert it to a big metrics */
metrics->height = smetrics.height;
metrics->width = smetrics.width;
metrics->horiBearingX = smetrics.bearingX;
metrics->horiBearingY = smetrics.bearingY;
metrics->horiAdvance = smetrics.advance;
/* these metrics are made up at a higher level when */
/* needed. */
metrics->vertBearingX = 0;
metrics->vertBearingY = 0;
metrics->vertAdvance = 0;
} }
break;
case 6:
case 7:
case 9:
/* variable big metrics */
{
if ( ACCESS_Frame( 8L ) )
goto Exit;
TT_Load_SBit_Metrics( metrics, stream );
FORGET_Frame();
} }
break; break;
default: /* constant metrics */ case 5:
*metrics = range->metrics; default: /* constant metrics */
} if ( range->index_format == 2 || range->index_format == 5 )
*metrics = range->metrics;
else
return FT_Err_Invalid_File_Format;
}
Exit: Exit:
return error; return error;
@ -1177,7 +1179,7 @@
/* don't forget to multiply `x_offset' by `map->pix_bits' as */ /* don't forget to multiply `x_offset' by `map->pix_bits' as */
/* the sbit blitter doesn't make a difference between pixmap */ /* the sbit blitter doesn't make a difference between pixmap */
/* depths. */ /* depths. */
blit_sbit( map, stream->cursor, line_bits, pad_bytes, blit_sbit( map, (FT_Byte*)stream->cursor, line_bits, pad_bytes,
x_offset * pix_bits, y_offset ); x_offset * pix_bits, y_offset );
FORGET_Frame(); FORGET_Frame();
@ -1267,6 +1269,9 @@
range->image_format, metrics, stream ); range->image_format, metrics, stream );
case 8: /* compound format */ case 8: /* compound format */
FT_Skip_Stream( stream, 1L );
/* fallthrough */
case 9: case 9:
break; break;
@ -1377,6 +1382,7 @@
TT_Int x_ppem, TT_Int x_ppem,
TT_Int y_ppem, TT_Int y_ppem,
TT_UInt glyph_index, TT_UInt glyph_index,
TT_UInt load_flags,
FT_Stream stream, FT_Stream stream,
FT_Bitmap* map, FT_Bitmap* map,
TT_SBit_Metrics* metrics ) TT_SBit_Metrics* metrics )
@ -1432,8 +1438,9 @@
metrics->vertAdvance = advance * 12 / 10; metrics->vertAdvance = advance * 12 / 10;
} }
/* Crop the bitmap now */ /* Crop the bitmap now, unless specified otherwise */
Crop_Bitmap( map, metrics ); if (load_flags & FT_LOAD_CROP_BITMAP)
Crop_Bitmap( map, metrics );
Exit: Exit:
return error; return error;

View File

@ -93,6 +93,7 @@
TT_Int x_ppem, TT_Int x_ppem,
TT_Int y_ppem, TT_Int y_ppem,
TT_UInt glyph_index, TT_UInt glyph_index,
TT_UInt load_flags,
FT_Stream stream, FT_Stream stream,
FT_Bitmap* map, FT_Bitmap* map,
TT_SBit_Metrics* metrics ); TT_SBit_Metrics* metrics );

View File

@ -239,8 +239,30 @@
root->charmaps[n] = (FT_CharMap)charmap; root->charmaps[n] = (FT_CharMap)charmap;
} }
root->num_fixed_sizes = 0; #ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
root->available_sizes = 0; if ( face->num_sbit_strikes )
{
face->root.num_fixed_sizes = face->num_sbit_strikes;
if ( ALLOC_ARRAY( face->root.available_sizes,
face->num_sbit_strikes,
FT_Bitmap_Size ) )
return error;
for ( n = 0 ; n < face->num_sbit_strikes ; n++ )
{
face->root.available_sizes[n].width =
face->sbit_strikes[n].x_ppem;
face->root.available_sizes[n].height =
face->sbit_strikes[n].y_ppem;
}
}
else
#else
{
root->num_fixed_sizes = 0;
root->available_sizes = 0;
}
#endif /* TT_CONFIG_OPTION_EMBEDDED_BITMAPS */
/*****************************************************************/ /*****************************************************************/
/* */ /* */

View File

@ -1231,6 +1231,7 @@
size->root.metrics.x_ppem, size->root.metrics.x_ppem,
size->root.metrics.y_ppem, size->root.metrics.y_ppem,
glyph_index, glyph_index,
load_flags,
stream, stream,
&glyph->bitmap, &glyph->bitmap,
&metrics ); &metrics );

View File

@ -373,6 +373,11 @@
FREE( face->root.family_name ); FREE( face->root.family_name );
FREE( face->root.style_name ); FREE( face->root.style_name );
/* freeing sbit size table */
face->root.num_fixed_sizes = 0;
if ( face->root.available_sizes )
FREE( face->root.available_sizes );
face->sfnt = 0; face->sfnt = 0;
} }