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