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     unsigned 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_font_t_
162   {
163     char*            name;           /* Name of the font.                   */
164     bdf_bbx_t        bbx;            /* Font bounding box.                  */
165 
166     unsigned long    point_size;     /* Point size of the font.             */
167     unsigned long    resolution_x;   /* Font horizontal resolution.         */
168     unsigned long    resolution_y;   /* Font vertical resolution.           */
169 
170     int              spacing;        /* Font spacing value.                 */
171 
172     unsigned short   monowidth;      /* Logical width for monowidth font.   */
173 
174     unsigned long    default_char;   /* Encoding of the default glyph.      */
175 
176     long             font_ascent;    /* Font ascent.                        */
177     long             font_descent;   /* Font descent.                       */
178 
179     unsigned long    glyphs_size;    /* Glyph structures allocated.         */
180     unsigned long    glyphs_used;    /* Glyph structures used.              */
181     bdf_glyph_t*     glyphs;         /* Glyphs themselves.                  */
182 
183     unsigned long    unencoded_size; /* Unencoded glyph struct. allocated.  */
184     unsigned long    unencoded_used; /* Unencoded glyph struct. used.       */
185     bdf_glyph_t*     unencoded;      /* Unencoded glyphs themselves.        */
186 
187     unsigned long    props_size;     /* Font properties allocated.          */
188     unsigned long    props_used;     /* Font properties used.               */
189     bdf_property_t*  props;          /* Font properties themselves.         */
190 
191     char*            comments;       /* Font comments.                      */
192     unsigned long    comments_len;   /* Length of comment string.           */
193 
194     void*            internal;       /* Internal data for the font.         */
195 
196     unsigned short   bpp;            /* Bits per pixel.                     */
197 
198     FT_Memory        memory;
199 
200     bdf_property_t*  user_props;
201     unsigned long    nuser_props;
202     FT_HashRec       proptbl;
203 
204   } bdf_font_t;
205 
206 
207   /**************************************************************************
208    *
209    * Types for load/save callbacks.
210    *
211    */
212 
213 
214   /* Error codes. */
215 #define BDF_MISSING_START       -1
216 #define BDF_MISSING_FONTNAME    -2
217 #define BDF_MISSING_SIZE        -3
218 #define BDF_MISSING_CHARS       -4
219 #define BDF_MISSING_STARTCHAR   -5
220 #define BDF_MISSING_ENCODING    -6
221 #define BDF_MISSING_BBX         -7
222 
223 #define BDF_OUT_OF_MEMORY      -20
224 
225 #define BDF_INVALID_LINE      -100
226 
227 
228   /**************************************************************************
229    *
230    * BDF font API.
231    *
232    */
233 
234   FT_LOCAL( FT_Error )
235   bdf_load_font( FT_Stream       stream,
236                  FT_Memory       memory,
237                  bdf_options_t*  opts,
238                  bdf_font_t*    *font );
239 
240   FT_LOCAL( void )
241   bdf_free_font( bdf_font_t*  font );
242 
243   FT_LOCAL( bdf_property_t * )
244   bdf_get_property( char*        name,
245                     bdf_font_t*  font );
246 
247   FT_LOCAL( bdf_property_t * )
248   bdf_get_font_property( bdf_font_t*  font,
249                          const char*  name );
250 
251 
252 FT_END_HEADER
253 
254 
255 #endif /* BDF_H_ */
256 
257 
258 /* END */
259