diff options
author | chai <chaifix@163.com> | 2021-10-30 13:28:39 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2021-10-30 13:28:39 +0800 |
commit | c3e259f4d29e9bdcb73617ad8e4d71f117b4d289 (patch) | |
tree | 893ed7b892d0b3b49db2d3e219da28fc2eea4769 /ThirdParty/freetype/src/bdf | |
parent | b2433cf2faf5c5c3d82d61c7b44928923c5fdcda (diff) |
+freetype
Diffstat (limited to 'ThirdParty/freetype/src/bdf')
-rw-r--r-- | ThirdParty/freetype/src/bdf/Jamfile | 31 | ||||
-rw-r--r-- | ThirdParty/freetype/src/bdf/README | 148 | ||||
-rw-r--r-- | ThirdParty/freetype/src/bdf/bdf.c | 35 | ||||
-rw-r--r-- | ThirdParty/freetype/src/bdf/bdf.h | 258 | ||||
-rw-r--r-- | ThirdParty/freetype/src/bdf/bdfdrivr.c | 1017 | ||||
-rw-r--r-- | ThirdParty/freetype/src/bdf/bdfdrivr.h | 73 | ||||
-rw-r--r-- | ThirdParty/freetype/src/bdf/bdferror.h | 45 | ||||
-rw-r--r-- | ThirdParty/freetype/src/bdf/bdflib.c | 2416 | ||||
-rw-r--r-- | ThirdParty/freetype/src/bdf/module.mk | 34 | ||||
-rw-r--r-- | ThirdParty/freetype/src/bdf/rules.mk | 84 |
10 files changed, 0 insertions, 4141 deletions
diff --git a/ThirdParty/freetype/src/bdf/Jamfile b/ThirdParty/freetype/src/bdf/Jamfile deleted file mode 100644 index a49c7f5..0000000 --- a/ThirdParty/freetype/src/bdf/Jamfile +++ /dev/null @@ -1,31 +0,0 @@ -# FreeType 2 src/bdf Jamfile -# -# Copyright (C) 2002-2019 by -# David Turner, Robert Wilhelm, and Werner Lemberg. -# -# This file is part of the FreeType project, and may only be used, modified, -# and distributed under the terms of the FreeType project license, -# LICENSE.TXT. By continuing to use, modify, or distribute this file you -# indicate that you have read the license and understand and accept it -# fully. - -SubDir FT2_TOP $(FT2_SRC_DIR) bdf ; - -{ - local _sources ; - - if $(FT2_MULTI) - { - _sources = bdfdrivr - bdflib - ; - } - else - { - _sources = bdf ; - } - - Library $(FT2_LIB) : $(_sources).c ; -} - -# end of src/bdf Jamfile diff --git a/ThirdParty/freetype/src/bdf/README b/ThirdParty/freetype/src/bdf/README deleted file mode 100644 index 996ac2d..0000000 --- a/ThirdParty/freetype/src/bdf/README +++ /dev/null @@ -1,148 +0,0 @@ - FreeType font driver for BDF fonts - - Francesco Zappa Nardelli - <francesco.zappa.nardelli@ens.fr> - - -Introduction -************ - -BDF (Bitmap Distribution Format) is a bitmap font format defined by Adobe, -which is intended to be easily understood by both humans and computers. -This code implements a BDF driver for the FreeType library, following the -Adobe Specification V 2.2. The specification of the BDF font format is -available from Adobe's web site: - - https://www.adobe.com/content/dam/acom/en/devnet/font/pdfs/5005.BDF_Spec.pdf - -Many good bitmap fonts in bdf format come with XFree86 (www.XFree86.org). -They do not define vertical metrics, because the X Consortium BDF -specification has removed them. - - -Encodings -********* - -The variety of encodings that accompanies bdf fonts appears to encompass the -small set defined in freetype.h. On the other hand, two properties that -specify encoding and registry are usually defined in bdf fonts. - -I decided to make these two properties directly accessible, leaving to the -client application the work of interpreting them. For instance: - - - #include FT_INTERNAL_BDF_TYPES_H - - FT_Face face; - BDF_Public_Face bdfface; - - - FT_New_Face( library, ..., &face ); - - bdfface = (BDF_Public_Face)face; - - if ( ( bdfface->charset_registry == "ISO10646" ) && - ( bdfface->charset_encoding == "1" ) ) - [..] - - -Thus the driver always exports `ft_encoding_none' as face->charmap.encoding. -FT_Get_Char_Index's behavior is unmodified, that is, it converts the ULong -value given as argument into the corresponding glyph number. - -If the two properties are not available, Adobe Standard Encoding should be -assumed. - - -Anti-Aliased Bitmaps -******************** - -The driver supports an extension to the BDF format as used in Mark Leisher's -xmbdfed bitmap font editor. Microsoft's SBIT tool expects bitmap fonts in -that format for adding anti-aliased them to TrueType fonts. It introduces a -fourth field to the `SIZE' keyword which gives the bpp value (bits per -pixel) of the glyph data in the font. Possible values are 1 (the default), -2 (four gray levels), 4 (16 gray levels), and 8 (256 gray levels). The -driver returns either a bitmap with 1 bit per pixel or a pixmap with 8bits -per pixel (using 4, 16, and 256 gray levels, respectively). - - -Known problems -************** - -- A font is entirely loaded into memory. Obviously, this is not the Right - Thing(TM). If you have big fonts I suggest you convert them into PCF - format (using the bdftopcf utility): the PCF font drive of FreeType can - perform incremental glyph loading. - -When I have some time, I will implement on-demand glyph parsing. - -- Except for encodings properties, client applications have no visibility of - the PCF_Face object. This means that applications cannot directly access - font tables and must trust FreeType. - -- Currently, glyph names are ignored. - - I plan to give full visibility of the BDF_Face object in an upcoming - revision of the driver, thus implementing also glyph names. - -- As I have never seen a BDF font that defines vertical metrics, vertical - metrics are (parsed and) discarded. If you own a BDF font that defines - vertical metrics, please let me know (I will implement them in 5-10 - minutes). - - -License -******* - -Copyright (C) 2001-2002 by Francesco Zappa Nardelli - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -*** Portions of the driver (that is, bdflib.c and bdf.h): - -Copyright 2000 Computing Research Labs, New Mexico State University -Copyright 2001-2002, 2011 Francesco Zappa Nardelli - -Permission is hereby granted, free of charge, to any person obtaining a -copy of this software and associated documentation files (the "Software"), -to deal in the Software without restriction, including without limitation -the rights to use, copy, modify, merge, publish, distribute, sublicense, -and/or sell copies of the Software, and to permit persons to whom the -Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -THE COMPUTING RESEARCH LAB OR NEW MEXICO STATE UNIVERSITY BE LIABLE FOR ANY -CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT -OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR -THE USE OR OTHER DEALINGS IN THE SOFTWARE. - - -Credits -******* - -This driver is based on excellent Mark Leisher's bdf library. If you -find something good in this driver you should probably thank him, not -me. diff --git a/ThirdParty/freetype/src/bdf/bdf.c b/ThirdParty/freetype/src/bdf/bdf.c deleted file mode 100644 index e54df66..0000000 --- a/ThirdParty/freetype/src/bdf/bdf.c +++ /dev/null @@ -1,35 +0,0 @@ -/* bdf.c - - FreeType font driver for bdf files - - Copyright (C) 2001, 2002 by - Francesco Zappa Nardelli - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -*/ - - -#define FT_MAKE_OPTION_SINGLE_OBJECT -#include <ft2build.h> - -#include "bdflib.c" -#include "bdfdrivr.c" - - -/* END */ diff --git a/ThirdParty/freetype/src/bdf/bdf.h b/ThirdParty/freetype/src/bdf/bdf.h deleted file mode 100644 index 4018756..0000000 --- a/ThirdParty/freetype/src/bdf/bdf.h +++ /dev/null @@ -1,258 +0,0 @@ -/* - * Copyright 2000 Computing Research Labs, New Mexico State University - * Copyright 2001-2004, 2011 Francesco Zappa Nardelli - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE COMPUTING RESEARCH LAB OR NEW MEXICO STATE UNIVERSITY BE LIABLE FOR ANY - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT - * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR - * THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - - -#ifndef BDF_H_ -#define BDF_H_ - - -/* - * Based on bdf.h,v 1.16 2000/03/16 20:08:51 mleisher - */ - -#include <ft2build.h> -#include FT_INTERNAL_OBJECTS_H -#include FT_INTERNAL_STREAM_H -#include FT_INTERNAL_HASH_H - - -FT_BEGIN_HEADER - - -/* Imported from bdfP.h */ - -#define _bdf_glyph_modified( map, e ) \ - ( (map)[(e) >> 5] & ( 1UL << ( (e) & 31 ) ) ) -#define _bdf_set_glyph_modified( map, e ) \ - ( (map)[(e) >> 5] |= ( 1UL << ( (e) & 31 ) ) ) -#define _bdf_clear_glyph_modified( map, e ) \ - ( (map)[(e) >> 5] &= ~( 1UL << ( (e) & 31 ) ) ) - -/* end of bdfP.h */ - - - /************************************************************************** - * - * BDF font options macros and types. - * - */ - - -#define BDF_CORRECT_METRICS 0x01 /* Correct invalid metrics when loading. */ -#define BDF_KEEP_COMMENTS 0x02 /* Preserve the font comments. */ -#define BDF_KEEP_UNENCODED 0x04 /* Keep the unencoded glyphs. */ -#define BDF_PROPORTIONAL 0x08 /* Font has proportional spacing. */ -#define BDF_MONOWIDTH 0x10 /* Font has mono width. */ -#define BDF_CHARCELL 0x20 /* Font has charcell spacing. */ - -#define BDF_ALL_SPACING ( BDF_PROPORTIONAL | \ - BDF_MONOWIDTH | \ - BDF_CHARCELL ) - -#define BDF_DEFAULT_LOAD_OPTIONS ( BDF_CORRECT_METRICS | \ - BDF_KEEP_COMMENTS | \ - BDF_KEEP_UNENCODED | \ - BDF_PROPORTIONAL ) - - - typedef struct bdf_options_t_ - { - int correct_metrics; - int keep_unencoded; - int keep_comments; - int font_spacing; - - } bdf_options_t; - - - /* Callback function type for unknown configuration options. */ - typedef int - (*bdf_options_callback_t)( bdf_options_t* opts, - char** params, - unsigned long nparams, - void* client_data ); - - - /************************************************************************** - * - * BDF font property macros and types. - * - */ - - -#define BDF_ATOM 1 -#define BDF_INTEGER 2 -#define BDF_CARDINAL 3 - - - /* This structure represents a particular property of a font. */ - /* There are a set of defaults and each font has their own. */ - typedef struct bdf_property_t_ - { - char* name; /* Name of the property. */ - int format; /* Format of the property. */ - int builtin; /* A builtin property. */ - union - { - char* atom; - long l; - unsigned long ul; - - } value; /* Value of the property. */ - - } bdf_property_t; - - - /************************************************************************** - * - * BDF font metric and glyph types. - * - */ - - - typedef struct bdf_bbx_t_ - { - unsigned short width; - unsigned short height; - - short x_offset; - short y_offset; - - short ascent; - short descent; - - } bdf_bbx_t; - - - typedef struct bdf_glyph_t_ - { - char* name; /* Glyph name. */ - unsigned long encoding; /* Glyph encoding. */ - unsigned short swidth; /* Scalable width. */ - unsigned short dwidth; /* Device width. */ - bdf_bbx_t bbx; /* Glyph bounding box. */ - unsigned char* bitmap; /* Glyph bitmap. */ - unsigned long bpr; /* Number of bytes used per row. */ - unsigned short bytes; /* Number of bytes used for the bitmap. */ - - } bdf_glyph_t; - - - typedef struct bdf_font_t_ - { - char* name; /* Name of the font. */ - bdf_bbx_t bbx; /* Font bounding box. */ - - unsigned long point_size; /* Point size of the font. */ - unsigned long resolution_x; /* Font horizontal resolution. */ - unsigned long resolution_y; /* Font vertical resolution. */ - - int spacing; /* Font spacing value. */ - - unsigned short monowidth; /* Logical width for monowidth font. */ - - unsigned long default_char; /* Encoding of the default glyph. */ - - long font_ascent; /* Font ascent. */ - long font_descent; /* Font descent. */ - - unsigned long glyphs_size; /* Glyph structures allocated. */ - unsigned long glyphs_used; /* Glyph structures used. */ - bdf_glyph_t* glyphs; /* Glyphs themselves. */ - - unsigned long unencoded_size; /* Unencoded glyph struct. allocated. */ - unsigned long unencoded_used; /* Unencoded glyph struct. used. */ - bdf_glyph_t* unencoded; /* Unencoded glyphs themselves. */ - - unsigned long props_size; /* Font properties allocated. */ - unsigned long props_used; /* Font properties used. */ - bdf_property_t* props; /* Font properties themselves. */ - - char* comments; /* Font comments. */ - unsigned long comments_len; /* Length of comment string. */ - - void* internal; /* Internal data for the font. */ - - unsigned short bpp; /* Bits per pixel. */ - - FT_Memory memory; - - bdf_property_t* user_props; - unsigned long nuser_props; - FT_HashRec proptbl; - - } bdf_font_t; - - - /************************************************************************** - * - * Types for load/save callbacks. - * - */ - - - /* Error codes. */ -#define BDF_MISSING_START -1 -#define BDF_MISSING_FONTNAME -2 -#define BDF_MISSING_SIZE -3 -#define BDF_MISSING_CHARS -4 -#define BDF_MISSING_STARTCHAR -5 -#define BDF_MISSING_ENCODING -6 -#define BDF_MISSING_BBX -7 - -#define BDF_OUT_OF_MEMORY -20 - -#define BDF_INVALID_LINE -100 - - - /************************************************************************** - * - * BDF font API. - * - */ - - FT_LOCAL( FT_Error ) - bdf_load_font( FT_Stream stream, - FT_Memory memory, - bdf_options_t* opts, - bdf_font_t* *font ); - - FT_LOCAL( void ) - bdf_free_font( bdf_font_t* font ); - - FT_LOCAL( bdf_property_t * ) - bdf_get_property( char* name, - bdf_font_t* font ); - - FT_LOCAL( bdf_property_t * ) - bdf_get_font_property( bdf_font_t* font, - const char* name ); - - -FT_END_HEADER - - -#endif /* BDF_H_ */ - - -/* END */ diff --git a/ThirdParty/freetype/src/bdf/bdfdrivr.c b/ThirdParty/freetype/src/bdf/bdfdrivr.c deleted file mode 100644 index 4a11843..0000000 --- a/ThirdParty/freetype/src/bdf/bdfdrivr.c +++ /dev/null @@ -1,1017 +0,0 @@ -/* bdfdrivr.c - - FreeType font driver for bdf files - - Copyright (C) 2001-2008, 2011, 2013, 2014 by - Francesco Zappa Nardelli - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -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 FT_SERVICE_BDF_H -#include FT_SERVICE_FONT_FORMAT_H - -#include "bdf.h" -#include "bdfdrivr.h" - -#include "bdferror.h" - - - /************************************************************************** - * - * The macro FT_COMPONENT is used in trace mode. It is an implicit - * parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log - * messages during execution. - */ -#undef FT_COMPONENT -#define FT_COMPONENT bdfdriver - - - typedef struct BDF_CMapRec_ - { - FT_CMapRec cmap; - FT_ULong num_encodings; /* ftobjs.h: FT_CMap->clazz->size */ - BDF_encoding_el* encodings; - - } BDF_CMapRec, *BDF_CMap; - - - FT_CALLBACK_DEF( FT_Error ) - bdf_cmap_init( FT_CMap bdfcmap, - FT_Pointer init_data ) - { - BDF_CMap cmap = (BDF_CMap)bdfcmap; - BDF_Face face = (BDF_Face)FT_CMAP_FACE( cmap ); - FT_UNUSED( init_data ); - - - cmap->num_encodings = face->bdffont->glyphs_used; - cmap->encodings = face->en_table; - - return FT_Err_Ok; - } - - - FT_CALLBACK_DEF( void ) - bdf_cmap_done( FT_CMap bdfcmap ) - { - BDF_CMap cmap = (BDF_CMap)bdfcmap; - - - cmap->encodings = NULL; - cmap->num_encodings = 0; - } - - - FT_CALLBACK_DEF( FT_UInt ) - bdf_cmap_char_index( FT_CMap bdfcmap, - FT_UInt32 charcode ) - { - 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 */ - - - min = 0; - max = cmap->num_encodings; - mid = ( min + max ) >> 1; - - while ( min < max ) - { - FT_ULong code; - - - if ( mid > max || mid < min ) - mid = ( min + max ) >> 1; - - code = encodings[mid].enc; - - if ( charcode == code ) - { - /* increase glyph index by 1 -- */ - /* we reserve slot 0 for the undefined glyph */ - result = encodings[mid].glyph + 1; - break; - } - - if ( charcode < code ) - max = mid; - else - min = mid + 1; - - /* prediction in a continuous block */ - mid += charcode - code; - } - - return result; - } - - - FT_CALLBACK_DEF( FT_UInt ) - bdf_cmap_char_next( FT_CMap bdfcmap, - FT_UInt32 *acharcode ) - { - 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; - - - 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; - - code = encodings[mid].enc; - - if ( charcode == code ) - { - /* increase glyph index by 1 -- */ - /* we reserve slot 0 for the undefined glyph */ - result = encodings[mid].glyph + 1; - goto Exit; - } - - if ( charcode < code ) - max = mid; - else - min = mid + 1; - - /* prediction in a continuous block */ - mid += charcode - code; - } - - charcode = 0; - if ( min < cmap->num_encodings ) - { - charcode = encodings[min].enc; - result = encodings[min].glyph + 1; - } - - Exit: - if ( charcode > 0xFFFFFFFFUL ) - { - FT_TRACE1(( "bdf_cmap_char_next: charcode 0x%x > 32bit API" )); - *acharcode = 0; - /* XXX: result should be changed to indicate an overflow error */ - } - else - *acharcode = (FT_UInt32)charcode; - return result; - } - - - static - const FT_CMap_ClassRec bdf_cmap_class = - { - sizeof ( BDF_CMapRec ), - bdf_cmap_init, - bdf_cmap_done, - bdf_cmap_char_index, - bdf_cmap_char_next, - - NULL, NULL, NULL, NULL, NULL - }; - - - static FT_Error - bdf_interpret_style( BDF_Face bdf ) - { - FT_Error error = FT_Err_Ok; - FT_Face face = FT_FACE( bdf ); - FT_Memory memory = face->memory; - bdf_font_t* font = bdf->bdffont; - bdf_property_t* prop; - - char* strings[4] = { NULL, NULL, NULL, NULL }; - size_t nn, len, lengths[4]; - - - face->style_flags = 0; - - prop = bdf_get_font_property( font, (char *)"SLANT" ); - if ( prop && prop->format == BDF_ATOM && - prop->value.atom && - ( *(prop->value.atom) == 'O' || *(prop->value.atom) == 'o' || - *(prop->value.atom) == 'I' || *(prop->value.atom) == 'i' ) ) - { - face->style_flags |= FT_STYLE_FLAG_ITALIC; - strings[2] = ( *(prop->value.atom) == 'O' || *(prop->value.atom) == 'o' ) - ? (char *)"Oblique" - : (char *)"Italic"; - } - - prop = bdf_get_font_property( font, (char *)"WEIGHT_NAME" ); - if ( prop && prop->format == BDF_ATOM && - prop->value.atom && - ( *(prop->value.atom) == 'B' || *(prop->value.atom) == 'b' ) ) - { - face->style_flags |= FT_STYLE_FLAG_BOLD; - strings[1] = (char *)"Bold"; - } - - prop = bdf_get_font_property( font, (char *)"SETWIDTH_NAME" ); - if ( prop && prop->format == BDF_ATOM && - prop->value.atom && *(prop->value.atom) && - !( *(prop->value.atom) == 'N' || *(prop->value.atom) == 'n' ) ) - strings[3] = (char *)(prop->value.atom); - - prop = bdf_get_font_property( font, (char *)"ADD_STYLE_NAME" ); - if ( prop && prop->format == BDF_ATOM && - prop->value.atom && *(prop->value.atom) && - !( *(prop->value.atom) == 'N' || *(prop->value.atom) == 'n' ) ) - strings[0] = (char *)(prop->value.atom); - - for ( len = 0, nn = 0; nn < 4; nn++ ) - { - lengths[nn] = 0; - if ( strings[nn] ) - { - lengths[nn] = ft_strlen( strings[nn] ); - len += lengths[nn] + 1; - } - } - - if ( len == 0 ) - { - strings[0] = (char *)"Regular"; - lengths[0] = ft_strlen( strings[0] ); - len = lengths[0] + 1; - } - - { - char* s; - - - if ( FT_ALLOC( face->style_name, len ) ) - return error; - - s = face->style_name; - - for ( nn = 0; nn < 4; nn++ ) - { - char* src = strings[nn]; - - - len = lengths[nn]; - - if ( !src ) - continue; - - /* separate elements with a space */ - if ( s != face->style_name ) - *s++ = ' '; - - ft_memcpy( s, src, len ); - - /* need to convert spaces to dashes for */ - /* add_style_name and setwidth_name */ - if ( nn == 0 || nn == 3 ) - { - size_t mm; - - - for ( mm = 0; mm < len; mm++ ) - if ( s[mm] == ' ' ) - s[mm] = '-'; - } - - s += len; - } - *s = 0; - } - - return error; - } - - - FT_CALLBACK_DEF( void ) - BDF_Face_Done( FT_Face bdfface ) /* BDF_Face */ - { - BDF_Face face = (BDF_Face)bdfface; - FT_Memory memory; - - - if ( !face ) - return; - - memory = FT_FACE_MEMORY( face ); - - bdf_free_font( face->bdffont ); - - FT_FREE( face->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->available_sizes ); - - FT_FREE( face->bdffont ); - } - - - FT_CALLBACK_DEF( FT_Error ) - BDF_Face_Init( FT_Stream stream, - FT_Face bdfface, /* 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 ); - - bdf_font_t* font = NULL; - bdf_options_t options; - - FT_UNUSED( num_params ); - FT_UNUSED( params ); - - - FT_TRACE2(( "BDF driver\n" )); - - if ( FT_STREAM_SEEK( 0 ) ) - goto Exit; - - options.correct_metrics = 1; /* FZ XXX: options semantics */ - options.keep_unencoded = 1; - options.keep_comments = 0; - options.font_spacing = BDF_PROPORTIONAL; - - error = bdf_load_font( stream, memory, &options, &font ); - if ( FT_ERR_EQ( error, Missing_Startfont_Field ) ) - { - FT_TRACE2(( " not a BDF file\n" )); - goto Fail; - } - else if ( error ) - goto Exit; - - /* we have a bdf font: let's construct the face object */ - face->bdffont = font; - - /* BDF cannot have multiple faces in a single font file. - * XXX: non-zero face_index is already invalid argument, but - * Type1, Type42 driver has a convention to return - * an invalid argument error when the font could be - * opened by the specified driver. - */ - if ( face_index > 0 && ( face_index & 0xFFFF ) > 0 ) - { - FT_ERROR(( "BDF_Face_Init: invalid face index\n" )); - BDF_Face_Done( bdfface ); - return FT_THROW( Invalid_Argument ); - } - - { - bdf_property_t* prop = NULL; - - - FT_TRACE4(( " number of glyphs: allocated %d (used %d)\n", - font->glyphs_size, - font->glyphs_used )); - FT_TRACE4(( " number of unencoded glyphs: allocated %d (used %d)\n", - font->unencoded_size, - font->unencoded_used )); - - bdfface->num_faces = 1; - bdfface->face_index = 0; - - bdfface->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; - - /* FZ XXX: TO DO: FT_FACE_FLAGS_VERTICAL */ - /* FZ XXX: I need a font to implement this */ - - prop = bdf_get_font_property( font, "FAMILY_NAME" ); - if ( prop && prop->value.atom ) - { - if ( FT_STRDUP( bdfface->family_name, prop->value.atom ) ) - goto Exit; - } - else - bdfface->family_name = NULL; - - if ( FT_SET_ERROR( bdf_interpret_style( face ) ) ) - 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 ); - - bdfface->num_fixed_sizes = 1; - if ( FT_NEW_ARRAY( bdfface->available_sizes, 1 ) ) - goto Exit; - - { - FT_Bitmap_Size* bsize = bdfface->available_sizes; - FT_Short resolution_x = 0, 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", - 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", - font->font_descent )); - } - - bsize->height = (FT_Short)( font->font_ascent + font->font_descent ); - - prop = bdf_get_font_property( font, "AVERAGE_WIDTH" ); - if ( prop ) - { -#ifdef FT_DEBUG_LEVEL_TRACE - if ( prop->value.l < 0 ) - FT_TRACE0(( "BDF_Face_Init: negative average width\n" )); -#endif - if ( prop->value.l > 0x7FFFL * 10 - 5 || - prop->value.l < -( 0x7FFFL * 10 - 5 ) ) - { - bsize->width = 0x7FFF; - FT_TRACE0(( "BDF_Face_Init: clamping average width to value %d\n", - bsize->width )); - } - else - bsize->width = FT_ABS( (FT_Short)( ( prop->value.l + 5 ) / 10 ) ); - } - else - { - /* this is a heuristical value */ - bsize->width = (FT_Short)FT_MulDiv( bsize->height, 2, 3 ); - } - - prop = bdf_get_font_property( font, "POINT_SIZE" ); - if ( prop ) - { -#ifdef FT_DEBUG_LEVEL_TRACE - if ( prop->value.l < 0 ) - FT_TRACE0(( "BDF_Face_Init: negative point size\n" )); -#endif - /* convert from 722.7 decipoints to 72 points per inch */ - if ( prop->value.l > 0x504C2L || /* 0x7FFF * 72270/7200 */ - prop->value.l < -0x504C2L ) - { - bsize->size = 0x7FFF; - FT_TRACE0(( "BDF_Face_Init: clamping point size to value %d\n", - bsize->size )); - } - else - bsize->size = FT_MulDiv( FT_ABS( prop->value.l ), - 64 * 7200, - 72270L ); - } - else if ( font->point_size ) - { - if ( font->point_size > 0x7FFF ) - { - bsize->size = 0x7FFF; - FT_TRACE0(( "BDF_Face_Init: clamping point size to value %d\n", - bsize->size )); - } - else - bsize->size = (FT_Pos)font->point_size << 6; - } - else - { - /* this is a heuristical value */ - bsize->size = bsize->width * 64; - } - - prop = bdf_get_font_property( font, "PIXEL_SIZE" ); - if ( prop ) - { -#ifdef FT_DEBUG_LEVEL_TRACE - if ( prop->value.l < 0 ) - FT_TRACE0(( "BDF_Face_Init: negative pixel size\n" )); -#endif - 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", - bsize->y_ppem )); - } - else - bsize->y_ppem = FT_ABS( (FT_Short)prop->value.l ) << 6; - } - - prop = bdf_get_font_property( font, "RESOLUTION_X" ); - if ( prop ) - value = prop->value.l; - else - value = (long)font->resolution_x; - if ( value ) - { -#ifdef FT_DEBUG_LEVEL_TRACE - if ( value < 0 ) - FT_TRACE0(( "BDF_Face_Init: negative X resolution\n" )); -#endif - if ( value > 0x7FFF || value < -0x7FFF ) - { - resolution_x = 0x7FFF; - FT_TRACE0(( "BDF_Face_Init: clamping X resolution to value %d\n", - resolution_x )); - } - else - resolution_x = FT_ABS( (FT_Short)value ); - } - - prop = bdf_get_font_property( font, "RESOLUTION_Y" ); - if ( prop ) - value = prop->value.l; - else - value = (long)font->resolution_y; - if ( value ) - { -#ifdef FT_DEBUG_LEVEL_TRACE - if ( value < 0 ) - FT_TRACE0(( "BDF_Face_Init: negative Y resolution\n" )); -#endif - if ( value > 0x7FFF || value < -0x7FFF ) - { - resolution_y = 0x7FFF; - FT_TRACE0(( "BDF_Face_Init: clamping Y resolution to value %d\n", - resolution_y )); - } - else - resolution_y = FT_ABS( (FT_Short)value ); - } - - if ( bsize->y_ppem == 0 ) - { - bsize->y_ppem = bsize->size; - if ( resolution_y ) - bsize->y_ppem = FT_MulDiv( bsize->y_ppem, resolution_y, 72 ); - } - if ( resolution_x && resolution_y ) - bsize->x_ppem = FT_MulDiv( bsize->y_ppem, - resolution_x, - resolution_y ); - else - bsize->x_ppem = bsize->y_ppem; - } - - /* encoding table */ - { - bdf_glyph_t* cur = font->glyphs; - unsigned long n; - - - if ( FT_NEW_ARRAY( face->en_table, font->glyphs_size ) ) - goto Exit; - - face->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; - - if ( cur[n].encoding == font->default_char ) - { - if ( n < FT_UINT_MAX ) - face->default_glyph = (FT_UInt)n; - else - FT_TRACE1(( "BDF_Face_Init:" - " idx %d is too large for this system\n", n )); - } - } - } - - /* charmaps */ - { - bdf_property_t *charset_registry, *charset_encoding; - FT_Bool unicode_charmap = 0; - - - charset_registry = - bdf_get_font_property( font, "CHARSET_REGISTRY" ); - charset_encoding = - bdf_get_font_property( font, "CHARSET_ENCODING" ); - if ( charset_registry && charset_encoding ) - { - if ( charset_registry->format == BDF_ATOM && - charset_encoding->format == BDF_ATOM && - charset_registry->value.atom && - charset_encoding->value.atom ) - { - const char* s; - - - if ( FT_STRDUP( face->charset_encoding, - charset_encoding->value.atom ) || - FT_STRDUP( face->charset_registry, - charset_registry->value.atom ) ) - goto Exit; - - /* Uh, oh, compare first letters manually to avoid dependency */ - /* on locales. */ - s = face->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" ) ) ) - unicode_charmap = 1; - /* another name for ASCII */ - else if ( !ft_strcmp( s, "646.1991" ) && - !ft_strcmp( face->charset_encoding, "IRV" ) ) - unicode_charmap = 1; - } - - { - FT_CharMapRec charmap; - - - charmap.face = FT_FACE( face ); - charmap.encoding = FT_ENCODING_NONE; - /* initial platform/encoding should indicate unset status? */ - charmap.platform_id = TT_PLATFORM_APPLE_UNICODE; - charmap.encoding_id = TT_APPLE_ID_DEFAULT; - - if ( unicode_charmap ) - { - charmap.encoding = FT_ENCODING_UNICODE; - charmap.platform_id = TT_PLATFORM_MICROSOFT; - charmap.encoding_id = TT_MS_ID_UNICODE_CS; - } - - error = FT_CMap_New( &bdf_cmap_class, NULL, &charmap, NULL ); - } - - goto Exit; - } - } - - /* otherwise assume Adobe standard encoding */ - - { - FT_CharMapRec charmap; - - - charmap.face = FT_FACE( face ); - charmap.encoding = FT_ENCODING_ADOBE_STANDARD; - charmap.platform_id = TT_PLATFORM_ADOBE; - charmap.encoding_id = TT_ADOBE_ID_STANDARD; - - error = FT_CMap_New( &bdf_cmap_class, NULL, &charmap, NULL ); - - /* Select default charmap */ - if ( bdfface->num_charmaps ) - bdfface->charmap = bdfface->charmaps[0]; - } - } - } - - Exit: - return error; - - Fail: - BDF_Face_Done( bdfface ); - return FT_THROW( Unknown_File_Format ); - } - - - FT_CALLBACK_DEF( FT_Error ) - BDF_Size_Select( FT_Size size, - FT_ULong strike_index ) - { - bdf_font_t* bdffont = ( (BDF_Face)size->face )->bdffont; - - - FT_Select_Metrics( size->face, strike_index ); - - size->metrics.ascender = bdffont->font_ascent * 64; - size->metrics.descender = -bdffont->font_descent * 64; - size->metrics.max_advance = bdffont->bbx.width * 64; - - return FT_Err_Ok; - } - - - FT_CALLBACK_DEF( FT_Error ) - BDF_Size_Request( FT_Size size, - FT_Size_Request req ) - { - FT_Face face = size->face; - FT_Bitmap_Size* bsize = face->available_sizes; - bdf_font_t* bdffont = ( (BDF_Face)face )->bdffont; - FT_Error error = FT_ERR( Invalid_Pixel_Size ); - FT_Long height; - - - height = FT_REQUEST_HEIGHT( req ); - height = ( height + 32 ) >> 6; - - switch ( req->type ) - { - case FT_SIZE_REQUEST_TYPE_NOMINAL: - if ( height == ( ( bsize->y_ppem + 32 ) >> 6 ) ) - error = FT_Err_Ok; - break; - - case FT_SIZE_REQUEST_TYPE_REAL_DIM: - if ( height == ( bdffont->font_ascent + - bdffont->font_descent ) ) - error = FT_Err_Ok; - break; - - default: - error = FT_THROW( Unimplemented_Feature ); - break; - } - - if ( error ) - return error; - else - return BDF_Size_Select( size, 0 ); - } - - - - FT_CALLBACK_DEF( FT_Error ) - BDF_Glyph_Load( FT_GlyphSlot slot, - FT_Size size, - FT_UInt glyph_index, - FT_Int32 load_flags ) - { - BDF_Face bdf = (BDF_Face)FT_SIZE_FACE( size ); - FT_Face face = FT_FACE( bdf ); - FT_Error error = FT_Err_Ok; - FT_Bitmap* bitmap = &slot->bitmap; - bdf_glyph_t glyph; - int bpp = bdf->bdffont->bpp; - - FT_UNUSED( load_flags ); - - - if ( !face ) - { - error = FT_THROW( Invalid_Face_Handle ); - goto Exit; - } - - if ( glyph_index >= (FT_UInt)face->num_glyphs ) - { - error = FT_THROW( Invalid_Argument ); - goto Exit; - } - - FT_TRACE1(( "BDF_Glyph_Load: glyph index %d\n", glyph_index )); - - /* index 0 is the undefined glyph */ - if ( glyph_index == 0 ) - glyph_index = bdf->default_glyph; - else - glyph_index--; - - /* slot, bitmap => freetype, glyph => bdflib */ - glyph = bdf->bdffont->glyphs[glyph_index]; - - 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", - glyph.bpr )); - bitmap->pitch = (int)glyph.bpr; /* same as FT_Bitmap.pitch */ - - /* note: we don't allocate a new array to hold the bitmap; */ - /* we can simply point to it */ - ft_glyphslot_set_bitmap( slot, glyph.bitmap ); - - switch ( bpp ) - { - case 1: - bitmap->pixel_mode = FT_PIXEL_MODE_MONO; - break; - case 2: - bitmap->pixel_mode = FT_PIXEL_MODE_GRAY2; - break; - case 4: - bitmap->pixel_mode = FT_PIXEL_MODE_GRAY4; - break; - case 8: - bitmap->pixel_mode = FT_PIXEL_MODE_GRAY; - bitmap->num_grays = 256; - break; - } - - slot->format = FT_GLYPH_FORMAT_BITMAP; - slot->bitmap_left = glyph.bbx.x_offset; - slot->bitmap_top = glyph.bbx.ascent; - - slot->metrics.horiAdvance = (FT_Pos)( glyph.dwidth * 64 ); - slot->metrics.horiBearingX = (FT_Pos)( glyph.bbx.x_offset * 64 ); - slot->metrics.horiBearingY = (FT_Pos)( glyph.bbx.ascent * 64 ); - slot->metrics.width = (FT_Pos)( bitmap->width * 64 ); - slot->metrics.height = (FT_Pos)( bitmap->rows * 64 ); - - /* - * XXX DWIDTH1 and VVECTOR should be parsed and - * used here, provided such fonts do exist. - */ - ft_synthesize_vertical_metrics( &slot->metrics, - bdf->bdffont->bbx.height * 64 ); - - Exit: - return error; - } - - - /* - * - * BDF SERVICE - * - */ - - static FT_Error - bdf_get_bdf_property( BDF_Face face, - const char* prop_name, - BDF_PropertyRec *aproperty ) - { - bdf_property_t* prop; - - - FT_ASSERT( face && face->bdffont ); - - prop = bdf_get_font_property( face->bdffont, prop_name ); - if ( prop ) - { - switch ( prop->format ) - { - case BDF_ATOM: - aproperty->type = BDF_PROPERTY_TYPE_ATOM; - aproperty->u.atom = prop->value.atom; - break; - - case BDF_INTEGER: - if ( prop->value.l > 0x7FFFFFFFL || prop->value.l < ( -1 - 0x7FFFFFFFL ) ) - { - FT_TRACE1(( "bdf_get_bdf_property:" - " too large integer 0x%x is truncated\n" )); - } - aproperty->type = BDF_PROPERTY_TYPE_INTEGER; - aproperty->u.integer = (FT_Int32)prop->value.l; - break; - - case BDF_CARDINAL: - if ( prop->value.ul > 0xFFFFFFFFUL ) - { - FT_TRACE1(( "bdf_get_bdf_property:" - " too large cardinal 0x%x is truncated\n" )); - } - aproperty->type = BDF_PROPERTY_TYPE_CARDINAL; - aproperty->u.cardinal = (FT_UInt32)prop->value.ul; - break; - - default: - goto Fail; - } - return 0; - } - - Fail: - return FT_THROW( Invalid_Argument ); - } - - - static FT_Error - bdf_get_charset_id( BDF_Face face, - const char* *acharset_encoding, - const char* *acharset_registry ) - { - *acharset_encoding = face->charset_encoding; - *acharset_registry = face->charset_registry; - - return 0; - } - - - static const FT_Service_BDFRec bdf_service_bdf = - { - (FT_BDF_GetCharsetIdFunc)bdf_get_charset_id, /* get_charset_id */ - (FT_BDF_GetPropertyFunc) bdf_get_bdf_property /* get_property */ - }; - - - /* - * - * SERVICES LIST - * - */ - - static const FT_ServiceDescRec bdf_services[] = - { - { FT_SERVICE_ID_BDF, &bdf_service_bdf }, - { FT_SERVICE_ID_FONT_FORMAT, FT_FONT_FORMAT_BDF }, - { NULL, NULL } - }; - - - FT_CALLBACK_DEF( FT_Module_Interface ) - bdf_driver_requester( FT_Module module, - const char* name ) - { - FT_UNUSED( module ); - - return ft_service_list_lookup( bdf_services, name ); - } - - - - FT_CALLBACK_TABLE_DEF - const FT_Driver_ClassRec bdf_driver_class = - { - { - FT_MODULE_FONT_DRIVER | - FT_MODULE_DRIVER_NO_OUTLINES, - sizeof ( FT_DriverRec ), - - "bdf", - 0x10000L, - 0x20000L, - - NULL, /* module-specific interface */ - - NULL, /* FT_Module_Constructor module_init */ - NULL, /* FT_Module_Destructor module_done */ - bdf_driver_requester /* FT_Module_Requester get_interface */ - }, - - sizeof ( BDF_FaceRec ), - sizeof ( FT_SizeRec ), - sizeof ( FT_GlyphSlotRec ), - - BDF_Face_Init, /* FT_Face_InitFunc init_face */ - BDF_Face_Done, /* FT_Face_DoneFunc done_face */ - NULL, /* FT_Size_InitFunc init_size */ - NULL, /* FT_Size_DoneFunc done_size */ - NULL, /* FT_Slot_InitFunc init_slot */ - NULL, /* FT_Slot_DoneFunc done_slot */ - - BDF_Glyph_Load, /* FT_Slot_LoadFunc load_glyph */ - - NULL, /* FT_Face_GetKerningFunc get_kerning */ - NULL, /* FT_Face_AttachFunc attach_file */ - NULL, /* FT_Face_GetAdvancesFunc get_advances */ - - BDF_Size_Request, /* FT_Size_RequestFunc request_size */ - BDF_Size_Select /* FT_Size_SelectFunc select_size */ - }; - - -/* END */ diff --git a/ThirdParty/freetype/src/bdf/bdfdrivr.h b/ThirdParty/freetype/src/bdf/bdfdrivr.h deleted file mode 100644 index b37b84e..0000000 --- a/ThirdParty/freetype/src/bdf/bdfdrivr.h +++ /dev/null @@ -1,73 +0,0 @@ -/* bdfdrivr.h - - FreeType font driver for bdf fonts - - Copyright (C) 2001, 2002, 2003, 2004 by - Francesco Zappa Nardelli - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -*/ - - -#ifndef BDFDRIVR_H_ -#define BDFDRIVR_H_ - -#include <ft2build.h> -#include FT_INTERNAL_DRIVER_H - -#include "bdf.h" - - -FT_BEGIN_HEADER - - - typedef struct BDF_encoding_el_ - { - FT_ULong enc; - FT_UShort glyph; - - } BDF_encoding_el; - - - typedef struct BDF_FaceRec_ - { - FT_FaceRec root; - - char* charset_encoding; - char* charset_registry; - - bdf_font_t* bdffont; - - BDF_encoding_el* en_table; - - FT_UInt default_glyph; - - } BDF_FaceRec, *BDF_Face; - - - FT_EXPORT_VAR( const FT_Driver_ClassRec ) bdf_driver_class; - - -FT_END_HEADER - - -#endif /* BDFDRIVR_H_ */ - - -/* END */ diff --git a/ThirdParty/freetype/src/bdf/bdferror.h b/ThirdParty/freetype/src/bdf/bdferror.h deleted file mode 100644 index dbe41c0..0000000 --- a/ThirdParty/freetype/src/bdf/bdferror.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2001, 2002, 2012 Francesco Zappa Nardelli - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE COMPUTING RESEARCH LAB OR NEW MEXICO STATE UNIVERSITY BE LIABLE FOR ANY - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT - * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR - * THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - - /************************************************************************** - * - * This file is used to define the BDF error enumeration constants. - * - */ - -#ifndef BDFERROR_H_ -#define BDFERROR_H_ - -#include FT_MODULE_ERRORS_H - -#undef FTERRORS_H_ - -#undef FT_ERR_PREFIX -#define FT_ERR_PREFIX BDF_Err_ -#define FT_ERR_BASE FT_Mod_Err_BDF - -#include FT_ERRORS_H - -#endif /* BDFERROR_H_ */ - - -/* END */ diff --git a/ThirdParty/freetype/src/bdf/bdflib.c b/ThirdParty/freetype/src/bdf/bdflib.c deleted file mode 100644 index 0898b0d..0000000 --- a/ThirdParty/freetype/src/bdf/bdflib.c +++ /dev/null @@ -1,2416 +0,0 @@ -/* - * Copyright 2000 Computing Research Labs, New Mexico State University - * Copyright 2001-2014 - * Francesco Zappa Nardelli - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE COMPUTING RESEARCH LAB OR NEW MEXICO STATE UNIVERSITY BE LIABLE FOR ANY - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT - * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR - * THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - - /************************************************************************** - * - * This file is based on bdf.c,v 1.22 2000/03/16 20:08:50 - * - * taken from Mark Leisher's xmbdfed package - * - */ - - -#include <ft2build.h> - -#include FT_FREETYPE_H -#include FT_INTERNAL_DEBUG_H -#include FT_INTERNAL_STREAM_H -#include FT_INTERNAL_OBJECTS_H - -#include "bdf.h" -#include "bdferror.h" - - - /************************************************************************** - * - * The macro FT_COMPONENT is used in trace mode. It is an implicit - * parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log - * messages during execution. - */ -#undef FT_COMPONENT -#define FT_COMPONENT bdflib - - - /************************************************************************** - * - * Default BDF font options. - * - */ - - - static const bdf_options_t _bdf_opts = - { - 1, /* Correct metrics. */ - 1, /* Preserve unencoded glyphs. */ - 0, /* Preserve comments. */ - BDF_PROPORTIONAL /* Default spacing. */ - }; - - - /************************************************************************** - * - * Builtin BDF font properties. - * - */ - - /* List of most properties that might appear in a font. Doesn't include */ - /* the RAW_* and AXIS_* properties in X11R6 polymorphic fonts. */ - - static const bdf_property_t _bdf_properties[] = - { - { (char *)"ADD_STYLE_NAME", BDF_ATOM, 1, { 0 } }, - { (char *)"AVERAGE_WIDTH", BDF_INTEGER, 1, { 0 } }, - { (char *)"AVG_CAPITAL_WIDTH", BDF_INTEGER, 1, { 0 } }, - { (char *)"AVG_LOWERCASE_WIDTH", BDF_INTEGER, 1, { 0 } }, - { (char *)"CAP_HEIGHT", BDF_INTEGER, 1, { 0 } }, - { (char *)"CHARSET_COLLECTIONS", BDF_ATOM, 1, { 0 } }, - { (char *)"CHARSET_ENCODING", BDF_ATOM, 1, { 0 } }, - { (char *)"CHARSET_REGISTRY", BDF_ATOM, 1, { 0 } }, - { (char *)"COMMENT", BDF_ATOM, 1, { 0 } }, - { (char *)"COPYRIGHT", BDF_ATOM, 1, { 0 } }, - { (char *)"DEFAULT_CHAR", BDF_CARDINAL, 1, { 0 } }, - { (char *)"DESTINATION", BDF_CARDINAL, 1, { 0 } }, - { (char *)"DEVICE_FONT_NAME", BDF_ATOM, 1, { 0 } }, - { (char *)"END_SPACE", BDF_INTEGER, 1, { 0 } }, - { (char *)"FACE_NAME", BDF_ATOM, 1, { 0 } }, - { (char *)"FAMILY_NAME", BDF_ATOM, 1, { 0 } }, - { (char *)"FIGURE_WIDTH", BDF_INTEGER, 1, { 0 } }, - { (char *)"FONT", BDF_ATOM, 1, { 0 } }, - { (char *)"FONTNAME_REGISTRY", BDF_ATOM, 1, { 0 } }, - { (char *)"FONT_ASCENT", BDF_INTEGER, 1, { 0 } }, - { (char *)"FONT_DESCENT", BDF_INTEGER, 1, { 0 } }, - { (char *)"FOUNDRY", BDF_ATOM, 1, { 0 } }, - { (char *)"FULL_NAME", BDF_ATOM, 1, { 0 } }, - { (char *)"ITALIC_ANGLE", BDF_INTEGER, 1, { 0 } }, - { (char *)"MAX_SPACE", BDF_INTEGER, 1, { 0 } }, - { (char *)"MIN_SPACE", BDF_INTEGER, 1, { 0 } }, - { (char *)"NORM_SPACE", BDF_INTEGER, 1, { 0 } }, - { (char *)"NOTICE", BDF_ATOM, 1, { 0 } }, - { (char *)"PIXEL_SIZE", BDF_INTEGER, 1, { 0 } }, - { (char *)"POINT_SIZE", BDF_INTEGER, 1, { 0 } }, - { (char *)"QUAD_WIDTH", BDF_INTEGER, 1, { 0 } }, - { (char *)"RAW_ASCENT", BDF_INTEGER, 1, { 0 } }, - { (char *)"RAW_AVERAGE_WIDTH", BDF_INTEGER, 1, { 0 } }, - { (char *)"RAW_AVG_CAPITAL_WIDTH", BDF_INTEGER, 1, { 0 } }, - { (char *)"RAW_AVG_LOWERCASE_WIDTH", BDF_INTEGER, 1, { 0 } }, - { (char *)"RAW_CAP_HEIGHT", BDF_INTEGER, 1, { 0 } }, - { (char *)"RAW_DESCENT", BDF_INTEGER, 1, { 0 } }, - { (char *)"RAW_END_SPACE", BDF_INTEGER, 1, { 0 } }, - { (char *)"RAW_FIGURE_WIDTH", BDF_INTEGER, 1, { 0 } }, - { (char *)"RAW_MAX_SPACE", BDF_INTEGER, 1, { 0 } }, - { (char *)"RAW_MIN_SPACE", BDF_INTEGER, 1, { 0 } }, - { (char *)"RAW_NORM_SPACE", BDF_INTEGER, 1, { 0 } }, - { (char *)"RAW_PIXEL_SIZE", BDF_INTEGER, 1, { 0 } }, - { (char *)"RAW_POINT_SIZE", BDF_INTEGER, 1, { 0 } }, - { (char *)"RAW_PIXELSIZE", BDF_INTEGER, 1, { 0 } }, - { (char *)"RAW_POINTSIZE", BDF_INTEGER, 1, { 0 } }, - { (char *)"RAW_QUAD_WIDTH", BDF_INTEGER, 1, { 0 } }, - { (char *)"RAW_SMALL_CAP_SIZE", BDF_INTEGER, 1, { 0 } }, - { (char *)"RAW_STRIKEOUT_ASCENT", BDF_INTEGER, 1, { 0 } }, - { (char *)"RAW_STRIKEOUT_DESCENT", BDF_INTEGER, 1, { 0 } }, - { (char *)"RAW_SUBSCRIPT_SIZE", BDF_INTEGER, 1, { 0 } }, - { (char *)"RAW_SUBSCRIPT_X", BDF_INTEGER, 1, { 0 } }, - { (char *)"RAW_SUBSCRIPT_Y", BDF_INTEGER, 1, { 0 } }, - { (char *)"RAW_SUPERSCRIPT_SIZE", BDF_INTEGER, 1, { 0 } }, - { (char *)"RAW_SUPERSCRIPT_X", BDF_INTEGER, 1, { 0 } }, - { (char *)"RAW_SUPERSCRIPT_Y", BDF_INTEGER, 1, { 0 } }, - { (char *)"RAW_UNDERLINE_POSITION", BDF_INTEGER, 1, { 0 } }, - { (char *)"RAW_UNDERLINE_THICKNESS", BDF_INTEGER, 1, { 0 } }, - { (char *)"RAW_X_HEIGHT", BDF_INTEGER, 1, { 0 } }, - { (char *)"RELATIVE_SETWIDTH", BDF_CARDINAL, 1, { 0 } }, - { (char *)"RELATIVE_WEIGHT", BDF_CARDINAL, 1, { 0 } }, - { (char *)"RESOLUTION", BDF_INTEGER, 1, { 0 } }, - { (char *)"RESOLUTION_X", BDF_CARDINAL, 1, { 0 } }, - { (char *)"RESOLUTION_Y", BDF_CARDINAL, 1, { 0 } }, - { (char *)"SETWIDTH_NAME", BDF_ATOM, 1, { 0 } }, - { (char *)"SLANT", BDF_ATOM, 1, { 0 } }, - { (char *)"SMALL_CAP_SIZE", BDF_INTEGER, 1, { 0 } }, - { (char *)"SPACING", BDF_ATOM, 1, { 0 } }, - { (char *)"STRIKEOUT_ASCENT", BDF_INTEGER, 1, { 0 } }, - { (char *)"STRIKEOUT_DESCENT", BDF_INTEGER, 1, { 0 } }, - { (char *)"SUBSCRIPT_SIZE", BDF_INTEGER, 1, { 0 } }, - { (char *)"SUBSCRIPT_X", BDF_INTEGER, 1, { 0 } }, - { (char *)"SUBSCRIPT_Y", BDF_INTEGER, 1, { 0 } }, - { (char *)"SUPERSCRIPT_SIZE", BDF_INTEGER, 1, { 0 } }, - { (char *)"SUPERSCRIPT_X", BDF_INTEGER, 1, { 0 } }, - { (char *)"SUPERSCRIPT_Y", BDF_INTEGER, 1, { 0 } }, - { (char *)"UNDERLINE_POSITION", BDF_INTEGER, 1, { 0 } }, - { (char *)"UNDERLINE_THICKNESS", BDF_INTEGER, 1, { 0 } }, - { (char *)"WEIGHT", BDF_CARDINAL, 1, { 0 } }, - { (char *)"WEIGHT_NAME", BDF_ATOM, 1, { 0 } }, - { (char *)"X_HEIGHT", BDF_INTEGER, 1, { 0 } }, - { (char *)"_MULE_BASELINE_OFFSET", BDF_INTEGER, 1, { 0 } }, - { (char *)"_MULE_RELATIVE_COMPOSE", BDF_INTEGER, 1, { 0 } }, - }; - - static const unsigned long - _num_bdf_properties = sizeof ( _bdf_properties ) / - sizeof ( _bdf_properties[0] ); - - - /* An auxiliary macro to parse properties, to be used in conditionals. */ - /* It behaves like `strncmp' but also tests the following character */ - /* whether it is a whitespace or NULL. */ - /* `property' is a constant string of length `n' to compare with. */ -#define _bdf_strncmp( name, property, n ) \ - ( ft_strncmp( name, property, n ) || \ - !( name[n] == ' ' || \ - name[n] == '\0' || \ - name[n] == '\n' || \ - name[n] == '\r' || \ - name[n] == '\t' ) ) - - /* Auto correction messages. */ -#define ACMSG1 "FONT_ASCENT property missing. " \ - "Added `FONT_ASCENT %hd'.\n" -#define ACMSG2 "FONT_DESCENT property missing. " \ - "Added `FONT_DESCENT %hd'.\n" -#define ACMSG3 "Font width != actual width. Old: %hd New: %hd.\n" -#define ACMSG4 "Font left bearing != actual left bearing. " \ - "Old: %hd New: %hd.\n" -#define ACMSG5 "Font ascent != actual ascent. Old: %hd New: %hd.\n" -#define ACMSG6 "Font descent != actual descent. Old: %hd New: %hd.\n" -#define ACMSG7 "Font height != actual height. Old: %hd New: %hd.\n" -#define ACMSG8 "Glyph scalable width (SWIDTH) adjustments made.\n" -#define ACMSG9 "SWIDTH field missing at line %ld. Set automatically.\n" -#define ACMSG10 "DWIDTH field missing at line %ld. Set to glyph width.\n" -#define ACMSG11 "SIZE bits per pixel field adjusted to %hd.\n" -#define ACMSG13 "Glyph %lu extra rows removed.\n" -#define ACMSG14 "Glyph %lu extra columns removed.\n" -#define ACMSG15 "Incorrect glyph count: %ld indicated but %ld found.\n" -#define ACMSG16 "Glyph %lu missing columns padded with zero bits.\n" -#define ACMSG17 "Adjusting number of glyphs to %ld.\n" - - /* Error messages. */ -#define ERRMSG1 "[line %ld] Missing `%s' line.\n" -#define ERRMSG2 "[line %ld] Font header corrupted or missing fields.\n" -#define ERRMSG3 "[line %ld] Font glyphs corrupted or missing fields.\n" -#define ERRMSG4 "[line %ld] BBX too big.\n" -#define ERRMSG5 "[line %ld] `%s' value too big.\n" -#define ERRMSG6 "[line %ld] Input line too long.\n" -#define ERRMSG7 "[line %ld] Font name too long.\n" -#define ERRMSG8 "[line %ld] Invalid `%s' value.\n" -#define ERRMSG9 "[line %ld] Invalid keyword.\n" - - /* Debug messages. */ -#define DBGMSG1 " [%6ld] %s" /* no \n */ -#define DBGMSG2 " (0x%lX)\n" - - - /************************************************************************** - * - * Utility types and functions. - * - */ - - - /* Function type for parsing lines of a BDF font. */ - - typedef FT_Error - (*_bdf_line_func_t)( char* line, - unsigned long linelen, - unsigned long lineno, - void* call_data, - void* client_data ); - - - /* List structure for splitting lines into fields. */ - - typedef struct _bdf_list_t_ - { - char** field; - unsigned long size; - unsigned long used; - FT_Memory memory; - - } _bdf_list_t; - - - /* Structure used while loading BDF fonts. */ - - typedef struct _bdf_parse_t_ - { - unsigned long flags; - unsigned long cnt; - unsigned long row; - - short minlb; - short maxlb; - short maxrb; - short maxas; - short maxds; - - short rbearing; - - char* glyph_name; - long glyph_enc; - - bdf_font_t* font; - bdf_options_t* opts; - - _bdf_list_t list; - - FT_Memory memory; - unsigned long size; /* the stream size */ - - } _bdf_parse_t; - - -#define setsbit( m, cc ) \ - ( m[(FT_Byte)(cc) >> 3] |= (FT_Byte)( 1 << ( (cc) & 7 ) ) ) -#define sbitset( m, cc ) \ - ( m[(FT_Byte)(cc) >> 3] & ( 1 << ( (cc) & 7 ) ) ) - - - static void - _bdf_list_init( _bdf_list_t* list, - FT_Memory memory ) - { - FT_ZERO( list ); - list->memory = memory; - } - - - static void - _bdf_list_done( _bdf_list_t* list ) - { - FT_Memory memory = list->memory; - - - if ( memory ) - { - FT_FREE( list->field ); - FT_ZERO( list ); - } - } - - - static FT_Error - _bdf_list_ensure( _bdf_list_t* list, - unsigned long num_items ) /* same as _bdf_list_t.used */ - { - FT_Error error = FT_Err_Ok; - - - if ( num_items > list->size ) - { - unsigned long oldsize = list->size; /* same as _bdf_list_t.size */ - unsigned long newsize = oldsize + ( oldsize >> 1 ) + 5; - unsigned long bigsize = (unsigned long)( FT_INT_MAX / sizeof ( char* ) ); - FT_Memory memory = list->memory; - - - if ( oldsize == bigsize ) - { - error = FT_THROW( Out_Of_Memory ); - goto Exit; - } - else if ( newsize < oldsize || newsize > bigsize ) - newsize = bigsize; - - if ( FT_RENEW_ARRAY( list->field, oldsize, newsize ) ) - goto Exit; - - list->size = newsize; - } - - Exit: - return error; - } - - - static void - _bdf_list_shift( _bdf_list_t* list, - unsigned long n ) - { - unsigned long i, u; - - - if ( list == 0 || list->used == 0 || n == 0 ) - return; - - if ( n >= list->used ) - { - list->used = 0; - return; - } - - for ( u = n, i = 0; u < list->used; i++, u++ ) - list->field[i] = list->field[u]; - list->used -= n; - } - - - /* An empty string for empty fields. */ - - static const char empty[1] = { 0 }; /* XXX eliminate this */ - - - static char * - _bdf_list_join( _bdf_list_t* list, - int c, - unsigned long *alen ) - { - unsigned long i, j; - char* dp; - - - *alen = 0; - - if ( list == 0 || list->used == 0 ) - return 0; - - dp = list->field[0]; - for ( i = j = 0; i < list->used; i++ ) - { - char* fp = list->field[i]; - - - while ( *fp ) - dp[j++] = *fp++; - - if ( i + 1 < list->used ) - dp[j++] = (char)c; - } - if ( dp != empty ) - dp[j] = 0; - - *alen = j; - return dp; - } - - - /* The code below ensures that we have at least 4 + 1 `field' */ - /* elements in `list' (which are possibly NULL) so that we */ - /* don't have to check the number of fields in most cases. */ - - static FT_Error - _bdf_list_split( _bdf_list_t* list, - char* separators, - char* line, - unsigned long linelen ) - { - unsigned long final_empty; - int mult; - char *sp, *ep, *end; - char seps[32]; - FT_Error error = FT_Err_Ok; - - - /* Initialize the list. */ - list->used = 0; - if ( list->size ) - { - list->field[0] = (char*)empty; - list->field[1] = (char*)empty; - list->field[2] = (char*)empty; - list->field[3] = (char*)empty; - list->field[4] = (char*)empty; - } - - /* If the line is empty, then simply return. */ - if ( linelen == 0 || line[0] == 0 ) - goto Exit; - - /* In the original code, if the `separators' parameter is NULL or */ - /* empty, the list is split into individual bytes. We don't need */ - /* this, so an error is signaled. */ - if ( separators == 0 || *separators == 0 ) - { - error = FT_THROW( Invalid_Argument ); - goto Exit; - } - - /* Prepare the separator bitmap. */ - FT_MEM_ZERO( seps, 32 ); - - /* If the very last character of the separator string is a plus, then */ - /* set the `mult' flag to indicate that multiple separators should be */ - /* collapsed into one. */ - for ( mult = 0, sp = separators; sp && *sp; sp++ ) - { - if ( *sp == '+' && *( sp + 1 ) == 0 ) - mult = 1; - else - setsbit( seps, *sp ); - } - - /* Break the line up into fields. */ - for ( final_empty = 0, sp = ep = line, end = sp + linelen; - sp < end && *sp; ) - { - /* Collect everything that is not a separator. */ - for ( ; *ep && !sbitset( seps, *ep ); ep++ ) - ; - - /* Resize the list if necessary. */ - if ( list->used == list->size ) - { - error = _bdf_list_ensure( list, list->used + 1 ); - if ( error ) - goto Exit; - } - - /* Assign the field appropriately. */ - list->field[list->used++] = ( ep > sp ) ? sp : (char*)empty; - - sp = ep; - - if ( mult ) - { - /* If multiple separators should be collapsed, do it now by */ - /* setting all the separator characters to 0. */ - for ( ; *ep && sbitset( seps, *ep ); ep++ ) - *ep = 0; - } - else if ( *ep != 0 ) - /* Don't collapse multiple separators by making them 0, so just */ - /* make the one encountered 0. */ - *ep++ = 0; - - final_empty = ( ep > sp && *ep == 0 ); - sp = ep; - } - - /* Finally, NULL-terminate the list. */ - if ( list->used + final_empty >= list->size ) - { - error = _bdf_list_ensure( list, list->used + final_empty + 1 ); - if ( error ) - goto Exit; - } - - if ( final_empty ) - list->field[list->used++] = (char*)empty; - - list->field[list->used] = 0; - - Exit: - return error; - } - - -#define NO_SKIP 256 /* this value cannot be stored in a 'char' */ - - - static FT_Error - _bdf_readstream( FT_Stream stream, - _bdf_line_func_t callback, - void* client_data, - unsigned long *lno ) - { - _bdf_line_func_t cb; - unsigned long lineno, buf_size; - int refill, hold, to_skip; - ptrdiff_t bytes, start, end, cursor, avail; - char* buf = NULL; - FT_Memory memory = stream->memory; - FT_Error error = FT_Err_Ok; - - - if ( callback == 0 ) - { - error = FT_THROW( Invalid_Argument ); - goto Exit; - } - - /* initial size and allocation of the input buffer */ - buf_size = 1024; - - if ( FT_NEW_ARRAY( buf, buf_size ) ) - goto Exit; - - cb = callback; - lineno = 1; - buf[0] = 0; - start = 0; - avail = 0; - cursor = 0; - refill = 1; - to_skip = NO_SKIP; - bytes = 0; /* make compiler happy */ - - for (;;) - { - if ( refill ) - { - bytes = (ptrdiff_t)FT_Stream_TryRead( - stream, (FT_Byte*)buf + cursor, - buf_size - (unsigned long)cursor ); - avail = cursor + bytes; - cursor = 0; - refill = 0; - } - - end = start; - - /* should we skip an optional character like \n or \r? */ - if ( start < avail && buf[start] == to_skip ) - { - start += 1; - to_skip = NO_SKIP; - continue; - } - - /* try to find the end of the line */ - while ( end < avail && buf[end] != '\n' && buf[end] != '\r' ) - end++; - - /* if we hit the end of the buffer, try shifting its content */ - /* or even resizing it */ - if ( end >= avail ) - { - if ( bytes == 0 ) /* last line in file doesn't end in \r or \n */ - break; /* ignore it then exit */ - - if ( start == 0 ) - { - /* this line is definitely too long; try resizing the input */ - /* buffer a bit to handle it. */ - FT_ULong new_size; - - - if ( buf_size >= 65536UL ) /* limit ourselves to 64KByte */ - { - FT_ERROR(( "_bdf_readstream: " ERRMSG6, lineno )); - error = FT_THROW( Invalid_Argument ); - goto Exit; - } - - new_size = buf_size * 2; - if ( FT_RENEW_ARRAY( buf, buf_size, new_size ) ) - goto Exit; - - cursor = (ptrdiff_t)buf_size; - buf_size = new_size; - } - else - { - bytes = avail - start; - - FT_MEM_MOVE( buf, buf + start, bytes ); - - cursor = bytes; - avail -= bytes; - start = 0; - } - refill = 1; - continue; - } - - /* Temporarily NUL-terminate the line. */ - hold = buf[end]; - buf[end] = 0; - - /* XXX: Use encoding independent value for 0x1A */ - if ( buf[start] != '#' && buf[start] != 0x1A && end > start ) - { - error = (*cb)( buf + start, (unsigned long)( end - start ), lineno, - (void*)&cb, client_data ); - /* Redo if we have encountered CHARS without properties. */ - if ( error == -1 ) - error = (*cb)( buf + start, (unsigned long)( end - start ), lineno, - (void*)&cb, client_data ); - if ( error ) - break; - } - - lineno += 1; - buf[end] = (char)hold; - start = end + 1; - - if ( hold == '\n' ) - to_skip = '\r'; - else if ( hold == '\r' ) - to_skip = '\n'; - else - to_skip = NO_SKIP; - } - - *lno = lineno; - - Exit: - FT_FREE( buf ); - return error; - } - - - /* XXX: make this work with EBCDIC also */ - - static const unsigned char a2i[128] = - { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - }; - - static const unsigned char ddigits[32] = - { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x03, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - }; - - static const unsigned char hdigits[32] = - { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x03, - 0x7E, 0x00, 0x00, 0x00, 0x7E, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - }; - - - /* Routine to convert a decimal ASCII string to an unsigned long integer. */ - static unsigned long - _bdf_atoul( char* s ) - { - unsigned long v; - - - if ( s == 0 || *s == 0 ) - return 0; - - for ( v = 0; sbitset( ddigits, *s ); s++ ) - { - if ( v < ( FT_ULONG_MAX - 9 ) / 10 ) - v = v * 10 + a2i[(int)*s]; - else - { - v = FT_ULONG_MAX; - break; - } - } - - return v; - } - - - /* Routine to convert a decimal ASCII string to a signed long integer. */ - static long - _bdf_atol( char* s ) - { - long v, neg; - - - if ( s == 0 || *s == 0 ) - return 0; - - /* Check for a minus sign. */ - neg = 0; - if ( *s == '-' ) - { - s++; - neg = 1; - } - - for ( v = 0; sbitset( ddigits, *s ); s++ ) - { - if ( v < ( FT_LONG_MAX - 9 ) / 10 ) - v = v * 10 + a2i[(int)*s]; - else - { - v = FT_LONG_MAX; - break; - } - } - - return ( !neg ) ? v : -v; - } - - - /* Routine to convert a decimal ASCII string to an unsigned short integer. */ - static unsigned short - _bdf_atous( char* s ) - { - unsigned short v; - - - if ( s == 0 || *s == 0 ) - return 0; - - for ( v = 0; sbitset( ddigits, *s ); s++ ) - { - if ( v < ( FT_USHORT_MAX - 9 ) / 10 ) - v = (unsigned short)( v * 10 + a2i[(int)*s] ); - else - { - v = FT_USHORT_MAX; - break; - } - } - - return v; - } - - - /* Routine to convert a decimal ASCII string to a signed short integer. */ - static short - _bdf_atos( char* s ) - { - short v, neg; - - - if ( s == 0 || *s == 0 ) - return 0; - - /* Check for a minus. */ - neg = 0; - if ( *s == '-' ) - { - s++; - neg = 1; - } - - for ( v = 0; sbitset( ddigits, *s ); s++ ) - { - if ( v < ( SHRT_MAX - 9 ) / 10 ) - v = (short)( v * 10 + a2i[(int)*s] ); - else - { - v = SHRT_MAX; - break; - } - } - - return (short)( ( !neg ) ? v : -v ); - } - - - /* Routine to compare two glyphs by encoding so they can be sorted. */ - static int - by_encoding( const void* a, - const void* b ) - { - bdf_glyph_t *c1, *c2; - - - c1 = (bdf_glyph_t *)a; - c2 = (bdf_glyph_t *)b; - - if ( c1->encoding < c2->encoding ) - return -1; - - if ( c1->encoding > c2->encoding ) - return 1; - - return 0; - } - - - static FT_Error - bdf_create_property( char* name, - int format, - bdf_font_t* font ) - { - size_t n; - bdf_property_t* p; - FT_Memory memory = font->memory; - FT_Error error = FT_Err_Ok; - - - /* First check whether the property has */ - /* already been added or not. If it has, then */ - /* simply ignore it. */ - if ( ft_hash_str_lookup( name, &(font->proptbl) ) ) - goto Exit; - - if ( FT_RENEW_ARRAY( font->user_props, - font->nuser_props, - font->nuser_props + 1 ) ) - goto Exit; - - p = font->user_props + font->nuser_props; - FT_ZERO( p ); - - n = ft_strlen( name ) + 1; - if ( n > FT_ULONG_MAX ) - return FT_THROW( Invalid_Argument ); - - if ( FT_NEW_ARRAY( p->name, n ) ) - goto Exit; - - FT_MEM_COPY( (char *)p->name, name, n ); - - p->format = format; - p->builtin = 0; - - n = _num_bdf_properties + font->nuser_props; - - error = ft_hash_str_insert( p->name, n, &(font->proptbl), memory ); - if ( error ) - goto Exit; - - font->nuser_props++; - - Exit: - return error; - } - - - FT_LOCAL_DEF( bdf_property_t* ) - bdf_get_property( char* name, - bdf_font_t* font ) - { - size_t* propid; - - - if ( name == 0 || *name == 0 ) - return 0; - - if ( ( propid = ft_hash_str_lookup( name, &(font->proptbl) ) ) == NULL ) - return 0; - - if ( *propid >= _num_bdf_properties ) - return font->user_props + ( *propid - _num_bdf_properties ); - - return (bdf_property_t*)_bdf_properties + *propid; - } - - - /************************************************************************** - * - * BDF font file parsing flags and functions. - * - */ - - - /* Parse flags. */ - -#define BDF_START_ 0x0001U -#define BDF_FONT_NAME_ 0x0002U -#define BDF_SIZE_ 0x0004U -#define BDF_FONT_BBX_ 0x0008U -#define BDF_PROPS_ 0x0010U -#define BDF_GLYPHS_ 0x0020U -#define BDF_GLYPH_ 0x0040U -#define BDF_ENCODING_ 0x0080U -#define BDF_SWIDTH_ 0x0100U -#define BDF_DWIDTH_ 0x0200U -#define BDF_BBX_ 0x0400U -#define BDF_BITMAP_ 0x0800U - -#define BDF_SWIDTH_ADJ_ 0x1000U - -#define BDF_GLYPH_BITS_ ( BDF_GLYPH_ | \ - BDF_ENCODING_ | \ - BDF_SWIDTH_ | \ - BDF_DWIDTH_ | \ - BDF_BBX_ | \ - BDF_BITMAP_ ) - -#define BDF_GLYPH_WIDTH_CHECK_ 0x40000000UL -#define BDF_GLYPH_HEIGHT_CHECK_ 0x80000000UL - - - static FT_Error - _bdf_add_comment( bdf_font_t* font, - char* comment, - unsigned long len ) - { - char* cp; - FT_Memory memory = font->memory; - FT_Error error = FT_Err_Ok; - - - if ( FT_RENEW_ARRAY( font->comments, - font->comments_len, - font->comments_len + len + 1 ) ) - goto Exit; - - cp = font->comments + font->comments_len; - - FT_MEM_COPY( cp, comment, len ); - cp[len] = '\n'; - - font->comments_len += len + 1; - - Exit: - return error; - } - - - /* Set the spacing from the font name if it exists, or set it to the */ - /* default specified in the options. */ - static FT_Error - _bdf_set_default_spacing( bdf_font_t* font, - bdf_options_t* opts, - unsigned long lineno ) - { - size_t len; - char name[256]; - _bdf_list_t list; - FT_Memory memory; - FT_Error error = FT_Err_Ok; - - FT_UNUSED( lineno ); /* only used in debug mode */ - - - if ( font == 0 || font->name == 0 || font->name[0] == 0 ) - { - error = FT_THROW( Invalid_Argument ); - goto Exit; - } - - memory = font->memory; - - _bdf_list_init( &list, memory ); - - font->spacing = opts->font_spacing; - - len = ft_strlen( font->name ) + 1; - /* Limit ourselves to 256 characters in the font name. */ - if ( len >= 256 ) - { - FT_ERROR(( "_bdf_set_default_spacing: " ERRMSG7, lineno )); - error = FT_THROW( Invalid_Argument ); - goto Exit; - } - - FT_MEM_COPY( name, font->name, len ); - - error = _bdf_list_split( &list, (char *)"-", name, (unsigned long)len ); - if ( error ) - goto Fail; - - if ( list.used == 15 ) - { - switch ( list.field[11][0] ) - { - case 'C': - case 'c': - font->spacing = BDF_CHARCELL; - break; - case 'M': - case 'm': - font->spacing = BDF_MONOWIDTH; - break; - case 'P': - case 'p': - font->spacing = BDF_PROPORTIONAL; - break; - } - } - - Fail: - _bdf_list_done( &list ); - - Exit: - return error; - } - - - /* Determine whether the property is an atom or not. If it is, then */ - /* clean it up so the double quotes are removed if they exist. */ - static int - _bdf_is_atom( char* line, - unsigned long linelen, - char** name, - char** value, - bdf_font_t* font ) - { - int hold; - char *sp, *ep; - bdf_property_t* p; - - - *name = sp = ep = line; - - while ( *ep && *ep != ' ' && *ep != '\t' ) - ep++; - - hold = -1; - if ( *ep ) - { - hold = *ep; - *ep = 0; - } - - p = bdf_get_property( sp, font ); - - /* Restore the character that was saved before any return can happen. */ - if ( hold != -1 ) - *ep = (char)hold; - - /* If the property exists and is not an atom, just return here. */ - if ( p && p->format != BDF_ATOM ) - return 0; - - /* The property is an atom. Trim all leading and trailing whitespace */ - /* and double quotes for the atom value. */ - sp = ep; - ep = line + linelen; - - /* Trim the leading whitespace if it exists. */ - if ( *sp ) - *sp++ = 0; - while ( *sp && - ( *sp == ' ' || *sp == '\t' ) ) - sp++; - - /* Trim the leading double quote if it exists. */ - if ( *sp == '"' ) - sp++; - *value = sp; - - /* Trim the trailing whitespace if it exists. */ - while ( ep > sp && - ( *( ep - 1 ) == ' ' || *( ep - 1 ) == '\t' ) ) - *--ep = 0; - - /* Trim the trailing double quote if it exists. */ - if ( ep > sp && *( ep - 1 ) == '"' ) - *--ep = 0; - - return 1; - } - - - static FT_Error - _bdf_add_property( bdf_font_t* font, - char* name, - char* value, - unsigned long lineno ) - { - size_t* propid; - bdf_property_t *prop, *fp; - FT_Memory memory = font->memory; - FT_Error error = FT_Err_Ok; - - FT_UNUSED( lineno ); /* only used in debug mode */ - - - /* First, check whether the property already exists in the font. */ - if ( ( propid = ft_hash_str_lookup( name, - (FT_Hash)font->internal ) ) != NULL ) - { - /* The property already exists in the font, so simply replace */ - /* the value of the property with the current value. */ - fp = font->props + *propid; - - switch ( fp->format ) - { - case BDF_ATOM: - /* Delete the current atom if it exists. */ - FT_FREE( fp->value.atom ); - - if ( value && value[0] != 0 ) - { - if ( FT_STRDUP( fp->value.atom, value ) ) - goto Exit; - } - break; - - case BDF_INTEGER: - fp->value.l = _bdf_atol( value ); - break; - - case BDF_CARDINAL: - fp->value.ul = _bdf_atoul( value ); - break; - - default: - ; - } - - goto Exit; - } - - /* See whether this property type exists yet or not. */ - /* If not, create it. */ - propid = ft_hash_str_lookup( name, &(font->proptbl) ); - if ( !propid ) - { - error = bdf_create_property( name, BDF_ATOM, font ); - if ( error ) - goto Exit; - propid = ft_hash_str_lookup( name, &(font->proptbl) ); - } - - /* Allocate another property if this is overflowing. */ - if ( font->props_used == font->props_size ) - { - if ( font->props_size == 0 ) - { - if ( FT_NEW_ARRAY( font->props, 1 ) ) - goto Exit; - } - else - { - if ( FT_RENEW_ARRAY( font->props, - font->props_size, - font->props_size + 1 ) ) - goto Exit; - } - - fp = font->props + font->props_size; - FT_ZERO( fp ); - font->props_size++; - } - - if ( *propid >= _num_bdf_properties ) - prop = font->user_props + ( *propid - _num_bdf_properties ); - else - prop = (bdf_property_t*)_bdf_properties + *propid; - - fp = font->props + font->props_used; - - fp->name = prop->name; - fp->format = prop->format; - fp->builtin = prop->builtin; - - switch ( prop->format ) - { - case BDF_ATOM: - fp->value.atom = 0; - if ( value != 0 && value[0] ) - { - if ( FT_STRDUP( fp->value.atom, value ) ) - goto Exit; - } - break; - - case BDF_INTEGER: - fp->value.l = _bdf_atol( value ); - break; - - case BDF_CARDINAL: - fp->value.ul = _bdf_atoul( value ); - break; - } - - /* If the property happens to be a comment, then it doesn't need */ - /* to be added to the internal hash table. */ - if ( _bdf_strncmp( name, "COMMENT", 7 ) != 0 ) - { - /* Add the property to the font property table. */ - error = ft_hash_str_insert( fp->name, - font->props_used, - (FT_Hash)font->internal, - memory ); - if ( error ) - goto Exit; - } - - font->props_used++; - - /* Some special cases need to be handled here. The DEFAULT_CHAR */ - /* property needs to be located if it exists in the property list, the */ - /* FONT_ASCENT and FONT_DESCENT need to be assigned if they are */ - /* present, and the SPACING property should override the default */ - /* spacing. */ - if ( _bdf_strncmp( name, "DEFAULT_CHAR", 12 ) == 0 ) - font->default_char = fp->value.ul; - else if ( _bdf_strncmp( name, "FONT_ASCENT", 11 ) == 0 ) - font->font_ascent = fp->value.l; - else if ( _bdf_strncmp( name, "FONT_DESCENT", 12 ) == 0 ) - font->font_descent = fp->value.l; - else if ( _bdf_strncmp( name, "SPACING", 7 ) == 0 ) - { - if ( !fp->value.atom ) - { - FT_ERROR(( "_bdf_add_property: " ERRMSG8, lineno, "SPACING" )); - error = FT_THROW( Invalid_File_Format ); - goto Exit; - } - - if ( fp->value.atom[0] == 'p' || fp->value.atom[0] == 'P' ) - font->spacing = BDF_PROPORTIONAL; - else if ( fp->value.atom[0] == 'm' || fp->value.atom[0] == 'M' ) - font->spacing = BDF_MONOWIDTH; - else if ( fp->value.atom[0] == 'c' || fp->value.atom[0] == 'C' ) - font->spacing = BDF_CHARCELL; - } - - Exit: - return error; - } - - - static const unsigned char nibble_mask[8] = - { - 0xFF, 0x80, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC, 0xFE - }; - - - static FT_Error - _bdf_parse_end( char* line, - unsigned long linelen, - unsigned long lineno, - void* call_data, - void* client_data ) - { - /* a no-op; we ignore everything after `ENDFONT' */ - - FT_UNUSED( line ); - FT_UNUSED( linelen ); - FT_UNUSED( lineno ); - FT_UNUSED( call_data ); - FT_UNUSED( client_data ); - - return FT_Err_Ok; - } - - - /* Actually parse the glyph info and bitmaps. */ - static FT_Error - _bdf_parse_glyphs( char* line, - unsigned long linelen, - unsigned long lineno, - void* call_data, - void* client_data ) - { - int c, mask_index; - char* s; - unsigned char* bp; - unsigned long i, slen, nibbles; - - _bdf_line_func_t* next; - _bdf_parse_t* p; - bdf_glyph_t* glyph; - bdf_font_t* font; - - FT_Memory memory; - FT_Error error = FT_Err_Ok; - - FT_UNUSED( lineno ); /* only used in debug mode */ - - - next = (_bdf_line_func_t *)call_data; - p = (_bdf_parse_t *) client_data; - - font = p->font; - memory = font->memory; - - /* Check for a comment. */ - if ( _bdf_strncmp( line, "COMMENT", 7 ) == 0 ) - { - linelen -= 7; - - s = line + 7; - if ( *s != 0 ) - { - s++; - linelen--; - } - error = _bdf_add_comment( p->font, s, linelen ); - goto Exit; - } - - /* The very first thing expected is the number of glyphs. */ - if ( !( p->flags & BDF_GLYPHS_ ) ) - { - if ( _bdf_strncmp( line, "CHARS", 5 ) != 0 ) - { - FT_ERROR(( "_bdf_parse_glyphs: " ERRMSG1, lineno, "CHARS" )); - error = FT_THROW( Missing_Chars_Field ); - goto Exit; - } - - error = _bdf_list_split( &p->list, (char *)" +", line, linelen ); - if ( error ) - goto Exit; - p->cnt = font->glyphs_size = _bdf_atoul( p->list.field[1] ); - - /* We need at least 20 bytes per glyph. */ - if ( p->cnt > p->size / 20 ) - { - p->cnt = font->glyphs_size = p->size / 20; - FT_TRACE2(( "_bdf_parse_glyphs: " ACMSG17, p->cnt )); - } - - /* Make sure the number of glyphs is non-zero. */ - if ( p->cnt == 0 ) - font->glyphs_size = 64; - - /* Limit ourselves to 1,114,112 glyphs in the font (this is the */ - /* number of code points available in Unicode). */ - if ( p->cnt >= 0x110000UL ) - { - FT_ERROR(( "_bdf_parse_glyphs: " ERRMSG5, lineno, "CHARS" )); - error = FT_THROW( Invalid_Argument ); - goto Exit; - } - - if ( FT_NEW_ARRAY( font->glyphs, font->glyphs_size ) ) - goto Exit; - - p->flags |= BDF_GLYPHS_; - - goto Exit; - } - - /* Check for the ENDFONT field. */ - if ( _bdf_strncmp( line, "ENDFONT", 7 ) == 0 ) - { - if ( p->flags & BDF_GLYPH_BITS_ ) - { - /* Missing ENDCHAR field. */ - FT_ERROR(( "_bdf_parse_glyphs: " ERRMSG1, lineno, "ENDCHAR" )); - error = FT_THROW( Corrupted_Font_Glyphs ); - goto Exit; - } - - /* Sort the glyphs by encoding. */ - ft_qsort( (char *)font->glyphs, - font->glyphs_used, - sizeof ( bdf_glyph_t ), - by_encoding ); - - p->flags &= ~BDF_START_; - *next = _bdf_parse_end; - - goto Exit; - } - - /* Check for the ENDCHAR field. */ - if ( _bdf_strncmp( line, "ENDCHAR", 7 ) == 0 ) - { - p->glyph_enc = 0; - p->flags &= ~BDF_GLYPH_BITS_; - - goto Exit; - } - - /* Check whether a glyph is being scanned but should be */ - /* ignored because it is an unencoded glyph. */ - if ( ( p->flags & BDF_GLYPH_ ) && - p->glyph_enc == -1 && - p->opts->keep_unencoded == 0 ) - goto Exit; - - /* Check for the STARTCHAR field. */ - if ( _bdf_strncmp( line, "STARTCHAR", 9 ) == 0 ) - { - if ( p->flags & BDF_GLYPH_BITS_ ) - { - /* Missing ENDCHAR field. */ - FT_ERROR(( "_bdf_parse_glyphs: " ERRMSG1, lineno, "ENDCHAR" )); - error = FT_THROW( Missing_Startchar_Field ); - goto Exit; - } - - /* Set the character name in the parse info first until the */ - /* encoding can be checked for an unencoded character. */ - FT_FREE( p->glyph_name ); - - error = _bdf_list_split( &p->list, (char *)" +", line, linelen ); - if ( error ) - goto Exit; - - _bdf_list_shift( &p->list, 1 ); - - s = _bdf_list_join( &p->list, ' ', &slen ); - - if ( !s ) - { - FT_ERROR(( "_bdf_parse_glyphs: " ERRMSG8, lineno, "STARTCHAR" )); - error = FT_THROW( Invalid_File_Format ); - goto Exit; - } - - if ( FT_NEW_ARRAY( p->glyph_name, slen + 1 ) ) - goto Exit; - - FT_MEM_COPY( p->glyph_name, s, slen + 1 ); - - p->flags |= BDF_GLYPH_; - - FT_TRACE4(( DBGMSG1, lineno, s )); - - goto Exit; - } - - /* Check for the ENCODING field. */ - if ( _bdf_strncmp( line, "ENCODING", 8 ) == 0 ) - { - if ( !( p->flags & BDF_GLYPH_ ) ) - { - /* Missing STARTCHAR field. */ - FT_ERROR(( "_bdf_parse_glyphs: " ERRMSG1, lineno, "STARTCHAR" )); - error = FT_THROW( Missing_Startchar_Field ); - goto Exit; - } - - error = _bdf_list_split( &p->list, (char *)" +", line, linelen ); - if ( error ) - goto Exit; - - p->glyph_enc = _bdf_atol( p->list.field[1] ); - - /* Normalize negative encoding values. The specification only */ - /* allows -1, but we can be more generous here. */ - if ( p->glyph_enc < -1 ) - p->glyph_enc = -1; - - /* Check for alternative encoding format. */ - if ( p->glyph_enc == -1 && p->list.used > 2 ) - p->glyph_enc = _bdf_atol( p->list.field[2] ); - - if ( p->glyph_enc < -1 || p->glyph_enc >= 0x110000L ) - p->glyph_enc = -1; - - FT_TRACE4(( DBGMSG2, p->glyph_enc )); - - if ( p->glyph_enc >= 0 ) - { - /* Make sure there are enough glyphs allocated in case the */ - /* number of characters happen to be wrong. */ - if ( font->glyphs_used == font->glyphs_size ) - { - if ( FT_RENEW_ARRAY( font->glyphs, - font->glyphs_size, - font->glyphs_size + 64 ) ) - goto Exit; - - font->glyphs_size += 64; - } - - glyph = font->glyphs + font->glyphs_used++; - glyph->name = p->glyph_name; - glyph->encoding = (unsigned long)p->glyph_enc; - - /* Reset the initial glyph info. */ - p->glyph_name = NULL; - } - else - { - /* Unencoded glyph. Check whether it should */ - /* be added or not. */ - if ( p->opts->keep_unencoded != 0 ) - { - /* Allocate the next unencoded glyph. */ - if ( font->unencoded_used == font->unencoded_size ) - { - if ( FT_RENEW_ARRAY( font->unencoded , - font->unencoded_size, - font->unencoded_size + 4 ) ) - goto Exit; - - font->unencoded_size += 4; - } - - glyph = font->unencoded + font->unencoded_used; - glyph->name = p->glyph_name; - glyph->encoding = font->unencoded_used++; - - /* Reset the initial glyph info. */ - p->glyph_name = NULL; - } - else - { - /* Free up the glyph name if the unencoded shouldn't be */ - /* kept. */ - FT_FREE( p->glyph_name ); - } - - p->glyph_name = NULL; - } - - /* Clear the flags that might be added when width and height are */ - /* checked for consistency. */ - p->flags &= ~( BDF_GLYPH_WIDTH_CHECK_ | BDF_GLYPH_HEIGHT_CHECK_ ); - - p->flags |= BDF_ENCODING_; - - goto Exit; - } - - if ( !( p->flags & BDF_ENCODING_ ) ) - goto Missing_Encoding; - - /* Point at the glyph being constructed. */ - if ( p->glyph_enc == -1 ) - glyph = font->unencoded + ( font->unencoded_used - 1 ); - else - glyph = font->glyphs + ( font->glyphs_used - 1 ); - - /* Check whether a bitmap is being constructed. */ - if ( p->flags & BDF_BITMAP_ ) - { - /* If there are more rows than are specified in the glyph metrics, */ - /* ignore the remaining lines. */ - if ( p->row >= (unsigned long)glyph->bbx.height ) - { - if ( !( p->flags & BDF_GLYPH_HEIGHT_CHECK_ ) ) - { - FT_TRACE2(( "_bdf_parse_glyphs: " ACMSG13, glyph->encoding )); - p->flags |= BDF_GLYPH_HEIGHT_CHECK_; - } - - goto Exit; - } - - /* Only collect the number of nibbles indicated by the glyph */ - /* metrics. If there are more columns, they are simply ignored. */ - nibbles = glyph->bpr << 1; - bp = glyph->bitmap + p->row * glyph->bpr; - - for ( i = 0; i < nibbles; i++ ) - { - c = line[i]; - if ( !sbitset( hdigits, c ) ) - break; - *bp = (FT_Byte)( ( *bp << 4 ) + a2i[c] ); - if ( i + 1 < nibbles && ( i & 1 ) ) - *++bp = 0; - } - - /* If any line has not enough columns, */ - /* indicate they have been padded with zero bits. */ - if ( i < nibbles && - !( p->flags & BDF_GLYPH_WIDTH_CHECK_ ) ) - { - FT_TRACE2(( "_bdf_parse_glyphs: " ACMSG16, glyph->encoding )); - p->flags |= BDF_GLYPH_WIDTH_CHECK_; - } - - /* Remove possible garbage at the right. */ - mask_index = ( glyph->bbx.width * p->font->bpp ) & 7; - if ( glyph->bbx.width ) - *bp &= nibble_mask[mask_index]; - - /* If any line has extra columns, indicate they have been removed. */ - if ( i == nibbles && - sbitset( hdigits, line[nibbles] ) && - !( p->flags & BDF_GLYPH_WIDTH_CHECK_ ) ) - { - FT_TRACE2(( "_bdf_parse_glyphs: " ACMSG14, glyph->encoding )); - p->flags |= BDF_GLYPH_WIDTH_CHECK_; - } - - p->row++; - goto Exit; - } - - /* Expect the SWIDTH (scalable width) field next. */ - if ( _bdf_strncmp( line, "SWIDTH", 6 ) == 0 ) - { - error = _bdf_list_split( &p->list, (char *)" +", line, linelen ); - if ( error ) - goto Exit; - - glyph->swidth = (unsigned short)_bdf_atoul( p->list.field[1] ); - p->flags |= BDF_SWIDTH_; - - goto Exit; - } - - /* Expect the DWIDTH (scalable width) field next. */ - if ( _bdf_strncmp( line, "DWIDTH", 6 ) == 0 ) - { - error = _bdf_list_split( &p->list, (char *)" +", line, linelen ); - if ( error ) - goto Exit; - - glyph->dwidth = (unsigned short)_bdf_atoul( p->list.field[1] ); - - if ( !( p->flags & BDF_SWIDTH_ ) ) - { - /* Missing SWIDTH field. Emit an auto correction message and set */ - /* the scalable width from the device width. */ - FT_TRACE2(( "_bdf_parse_glyphs: " ACMSG9, lineno )); - - glyph->swidth = (unsigned short)FT_MulDiv( - glyph->dwidth, 72000L, - (FT_Long)( font->point_size * - font->resolution_x ) ); - } - - p->flags |= BDF_DWIDTH_; - goto Exit; - } - - /* Expect the BBX field next. */ - if ( _bdf_strncmp( line, "BBX", 3 ) == 0 ) - { - error = _bdf_list_split( &p->list, (char *)" +", line, linelen ); - if ( error ) - goto Exit; - - glyph->bbx.width = _bdf_atous( p->list.field[1] ); - glyph->bbx.height = _bdf_atous( p->list.field[2] ); - glyph->bbx.x_offset = _bdf_atos( p->list.field[3] ); - glyph->bbx.y_offset = _bdf_atos( p->list.field[4] ); - - /* Generate the ascent and descent of the character. */ - glyph->bbx.ascent = (short)( glyph->bbx.height + glyph->bbx.y_offset ); - glyph->bbx.descent = (short)( -glyph->bbx.y_offset ); - - /* Determine the overall font bounding box as the characters are */ - /* loaded so corrections can be done later if indicated. */ - p->maxas = (short)FT_MAX( glyph->bbx.ascent, p->maxas ); - p->maxds = (short)FT_MAX( glyph->bbx.descent, p->maxds ); - - p->rbearing = (short)( glyph->bbx.width + glyph->bbx.x_offset ); - - p->maxrb = (short)FT_MAX( p->rbearing, p->maxrb ); - p->minlb = (short)FT_MIN( glyph->bbx.x_offset, p->minlb ); - p->maxlb = (short)FT_MAX( glyph->bbx.x_offset, p->maxlb ); - - if ( !( p->flags & BDF_DWIDTH_ ) ) - { - /* Missing DWIDTH field. Emit an auto correction message and set */ - /* the device width to the glyph width. */ - FT_TRACE2(( "_bdf_parse_glyphs: " ACMSG10, lineno )); - glyph->dwidth = glyph->bbx.width; - } - - /* If the BDF_CORRECT_METRICS flag is set, then adjust the SWIDTH */ - /* value if necessary. */ - if ( p->opts->correct_metrics != 0 ) - { - /* Determine the point size of the glyph. */ - unsigned short sw = (unsigned short)FT_MulDiv( - glyph->dwidth, 72000L, - (FT_Long)( font->point_size * - font->resolution_x ) ); - - - if ( sw != glyph->swidth ) - { - glyph->swidth = sw; - - p->flags |= BDF_SWIDTH_ADJ_; - } - } - - p->flags |= BDF_BBX_; - goto Exit; - } - - /* And finally, gather up the bitmap. */ - if ( _bdf_strncmp( line, "BITMAP", 6 ) == 0 ) - { - unsigned long bitmap_size; - - - if ( !( p->flags & BDF_BBX_ ) ) - { - /* Missing BBX field. */ - FT_ERROR(( "_bdf_parse_glyphs: " ERRMSG1, lineno, "BBX" )); - error = FT_THROW( Missing_Bbx_Field ); - goto Exit; - } - - /* Allocate enough space for the bitmap. */ - glyph->bpr = ( glyph->bbx.width * p->font->bpp + 7 ) >> 3; - - bitmap_size = glyph->bpr * glyph->bbx.height; - if ( glyph->bpr > 0xFFFFU || bitmap_size > 0xFFFFU ) - { - FT_ERROR(( "_bdf_parse_glyphs: " ERRMSG4, lineno )); - error = FT_THROW( Bbx_Too_Big ); - goto Exit; - } - else - glyph->bytes = (unsigned short)bitmap_size; - - if ( FT_NEW_ARRAY( glyph->bitmap, glyph->bytes ) ) - goto Exit; - - p->row = 0; - p->flags |= BDF_BITMAP_; - - goto Exit; - } - - FT_ERROR(( "_bdf_parse_glyphs: " ERRMSG9, lineno )); - error = FT_THROW( Invalid_File_Format ); - goto Exit; - - Missing_Encoding: - /* Missing ENCODING field. */ - FT_ERROR(( "_bdf_parse_glyphs: " ERRMSG1, lineno, "ENCODING" )); - error = FT_THROW( Missing_Encoding_Field ); - - Exit: - if ( error && ( p->flags & BDF_GLYPH_ ) ) - FT_FREE( p->glyph_name ); - - return error; - } - - - /* Load the font properties. */ - static FT_Error - _bdf_parse_properties( char* line, - unsigned long linelen, - unsigned long lineno, - void* call_data, - void* client_data ) - { - unsigned long vlen; - _bdf_line_func_t* next; - _bdf_parse_t* p; - char* name; - char* value; - char nbuf[128]; - FT_Error error = FT_Err_Ok; - - FT_UNUSED( lineno ); - - - next = (_bdf_line_func_t *)call_data; - p = (_bdf_parse_t *) client_data; - - /* Check for the end of the properties. */ - if ( _bdf_strncmp( line, "ENDPROPERTIES", 13 ) == 0 ) - { - /* If the FONT_ASCENT or FONT_DESCENT properties have not been */ - /* encountered yet, then make sure they are added as properties and */ - /* make sure they are set from the font bounding box info. */ - /* */ - /* This is *always* done regardless of the options, because X11 */ - /* requires these two fields to compile fonts. */ - if ( bdf_get_font_property( p->font, "FONT_ASCENT" ) == 0 ) - { - p->font->font_ascent = p->font->bbx.ascent; - ft_sprintf( nbuf, "%hd", p->font->bbx.ascent ); - error = _bdf_add_property( p->font, (char *)"FONT_ASCENT", - nbuf, lineno ); - if ( error ) - goto Exit; - - FT_TRACE2(( "_bdf_parse_properties: " ACMSG1, p->font->bbx.ascent )); - } - - if ( bdf_get_font_property( p->font, "FONT_DESCENT" ) == 0 ) - { - p->font->font_descent = p->font->bbx.descent; - ft_sprintf( nbuf, "%hd", p->font->bbx.descent ); - error = _bdf_add_property( p->font, (char *)"FONT_DESCENT", - nbuf, lineno ); - if ( error ) - goto Exit; - - FT_TRACE2(( "_bdf_parse_properties: " ACMSG2, p->font->bbx.descent )); - } - - p->flags &= ~BDF_PROPS_; - *next = _bdf_parse_glyphs; - - goto Exit; - } - - /* Ignore the _XFREE86_GLYPH_RANGES properties. */ - if ( _bdf_strncmp( line, "_XFREE86_GLYPH_RANGES", 21 ) == 0 ) - goto Exit; - - /* Handle COMMENT fields and properties in a special way to preserve */ - /* the spacing. */ - if ( _bdf_strncmp( line, "COMMENT", 7 ) == 0 ) - { - name = value = line; - value += 7; - if ( *value ) - *value++ = 0; - error = _bdf_add_property( p->font, name, value, lineno ); - if ( error ) - goto Exit; - } - else if ( _bdf_is_atom( line, linelen, &name, &value, p->font ) ) - { - error = _bdf_add_property( p->font, name, value, lineno ); - if ( error ) - goto Exit; - } - else - { - error = _bdf_list_split( &p->list, (char *)" +", line, linelen ); - if ( error ) - goto Exit; - name = p->list.field[0]; - - _bdf_list_shift( &p->list, 1 ); - value = _bdf_list_join( &p->list, ' ', &vlen ); - - error = _bdf_add_property( p->font, name, value, lineno ); - if ( error ) - goto Exit; - } - - Exit: - return error; - } - - - /* Load the font header. */ - static FT_Error - _bdf_parse_start( char* line, - unsigned long linelen, - unsigned long lineno, - void* call_data, - void* client_data ) - { - unsigned long slen; - _bdf_line_func_t* next; - _bdf_parse_t* p; - bdf_font_t* font; - char *s; - - FT_Memory memory = NULL; - FT_Error error = FT_Err_Ok; - - FT_UNUSED( lineno ); /* only used in debug mode */ - - - next = (_bdf_line_func_t *)call_data; - p = (_bdf_parse_t *) client_data; - - if ( p->font ) - memory = p->font->memory; - - /* Check for a comment. This is done to handle those fonts that have */ - /* comments before the STARTFONT line for some reason. */ - if ( _bdf_strncmp( line, "COMMENT", 7 ) == 0 ) - { - if ( p->opts->keep_comments != 0 && p->font != 0 ) - { - linelen -= 7; - - s = line + 7; - if ( *s != 0 ) - { - s++; - linelen--; - } - - error = _bdf_add_comment( p->font, s, linelen ); - if ( error ) - goto Exit; - /* here font is not defined! */ - } - - goto Exit; - } - - if ( !( p->flags & BDF_START_ ) ) - { - memory = p->memory; - - if ( _bdf_strncmp( line, "STARTFONT", 9 ) != 0 ) - { - /* we don't emit an error message since this code gets */ - /* explicitly caught one level higher */ - error = FT_THROW( Missing_Startfont_Field ); - goto Exit; - } - - p->flags = BDF_START_; - font = p->font = 0; - - if ( FT_NEW( font ) ) - goto Exit; - p->font = font; - - font->memory = p->memory; - p->memory = 0; - - { /* setup */ - size_t i; - bdf_property_t* prop; - - - error = ft_hash_str_init( &(font->proptbl), memory ); - if ( error ) - goto Exit; - for ( i = 0, prop = (bdf_property_t*)_bdf_properties; - i < _num_bdf_properties; i++, prop++ ) - { - error = ft_hash_str_insert( prop->name, i, - &(font->proptbl), memory ); - if ( error ) - goto Exit; - } - } - - if ( FT_ALLOC( p->font->internal, sizeof ( FT_HashRec ) ) ) - goto Exit; - error = ft_hash_str_init( (FT_Hash)p->font->internal, memory ); - if ( error ) - goto Exit; - p->font->spacing = p->opts->font_spacing; - p->font->default_char = ~0UL; - - goto Exit; - } - - /* Check for the start of the properties. */ - if ( _bdf_strncmp( line, "STARTPROPERTIES", 15 ) == 0 ) - { - if ( !( p->flags & BDF_FONT_BBX_ ) ) - { - /* Missing the FONTBOUNDINGBOX field. */ - FT_ERROR(( "_bdf_parse_start: " ERRMSG1, lineno, "FONTBOUNDINGBOX" )); - error = FT_THROW( Missing_Fontboundingbox_Field ); - goto Exit; - } - - error = _bdf_list_split( &p->list, (char *)" +", line, linelen ); - if ( error ) - goto Exit; - - /* at this point, `p->font' can't be NULL */ - p->cnt = p->font->props_size = _bdf_atoul( p->list.field[1] ); - /* We need at least 4 bytes per property. */ - if ( p->cnt > p->size / 4 ) - { - p->font->props_size = 0; - - FT_ERROR(( "_bdf_parse_glyphs: " ERRMSG5, lineno, "STARTPROPERTIES" )); - error = FT_THROW( Invalid_Argument ); - goto Exit; - } - - if ( FT_NEW_ARRAY( p->font->props, p->cnt ) ) - { - p->font->props_size = 0; - goto Exit; - } - - p->flags |= BDF_PROPS_; - *next = _bdf_parse_properties; - - goto Exit; - } - - /* Check for the FONTBOUNDINGBOX field. */ - if ( _bdf_strncmp( line, "FONTBOUNDINGBOX", 15 ) == 0 ) - { - if ( !( p->flags & BDF_SIZE_ ) ) - { - /* Missing the SIZE field. */ - FT_ERROR(( "_bdf_parse_start: " ERRMSG1, lineno, "SIZE" )); - error = FT_THROW( Missing_Size_Field ); - goto Exit; - } - - error = _bdf_list_split( &p->list, (char *)" +", line, linelen ); - if ( error ) - goto Exit; - - p->font->bbx.width = _bdf_atous( p->list.field[1] ); - p->font->bbx.height = _bdf_atous( p->list.field[2] ); - - p->font->bbx.x_offset = _bdf_atos( p->list.field[3] ); - p->font->bbx.y_offset = _bdf_atos( p->list.field[4] ); - - p->font->bbx.ascent = (short)( p->font->bbx.height + - p->font->bbx.y_offset ); - - p->font->bbx.descent = (short)( -p->font->bbx.y_offset ); - - p->flags |= BDF_FONT_BBX_; - - goto Exit; - } - - /* The next thing to check for is the FONT field. */ - if ( _bdf_strncmp( line, "FONT", 4 ) == 0 ) - { - error = _bdf_list_split( &p->list, (char *)" +", line, linelen ); - if ( error ) - goto Exit; - _bdf_list_shift( &p->list, 1 ); - - s = _bdf_list_join( &p->list, ' ', &slen ); - - if ( !s ) - { - FT_ERROR(( "_bdf_parse_start: " ERRMSG8, lineno, "FONT" )); - error = FT_THROW( Invalid_File_Format ); - goto Exit; - } - - /* Allowing multiple `FONT' lines (which is invalid) doesn't hurt... */ - FT_FREE( p->font->name ); - - if ( FT_NEW_ARRAY( p->font->name, slen + 1 ) ) - goto Exit; - FT_MEM_COPY( p->font->name, s, slen + 1 ); - - /* If the font name is an XLFD name, set the spacing to the one in */ - /* the font name. If there is no spacing fall back on the default. */ - error = _bdf_set_default_spacing( p->font, p->opts, lineno ); - if ( error ) - goto Exit; - - p->flags |= BDF_FONT_NAME_; - - goto Exit; - } - - /* Check for the SIZE field. */ - if ( _bdf_strncmp( line, "SIZE", 4 ) == 0 ) - { - if ( !( p->flags & BDF_FONT_NAME_ ) ) - { - /* Missing the FONT field. */ - FT_ERROR(( "_bdf_parse_start: " ERRMSG1, lineno, "FONT" )); - error = FT_THROW( Missing_Font_Field ); - goto Exit; - } - - error = _bdf_list_split( &p->list, (char *)" +", line, linelen ); - if ( error ) - goto Exit; - - p->font->point_size = _bdf_atoul( p->list.field[1] ); - p->font->resolution_x = _bdf_atoul( p->list.field[2] ); - p->font->resolution_y = _bdf_atoul( p->list.field[3] ); - - /* Check for the bits per pixel field. */ - if ( p->list.used == 5 ) - { - unsigned short bpp; - - - bpp = (unsigned short)_bdf_atos( p->list.field[4] ); - - /* Only values 1, 2, 4, 8 are allowed for greymap fonts. */ - if ( bpp > 4 ) - p->font->bpp = 8; - else if ( bpp > 2 ) - p->font->bpp = 4; - else if ( bpp > 1 ) - p->font->bpp = 2; - else - p->font->bpp = 1; - - if ( p->font->bpp != bpp ) - FT_TRACE2(( "_bdf_parse_start: " ACMSG11, p->font->bpp )); - } - else - p->font->bpp = 1; - - p->flags |= BDF_SIZE_; - - goto Exit; - } - - /* Check for the CHARS field -- font properties are optional */ - if ( _bdf_strncmp( line, "CHARS", 5 ) == 0 ) - { - char nbuf[128]; - - - if ( !( p->flags & BDF_FONT_BBX_ ) ) - { - /* Missing the FONTBOUNDINGBOX field. */ - FT_ERROR(( "_bdf_parse_start: " ERRMSG1, lineno, "FONTBOUNDINGBOX" )); - error = FT_THROW( Missing_Fontboundingbox_Field ); - goto Exit; - } - - /* Add the two standard X11 properties which are required */ - /* for compiling fonts. */ - p->font->font_ascent = p->font->bbx.ascent; - ft_sprintf( nbuf, "%hd", p->font->bbx.ascent ); - error = _bdf_add_property( p->font, (char *)"FONT_ASCENT", - nbuf, lineno ); - if ( error ) - goto Exit; - FT_TRACE2(( "_bdf_parse_properties: " ACMSG1, p->font->bbx.ascent )); - - p->font->font_descent = p->font->bbx.descent; - ft_sprintf( nbuf, "%hd", p->font->bbx.descent ); - error = _bdf_add_property( p->font, (char *)"FONT_DESCENT", - nbuf, lineno ); - if ( error ) - goto Exit; - FT_TRACE2(( "_bdf_parse_properties: " ACMSG2, p->font->bbx.descent )); - - *next = _bdf_parse_glyphs; - - /* A special return value. */ - error = -1; - goto Exit; - } - - FT_ERROR(( "_bdf_parse_start: " ERRMSG9, lineno )); - error = FT_THROW( Invalid_File_Format ); - - Exit: - return error; - } - - - /************************************************************************** - * - * API. - * - */ - - - FT_LOCAL_DEF( FT_Error ) - bdf_load_font( FT_Stream stream, - FT_Memory extmemory, - bdf_options_t* opts, - bdf_font_t* *font ) - { - unsigned long lineno = 0; /* make compiler happy */ - _bdf_parse_t *p = NULL; - - FT_Memory memory = extmemory; /* needed for FT_NEW */ - FT_Error error = FT_Err_Ok; - - - if ( FT_NEW( p ) ) - goto Exit; - - memory = NULL; - p->opts = (bdf_options_t*)( ( opts != 0 ) ? opts : &_bdf_opts ); - p->minlb = 32767; - p->size = stream->size; - p->memory = extmemory; /* only during font creation */ - - _bdf_list_init( &p->list, extmemory ); - - error = _bdf_readstream( stream, _bdf_parse_start, - (void *)p, &lineno ); - if ( error ) - goto Fail; - - if ( p->font != 0 ) - { - /* If the font is not proportional, set the font's monowidth */ - /* field to the width of the font bounding box. */ - - if ( p->font->spacing != BDF_PROPORTIONAL ) - p->font->monowidth = p->font->bbx.width; - - /* If the number of glyphs loaded is not that of the original count, */ - /* indicate the difference. */ - if ( p->cnt != p->font->glyphs_used + p->font->unencoded_used ) - { - FT_TRACE2(( "bdf_load_font: " ACMSG15, p->cnt, - p->font->glyphs_used + p->font->unencoded_used )); - } - - /* Once the font has been loaded, adjust the overall font metrics if */ - /* necessary. */ - if ( p->opts->correct_metrics != 0 && - ( p->font->glyphs_used > 0 || p->font->unencoded_used > 0 ) ) - { - if ( p->maxrb - p->minlb != p->font->bbx.width ) - { - FT_TRACE2(( "bdf_load_font: " ACMSG3, - p->font->bbx.width, p->maxrb - p->minlb )); - p->font->bbx.width = (unsigned short)( p->maxrb - p->minlb ); - } - - if ( p->font->bbx.x_offset != p->minlb ) - { - FT_TRACE2(( "bdf_load_font: " ACMSG4, - p->font->bbx.x_offset, p->minlb )); - p->font->bbx.x_offset = p->minlb; - } - - if ( p->font->bbx.ascent != p->maxas ) - { - FT_TRACE2(( "bdf_load_font: " ACMSG5, - p->font->bbx.ascent, p->maxas )); - p->font->bbx.ascent = p->maxas; - } - - if ( p->font->bbx.descent != p->maxds ) - { - FT_TRACE2(( "bdf_load_font: " ACMSG6, - p->font->bbx.descent, p->maxds )); - p->font->bbx.descent = p->maxds; - p->font->bbx.y_offset = (short)( -p->maxds ); - } - - if ( p->maxas + p->maxds != p->font->bbx.height ) - { - FT_TRACE2(( "bdf_load_font: " ACMSG7, - p->font->bbx.height, p->maxas + p->maxds )); - p->font->bbx.height = (unsigned short)( p->maxas + p->maxds ); - } - - if ( p->flags & BDF_SWIDTH_ADJ_ ) - FT_TRACE2(( "bdf_load_font: " ACMSG8 )); - } - } - - if ( p->flags & BDF_START_ ) - { - /* The ENDFONT field was never reached or did not exist. */ - if ( !( p->flags & BDF_GLYPHS_ ) ) - { - /* Error happened while parsing header. */ - FT_ERROR(( "bdf_load_font: " ERRMSG2, lineno )); - error = FT_THROW( Corrupted_Font_Header ); - goto Fail; - } - else - { - /* Error happened when parsing glyphs. */ - FT_ERROR(( "bdf_load_font: " ERRMSG3, lineno )); - error = FT_THROW( Corrupted_Font_Glyphs ); - goto Fail; - } - } - - if ( p->font != 0 ) - { - /* Make sure the comments are NULL terminated if they exist. */ - memory = p->font->memory; - - if ( p->font->comments_len > 0 ) - { - if ( FT_RENEW_ARRAY( p->font->comments, - p->font->comments_len, - p->font->comments_len + 1 ) ) - goto Fail; - - p->font->comments[p->font->comments_len] = 0; - } - } - else if ( !error ) - error = FT_THROW( Invalid_File_Format ); - - *font = p->font; - - Exit: - if ( p ) - { - _bdf_list_done( &p->list ); - - memory = extmemory; - - FT_FREE( p->glyph_name ); - FT_FREE( p ); - } - - return error; - - Fail: - bdf_free_font( p->font ); - - memory = extmemory; - - FT_FREE( p->font ); - - goto Exit; - } - - - FT_LOCAL_DEF( void ) - bdf_free_font( bdf_font_t* font ) - { - bdf_property_t* prop; - unsigned long i; - bdf_glyph_t* glyphs; - FT_Memory memory; - - - if ( font == 0 ) - return; - - memory = font->memory; - - FT_FREE( font->name ); - - /* Free up the internal hash table of property names. */ - if ( font->internal ) - { - ft_hash_str_free( (FT_Hash)font->internal, memory ); - FT_FREE( font->internal ); - } - - /* Free up the comment info. */ - FT_FREE( font->comments ); - - /* Free up the properties. */ - for ( i = 0; i < font->props_size; i++ ) - { - if ( font->props[i].format == BDF_ATOM ) - FT_FREE( font->props[i].value.atom ); - } - - FT_FREE( font->props ); - - /* Free up the character info. */ - for ( i = 0, glyphs = font->glyphs; - i < font->glyphs_used; i++, glyphs++ ) - { - FT_FREE( glyphs->name ); - FT_FREE( glyphs->bitmap ); - } - - for ( i = 0, glyphs = font->unencoded; i < font->unencoded_used; - i++, glyphs++ ) - { - FT_FREE( glyphs->name ); - FT_FREE( glyphs->bitmap ); - } - - FT_FREE( font->glyphs ); - FT_FREE( font->unencoded ); - - /* bdf_cleanup */ - ft_hash_str_free( &(font->proptbl), memory ); - - /* Free up the user defined properties. */ - for ( prop = font->user_props, i = 0; - i < font->nuser_props; i++, prop++ ) - { - FT_FREE( prop->name ); - if ( prop->format == BDF_ATOM ) - FT_FREE( prop->value.atom ); - } - - FT_FREE( font->user_props ); - - /* FREE( font ); */ /* XXX Fixme */ - } - - - FT_LOCAL_DEF( bdf_property_t * ) - bdf_get_font_property( bdf_font_t* font, - const char* name ) - { - size_t* propid; - - - if ( font == 0 || font->props_size == 0 || name == 0 || *name == 0 ) - return 0; - - propid = ft_hash_str_lookup( name, (FT_Hash)font->internal ); - - return propid ? ( font->props + *propid ) : 0; - } - - -/* END */ diff --git a/ThirdParty/freetype/src/bdf/module.mk b/ThirdParty/freetype/src/bdf/module.mk deleted file mode 100644 index fe06ae8..0000000 --- a/ThirdParty/freetype/src/bdf/module.mk +++ /dev/null @@ -1,34 +0,0 @@ -# -# FreeType 2 BDF module definition -# - -# Copyright 2001, 2002, 2006 by -# Francesco Zappa Nardelli -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. - - -FTMODULE_H_COMMANDS += BDF_DRIVER - -define BDF_DRIVER -$(OPEN_DRIVER) FT_Driver_ClassRec, bdf_driver_class $(CLOSE_DRIVER) -$(ECHO_DRIVER)bdf $(ECHO_DRIVER_DESC)bdf bitmap fonts$(ECHO_DRIVER_DONE) -endef - -# EOF diff --git a/ThirdParty/freetype/src/bdf/rules.mk b/ThirdParty/freetype/src/bdf/rules.mk deleted file mode 100644 index d1dd76b..0000000 --- a/ThirdParty/freetype/src/bdf/rules.mk +++ /dev/null @@ -1,84 +0,0 @@ -# -# FreeType 2 bdf driver configuration rules -# - - -# Copyright (C) 2001, 2002, 2003, 2008 by -# Francesco Zappa Nardelli -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. - - - - -# bdf driver directory -# -BDF_DIR := $(SRC_DIR)/bdf - - -BDF_COMPILE := $(CC) $(ANSIFLAGS) \ - $I$(subst /,$(COMPILER_SEP),$(BDF_DIR)) \ - $(INCLUDE_FLAGS) \ - $(FT_CFLAGS) - - -# bdf driver sources (i.e., C files) -# -BDF_DRV_SRC := $(BDF_DIR)/bdflib.c \ - $(BDF_DIR)/bdfdrivr.c - - -# bdf driver headers -# -BDF_DRV_H := $(BDF_DIR)/bdf.h \ - $(BDF_DIR)/bdfdrivr.h \ - $(BDF_DIR)/bdferror.h - -# bdf driver object(s) -# -# BDF_DRV_OBJ_M is used during `multi' builds -# BDF_DRV_OBJ_S is used during `single' builds -# -BDF_DRV_OBJ_M := $(BDF_DRV_SRC:$(BDF_DIR)/%.c=$(OBJ_DIR)/%.$O) -BDF_DRV_OBJ_S := $(OBJ_DIR)/bdf.$O - -# bdf driver source file for single build -# -BDF_DRV_SRC_S := $(BDF_DIR)/bdf.c - - -# bdf driver - single object -# -$(BDF_DRV_OBJ_S): $(BDF_DRV_SRC_S) $(BDF_DRV_SRC) $(FREETYPE_H) $(BDF_DRV_H) - $(BDF_COMPILE) $T$(subst /,$(COMPILER_SEP),$@ $(BDF_DRV_SRC_S)) - - -# bdf driver - multiple objects -# -$(OBJ_DIR)/%.$O: $(BDF_DIR)/%.c $(FREETYPE_H) $(BDF_DRV_H) - $(BDF_COMPILE) $T$(subst /,$(COMPILER_SEP),$@ $<) - - -# update main driver object lists -# -DRV_OBJS_S += $(BDF_DRV_OBJ_S) -DRV_OBJS_M += $(BDF_DRV_OBJ_M) - - -# EOF |