1 /* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ 2 /* cairo - a vector graphics library with display and print output 3 * 4 * Copyright © 2004 Red Hat, Inc 5 * Copyright © 2006 Red Hat, Inc 6 * Copyright © 2007 Adrian Johnson 7 * 8 * This library is free software; you can redistribute it and/or 9 * modify it either under the terms of the GNU Lesser General Public 10 * License version 2.1 as published by the Free Software Foundation 11 * (the "LGPL") or, at your option, under the terms of the Mozilla 12 * Public License Version 1.1 (the "MPL"). If you do not alter this 13 * notice, a recipient may use your version of this file under either 14 * the MPL or the LGPL. 15 * 16 * You should have received a copy of the LGPL along with this library 17 * in the file COPYING-LGPL-2.1; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA 19 * You should have received a copy of the MPL along with this library 20 * in the file COPYING-MPL-1.1 21 * 22 * The contents of this file are subject to the Mozilla Public License 23 * Version 1.1 (the "License"); you may not use this file except in 24 * compliance with the License. You may obtain a copy of the License at 25 * http://www.mozilla.org/MPL/ 26 * 27 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY 28 * OF ANY KIND, either express or implied. See the LGPL or the MPL for 29 * the specific language governing rights and limitations. 30 * 31 * The Original Code is the cairo graphics library. 32 * 33 * The Initial Developer of the Original Code is University of Southern 34 * California. 35 * 36 * Contributor(s): 37 * Kristian Høgsberg <krh@redhat.com> 38 * Carl Worth <cworth@cworth.org> 39 * Adrian Johnson <ajohnson@redneon.com> 40 */ 41 42 #ifndef CAIRO_PDF_OPERATORS_H 43 #define CAIRO_PDF_OPERATORS_H 44 45 #include "cairo-compiler-private.h" 46 #include "cairo-error-private.h" 47 #include "cairo-types-private.h" 48 49 /* The glyph buffer size is based on the expected maximum glyphs in a 50 * line so that an entire line can be emitted in as one string. If the 51 * glyphs in a line exceeds this size the only downside is the slight 52 * overhead of emitting two strings. 53 */ 54 #define PDF_GLYPH_BUFFER_SIZE 200 55 56 typedef cairo_int_status_t 57 (*cairo_pdf_operators_use_font_subset_t) (unsigned int font_id, 58 unsigned int subset_id, 59 void *closure); 60 61 typedef struct _cairo_pdf_glyph { 62 unsigned int glyph_index; 63 double x_position; 64 double x_advance; 65 } cairo_pdf_glyph_t; 66 67 typedef struct _cairo_pdf_operators { 68 cairo_output_stream_t *stream; 69 cairo_matrix_t cairo_to_pdf; 70 cairo_scaled_font_subsets_t *font_subsets; 71 cairo_pdf_operators_use_font_subset_t use_font_subset; 72 void *use_font_subset_closure; 73 cairo_bool_t ps_output; /* output is for PostScript */ 74 cairo_bool_t use_actual_text; 75 cairo_bool_t in_text_object; /* inside BT/ET pair */ 76 77 /* PDF text state */ 78 cairo_bool_t is_new_text_object; /* text object started but matrix and font not yet selected */ 79 unsigned int font_id; 80 unsigned int subset_id; 81 cairo_matrix_t text_matrix; /* PDF text matrix (Tlm in the PDF reference) */ 82 cairo_matrix_t cairo_to_pdftext; /* translate cairo coords to PDF text space */ 83 cairo_matrix_t font_matrix_inverse; 84 double cur_x; /* Current position in PDF text space (Tm in the PDF reference) */ 85 double cur_y; 86 int hex_width; 87 cairo_bool_t is_latin; 88 int num_glyphs; 89 double glyph_buf_x_pos; 90 cairo_pdf_glyph_t glyphs[PDF_GLYPH_BUFFER_SIZE]; 91 92 /* PDF line style */ 93 cairo_bool_t has_line_style; 94 double line_width; 95 cairo_line_cap_t line_cap; 96 cairo_line_join_t line_join; 97 double miter_limit; 98 cairo_bool_t has_dashes; 99 } cairo_pdf_operators_t; 100 101 cairo_private void 102 _cairo_pdf_operators_init (cairo_pdf_operators_t *pdf_operators, 103 cairo_output_stream_t *stream, 104 cairo_matrix_t *cairo_to_pdf, 105 cairo_scaled_font_subsets_t *font_subsets, 106 cairo_bool_t ps); 107 108 cairo_private cairo_status_t 109 _cairo_pdf_operators_fini (cairo_pdf_operators_t *pdf_operators); 110 111 cairo_private void 112 _cairo_pdf_operators_set_font_subsets_callback (cairo_pdf_operators_t *pdf_operators, 113 cairo_pdf_operators_use_font_subset_t use_font_subset, 114 void *closure); 115 116 cairo_private void 117 _cairo_pdf_operators_set_stream (cairo_pdf_operators_t *pdf_operators, 118 cairo_output_stream_t *stream); 119 120 121 cairo_private void 122 _cairo_pdf_operators_set_cairo_to_pdf_matrix (cairo_pdf_operators_t *pdf_operators, 123 cairo_matrix_t *cairo_to_pdf); 124 125 cairo_private void 126 _cairo_pdf_operators_enable_actual_text (cairo_pdf_operators_t *pdf_operators, 127 cairo_bool_t enable); 128 129 cairo_private cairo_status_t 130 _cairo_pdf_operators_flush (cairo_pdf_operators_t *pdf_operators); 131 132 cairo_private void 133 _cairo_pdf_operators_reset (cairo_pdf_operators_t *pdf_operators); 134 135 cairo_private cairo_int_status_t 136 _cairo_pdf_operators_clip (cairo_pdf_operators_t *pdf_operators, 137 const cairo_path_fixed_t *path, 138 cairo_fill_rule_t fill_rule); 139 140 cairo_private cairo_int_status_t 141 _cairo_pdf_operators_emit_stroke_style (cairo_pdf_operators_t *pdf_operators, 142 const cairo_stroke_style_t *style, 143 double scale); 144 145 cairo_private cairo_int_status_t 146 _cairo_pdf_operators_stroke (cairo_pdf_operators_t *pdf_operators, 147 const cairo_path_fixed_t *path, 148 const cairo_stroke_style_t *style, 149 const cairo_matrix_t *ctm, 150 const cairo_matrix_t *ctm_inverse); 151 152 cairo_private cairo_int_status_t 153 _cairo_pdf_operators_fill (cairo_pdf_operators_t *pdf_operators, 154 const cairo_path_fixed_t *path, 155 cairo_fill_rule_t fill_rule); 156 157 cairo_private cairo_int_status_t 158 _cairo_pdf_operators_fill_stroke (cairo_pdf_operators_t *pdf_operators, 159 const cairo_path_fixed_t *path, 160 cairo_fill_rule_t fill_rule, 161 const cairo_stroke_style_t *style, 162 const cairo_matrix_t *ctm, 163 const cairo_matrix_t *ctm_inverse); 164 165 cairo_private cairo_int_status_t 166 _cairo_pdf_operators_show_text_glyphs (cairo_pdf_operators_t *pdf_operators, 167 const char *utf8, 168 int utf8_len, 169 cairo_glyph_t *glyphs, 170 int num_glyphs, 171 const cairo_text_cluster_t *clusters, 172 int num_clusters, 173 cairo_text_cluster_flags_t cluster_flags, 174 cairo_scaled_font_t *scaled_font); 175 176 cairo_private cairo_int_status_t 177 _cairo_pdf_operators_tag_begin (cairo_pdf_operators_t *pdf_operators, 178 const char *tag_name, 179 int mcid); 180 181 cairo_private cairo_int_status_t 182 _cairo_pdf_operators_tag_end (cairo_pdf_operators_t *pdf_operators); 183 184 #endif /* CAIRO_PDF_OPERATORS_H */ 185