bdf.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. /*
  2. * Copyright 2000 Computing Research Labs, New Mexico State University
  3. * Copyright 2001, 2002 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. #ifndef __BDF_H__
  24. #define __BDF_H__
  25. /*
  26. * Based on bdf.h,v 1.16 2000/03/16 20:08:51 mleisher
  27. */
  28. #include <ft2build.h>
  29. #include FT_INTERNAL_OBJECTS_H
  30. #include FT_INTERNAL_STREAM_H
  31. FT_BEGIN_HEADER
  32. /* Imported from bdfP.h */
  33. #define _bdf_glyph_modified( map, e ) \
  34. ( (map)[(e) >> 5] & ( 1 << ( (e) & 31 ) ) )
  35. #define _bdf_set_glyph_modified( map, e ) \
  36. ( (map)[(e) >> 5] |= ( 1 << ( (e) & 31 ) ) )
  37. #define _bdf_clear_glyph_modified( map, e ) \
  38. ( (map)[(e) >> 5] &= ~( 1 << ( (e) & 31 ) ) )
  39. /* end of bdfP.h */
  40. /*************************************************************************/
  41. /* */
  42. /* BDF font options macros and types. */
  43. /* */
  44. /*************************************************************************/
  45. #define BDF_CORRECT_METRICS 0x01 /* Correct invalid metrics when loading. */
  46. #define BDF_KEEP_COMMENTS 0x02 /* Preserve the font comments. */
  47. #define BDF_KEEP_UNENCODED 0x04 /* Keep the unencoded glyphs. */
  48. #define BDF_PROPORTIONAL 0x08 /* Font has proportional spacing. */
  49. #define BDF_MONOWIDTH 0x10 /* Font has mono width. */
  50. #define BDF_CHARCELL 0x20 /* Font has charcell spacing. */
  51. #define BDF_ALL_SPACING ( BDF_PROPORTIONAL | \
  52. BDF_MONOWIDTH | \
  53. BDF_CHARCELL )
  54. #define BDF_DEFAULT_LOAD_OPTIONS ( BDF_CORRECT_METRICS | \
  55. BDF_KEEP_COMMENTS | \
  56. BDF_KEEP_UNENCODED | \
  57. BDF_PROPORTIONAL )
  58. typedef struct bdf_options_t_
  59. {
  60. int correct_metrics;
  61. int keep_unencoded;
  62. int keep_comments;
  63. int font_spacing;
  64. } bdf_options_t;
  65. /* Callback function type for unknown configuration options. */
  66. typedef int
  67. (*bdf_options_callback_t)( bdf_options_t* opts,
  68. char** params,
  69. unsigned long nparams,
  70. void* client_data );
  71. /*************************************************************************/
  72. /* */
  73. /* BDF font property macros and types. */
  74. /* */
  75. /*************************************************************************/
  76. #define BDF_ATOM 1
  77. #define BDF_INTEGER 2
  78. #define BDF_CARDINAL 3
  79. /* This structure represents a particular property of a font. */
  80. /* There are a set of defaults and each font has their own. */
  81. typedef struct bdf_property_t_
  82. {
  83. char* name; /* Name of the property. */
  84. int format; /* Format of the property. */
  85. int builtin; /* A builtin property. */
  86. union
  87. {
  88. char* atom;
  89. long int32;
  90. unsigned long card32;
  91. } value; /* Value of the property. */
  92. } bdf_property_t;
  93. /*************************************************************************/
  94. /* */
  95. /* BDF font metric and glyph types. */
  96. /* */
  97. /*************************************************************************/
  98. typedef struct bdf_bbx_t_
  99. {
  100. unsigned short width;
  101. unsigned short height;
  102. short x_offset;
  103. short y_offset;
  104. short ascent;
  105. short descent;
  106. } bdf_bbx_t;
  107. typedef struct bdf_glyph_t_
  108. {
  109. char* name; /* Glyph name. */
  110. long encoding; /* Glyph encoding. */
  111. unsigned short swidth; /* Scalable width. */
  112. unsigned short dwidth; /* Device width. */
  113. bdf_bbx_t bbx; /* Glyph bounding box. */
  114. unsigned char* bitmap; /* Glyph bitmap. */
  115. unsigned long bpr; /* Number of bytes used per row. */
  116. unsigned short bytes; /* Number of bytes used for the bitmap. */
  117. } bdf_glyph_t;
  118. typedef struct _hashnode_
  119. {
  120. char* key;
  121. void* data;
  122. } _hashnode, *hashnode;
  123. typedef struct hashtable_
  124. {
  125. int limit;
  126. int size;
  127. int used;
  128. hashnode* table;
  129. } hashtable;
  130. typedef struct bdf_glyphlist_t_
  131. {
  132. unsigned short pad; /* Pad to 4-byte boundary. */
  133. unsigned short bpp; /* Bits per pixel. */
  134. long start; /* Beginning encoding value of glyphs. */
  135. long end; /* Ending encoding value of glyphs. */
  136. bdf_glyph_t* glyphs; /* Glyphs themselves. */
  137. unsigned long glyphs_size; /* Glyph structures allocated. */
  138. unsigned long glyphs_used; /* Glyph structures used. */
  139. bdf_bbx_t bbx; /* Overall bounding box of glyphs. */
  140. } bdf_glyphlist_t;
  141. typedef struct bdf_font_t_
  142. {
  143. char* name; /* Name of the font. */
  144. bdf_bbx_t bbx; /* Font bounding box. */
  145. long point_size; /* Point size of the font. */
  146. unsigned long resolution_x; /* Font horizontal resolution. */
  147. unsigned long resolution_y; /* Font vertical resolution. */
  148. int spacing; /* Font spacing value. */
  149. unsigned short monowidth; /* Logical width for monowidth font. */
  150. long default_glyph; /* Encoding of the default glyph. */
  151. long font_ascent; /* Font ascent. */
  152. long font_descent; /* Font descent. */
  153. unsigned long glyphs_size; /* Glyph structures allocated. */
  154. unsigned long glyphs_used; /* Glyph structures used. */
  155. bdf_glyph_t* glyphs; /* Glyphs themselves. */
  156. unsigned long unencoded_size; /* Unencoded glyph struct. allocated. */
  157. unsigned long unencoded_used; /* Unencoded glyph struct. used. */
  158. bdf_glyph_t* unencoded; /* Unencoded glyphs themselves. */
  159. unsigned long props_size; /* Font properties allocated. */
  160. unsigned long props_used; /* Font properties used. */
  161. bdf_property_t* props; /* Font properties themselves. */
  162. char* comments; /* Font comments. */
  163. unsigned long comments_len; /* Length of comment string. */
  164. bdf_glyphlist_t overflow; /* Storage used for glyph insertion. */
  165. void* internal; /* Internal data for the font. */
  166. unsigned long nmod[2048]; /* Bitmap indicating modified glyphs. */
  167. unsigned long umod[2048]; /* Bitmap indicating modified */
  168. /* unencoded glyphs. */
  169. unsigned short modified; /* Boolean indicating font modified. */
  170. unsigned short bpp; /* Bits per pixel. */
  171. FT_Memory memory;
  172. bdf_property_t* user_props;
  173. unsigned long nuser_props;
  174. hashtable proptbl;
  175. } bdf_font_t;
  176. /*************************************************************************/
  177. /* */
  178. /* Types for load/save callbacks. */
  179. /* */
  180. /*************************************************************************/
  181. /* Error codes. */
  182. #define BDF_MISSING_START -1
  183. #define BDF_MISSING_FONTNAME -2
  184. #define BDF_MISSING_SIZE -3
  185. #define BDF_MISSING_CHARS -4
  186. #define BDF_MISSING_STARTCHAR -5
  187. #define BDF_MISSING_ENCODING -6
  188. #define BDF_MISSING_BBX -7
  189. #define BDF_OUT_OF_MEMORY -20
  190. #define BDF_INVALID_LINE -100
  191. /*************************************************************************/
  192. /* */
  193. /* BDF font API. */
  194. /* */
  195. /*************************************************************************/
  196. FT_LOCAL( FT_Error )
  197. bdf_load_font( FT_Stream stream,
  198. FT_Memory memory,
  199. bdf_options_t* opts,
  200. bdf_font_t* *font );
  201. FT_LOCAL( void )
  202. bdf_free_font( bdf_font_t* font );
  203. FT_LOCAL( bdf_property_t * )
  204. bdf_get_property( char* name,
  205. bdf_font_t* font );
  206. FT_LOCAL( bdf_property_t * )
  207. bdf_get_font_property( bdf_font_t* font,
  208. char* name );
  209. FT_END_HEADER
  210. #endif /* __BDF_H__ */
  211. /* END */