28#ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
45#define FT_COMPONENT ttsbit
58 face->sbit_table_size = 0;
60 face->sbit_num_strikes = 0;
85 FT_ERROR((
"tt_face_load_sbit_strikes: table too short\n" ));
108 p =
face->sbit_table;
124 if ( num_strikes >= 0x10000UL )
169 num_strikes >= 0x10000UL )
179 " sbix overlay not supported yet\n"
181 " expect bad rendering results\n" ));
209 FT_TRACE3((
"tt_face_load_sbit_strikes: found %u strikes\n",
210 face->sbit_num_strikes ));
212 face->ebdt_start = 0;
219 face->ebdt_start = table_start;
236 face->ebdt_size = ebdt_size;
240 if ( !
face->ebdt_size )
243 " no embedded bitmap data table found;\n"
245 " resetting number of strikes to zero\n" ));
246 face->sbit_num_strikes = 0;
254 if (
face->sbit_table )
256 face->sbit_table_size = 0;
271 face->sbit_table_size = 0;
273 face->sbit_num_strikes = 0;
294 if (
face->sbit_strike_map )
296 if ( strike_index >= (
FT_ULong)
face->root.num_fixed_sizes )
297 return FT_THROW( Invalid_Argument );
300 strike_index =
face->sbit_strike_map[strike_index];
305 return FT_THROW( Invalid_Argument );
318 strike =
face->sbit_table + 8 + strike_index * 48;
333 max_before_bl = (
FT_Char)strike[24];
334 min_after_bl = (
FT_Char)strike[25];
339 if ( min_after_bl < 0 )
343 else if (
metrics->descender == 0 )
347 FT_TRACE2((
"tt_face_load_strike_metrics:"
348 " sanitizing invalid ascender and descender\n"
350 " values for strike %ld (%dppem, %dppem)\n",
355 if ( max_before_bl || min_after_bl )
357 metrics->ascender = max_before_bl * 64;
358 metrics->descender = min_after_bl * 64;
376 FT_TRACE2((
"tt_face_load_strike_metrics:"
377 " sanitizing invalid height value\n"
379 " for strike (%d, %d)\n",
395 face->header.Units_Per_EM );
398 face->header.Units_Per_EM );
415 p =
face->sbit_table + 8 + 4 * strike_index;
419 return FT_THROW( Invalid_File_Format );
432 upem =
face->header.Units_Per_EM;
433 hori = &
face->horizontal;
454 face->header.Units_Per_EM );
457 face->header.Units_Per_EM );
463 return FT_THROW( Unknown_File_Format );
468 typedef struct TT_SBitDecoderRec_
486 } TT_SBitDecoderRec, *TT_SBitDecoder;
490 tt_sbit_decoder_init( TT_SBitDecoder
decoder,
499 strike_index =
face->sbit_strike_map[strike_index];
501 if ( !
face->ebdt_size )
525 if ( 8 + 48 * strike_index + 3 * 4 + 34 + 1 >
face->sbit_table_size )
531 p =
decoder->eblc_base + 8 + 48 * strike_index;
541 if (
decoder->strike_index_array >
face->sbit_table_size ||
543 (
face->sbit_table_size -
decoder->strike_index_array ) / 8 )
553 tt_sbit_decoder_done( TT_SBitDecoder
decoder )
560 tt_sbit_decoder_alloc_bitmap( TT_SBitDecoder
decoder,
569 if ( !
decoder->metrics_loaded )
585 map->pitch = (
int)( (
map->width + 7 ) >> 3 );
591 map->pitch = (
int)( (
map->width + 3 ) >> 2 );
597 map->pitch = (
int)( (
map->width + 1 ) >> 1 );
604 map->num_grays = 256;
610 map->num_grays = 256;
639 tt_sbit_decoder_load_metrics( TT_SBitDecoder
decoder,
682 FT_TRACE1((
"tt_sbit_decoder_load_metrics: broken table\n" ));
683 return FT_THROW( Invalid_Argument );
689 tt_sbit_decoder_load_image( TT_SBitDecoder
decoder,
696 typedef FT_Error (*TT_SBitDecoder_LoadFunc)(
706 tt_sbit_decoder_load_byte_aligned( TT_SBitDecoder
decoder,
725 bit_height =
bitmap->rows;
734 if ( x_pos < 0 || (
FT_UInt)( x_pos +
width ) > bit_width ||
737 FT_TRACE1((
"tt_sbit_decoder_load_byte_aligned:"
738 " invalid bitmap dimensions\n" ));
745 FT_TRACE1((
"tt_sbit_decoder_load_byte_aligned: broken bitmap\n" ));
751 line += y_pos * pitch + ( x_pos >> 3 );
762 for (
w = line_bits;
w >= 8;
w -= 8 )
781 for (
w = line_bits;
w >= 8;
w -= 8 )
790 wval = (
FT_UInt)( wval | ( *
p++ & ( 0xFF00U >>
w ) ) );
807 FT_TRACE3((
"tt_sbit_decoder_load_byte_aligned: loaded\n" ));
848 tt_sbit_decoder_load_bit_aligned( TT_SBitDecoder
decoder,
868 bit_height =
bitmap->rows;
877 if ( x_pos < 0 || (
FT_UInt)( x_pos +
width ) > bit_width ||
880 FT_TRACE1((
"tt_sbit_decoder_load_bit_aligned:"
881 " invalid bitmap dimensions\n" ));
888 FT_TRACE1((
"tt_sbit_decoder_load_bit_aligned: broken bitmap\n" ));
893 if ( !line_bits || !
height )
902 line += y_pos * pitch + ( x_pos >> 3 );
918 w = ( line_bits < 8 - x_pos ) ? line_bits : 8 - x_pos;
925 else if ( nbits <
w )
938 ( ~( 0xFFU <<
w ) << ( 8 -
w - x_pos ) );
945 for ( ;
w >= 8;
w -= 8 )
960 *
pwrite |= ( (
rval >> nbits ) & 0xFF ) & ( 0xFF00U >>
w );
967 *
pwrite |= ( (
rval >> nbits ) & 0xFF ) & ( 0xFF00U >>
w );
975 FT_TRACE3((
"tt_sbit_decoder_load_bit_aligned: loaded\n" ));
981 tt_sbit_decoder_load_compound( TT_SBitDecoder
decoder,
1003 if (
p + 4 * num_components >
limit )
1005 FT_TRACE1((
"tt_sbit_decoder_load_compound: broken table\n" ));
1009 FT_TRACE3((
"tt_sbit_decoder_load_compound: loading %d component%s\n",
1011 num_components == 1 ?
"" :
"s" ));
1013 for ( nn = 0; nn < num_components; nn++ )
1032 FT_TRACE3((
"tt_sbit_decoder_load_compound: done\n" ));
1034 decoder->metrics->horiBearingX = horiBearingX;
1035 decoder->metrics->horiBearingY = horiBearingY;
1036 decoder->metrics->horiAdvance = horiAdvance;
1037 decoder->metrics->vertBearingX = vertBearingX;
1038 decoder->metrics->vertBearingY = vertBearingY;
1039 decoder->metrics->vertAdvance = vertAdvance;
1052#ifdef FT_CONFIG_OPTION_USE_PNG
1055 tt_sbit_decoder_load_png( TT_SBitDecoder
decoder,
1070 FT_TRACE1((
"tt_sbit_decoder_load_png: broken bitmap\n" ));
1078 FT_TRACE1((
"tt_sbit_decoder_load_png: broken bitmap\n" ));
1096 FT_TRACE3((
"tt_sbit_decoder_load_png: loaded\n" ));
1104 tt_sbit_decoder_load_bitmap( TT_SBitDecoder
decoder,
1122 glyph_start + glyph_size >
decoder->ebdt_size )
1133 p_limit =
p + glyph_size;
1136 switch ( glyph_format )
1142 error = tt_sbit_decoder_load_metrics(
decoder, &
p, p_limit, 0 );
1149 error = tt_sbit_decoder_load_metrics(
decoder, &
p, p_limit, 1 );
1160 TT_SBitDecoder_LoadFunc loader;
1163 switch ( glyph_format )
1167 loader = tt_sbit_decoder_load_byte_aligned;
1192 if ( bit_size < byte_size &&
1193 byte_size == (
FT_UInt)( p_limit -
p ) )
1194 loader = tt_sbit_decoder_load_byte_aligned;
1196 loader = tt_sbit_decoder_load_bit_aligned;
1201 loader = tt_sbit_decoder_load_bit_aligned;
1205 if (
p + 1 > p_limit )
1212 loader = tt_sbit_decoder_load_compound;
1218#ifdef FT_CONFIG_OPTION_USE_PNG
1219 loader = tt_sbit_decoder_load_png;
1231 if ( !
decoder->bitmap_allocated )
1233 error = tt_sbit_decoder_alloc_bitmap(
decoder, metrics_only );
1242 error = loader(
decoder,
p, p_limit, x_pos, y_pos, recurse_count );
1254 tt_sbit_decoder_load_image( TT_SBitDecoder
decoder,
1265 FT_ULong image_start = 0, image_end = 0, image_offset;
1269 if ( recurse_count > 100 )
1271 FT_TRACE4((
"tt_sbit_decoder_load_image:"
1272 " recursion depth exceeded\n" ));
1279 for ( ; num_ranges > 0; num_ranges-- )
1284 if ( glyph_index >=
start && glyph_index <=
end )
1296 if ( image_offset > (
FT_ULong)( p_limit -
p ) )
1300 if (
p + 8 > p_limit )
1308 switch ( index_format )
1311 p += 4 * ( glyph_index -
start );
1312 if (
p + 8 > p_limit )
1318 if ( image_start == image_end )
1327 if (
p + 12 > p_limit )
1332 if ( tt_sbit_decoder_load_metrics(
decoder, &
p, p_limit, 1 ) )
1341 p += 2 * ( glyph_index -
start );
1342 if (
p + 4 > p_limit )
1348 if ( image_start == image_end )
1357 if (
p + 4 > p_limit )
1363 if (
p + 4 > p_limit ||
1364 num_glyphs > (
FT_ULong)( ( ( p_limit -
p ) >> 2 ) - 1 ) )
1367 for ( mm = 0; mm < num_glyphs; mm++ )
1372 if ( gindex == glyph_index )
1382 if ( mm >= num_glyphs )
1393 if (
p + 16 > p_limit )
1398 if ( tt_sbit_decoder_load_metrics(
decoder, &
p, p_limit, 1 ) )
1404 if ( num_glyphs > (
FT_ULong)( ( p_limit -
p ) >> 1 ) )
1407 for ( mm = 0; mm < num_glyphs; mm++ )
1412 if ( gindex == glyph_index )
1416 if ( mm >= num_glyphs )
1428 if ( image_start > image_end )
1431 image_end -= image_start;
1432 image_start = image_offset + image_start;
1434 FT_TRACE3((
"tt_sbit_decoder_load_image:"
1435 " found sbit (format %d) for glyph index %d\n",
1436 image_format, glyph_index ));
1438 return tt_sbit_decoder_load_bitmap(
decoder,
1451 if ( recurse_count )
1453 FT_TRACE4((
"tt_sbit_decoder_load_image:"
1454 " missing subglyph sbit with glyph index %d\n",
1456 return FT_THROW( Invalid_Composite );
1459 FT_TRACE4((
"tt_sbit_decoder_load_image:"
1460 " no sbit found for glyph index %d\n", glyph_index ));
1474 FT_UInt strike_offset, glyph_start, glyph_end;
1475 FT_Int originOffsetX, originOffsetY;
1477 FT_Int recurse_depth = 0;
1483#ifndef FT_CONFIG_OPTION_USE_PNG
1488 strike_index =
face->sbit_strike_map[strike_index];
1493 p =
face->sbit_table + 8 + 4 * strike_index;
1497 if ( glyph_index > (
FT_UInt)
face->root.num_glyphs )
1498 return FT_THROW( Invalid_Argument );
1500 if ( strike_offset >=
face->ebdt_size ||
1501 face->ebdt_size - strike_offset < 4 + glyph_index * 4 + 8 )
1502 return FT_THROW( Invalid_File_Format );
1506 glyph_index * 4 ) ||
1515 if ( glyph_start == glyph_end )
1517 if ( glyph_start > glyph_end ||
1518 glyph_end - glyph_start < 8 ||
1519 face->ebdt_size - strike_offset < glyph_end )
1520 return FT_THROW( Invalid_File_Format );
1531 switch ( graphicType )
1534 if ( recurse_depth < 4 )
1545#ifdef FT_CONFIG_OPTION_USE_PNG
1553 glyph_end - glyph_start - 8,
1585 face->root.size->metrics.x_ppem /
1586 face->header.Units_Per_EM );
1623 error = tt_sbit_decoder_load_image(
1630 tt_sbit_decoder_done(
decoder );
1639 error = tt_face_load_sbix_image(
static const WCHAR version[]
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
#define FT_LOAD_BITMAP_METRICS_ONLY
FT_MulDiv(FT_Long a, FT_Long b, FT_Long c)
FT_Bitmap_Convert(FT_Library library, const FT_Bitmap *source, FT_Bitmap *target, FT_Int alignment)
FT_BEGIN_HEADER FT_Bitmap_Init(FT_Bitmap *abitmap)
FT_Bitmap_Done(FT_Library library, FT_Bitmap *bitmap)
#define FT_ERROR(varformat)
#define FT_TRACE3(varformat)
#define FT_TRACE2(varformat)
#define FT_TRACE1(varformat)
#define FT_TRACE4(varformat)
FT_BEGIN_HEADER typedef signed long FT_Pos
FT_Match_Size(FT_Face face, FT_Size_Request req, FT_Bool ignore_width, FT_ULong *size_index)
#define FT_GLYPH_OWN_BITMAP
ft_glyphslot_alloc_bitmap(FT_GlyphSlot slot, FT_ULong size)
ft_glyphslot_set_bitmap(FT_GlyphSlot slot, FT_Byte *buffer)
#define FT_FRAME_ENTER(size)
#define FT_FRAME_RELEASE(bytes)
#define FT_STREAM_SEEK(position)
#define FT_NEXT_USHORT(buffer)
#define FT_NEXT_CHAR(buffer)
#define FT_PEEK_USHORT(p)
#define FT_NEXT_LONG(buffer)
#define FT_FRAME_EXTRACT(size, bytes)
#define FT_NEXT_ULONG(buffer)
FT_BEGIN_HEADER typedef unsigned char FT_Bool
#define FT_MAKE_TAG(_x1, _x2, _x3, _x4)
GLuint GLuint GLsizei count
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
GLint GLint GLsizei GLsizei height
GLint GLint GLsizei width
GLenum GLuint GLint GLenum face
GLsizei GLenum const GLvoid GLuint GLsizei GLfloat * metrics
GLubyte GLubyte GLubyte GLubyte w
GLfloat GLfloat GLfloat GLfloat h
static GLint image_size(GLint width, GLint height, GLenum format, GLenum type)
static char memory[1024 *256]
ssize_t pwrite(int fd, const void *buf, size_t count, off_t offset)
tt_face_get_metrics(TT_Face face, FT_Bool vertical, FT_UInt gindex, FT_Short *abearing, FT_UShort *aadvance)
tt_face_load_sbit_image(TT_Face face, FT_ULong strike_index, FT_UInt glyph_index, FT_UInt load_flags, FT_Stream stream, FT_Bitmap *map, TT_SBit_MetricsRec *metrics)
tt_face_set_sbit_strike(TT_Face face, FT_Size_Request req, FT_ULong *astrike_index)
tt_face_load_strike_metrics(TT_Face face, FT_ULong strike_index, FT_Size_Metrics *metrics)
FT_BEGIN_HEADER tt_face_load_sbit(TT_Face face, FT_Stream stream)
tt_face_free_sbit(TT_Face face)
@ TT_SBIT_TABLE_TYPE_CBLC
@ TT_SBIT_TABLE_TYPE_NONE
@ TT_SBIT_TABLE_TYPE_SBIX
@ TT_SBIT_TABLE_TYPE_EBLC