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