2 * Paper printing definitions.
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.
8 #ifndef HALIBUT_PAPER_H
9 #define HALIBUT_PAPER_H
11 /* Number of internal units per PostScript point. */
12 #define UNITS_PER_PT 1000
13 #define FUNITS_PER_PT 1000.0
15 typedef struct document_Tag document
;
16 typedef struct font_data_Tag font_data
;
17 typedef struct font_encoding_Tag font_encoding
;
18 typedef struct font_list_Tag font_list
;
19 typedef struct para_data_Tag para_data
;
20 typedef struct line_data_Tag line_data
;
21 typedef struct page_data_Tag page_data
;
22 typedef struct subfont_map_entry_Tag subfont_map_entry
;
23 typedef struct text_fragment_Tag text_fragment
;
24 typedef struct xref_Tag xref
;
25 typedef struct xref_dest_Tag xref_dest
;
26 typedef struct rect_Tag rect
;
27 typedef struct outline_element_Tag outline_element
;
30 * This data structure represents the overall document, in the form
31 * it will be given to the client backends.
34 int paper_width
, paper_height
;
37 outline_element
*outline_elements
;
38 int n_outline_elements
;
42 * This data structure represents a particular font.
44 struct font_data_Tag
{
46 * Specify the PostScript name of the font and its point size.
50 * An array of pointers to the available glyph names, and their
51 * corresponding character widths. These two arrays have
55 const char *const *glyphs
;
58 * For reasonably speedy lookup, we set up a 65536-element
59 * table representing the Unicode BMP (I can conveniently
60 * restrict myself to the BMP for the moment since I happen to
61 * know that no glyph in the Adobe Glyph List falls outside
62 * it), whose elements are indices into the above two arrays.
64 unsigned short bmp
[65536];
66 * At some point I'm going to divide the font into sub-fonts
67 * with largely non-overlapping encoding vectors. This array
68 * will track which glyphs go into which subfonts. Also here I
69 * keep track of the latest subfont of any given font, so I can
70 * go back and extend its encoding.
72 subfont_map_entry
*subfont_map
;
73 font_encoding
*latest_subfont
;
75 * The font list to which this font belongs.
80 struct subfont_map_entry_Tag
{
81 font_encoding
*subfont
;
82 unsigned char position
;
86 * This data structure represents a sub-font: a font with an
89 struct font_encoding_Tag
{
92 char *name
; /* used by client backends */
94 font_data
*font
; /* the parent font structure */
95 const char *vector
[256]; /* the actual encoding vector */
96 int indices
[256]; /* indices back into main font struct */
97 wchar_t to_unicode
[256]; /* PDF will want to know this */
98 int free_pos
; /* space left to extend encoding */
102 * This data structure represents the overall list of sub-fonts in
103 * the whole document.
105 struct font_list_Tag
{
111 * Constants defining array indices for the various fonts used in a
122 * This is the data structure which is stored in the private_data
123 * field of each paragraph. It divides the paragraph up into a
124 * linked list of lines, while at the same time providing for those
125 * lines to be linked together into a much longer list spanning the
126 * whole document for page-breaking purposes.
129 struct para_data_Tag
{
132 * Data about the fonts used in this paragraph. Indices are the
133 * FONT_* constants defined above.
135 font_data
*fonts
[NFONTS
];
138 * Pointers to the first and last line of the paragraph. The
139 * line structures are linked into a list, which runs from
140 * `first' to `last' as might be expected. However, the list
141 * does not terminate there: first->prev will end up pointing
142 * to the last line of the previous paragraph in most cases,
143 * and likewise last->next will point to the first line of the
146 line_data
*first
; /* first line in paragraph */
147 line_data
*last
; /* last line in paragraph */
149 * Some paragraphs have associated graphics; currently this is
150 * nothing more complex than a single black rectangle.
153 RECT_NONE
, RECT_CHAPTER_UNDERLINE
, RECT_RULE
156 * We left- and right-justify in special circumstances.
162 * For constructing the page outline.
164 int outline_level
; /* 0=title 1=C 2=H 3=S 4=S2... */
165 wchar_t *outline_title
;
167 * For adding the page number of a contents entry afterwards.
169 paragraph
*contents_entry
;
172 struct line_data_Tag
{
174 * The parent paragraph.
178 * Pointers to join lines into a linked list.
183 * The extent of the text displayed on this line. Also mention
184 * its starting x position, and by how much the width of spaces
185 * needs to be adjusted for paragraph justification.
187 * (Unlike most of the `last' pointers defined in this file,
188 * this `end' pointer points to the word _after_ the last one
189 * that should be displayed on the line. This is how it's
190 * returned from wrap_para().)
195 int hshortfall
, nspaces
; /* for justifying paragraphs */
198 * Auxiliary text: a section number in a margin, or a list item
199 * bullet or number. Also mention where to display this text
200 * relative to the left margin.
206 * This line might have a non-negotiable page break before it.
207 * Also there will be space required above and below it; also I
208 * store the physical line height (defined as the maximum of
209 * the heights of the three fonts in the pdata) because it's
210 * easier than looking it up repeatedly during page breaking.
217 * Penalties for page breaking before or after this line.
219 int penalty_before
, penalty_after
;
221 * These fields are used in the page breaking algorithm.
224 int *vshortfall
, *text
, *space
;
225 line_data
**page_last
; /* last line on a page starting here */
227 * After page breaking, we can assign an actual y-coordinate on
228 * the page to each line. Also we store a pointer back to the
229 * page structure itself.
236 * This data structure is constructed to describe each page of the
239 struct page_data_Tag
{
241 * Pointers to join pages into a linked list.
246 * The set of lines displayed on this page.
248 line_data
*first_line
;
249 line_data
*last_line
;
251 * After text rendering: the set of actual pieces of text
252 * needing to be displayed on this page.
254 text_fragment
*first_text
;
255 text_fragment
*last_text
;
262 * Rectangles to be drawn. (These are currently only used for
263 * underlining chapter titles and drawing horizontal rules.)
268 * The page number, as a string.
272 * This spare pointer field is for use by the client backends.
277 struct text_fragment_Tag
{
286 struct xref_dest_Tag
{
287 enum { NONE
, PAGE
, URL
} type
;
303 struct outline_element_Tag
{
304 int level
; /* 0=title 1=C 2=H 3=S 4=S2... */
309 * Functions and data exported from psdata.c.
311 wchar_t ps_glyph_to_unicode(char const *glyph
);
312 extern const char *const ps_std_glyphs
[];
313 const int *ps_std_font_widths(char const *fontname
);