1 /* pcf.h 2 3 FreeType font driver for pcf fonts 4 5 Copyright (C) 2000, 2001, 2002, 2003, 2006, 2010 by 6 Francesco Zappa Nardelli 7 8 Permission is hereby granted, free of charge, to any person obtaining a copy 9 of this software and associated documentation files (the "Software"), to deal 10 in the Software without restriction, including without limitation the rights 11 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 copies of the Software, and to permit persons to whom the Software is 13 furnished to do so, subject to the following conditions: 14 15 The above copyright notice and this permission notice shall be included in 16 all copies or substantial portions of the Software. 17 18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 THE SOFTWARE. 25 */ 26 27 28 #ifndef PCF_H_ 29 #define PCF_H_ 30 31 32 #include <ft2build.h> 33 #include FT_INTERNAL_DRIVER_H 34 #include FT_INTERNAL_STREAM_H 35 36 37 FT_BEGIN_HEADER 38 39 typedef struct PCF_TableRec_ 40 { 41 FT_ULong type; 42 FT_ULong format; 43 FT_ULong size; 44 FT_ULong offset; 45 46 } PCF_TableRec, *PCF_Table; 47 48 49 typedef struct PCF_TocRec_ 50 { 51 FT_ULong version; 52 FT_ULong count; 53 PCF_Table tables; 54 55 } PCF_TocRec, *PCF_Toc; 56 57 58 typedef struct PCF_ParsePropertyRec_ 59 { 60 FT_Long name; 61 FT_Byte isString; 62 FT_Long value; 63 64 } PCF_ParsePropertyRec, *PCF_ParseProperty; 65 66 67 typedef struct PCF_PropertyRec_ 68 { 69 FT_String* name; 70 FT_Byte isString; 71 72 union 73 { 74 FT_String* atom; 75 FT_Long l; 76 FT_ULong ul; 77 78 } value; 79 80 } PCF_PropertyRec, *PCF_Property; 81 82 83 typedef struct PCF_Compressed_MetricRec_ 84 { 85 FT_Byte leftSideBearing; 86 FT_Byte rightSideBearing; 87 FT_Byte characterWidth; 88 FT_Byte ascent; 89 FT_Byte descent; 90 91 } PCF_Compressed_MetricRec, *PCF_Compressed_Metric; 92 93 94 typedef struct PCF_MetricRec_ 95 { 96 FT_Short leftSideBearing; 97 FT_Short rightSideBearing; 98 FT_Short characterWidth; 99 FT_Short ascent; 100 FT_Short descent; 101 FT_Short attributes; 102 103 FT_ULong bits; /* offset into the PCF_BITMAPS table */ 104 105 } PCF_MetricRec, *PCF_Metric; 106 107 108 typedef struct PCF_EncRec_ 109 { 110 FT_UShort firstCol; 111 FT_UShort lastCol; 112 FT_UShort firstRow; 113 FT_UShort lastRow; 114 FT_UShort defaultChar; 115 116 FT_UShort* offset; 117 118 } PCF_EncRec, *PCF_Enc; 119 120 121 typedef struct PCF_AccelRec_ 122 { 123 FT_Byte noOverlap; 124 FT_Byte constantMetrics; 125 FT_Byte terminalFont; 126 FT_Byte constantWidth; 127 FT_Byte inkInside; 128 FT_Byte inkMetrics; 129 FT_Byte drawDirection; 130 FT_Long fontAscent; 131 FT_Long fontDescent; 132 FT_Long maxOverlap; 133 PCF_MetricRec minbounds; 134 PCF_MetricRec maxbounds; 135 PCF_MetricRec ink_minbounds; 136 PCF_MetricRec ink_maxbounds; 137 138 } PCF_AccelRec, *PCF_Accel; 139 140 141 /* 142 * This file uses X11 terminology for PCF data; an `encoding' in X11 speak 143 * is the same as a `character code' in FreeType speak. 144 */ 145 typedef struct PCF_FaceRec_ 146 { 147 FT_FaceRec root; 148 149 FT_StreamRec comp_stream; 150 FT_Stream comp_source; 151 152 char* charset_encoding; 153 char* charset_registry; 154 155 PCF_TocRec toc; 156 PCF_AccelRec accel; 157 158 int nprops; 159 PCF_Property properties; 160 161 FT_ULong nmetrics; 162 PCF_Metric metrics; 163 164 PCF_EncRec enc; 165 166 FT_ULong bitmapsFormat; 167 168 } PCF_FaceRec, *PCF_Face; 169 170 171 typedef struct PCF_DriverRec_ 172 { 173 FT_DriverRec root; 174 175 FT_Bool no_long_family_names; 176 177 } PCF_DriverRec, *PCF_Driver; 178 179 180 /* macros for pcf font format */ 181 182 #define LSBFirst 0 183 #define MSBFirst 1 184 185 #define PCF_FILE_VERSION ( ( 'p' << 24 ) | \ 186 ( 'c' << 16 ) | \ 187 ( 'f' << 8 ) | 1 ) 188 #define PCF_FORMAT_MASK 0xFFFFFF00UL 189 190 #define PCF_DEFAULT_FORMAT 0x00000000UL 191 #define PCF_INKBOUNDS 0x00000200UL 192 #define PCF_ACCEL_W_INKBOUNDS 0x00000100UL 193 #define PCF_COMPRESSED_METRICS 0x00000100UL 194 195 #define PCF_FORMAT_MATCH( a, b ) \ 196 ( ( (a) & PCF_FORMAT_MASK ) == ( (b) & PCF_FORMAT_MASK ) ) 197 198 #define PCF_GLYPH_PAD_MASK ( 3 << 0 ) 199 #define PCF_BYTE_MASK ( 1 << 2 ) 200 #define PCF_BIT_MASK ( 1 << 3 ) 201 #define PCF_SCAN_UNIT_MASK ( 3 << 4 ) 202 203 #define PCF_BYTE_ORDER( f ) \ 204 ( ( (f) & PCF_BYTE_MASK ) ? MSBFirst : LSBFirst ) 205 #define PCF_BIT_ORDER( f ) \ 206 ( ( (f) & PCF_BIT_MASK ) ? MSBFirst : LSBFirst ) 207 #define PCF_GLYPH_PAD_INDEX( f ) \ 208 ( (f) & PCF_GLYPH_PAD_MASK ) 209 #define PCF_GLYPH_PAD( f ) \ 210 ( 1 << PCF_GLYPH_PAD_INDEX( f ) ) 211 #define PCF_SCAN_UNIT_INDEX( f ) \ 212 ( ( (f) & PCF_SCAN_UNIT_MASK ) >> 4 ) 213 #define PCF_SCAN_UNIT( f ) \ 214 ( 1 << PCF_SCAN_UNIT_INDEX( f ) ) 215 #define PCF_FORMAT_BITS( f ) \ 216 ( (f) & ( PCF_GLYPH_PAD_MASK | \ 217 PCF_BYTE_MASK | \ 218 PCF_BIT_MASK | \ 219 PCF_SCAN_UNIT_MASK ) ) 220 221 #define PCF_SIZE_TO_INDEX( s ) ( (s) == 4 ? 2 : (s) == 2 ? 1 : 0 ) 222 #define PCF_INDEX_TO_SIZE( b ) ( 1 << b ) 223 224 #define PCF_FORMAT( bit, byte, glyph, scan ) \ 225 ( ( PCF_SIZE_TO_INDEX( scan ) << 4 ) | \ 226 ( ( (bit) == MSBFirst ? 1 : 0 ) << 3 ) | \ 227 ( ( (byte) == MSBFirst ? 1 : 0 ) << 2 ) | \ 228 ( PCF_SIZE_TO_INDEX( glyph ) << 0 ) ) 229 230 #define PCF_PROPERTIES ( 1 << 0 ) 231 #define PCF_ACCELERATORS ( 1 << 1 ) 232 #define PCF_METRICS ( 1 << 2 ) 233 #define PCF_BITMAPS ( 1 << 3 ) 234 #define PCF_INK_METRICS ( 1 << 4 ) 235 #define PCF_BDF_ENCODINGS ( 1 << 5 ) 236 #define PCF_SWIDTHS ( 1 << 6 ) 237 #define PCF_GLYPH_NAMES ( 1 << 7 ) 238 #define PCF_BDF_ACCELERATORS ( 1 << 8 ) 239 240 #define GLYPHPADOPTIONS 4 /* I'm not sure about this */ 241 242 FT_LOCAL( FT_Error ) 243 pcf_load_font( FT_Stream stream, 244 PCF_Face face, 245 FT_Long face_index ); 246 247 FT_END_HEADER 248 249 #endif /* PCF_H_ */ 250 251 252 /* END */ 253