23#include FT_INTERNAL_DEBUG_H
24#include FT_INTERNAL_STREAM_H
25#include FT_TRUETYPE_TAGS_H
29#ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
46#define FT_COMPONENT trace_ttsbit
59 face->sbit_table_size = 0;
61 face->sbit_num_strikes = 0;
86 FT_ERROR((
"tt_face_load_sbit_strikes: table too short\n" ));
109 p =
face->sbit_table;
125 if ( num_strikes >= 0x10000UL )
170 num_strikes >= 0x10000UL )
180 " sbix overlay not supported yet\n"
182 " expect bad rendering results\n" ));
210 FT_TRACE3((
"tt_face_load_sbit_strikes: found %u strikes\n",
211 face->sbit_num_strikes ));
213 face->ebdt_start = 0;
220 face->ebdt_start = table_start;
237 face->ebdt_size = ebdt_size;
241 if ( !
face->ebdt_size )
244 " no embedded bitmap data table found;\n"
246 " resetting number of strikes to zero\n" ));
247 face->sbit_num_strikes = 0;
255 if (
face->sbit_table )
257 face->sbit_table_size = 0;
272 face->sbit_table_size = 0;
274 face->sbit_num_strikes = 0;
295 if (
face->sbit_strike_map )
297 if ( strike_index >= (
FT_ULong)
face->root.num_fixed_sizes )
298 return FT_THROW( Invalid_Argument );
301 strike_index =
face->sbit_strike_map[strike_index];
306 return FT_THROW( Invalid_Argument );
319 strike =
face->sbit_table + 8 + strike_index * 48;
334 max_before_bl = (
FT_Char)strike[24];
335 min_after_bl = (
FT_Char)strike[25];
340 if ( min_after_bl < 0 )
344 else if (
metrics->descender == 0 )
348 FT_TRACE2((
"tt_face_load_strike_metrics:"
349 " sanitizing invalid ascender and descender\n"
351 " values for strike %d (%dppem, %dppem)\n",
356 if ( max_before_bl || min_after_bl )
358 metrics->ascender = max_before_bl * 64;
359 metrics->descender = min_after_bl * 64;
377 FT_TRACE2((
"tt_face_load_strike_metrics:"
378 " sanitizing invalid height value\n"
380 " for strike (%d, %d)\n",
396 face->header.Units_Per_EM );
399 face->header.Units_Per_EM );
416 p =
face->sbit_table + 8 + 4 * strike_index;
420 return FT_THROW( Invalid_File_Format );
433 upem =
face->header.Units_Per_EM;
434 hori = &
face->horizontal;
455 face->header.Units_Per_EM );
458 face->header.Units_Per_EM );
464 return FT_THROW( Unknown_File_Format );
469 typedef struct TT_SBitDecoderRec_
487 } TT_SBitDecoderRec, *TT_SBitDecoder;
491 tt_sbit_decoder_init( TT_SBitDecoder
decoder,
500 strike_index =
face->sbit_strike_map[strike_index];
502 if ( !
face->ebdt_size )
526 if ( 8 + 48 * strike_index + 3 * 4 + 34 + 1 >
face->sbit_table_size )
532 p =
decoder->eblc_base + 8 + 48 * strike_index;
542 if (
decoder->strike_index_array >
face->sbit_table_size ||
544 (
face->sbit_table_size -
decoder->strike_index_array ) / 8 )
554 tt_sbit_decoder_done( TT_SBitDecoder
decoder )
561 tt_sbit_decoder_alloc_bitmap( TT_SBitDecoder
decoder,
570 if ( !
decoder->metrics_loaded )
586 map->pitch = (
int)( (
map->width + 7 ) >> 3 );
592 map->pitch = (
int)( (
map->width + 3 ) >> 2 );
598 map->pitch = (
int)( (
map->width + 1 ) >> 1 );
605 map->num_grays = 256;
611 map->num_grays = 256;
640 tt_sbit_decoder_load_metrics( TT_SBitDecoder
decoder,
683 FT_TRACE1((
"tt_sbit_decoder_load_metrics: broken table\n" ));
684 return FT_THROW( Invalid_Argument );
690 tt_sbit_decoder_load_image( TT_SBitDecoder
decoder,
697 typedef FT_Error (*TT_SBitDecoder_LoadFunc)(
707 tt_sbit_decoder_load_byte_aligned( TT_SBitDecoder
decoder,
726 bit_height =
bitmap->rows;
735 if ( x_pos < 0 || (
FT_UInt)( x_pos +
width ) > bit_width ||
738 FT_TRACE1((
"tt_sbit_decoder_load_byte_aligned:"
739 " invalid bitmap dimensions\n" ));
746 FT_TRACE1((
"tt_sbit_decoder_load_byte_aligned: broken bitmap\n" ));
752 line += y_pos * pitch + ( x_pos >> 3 );
763 for (
w = line_bits;
w >= 8;
w -= 8 )
782 for (
w = line_bits;
w >= 8;
w -= 8 )
791 wval = (
FT_UInt)( wval | ( *
p++ & ( 0xFF00U >>
w ) ) );
808 FT_TRACE3((
"tt_sbit_decoder_load_byte_aligned: loaded\n" ));
849 tt_sbit_decoder_load_bit_aligned( TT_SBitDecoder
decoder,
869 bit_height =
bitmap->rows;
878 if ( x_pos < 0 || (
FT_UInt)( x_pos +
width ) > bit_width ||
881 FT_TRACE1((
"tt_sbit_decoder_load_bit_aligned:"
882 " invalid bitmap dimensions\n" ));
889 FT_TRACE1((
"tt_sbit_decoder_load_bit_aligned: broken bitmap\n" ));
894 if ( !line_bits || !
height )
903 line += y_pos * pitch + ( x_pos >> 3 );
919 w = ( line_bits < 8 - x_pos ) ? line_bits : 8 - x_pos;
926 else if ( nbits <
w )
939 ( ~( 0xFFU <<
w ) << ( 8 -
w - x_pos ) );
946 for ( ;
w >= 8;
w -= 8 )
961 *
pwrite |= ( (
rval >> nbits ) & 0xFF ) & ( 0xFF00U >>
w );
968 *
pwrite |= ( (
rval >> nbits ) & 0xFF ) & ( 0xFF00U >>
w );
976 FT_TRACE3((
"tt_sbit_decoder_load_bit_aligned: loaded\n" ));
982 tt_sbit_decoder_load_compound( TT_SBitDecoder
decoder,
1004 if (
p + 4 * num_components >
limit )
1006 FT_TRACE1((
"tt_sbit_decoder_load_compound: broken table\n" ));
1010 FT_TRACE3((
"tt_sbit_decoder_load_compound: loading %d component%s\n",
1012 num_components == 1 ?
"" :
"s" ));
1014 for ( nn = 0; nn < num_components; nn++ )
1033 FT_TRACE3((
"tt_sbit_decoder_load_compound: done\n" ));
1035 decoder->metrics->horiBearingX = horiBearingX;
1036 decoder->metrics->horiBearingY = horiBearingY;
1037 decoder->metrics->horiAdvance = horiAdvance;
1038 decoder->metrics->vertBearingX = vertBearingX;
1039 decoder->metrics->vertBearingY = vertBearingY;
1040 decoder->metrics->vertAdvance = vertAdvance;
1053#ifdef FT_CONFIG_OPTION_USE_PNG
1056 tt_sbit_decoder_load_png( TT_SBitDecoder
decoder,
1071 FT_TRACE1((
"tt_sbit_decoder_load_png: broken bitmap\n" ));
1079 FT_TRACE1((
"tt_sbit_decoder_load_png: broken bitmap\n" ));
1097 FT_TRACE3((
"tt_sbit_decoder_load_png: loaded\n" ));
1105 tt_sbit_decoder_load_bitmap( TT_SBitDecoder
decoder,
1123 glyph_start + glyph_size >
decoder->ebdt_size )
1134 p_limit =
p + glyph_size;
1137 switch ( glyph_format )
1143 error = tt_sbit_decoder_load_metrics(
decoder, &
p, p_limit, 0 );
1150 error = tt_sbit_decoder_load_metrics(
decoder, &
p, p_limit, 1 );
1161 TT_SBitDecoder_LoadFunc loader;
1164 switch ( glyph_format )
1168 loader = tt_sbit_decoder_load_byte_aligned;
1193 if ( bit_size < byte_size &&
1194 byte_size == (
FT_UInt)( p_limit -
p ) )
1195 loader = tt_sbit_decoder_load_byte_aligned;
1197 loader = tt_sbit_decoder_load_bit_aligned;
1202 loader = tt_sbit_decoder_load_bit_aligned;
1206 if (
p + 1 > p_limit )
1213 loader = tt_sbit_decoder_load_compound;
1219#ifdef FT_CONFIG_OPTION_USE_PNG
1220 loader = tt_sbit_decoder_load_png;
1232 if ( !
decoder->bitmap_allocated )
1234 error = tt_sbit_decoder_alloc_bitmap(
decoder, metrics_only );
1243 error = loader(
decoder,
p, p_limit, x_pos, y_pos, recurse_count );
1255 tt_sbit_decoder_load_image( TT_SBitDecoder
decoder,
1266 FT_ULong image_start = 0, image_end = 0, image_offset;
1270 if ( recurse_count > 100 )
1272 FT_TRACE4((
"tt_sbit_decoder_load_image:"
1273 " recursion depth exceeded\n" ));
1280 for ( ; num_ranges > 0; num_ranges-- )
1285 if ( glyph_index >=
start && glyph_index <=
end )
1297 if ( image_offset > (
FT_ULong)( p_limit -
p ) )
1301 if (
p + 8 > p_limit )
1309 switch ( index_format )
1312 p += 4 * ( glyph_index -
start );
1313 if (
p + 8 > p_limit )
1319 if ( image_start == image_end )
1328 if (
p + 12 > p_limit )
1333 if ( tt_sbit_decoder_load_metrics(
decoder, &
p, p_limit, 1 ) )
1342 p += 2 * ( glyph_index -
start );
1343 if (
p + 4 > p_limit )
1349 if ( image_start == image_end )
1358 if (
p + 4 > p_limit )
1364 if (
p + 4 > p_limit ||
1365 num_glyphs > (
FT_ULong)( ( ( p_limit -
p ) >> 2 ) - 1 ) )
1368 for ( mm = 0; mm < num_glyphs; mm++ )
1373 if ( gindex == glyph_index )
1383 if ( mm >= num_glyphs )
1394 if (
p + 16 > p_limit )
1399 if ( tt_sbit_decoder_load_metrics(
decoder, &
p, p_limit, 1 ) )
1405 if ( num_glyphs > (
FT_ULong)( ( p_limit -
p ) >> 1 ) )
1408 for ( mm = 0; mm < num_glyphs; mm++ )
1413 if ( gindex == glyph_index )
1417 if ( mm >= num_glyphs )
1429 if ( image_start > image_end )
1432 image_end -= image_start;
1433 image_start = image_offset + image_start;
1435 FT_TRACE3((
"tt_sbit_decoder_load_image:"
1436 " found sbit (format %d) for glyph index %d\n",
1437 image_format, glyph_index ));
1439 return tt_sbit_decoder_load_bitmap(
decoder,
1452 if ( recurse_count )
1454 FT_TRACE4((
"tt_sbit_decoder_load_image:"
1455 " missing subglyph sbit with glyph index %d\n",
1457 return FT_THROW( Invalid_Composite );
1460 FT_TRACE4((
"tt_sbit_decoder_load_image:"
1461 " no sbit found for glyph index %d\n", glyph_index ));
1475 FT_UInt strike_offset, glyph_start, glyph_end;
1476 FT_Int originOffsetX, originOffsetY;
1478 FT_Int recurse_depth = 0;
1484#ifndef FT_CONFIG_OPTION_USE_PNG
1489 strike_index =
face->sbit_strike_map[strike_index];
1494 p =
face->sbit_table + 8 + 4 * strike_index;
1498 if ( glyph_index > (
FT_UInt)
face->root.num_glyphs )
1499 return FT_THROW( Invalid_Argument );
1501 if ( strike_offset >=
face->ebdt_size ||
1502 face->ebdt_size - strike_offset < 4 + glyph_index * 4 + 8 )
1503 return FT_THROW( Invalid_File_Format );
1507 glyph_index * 4 ) ||
1516 if ( glyph_start == glyph_end )
1517 return FT_THROW( Invalid_Argument );
1518 if ( glyph_start > glyph_end ||
1519 glyph_end - glyph_start < 8 ||
1520 face->ebdt_size - strike_offset < glyph_end )
1521 return FT_THROW( Invalid_File_Format );
1532 switch ( graphicType )
1535 if ( recurse_depth < 4 )
1554 glyph_end - glyph_start - 8,
1586 face->root.size->metrics.x_ppem /
1587 face->header.Units_Per_EM );
1616 error = tt_sbit_decoder_load_image(
1623 tt_sbit_decoder_done(
decoder );
1629 error = tt_face_load_sbix_image(
#define FT_CONFIG_OPTION_USE_PNG
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_PEEK_USHORT(p)
#define FT_NEXT_LONG(buffer)
#define FT_FRAME_EXTRACT(size, bytes)
#define FT_NEXT_ULONG(buffer)
#define FT_NEXT_BYTE(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