1 /* 2 * This program is free software; you can redistribute it and/or 3 * modify it under the terms of the GNU General Public 4 * License as published by the Free Software Foundation; either 5 * version 2 of the License, or (at your option) any later version. 6 * 7 * This software is distributed in the hope that it will be useful, 8 * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 10 * General Public License for more details. 11 * 12 * You should have received a copy of the GNU General Public License 13 * along with this program. If not, see <http://www.gnu.org/licenses/>. 14 */ 15 16 typedef struct XrefTable { 17 int *data; 18 int last; 19 int n_alloc; 20 } XrefTable; 21 22 typedef struct PdfPageDesc { 23 struct PdfObj *resources, *mediabox, *contents; 24 int rotate; 25 } PdfPageDesc; 26 27 typedef struct PdfInfo { 28 int startxref; 29 struct PdfObj *trailerdict; 30 int npages; 31 struct PdfPageDesc *pages; 32 } PdfInfo; 33 34 typedef struct PdfObj { 35 int type; 36 int intval; 37 double realval; 38 char *str; 39 int len, num; 40 struct PdfObj **elts; 41 char **names; 42 } PdfObj; 43 44 typedef struct PdfFont { 45 int n_obj; 46 gboolean used_in_this_page; 47 char *filename; 48 int font_id; 49 gboolean is_truetype; 50 int glyph_page; 51 int glyphmap[256]; 52 int advance[256]; 53 char *glyphpsnames[256]; 54 int num_glyphs_used; 55 // fields from the FT_Face 56 gdouble ft2ps; 57 int nglyphs; 58 int ascender, descender, xmin, xmax, ymin, ymax; // in PDF font units 59 gchar *fontname; 60 int flags; 61 } PdfFont; 62 63 typedef struct PdfImage { 64 int n_obj; 65 gboolean has_alpha; 66 int n_obj_smask; /* only if has_alpha */ 67 GdkPixbuf *pixbuf; 68 gboolean used_in_this_page; 69 } PdfImage; 70 71 72 #define PDFTYPE_CST 0 // intval: true=1, false=0, null=-1 73 #define PDFTYPE_INT 1 // intval 74 #define PDFTYPE_REAL 2 // realval 75 #define PDFTYPE_STRING 3 // str, len 76 #define PDFTYPE_NAME 4 // str 77 #define PDFTYPE_ARRAY 5 // num, elts 78 #define PDFTYPE_DICT 6 // num, elts, names 79 #define PDFTYPE_STREAM 7 // dict: num, elts, names; data: str, len 80 #define PDFTYPE_REF 8 // intval, num 81 82 struct PdfObj *parse_pdf_object(char **ptr, char *eof); 83 void free_pdfobj(struct PdfObj *obj); 84 struct PdfObj *dup_pdfobj(struct PdfObj *obj); 85 struct PdfObj *get_pdfobj(GString *pdfbuf, struct XrefTable *xref, struct PdfObj *obj); 86 void make_xref(struct XrefTable *xref, int nobj, int offset); 87 88 gboolean pdf_parse_info(GString *pdfbuf, struct PdfInfo *pdfinfo, struct XrefTable *xref); 89 90 // main printing functions 91 92 gboolean print_to_pdf(char *filename); 93 gboolean print_to_pdf_cairo(char *filename); 94 95 #if GTK_CHECK_VERSION(2, 10, 0) 96 void print_job_render_page(GtkPrintOperation *print, GtkPrintContext *context, gint pageno, gpointer user_data); 97 #endif 98