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 /* Glyphs are represented by integer indicies into a table of names. */
16 typedef unsigned short glyph
;
17 #define NOGLYPH 0xFFFF
19 typedef struct document_Tag document
;
20 typedef struct glyph_width_Tag glyph_width
;
21 typedef struct kern_pair_Tag kern_pair
;
22 typedef struct ligature_Tag ligature
;
23 typedef struct font_info_Tag font_info
;
24 typedef struct font_data_Tag font_data
;
25 typedef struct font_encoding_Tag font_encoding
;
26 typedef struct font_list_Tag font_list
;
27 typedef struct para_data_Tag para_data
;
28 typedef struct line_data_Tag line_data
;
29 typedef struct page_data_Tag page_data
;
30 typedef struct subfont_map_entry_Tag subfont_map_entry
;
31 typedef struct text_fragment_Tag text_fragment
;
32 typedef struct xref_Tag xref
;
33 typedef struct xref_dest_Tag xref_dest
;
34 typedef struct rect_Tag rect
;
35 typedef struct outline_element_Tag outline_element
;
38 * This data structure represents the overall document, in the form
39 * it will be given to the client backends.
42 int paper_width
, paper_height
;
45 outline_element
*outline_elements
;
46 int n_outline_elements
;
50 * This data structure represents the normal width of a single glyph
53 struct glyph_width_Tag
{
59 * This data structure represents a kerning pair within a font.
61 struct kern_pair_Tag
{
64 /* Kern amount, in internal units. */
69 * ... and this one represents a ligature.
72 glyph left
, right
, lig
;
76 * This data structure holds static information about a font that doesn't
77 * depend on the particular document. It gets generated when the font's
78 * metrics are read in.
83 struct font_info_Tag
{
86 * Specify the PostScript name of the font and its point size.
90 * The file containing this font, if any.
95 * Lengths of the unencrypted and encrypted portions of the font.
97 long length1
, length2
;
98 /* A tree of glyph_widths */
100 /* A tree of kern_pairs */
102 /* ... and one of ligatures */
105 * For reasonably speedy lookup, we set up a 65536-element
106 * table representing the Unicode BMP (I can conveniently
107 * restrict myself to the BMP for the moment since I happen to
108 * know that no glyph in the Adobe Glyph List falls outside
109 * it), whose elements are indices into the above two arrays.
113 * Various bits of metadata needed for the /FontDescriptor dictionary
127 * This structure holds the information about how a font is used
130 struct font_data_Tag
{
131 font_info
const *info
;
133 * At some point I'm going to divide the font into sub-fonts
134 * with largely non-overlapping encoding vectors. This tree
135 * will track which glyphs go into which subfonts. Also here I
136 * keep track of the latest subfont of any given font, so I can
137 * go back and extend its encoding.
139 tree234
*subfont_map
;
140 font_encoding
*latest_subfont
;
142 * The font list to which this font belongs.
147 struct subfont_map_entry_Tag
{
148 font_encoding
*subfont
;
149 unsigned char position
;
153 * This data structure represents a sub-font: a font with an
156 struct font_encoding_Tag
{
159 char *name
; /* used by client backends */
161 font_data
*font
; /* the parent font structure */
162 glyph vector
[256]; /* the actual encoding vector */
163 wchar_t to_unicode
[256]; /* PDF will want to know this */
164 int free_pos
; /* space left to extend encoding */
168 * This data structure represents the overall list of sub-fonts in
169 * the whole document.
171 struct font_list_Tag
{
177 * Constants defining array indices for the various fonts used in a
188 * This is the data structure which is stored in the private_data
189 * field of each paragraph. It divides the paragraph up into a
190 * linked list of lines, while at the same time providing for those
191 * lines to be linked together into a much longer list spanning the
192 * whole document for page-breaking purposes.
195 struct para_data_Tag
{
198 * Data about the fonts used in this paragraph. Indices are the
199 * FONT_* constants defined above.
201 font_data
*fonts
[NFONTS
];
204 * Pointers to the first and last line of the paragraph. The
205 * line structures are linked into a list, which runs from
206 * `first' to `last' as might be expected. However, the list
207 * does not terminate there: first->prev will end up pointing
208 * to the last line of the previous paragraph in most cases,
209 * and likewise last->next will point to the first line of the
212 line_data
*first
; /* first line in paragraph */
213 line_data
*last
; /* last line in paragraph */
215 * Some paragraphs have associated graphics; currently this is
216 * nothing more complex than a single black rectangle.
219 RECT_NONE
, RECT_CHAPTER_UNDERLINE
, RECT_RULE
222 * We left- and right-justify in special circumstances.
228 * For constructing the page outline.
230 int outline_level
; /* 0=title 1=C 2=H 3=S 4=S2... */
231 wchar_t *outline_title
;
233 * For adding the page number of a contents entry afterwards.
235 paragraph
*contents_entry
;
238 struct line_data_Tag
{
240 * The parent paragraph.
244 * Pointers to join lines into a linked list.
249 * The extent of the text displayed on this line. Also mention
250 * its starting x position, and by how much the width of spaces
251 * needs to be adjusted for paragraph justification.
253 * (Unlike most of the `last' pointers defined in this file,
254 * this `end' pointer points to the word _after_ the last one
255 * that should be displayed on the line. This is how it's
256 * returned from wrap_para().)
261 int hshortfall
, nspaces
; /* for justifying paragraphs */
264 * Auxiliary text: a section number in a margin, or a list item
265 * bullet or number. Also mention where to display this text
266 * relative to the left margin.
272 * This line might have a non-negotiable page break before it.
273 * Also there will be space required above and below it; also I
274 * store the physical line height (defined as the maximum of
275 * the heights of the three fonts in the pdata) because it's
276 * easier than looking it up repeatedly during page breaking.
283 * Penalties for page breaking before or after this line.
285 int penalty_before
, penalty_after
;
287 * These fields are used in the page breaking algorithm.
290 int *vshortfall
, *text
, *space
;
291 line_data
**page_last
; /* last line on a page starting here */
293 * After page breaking, we can assign an actual y-coordinate on
294 * the page to each line. Also we store a pointer back to the
295 * page structure itself.
302 * This data structure is constructed to describe each page of the
305 struct page_data_Tag
{
307 * Pointers to join pages into a linked list.
312 * The set of lines displayed on this page.
314 line_data
*first_line
;
315 line_data
*last_line
;
317 * After text rendering: the set of actual pieces of text
318 * needing to be displayed on this page.
320 text_fragment
*first_text
;
321 text_fragment
*last_text
;
328 * Rectangles to be drawn. (These are currently only used for
329 * underlining chapter titles and drawing horizontal rules.)
334 * The page number, as a string.
338 * This spare pointer field is for use by the client backends.
343 struct text_fragment_Tag
{
352 struct xref_dest_Tag
{
353 enum { NONE
, PAGE
, URL
} type
;
369 struct outline_element_Tag
{
370 int level
; /* 0=title 1=C 2=H 3=S 4=S2... */
375 * Functions exported from bk_paper.c
377 int width_cmp(void *, void *); /* use when setting up widths */
378 int kern_cmp(void *, void *); /* use when setting up kern_pairs */
379 int lig_cmp(void *, void *); /* use when setting up ligatures */
380 int find_width(font_data
*, glyph
);
383 * Functions and data exported from psdata.c.
385 glyph
glyph_intern(char const *);
386 char const *glyph_extern(glyph
);
387 wchar_t ps_glyph_to_unicode(glyph
);
388 extern const char *const ps_std_glyphs
[];
389 void init_std_fonts(void);
390 const int *ps_std_font_widths(char const *fontname
);
391 const kern_pair
*ps_std_font_kerns(char const *fontname
);
394 * Function from bk_pdf.c borrowed by bk_ps.c
396 char *pdf_outline_convert(wchar_t *s
, int *len
);
399 * Backend functions exported by in_pf.c
401 void pf_part1(font_info
*fi
, char **bufp
, size_t *lenp
);
402 void pf_part2(font_info
*fi
, char **bufp
, size_t *lenp
);