xref: /plan9/sys/src/cmd/gs/src/gdevpdtd.h (revision 593dc095aefb2a85c828727bbfa9da139a49bdf4)
1 /* Copyright (C) 2002 Aladdin Enterprises.  All rights reserved.
2 
3   This software is provided AS-IS with no warranty, either express or
4   implied.
5 
6   This software is distributed under license and may not be copied,
7   modified or distributed except as expressly authorized under the terms
8   of the license contained in the file LICENSE in this distribution.
9 
10   For more information about licensing, please refer to
11   http://www.ghostscript.com/licensing/. For information on
12   commercial licensing, go to http://www.artifex.com/licensing/ or
13   contact Artifex Software, Inc., 101 Lucas Valley Road #110,
14   San Rafael, CA  94903, U.S.A., +1(415)492-9861.
15 */
16 
17 /* $Id: gdevpdtd.h,v 1.5 2005/04/05 15:44:44 igor Exp $ */
18 /* FontDescriptor structure and API for pdfwrite */
19 
20 #ifndef gdevpdtd_INCLUDED
21 #  define gdevpdtd_INCLUDED
22 
23 #include "gdevpdtx.h"
24 #include "gdevpdtb.h"
25 
26 /* ================ Types and structures ================ */
27 
28 /*
29  * FontDescriptors are handled as pseudo-resources.  Multiple Font resources
30  * may share a descriptor.  We don't need to use reference counting to keep
31  * track of this, since all descriptors persist until the device is closed.
32  * The CharSet entry in the FontDescriptor for a Type 1 subset font lists
33  * the glyphs that are included in the subset, so the FontDescriptor cannot
34  * be written until the font has been written, but we could use an indirect
35  * object for the CharSet and write the FontDescriptor itself early.
36  * However, we don't think that is worthwhile, since FontDescriptors are
37  * small objects compared to the fonts themselves, and it's simpler to keep
38  * all the FontDescriptors until the end.
39  *
40  * Note that FontDescriptors and BaseFonts correspond 1-to-1.  While the PDF
41  * specification allows multiple FontDescriptors for a single BaseFont, this
42  * has no value: all the information in the FontDescriptor is derived from
43  * the BaseFont, so all the FontDescriptors for the same BaseFont must be
44  * the same.
45  */
46 /*
47  * Font names in PDF files have caused an enormous amount of trouble, so we
48  * document specifically how they are handled in each structure.
49  *
50  * The PDF Reference says that the FontName in a font descriptor must be
51  * the same as the BaseFont in the font or CIDFont resource(s) that
52  * reference(s) it.
53  *
54  * We never create a font descriptor without also creating a font resource
55  * that references it, so we set the FontName at the same time as the
56  * BaseFont of the font resource.  For more information, see gdevpdtf.h.
57  */
58 
59 #ifndef pdf_font_descriptor_DEFINED
60 #  define pdf_font_descriptor_DEFINED
61 typedef struct pdf_font_descriptor_s pdf_font_descriptor_t;
62 #endif
63 
64 /* ================ Procedures ================ */
65 
66 /*
67  * Allocate a FontDescriptor, initializing the FontType and rid from the
68  * gs_font.
69  */
70 int pdf_font_descriptor_alloc(gx_device_pdf *pdev,
71 			      pdf_font_descriptor_t **ppfd,
72 			      gs_font_base *font, bool embed);
73 
74 /*
75  * Get the object ID of a FontDescriptor.
76  */
77 long pdf_font_descriptor_id(const pdf_font_descriptor_t *pfd);
78 
79 /*
80  * Get the FontType of a FontDescriptor.
81  */
82 font_type pdf_font_descriptor_FontType(const pdf_font_descriptor_t *pfd);
83 
84 /*
85  * Get the embedding status of a FontDescriptor.
86  */
87 bool pdf_font_descriptor_embedding(const pdf_font_descriptor_t *pfd);
88 
89 /*
90  * Check for subset font.
91  */
92 bool pdf_font_descriptor_is_subset(const pdf_font_descriptor_t *pfd);
93 
94 /*
95  * Return a reference to the FontName of a FontDescriptor, similar to
96  * pdf_base_font_name.
97  */
98 gs_string *pdf_font_descriptor_name(pdf_font_descriptor_t *pfd);
99 
100 /*
101  * Return the (copied, subset or complete) font associated with a FontDescriptor.
102  * This procedure probably shouldn't exist....
103  */
104 gs_font_base *pdf_font_descriptor_font(const pdf_font_descriptor_t *pfd, bool complete);
105 
106 /*
107  * Drop the copied complete font associated with a FontDescriptor.
108  */
109 void pdf_font_descriptor_drop_complete_font(const pdf_font_descriptor_t *pfd);
110 
111 /*
112  * Return a reference to the name of a FontDescriptor's base font, per
113  * pdf_base_font_name.
114  */
115 gs_string *pdf_font_descriptor_base_name(const pdf_font_descriptor_t *pfd);
116 
117 /*
118  * Copy a glyph from a font to the stable copy.  Return 0 if this is a
119  * new glyph, 1 if it was already copied.
120  */
121 int pdf_font_used_glyph(pdf_font_descriptor_t *pfd, gs_glyph glyph,
122 			gs_font_base *font);
123 
124 /*
125  * Compute the FontDescriptor metrics for a font.
126  */
127 int pdf_compute_font_descriptor(pdf_font_descriptor_t *pfd);
128 
129 /*
130  * Finish a FontDescriptor by computing the metric values, and then
131  * writing the associated embedded font if any.
132  */
133 int pdf_finish_FontDescriptor(gx_device_pdf *pdev,
134 			      pdf_font_descriptor_t *pfd);
135 
136 int pdf_finish_font_descriptors(gx_device_pdf *pdev,
137 			int (*finish_proc)(gx_device_pdf *,
138 					   pdf_font_descriptor_t *));
139 /*
140  * Write a FontDescriptor.
141  */
142 int pdf_write_FontDescriptor(gx_device_pdf *pdev,
143 			     pdf_font_descriptor_t *pfd);
144 
145 /*
146  * Release a FontDescriptor components.
147  */
148 int pdf_release_FontDescriptor_components(gx_device_pdf *pdev, pdf_font_descriptor_t *pfd);
149 
150 #endif /* gdevpdtd_INCLUDED */
151