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 | |
11 | typedef struct document_Tag document; |
12 | typedef struct font_data_Tag font_data; |
13 | typedef struct font_encoding_Tag font_encoding; |
14 | typedef struct font_list_Tag font_list; |
15 | typedef struct para_data_Tag para_data; |
16 | typedef struct line_data_Tag line_data; |
17 | typedef struct page_data_Tag page_data; |
18 | typedef struct subfont_map_entry_Tag subfont_map_entry; |
19 | typedef struct text_fragment_Tag text_fragment; |
138d7ffb |
20 | typedef struct xref_Tag xref; |
21 | typedef struct xref_dest_Tag xref_dest; |
23765aeb |
22 | typedef struct rect_Tag rect; |
f0e51ce1 |
23 | typedef struct outline_element_Tag outline_element; |
43341922 |
24 | |
25 | /* |
26 | * This data structure represents the overall document, in the form |
27 | * it will be given to the client backends. |
28 | */ |
29 | struct document_Tag { |
30 | int paper_width, paper_height; |
31 | font_list *fonts; |
32 | page_data *pages; |
f0e51ce1 |
33 | outline_element *outline_elements; |
34 | int n_outline_elements; |
43341922 |
35 | }; |
36 | |
37 | /* |
38 | * This data structure represents a particular font. |
39 | */ |
40 | struct font_data_Tag { |
41 | /* |
42 | * Specify the PostScript name of the font and its point size. |
43 | */ |
44 | const char *name; |
45 | /* |
46 | * An array of pointers to the available glyph names, and their |
47 | * corresponding character widths. These two arrays have |
48 | * parallel indices. |
49 | */ |
50 | int nglyphs; |
51 | const char *const *glyphs; |
52 | const int *widths; |
53 | /* |
54 | * For reasonably speedy lookup, we set up a 65536-element |
55 | * table representing the Unicode BMP (I can conveniently |
56 | * restrict myself to the BMP for the moment since I happen to |
57 | * know that no glyph in the Adobe Glyph List falls outside |
58 | * it), whose elements are indices into the above two arrays. |
59 | */ |
60 | unsigned short bmp[65536]; |
61 | /* |
62 | * At some point I'm going to divide the font into sub-fonts |
63 | * with largely non-overlapping encoding vectors. This array |
64 | * will track which glyphs go into which subfonts. Also here I |
65 | * keep track of the latest subfont of any given font, so I can |
66 | * go back and extend its encoding. |
67 | */ |
68 | subfont_map_entry *subfont_map; |
69 | font_encoding *latest_subfont; |
70 | /* |
71 | * The font list to which this font belongs. |
72 | */ |
73 | font_list *list; |
74 | }; |
75 | |
76 | struct subfont_map_entry_Tag { |
77 | font_encoding *subfont; |
78 | unsigned char position; |
79 | }; |
80 | |
81 | /* |
82 | * This data structure represents a sub-font: a font with an |
83 | * encoding vector. |
84 | */ |
85 | struct font_encoding_Tag { |
86 | font_encoding *next; |
87 | |
88 | char *name; /* used by client backends */ |
89 | |
90 | font_data *font; /* the parent font structure */ |
91 | const char *vector[256]; /* the actual encoding vector */ |
92 | int indices[256]; /* indices back into main font struct */ |
93 | wchar_t to_unicode[256]; /* PDF will want to know this */ |
94 | int free_pos; /* space left to extend encoding */ |
95 | }; |
96 | |
97 | /* |
98 | * This data structure represents the overall list of sub-fonts in |
99 | * the whole document. |
100 | */ |
101 | struct font_list_Tag { |
102 | font_encoding *head; |
103 | font_encoding *tail; |
104 | }; |
105 | |
106 | /* |
107 | * Constants defining array indices for the various fonts used in a |
108 | * paragraph. |
109 | */ |
110 | enum { |
111 | FONT_NORMAL, |
112 | FONT_EMPH, |
113 | FONT_CODE, |
114 | NFONTS |
115 | }; |
116 | |
117 | /* |
118 | * This is the data structure which is stored in the private_data |
119 | * field of each paragraph. It divides the paragraph up into a |
120 | * linked list of lines, while at the same time providing for those |
121 | * lines to be linked together into a much longer list spanning the |
122 | * whole document for page-breaking purposes. |
123 | */ |
124 | |
125 | struct para_data_Tag { |
126 | /* |
127 | * Data about the fonts used in this paragraph. Indices are the |
128 | * FONT_* constants defined above. |
129 | */ |
130 | font_data *fonts[NFONTS]; |
131 | int sizes[NFONTS]; |
132 | /* |
133 | * Pointers to the first and last line of the paragraph. The |
134 | * line structures are linked into a list, which runs from |
135 | * `first' to `last' as might be expected. However, the list |
136 | * does not terminate there: first->prev will end up pointing |
137 | * to the last line of the previous paragraph in most cases, |
138 | * and likewise last->next will point to the first line of the |
139 | * next paragraph. |
140 | */ |
141 | line_data *first; /* first line in paragraph */ |
142 | line_data *last; /* last line in paragraph */ |
143 | }; |
144 | |
145 | struct line_data_Tag { |
146 | /* |
147 | * The parent paragraph. |
148 | */ |
149 | para_data *pdata; |
150 | /* |
151 | * Pointers to join lines into a linked list. |
152 | */ |
153 | line_data *prev; |
154 | line_data *next; |
155 | /* |
156 | * The extent of the text displayed on this line. Also mention |
157 | * its starting x position, and by how much the width of spaces |
158 | * needs to be adjusted for paragraph justification. |
159 | * |
faad4952 |
160 | * (Unlike most of the `last' pointers defined in this file, |
161 | * this `end' pointer points to the word _after_ the last one |
162 | * that should be displayed on the line. This is how it's |
163 | * returned from wrap_para().) |
43341922 |
164 | */ |
165 | word *first; |
faad4952 |
166 | word *end; |
43341922 |
167 | int xpos; |
faad4952 |
168 | int hshortfall, nspaces; /* for justifying paragraphs */ |
43341922 |
169 | /* |
170 | * Auxiliary text: a section number in a margin, or a list item |
171 | * bullet or number. Also mention where to display this text |
172 | * relative to the left margin. |
173 | */ |
174 | word *aux_text; |
515d216b |
175 | word *aux_text_2; |
43341922 |
176 | int aux_left_indent; |
177 | /* |
178 | * This line might have a non-negotiable page break before it. |
179 | * Also there will be space required above and below it; also I |
180 | * store the physical line height (defined as the maximum of |
181 | * the heights of the three fonts in the pdata) because it's |
182 | * easier than looking it up repeatedly during page breaking. |
183 | */ |
184 | int page_break; |
185 | int space_before; |
186 | int space_after; |
187 | int line_height; |
188 | /* |
39a0cfb9 |
189 | * Penalties for page breaking before or after this line. |
190 | */ |
191 | int penalty_before, penalty_after; |
192 | /* |
43341922 |
193 | * These fields are used in the page breaking algorithm. |
194 | */ |
195 | int bestcost; |
faad4952 |
196 | int vshortfall, text, space; |
43341922 |
197 | line_data *page_last; /* last line on a page starting here */ |
198 | /* |
199 | * After page breaking, we can assign an actual y-coordinate on |
200 | * the page to each line. Also we store a pointer back to the |
201 | * page structure itself. |
202 | */ |
203 | int ypos; |
204 | page_data *page; |
205 | }; |
206 | |
207 | /* |
208 | * This data structure is constructed to describe each page of the |
209 | * printed output. |
210 | */ |
211 | struct page_data_Tag { |
212 | /* |
213 | * Pointers to join pages into a linked list. |
214 | */ |
215 | page_data *prev; |
216 | page_data *next; |
217 | /* |
218 | * The set of lines displayed on this page. |
219 | */ |
220 | line_data *first_line; |
221 | line_data *last_line; |
222 | /* |
223 | * After text rendering: the set of actual pieces of text |
224 | * needing to be displayed on this page. |
225 | */ |
226 | text_fragment *first_text; |
227 | text_fragment *last_text; |
228 | /* |
138d7ffb |
229 | * Cross-references. |
230 | */ |
231 | xref *first_xref; |
232 | xref *last_xref; |
233 | /* |
23765aeb |
234 | * Rectangles to be drawn. (These are currently only used for |
235 | * underlining chapter titles and drawing horizontal rules.) |
236 | */ |
237 | rect *first_rect; |
238 | rect *last_rect; |
239 | /* |
43341922 |
240 | * This spare pointer field is for use by the client backends. |
241 | */ |
242 | void *spare; |
243 | }; |
244 | |
245 | struct text_fragment_Tag { |
246 | text_fragment *next; |
247 | int x, y; |
248 | font_encoding *fe; |
249 | int fontsize; |
250 | char *text; |
251 | }; |
252 | |
138d7ffb |
253 | struct xref_dest_Tag { |
254 | enum { NONE, PAGE, URL } type; |
255 | page_data *page; |
256 | char *url; |
257 | }; |
258 | |
259 | struct xref_Tag { |
260 | xref *next; |
261 | int lx, rx, ty, by; |
262 | xref_dest dest; |
263 | }; |
264 | |
23765aeb |
265 | struct rect_Tag { |
266 | rect *next; |
267 | int x, y, w, h; |
268 | }; |
269 | |
f0e51ce1 |
270 | struct outline_element_Tag { |
271 | int level; /* 0=title 1=C 2=H 3=S 4=S2... */ |
272 | paragraph *para; |
273 | }; |
274 | |
43341922 |
275 | /* |
276 | * Functions and data exported from psdata.c. |
277 | */ |
278 | wchar_t ps_glyph_to_unicode(char const *glyph); |
279 | extern const char *const ps_std_glyphs[]; |
280 | const int *ps_std_font_widths(char const *fontname); |
281 | |
282 | #endif |