43341922 |
1 | /* |
2 | * Paper printing definitions. |
3 | * |
4 | * This header file defines data structures and constants which are |
5 | * shared between bk_paper.c and its clients bk_ps.c and bk_pdf.c. |
6 | */ |
7 | |
8 | #ifndef HALIBUT_PAPER_H |
9 | #define HALIBUT_PAPER_H |
10 | |
17c71b41 |
11 | /* Number of internal units per PostScript point. */ |
0f6715c9 |
12 | #define UNITS_PER_PT 1000 |
13 | #define FUNITS_PER_PT 1000.0 |
17c71b41 |
14 | |
43341922 |
15 | typedef struct document_Tag document; |
9db47bc3 |
16 | typedef struct kern_pair_Tag kern_pair; |
ba0fe3ec |
17 | typedef struct font_info_Tag font_info; |
43341922 |
18 | typedef struct font_data_Tag font_data; |
19 | typedef struct font_encoding_Tag font_encoding; |
20 | typedef struct font_list_Tag font_list; |
21 | typedef struct para_data_Tag para_data; |
22 | typedef struct line_data_Tag line_data; |
23 | typedef struct page_data_Tag page_data; |
24 | typedef struct subfont_map_entry_Tag subfont_map_entry; |
25 | typedef struct text_fragment_Tag text_fragment; |
138d7ffb |
26 | typedef struct xref_Tag xref; |
27 | typedef struct xref_dest_Tag xref_dest; |
23765aeb |
28 | typedef struct rect_Tag rect; |
f0e51ce1 |
29 | typedef struct outline_element_Tag outline_element; |
43341922 |
30 | |
31 | /* |
32 | * This data structure represents the overall document, in the form |
33 | * it will be given to the client backends. |
34 | */ |
35 | struct document_Tag { |
36 | int paper_width, paper_height; |
37 | font_list *fonts; |
38 | page_data *pages; |
f0e51ce1 |
39 | outline_element *outline_elements; |
40 | int n_outline_elements; |
43341922 |
41 | }; |
42 | |
43 | /* |
9db47bc3 |
44 | * This data structure represents a kerning pair within a font. |
45 | */ |
46 | struct kern_pair_Tag { |
47 | /* Glyph indices, in font_data.glyphs. */ |
48 | unsigned short left, right; |
49 | /* Kern amount, in internal units. */ |
50 | int kern; |
51 | }; |
52 | |
53 | /* |
ba0fe3ec |
54 | * This data structure holds static information about a font that doesn't |
55 | * depend on the particular document. It gets generated when the font's |
56 | * metrics are read in. |
43341922 |
57 | */ |
ba0fe3ec |
58 | |
59 | font_info *all_fonts; |
60 | |
61 | struct font_info_Tag { |
62 | font_info *next; |
43341922 |
63 | /* |
64 | * Specify the PostScript name of the font and its point size. |
65 | */ |
66 | const char *name; |
67 | /* |
44407fea |
68 | * The file containing this font, if any. |
69 | */ |
70 | FILE *fp; |
c885c2ff |
71 | filepos pos; |
72 | /* |
73 | * Lengths of the unencrypted and encrypted portions of the font. |
74 | */ |
75 | long length1, length2; |
44407fea |
76 | /* |
43341922 |
77 | * An array of pointers to the available glyph names, and their |
78 | * corresponding character widths. These two arrays have |
79 | * parallel indices. |
80 | */ |
81 | int nglyphs; |
82 | const char *const *glyphs; |
83 | const int *widths; |
ba0fe3ec |
84 | /* |
85 | * Glyph indices sorted into glyph-name order, for name-to-index |
86 | * mapping. |
87 | */ |
88 | unsigned short *glyphsbyname; |
89 | /* A tree of kern_pairs */ |
9db47bc3 |
90 | tree234 *kerns; |
43341922 |
91 | /* |
92 | * For reasonably speedy lookup, we set up a 65536-element |
93 | * table representing the Unicode BMP (I can conveniently |
94 | * restrict myself to the BMP for the moment since I happen to |
95 | * know that no glyph in the Adobe Glyph List falls outside |
96 | * it), whose elements are indices into the above two arrays. |
97 | */ |
98 | unsigned short bmp[65536]; |
255b7ff3 |
99 | /* |
100 | * Various bits of metadata needed for the /FontDescriptor dictionary |
101 | * in PDF. |
102 | */ |
103 | float fontbbox[4]; |
104 | float capheight; |
105 | float xheight; |
106 | float ascent; |
107 | float descent; |
108 | float stemv; |
109 | float stemh; |
110 | float italicangle; |
ba0fe3ec |
111 | }; |
112 | |
113 | /* |
114 | * This structure holds the information about how a font is used |
115 | * in a document. |
116 | */ |
117 | struct font_data_Tag { |
118 | font_info const *info; |
43341922 |
119 | /* |
120 | * At some point I'm going to divide the font into sub-fonts |
121 | * with largely non-overlapping encoding vectors. This array |
122 | * will track which glyphs go into which subfonts. Also here I |
123 | * keep track of the latest subfont of any given font, so I can |
124 | * go back and extend its encoding. |
125 | */ |
126 | subfont_map_entry *subfont_map; |
127 | font_encoding *latest_subfont; |
128 | /* |
129 | * The font list to which this font belongs. |
130 | */ |
131 | font_list *list; |
132 | }; |
133 | |
134 | struct subfont_map_entry_Tag { |
135 | font_encoding *subfont; |
136 | unsigned char position; |
137 | }; |
138 | |
139 | /* |
140 | * This data structure represents a sub-font: a font with an |
141 | * encoding vector. |
142 | */ |
143 | struct font_encoding_Tag { |
144 | font_encoding *next; |
145 | |
146 | char *name; /* used by client backends */ |
147 | |
148 | font_data *font; /* the parent font structure */ |
149 | const char *vector[256]; /* the actual encoding vector */ |
150 | int indices[256]; /* indices back into main font struct */ |
151 | wchar_t to_unicode[256]; /* PDF will want to know this */ |
152 | int free_pos; /* space left to extend encoding */ |
153 | }; |
154 | |
155 | /* |
156 | * This data structure represents the overall list of sub-fonts in |
157 | * the whole document. |
158 | */ |
159 | struct font_list_Tag { |
160 | font_encoding *head; |
161 | font_encoding *tail; |
162 | }; |
163 | |
164 | /* |
165 | * Constants defining array indices for the various fonts used in a |
166 | * paragraph. |
167 | */ |
168 | enum { |
169 | FONT_NORMAL, |
170 | FONT_EMPH, |
171 | FONT_CODE, |
172 | NFONTS |
173 | }; |
174 | |
175 | /* |
176 | * This is the data structure which is stored in the private_data |
177 | * field of each paragraph. It divides the paragraph up into a |
178 | * linked list of lines, while at the same time providing for those |
179 | * lines to be linked together into a much longer list spanning the |
180 | * whole document for page-breaking purposes. |
181 | */ |
182 | |
183 | struct para_data_Tag { |
be76d597 |
184 | para_data *next; |
43341922 |
185 | /* |
186 | * Data about the fonts used in this paragraph. Indices are the |
187 | * FONT_* constants defined above. |
188 | */ |
189 | font_data *fonts[NFONTS]; |
190 | int sizes[NFONTS]; |
191 | /* |
192 | * Pointers to the first and last line of the paragraph. The |
193 | * line structures are linked into a list, which runs from |
194 | * `first' to `last' as might be expected. However, the list |
195 | * does not terminate there: first->prev will end up pointing |
196 | * to the last line of the previous paragraph in most cases, |
197 | * and likewise last->next will point to the first line of the |
198 | * next paragraph. |
199 | */ |
200 | line_data *first; /* first line in paragraph */ |
201 | line_data *last; /* last line in paragraph */ |
be76d597 |
202 | /* |
203 | * Some paragraphs have associated graphics; currently this is |
204 | * nothing more complex than a single black rectangle. |
205 | */ |
206 | enum { |
207 | RECT_NONE, RECT_CHAPTER_UNDERLINE, RECT_RULE |
208 | } rect_type; |
209 | /* |
c6536773 |
210 | * We left- and right-justify in special circumstances. |
211 | */ |
212 | enum { |
213 | JUST, LEFT, RIGHT |
214 | } justification; |
215 | /* |
be76d597 |
216 | * For constructing the page outline. |
217 | */ |
218 | int outline_level; /* 0=title 1=C 2=H 3=S 4=S2... */ |
219 | wchar_t *outline_title; |
2bfd1b76 |
220 | /* |
221 | * For adding the page number of a contents entry afterwards. |
222 | */ |
223 | paragraph *contents_entry; |
43341922 |
224 | }; |
225 | |
226 | struct line_data_Tag { |
227 | /* |
228 | * The parent paragraph. |
229 | */ |
230 | para_data *pdata; |
231 | /* |
232 | * Pointers to join lines into a linked list. |
233 | */ |
234 | line_data *prev; |
235 | line_data *next; |
236 | /* |
237 | * The extent of the text displayed on this line. Also mention |
238 | * its starting x position, and by how much the width of spaces |
239 | * needs to be adjusted for paragraph justification. |
240 | * |
faad4952 |
241 | * (Unlike most of the `last' pointers defined in this file, |
242 | * this `end' pointer points to the word _after_ the last one |
243 | * that should be displayed on the line. This is how it's |
244 | * returned from wrap_para().) |
43341922 |
245 | */ |
246 | word *first; |
faad4952 |
247 | word *end; |
43341922 |
248 | int xpos; |
faad4952 |
249 | int hshortfall, nspaces; /* for justifying paragraphs */ |
c6536773 |
250 | int real_shortfall; |
43341922 |
251 | /* |
252 | * Auxiliary text: a section number in a margin, or a list item |
253 | * bullet or number. Also mention where to display this text |
254 | * relative to the left margin. |
255 | */ |
256 | word *aux_text; |
515d216b |
257 | word *aux_text_2; |
43341922 |
258 | int aux_left_indent; |
259 | /* |
260 | * This line might have a non-negotiable page break before it. |
261 | * Also there will be space required above and below it; also I |
262 | * store the physical line height (defined as the maximum of |
263 | * the heights of the three fonts in the pdata) because it's |
264 | * easier than looking it up repeatedly during page breaking. |
265 | */ |
266 | int page_break; |
267 | int space_before; |
268 | int space_after; |
269 | int line_height; |
270 | /* |
39a0cfb9 |
271 | * Penalties for page breaking before or after this line. |
272 | */ |
273 | int penalty_before, penalty_after; |
274 | /* |
43341922 |
275 | * These fields are used in the page breaking algorithm. |
276 | */ |
c6536773 |
277 | int *bestcost; |
278 | int *vshortfall, *text, *space; |
279 | line_data **page_last; /* last line on a page starting here */ |
43341922 |
280 | /* |
281 | * After page breaking, we can assign an actual y-coordinate on |
282 | * the page to each line. Also we store a pointer back to the |
283 | * page structure itself. |
284 | */ |
285 | int ypos; |
286 | page_data *page; |
287 | }; |
288 | |
289 | /* |
290 | * This data structure is constructed to describe each page of the |
291 | * printed output. |
292 | */ |
293 | struct page_data_Tag { |
294 | /* |
295 | * Pointers to join pages into a linked list. |
296 | */ |
297 | page_data *prev; |
298 | page_data *next; |
299 | /* |
300 | * The set of lines displayed on this page. |
301 | */ |
302 | line_data *first_line; |
303 | line_data *last_line; |
304 | /* |
305 | * After text rendering: the set of actual pieces of text |
306 | * needing to be displayed on this page. |
307 | */ |
308 | text_fragment *first_text; |
309 | text_fragment *last_text; |
310 | /* |
138d7ffb |
311 | * Cross-references. |
312 | */ |
313 | xref *first_xref; |
314 | xref *last_xref; |
315 | /* |
23765aeb |
316 | * Rectangles to be drawn. (These are currently only used for |
317 | * underlining chapter titles and drawing horizontal rules.) |
318 | */ |
319 | rect *first_rect; |
320 | rect *last_rect; |
321 | /* |
2bfd1b76 |
322 | * The page number, as a string. |
323 | */ |
324 | wchar_t *number; |
325 | /* |
43341922 |
326 | * This spare pointer field is for use by the client backends. |
327 | */ |
328 | void *spare; |
329 | }; |
330 | |
331 | struct text_fragment_Tag { |
332 | text_fragment *next; |
333 | int x, y; |
334 | font_encoding *fe; |
335 | int fontsize; |
336 | char *text; |
7c8c4239 |
337 | int width; |
43341922 |
338 | }; |
339 | |
138d7ffb |
340 | struct xref_dest_Tag { |
341 | enum { NONE, PAGE, URL } type; |
342 | page_data *page; |
343 | char *url; |
344 | }; |
345 | |
346 | struct xref_Tag { |
347 | xref *next; |
348 | int lx, rx, ty, by; |
349 | xref_dest dest; |
350 | }; |
351 | |
23765aeb |
352 | struct rect_Tag { |
353 | rect *next; |
354 | int x, y, w, h; |
355 | }; |
356 | |
f0e51ce1 |
357 | struct outline_element_Tag { |
358 | int level; /* 0=title 1=C 2=H 3=S 4=S2... */ |
be76d597 |
359 | para_data *pdata; |
f0e51ce1 |
360 | }; |
361 | |
43341922 |
362 | /* |
ba0fe3ec |
363 | * Functions exported from bk_paper.c |
364 | */ |
365 | int kern_cmp(void *, void *); /* use when setting up kern_pairs */ |
366 | void font_index_glyphs(font_info *fi); |
367 | int find_glyph(font_info *fi, char const *name); |
368 | |
369 | |
370 | /* |
43341922 |
371 | * Functions and data exported from psdata.c. |
372 | */ |
373 | wchar_t ps_glyph_to_unicode(char const *glyph); |
374 | extern const char *const ps_std_glyphs[]; |
ba0fe3ec |
375 | void init_std_fonts(void); |
43341922 |
376 | const int *ps_std_font_widths(char const *fontname); |
9db47bc3 |
377 | const kern_pair *ps_std_font_kerns(char const *fontname); |
43341922 |
378 | |
f8194b21 |
379 | /* |
380 | * Function from bk_pdf.c borrowed by bk_ps.c |
381 | */ |
382 | char *pdf_outline_convert(wchar_t *s, int *len); |
383 | |
c885c2ff |
384 | /* |
385 | * Backend functions exported by in_pf.c |
386 | */ |
387 | void pf_part1(font_info *fi, char **bufp, size_t *lenp); |
388 | void pf_part2(font_info *fi, char **bufp, size_t *lenp); |
389 | |
43341922 |
390 | #endif |