bdf.h (7127B)
1 /* 2 * Copyright 2000 Computing Research Labs, New Mexico State University 3 * Copyright 2001-2004, 2011 Francesco Zappa Nardelli 4 * 5 * Permission is hereby granted, free of charge, to any person obtaining a 6 * copy of this software and associated documentation files (the "Software"), 7 * to deal in the Software without restriction, including without limitation 8 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9 * and/or sell copies of the Software, and to permit persons to whom the 10 * Software is furnished to do so, subject to the following conditions: 11 * 12 * The above copyright notice and this permission notice shall be included in 13 * all copies or substantial portions of the Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 * THE COMPUTING RESEARCH LAB OR NEW MEXICO STATE UNIVERSITY BE LIABLE FOR ANY 19 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT 20 * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR 21 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 */ 23 24 25 #ifndef BDF_H_ 26 #define BDF_H_ 27 28 29 /* 30 * Based on bdf.h,v 1.16 2000/03/16 20:08:51 mleisher 31 */ 32 33 #include <freetype/internal/ftobjs.h> 34 #include <freetype/internal/ftstream.h> 35 #include <freetype/internal/fthash.h> 36 37 38 FT_BEGIN_HEADER 39 40 41 /* Imported from bdfP.h */ 42 43 #define _bdf_glyph_modified( map, e ) \ 44 ( (map)[(e) >> 5] & ( 1UL << ( (e) & 31 ) ) ) 45 #define _bdf_set_glyph_modified( map, e ) \ 46 ( (map)[(e) >> 5] |= ( 1UL << ( (e) & 31 ) ) ) 47 #define _bdf_clear_glyph_modified( map, e ) \ 48 ( (map)[(e) >> 5] &= ~( 1UL << ( (e) & 31 ) ) ) 49 50 /* end of bdfP.h */ 51 52 53 /************************************************************************** 54 * 55 * BDF font options macros and types. 56 * 57 */ 58 59 60 #define BDF_CORRECT_METRICS 0x1000 /* Correct metrics when loading. */ 61 #define BDF_KEEP_COMMENTS 0x2000 /* Preserve the font comments. */ 62 #define BDF_KEEP_UNENCODED 0x4000 /* Keep the unencoded glyphs. */ 63 64 #define BDF_PROPORTIONAL 0x08 /* Font has proportional spacing. */ 65 #define BDF_MONOWIDTH 0x10 /* Font has mono width. */ 66 #define BDF_CHARCELL 0x20 /* Font has charcell spacing. */ 67 68 69 /************************************************************************** 70 * 71 * BDF font property macros and types. 72 * 73 */ 74 75 76 #define BDF_ATOM 1 77 #define BDF_INTEGER 2 78 #define BDF_CARDINAL 3 79 80 81 /* This structure represents a particular property of a font. */ 82 /* There are a set of defaults and each font has their own. */ 83 typedef struct bdf_property_t_ 84 { 85 const char* name; /* Name of the property. */ 86 int format; /* Format of the property. */ 87 int builtin; /* A builtin property. */ 88 union 89 { 90 char* atom; 91 long l; 92 unsigned long ul; 93 94 } value; /* Value of the property. */ 95 96 } bdf_property_t; 97 98 99 /************************************************************************** 100 * 101 * BDF font metric and glyph types. 102 * 103 */ 104 105 106 typedef struct bdf_bbx_t_ 107 { 108 unsigned short width; 109 unsigned short height; 110 111 short x_offset; 112 short y_offset; 113 114 short ascent; 115 short descent; 116 117 } bdf_bbx_t; 118 119 120 typedef struct bdf_glyph_t_ 121 { 122 char* name; /* Glyph name. */ 123 unsigned long encoding; /* Glyph encoding. */ 124 unsigned short swidth; /* Scalable width. */ 125 unsigned short dwidth; /* Device width. */ 126 bdf_bbx_t bbx; /* Glyph bounding box. */ 127 unsigned char* bitmap; /* Glyph bitmap. */ 128 unsigned long bpr; /* Number of bytes used per row. */ 129 unsigned short bytes; /* Number of bytes used for the bitmap. */ 130 131 } bdf_glyph_t; 132 133 134 typedef struct bdf_font_t_ 135 { 136 char* name; /* Name of the font. */ 137 bdf_bbx_t bbx; /* Font bounding box. */ 138 139 unsigned long point_size; /* Point size of the font. */ 140 unsigned long resolution_x; /* Font horizontal resolution. */ 141 unsigned long resolution_y; /* Font vertical resolution. */ 142 143 int spacing; /* Font spacing value. */ 144 unsigned long default_char; /* Encoding of the default glyph. */ 145 146 long font_ascent; /* Font ascent. */ 147 long font_descent; /* Font descent. */ 148 149 unsigned long glyphs_size; /* Glyph structures allocated. */ 150 unsigned long glyphs_used; /* Glyph structures used. */ 151 bdf_glyph_t* glyphs; /* Glyphs themselves. */ 152 153 unsigned long unencoded_size; /* Unencoded glyph struct. allocated. */ 154 unsigned long unencoded_used; /* Unencoded glyph struct. used. */ 155 bdf_glyph_t* unencoded; /* Unencoded glyphs themselves. */ 156 157 unsigned long props_size; /* Font properties allocated. */ 158 unsigned long props_used; /* Font properties used. */ 159 bdf_property_t* props; /* Font properties themselves. */ 160 161 char* comments; /* Font comments. */ 162 unsigned long comments_len; /* Length of comment string. */ 163 164 FT_Hash internal; /* Internal data for the font. */ 165 166 unsigned short bpp; /* Bits per pixel. */ 167 168 FT_Memory memory; 169 170 bdf_property_t* user_props; 171 unsigned long nuser_props; 172 FT_HashRec proptbl; 173 174 } bdf_font_t; 175 176 177 /************************************************************************** 178 * 179 * Types for load/save callbacks. 180 * 181 */ 182 183 184 /* Error codes. */ 185 #define BDF_MISSING_START -1 186 #define BDF_MISSING_FONTNAME -2 187 #define BDF_MISSING_SIZE -3 188 #define BDF_MISSING_CHARS -4 189 #define BDF_MISSING_STARTCHAR -5 190 #define BDF_MISSING_ENCODING -6 191 #define BDF_MISSING_BBX -7 192 193 #define BDF_OUT_OF_MEMORY -20 194 195 #define BDF_INVALID_LINE -100 196 197 198 /************************************************************************** 199 * 200 * BDF font API. 201 * 202 */ 203 204 FT_LOCAL( FT_Error ) 205 bdf_load_font( FT_Stream stream, 206 FT_Memory memory, 207 unsigned long flags, 208 bdf_font_t* *font ); 209 210 FT_LOCAL( void ) 211 bdf_free_font( bdf_font_t* font ); 212 213 FT_LOCAL( bdf_property_t * ) 214 bdf_get_font_property( bdf_font_t* font, 215 const char* name ); 216 217 218 FT_END_HEADER 219 220 221 #endif /* BDF_H_ */ 222 223 224 /* END */