diff options
Diffstat (limited to 'src/3rdparty/freetype/src/bdf/bdfdrivr.c')
-rw-r--r-- | src/3rdparty/freetype/src/bdf/bdfdrivr.c | 200 |
1 files changed, 98 insertions, 102 deletions
diff --git a/src/3rdparty/freetype/src/bdf/bdfdrivr.c b/src/3rdparty/freetype/src/bdf/bdfdrivr.c index 60eb93305e..e02a160930 100644 --- a/src/3rdparty/freetype/src/bdf/bdfdrivr.c +++ b/src/3rdparty/freetype/src/bdf/bdfdrivr.c @@ -24,16 +24,15 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include <ft2build.h> -#include FT_INTERNAL_DEBUG_H -#include FT_INTERNAL_STREAM_H -#include FT_INTERNAL_OBJECTS_H -#include FT_BDF_H -#include FT_TRUETYPE_IDS_H +#include <freetype/internal/ftdebug.h> +#include <freetype/internal/ftstream.h> +#include <freetype/internal/ftobjs.h> +#include <freetype/ftbdf.h> +#include <freetype/ttnameid.h> -#include FT_SERVICE_BDF_H -#include FT_SERVICE_FONT_FORMAT_H +#include <freetype/internal/services/svbdf.h> +#include <freetype/internal/services/svfntfmt.h> #include "bdf.h" #include "bdfdrivr.h" @@ -93,24 +92,18 @@ THE SOFTWARE. { BDF_CMap cmap = (BDF_CMap)bdfcmap; BDF_encoding_el* encodings = cmap->encodings; - FT_ULong min, max, mid; /* num_encodings */ FT_UShort result = 0; /* encodings->glyph */ + FT_ULong min = 0; + FT_ULong max = cmap->num_encodings; + FT_ULong mid = ( min + max ) >> 1; - min = 0; - max = cmap->num_encodings; - mid = ( min + max ) >> 1; while ( min < max ) { - FT_ULong code; + FT_ULong code = encodings[mid].enc; - if ( mid >= max || mid < min ) - mid = ( min + max ) >> 1; - - code = encodings[mid].enc; - if ( charcode == code ) { /* increase glyph index by 1 -- */ @@ -124,8 +117,10 @@ THE SOFTWARE. else min = mid + 1; - /* prediction in a continuous block */ + /* reasonable prediction in a continuous block */ mid += charcode - code; + if ( mid >= max || mid < min ) + mid = ( min + max ) >> 1; } return result; @@ -138,24 +133,18 @@ THE SOFTWARE. { BDF_CMap cmap = (BDF_CMap)bdfcmap; BDF_encoding_el* encodings = cmap->encodings; - FT_ULong min, max, mid; /* num_encodings */ FT_UShort result = 0; /* encodings->glyph */ FT_ULong charcode = *acharcode + 1; + FT_ULong min = 0; + FT_ULong max = cmap->num_encodings; + FT_ULong mid = ( min + max ) >> 1; - min = 0; - max = cmap->num_encodings; - mid = ( min + max ) >> 1; while ( min < max ) { - FT_ULong code; /* same as BDF_encoding_el.enc */ - - - if ( mid >= max || mid < min ) - mid = ( min + max ) >> 1; + FT_ULong code = encodings[mid].enc; - code = encodings[mid].enc; if ( charcode == code ) { @@ -172,6 +161,8 @@ THE SOFTWARE. /* prediction in a continuous block */ mid += charcode - code; + if ( mid >= max || mid < min ) + mid = ( min + max ) >> 1; } charcode = 0; @@ -184,7 +175,8 @@ THE SOFTWARE. Exit: if ( charcode > 0xFFFFFFFFUL ) { - FT_TRACE1(( "bdf_cmap_char_next: charcode 0x%x > 32bit API" )); + FT_TRACE1(( "bdf_cmap_char_next: charcode 0x%lx > 32bit API", + charcode )); *acharcode = 0; /* XXX: result should be changed to indicate an overflow error */ } @@ -276,7 +268,7 @@ THE SOFTWARE. char* s; - if ( FT_ALLOC( face->style_name, len ) ) + if ( FT_QALLOC( face->style_name, len ) ) return error; s = face->style_name; @@ -319,9 +311,9 @@ THE SOFTWARE. FT_CALLBACK_DEF( void ) - BDF_Face_Done( FT_Face bdfface ) /* BDF_Face */ + BDF_Face_Done( FT_Face face ) /* BDF_Face */ { - BDF_Face face = (BDF_Face)bdfface; + BDF_Face bdfface = (BDF_Face)face; FT_Memory memory; @@ -330,31 +322,31 @@ THE SOFTWARE. memory = FT_FACE_MEMORY( face ); - bdf_free_font( face->bdffont ); + bdf_free_font( bdfface->bdffont ); - FT_FREE( face->en_table ); + FT_FREE( bdfface->en_table ); - FT_FREE( face->charset_encoding ); - FT_FREE( face->charset_registry ); - FT_FREE( bdfface->family_name ); - FT_FREE( bdfface->style_name ); + FT_FREE( bdfface->charset_encoding ); + FT_FREE( bdfface->charset_registry ); + FT_FREE( face->family_name ); + FT_FREE( face->style_name ); - FT_FREE( bdfface->available_sizes ); + FT_FREE( face->available_sizes ); - FT_FREE( face->bdffont ); + FT_FREE( bdfface->bdffont ); } FT_CALLBACK_DEF( FT_Error ) BDF_Face_Init( FT_Stream stream, - FT_Face bdfface, /* BDF_Face */ + FT_Face face, /* BDF_Face */ FT_Int face_index, FT_Int num_params, FT_Parameter* params ) { - FT_Error error = FT_Err_Ok; - BDF_Face face = (BDF_Face)bdfface; - FT_Memory memory = FT_FACE_MEMORY( face ); + FT_Error error = FT_Err_Ok; + BDF_Face bdfface = (BDF_Face)face; + FT_Memory memory = FT_FACE_MEMORY( face ); bdf_font_t* font = NULL; bdf_options_t options; @@ -383,7 +375,7 @@ THE SOFTWARE. goto Exit; /* we have a bdf font: let's construct the face object */ - face->bdffont = font; + bdfface->bdffont = font; /* BDF cannot have multiple faces in a single font file. * XXX: non-zero face_index is already invalid argument, but @@ -394,7 +386,7 @@ THE SOFTWARE. if ( face_index > 0 && ( face_index & 0xFFFF ) > 0 ) { FT_ERROR(( "BDF_Face_Init: invalid face index\n" )); - BDF_Face_Done( bdfface ); + BDF_Face_Done( face ); return FT_THROW( Invalid_Argument ); } @@ -402,25 +394,25 @@ THE SOFTWARE. bdf_property_t* prop = NULL; - FT_TRACE4(( " number of glyphs: allocated %d (used %d)\n", + FT_TRACE4(( " number of glyphs: allocated %ld (used %ld)\n", font->glyphs_size, font->glyphs_used )); - FT_TRACE4(( " number of unencoded glyphs: allocated %d (used %d)\n", + FT_TRACE4(( " number of unencoded glyphs: allocated %ld (used %ld)\n", font->unencoded_size, font->unencoded_used )); - bdfface->num_faces = 1; - bdfface->face_index = 0; + face->num_faces = 1; + face->face_index = 0; - bdfface->face_flags |= FT_FACE_FLAG_FIXED_SIZES | - FT_FACE_FLAG_HORIZONTAL; + face->face_flags |= FT_FACE_FLAG_FIXED_SIZES | + FT_FACE_FLAG_HORIZONTAL; prop = bdf_get_font_property( font, "SPACING" ); if ( prop && prop->format == BDF_ATOM && prop->value.atom && ( *(prop->value.atom) == 'M' || *(prop->value.atom) == 'm' || *(prop->value.atom) == 'C' || *(prop->value.atom) == 'c' ) ) - bdfface->face_flags |= FT_FACE_FLAG_FIXED_WIDTH; + face->face_flags |= FT_FACE_FLAG_FIXED_WIDTH; /* FZ XXX: TO DO: FT_FACE_FLAGS_VERTICAL */ /* FZ XXX: I need a font to implement this */ @@ -428,42 +420,41 @@ THE SOFTWARE. prop = bdf_get_font_property( font, "FAMILY_NAME" ); if ( prop && prop->value.atom ) { - if ( FT_STRDUP( bdfface->family_name, prop->value.atom ) ) + if ( FT_STRDUP( face->family_name, prop->value.atom ) ) goto Exit; } else - bdfface->family_name = NULL; + face->family_name = NULL; - if ( FT_SET_ERROR( bdf_interpret_style( face ) ) ) + if ( FT_SET_ERROR( bdf_interpret_style( bdfface ) ) ) goto Exit; /* the number of glyphs (with one slot for the undefined glyph */ /* at position 0 and all unencoded glyphs) */ - bdfface->num_glyphs = (FT_Long)( font->glyphs_size + 1 ); + face->num_glyphs = (FT_Long)( font->glyphs_size + 1 ); - bdfface->num_fixed_sizes = 1; - if ( FT_NEW_ARRAY( bdfface->available_sizes, 1 ) ) + face->num_fixed_sizes = 1; + if ( FT_NEW( face->available_sizes ) ) goto Exit; { - FT_Bitmap_Size* bsize = bdfface->available_sizes; - FT_Short resolution_x = 0, resolution_y = 0; + FT_Bitmap_Size* bsize = face->available_sizes; + FT_Short resolution_x = 0; + FT_Short resolution_y = 0; long value; - FT_ZERO( bsize ); - /* sanity checks */ if ( font->font_ascent > 0x7FFF || font->font_ascent < -0x7FFF ) { font->font_ascent = font->font_ascent < 0 ? -0x7FFF : 0x7FFF; - FT_TRACE0(( "BDF_Face_Init: clamping font ascent to value %d\n", + FT_TRACE0(( "BDF_Face_Init: clamping font ascent to value %ld\n", font->font_ascent )); } if ( font->font_descent > 0x7FFF || font->font_descent < -0x7FFF ) { font->font_descent = font->font_descent < 0 ? -0x7FFF : 0x7FFF; - FT_TRACE0(( "BDF_Face_Init: clamping font descent to value %d\n", + FT_TRACE0(( "BDF_Face_Init: clamping font descent to value %ld\n", font->font_descent )); } @@ -489,7 +480,7 @@ THE SOFTWARE. else { /* this is a heuristical value */ - bsize->width = (FT_Short)FT_MulDiv( bsize->height, 2, 3 ); + bsize->width = ( bsize->height * 2 + 1 ) / 3; } prop = bdf_get_font_property( font, "POINT_SIZE" ); @@ -504,7 +495,7 @@ THE SOFTWARE. prop->value.l < -0x504C2L ) { bsize->size = 0x7FFF; - FT_TRACE0(( "BDF_Face_Init: clamping point size to value %d\n", + FT_TRACE0(( "BDF_Face_Init: clamping point size to value %ld\n", bsize->size )); } else @@ -517,7 +508,7 @@ THE SOFTWARE. if ( font->point_size > 0x7FFF ) { bsize->size = 0x7FFF; - FT_TRACE0(( "BDF_Face_Init: clamping point size to value %d\n", + FT_TRACE0(( "BDF_Face_Init: clamping point size to value %ld\n", bsize->size )); } else @@ -539,7 +530,7 @@ THE SOFTWARE. if ( prop->value.l > 0x7FFF || prop->value.l < -0x7FFF ) { bsize->y_ppem = 0x7FFF << 6; - FT_TRACE0(( "BDF_Face_Init: clamping pixel size to value %d\n", + FT_TRACE0(( "BDF_Face_Init: clamping pixel size to value %ld\n", bsize->y_ppem )); } else @@ -608,23 +599,23 @@ THE SOFTWARE. unsigned long n; - if ( FT_NEW_ARRAY( face->en_table, font->glyphs_size ) ) + if ( FT_QNEW_ARRAY( bdfface->en_table, font->glyphs_size ) ) goto Exit; - face->default_glyph = 0; + bdfface->default_glyph = 0; for ( n = 0; n < font->glyphs_size; n++ ) { - (face->en_table[n]).enc = cur[n].encoding; - FT_TRACE4(( " idx %d, val 0x%lX\n", n, cur[n].encoding )); - (face->en_table[n]).glyph = (FT_UShort)n; + (bdfface->en_table[n]).enc = cur[n].encoding; + FT_TRACE4(( " idx %ld, val 0x%lX\n", n, cur[n].encoding )); + (bdfface->en_table[n]).glyph = (FT_UShort)n; if ( cur[n].encoding == font->default_char ) { if ( n < FT_UINT_MAX ) - face->default_glyph = (FT_UInt)n; + bdfface->default_glyph = (FT_UInt)n; else FT_TRACE1(( "BDF_Face_Init:" - " idx %d is too large for this system\n", n )); + " idx %ld is too large for this system\n", n )); } } } @@ -649,27 +640,27 @@ THE SOFTWARE. const char* s; - if ( FT_STRDUP( face->charset_encoding, + if ( FT_STRDUP( bdfface->charset_encoding, charset_encoding->value.atom ) || - FT_STRDUP( face->charset_registry, + FT_STRDUP( bdfface->charset_registry, charset_registry->value.atom ) ) goto Exit; /* Uh, oh, compare first letters manually to avoid dependency */ /* on locales. */ - s = face->charset_registry; + s = bdfface->charset_registry; if ( ( s[0] == 'i' || s[0] == 'I' ) && ( s[1] == 's' || s[1] == 'S' ) && ( s[2] == 'o' || s[2] == 'O' ) ) { s += 3; - if ( !ft_strcmp( s, "10646" ) || - ( !ft_strcmp( s, "8859" ) && - !ft_strcmp( face->charset_encoding, "1" ) ) ) + if ( !ft_strcmp( s, "10646" ) || + ( !ft_strcmp( s, "8859" ) && + !ft_strcmp( bdfface->charset_encoding, "1" ) ) ) unicode_charmap = 1; /* another name for ASCII */ - else if ( !ft_strcmp( s, "646.1991" ) && - !ft_strcmp( face->charset_encoding, "IRV" ) ) + else if ( !ft_strcmp( s, "646.1991" ) && + !ft_strcmp( bdfface->charset_encoding, "IRV" ) ) unicode_charmap = 1; } @@ -677,7 +668,7 @@ THE SOFTWARE. FT_CharMapRec charmap; - charmap.face = FT_FACE( face ); + charmap.face = face; charmap.encoding = FT_ENCODING_NONE; /* initial platform/encoding should indicate unset status? */ charmap.platform_id = TT_PLATFORM_APPLE_UNICODE; @@ -703,7 +694,7 @@ THE SOFTWARE. FT_CharMapRec charmap; - charmap.face = FT_FACE( face ); + charmap.face = face; charmap.encoding = FT_ENCODING_ADOBE_STANDARD; charmap.platform_id = TT_PLATFORM_ADOBE; charmap.encoding_id = TT_ADOBE_ID_STANDARD; @@ -711,8 +702,8 @@ THE SOFTWARE. error = FT_CMap_New( &bdf_cmap_class, NULL, &charmap, NULL ); /* Select default charmap */ - if ( bdfface->num_charmaps ) - bdfface->charmap = bdfface->charmaps[0]; + if ( face->num_charmaps ) + face->charmap = face->charmaps[0]; } } } @@ -721,7 +712,7 @@ THE SOFTWARE. return error; Fail: - BDF_Face_Done( bdfface ); + BDF_Face_Done( face ); return FT_THROW( Unknown_File_Format ); } @@ -825,7 +816,7 @@ THE SOFTWARE. bitmap->rows = glyph.bbx.height; bitmap->width = glyph.bbx.width; if ( glyph.bpr > FT_INT_MAX ) - FT_TRACE1(( "BDF_Glyph_Load: too large pitch %d is truncated\n", + FT_TRACE1(( "BDF_Glyph_Load: too large pitch %ld is truncated\n", glyph.bpr )); bitmap->pitch = (int)glyph.bpr; /* same as FT_Bitmap.pitch */ @@ -878,17 +869,18 @@ THE SOFTWARE. * */ - static FT_Error - bdf_get_bdf_property( BDF_Face face, + FT_CALLBACK_DEF( FT_Error ) + bdf_get_bdf_property( FT_Face face, /* BDF_Face */ const char* prop_name, BDF_PropertyRec *aproperty ) { + BDF_Face bdfface = (BDF_Face)face; bdf_property_t* prop; - FT_ASSERT( face && face->bdffont ); + FT_ASSERT( bdfface && bdfface->bdffont ); - prop = bdf_get_font_property( face->bdffont, prop_name ); + prop = bdf_get_font_property( bdfface->bdffont, prop_name ); if ( prop ) { switch ( prop->format ) @@ -902,7 +894,8 @@ THE SOFTWARE. if ( prop->value.l > 0x7FFFFFFFL || prop->value.l < ( -1 - 0x7FFFFFFFL ) ) { FT_TRACE1(( "bdf_get_bdf_property:" - " too large integer 0x%x is truncated\n" )); + " too large integer 0x%lx is truncated\n", + prop->value.l )); } aproperty->type = BDF_PROPERTY_TYPE_INTEGER; aproperty->u.integer = (FT_Int32)prop->value.l; @@ -912,7 +905,8 @@ THE SOFTWARE. if ( prop->value.ul > 0xFFFFFFFFUL ) { FT_TRACE1(( "bdf_get_bdf_property:" - " too large cardinal 0x%x is truncated\n" )); + " too large cardinal 0x%lx is truncated\n", + prop->value.ul )); } aproperty->type = BDF_PROPERTY_TYPE_CARDINAL; aproperty->u.cardinal = (FT_UInt32)prop->value.ul; @@ -929,13 +923,16 @@ THE SOFTWARE. } - static FT_Error - bdf_get_charset_id( BDF_Face face, + FT_CALLBACK_DEF( FT_Error ) + bdf_get_charset_id( FT_Face face, /* BDF_Face */ const char* *acharset_encoding, const char* *acharset_registry ) { - *acharset_encoding = face->charset_encoding; - *acharset_registry = face->charset_registry; + BDF_Face bdfface = (BDF_Face)face; + + + *acharset_encoding = bdfface->charset_encoding; + *acharset_registry = bdfface->charset_registry; return 0; } @@ -972,7 +969,6 @@ THE SOFTWARE. } - FT_CALLBACK_TABLE_DEF const FT_Driver_ClassRec bdf_driver_class = { |