36 #include FT_FREETYPE_H 37 #include FT_INTERNAL_DEBUG_H 38 #include FT_INTERNAL_STREAM_H 39 #include FT_INTERNAL_OBJECTS_H 52 #define FT_COMPONENT trace_bdflib 82 { (
char *)
"ADD_STYLE_NAME",
BDF_ATOM, 1, { 0 } },
84 { (
char *)
"AVG_CAPITAL_WIDTH",
BDF_INTEGER, 1, { 0 } },
85 { (
char *)
"AVG_LOWERCASE_WIDTH",
BDF_INTEGER, 1, { 0 } },
87 { (
char *)
"CHARSET_COLLECTIONS",
BDF_ATOM, 1, { 0 } },
88 { (
char *)
"CHARSET_ENCODING",
BDF_ATOM, 1, { 0 } },
89 { (
char *)
"CHARSET_REGISTRY",
BDF_ATOM, 1, { 0 } },
90 { (
char *)
"COMMENT",
BDF_ATOM, 1, { 0 } },
91 { (
char *)
"COPYRIGHT",
BDF_ATOM, 1, { 0 } },
94 { (
char *)
"DEVICE_FONT_NAME",
BDF_ATOM, 1, { 0 } },
96 { (
char *)
"FACE_NAME",
BDF_ATOM, 1, { 0 } },
97 { (
char *)
"FAMILY_NAME",
BDF_ATOM, 1, { 0 } },
99 { (
char *)
"FONT",
BDF_ATOM, 1, { 0 } },
100 { (
char *)
"FONTNAME_REGISTRY",
BDF_ATOM, 1, { 0 } },
103 { (
char *)
"FOUNDRY",
BDF_ATOM, 1, { 0 } },
104 { (
char *)
"FULL_NAME",
BDF_ATOM, 1, { 0 } },
109 { (
char *)
"NOTICE",
BDF_ATOM, 1, { 0 } },
114 { (
char *)
"RAW_AVERAGE_WIDTH",
BDF_INTEGER, 1, { 0 } },
115 { (
char *)
"RAW_AVG_CAPITAL_WIDTH",
BDF_INTEGER, 1, { 0 } },
116 { (
char *)
"RAW_AVG_LOWERCASE_WIDTH",
BDF_INTEGER, 1, { 0 } },
117 { (
char *)
"RAW_CAP_HEIGHT",
BDF_INTEGER, 1, { 0 } },
119 { (
char *)
"RAW_END_SPACE",
BDF_INTEGER, 1, { 0 } },
120 { (
char *)
"RAW_FIGURE_WIDTH",
BDF_INTEGER, 1, { 0 } },
121 { (
char *)
"RAW_MAX_SPACE",
BDF_INTEGER, 1, { 0 } },
122 { (
char *)
"RAW_MIN_SPACE",
BDF_INTEGER, 1, { 0 } },
123 { (
char *)
"RAW_NORM_SPACE",
BDF_INTEGER, 1, { 0 } },
124 { (
char *)
"RAW_PIXEL_SIZE",
BDF_INTEGER, 1, { 0 } },
125 { (
char *)
"RAW_POINT_SIZE",
BDF_INTEGER, 1, { 0 } },
126 { (
char *)
"RAW_PIXELSIZE",
BDF_INTEGER, 1, { 0 } },
127 { (
char *)
"RAW_POINTSIZE",
BDF_INTEGER, 1, { 0 } },
128 { (
char *)
"RAW_QUAD_WIDTH",
BDF_INTEGER, 1, { 0 } },
129 { (
char *)
"RAW_SMALL_CAP_SIZE",
BDF_INTEGER, 1, { 0 } },
130 { (
char *)
"RAW_STRIKEOUT_ASCENT",
BDF_INTEGER, 1, { 0 } },
131 { (
char *)
"RAW_STRIKEOUT_DESCENT",
BDF_INTEGER, 1, { 0 } },
132 { (
char *)
"RAW_SUBSCRIPT_SIZE",
BDF_INTEGER, 1, { 0 } },
133 { (
char *)
"RAW_SUBSCRIPT_X",
BDF_INTEGER, 1, { 0 } },
134 { (
char *)
"RAW_SUBSCRIPT_Y",
BDF_INTEGER, 1, { 0 } },
135 { (
char *)
"RAW_SUPERSCRIPT_SIZE",
BDF_INTEGER, 1, { 0 } },
136 { (
char *)
"RAW_SUPERSCRIPT_X",
BDF_INTEGER, 1, { 0 } },
137 { (
char *)
"RAW_SUPERSCRIPT_Y",
BDF_INTEGER, 1, { 0 } },
138 { (
char *)
"RAW_UNDERLINE_POSITION",
BDF_INTEGER, 1, { 0 } },
139 { (
char *)
"RAW_UNDERLINE_THICKNESS",
BDF_INTEGER, 1, { 0 } },
141 { (
char *)
"RELATIVE_SETWIDTH",
BDF_CARDINAL, 1, { 0 } },
146 { (
char *)
"SETWIDTH_NAME",
BDF_ATOM, 1, { 0 } },
147 { (
char *)
"SLANT",
BDF_ATOM, 1, { 0 } },
148 { (
char *)
"SMALL_CAP_SIZE",
BDF_INTEGER, 1, { 0 } },
149 { (
char *)
"SPACING",
BDF_ATOM, 1, { 0 } },
150 { (
char *)
"STRIKEOUT_ASCENT",
BDF_INTEGER, 1, { 0 } },
151 { (
char *)
"STRIKEOUT_DESCENT",
BDF_INTEGER, 1, { 0 } },
152 { (
char *)
"SUBSCRIPT_SIZE",
BDF_INTEGER, 1, { 0 } },
155 { (
char *)
"SUPERSCRIPT_SIZE",
BDF_INTEGER, 1, { 0 } },
156 { (
char *)
"SUPERSCRIPT_X",
BDF_INTEGER, 1, { 0 } },
157 { (
char *)
"SUPERSCRIPT_Y",
BDF_INTEGER, 1, { 0 } },
158 { (
char *)
"UNDERLINE_POSITION",
BDF_INTEGER, 1, { 0 } },
159 { (
char *)
"UNDERLINE_THICKNESS",
BDF_INTEGER, 1, { 0 } },
161 { (
char *)
"WEIGHT_NAME",
BDF_ATOM, 1, { 0 } },
163 { (
char *)
"_MULE_BASELINE_OFFSET",
BDF_INTEGER, 1, { 0 } },
164 { (
char *)
"_MULE_RELATIVE_COMPOSE",
BDF_INTEGER, 1, { 0 } },
167 static const unsigned long 168 _num_bdf_properties =
sizeof ( _bdf_properties ) /
169 sizeof ( _bdf_properties[0] );
173 #define ACMSG1 "FONT_ASCENT property missing. " \ 174 "Added `FONT_ASCENT %hd'.\n" 175 #define ACMSG2 "FONT_DESCENT property missing. " \ 176 "Added `FONT_DESCENT %hd'.\n" 177 #define ACMSG3 "Font width != actual width. Old: %hd New: %hd.\n" 178 #define ACMSG4 "Font left bearing != actual left bearing. " \ 179 "Old: %hd New: %hd.\n" 180 #define ACMSG5 "Font ascent != actual ascent. Old: %hd New: %hd.\n" 181 #define ACMSG6 "Font descent != actual descent. Old: %hd New: %hd.\n" 182 #define ACMSG7 "Font height != actual height. Old: %hd New: %hd.\n" 183 #define ACMSG8 "Glyph scalable width (SWIDTH) adjustments made.\n" 184 #define ACMSG9 "SWIDTH field missing at line %ld. Set automatically.\n" 185 #define ACMSG10 "DWIDTH field missing at line %ld. Set to glyph width.\n" 186 #define ACMSG11 "SIZE bits per pixel field adjusted to %hd.\n" 187 #define ACMSG12 "Duplicate encoding %ld (%s) changed to unencoded.\n" 188 #define ACMSG13 "Glyph %ld extra rows removed.\n" 189 #define ACMSG14 "Glyph %ld extra columns removed.\n" 190 #define ACMSG15 "Incorrect glyph count: %ld indicated but %ld found.\n" 191 #define ACMSG16 "Glyph %ld missing columns padded with zero bits.\n" 194 #define ERRMSG1 "[line %ld] Missing `%s' line.\n" 195 #define ERRMSG2 "[line %ld] Font header corrupted or missing fields.\n" 196 #define ERRMSG3 "[line %ld] Font glyphs corrupted or missing fields.\n" 197 #define ERRMSG4 "[line %ld] BBX too big.\n" 198 #define ERRMSG5 "[line %ld] `%s' value too big.\n" 199 #define ERRMSG6 "[line %ld] Input line too long.\n" 200 #define ERRMSG7 "[line %ld] Font name too long.\n" 201 #define ERRMSG8 "[line %ld] Invalid `%s' value.\n" 202 #define ERRMSG9 "[line %ld] Invalid keyword.\n" 205 #define DBGMSG1 " [%6ld] %s" 206 #define DBGMSG2 " (0x%lX)\n" 218 #define INITIAL_HT_SIZE 241 224 hash_bucket(
const char* key,
227 const char* kp = key;
228 unsigned long res = 0;
234 res = ( res << 5 ) - res + *kp++;
236 ndp = bp + ( res % ht->
size );
240 if ( kp[0] == key[0] &&
ft_strcmp( kp, key ) == 0 )
244 ndp = bp + ( ht->
size - 1 );
256 int i, sz = ht->
size;
266 for ( i = 0, bp = obp; i < sz; i++, bp++ )
270 nbp = hash_bucket( (*bp)->key, ht );
307 int i, sz = ht->
size;
311 for ( i = 0; i < sz; i++, bp++ )
320 hash_insert(
char* key,
326 hashnode* bp = hash_bucket( key, ht );
342 error = hash_rehash( ht, memory );
357 hash_lookup(
const char* key,
360 hashnode *np = hash_bucket( key, ht );
378 unsigned long linelen,
379 unsigned long lineno,
386 typedef struct _bdf_list_t_
398 typedef struct _bdf_parse_t_
418 unsigned long have[34816];
427 #define setsbit( m, cc ) \ 428 ( m[(FT_Byte)(cc) >> 3] |= (FT_Byte)( 1 << ( (cc) & 7 ) ) ) 429 #define sbitset( m, cc ) \ 430 ( m[(FT_Byte)(cc) >> 3] & ( 1 << ( (cc) & 7 ) ) ) 438 list->memory = memory;
458 unsigned long num_items )
463 if ( num_items > list->size )
465 unsigned long oldsize = list->size;
466 unsigned long newsize = oldsize + ( oldsize >> 1 ) + 5;
467 unsigned long bigsize = (
unsigned long)(
FT_INT_MAX /
sizeof (
char* ) );
471 if ( oldsize == bigsize )
476 else if ( newsize < oldsize || newsize > bigsize )
482 list->size = newsize;
497 if ( list == 0 || list->used == 0 || n == 0 )
500 if ( n >= list->used )
506 for ( u = n, i = 0; u < list->used; i++, u++ )
507 list->field[i] = list->field[u];
514 static const char empty[1] = { 0 };
520 unsigned long *alen )
528 if ( list == 0 || list->used == 0 )
532 for ( i = j = 0; i < list->used; i++ )
538 if ( i + 1 < list->used )
557 unsigned long linelen )
559 int mult, final_empty;
569 list->field[0] = (
char*)empty;
570 list->field[1] = (
char*)empty;
571 list->field[2] = (
char*)empty;
572 list->field[3] = (
char*)empty;
573 list->field[4] = (
char*)empty;
577 if ( linelen == 0 || line[0] == 0 )
583 if ( separators == 0 || *separators == 0 )
585 error =
FT_THROW( Invalid_Argument );
595 for ( mult = 0, sp = separators; sp && *sp; sp++ )
597 if ( *sp ==
'+' && *( sp + 1 ) == 0 )
604 for ( final_empty = 0, sp = ep = line, end = sp + linelen;
608 for ( ; *ep && !
sbitset( seps, *ep ); ep++ )
612 if ( list->used == list->size )
614 error = _bdf_list_ensure( list, list->used + 1 );
620 list->field[list->used++] = ( ep > sp ) ? sp : (
char*)empty;
628 for ( ; *ep &&
sbitset( seps, *ep ); ep++ )
636 final_empty = ( ep > sp && *ep == 0 );
641 if ( list->used + final_empty >= list->size )
643 error = _bdf_list_ensure( list, list->used + final_empty + 1 );
649 list->field[list->used++] = (
char*)empty;
651 list->field[list->used] = 0;
668 unsigned long lineno, buf_size;
669 int refill, hold, to_skip;
670 ptrdiff_t bytes,
start,
end, cursor, avail;
678 error =
FT_THROW( Invalid_Argument );
704 stream, (
FT_Byte*)buf + cursor,
706 avail = cursor + bytes;
714 if ( start < avail && buf[start] == to_skip )
722 while ( end < avail && buf[end] !=
'\n' && buf[end] !=
'\r' )
739 if ( buf_size >= 65536UL )
742 error =
FT_THROW( Invalid_Argument );
746 new_size = buf_size * 2;
755 bytes = avail -
start;
772 if ( buf[start] !=
'#' && buf[start] != 0x1a && end > start )
774 error = (*cb)( buf +
start, (
unsigned long)( end - start ), lineno,
775 (
void*)&cb, client_data );
778 error = (*cb)( buf +
start, (
unsigned long)( end - start ), lineno,
779 (
void*)&cb, client_data );
785 buf[
end] = (char)hold;
790 else if ( hold ==
'\r' )
806 static const unsigned char a2i[128] =
808 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
809 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
810 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
811 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
812 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x00, 0x00,
813 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00,
814 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
815 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
816 0x00, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00,
817 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
818 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
821 static const unsigned char odigits[32] =
823 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00,
824 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
825 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
826 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
829 static const unsigned char ddigits[32] =
831 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x03,
832 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
833 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
834 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
837 static const unsigned char hdigits[32] =
839 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x03,
840 0x7e, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x00,
841 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
842 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
853 const unsigned char* dmap;
856 if ( s == 0 || *s == 0 )
876 ( *( s + 1 ) ==
'x' || *( s + 1 ) ==
'X' ) )
883 for ( v = 0;
sbitset( dmap, *s ); s++ )
884 v = v * base + a2i[(
int)*
s];
900 const unsigned char* dmap;
903 if ( s == 0 || *s == 0 )
931 ( *( s + 1 ) ==
'x' || *( s + 1 ) ==
'X' ) )
938 for ( v = 0;
sbitset( dmap, *s ); s++ )
939 v = v * base + a2i[(
int)*
s];
944 return ( !neg ) ?
v : -
v;
955 const unsigned char* dmap;
958 if ( s == 0 || *s == 0 )
986 ( *( s + 1 ) ==
'x' || *( s + 1 ) ==
'X' ) )
993 for ( v = 0;
sbitset( dmap, *s ); s++ )
994 v = (
short)( v * base + a2i[(
int)*s] );
999 return (
short)( ( !neg ) ? v : -v );
1005 by_encoding(
const void*
a,
1025 bdf_create_property(
char*
name,
1038 if ( hash_lookup( name, &(font->
proptbl) ) )
1051 return FT_THROW( Invalid_Argument );
1063 error = hash_insert( p->
name, n, &(font->
proptbl), memory );
1082 if ( name == 0 || *name == 0 )
1085 if ( ( hn = hash_lookup( name, &(font->proptbl) ) ) == 0 )
1089 if ( propid >= _num_bdf_properties )
1090 return font->user_props + ( propid - _num_bdf_properties );
1105 #define _BDF_START 0x0001 1106 #define _BDF_FONT_NAME 0x0002 1107 #define _BDF_SIZE 0x0004 1108 #define _BDF_FONT_BBX 0x0008 1109 #define _BDF_PROPS 0x0010 1110 #define _BDF_GLYPHS 0x0020 1111 #define _BDF_GLYPH 0x0040 1112 #define _BDF_ENCODING 0x0080 1113 #define _BDF_SWIDTH 0x0100 1114 #define _BDF_DWIDTH 0x0200 1115 #define _BDF_BBX 0x0400 1116 #define _BDF_BITMAP 0x0800 1118 #define _BDF_SWIDTH_ADJ 0x1000 1120 #define _BDF_GLYPH_BITS ( _BDF_GLYPH | \ 1127 #define _BDF_GLYPH_WIDTH_CHECK 0x40000000UL 1128 #define _BDF_GLYPH_HEIGHT_CHECK 0x80000000UL 1163 unsigned long lineno )
1172 if ( font == 0 || font->
name == 0 || font->
name[0] == 0 )
1174 error =
FT_THROW( Invalid_Argument );
1180 _bdf_list_init( &list, memory );
1189 error =
FT_THROW( Invalid_Argument );
1195 error = _bdf_list_split( &list, (
char *)
"-", name, len );
1199 if ( list.used == 15 )
1201 switch ( list.field[11][0] )
1219 _bdf_list_done( &list );
1229 _bdf_is_atom(
char* line,
1230 unsigned long linelen,
1240 *name = sp = ep = line;
1242 while ( *ep && *ep !=
' ' && *ep !=
'\t' )
1265 ep = line + linelen;
1271 ( *sp ==
' ' || *sp ==
'\t' ) )
1281 ( *( ep - 1 ) ==
' ' || *( ep - 1 ) ==
'\t' ) )
1285 if ( ep > sp && *( ep - 1 ) ==
'"' )
1296 unsigned long lineno )
1318 if ( value && value[0] != 0 )
1326 fp->
value.
l = _bdf_atol( value, 0, 10 );
1330 fp->
value.
ul = _bdf_atoul( value, 0, 10 );
1342 hn = hash_lookup( name, &(font->
proptbl) );
1345 error = bdf_create_property( name,
BDF_ATOM, font );
1348 hn = hash_lookup( name, &(font->
proptbl) );
1373 if ( propid >= _num_bdf_properties )
1374 prop = font->
user_props + ( propid - _num_bdf_properties );
1388 if ( value != 0 && value[0] )
1396 fp->
value.
l = _bdf_atol( value, 0, 10 );
1400 fp->
value.
ul = _bdf_atoul( value, 0, 10 );
1406 if (
ft_memcmp( name,
"COMMENT", 7 ) != 0 )
1409 error = hash_insert( fp->
name,
1424 if (
ft_memcmp( name,
"DEFAULT_CHAR", 12 ) == 0 )
1426 else if (
ft_memcmp( name,
"FONT_ASCENT", 11 ) == 0 )
1428 else if (
ft_memcmp( name,
"FONT_DESCENT", 12 ) == 0 )
1430 else if (
ft_memcmp( name,
"SPACING", 7 ) == 0 )
1435 error =
FT_THROW( Invalid_File_Format );
1452 static const unsigned char nibble_mask[8] =
1454 0xFF, 0x80, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC, 0xFE
1460 _bdf_parse_glyphs(
char* line,
1461 unsigned long linelen,
1462 unsigned long lineno,
1469 unsigned long i, slen, nibbles;
1488 if (
ft_memcmp( line,
"COMMENT", 7 ) == 0 )
1498 error = _bdf_add_comment( p->font, s, linelen );
1505 if (
ft_memcmp( line,
"CHARS", 5 ) != 0 )
1508 error =
FT_THROW( Missing_Chars_Field );
1512 error = _bdf_list_split( &p->list, (
char *)
" +", line, linelen );
1515 p->cnt = font->
glyphs_size = _bdf_atoul( p->list.field[1], 0, 10 );
1523 if ( p->cnt >= 0x110000UL )
1526 error =
FT_THROW( Invalid_Argument );
1539 if (
ft_memcmp( line,
"ENDFONT", 7 ) == 0 )
1553 if (
ft_memcmp( line,
"ENDCHAR", 7 ) == 0 )
1564 p->glyph_enc == -1 &&
1565 p->opts->keep_unencoded == 0 )
1569 if (
ft_memcmp( line,
"STARTCHAR", 9 ) == 0 )
1575 error = _bdf_list_split( &p->list, (
char *)
" +", line, linelen );
1579 _bdf_list_shift( &p->list, 1 );
1581 s = _bdf_list_join( &p->list,
' ', &slen );
1586 error =
FT_THROW( Invalid_File_Format );
1603 if (
ft_memcmp( line,
"ENCODING", 8 ) == 0 )
1609 error =
FT_THROW( Missing_Startchar_Field );
1613 error = _bdf_list_split( &p->list, (
char *)
" +", line, linelen );
1617 p->glyph_enc = _bdf_atol( p->list.field[1], 0, 10 );
1621 if ( p->glyph_enc < -1 )
1625 if ( p->glyph_enc == -1 && p->list.used > 2 )
1626 p->glyph_enc = _bdf_atol( p->list.field[2], 0, 10 );
1628 if ( p->glyph_enc < -1 )
1635 if ( p->glyph_enc > 0 &&
1636 (
size_t)p->glyph_enc >=
sizeof ( p->have ) /
1637 sizeof (
unsigned long ) * 32 )
1640 error =
FT_THROW( Invalid_File_Format );
1647 if ( p->glyph_enc >= 0 )
1654 p->glyph_enc, p->glyph_name ));
1662 if ( p->glyph_enc >= 0 )
1677 glyph->
name = p->glyph_name;
1687 if ( p->opts->keep_unencoded != 0 )
1701 glyph->
name = p->glyph_name;
1722 if ( p->glyph_enc == -1 )
1732 if ( p->row >= (
unsigned long)glyph->
bbx.
height )
1746 nibbles = glyph->
bpr << 1;
1747 bp = glyph->
bitmap + p->row * glyph->
bpr;
1749 for ( i = 0; i < nibbles; i++ )
1754 *bp = (
FT_Byte)( ( *bp << 4 ) + a2i[
c] );
1755 if ( i + 1 < nibbles && ( i & 1 ) )
1770 mask_index = ( glyph->
bbx.
width * p->font->bpp ) & 7;
1772 *bp &= nibble_mask[mask_index];
1775 if ( i == nibbles &&
1776 sbitset( hdigits, line[nibbles] ) &&
1789 if (
ft_memcmp( line,
"SWIDTH", 6 ) == 0 )
1792 goto Missing_Encoding;
1794 error = _bdf_list_split( &p->list, (
char *)
" +", line, linelen );
1798 glyph->
swidth = (
unsigned short)_bdf_atoul( p->list.field[1], 0, 10 );
1805 if (
ft_memcmp( line,
"DWIDTH", 6 ) == 0 )
1808 goto Missing_Encoding;
1810 error = _bdf_list_split( &p->list, (
char *)
" +", line, linelen );
1814 glyph->
dwidth = (
unsigned short)_bdf_atoul( p->list.field[1], 0, 10 );
1836 goto Missing_Encoding;
1838 error = _bdf_list_split( &p->list, (
char *)
" +", line, linelen );
1842 glyph->
bbx.
width = _bdf_atos( p->list.field[1], 0, 10 );
1843 glyph->
bbx.
height = _bdf_atos( p->list.field[2], 0, 10 );
1844 glyph->
bbx.
x_offset = _bdf_atos( p->list.field[3], 0, 10 );
1845 glyph->
bbx.
y_offset = _bdf_atos( p->list.field[4], 0, 10 );
1858 p->maxrb = (short)
FT_MAX( p->rbearing, p->maxrb );
1872 if ( p->opts->correct_metrics != 0 )
1875 unsigned short sw = (
unsigned short)
FT_MulDiv(
1881 if ( sw != glyph->
swidth )
1885 if ( p->glyph_enc == -1 )
1901 if (
ft_memcmp( line,
"BITMAP", 6 ) == 0 )
1903 unsigned long bitmap_size;
1910 error =
FT_THROW( Missing_Bbx_Field );
1915 glyph->
bpr = ( glyph->
bbx.
width * p->font->bpp + 7 ) >> 3;
1918 if ( glyph->
bpr > 0xFFFFU || bitmap_size > 0xFFFFU )
1925 glyph->
bytes = (
unsigned short)bitmap_size;
1937 error =
FT_THROW( Invalid_File_Format );
1943 error =
FT_THROW( Missing_Encoding_Field );
1955 _bdf_parse_properties(
char* line,
1956 unsigned long linelen,
1957 unsigned long lineno,
1976 if (
ft_memcmp( line,
"ENDPROPERTIES", 13 ) == 0 )
1986 p->font->font_ascent = p->font->bbx.ascent;
1987 ft_sprintf( nbuf,
"%hd", p->font->bbx.ascent );
1988 error = _bdf_add_property( p->font, (
char *)
"FONT_ASCENT",
1994 p->font->modified = 1;
1999 p->font->font_descent = p->font->bbx.descent;
2000 ft_sprintf( nbuf,
"%hd", p->font->bbx.descent );
2001 error = _bdf_add_property( p->font, (
char *)
"FONT_DESCENT",
2006 FT_TRACE2((
"_bdf_parse_properties: " ACMSG2, p->font->bbx.descent ));
2007 p->font->modified = 1;
2011 *next = _bdf_parse_glyphs;
2017 if (
ft_memcmp( line,
"_XFREE86_GLYPH_RANGES", 21 ) == 0 )
2022 if (
ft_memcmp( line,
"COMMENT", 7 ) == 0 )
2024 name = value = line;
2028 error = _bdf_add_property( p->font, name, value, lineno );
2032 else if ( _bdf_is_atom( line, linelen, &name, &value, p->font ) )
2034 error = _bdf_add_property( p->font, name, value, lineno );
2040 error = _bdf_list_split( &p->list, (
char *)
" +", line, linelen );
2043 name = p->list.field[0];
2045 _bdf_list_shift( &p->list, 1 );
2046 value = _bdf_list_join( &p->list,
' ', &vlen );
2048 error = _bdf_add_property( p->font, name, value, lineno );
2060 _bdf_parse_start(
char* line,
2061 unsigned long linelen,
2062 unsigned long lineno,
2082 memory = p->font->memory;
2086 if (
ft_memcmp( line,
"COMMENT", 7 ) == 0 )
2088 if ( p->opts->keep_comments != 0 && p->font != 0 )
2099 error = _bdf_add_comment( p->font, s, linelen );
2112 if (
ft_memcmp( line,
"STARTFONT", 9 ) != 0 )
2116 error =
FT_THROW( Missing_Startfont_Field );
2127 font->
memory = p->memory;
2135 error = hash_init( &(font->
proptbl), memory );
2139 i < _num_bdf_properties; i++, prop++ )
2141 error = hash_insert( prop->
name, i,
2150 error = hash_init( (
hashtable *)p->font->internal,memory );
2153 p->font->spacing = p->opts->font_spacing;
2154 p->font->default_char = -1;
2160 if (
ft_memcmp( line,
"STARTPROPERTIES", 15 ) == 0 )
2165 FT_ERROR((
"_bdf_parse_start: " ERRMSG1, lineno,
"FONTBOUNDINGBOX" ));
2166 error =
FT_THROW( Missing_Fontboundingbox_Field );
2170 error = _bdf_list_split( &p->list, (
char *)
" +", line, linelen );
2174 p->cnt = p->font->props_size = _bdf_atoul( p->list.field[1], 0, 10 );
2178 p->font->props_size = 0;
2183 *next = _bdf_parse_properties;
2189 if (
ft_memcmp( line,
"FONTBOUNDINGBOX", 15 ) == 0 )
2195 error =
FT_THROW( Missing_Size_Field );
2199 error = _bdf_list_split( &p->list, (
char *)
" +", line, linelen );
2203 p->font->bbx.width = _bdf_atos( p->list.field[1], 0, 10 );
2204 p->font->bbx.height = _bdf_atos( p->list.field[2], 0, 10 );
2206 p->font->bbx.x_offset = _bdf_atos( p->list.field[3], 0, 10 );
2207 p->font->bbx.y_offset = _bdf_atos( p->list.field[4], 0, 10 );
2209 p->font->bbx.ascent = (short)( p->font->bbx.height +
2210 p->font->bbx.y_offset );
2212 p->font->bbx.descent = (short)( -p->font->bbx.y_offset );
2220 if (
ft_memcmp( line,
"FONT", 4 ) == 0 )
2222 error = _bdf_list_split( &p->list, (
char *)
" +", line, linelen );
2225 _bdf_list_shift( &p->list, 1 );
2227 s = _bdf_list_join( &p->list,
' ', &slen );
2232 error =
FT_THROW( Invalid_File_Format );
2245 error = _bdf_set_default_spacing( p->font, p->opts, lineno );
2255 if (
ft_memcmp( line,
"SIZE", 4 ) == 0 )
2261 error =
FT_THROW( Missing_Font_Field );
2265 error = _bdf_list_split( &p->list, (
char *)
" +", line, linelen );
2269 p->font->point_size = _bdf_atoul( p->list.field[1], 0, 10 );
2270 p->font->resolution_x = _bdf_atoul( p->list.field[2], 0, 10 );
2271 p->font->resolution_y = _bdf_atoul( p->list.field[3], 0, 10 );
2274 if ( p->list.used == 5 )
2276 unsigned short bitcount,
i, shift;
2279 p->font->bpp = (
unsigned short)_bdf_atos( p->list.field[4], 0, 10 );
2282 shift = p->font->bpp;
2284 for ( i = 0; shift > 0; i++ )
2291 shift = (short)( ( bitcount > 3 ) ? 8 : ( 1 << bitcount ) );
2293 if ( p->font->bpp > shift || p->font->bpp != shift )
2296 p->font->bpp = (
unsigned short)( shift << 1 );
2309 if (
ft_memcmp( line,
"CHARS", 5 ) == 0 )
2317 FT_ERROR((
"_bdf_parse_start: " ERRMSG1, lineno,
"FONTBOUNDINGBOX" ));
2318 error =
FT_THROW( Missing_Fontboundingbox_Field );
2324 p->font->font_ascent = p->font->bbx.ascent;
2325 ft_sprintf( nbuf,
"%hd", p->font->bbx.ascent );
2326 error = _bdf_add_property( p->font, (
char *)
"FONT_ASCENT",
2332 p->font->font_descent = p->font->bbx.descent;
2333 ft_sprintf( nbuf,
"%hd", p->font->bbx.descent );
2334 error = _bdf_add_property( p->font, (
char *)
"FONT_DESCENT",
2338 FT_TRACE2((
"_bdf_parse_properties: " ACMSG2, p->font->bbx.descent ));
2340 p->font->modified = 1;
2342 *next = _bdf_parse_glyphs;
2350 error =
FT_THROW( Invalid_File_Format );
2370 unsigned long lineno = 0;
2381 p->opts = (
bdf_options_t*)( ( opts != 0 ) ? opts : &_bdf_opts );
2383 p->memory = extmemory;
2385 _bdf_list_init( &p->list, extmemory );
2387 error = _bdf_readstream( stream, _bdf_parse_start,
2388 (
void *)p, &lineno );
2396 memory = p->font->memory;
2399 p->font->monowidth = p->font->bbx.width;
2403 if ( p->cnt != p->font->glyphs_used + p->font->unencoded_used )
2406 p->font->glyphs_used + p->font->unencoded_used ));
2407 p->font->modified = 1;
2412 if ( p->opts->correct_metrics != 0 &&
2413 ( p->font->glyphs_used > 0 || p->font->unencoded_used > 0 ) )
2415 if ( p->maxrb - p->minlb != p->font->bbx.width )
2418 p->font->bbx.width, p->maxrb - p->minlb ));
2419 p->font->bbx.width = (
unsigned short)( p->maxrb - p->minlb );
2420 p->font->modified = 1;
2423 if ( p->font->bbx.x_offset != p->minlb )
2426 p->font->bbx.x_offset, p->minlb ));
2427 p->font->bbx.x_offset = p->minlb;
2428 p->font->modified = 1;
2431 if ( p->font->bbx.ascent != p->maxas )
2434 p->font->bbx.ascent, p->maxas ));
2435 p->font->bbx.ascent = p->maxas;
2436 p->font->modified = 1;
2439 if ( p->font->bbx.descent != p->maxds )
2442 p->font->bbx.descent, p->maxds ));
2443 p->font->bbx.descent = p->maxds;
2444 p->font->bbx.y_offset = (short)( -p->maxds );
2445 p->font->modified = 1;
2448 if ( p->maxas + p->maxds != p->font->bbx.height )
2451 p->font->bbx.height, p->maxas + p->maxds ));
2452 p->font->bbx.height = (
unsigned short)( p->maxas + p->maxds );
2467 error =
FT_THROW( Corrupted_Font_Header );
2474 error =
FT_THROW( Corrupted_Font_Glyphs );
2482 memory = p->font->memory;
2484 if ( p->font->comments_len > 0 )
2487 p->font->comments_len,
2488 p->font->comments_len + 1 ) )
2491 p->font->comments[p->font->comments_len] = 0;
2495 error =
FT_THROW( Invalid_File_Format );
2502 _bdf_list_done( &p->list );
2534 memory = font->memory;
2539 if ( font->internal )
2541 hash_free( (
hashtable *)font->internal, memory );
2549 for (
i = 0;
i < font->props_size;
i++ )
2551 if ( font->props[
i].format ==
BDF_ATOM )
2552 FT_FREE( font->props[
i].value.atom );
2558 for (
i = 0, glyphs = font->glyphs;
2559 i < font->glyphs_used;
i++, glyphs++ )
2565 for (
i = 0, glyphs = font->unencoded; i < font->unencoded_used;
2576 for (
i = 0, glyphs = font->overflow.glyphs;
2577 i < font->overflow.glyphs_used;
i++, glyphs++ )
2583 FT_FREE( font->overflow.glyphs );
2586 hash_free( &(font->proptbl), memory );
2589 for ( prop = font->user_props,
i = 0;
2590 i < font->nuser_props;
i++, prop++ )
2610 if ( font == 0 || font->props_size == 0 ||
name == 0 || *
name == 0 )
2615 return hn ? ( font->props + hn->
data ) : 0;
#define FT_ALLOC(ptr, size)
#define _BDF_GLYPH_WIDTH_CHECK
unsigned long unencoded_size
bdf_property_t * user_props
GLboolean GLboolean GLboolean GLboolean a
#define _bdf_set_glyph_modified(map, e)
#define _bdf_glyph_modified(map, e)
#define FT_MEM_ZERO(dest, count)
FT_Stream_TryRead(FT_Stream stream, FT_Byte *buffer, FT_ULong count)
return FT_THROW(Missing_Property)
void(* hash_free_func)(hashnode node)
typedef void(APIENTRY *GLDEBUGPROCARB)(GLenum source
GLboolean GLboolean GLboolean b
unsigned long resolution_x
bdf_get_property(char *name, bdf_font_t *font)
GLenum GLuint GLenum GLsizei const GLchar * buf
bdf_get_font_property(bdf_font_t *font, const char *name)
#define FT_ERROR(varformat)
GLenum GLenum GLvoid * row
#define FT_TRACE4(varformat)
FT_Error(* _bdf_line_func_t)(char *line, unsigned long linelen, unsigned long lineno, void *call_data, void *client_data)
struct _bdf_list_t_ _bdf_list_t
unsigned long glyphs_size
FT_MulDiv(FT_Long a, FT_Long b, FT_Long c)
GLsizei GLsizei GLenum GLenum const GLvoid * data
typedef long(ZCALLBACK *tell_file_func) OF((voidpf opaque
#define FT_TRACE2(varformat)
unsigned long nuser_props
bdf_load_font(FT_Stream stream, FT_Memory extmemory, bdf_options_t *opts, bdf_font_t **font)
#define FT_RENEW_ARRAY(ptr, curcnt, newcnt)
unsigned long unencoded_used
unsigned long comments_len
GLsizei const GLfloat * value
typedefFT_BEGIN_HEADER struct FT_MemoryRec_ * FT_Memory
#define FT_NEW_ARRAY(ptr, count)
GLuint const GLchar * name
bdf_free_font(bdf_font_t *font)
unsigned long nmod[34816]
#define FT_STRDUP(dst, str)
unsigned long glyphs_used
#define FT_MEM_COPY(dest, source, count)
#define FT_MEM_MOVE(dest, source, count)
unsigned long umod[34816]
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
#define _BDF_GLYPH_HEIGHT_CHECK
union bdf_property_t_::@7 value
struct _bdf_parse_t_ _bdf_parse_t