• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <ft2build.h>
34 #include FT_INTERNAL_OBJECTS_H
35 #include FT_INTERNAL_STREAM_H
36 #include FT_INTERNAL_HASH_H
37 
38 
39 FT_BEGIN_HEADER
40 
41 
42 /* Imported from bdfP.h */
43 
44 #define _bdf_glyph_modified( map, e )                     \
45           ( (map)[(e) >> 5] & ( 1UL << ( (e) & 31 ) ) )
46 #define _bdf_set_glyph_modified( map, e )                 \
47           ( (map)[(e) >> 5] |= ( 1UL << ( (e) & 31 ) ) )
48 #define _bdf_clear_glyph_modified( map, e )               \
49           ( (map)[(e) >> 5] &= ~( 1UL << ( (e) & 31 ) ) )
50 
51 /* end of bdfP.h */
52 
53 
54   /**************************************************************************
55    *
56    * BDF font options macros and types.
57    *
58    */
59 
60 
61 #define BDF_CORRECT_METRICS  0x01 /* Correct invalid metrics when loading. */
62 #define BDF_KEEP_COMMENTS    0x02 /* Preserve the font comments.           */
63 #define BDF_KEEP_UNENCODED   0x04 /* Keep the unencoded glyphs.            */
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 #define BDF_ALL_SPACING  ( BDF_PROPORTIONAL | \
69                            BDF_MONOWIDTH    | \
70                            BDF_CHARCELL     )
71 
72 #define BDF_DEFAULT_LOAD_OPTIONS  ( BDF_CORRECT_METRICS | \
73                                     BDF_KEEP_COMMENTS   | \
74                                     BDF_KEEP_UNENCODED  | \
75                                     BDF_PROPORTIONAL    )
76 
77 
78   typedef struct  bdf_options_t_
79   {
80     int            correct_metrics;
81     int            keep_unencoded;
82     int            keep_comments;
83     int            font_spacing;
84 
85   } bdf_options_t;
86 
87 
88   /* Callback function type for unknown configuration options. */
89   typedef int
90   (*bdf_options_callback_t)( bdf_options_t*  opts,
91                              char**          params,
92                              unsigned long   nparams,
93                              void*           client_data );
94 
95 
96   /**************************************************************************
97    *
98    * BDF font property macros and types.
99    *
100    */
101 
102 
103 #define BDF_ATOM      1
104 #define BDF_INTEGER   2
105 #define BDF_CARDINAL  3
106 
107 
108   /* This structure represents a particular property of a font. */
109   /* There are a set of defaults and each font has their own.   */
110   typedef struct  bdf_property_t_
111   {
112     char*  name;         /* Name of the property.   */
113     int    format;       /* Format of the property. */
114     int    builtin;      /* A builtin property.     */
115     union
116     {
117       char*          atom;
118       long           l;
119       unsigned long  ul;
120 
121     } value;             /* Value of the property.  */
122 
123   } bdf_property_t;
124 
125 
126   /**************************************************************************
127    *
128    * BDF font metric and glyph types.
129    *
130    */
131 
132 
133   typedef struct  bdf_bbx_t_
134   {
135     unsigned short  width;
136     unsigned short  height;
137 
138     short           x_offset;
139     short           y_offset;
140 
141     short           ascent;
142     short           descent;
143 
144   } bdf_bbx_t;
145 
146 
147   typedef struct  bdf_glyph_t_
148   {
149     char*           name;        /* Glyph name.                          */
150     long            encoding;    /* Glyph encoding.                      */
151     unsigned short  swidth;      /* Scalable width.                      */
152     unsigned short  dwidth;      /* Device width.                        */
153     bdf_bbx_t       bbx;         /* Glyph bounding box.                  */
154     unsigned char*  bitmap;      /* Glyph bitmap.                        */
155     unsigned long   bpr;         /* Number of bytes used per row.        */
156     unsigned short  bytes;       /* Number of bytes used for the bitmap. */
157 
158   } bdf_glyph_t;
159 
160 
161   typedef struct  bdf_glyphlist_t_
162   {
163     unsigned short  pad;          /* Pad to 4-byte boundary.              */
164     unsigned short  bpp;          /* Bits per pixel.                      */
165     long            start;        /* Beginning encoding value of glyphs.  */
166     long            end;          /* Ending encoding value of glyphs.     */
167     bdf_glyph_t*    glyphs;       /* Glyphs themselves.                   */
168     unsigned long   glyphs_size;  /* Glyph structures allocated.          */
169     unsigned long   glyphs_used;  /* Glyph structures used.               */
170     bdf_bbx_t       bbx;          /* Overall bounding box of glyphs.      */
171 
172   } bdf_glyphlist_t;
173 
174 
175   typedef struct  bdf_font_t_
176   {
177     char*            name;           /* Name of the font.                   */
178     bdf_bbx_t        bbx;            /* Font bounding box.                  */
179 
180     unsigned long    point_size;     /* Point size of the font.             */
181     unsigned long    resolution_x;   /* Font horizontal resolution.         */
182     unsigned long    resolution_y;   /* Font vertical resolution.           */
183 
184     int              spacing;        /* Font spacing value.                 */
185 
186     unsigned short   monowidth;      /* Logical width for monowidth font.   */
187 
188     long             default_char;   /* Encoding of the default glyph.      */
189 
190     long             font_ascent;    /* Font ascent.                        */
191     long             font_descent;   /* Font descent.                       */
192 
193     unsigned long    glyphs_size;    /* Glyph structures allocated.         */
194     unsigned long    glyphs_used;    /* Glyph structures used.              */
195     bdf_glyph_t*     glyphs;         /* Glyphs themselves.                  */
196 
197     unsigned long    unencoded_size; /* Unencoded glyph struct. allocated.  */
198     unsigned long    unencoded_used; /* Unencoded glyph struct. used.       */
199     bdf_glyph_t*     unencoded;      /* Unencoded glyphs themselves.        */
200 
201     unsigned long    props_size;     /* Font properties allocated.          */
202     unsigned long    props_used;     /* Font properties used.               */
203     bdf_property_t*  props;          /* Font properties themselves.         */
204 
205     char*            comments;       /* Font comments.                      */
206     unsigned long    comments_len;   /* Length of comment string.           */
207 
208     bdf_glyphlist_t  overflow;       /* Storage used for glyph insertion.   */
209 
210     void*            internal;       /* Internal data for the font.         */
211 
212     /* The size of the next two arrays must be in sync with the */
213     /* size of the `have' array in the `bdf_parse_t' structure. */
214     unsigned long    nmod[34816];    /* Bitmap indicating modified glyphs.  */
215     unsigned long    umod[34816];    /* Bitmap indicating modified          */
216                                      /* unencoded glyphs.                   */
217     unsigned short   modified;       /* Boolean indicating font modified.   */
218     unsigned short   bpp;            /* Bits per pixel.                     */
219 
220     FT_Memory        memory;
221 
222     bdf_property_t*  user_props;
223     unsigned long    nuser_props;
224     FT_HashRec       proptbl;
225 
226   } bdf_font_t;
227 
228 
229   /**************************************************************************
230    *
231    * Types for load/save callbacks.
232    *
233    */
234 
235 
236   /* Error codes. */
237 #define BDF_MISSING_START       -1
238 #define BDF_MISSING_FONTNAME    -2
239 #define BDF_MISSING_SIZE        -3
240 #define BDF_MISSING_CHARS       -4
241 #define BDF_MISSING_STARTCHAR   -5
242 #define BDF_MISSING_ENCODING    -6
243 #define BDF_MISSING_BBX         -7
244 
245 #define BDF_OUT_OF_MEMORY      -20
246 
247 #define BDF_INVALID_LINE      -100
248 
249 
250   /**************************************************************************
251    *
252    * BDF font API.
253    *
254    */
255 
256   FT_LOCAL( FT_Error )
257   bdf_load_font( FT_Stream       stream,
258                  FT_Memory       memory,
259                  bdf_options_t*  opts,
260                  bdf_font_t*    *font );
261 
262   FT_LOCAL( void )
263   bdf_free_font( bdf_font_t*  font );
264 
265   FT_LOCAL( bdf_property_t * )
266   bdf_get_property( char*        name,
267                     bdf_font_t*  font );
268 
269   FT_LOCAL( bdf_property_t * )
270   bdf_get_font_property( bdf_font_t*  font,
271                          const char*  name );
272 
273 
274 FT_END_HEADER
275 
276 
277 #endif /* BDF_H_ */
278 
279 
280 /* END */
281