gdevpsf.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. /* Copyright (C) 2000, 2001 Aladdin Enterprises. All rights reserved.
  2. This software is provided AS-IS with no warranty, either express or
  3. implied.
  4. This software is distributed under license and may not be copied,
  5. modified or distributed except as expressly authorized under the terms
  6. of the license contained in the file LICENSE in this distribution.
  7. For more information about licensing, please refer to
  8. http://www.ghostscript.com/licensing/. For information on
  9. commercial licensing, go to http://www.artifex.com/licensing/ or
  10. contact Artifex Software, Inc., 101 Lucas Valley Road #110,
  11. San Rafael, CA 94903, U.S.A., +1(415)492-9861.
  12. */
  13. /* $Id: gdevpsf.h,v 1.27 2004/08/19 19:33:09 stefan Exp $ */
  14. /* PostScript/PDF font writing interface */
  15. #ifndef gdevpsf_INCLUDED
  16. # define gdevpsf_INCLUDED
  17. #include "gsccode.h"
  18. #include "gsgdata.h"
  19. /* ---------------- Embedded font writing ---------------- */
  20. #ifndef gs_font_DEFINED
  21. # define gs_font_DEFINED
  22. typedef struct gs_font_s gs_font;
  23. #endif
  24. #ifndef gs_font_base_DEFINED
  25. # define gs_font_base_DEFINED
  26. typedef struct gs_font_base_s gs_font_base;
  27. #endif
  28. #ifndef stream_DEFINED
  29. # define stream_DEFINED
  30. typedef struct stream_s stream;
  31. #endif
  32. /*
  33. * Define the structure used for enumerating the glyphs in a font or a
  34. * font subset. This type is opaque to clients: we declare it here only
  35. * so that clients can allocate it on the stack.
  36. */
  37. typedef struct psf_glyph_enum_s psf_glyph_enum_t;
  38. struct psf_glyph_enum_s {
  39. gs_font *font;
  40. struct su_ {
  41. union sus_ {
  42. const gs_glyph *list; /* if subset given by a list */
  43. const byte *bits; /* if CID or TT subset given by a bitmap */
  44. } selected;
  45. uint size;
  46. } subset;
  47. gs_glyph_space_t glyph_space;
  48. ulong index;
  49. int (*enumerate_next)(psf_glyph_enum_t *, gs_glyph *);
  50. };
  51. /*
  52. * Begin enumerating the glyphs in a font or a font subset. If subset_size
  53. * > 0 but subset_glyphs == 0, enumerate all glyphs in [0 .. subset_size-1]
  54. * (as integer glyphs, i.e., offset by gs_min_cid_glyph).
  55. */
  56. void psf_enumerate_list_begin(psf_glyph_enum_t *ppge, gs_font *font,
  57. const gs_glyph *subset_list,
  58. uint subset_size,
  59. gs_glyph_space_t glyph_space);
  60. /* Backward compatibility */
  61. #define psf_enumerate_glyphs_begin psf_enumerate_list_begin
  62. /* Begin enumerating CID or TT glyphs in a subset given by a bit vector. */
  63. /* Note that subset_size is given in bits, not in bytes. */
  64. void psf_enumerate_bits_begin(psf_glyph_enum_t *ppge, gs_font *font,
  65. const byte *subset_bits, uint subset_size,
  66. gs_glyph_space_t glyph_space);
  67. /* Backward compatibility */
  68. #define psf_enumerate_cids_begin(ppge, font, bits, size)\
  69. psf_enumerate_bits_begin(ppge, font, bits, size, GLYPH_SPACE_NAME)
  70. /*
  71. * Reset a glyph enumeration.
  72. */
  73. void psf_enumerate_glyphs_reset(psf_glyph_enum_t *ppge);
  74. /*
  75. * Enumerate the next glyph in a font or a font subset.
  76. * Return 0 if more glyphs, 1 if done, <0 if error.
  77. */
  78. int psf_enumerate_glyphs_next(psf_glyph_enum_t *ppge, gs_glyph *pglyph);
  79. /*
  80. * Add composite glyph pieces to a list of glyphs. Does not sort or
  81. * remove duplicates. max_pieces is the maximum number of pieces that a
  82. * single glyph can have: if this value is not known, the caller should
  83. * use max_count.
  84. */
  85. int psf_add_subset_pieces(gs_glyph *glyphs, uint *pcount, uint max_count,
  86. uint max_pieces, gs_font *font);
  87. /*
  88. * Sort a list of glyphs and remove duplicates. Return the number of glyphs
  89. * in the result.
  90. */
  91. int psf_sort_glyphs(gs_glyph *glyphs, int count);
  92. /*
  93. * Return the index of a given glyph in a sorted list of glyphs, or -1
  94. * if the glyph is not present.
  95. */
  96. int psf_sorted_glyphs_index_of(const gs_glyph *glyphs, int count,
  97. gs_glyph glyph);
  98. /*
  99. * Determine whether a sorted list of glyphs includes a given glyph.
  100. */
  101. bool psf_sorted_glyphs_include(const gs_glyph *glyphs, int count,
  102. gs_glyph glyph);
  103. /*
  104. * Define the internal structure that holds glyph information for an
  105. * outline-based font to be written. Currently this only applies to
  106. * Type 1, Type 2, and CIDFontType 0 fonts, but someday it might also
  107. * be usable with TrueType (Type 42) and CIDFontType 2 fonts.
  108. */
  109. #define MAX_CFF_MISC_STRINGS 40
  110. #define MAX_CFF_STD_STRINGS 500 /* 391 entries used */
  111. typedef struct psf_outline_glyphs_s {
  112. gs_glyph notdef;
  113. /* gs_glyph subset_data[256 * 3 + 1]; *3 for seac, +1 for .notdef */
  114. gs_glyph *subset_data;
  115. gs_glyph *subset_glyphs; /* 0 or subset_data */
  116. uint subset_size;
  117. } psf_outline_glyphs_t;
  118. #ifndef gs_font_type1_DEFINED
  119. # define gs_font_type1_DEFINED
  120. typedef struct gs_font_type1_s gs_font_type1;
  121. #endif
  122. /* Define the type for the glyph data callback procedure. */
  123. typedef int (*glyph_data_proc_t)(gs_font_base *, gs_glyph,
  124. gs_glyph_data_t *, gs_font_type1 **);
  125. /* Check that all selected glyphs can be written. */
  126. int psf_check_outline_glyphs(gs_font_base *pfont,
  127. psf_glyph_enum_t *ppge,
  128. glyph_data_proc_t glyph_data);
  129. /*
  130. * Gather glyph information for a Type 1, Type 2, or CIDFontType 0 font.
  131. * Note that the glyph_data procedure returns both the outline string and
  132. * a gs_font_type1 (Type 1 or Type 2) font: for Type 1 or Type 2 fonts,
  133. * this is the original font, but for CIDFontType 0 fonts, it is the
  134. * FDArray element. If subset_glyphs != 0, this procedure removes
  135. * undefined glyphs from the list it builds.
  136. */
  137. int psf_get_outline_glyphs(psf_outline_glyphs_t *pglyphs,
  138. gs_font_base *pfont, gs_glyph *subset_glyphs,
  139. uint subset_size, glyph_data_proc_t glyph_data);
  140. /* ------ Exported by gdevpsf1.c ------ */
  141. /* Gather glyph information for a Type 1 or Type 2 font. */
  142. int psf_type1_glyph_data(gs_font_base *, gs_glyph, gs_glyph_data_t *,
  143. gs_font_type1 **);
  144. int psf_get_type1_glyphs(psf_outline_glyphs_t *pglyphs,
  145. gs_font_type1 *pfont,
  146. gs_glyph *subset_glyphs, uint subset_size);
  147. /*
  148. * Write a Type 1 font definition. This procedure does not allocate
  149. * or free any data.
  150. */
  151. #define WRITE_TYPE1_EEXEC 1
  152. #define WRITE_TYPE1_ASCIIHEX 2 /* use ASCII hex rather than binary */
  153. #define WRITE_TYPE1_EEXEC_PAD 4 /* add 512 0s */
  154. #define WRITE_TYPE1_EEXEC_MARK 8 /* assume 512 0s will be added */
  155. #define WRITE_TYPE1_POSTSCRIPT 16 /* don't observe ATM restrictions */
  156. #define WRITE_TYPE1_WITH_LENIV 32 /* don't allow lenIV = -1 */
  157. int psf_write_type1_font(stream *s, gs_font_type1 *pfont, int options,
  158. gs_glyph *subset_glyphs, uint subset_size,
  159. const gs_const_string *alt_font_name,
  160. int lengths[3]);
  161. /* ------ Exported by gdevpsf2.c ------ */
  162. /*
  163. * Write a Type 1 or Type 2 font definition as CFF.
  164. * This procedure does not allocate or free any data.
  165. */
  166. #define WRITE_TYPE2_NO_LENIV 1 /* always use lenIV = -1 */
  167. #define WRITE_TYPE2_CHARSTRINGS 2 /* convert T1 charstrings to T2 */
  168. #define WRITE_TYPE2_AR3 4 /* work around bugs in Acrobat Reader 3 */
  169. #define WRITE_TYPE2_NO_GSUBRS 8 /* omit GlobalSubrs */
  170. int psf_write_type2_font(stream *s, gs_font_type1 *pfont, int options,
  171. gs_glyph *subset_glyphs, uint subset_size,
  172. const gs_const_string *alt_font_name,
  173. gs_int_rect *FontBBox);
  174. #ifndef gs_font_cid0_DEFINED
  175. # define gs_font_cid0_DEFINED
  176. typedef struct gs_font_cid0_s gs_font_cid0;
  177. #endif
  178. /*
  179. * Write a CIDFontType 0 font definition as CFF. The options are
  180. * the same as for psf_write_type2_font. subset_cids is a bit vector of
  181. * subset_size bits (not bytes).
  182. * This procedure does not allocate or free any data.
  183. */
  184. int psf_write_cid0_font(stream *s, gs_font_cid0 *pfont, int options,
  185. const byte *subset_cids, uint subset_size,
  186. const gs_const_string *alt_font_name);
  187. /* ------ Exported by gdevpsfm.c ------ */
  188. /*
  189. * Write a CMap in its customary (source) form.
  190. * This procedure does not allocate or free any data.
  191. */
  192. #ifndef gs_cmap_DEFINED
  193. # define gs_cmap_DEFINED
  194. typedef struct gs_cmap_s gs_cmap_t;
  195. #endif
  196. typedef int (*psf_put_name_chars_proc_t)(stream *, const byte *, uint);
  197. int psf_write_cmap(const gs_memory_t *mem, stream *s, const gs_cmap_t *pcmap,
  198. psf_put_name_chars_proc_t put_name_chars,
  199. const gs_const_string *alt_cmap_name, int font_index_only);
  200. /* ------ Exported by gdevpsft.c ------ */
  201. /*
  202. * Write a TrueType (Type 42) font definition.
  203. * This procedure does not allocate or free any data.
  204. */
  205. #ifndef gs_font_type42_DEFINED
  206. # define gs_font_type42_DEFINED
  207. typedef struct gs_font_type42_s gs_font_type42;
  208. #endif
  209. #define WRITE_TRUETYPE_CMAP 1 /* generate cmap from the Encoding */
  210. #define WRITE_TRUETYPE_NAME 2 /* generate name if missing */
  211. #define WRITE_TRUETYPE_POST 4 /* generate post if missing */
  212. #define WRITE_TRUETYPE_NO_TRIMMED_TABLE 8 /* not OK to use cmap format 6 */
  213. #define WRITE_TRUETYPE_HVMTX 16 /* generate [hv]mtx from glyph_info */
  214. int psf_write_truetype_font(stream *s, gs_font_type42 *pfont, int options,
  215. gs_glyph *subset_glyphs, uint subset_size,
  216. const gs_const_string *alt_font_name);
  217. /*
  218. * Write a "stripped" TrueType font definition. All tables are written
  219. * verbatim, except for deleting the bogus Adobe marker "tables" gdir, glyx,
  220. * and locx, and also deleting glyf and loca.
  221. * This procedure does not allocate or free any data.
  222. *
  223. * The purpose of "stripped" fonts is simply to store all of the non-glyph
  224. * information from a TrueType-family font in a structure that can be easily
  225. * stored, accessed, and eventually combined with the glyph information.
  226. * The only intended client for this function is the font copying code in
  227. * gxfcopy.c, q.v. In particular, "stripped" fonts are not fully valid
  228. * fonts because they lack glyph 0 (the .notdef glyph).
  229. */
  230. int psf_write_truetype_stripped(stream *s, gs_font_type42 *pfont);
  231. #ifndef gs_font_cid2_DEFINED
  232. # define gs_font_cid2_DEFINED
  233. typedef struct gs_font_cid2_s gs_font_cid2;
  234. #endif
  235. /*
  236. * Write a CIDFontType 2 font definition. This differs from
  237. * psf_write_truetype_font in that the subset, if any, is specified
  238. * as a bit vector (as for psf_write_cid0_font) rather than a list of glyphs.
  239. * Also, none of the options currently have any effect. The only tables
  240. * written are:
  241. * - The "required" tables: head, hhea, loca, maxp, cvt_, prep, glyf,
  242. * hmtx, fpgm.
  243. * - If present in the font: post, gasp, kern, vhea, vmtx.
  244. * Note that in particular, the cmap, name, and OS/2 tables are omitted.
  245. * NOTE: it is the client's responsibility to ensure that if the subset
  246. * contains any composite glyphs, the components of the composites are
  247. * included explicitly in the subset.
  248. * This procedure does not allocate or free any data.
  249. */
  250. int psf_write_cid2_font(stream *s, gs_font_cid2 *pfont, int options,
  251. const byte *subset_glyphs, uint subset_size,
  252. const gs_const_string *alt_font_name);
  253. /*
  254. * Write a "stripped" CIDFontType 2 font definition. This is the same
  255. * as an ordinary CIDFontType 2 definition, minus glyf and loca.
  256. */
  257. int psf_write_cid2_stripped(stream *s, gs_font_cid2 *pfont);
  258. /* ------ Exported by gdevpsfx.c ------ */
  259. /*
  260. * Convert a Type 1 CharString to (unencrypted) Type 2.
  261. * This procedure does not allocate or free any data.
  262. * NOTE: this procedure expands all Subrs in-line.
  263. */
  264. int psf_convert_type1_to_type2(stream *s, const gs_glyph_data_t *pgd,
  265. gs_font_type1 *pfont);
  266. #endif /* gdevpsf_INCLUDED */