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