gxfont.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  1. /* Copyright (C) 1989, 1995, 1996, 1997, 1999, 2000 Aladdin Enterprises. All rights reserved.
  2. This file is part of AFPL Ghostscript.
  3. AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND. No author or
  4. distributor accepts any responsibility for the consequences of using it, or
  5. for whether it serves any particular purpose or works at all, unless he or
  6. she says so in writing. Refer to the Aladdin Free Public License (the
  7. "License") for full details.
  8. Every copy of AFPL Ghostscript must include a copy of the License, normally
  9. in a plain ASCII text file named PUBLIC. The License grants you the right
  10. to copy, modify and redistribute AFPL Ghostscript, but only under certain
  11. conditions described in the License. Among other things, the License
  12. requires that the copyright notice and this notice be preserved on all
  13. copies.
  14. */
  15. /*$Id: gxfont.h,v 1.3 2000/11/23 23:23:40 lpd Exp $ */
  16. /* Font object structure */
  17. /* Requires gsmatrix.h, gxdevice.h */
  18. #ifndef gxfont_INCLUDED
  19. # define gxfont_INCLUDED
  20. #include "gsccode.h"
  21. #include "gsfont.h"
  22. #include "gsnotify.h"
  23. #include "gsuid.h"
  24. #include "gsstype.h" /* for extern_st */
  25. #include "gxftype.h"
  26. /* A font object as seen by clients. */
  27. /* See the PostScript Language Reference Manual for details. */
  28. #ifndef gs_text_enum_DEFINED
  29. # define gs_text_enum_DEFINED
  30. typedef struct gs_text_enum_s gs_text_enum_t;
  31. #endif
  32. #ifndef gx_path_DEFINED
  33. # define gx_path_DEFINED
  34. typedef struct gx_path_s gx_path;
  35. #endif
  36. /*
  37. * Define flags for font properties (Flags* members in the structure below.)
  38. * Currently these must match the ones defined for PDF.
  39. */
  40. #define FONT_IS_FIXED_WIDTH (1<<0)
  41. /*
  42. * Define the structure used to return information about the font as a
  43. * whole. Currently this structure almost exactly parallels the PDF
  44. * FontDescriptor.
  45. *
  46. * Unless otherwise specified, values are in the font's native character
  47. * space, scaled as requested by the call to the font_info procedure.
  48. * Note that Type 1 fonts typically have 1000 units per em, while
  49. * TrueType fonts typically have 1 unit per em.
  50. */
  51. typedef struct gs_font_info_s {
  52. int members;
  53. /* The following members exactly parallel the PDF FontDescriptor flags. */
  54. #define FONT_INFO_ASCENT 0x0001
  55. int Ascent;
  56. #define FONT_INFO_AVG_WIDTH 0x0002
  57. int AvgWidth;
  58. #define FONT_INFO_BBOX 0x0004
  59. gs_int_rect BBox; /* computed from outlines, not FontBBox */
  60. #define FONT_INFO_CAP_HEIGHT 0x0008
  61. int CapHeight;
  62. #define FONT_INFO_DESCENT 0x0010
  63. int Descent;
  64. #define FONT_INFO_FLAGS 0x0020
  65. uint Flags; /* a mask of FONT_IS_ bits */
  66. uint Flags_requested; /* client must set this if FLAGS requested */
  67. uint Flags_returned;
  68. #define FONT_INFO_ITALIC_ANGLE 0x0100
  69. float ItalicAngle; /* degrees CCW from vertical */
  70. #define FONT_INFO_LEADING 0x0200
  71. int Leading;
  72. #define FONT_INFO_MAX_WIDTH 0x0400
  73. int MaxWidth;
  74. #define FONT_INFO_MISSING_WIDTH 0x0800
  75. int MissingWidth;
  76. #define FONT_INFO_STEM_H 0x00010000
  77. int StemH;
  78. #define FONT_INFO_STEM_V 0x00020000
  79. int StemV;
  80. #define FONT_INFO_UNDERLINE_POSITION 0x00040000
  81. int UnderlinePosition;
  82. #define FONT_INFO_UNDERLINE_THICKNESS 0x00080000
  83. int UnderlineThickness;
  84. #define FONT_INFO_X_HEIGHT 0x00100000
  85. int XHeight;
  86. /* The following members do NOT appear in the PDF FontDescriptor. */
  87. #define FONT_INFO_COPYRIGHT 0x0040
  88. gs_const_string Copyright;
  89. #define FONT_INFO_NOTICE 0x0080
  90. gs_const_string Notice;
  91. #define FONT_INFO_FAMILY_NAME 0x1000
  92. gs_const_string FamilyName;
  93. #define FONT_INFO_FULL_NAME 0x2000
  94. gs_const_string FullName;
  95. } gs_font_info_t;
  96. /*
  97. * Define the structure used to return information about a glyph.
  98. */
  99. typedef struct gs_glyph_info_s {
  100. int members; /* mask of which members are valid */
  101. #define GLYPH_INFO_WIDTH0 1
  102. #define GLYPH_INFO_WIDTH GLYPH_INFO_WIDTH0
  103. #define GLYPH_INFO_WIDTH1 2 /* must be WIDTH0 << 1 */
  104. #define GLYPH_INFO_WIDTHS (GLYPH_INFO_WIDTH0 | GLYPH_INFO_WIDTH1)
  105. gs_point width[2]; /* width for WMode 0/1 */
  106. #define GLYPH_INFO_BBOX 4
  107. gs_rect bbox;
  108. #define GLYPH_INFO_NUM_PIECES 8
  109. int num_pieces; /* # of pieces if composite, 0 if not */
  110. #define GLYPH_INFO_PIECES 16
  111. gs_glyph *pieces; /* pieces are stored here: the caller must */
  112. /* preset pieces if INFO_PIECES is set. */
  113. } gs_glyph_info_t;
  114. /* Define the "object" procedures of fonts. */
  115. typedef struct gs_font_procs_s {
  116. /* ------ Font-level procedures ------ */
  117. /*
  118. * Define any special handling of gs_definefont.
  119. * We break this out so it can be different for composite fonts.
  120. */
  121. #define font_proc_define_font(proc)\
  122. int proc(P2(gs_font_dir *, gs_font *))
  123. font_proc_define_font((*define_font));
  124. /*
  125. * Define any special handling of gs_makefont.
  126. * We break this out so it can be different for composite fonts.
  127. */
  128. #define font_proc_make_font(proc)\
  129. int proc(P4(gs_font_dir *, const gs_font *, const gs_matrix *, gs_font **))
  130. font_proc_make_font((*make_font));
  131. /*
  132. * Get information about the font, as specified by the members mask.
  133. * Disregard the FontMatrix: scale the font as indicated by *pscale
  134. * (pscale=NULL means no scaling). Set info->members to the members
  135. * that are actually returned. Note that some member options require
  136. * the caller to preset some of the elements of info. Note also that
  137. * this procedure may return more information than was requested.
  138. */
  139. #define font_proc_font_info(proc)\
  140. int proc(P4(gs_font *font, const gs_point *pscale, int members,\
  141. gs_font_info_t *info))
  142. font_proc_font_info((*font_info));
  143. /*
  144. * Determine whether this font is the "same as" another font in the ways
  145. * specified by the mask. The returned value is a subset of the mask.
  146. * This procedure is allowed to be conservative (return false in cases
  147. * of uncertainty). Note that this procedure does not test the UniqueID
  148. * or FontMatrix.
  149. */
  150. #define FONT_SAME_OUTLINES 1
  151. #define FONT_SAME_METRICS 2
  152. #define FONT_SAME_ENCODING 4
  153. #define font_proc_same_font(proc)\
  154. int proc(P3(const gs_font *font, const gs_font *ofont, int mask))
  155. font_proc_same_font((*same_font));
  156. /* ------ Glyph-level procedures ------ */
  157. /* Map a character code to a glyph. Some PostScript fonts use both
  158. * names and indices to identify glyphs: for example, in PostScript Type
  159. * 42 fonts, the Encoding array maps character codes to glyph names, and
  160. * the CharStrings dictionary maps glyph names to glyph indices. In
  161. * such fonts, the glyph_space argument determines which type of glyph
  162. * is returned.
  163. */
  164. #define font_proc_encode_char(proc)\
  165. gs_glyph proc(P3(gs_font *, gs_char, gs_glyph_space_t))
  166. font_proc_encode_char((*encode_char));
  167. /*
  168. * Get the next glyph in an enumeration of all glyphs defined by the
  169. * font. index = 0 means return the first one; a returned index of 0
  170. * means the enumeration is finished. The glyphs are enumerated in
  171. * an unpredictable order.
  172. */
  173. #define font_proc_enumerate_glyph(proc)\
  174. int proc(P4(gs_font *font, int *pindex, gs_glyph_space_t glyph_space,\
  175. gs_glyph *pglyph))
  176. font_proc_enumerate_glyph((*enumerate_glyph));
  177. /*
  178. * Get information about a glyph, as specified by the members mask.
  179. * pmat = NULL means get the scalable values; non-NULL pmat means get
  180. * the scaled values. Set info->members to the members that are
  181. * actually returned. Return gs_error_undefined if the glyph doesn't
  182. * exist in the font; calling glyph_info with members = 0 is an
  183. * efficient way to find out whether a given glyph exists. Note that
  184. * some member options require the caller to preset some of the elements
  185. * of info. Note also that this procedure may return more information
  186. * than was requested.
  187. */
  188. #define font_proc_glyph_info(proc)\
  189. int proc(P5(gs_font *font, gs_glyph glyph, const gs_matrix *pmat,\
  190. int members, gs_glyph_info_t *info))
  191. font_proc_glyph_info((*glyph_info));
  192. /*
  193. * Append the outline for a glyph to a path, with the glyph origin
  194. * at the current point. pmat is as for glyph_width. The outline
  195. * does include a final moveto for the advance width.
  196. */
  197. #define font_proc_glyph_outline(proc)\
  198. int proc(P4(gs_font *font, gs_glyph glyph, const gs_matrix *pmat,\
  199. gx_path *ppath))
  200. font_proc_glyph_outline((*glyph_outline));
  201. /* ------ Glyph rendering procedures ------ */
  202. /*
  203. * Define any needed procedure for initializing the composite
  204. * font stack in a show enumerator. This is a no-op for
  205. * all but composite fonts.
  206. */
  207. #define font_proc_init_fstack(proc)\
  208. int proc(P2(gs_text_enum_t *, gs_font *))
  209. font_proc_init_fstack((*init_fstack));
  210. /*
  211. * Define the font's algorithm for getting the next character or glyph
  212. * from a string being shown. This is trivial, except for composite
  213. * fonts. Returns 0 if the current (base) font didn't change, 1 if it
  214. * did change, 2 if there are no more characters, or an error code.
  215. *
  216. * This procedure may set either *pchar to gs_no_char or *pglyph to
  217. * gs_no_glyph, but not both.
  218. */
  219. #define font_proc_next_char_glyph(proc)\
  220. int proc(P3(gs_text_enum_t *pte, gs_char *pchar, gs_glyph *pglyph))
  221. font_proc_next_char_glyph((*next_char_glyph));
  222. /*
  223. * Define a client-supplied BuildChar/BuildGlyph procedure.
  224. * The gs_char may be gs_no_char (for BuildGlyph), or the gs_glyph
  225. * may be gs_no_glyph (for BuildChar), but not both. Return 0 for
  226. * success, 1 if the procedure was unable to render the character
  227. * (but no error occurred), <0 for error.
  228. */
  229. #define font_proc_build_char(proc)\
  230. int proc(P5(gs_text_enum_t *, gs_state *, gs_font *, gs_char, gs_glyph))
  231. font_proc_build_char((*build_char));
  232. /* Callback procedures for external font rasterizers */
  233. /* (see gsccode.h for details.) */
  234. gx_xfont_callbacks callbacks;
  235. } gs_font_procs;
  236. /* Default font-level font procedures in gsfont.c */
  237. font_proc_define_font(gs_no_define_font);
  238. font_proc_make_font(gs_no_make_font);
  239. font_proc_make_font(gs_base_make_font);
  240. font_proc_font_info(gs_default_font_info);
  241. font_proc_same_font(gs_default_same_font);
  242. font_proc_same_font(gs_base_same_font);
  243. /* Default glyph-level font procedures in gsfont.c */
  244. font_proc_encode_char(gs_no_encode_char);
  245. font_proc_enumerate_glyph(gs_no_enumerate_glyph);
  246. font_proc_glyph_info(gs_default_glyph_info);
  247. font_proc_glyph_outline(gs_no_glyph_outline);
  248. /* Default glyph rendering procedures in gstext.c */
  249. font_proc_init_fstack(gs_default_init_fstack);
  250. font_proc_next_char_glyph(gs_default_next_char_glyph);
  251. font_proc_build_char(gs_no_build_char);
  252. /* Default procedure vector in gsfont.c */
  253. extern const gs_font_procs gs_font_procs_default;
  254. /* The font names are only needed for xfont lookup and high-level output. */
  255. typedef struct gs_font_name_s {
  256. #define gs_font_name_max 47 /* must be >= 40 */
  257. /* The +1 is so we can null-terminate for debugging printout. */
  258. byte chars[gs_font_name_max + 1];
  259. uint size;
  260. } gs_font_name;
  261. /*
  262. * Define a generic font. We include PaintType and StrokeWidth here because
  263. * they affect rendering algorithms outside the Type 1 font machinery.
  264. *
  265. * ****** NOTE: If you define any subclasses of gs_font, you *must* define
  266. * ****** the finalization procedure as gs_font_finalize. Finalization
  267. * ****** procedures are not automatically inherited.
  268. */
  269. #define gs_font_common\
  270. gs_font *next, *prev; /* chain for original font list or */\
  271. /* scaled font cache */\
  272. gs_memory_t *memory; /* allocator for this font */\
  273. gs_font_dir *dir; /* directory where registered */\
  274. bool is_resource;\
  275. gs_notify_list_t notify_list; /* clients to notify when freeing */\
  276. gs_id id; /* internal ID (no relation to UID) */\
  277. gs_font *base; /* original (unscaled) base font */\
  278. void *client_data; /* additional client data */\
  279. gs_matrix FontMatrix;\
  280. font_type FontType;\
  281. bool BitmapWidths;\
  282. fbit_type ExactSize, InBetweenSize, TransformedChar;\
  283. int WMode; /* 0 or 1 */\
  284. int PaintType; /* PaintType for Type 1/4/42 fonts, */\
  285. /* 0 for others */\
  286. float StrokeWidth; /* StrokeWidth for Type 1/4/42 */\
  287. /* fonts (if present), 0 for others */\
  288. gs_font_procs procs;\
  289. /* We store both the FontDirectory key (key_name) and, */\
  290. /* if present, the FontName (font_name). */\
  291. gs_font_name key_name, font_name
  292. /*typedef struct gs_font_s gs_font; *//* in gsfont.h and other places */
  293. struct gs_font_s {
  294. gs_font_common;
  295. };
  296. extern_st(st_gs_font); /* (abstract) */
  297. struct_proc_finalize(gs_font_finalize); /* public for concrete subclasses */
  298. #define public_st_gs_font() /* in gsfont.c */\
  299. gs_public_st_complex_only(st_gs_font, gs_font, "gs_font",\
  300. 0, font_enum_ptrs, font_reloc_ptrs, gs_font_finalize)
  301. #define st_gs_font_max_ptrs (st_gs_notify_list_max_ptrs + 5)
  302. #define private_st_gs_font_ptr() /* in gsfont.c */\
  303. gs_private_st_ptr(st_gs_font_ptr, gs_font *, "gs_font *",\
  304. font_ptr_enum_ptrs, font_ptr_reloc_ptrs)
  305. #define st_gs_font_ptr_max_ptrs 1
  306. extern_st(st_gs_font_ptr_element);
  307. #define public_st_gs_font_ptr_element() /* in gsfont.c */\
  308. gs_public_st_element(st_gs_font_ptr_element, gs_font *, "gs_font *[]",\
  309. font_ptr_element_enum_ptrs, font_ptr_element_reloc_ptrs, st_gs_font_ptr)
  310. /* Allocate and minimally initialize a font. */
  311. /* Does not set: FontMatrix, FontType, key_name, font_name. */
  312. gs_font *
  313. gs_font_alloc(P5(gs_memory_t *mem, gs_memory_type_ptr_t pstype,
  314. const gs_font_procs *procs, gs_font_dir *dir,
  315. client_name_t cname));
  316. /*
  317. * Register/unregister a client for notification by a font. Currently
  318. * the clients are only notified when a font is freed. Note that any
  319. * such client must unregister itself when *it* is freed.
  320. */
  321. int gs_font_notify_register(P3(gs_font *font, gs_notify_proc_t proc,
  322. void *proc_data));
  323. int gs_font_notify_unregister(P3(gs_font *font, gs_notify_proc_t proc,
  324. void *proc_data));
  325. /* Define a base (not composite) font. */
  326. #define gs_font_base_common\
  327. gs_font_common;\
  328. gs_rect FontBBox;\
  329. gs_uid UID;\
  330. gs_encoding_index_t encoding_index;\
  331. gs_encoding_index_t nearest_encoding_index /* (may be >= 0 even if */\
  332. /* encoding_index = -1) */
  333. #ifndef gs_font_base_DEFINED
  334. # define gs_font_base_DEFINED
  335. typedef struct gs_font_base_s gs_font_base;
  336. #endif
  337. struct gs_font_base_s {
  338. gs_font_base_common;
  339. };
  340. extern_st(st_gs_font_base);
  341. #define public_st_gs_font_base() /* in gsfont.c */\
  342. gs_public_st_suffix_add1_final(st_gs_font_base, gs_font_base,\
  343. "gs_font_base", font_base_enum_ptrs, font_base_reloc_ptrs,\
  344. gs_font_finalize, st_gs_font, UID.xvalues)
  345. #define st_gs_font_base_max_ptrs (st_gs_font_max_ptrs + 1)
  346. /* Allocate and minimally initialize a base font. */
  347. /* Does not set: same elements as gs_alloc_font. */
  348. gs_font_base *
  349. gs_font_base_alloc(P5(gs_memory_t *mem, gs_memory_type_ptr_t pstype,
  350. const gs_font_procs *procs, gs_font_dir *dir,
  351. client_name_t cname));
  352. /*
  353. * Test whether a glyph is the notdef glyph for a base font.
  354. * The test is somewhat adhoc: perhaps this should be a virtual procedure.
  355. */
  356. bool gs_font_glyph_is_notdef(P2(gs_font_base *bfont, gs_glyph glyph));
  357. #endif /* gxfont_INCLUDED */