24 #include FT_INTERNAL_DEBUG_H
25 #include FT_INTERNAL_STREAM_H
26 #include FT_TRUETYPE_TAGS_H
39 #define FT_COMPONENT trace_ttsbit
54 face->sbit_num_strikes = 0;
57 error = face->goto_table( face,
TTAG_EBLC, stream, &table_size );
59 error = face->goto_table( face,
TTAG_bloc, stream, &table_size );
65 FT_ERROR((
"tt_face_load_sbit_strikes: table too short\n" ));
66 error = SFNT_Err_Invalid_File_Format;
73 face->sbit_table_size = table_size;
76 p_limit = p + table_size;
81 if ( version != 0x00020000UL || num_strikes >= 0x10000UL )
83 FT_ERROR((
"tt_face_load_sbit_strikes: invalid table version\n" ));
84 error = SFNT_Err_Invalid_File_Format;
93 if ( 8 + 48UL * count > table_size )
94 count = (
FT_UInt)( ( p_limit - p ) / 48 );
96 face->sbit_num_strikes =
count;
98 FT_TRACE3((
"sbit_num_strikes: %u\n", count ));
104 face->sbit_table_size = 0;
116 face->sbit_table_size = 0;
117 face->sbit_num_strikes = 0;
138 if ( strike_index >= (
FT_ULong)face->sbit_num_strikes )
139 return SFNT_Err_Invalid_Argument;
141 strike = face->sbit_table + 8 + strike_index * 48;
146 metrics->ascender = (
FT_Char)strike[16] << 6;
147 metrics->descender = (
FT_Char)strike[17] << 6;
148 metrics->height = metrics->ascender - metrics->descender;
151 metrics->max_advance = ( (
FT_Char)strike[22] +
160 typedef struct TT_SBitDecoderRec_
198 decoder->face =
face;
203 decoder->metrics_loaded = 0;
204 decoder->bitmap_allocated = 0;
207 decoder->ebdt_size = ebdt_size;
219 error = SFNT_Err_Invalid_File_Format;
223 p = decoder->eblc_base + 8 + 48 * strike_index;
229 decoder->bit_depth = *
p;
232 decoder->strike_index_array + 8 * decoder->strike_index_count >
234 error = SFNT_Err_Invalid_File_Format;
258 if ( !decoder->metrics_loaded )
260 error = SFNT_Err_Invalid_Argument;
264 width = decoder->metrics->width;
265 height = decoder->metrics->height;
270 switch ( decoder->bit_depth )
293 error = SFNT_Err_Invalid_File_Format;
307 decoder->bitmap_allocated = 1;
328 metrics->
width = p[1];
346 decoder->metrics_loaded = 1;
351 return SFNT_Err_Invalid_Argument;
382 if ( !decoder->bitmap_allocated )
390 bitmap = decoder->bitmap;
391 bit_width = bitmap->
width;
392 bit_height = bitmap->
rows;
393 pitch = bitmap->
pitch;
396 width = decoder->metrics->width;
397 height = decoder->metrics->height;
399 if ( x_pos < 0 || x_pos + width > bit_width ||
400 y_pos < 0 || y_pos + height > bit_height )
402 error = SFNT_Err_Invalid_File_Format;
406 if ( p + ( ( width + 7 ) >> 3 ) * height > limit )
408 error = SFNT_Err_Invalid_File_Format;
413 line += y_pos * pitch + ( x_pos >> 3 );
418 for ( h = height; h > 0; h--, line += pitch )
424 for ( w = width; w >= 8; w -= 8 )
426 write[0] = (
FT_Byte)( write[0] | *p++ );
431 write[0] = (
FT_Byte)( write[0] | ( *p++ & ( 0xFF00U >> w ) ) );
436 for ( h = height; h > 0; h--, line += pitch )
443 for ( w = width; w >= 8; w -= 8 )
445 wval = (
FT_UInt)( wval | *p++ );
446 write[0] = (
FT_Byte)( write[0] | ( wval >> x_pos ) );
452 wval = (
FT_UInt)( wval | ( *p++ & ( 0xFF00U >> w ) ) );
456 write[0] = (
FT_Byte)( write[0] | ( wval >> x_pos ) );
462 write[0] = (
FT_Byte)( write[0] | ( wval >> x_pos ) );
521 if ( !decoder->bitmap_allocated )
529 bitmap = decoder->bitmap;
530 bit_width = bitmap->
width;
531 bit_height = bitmap->
rows;
532 pitch = bitmap->
pitch;
535 width = decoder->metrics->width;
536 height = decoder->metrics->height;
538 if ( x_pos < 0 || x_pos + width > bit_width ||
539 y_pos < 0 || y_pos + height > bit_height )
541 error = SFNT_Err_Invalid_File_Format;
545 if ( p + ( ( width * height + 7 ) >> 3 ) > limit )
547 error = SFNT_Err_Invalid_File_Format;
554 line += y_pos * pitch + ( x_pos >> 3 );
561 for ( h = height; h > 0; h--, line += pitch )
570 w = ( width < 8 - x_pos ) ? width : 8 - x_pos;
577 else if ( nbits < w )
589 *write++ |= ( ( rval >> nbits ) & 0xFF ) &
590 ( ~( 0xFF <<
w ) << ( 8 - w - x_pos ) );
597 for ( ; w >= 8; w -= 8 )
600 *write++ |= ( rval >> nbits ) & 0xFF;
612 *write |= ( ( rval >> nbits ) & 0xFF ) & ( 0xFF00U >>
w );
619 *write |= ( ( rval >> nbits ) & 0xFF ) & ( 0xFF00U >>
w );
640 FT_Char horiBearingX = decoder->metrics->horiBearingX;
641 FT_Char horiBearingY = decoder->metrics->horiBearingY;
642 FT_Byte horiAdvance = decoder->metrics->horiAdvance;
643 FT_Char vertBearingX = decoder->metrics->vertBearingX;
644 FT_Char vertBearingY = decoder->metrics->vertBearingY;
645 FT_Byte vertAdvance = decoder->metrics->vertAdvance;
652 if ( p + 4 * num_components > limit )
655 if ( !decoder->bitmap_allocated )
662 for ( nn = 0; nn < num_components; nn++ )
671 x_pos + dx, y_pos + dy );
676 decoder->metrics->horiBearingX = horiBearingX;
677 decoder->metrics->horiBearingY = horiBearingY;
678 decoder->metrics->horiAdvance = horiAdvance;
679 decoder->metrics->vertBearingX = vertBearingX;
680 decoder->metrics->vertBearingY = vertBearingY;
681 decoder->metrics->vertAdvance = vertAdvance;
682 decoder->metrics->width = (
FT_UInt)decoder->bitmap->width;
683 decoder->metrics->height = (
FT_UInt)decoder->bitmap->rows;
689 error = SFNT_Err_Invalid_File_Format;
710 if ( glyph_start + glyph_size > decoder->ebdt_size )
712 error = SFNT_Err_Invalid_Argument;
721 p_limit = p + glyph_size;
724 switch ( glyph_format )
749 switch ( glyph_format )
763 if ( p + 1 > p_limit )
777 error = loader( decoder, p, p_limit, x_pos, y_pos );
799 FT_Byte*
p = decoder->eblc_base + decoder->strike_index_array;
800 FT_Byte* p_limit = decoder->eblc_limit;
801 FT_ULong num_ranges = decoder->strike_index_count;
803 FT_ULong image_start = 0, image_end = 0, image_offset;
806 for ( ; num_ranges > 0; num_ranges-- )
811 if ( glyph_index >= start && glyph_index <= end )
822 if ( decoder->eblc_base + decoder->strike_index_array + image_offset <
826 p = decoder->eblc_base + decoder->strike_index_array + image_offset;
827 if ( p + 8 > p_limit )
835 switch ( index_format )
839 p += 4 * ( glyph_index -
start );
840 if ( p + 8 > p_limit )
846 if ( image_start == image_end )
856 if ( p + 12 > p_limit )
864 image_start = image_size * ( glyph_index -
start );
865 image_end = image_start + image_size;
871 p += 2 * ( glyph_index -
start );
872 if ( p + 4 > p_limit )
878 if ( image_start == image_end )
888 if ( p + 4 > p_limit )
894 if ( p + ( num_glyphs + 1 ) * 4 < p )
897 if ( p + ( num_glyphs + 1 ) * 4 > p_limit )
900 for ( mm = 0; mm < num_glyphs; mm++ )
905 if ( gindex == glyph_index )
915 if ( mm >= num_glyphs )
922 FT_ULong image_size, mm, num_glyphs;
925 if ( p + 16 > p_limit )
936 if ( p + 2 * num_glyphs < p )
939 if ( p + 2 * num_glyphs > p_limit )
942 for ( mm = 0; mm < num_glyphs; mm++ )
947 if ( gindex == glyph_index )
951 if ( mm >= num_glyphs )
954 image_start = image_size * mm;
955 image_end = image_start + image_size;
963 if ( image_start > image_end )
966 image_end -= image_start;
967 image_start = image_offset + image_start;
977 return SFNT_Err_Invalid_Table;
980 return SFNT_Err_Invalid_Argument;
static FT_Error tt_sbit_decoder_load_compound(TT_SBitDecoder decoder, FT_Byte *p, FT_Byte *limit, FT_Int x_pos, FT_Int y_pos)
GLfloat GLfloat GLfloat GLfloat h
static FT_Error tt_sbit_decoder_load_metrics(TT_SBitDecoder decoder, FT_Byte **pp, FT_Byte *limit, FT_Bool big)
#define FT_NEXT_BYTE(buffer)
GLuint GLsizei GLsizei GLfloat * metrics
EGLSurface EGLint EGLint EGLint EGLint height
tt_face_set_sbit_strike(TT_Face face, FT_Size_Request req, FT_ULong *astrike_index)
TT_Loader_GotoTableFunc goto_table
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)
FT_BEGIN_HEADER typedef unsigned char FT_Bool
#define FT_ERROR(varformat)
struct TT_SBitDecoderRec_ TT_SBitDecoderRec
FT_Match_Size(FT_Face face, FT_Size_Request req, FT_Bool ignore_width, FT_ULong *size_index)
static FT_Error tt_sbit_decoder_load_bitmap(TT_SBitDecoder decoder, FT_UInt glyph_format, FT_ULong glyph_start, FT_ULong glyph_size, FT_Int x_pos, FT_Int y_pos)
static FT_Error tt_sbit_decoder_init(TT_SBitDecoder decoder, TT_Face face, FT_ULong strike_index, TT_SBit_MetricsRec *metrics)
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
EGLSurface EGLint EGLint EGLint width
ft_glyphslot_alloc_bitmap(FT_GlyphSlot slot, FT_ULong size)
#define FT_PEEK_USHORT(p)
FT_BEGIN_HEADER tt_face_load_eblc(TT_Face face, FT_Stream stream)
struct TT_SBitDecoderRec_ * TT_SBitDecoder
#define FT_STREAM_SEEK(position)
static FT_Error tt_sbit_decoder_load_byte_aligned(TT_SBitDecoder decoder, FT_Byte *p, FT_Byte *limit, FT_Int x_pos, FT_Int y_pos)
#define FT_NEXT_USHORT(buffer)
#define FT_FRAME_RELEASE(bytes)
#define FT_TRACE3(varformat)
static FT_Error tt_sbit_decoder_alloc_bitmap(TT_SBitDecoder decoder)
#define FT_NEXT_ULONG(buffer)
#define FT_FRAME_EXTRACT(size, bytes)
tt_face_free_eblc(TT_Face face)
GLint GLint GLint GLint GLint w
GLsizei GLfixed GLfixed GLfixed GLfixed const GLubyte * bitmap
static FT_Error tt_sbit_decoder_load_bit_aligned(TT_SBitDecoder decoder, FT_Byte *p, FT_Byte *limit, FT_Int x_pos, FT_Int y_pos)
const GLubyte GLuint GLuint GLuint GLuint alpha GLboolean GLboolean GLboolean GLboolean alpha GLint GLint GLsizei GLsizei GLenum type GLenum GLint GLenum GLint GLint GLsizei GLsizei GLint border GLenum GLint GLint GLint GLint GLint GLsizei GLsizei height GLsizei GLsizei GLenum GLenum const GLvoid *pixels GLenum GLint GLint GLint GLint j2 GLdouble GLdouble GLdouble GLdouble GLdouble GLdouble zFar GLenum GLenum GLint *params GLenum GLenum GLint *params GLenum GLenum GLint *params GLenum GLenum GLfloat *params GLenum GLint GLenum GLenum GLvoid *pixels GLenum GLint GLenum GLint *params GLenum GLenum GLint *params GLenum GLsizei const GLvoid *pointer GLenum GLenum const GLint *params GLenum GLfloat GLfloat GLint GLint const GLfloat *points GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat *points GLint GLfloat GLfloat GLint GLfloat GLfloat v2 GLenum GLenum const GLint *params GLdouble GLdouble GLdouble GLdouble GLdouble GLdouble zFar GLenum map
static void tt_sbit_decoder_done(TT_SBitDecoder decoder)
static FT_Error tt_sbit_decoder_load_image(TT_SBitDecoder decoder, FT_UInt glyph_index, FT_Int x_pos, FT_Int y_pos)
tt_face_load_strike_metrics(TT_Face face, FT_ULong strike_index, FT_Size_Metrics *metrics)
FT_Error(* TT_SBitDecoder_LoadFunc)(TT_SBitDecoder decoder, FT_Byte *p, FT_Byte *plimit, FT_Int x_pos, FT_Int y_pos)