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 kern_pair_Tag kern_pair
;
17 typedef struct font_data_Tag font_data
;
18 typedef struct font_encoding_Tag font_encoding
;
19 typedef struct font_list_Tag font_list
;
20 typedef struct para_data_Tag para_data
;
21 typedef struct line_data_Tag line_data
;
22 typedef struct page_data_Tag page_data
;
23 typedef struct subfont_map_entry_Tag subfont_map_entry
;
24 typedef struct text_fragment_Tag text_fragment
;
25 typedef struct xref_Tag xref
;
26 typedef struct xref_dest_Tag xref_dest
;
27 typedef struct rect_Tag rect
;
28 typedef struct outline_element_Tag outline_element
;
31 * This data structure represents the overall document, in the form
32 * it will be given to the client backends.
35 int paper_width
, paper_height
;
38 outline_element
*outline_elements
;
39 int n_outline_elements
;
43 * This data structure represents a kerning pair within a font.
45 struct kern_pair_Tag
{
46 /* Glyph indices, in font_data.glyphs. */
47 unsigned short left
, right
;
48 /* Kern amount, in internal units. */
53 * This data structure represents a particular font.
55 struct font_data_Tag
{
57 * Specify the PostScript name of the font and its point size.
61 * An array of pointers to the available glyph names, and their
62 * corresponding character widths. These two arrays have
66 const char *const *glyphs
;
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.
76 unsigned short bmp
[65536];
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.
84 subfont_map_entry
*subfont_map
;
85 font_encoding
*latest_subfont
;
87 * The font list to which this font belongs.
92 struct subfont_map_entry_Tag
{
93 font_encoding
*subfont
;
94 unsigned char position
;
98 * This data structure represents a sub-font: a font with an
101 struct font_encoding_Tag
{
104 char *name
; /* used by client backends */
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 */
114 * This data structure represents the overall list of sub-fonts in
115 * the whole document.
117 struct font_list_Tag
{
123 * Constants defining array indices for the various fonts used in a
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.
141 struct para_data_Tag
{
144 * Data about the fonts used in this paragraph. Indices are the
145 * FONT_* constants defined above.
147 font_data
*fonts
[NFONTS
];
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
158 line_data
*first
; /* first line in paragraph */
159 line_data
*last
; /* last line in paragraph */
161 * Some paragraphs have associated graphics; currently this is
162 * nothing more complex than a single black rectangle.
165 RECT_NONE
, RECT_CHAPTER_UNDERLINE
, RECT_RULE
168 * We left- and right-justify in special circumstances.
174 * For constructing the page outline.
176 int outline_level
; /* 0=title 1=C 2=H 3=S 4=S2... */
177 wchar_t *outline_title
;
179 * For adding the page number of a contents entry afterwards.
181 paragraph
*contents_entry
;
184 struct line_data_Tag
{
186 * The parent paragraph.
190 * Pointers to join lines into a linked list.
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.
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().)
207 int hshortfall
, nspaces
; /* for justifying paragraphs */
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.
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.
229 * Penalties for page breaking before or after this line.
231 int penalty_before
, penalty_after
;
233 * These fields are used in the page breaking algorithm.
236 int *vshortfall
, *text
, *space
;
237 line_data
**page_last
; /* last line on a page starting here */
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.
248 * This data structure is constructed to describe each page of the
251 struct page_data_Tag
{
253 * Pointers to join pages into a linked list.
258 * The set of lines displayed on this page.
260 line_data
*first_line
;
261 line_data
*last_line
;
263 * After text rendering: the set of actual pieces of text
264 * needing to be displayed on this page.
266 text_fragment
*first_text
;
267 text_fragment
*last_text
;
274 * Rectangles to be drawn. (These are currently only used for
275 * underlining chapter titles and drawing horizontal rules.)
280 * The page number, as a string.
284 * This spare pointer field is for use by the client backends.
289 struct text_fragment_Tag
{
298 struct xref_dest_Tag
{
299 enum { NONE
, PAGE
, URL
} type
;
315 struct outline_element_Tag
{
316 int level
; /* 0=title 1=C 2=H 3=S 4=S2... */
321 * Functions and data exported from psdata.c.
323 wchar_t ps_glyph_to_unicode(char const *glyph
);
324 extern const char *const ps_std_glyphs
[];
325 const int *ps_std_font_widths(char const *fontname
);
326 const kern_pair
*ps_std_font_kerns(char const *fontname
);