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 =
FT_THROW( 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 =
FT_THROW( 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 FT_THROW( Invalid_Argument );
141 strike = face->sbit_table + 8 + strike_index * 48;
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 =
FT_THROW( 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 =
FT_THROW( Invalid_File_Format );
258 if ( !decoder->metrics_loaded )
260 error =
FT_THROW( Invalid_Argument );
264 width = decoder->metrics->width;
265 height = decoder->metrics->height;
270 switch ( decoder->bit_depth )
293 error =
FT_THROW( Invalid_File_Format );
307 decoder->bitmap_allocated = 1;
328 metrics->
width = p[1];
346 decoder->metrics_loaded = 1;
351 return FT_THROW( Invalid_Argument );
382 if ( !decoder->bitmap_allocated )
384 error = tt_sbit_decoder_alloc_bitmap( decoder );
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 line_bits = width * decoder->bit_depth;
401 if ( x_pos < 0 || x_pos + width > bit_width ||
402 y_pos < 0 || y_pos + height > bit_height )
404 error =
FT_THROW( Invalid_File_Format );
408 if ( p + ( ( line_bits + 7 ) >> 3 ) * height > limit )
410 error =
FT_THROW( Invalid_File_Format );
415 line += y_pos * pitch + ( x_pos >> 3 );
420 for ( h = height; h > 0; h--, line += pitch )
426 for ( w = line_bits; w >= 8; w -= 8 )
428 write[0] = (
FT_Byte)( write[0] | *p++ );
433 write[0] = (
FT_Byte)( write[0] | ( *p++ & ( 0xFF00U >> w ) ) );
438 for ( h = height; h > 0; h--, line += pitch )
445 for ( w = line_bits; w >= 8; w -= 8 )
447 wval = (
FT_UInt)( wval | *p++ );
448 write[0] = (
FT_Byte)( write[0] | ( wval >> x_pos ) );
454 wval = (
FT_UInt)( wval | ( *p++ & ( 0xFF00U >> w ) ) );
458 write[0] = (
FT_Byte)( write[0] | ( wval >> x_pos ) );
464 write[0] = (
FT_Byte)( write[0] | ( wval >> x_pos ) );
523 if ( !decoder->bitmap_allocated )
525 error = tt_sbit_decoder_alloc_bitmap( decoder );
531 bitmap = decoder->bitmap;
532 bit_width = bitmap->
width;
533 bit_height = bitmap->
rows;
534 pitch = bitmap->
pitch;
537 width = decoder->metrics->width;
538 height = decoder->metrics->height;
540 line_bits = width * decoder->bit_depth;
542 if ( x_pos < 0 || x_pos + width > bit_width ||
543 y_pos < 0 || y_pos + height > bit_height )
545 error =
FT_THROW( Invalid_File_Format );
549 if (
p + ( ( line_bits * height + 7 ) >> 3 ) >
limit )
551 error =
FT_THROW( Invalid_File_Format );
558 line += y_pos * pitch + ( x_pos >> 3 );
565 for ( h = height; h > 0; h--, line += pitch )
574 w = ( line_bits < 8 - x_pos ) ? line_bits : 8 - x_pos;
581 else if ( nbits < w )
593 *write++ |= ( ( rval >>
nbits ) & 0xFF ) &
594 ( ~( 0xFF <<
w ) << ( 8 - w - x_pos ) );
601 for ( ; w >= 8; w -= 8 )
604 *write++ |= ( rval >>
nbits ) & 0xFF;
616 *write |= ( ( rval >>
nbits ) & 0xFF ) & ( 0xFF00U >>
w );
623 *write |= ( ( rval >>
nbits ) & 0xFF ) & ( 0xFF00U >>
w );
644 FT_Char horiBearingX = decoder->metrics->horiBearingX;
645 FT_Char horiBearingY = decoder->metrics->horiBearingY;
646 FT_Byte horiAdvance = decoder->metrics->horiAdvance;
647 FT_Char vertBearingX = decoder->metrics->vertBearingX;
648 FT_Char vertBearingY = decoder->metrics->vertBearingY;
649 FT_Byte vertAdvance = decoder->metrics->vertAdvance;
656 if (
p + 4 * num_components >
limit )
659 if ( !decoder->bitmap_allocated )
661 error = tt_sbit_decoder_alloc_bitmap( decoder );
666 for ( nn = 0; nn < num_components; nn++ )
674 error = tt_sbit_decoder_load_image( decoder, gindex,
675 x_pos + dx, y_pos + dy );
680 decoder->metrics->horiBearingX = horiBearingX;
681 decoder->metrics->horiBearingY = horiBearingY;
682 decoder->metrics->horiAdvance = horiAdvance;
683 decoder->metrics->vertBearingX = vertBearingX;
684 decoder->metrics->vertBearingY = vertBearingY;
685 decoder->metrics->vertAdvance = vertAdvance;
686 decoder->metrics->width = (
FT_UInt)decoder->bitmap->width;
687 decoder->metrics->height = (
FT_UInt)decoder->bitmap->rows;
693 error =
FT_THROW( Invalid_File_Format );
714 if ( glyph_start + glyph_size > decoder->ebdt_size )
716 error =
FT_THROW( Invalid_Argument );
725 p_limit = p + glyph_size;
728 switch ( glyph_format )
733 error = tt_sbit_decoder_load_metrics( decoder, &p, p_limit, 0 );
739 error = tt_sbit_decoder_load_metrics( decoder, &p, p_limit, 1 );
753 switch ( glyph_format )
757 loader = tt_sbit_decoder_load_byte_aligned;
763 loader = tt_sbit_decoder_load_bit_aligned;
767 if ( p + 1 > p_limit )
774 loader = tt_sbit_decoder_load_compound;
781 error = loader( decoder, p, p_limit, x_pos, y_pos );
803 FT_Byte*
p = decoder->eblc_base + decoder->strike_index_array;
804 FT_Byte* p_limit = decoder->eblc_limit;
805 FT_ULong num_ranges = decoder->strike_index_count;
807 FT_ULong image_start = 0, image_end = 0, image_offset;
810 for ( ; num_ranges > 0; num_ranges-- )
815 if ( glyph_index >= start && glyph_index <= end )
826 p = decoder->eblc_base + decoder->strike_index_array;
827 if ( image_offset > (
FT_ULong)( p_limit - p ) )
831 if ( p + 8 > p_limit )
839 switch ( index_format )
843 p += 4 * ( glyph_index -
start );
844 if ( p + 8 > p_limit )
850 if ( image_start == image_end )
860 if ( p + 12 > p_limit )
865 if ( tt_sbit_decoder_load_metrics( decoder, &p, p_limit, 1 ) )
868 image_start = image_size * ( glyph_index -
start );
869 image_end = image_start + image_size;
875 p += 2 * ( glyph_index -
start );
876 if ( p + 4 > p_limit )
882 if ( image_start == image_end )
892 if ( p + 4 > p_limit )
898 if ( num_glyphs > (
FT_ULong)( ( ( p_limit - p ) >> 2 ) - 1 ) )
901 for ( mm = 0; mm < num_glyphs; mm++ )
906 if ( gindex == glyph_index )
916 if ( mm >= num_glyphs )
923 FT_ULong image_size, mm, num_glyphs;
926 if ( p + 16 > p_limit )
931 if ( tt_sbit_decoder_load_metrics( decoder, &p, p_limit, 1 ) )
937 if ( num_glyphs > (
FT_ULong)( ( p_limit - p ) >> 1 ) )
940 for ( mm = 0; mm < num_glyphs; mm++ )
945 if ( gindex == glyph_index )
949 if ( mm >= num_glyphs )
952 image_start = image_size * mm;
953 image_end = image_start + image_size;
961 if ( image_start > image_end )
964 image_end -= image_start;
965 image_start = image_offset + image_start;
967 return tt_sbit_decoder_load_bitmap( decoder,
978 return FT_THROW( Invalid_Argument );
999 error = tt_sbit_decoder_init( decoder, face, strike_index, metrics );
1002 error = tt_sbit_decoder_load_image( decoder, glyph_index, 0, 0 );
1003 tt_sbit_decoder_done( decoder );
GLint GLint GLsizei GLsizei height
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)
int write(int fd, const char *buf, int nbytes)
GLfloat GLfloat GLfloat GLfloat h
return FT_THROW(Missing_Property)
#define FT_NEXT_BYTE(buffer)
GLint GLint GLsizei width
tt_face_free_eblc(TT_Face face)
TT_Loader_GotoTableFunc goto_table
FT_BEGIN_HEADER typedef unsigned char FT_Bool
GLenum GLuint GLint GLenum face
#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)
ft_glyphslot_alloc_bitmap(FT_GlyphSlot slot, FT_ULong size)
GLsizei GLsizei GLenum GLenum const GLvoid * data
register bit_buf_type register int int nbits
#define FT_PEEK_USHORT(p)
struct TT_SBitDecoderRec_ * TT_SBitDecoder
tt_face_load_strike_metrics(TT_Face face, FT_ULong strike_index, FT_Size_Metrics *metrics)
#define FT_STREAM_SEEK(position)
#define FT_NEXT_USHORT(buffer)
#define FT_FRAME_RELEASE(bytes)
#define FT_TRACE3(varformat)
GLubyte GLubyte GLubyte GLubyte w
#define FT_NEXT_ULONG(buffer)
#define FT_FRAME_EXTRACT(size, bytes)
GLuint GLuint GLsizei count
FT_Error(* TT_SBitDecoder_LoadFunc)(TT_SBitDecoder decoder, FT_Byte *p, FT_Byte *plimit, FT_Int x_pos, FT_Int y_pos)
tt_face_load_eblc(TT_Face face, FT_Stream stream)
GLsizei GLenum const GLvoid GLuint GLsizei GLfloat * metrics
tt_face_set_sbit_strike(TT_Face face, FT_Size_Request req, FT_ULong *astrike_index)