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_info_Tag font_info
;
18 typedef struct font_data_Tag font_data
;
19 typedef struct font_encoding_Tag font_encoding
;
20 typedef struct font_list_Tag font_list
;
21 typedef struct para_data_Tag para_data
;
22 typedef struct line_data_Tag line_data
;
23 typedef struct page_data_Tag page_data
;
24 typedef struct subfont_map_entry_Tag subfont_map_entry
;
25 typedef struct text_fragment_Tag text_fragment
;
26 typedef struct xref_Tag xref
;
27 typedef struct xref_dest_Tag xref_dest
;
28 typedef struct rect_Tag rect
;
29 typedef struct outline_element_Tag outline_element
;
32 * This data structure represents the overall document, in the form
33 * it will be given to the client backends.
36 int paper_width
, paper_height
;
39 outline_element
*outline_elements
;
40 int n_outline_elements
;
44 * This data structure represents a kerning pair within a font.
46 struct kern_pair_Tag
{
47 /* Glyph indices, in font_data.glyphs. */
48 unsigned short left
, right
;
49 /* Kern amount, in internal units. */
54 * This data structure holds static information about a font that doesn't
55 * depend on the particular document. It gets generated when the font's
56 * metrics are read in.
61 struct font_info_Tag
{
64 * Specify the PostScript name of the font and its point size.
68 * The file containing this font, if any.
72 * An array of pointers to the available glyph names, and their
73 * corresponding character widths. These two arrays have
77 const char *const *glyphs
;
80 * Glyph indices sorted into glyph-name order, for name-to-index
83 unsigned short *glyphsbyname
;
84 /* A tree of kern_pairs */
87 * For reasonably speedy lookup, we set up a 65536-element
88 * table representing the Unicode BMP (I can conveniently
89 * restrict myself to the BMP for the moment since I happen to
90 * know that no glyph in the Adobe Glyph List falls outside
91 * it), whose elements are indices into the above two arrays.
93 unsigned short bmp
[65536];
95 * Various bits of metadata needed for the /FontDescriptor dictionary
109 * This structure holds the information about how a font is used
112 struct font_data_Tag
{
113 font_info
const *info
;
115 * At some point I'm going to divide the font into sub-fonts
116 * with largely non-overlapping encoding vectors. This array
117 * will track which glyphs go into which subfonts. Also here I
118 * keep track of the latest subfont of any given font, so I can
119 * go back and extend its encoding.
121 subfont_map_entry
*subfont_map
;
122 font_encoding
*latest_subfont
;
124 * The font list to which this font belongs.
129 struct subfont_map_entry_Tag
{
130 font_encoding
*subfont
;
131 unsigned char position
;
135 * This data structure represents a sub-font: a font with an
138 struct font_encoding_Tag
{
141 char *name
; /* used by client backends */
143 font_data
*font
; /* the parent font structure */
144 const char *vector
[256]; /* the actual encoding vector */
145 int indices
[256]; /* indices back into main font struct */
146 wchar_t to_unicode
[256]; /* PDF will want to know this */
147 int free_pos
; /* space left to extend encoding */
151 * This data structure represents the overall list of sub-fonts in
152 * the whole document.
154 struct font_list_Tag
{
160 * Constants defining array indices for the various fonts used in a
171 * This is the data structure which is stored in the private_data
172 * field of each paragraph. It divides the paragraph up into a
173 * linked list of lines, while at the same time providing for those
174 * lines to be linked together into a much longer list spanning the
175 * whole document for page-breaking purposes.
178 struct para_data_Tag
{
181 * Data about the fonts used in this paragraph. Indices are the
182 * FONT_* constants defined above.
184 font_data
*fonts
[NFONTS
];
187 * Pointers to the first and last line of the paragraph. The
188 * line structures are linked into a list, which runs from
189 * `first' to `last' as might be expected. However, the list
190 * does not terminate there: first->prev will end up pointing
191 * to the last line of the previous paragraph in most cases,
192 * and likewise last->next will point to the first line of the
195 line_data
*first
; /* first line in paragraph */
196 line_data
*last
; /* last line in paragraph */
198 * Some paragraphs have associated graphics; currently this is
199 * nothing more complex than a single black rectangle.
202 RECT_NONE
, RECT_CHAPTER_UNDERLINE
, RECT_RULE
205 * We left- and right-justify in special circumstances.
211 * For constructing the page outline.
213 int outline_level
; /* 0=title 1=C 2=H 3=S 4=S2... */
214 wchar_t *outline_title
;
216 * For adding the page number of a contents entry afterwards.
218 paragraph
*contents_entry
;
221 struct line_data_Tag
{
223 * The parent paragraph.
227 * Pointers to join lines into a linked list.
232 * The extent of the text displayed on this line. Also mention
233 * its starting x position, and by how much the width of spaces
234 * needs to be adjusted for paragraph justification.
236 * (Unlike most of the `last' pointers defined in this file,
237 * this `end' pointer points to the word _after_ the last one
238 * that should be displayed on the line. This is how it's
239 * returned from wrap_para().)
244 int hshortfall
, nspaces
; /* for justifying paragraphs */
247 * Auxiliary text: a section number in a margin, or a list item
248 * bullet or number. Also mention where to display this text
249 * relative to the left margin.
255 * This line might have a non-negotiable page break before it.
256 * Also there will be space required above and below it; also I
257 * store the physical line height (defined as the maximum of
258 * the heights of the three fonts in the pdata) because it's
259 * easier than looking it up repeatedly during page breaking.
266 * Penalties for page breaking before or after this line.
268 int penalty_before
, penalty_after
;
270 * These fields are used in the page breaking algorithm.
273 int *vshortfall
, *text
, *space
;
274 line_data
**page_last
; /* last line on a page starting here */
276 * After page breaking, we can assign an actual y-coordinate on
277 * the page to each line. Also we store a pointer back to the
278 * page structure itself.
285 * This data structure is constructed to describe each page of the
288 struct page_data_Tag
{
290 * Pointers to join pages into a linked list.
295 * The set of lines displayed on this page.
297 line_data
*first_line
;
298 line_data
*last_line
;
300 * After text rendering: the set of actual pieces of text
301 * needing to be displayed on this page.
303 text_fragment
*first_text
;
304 text_fragment
*last_text
;
311 * Rectangles to be drawn. (These are currently only used for
312 * underlining chapter titles and drawing horizontal rules.)
317 * The page number, as a string.
321 * This spare pointer field is for use by the client backends.
326 struct text_fragment_Tag
{
335 struct xref_dest_Tag
{
336 enum { NONE
, PAGE
, URL
} type
;
352 struct outline_element_Tag
{
353 int level
; /* 0=title 1=C 2=H 3=S 4=S2... */
358 * Functions exported from bk_paper.c
360 int kern_cmp(void *, void *); /* use when setting up kern_pairs */
361 void font_index_glyphs(font_info
*fi
);
362 int find_glyph(font_info
*fi
, char const *name
);
366 * Functions and data exported from psdata.c.
368 wchar_t ps_glyph_to_unicode(char const *glyph
);
369 extern const char *const ps_std_glyphs
[];
370 void init_std_fonts(void);
371 const int *ps_std_font_widths(char const *fontname
);
372 const kern_pair
*ps_std_font_kerns(char const *fontname
);
375 * Function from bk_pdf.c borrowed by bk_ps.c
377 char *pdf_outline_convert(wchar_t *s
, int *len
);