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