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