Mercurial > hgrepos > Python2 > PyMuPDF
comparison mupdf-source/source/fitz/trace-device.c @ 2:b50eed0cc0ef upstream
ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4.
The directory name has changed: no version number in the expanded directory now.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Mon, 15 Sep 2025 11:43:07 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 1:1d09e1dec1d9 | 2:b50eed0cc0ef |
|---|---|
| 1 // Copyright (C) 2004-2024 Artifex Software, Inc. | |
| 2 // | |
| 3 // This file is part of MuPDF. | |
| 4 // | |
| 5 // MuPDF is free software: you can redistribute it and/or modify it under the | |
| 6 // terms of the GNU Affero General Public License as published by the Free | |
| 7 // Software Foundation, either version 3 of the License, or (at your option) | |
| 8 // any later version. | |
| 9 // | |
| 10 // MuPDF is distributed in the hope that it will be useful, but WITHOUT ANY | |
| 11 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | |
| 12 // FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more | |
| 13 // details. | |
| 14 // | |
| 15 // You should have received a copy of the GNU Affero General Public License | |
| 16 // along with MuPDF. If not, see <https://www.gnu.org/licenses/agpl-3.0.en.html> | |
| 17 // | |
| 18 // Alternative licensing terms are available from the licensor. | |
| 19 // For commercial licensing, see <https://www.artifex.com/> or contact | |
| 20 // Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco, | |
| 21 // CA 94129, USA, for further information. | |
| 22 | |
| 23 #include "mupdf/fitz.h" | |
| 24 | |
| 25 typedef struct | |
| 26 { | |
| 27 fz_device super; | |
| 28 fz_output *out; | |
| 29 int depth; | |
| 30 } fz_trace_device; | |
| 31 | |
| 32 static void fz_trace_indent(fz_context *ctx, fz_output *out, int depth) | |
| 33 { | |
| 34 while (depth-- > 0) | |
| 35 fz_write_string(ctx, out, " "); | |
| 36 } | |
| 37 | |
| 38 static void | |
| 39 fz_trace_matrix(fz_context *ctx, fz_output *out, fz_matrix ctm) | |
| 40 { | |
| 41 fz_write_printf(ctx, out, " transform=\"%g %g %g %g %g %g\"", ctm.a, ctm.b, ctm.c, ctm.d, ctm.e, ctm.f); | |
| 42 } | |
| 43 | |
| 44 static void | |
| 45 fz_trace_color(fz_context *ctx, fz_output *out, fz_colorspace *colorspace, const float *color, float alpha) | |
| 46 { | |
| 47 int i, n; | |
| 48 if (colorspace) | |
| 49 { | |
| 50 n = fz_colorspace_n(ctx, colorspace); | |
| 51 fz_write_printf(ctx, out, " colorspace=\"%s\" color=\"", fz_colorspace_name(ctx, colorspace)); | |
| 52 for (i = 0; i < n; i++) | |
| 53 fz_write_printf(ctx, out, "%s%g", i == 0 ? "" : " ", color[i]); | |
| 54 fz_write_printf(ctx, out, "\""); | |
| 55 } | |
| 56 if (alpha < 1) | |
| 57 fz_write_printf(ctx, out, " alpha=\"%g\"", alpha); | |
| 58 } | |
| 59 | |
| 60 static void | |
| 61 fz_trace_color_params(fz_context *ctx, fz_output *out, fz_color_params color_params) | |
| 62 { | |
| 63 fz_write_printf(ctx, out, " ri=\"%d\" bp=\"%d\" op=\"%d\" opm=\"%d\"", | |
| 64 color_params.ri, color_params.bp, color_params.op, color_params.opm); | |
| 65 } | |
| 66 | |
| 67 static void | |
| 68 fz_trace_text_span(fz_context *ctx, fz_output *out, fz_text_span *span, int depth) | |
| 69 { | |
| 70 int i; | |
| 71 fz_trace_indent(ctx, out, depth); | |
| 72 fz_write_printf(ctx, out, "<span font=\"%s\" wmode=\"%d\" bidi=\"%d\"", fz_font_name(ctx, span->font), span->wmode, span->bidi_level); | |
| 73 if (span->language != FZ_LANG_UNSET) | |
| 74 { | |
| 75 char text[8]; | |
| 76 fz_string_from_text_language(text, span->language); | |
| 77 fz_write_printf(ctx, out, " lang=\"%s\"", text); | |
| 78 } | |
| 79 fz_write_printf(ctx, out, " trm=\"%g %g %g %g\">\n", span->trm.a, span->trm.b, span->trm.c, span->trm.d); | |
| 80 for (i = 0; i < span->len; i++) | |
| 81 { | |
| 82 int ucs = span->items[i].ucs; | |
| 83 | |
| 84 fz_trace_indent(ctx, out, depth+1); | |
| 85 fz_write_string(ctx, out, "<g"); | |
| 86 if (span->items[i].ucs >= 0) | |
| 87 { | |
| 88 fz_write_string(ctx, out, " unicode=\""); | |
| 89 switch (ucs) | |
| 90 { | |
| 91 default: | |
| 92 if (ucs < 32) | |
| 93 fz_write_printf(ctx, out, "&#x%x;", ucs); | |
| 94 else | |
| 95 fz_write_rune(ctx, out, ucs); | |
| 96 break; | |
| 97 case '&': fz_write_string(ctx, out, "&"); break; | |
| 98 case '\'': fz_write_string(ctx, out, "'"); break; | |
| 99 case '"': fz_write_string(ctx, out, """); break; | |
| 100 case '<': fz_write_string(ctx, out, "<"); break; | |
| 101 case '>': fz_write_string(ctx, out, ">"); break; | |
| 102 } | |
| 103 fz_write_string(ctx, out, "\""); | |
| 104 } | |
| 105 if (span->items[i].gid >= 0) | |
| 106 { | |
| 107 char name[32]; | |
| 108 fz_get_glyph_name(ctx, span->font, span->items[i].gid, name, sizeof name); | |
| 109 fz_write_printf(ctx, out, " glyph=\"%s\"", name); | |
| 110 } | |
| 111 | |
| 112 fz_write_printf(ctx, out, " x=\"%g\" y=\"%g\" adv=\"%g\"/>\n", span->items[i].x, span->items[i].y, span->items[i].adv); | |
| 113 } | |
| 114 fz_trace_indent(ctx, out, depth); | |
| 115 fz_write_string(ctx, out, "</span>\n"); | |
| 116 } | |
| 117 | |
| 118 static void | |
| 119 fz_trace_text(fz_context *ctx, fz_output *out, const fz_text *text, int depth) | |
| 120 { | |
| 121 fz_text_span *span; | |
| 122 for (span = text->head; span; span = span->next) | |
| 123 fz_trace_text_span(ctx, out, span, depth); | |
| 124 } | |
| 125 | |
| 126 static void | |
| 127 trace_moveto(fz_context *ctx, void *dev_, float x, float y) | |
| 128 { | |
| 129 fz_trace_device *dev = (fz_trace_device*)dev_; | |
| 130 fz_output *out = dev->out; | |
| 131 fz_trace_indent(ctx, out, dev->depth); | |
| 132 fz_write_printf(ctx, out, "<moveto x=\"%g\" y=\"%g\"/>\n", x, y); | |
| 133 } | |
| 134 | |
| 135 static void | |
| 136 trace_lineto(fz_context *ctx, void *dev_, float x, float y) | |
| 137 { | |
| 138 fz_trace_device *dev = (fz_trace_device*)dev_; | |
| 139 fz_output *out = dev->out; | |
| 140 fz_trace_indent(ctx, out, dev->depth); | |
| 141 fz_write_printf(ctx, out, "<lineto x=\"%g\" y=\"%g\"/>\n", x, y); | |
| 142 } | |
| 143 | |
| 144 static void | |
| 145 trace_curveto(fz_context *ctx, void *dev_, float x1, float y1, float x2, float y2, float x3, float y3) | |
| 146 { | |
| 147 fz_trace_device *dev = (fz_trace_device*)dev_; | |
| 148 fz_output *out = dev->out; | |
| 149 fz_trace_indent(ctx, out, dev->depth); | |
| 150 fz_write_printf(ctx, out, "<curveto x1=\"%g\" y1=\"%g\" x2=\"%g\" y2=\"%g\" x3=\"%g\" y3=\"%g\"/>\n", x1, y1, x2, y2, x3, y3); | |
| 151 } | |
| 152 | |
| 153 static void | |
| 154 trace_close(fz_context *ctx, void *dev_) | |
| 155 { | |
| 156 fz_trace_device *dev = (fz_trace_device*)dev_; | |
| 157 fz_output *out = dev->out; | |
| 158 fz_trace_indent(ctx, out, dev->depth); | |
| 159 fz_write_printf(ctx, out, "<closepath/>\n"); | |
| 160 } | |
| 161 | |
| 162 static const fz_path_walker trace_path_walker = | |
| 163 { | |
| 164 trace_moveto, | |
| 165 trace_lineto, | |
| 166 trace_curveto, | |
| 167 trace_close | |
| 168 }; | |
| 169 | |
| 170 static void | |
| 171 fz_trace_path(fz_context *ctx, fz_trace_device *dev, const fz_path *path) | |
| 172 { | |
| 173 dev->depth++; | |
| 174 fz_walk_path(ctx, path, &trace_path_walker, dev); | |
| 175 dev->depth--; | |
| 176 } | |
| 177 | |
| 178 static void | |
| 179 fz_trace_fill_path(fz_context *ctx, fz_device *dev_, const fz_path *path, int even_odd, fz_matrix ctm, | |
| 180 fz_colorspace *colorspace, const float *color, float alpha, fz_color_params color_params) | |
| 181 { | |
| 182 fz_trace_device *dev = (fz_trace_device*)dev_; | |
| 183 fz_output *out = dev->out; | |
| 184 fz_trace_indent(ctx, out, dev->depth); | |
| 185 fz_write_printf(ctx, out, "<fill_path"); | |
| 186 if (even_odd) | |
| 187 fz_write_printf(ctx, out, " winding=\"eofill\""); | |
| 188 else | |
| 189 fz_write_printf(ctx, out, " winding=\"nonzero\""); | |
| 190 fz_trace_color(ctx, out, colorspace, color, alpha); | |
| 191 fz_trace_color_params(ctx, out, color_params); | |
| 192 fz_trace_matrix(ctx, out, ctm); | |
| 193 fz_write_printf(ctx, out, ">\n"); | |
| 194 fz_trace_path(ctx, dev, path); | |
| 195 fz_trace_indent(ctx, out, dev->depth); | |
| 196 fz_write_printf(ctx, out, "</fill_path>\n"); | |
| 197 } | |
| 198 | |
| 199 static void | |
| 200 fz_trace_stroke_path(fz_context *ctx, fz_device *dev_, const fz_path *path, const fz_stroke_state *stroke, fz_matrix ctm, | |
| 201 fz_colorspace *colorspace, const float *color, float alpha, fz_color_params color_params) | |
| 202 { | |
| 203 fz_trace_device *dev = (fz_trace_device*)dev_; | |
| 204 fz_output *out = dev->out; | |
| 205 int i; | |
| 206 | |
| 207 fz_trace_indent(ctx, out, dev->depth); | |
| 208 fz_write_printf(ctx, out, "<stroke_path"); | |
| 209 fz_write_printf(ctx, out, " linewidth=\"%g\"", stroke->linewidth); | |
| 210 fz_write_printf(ctx, out, " miterlimit=\"%g\"", stroke->miterlimit); | |
| 211 fz_write_printf(ctx, out, " linecap=\"%d,%d,%d\"", stroke->start_cap, stroke->dash_cap, stroke->end_cap); | |
| 212 fz_write_printf(ctx, out, " linejoin=\"%d\"", stroke->linejoin); | |
| 213 | |
| 214 if (stroke->dash_len) | |
| 215 { | |
| 216 fz_write_printf(ctx, out, " dash_phase=\"%g\" dash=\"", stroke->dash_phase); | |
| 217 for (i = 0; i < stroke->dash_len; i++) | |
| 218 fz_write_printf(ctx, out, "%s%g", i > 0 ? " " : "", stroke->dash_list[i]); | |
| 219 fz_write_printf(ctx, out, "\""); | |
| 220 } | |
| 221 | |
| 222 fz_trace_color(ctx, out, colorspace, color, alpha); | |
| 223 fz_trace_color_params(ctx, out, color_params); | |
| 224 fz_trace_matrix(ctx, out, ctm); | |
| 225 fz_write_printf(ctx, out, ">\n"); | |
| 226 | |
| 227 fz_trace_path(ctx, dev, path); | |
| 228 | |
| 229 fz_trace_indent(ctx, out, dev->depth); | |
| 230 fz_write_printf(ctx, out, "</stroke_path>\n"); | |
| 231 } | |
| 232 | |
| 233 static void | |
| 234 fz_trace_clip_path(fz_context *ctx, fz_device *dev_, const fz_path *path, int even_odd, fz_matrix ctm, fz_rect scissor) | |
| 235 { | |
| 236 fz_trace_device *dev = (fz_trace_device*)dev_; | |
| 237 fz_output *out = dev->out; | |
| 238 fz_trace_indent(ctx, out, dev->depth); | |
| 239 fz_write_printf(ctx, out, "<clip_path"); | |
| 240 if (even_odd) | |
| 241 fz_write_printf(ctx, out, " winding=\"eofill\""); | |
| 242 else | |
| 243 fz_write_printf(ctx, out, " winding=\"nonzero\""); | |
| 244 fz_trace_matrix(ctx, out, ctm); | |
| 245 fz_write_printf(ctx, out, ">\n"); | |
| 246 fz_trace_path(ctx, dev, path); | |
| 247 fz_trace_indent(ctx, out, dev->depth); | |
| 248 fz_write_printf(ctx, out, "</clip_path>\n"); | |
| 249 dev->depth++; | |
| 250 } | |
| 251 | |
| 252 static void | |
| 253 fz_trace_clip_stroke_path(fz_context *ctx, fz_device *dev_, const fz_path *path, const fz_stroke_state *stroke, fz_matrix ctm, fz_rect scissor) | |
| 254 { | |
| 255 fz_trace_device *dev = (fz_trace_device*)dev_; | |
| 256 fz_output *out = dev->out; | |
| 257 fz_trace_indent(ctx, out, dev->depth); | |
| 258 fz_write_printf(ctx, out, "<clip_stroke_path"); | |
| 259 fz_trace_matrix(ctx, out, ctm); | |
| 260 fz_write_printf(ctx, out, ">\n"); | |
| 261 fz_trace_path(ctx, dev, path); | |
| 262 fz_trace_indent(ctx, out, dev->depth); | |
| 263 fz_write_printf(ctx, out, "</clip_stroke_path>\n"); | |
| 264 dev->depth++; | |
| 265 } | |
| 266 | |
| 267 static void | |
| 268 fz_trace_fill_text(fz_context *ctx, fz_device *dev_, const fz_text *text, fz_matrix ctm, | |
| 269 fz_colorspace *colorspace, const float *color, float alpha, fz_color_params color_params) | |
| 270 { | |
| 271 fz_trace_device *dev = (fz_trace_device*)dev_; | |
| 272 fz_output *out = dev->out; | |
| 273 fz_trace_indent(ctx, out, dev->depth); | |
| 274 fz_write_printf(ctx, out, "<fill_text"); | |
| 275 fz_trace_color(ctx, out, colorspace, color, alpha); | |
| 276 fz_trace_color_params(ctx, out, color_params); | |
| 277 fz_trace_matrix(ctx, out, ctm); | |
| 278 fz_write_printf(ctx, out, ">\n"); | |
| 279 fz_trace_text(ctx, out, text, dev->depth+1); | |
| 280 fz_trace_indent(ctx, out, dev->depth); | |
| 281 fz_write_printf(ctx, out, "</fill_text>\n"); | |
| 282 } | |
| 283 | |
| 284 static void | |
| 285 fz_trace_stroke_text(fz_context *ctx, fz_device *dev_, const fz_text *text, const fz_stroke_state *stroke, fz_matrix ctm, | |
| 286 fz_colorspace *colorspace, const float *color, float alpha, fz_color_params color_params) | |
| 287 { | |
| 288 fz_trace_device *dev = (fz_trace_device*)dev_; | |
| 289 fz_output *out = dev->out; | |
| 290 fz_trace_indent(ctx, out, dev->depth); | |
| 291 fz_write_printf(ctx, out, "<stroke_text"); | |
| 292 fz_trace_color(ctx, out, colorspace, color, alpha); | |
| 293 fz_trace_color_params(ctx, out, color_params); | |
| 294 fz_trace_matrix(ctx, out, ctm); | |
| 295 fz_write_printf(ctx, out, ">\n"); | |
| 296 fz_trace_text(ctx, out, text, dev->depth+1); | |
| 297 fz_trace_indent(ctx, out, dev->depth); | |
| 298 fz_write_printf(ctx, out, "</stroke_text>\n"); | |
| 299 } | |
| 300 | |
| 301 static void | |
| 302 fz_trace_clip_text(fz_context *ctx, fz_device *dev_, const fz_text *text, fz_matrix ctm, fz_rect scissor) | |
| 303 { | |
| 304 fz_trace_device *dev = (fz_trace_device*)dev_; | |
| 305 fz_output *out = dev->out; | |
| 306 fz_trace_indent(ctx, out, dev->depth); | |
| 307 fz_write_printf(ctx, out, "<clip_text"); | |
| 308 fz_trace_matrix(ctx, out, ctm); | |
| 309 fz_write_printf(ctx, out, ">\n"); | |
| 310 fz_trace_text(ctx, out, text, dev->depth+1); | |
| 311 fz_trace_indent(ctx, out, dev->depth); | |
| 312 fz_write_printf(ctx, out, "</clip_text>\n"); | |
| 313 dev->depth++; | |
| 314 } | |
| 315 | |
| 316 static void | |
| 317 fz_trace_clip_stroke_text(fz_context *ctx, fz_device *dev_, const fz_text *text, const fz_stroke_state *stroke, fz_matrix ctm, fz_rect scissor) | |
| 318 { | |
| 319 fz_trace_device *dev = (fz_trace_device*)dev_; | |
| 320 fz_output *out = dev->out; | |
| 321 fz_trace_indent(ctx, out, dev->depth); | |
| 322 fz_write_printf(ctx, out, "<clip_stroke_text"); | |
| 323 fz_trace_matrix(ctx, out, ctm); | |
| 324 fz_write_printf(ctx, out, ">\n"); | |
| 325 fz_trace_text(ctx, out, text, dev->depth+1); | |
| 326 fz_trace_indent(ctx, out, dev->depth); | |
| 327 fz_write_printf(ctx, out, "</clip_stroke_text>\n"); | |
| 328 dev->depth++; | |
| 329 } | |
| 330 | |
| 331 static void | |
| 332 fz_trace_ignore_text(fz_context *ctx, fz_device *dev_, const fz_text *text, fz_matrix ctm) | |
| 333 { | |
| 334 fz_trace_device *dev = (fz_trace_device*)dev_; | |
| 335 fz_output *out = dev->out; | |
| 336 fz_trace_indent(ctx, out, dev->depth); | |
| 337 fz_write_printf(ctx, out, "<ignore_text"); | |
| 338 fz_trace_matrix(ctx, out, ctm); | |
| 339 fz_write_printf(ctx, out, ">\n"); | |
| 340 fz_trace_text(ctx, out, text, dev->depth+1); | |
| 341 fz_trace_indent(ctx, out, dev->depth); | |
| 342 fz_write_printf(ctx, out, "</ignore_text>\n"); | |
| 343 } | |
| 344 | |
| 345 static void | |
| 346 fz_trace_fill_image(fz_context *ctx, fz_device *dev_, fz_image *image, fz_matrix ctm, float alpha, fz_color_params color_params) | |
| 347 { | |
| 348 fz_trace_device *dev = (fz_trace_device*)dev_; | |
| 349 fz_output *out = dev->out; | |
| 350 fz_trace_indent(ctx, out, dev->depth); | |
| 351 fz_write_printf(ctx, out, "<fill_image alpha=\"%g\"", alpha); | |
| 352 if (image->colorspace) | |
| 353 fz_write_printf(ctx, out, " colorspace=\"%s\"", fz_colorspace_name(ctx, image->colorspace)); | |
| 354 fz_trace_color_params(ctx, out, color_params); | |
| 355 fz_trace_matrix(ctx, out, ctm); | |
| 356 fz_write_printf(ctx, out, " width=\"%d\" height=\"%d\"", image->w, image->h); | |
| 357 fz_write_printf(ctx, out, "/>\n"); | |
| 358 } | |
| 359 | |
| 360 static void | |
| 361 fz_trace_fill_shade(fz_context *ctx, fz_device *dev_, fz_shade *shade, fz_matrix ctm, float alpha, fz_color_params color_params) | |
| 362 { | |
| 363 fz_trace_device *dev = (fz_trace_device*)dev_; | |
| 364 fz_output *out = dev->out; | |
| 365 fz_trace_indent(ctx, out, dev->depth); | |
| 366 fz_write_printf(ctx, out, "<fill_shade alpha=\"%g\"", alpha); | |
| 367 fz_trace_matrix(ctx, out, ctm); | |
| 368 fz_write_printf(ctx, out, " pattern_matrix=\"%g %g %g %g %g %g\"", | |
| 369 shade->matrix.a, | |
| 370 shade->matrix.b, | |
| 371 shade->matrix.c, | |
| 372 shade->matrix.d, | |
| 373 shade->matrix.e, | |
| 374 shade->matrix.f); | |
| 375 fz_write_printf(ctx, out, " colorspace=\"%s\"", fz_colorspace_name(ctx, shade->colorspace)); | |
| 376 fz_trace_color_params(ctx, out, color_params); | |
| 377 // TODO: use_background and background | |
| 378 // TODO: use_function and function | |
| 379 switch (shade->type) | |
| 380 { | |
| 381 case FZ_FUNCTION_BASED: | |
| 382 fz_write_printf(ctx, out, " type=\"function\""); | |
| 383 fz_write_printf(ctx, out, " function_matrix=\"%g %g %g %g %g %g\"", | |
| 384 shade->u.f.matrix.a, | |
| 385 shade->u.f.matrix.b, | |
| 386 shade->u.f.matrix.c, | |
| 387 shade->u.f.matrix.d, | |
| 388 shade->u.f.matrix.e, | |
| 389 shade->u.f.matrix.f); | |
| 390 fz_write_printf(ctx, out, " domain=\"%g %g %g %g\"", | |
| 391 shade->u.f.domain[0][0], | |
| 392 shade->u.f.domain[0][1], | |
| 393 shade->u.f.domain[1][0], | |
| 394 shade->u.f.domain[1][1]); | |
| 395 fz_write_printf(ctx, out, " samples=\"%d %d\"", | |
| 396 shade->u.f.xdivs, | |
| 397 shade->u.f.ydivs); | |
| 398 fz_write_printf(ctx, out, "/>\n"); | |
| 399 break; | |
| 400 case FZ_LINEAR: | |
| 401 fz_write_printf(ctx, out, " type=\"linear\""); | |
| 402 fz_write_printf(ctx, out, " extend=\"%d %d\"", | |
| 403 shade->u.l_or_r.extend[0], | |
| 404 shade->u.l_or_r.extend[1]); | |
| 405 fz_write_printf(ctx, out, " start=\"%g %g\"", | |
| 406 shade->u.l_or_r.coords[0][0], | |
| 407 shade->u.l_or_r.coords[0][1]); | |
| 408 fz_write_printf(ctx, out, " end=\"%g %g\"", | |
| 409 shade->u.l_or_r.coords[1][0], | |
| 410 shade->u.l_or_r.coords[1][1]); | |
| 411 fz_write_printf(ctx, out, "/>\n"); | |
| 412 break; | |
| 413 case FZ_RADIAL: | |
| 414 fz_write_printf(ctx, out, " type=\"radial\""); | |
| 415 fz_write_printf(ctx, out, " extend=\"%d %d\"", | |
| 416 shade->u.l_or_r.extend[0], | |
| 417 shade->u.l_or_r.extend[1]); | |
| 418 fz_write_printf(ctx, out, " inner=\"%g %g %g\"", | |
| 419 shade->u.l_or_r.coords[0][0], | |
| 420 shade->u.l_or_r.coords[0][1], | |
| 421 shade->u.l_or_r.coords[0][2]); | |
| 422 fz_write_printf(ctx, out, " outer=\"%g %g %g\"", | |
| 423 shade->u.l_or_r.coords[1][0], | |
| 424 shade->u.l_or_r.coords[1][1], | |
| 425 shade->u.l_or_r.coords[1][2]); | |
| 426 fz_write_printf(ctx, out, "/>\n"); | |
| 427 break; | |
| 428 default: | |
| 429 fz_write_printf(ctx, out, " type=\"mesh\"/>\n"); | |
| 430 break; | |
| 431 } | |
| 432 } | |
| 433 | |
| 434 static void | |
| 435 fz_trace_fill_image_mask(fz_context *ctx, fz_device *dev_, fz_image *image, fz_matrix ctm, | |
| 436 fz_colorspace *colorspace, const float *color, float alpha, fz_color_params color_params) | |
| 437 { | |
| 438 fz_trace_device *dev = (fz_trace_device*)dev_; | |
| 439 fz_output *out = dev->out; | |
| 440 fz_trace_indent(ctx, out, dev->depth); | |
| 441 fz_write_printf(ctx, out, "<fill_image_mask"); | |
| 442 fz_trace_matrix(ctx, out, ctm); | |
| 443 fz_trace_color(ctx, out, colorspace, color, alpha); | |
| 444 fz_trace_color_params(ctx, out, color_params); | |
| 445 fz_write_printf(ctx, out, " width=\"%d\" height=\"%d\"", image->w, image->h); | |
| 446 fz_write_printf(ctx, out, "/>\n"); | |
| 447 } | |
| 448 | |
| 449 static void | |
| 450 fz_trace_clip_image_mask(fz_context *ctx, fz_device *dev_, fz_image *image, fz_matrix ctm, fz_rect scissor) | |
| 451 { | |
| 452 fz_trace_device *dev = (fz_trace_device*)dev_; | |
| 453 fz_output *out = dev->out; | |
| 454 fz_trace_indent(ctx, out, dev->depth); | |
| 455 fz_write_printf(ctx, out, "<clip_image_mask"); | |
| 456 fz_trace_matrix(ctx, out, ctm); | |
| 457 fz_write_printf(ctx, out, " width=\"%d\" height=\"%d\"", image->w, image->h); | |
| 458 fz_write_printf(ctx, out, "/>\n"); | |
| 459 dev->depth++; | |
| 460 } | |
| 461 | |
| 462 static void | |
| 463 fz_trace_pop_clip(fz_context *ctx, fz_device *dev_) | |
| 464 { | |
| 465 fz_trace_device *dev = (fz_trace_device*)dev_; | |
| 466 fz_output *out = dev->out; | |
| 467 dev->depth--; | |
| 468 fz_trace_indent(ctx, out, dev->depth); | |
| 469 fz_write_printf(ctx, out, "<pop_clip/>\n"); | |
| 470 } | |
| 471 | |
| 472 static void | |
| 473 fz_trace_begin_mask(fz_context *ctx, fz_device *dev_, fz_rect bbox, int luminosity, fz_colorspace *colorspace, const float *color, fz_color_params color_params) | |
| 474 { | |
| 475 fz_trace_device *dev = (fz_trace_device*)dev_; | |
| 476 fz_output *out = dev->out; | |
| 477 fz_trace_indent(ctx, out, dev->depth); | |
| 478 fz_write_printf(ctx, out, "<clip_mask bbox=\"%g %g %g %g\" s=\"%s\"", | |
| 479 bbox.x0, bbox.y0, bbox.x1, bbox.y1, | |
| 480 luminosity ? "luminosity" : "alpha"); | |
| 481 fz_trace_color_params(ctx, out, color_params); | |
| 482 fz_write_printf(ctx, out, ">\n"); | |
| 483 dev->depth++; | |
| 484 } | |
| 485 | |
| 486 static void | |
| 487 fz_trace_end_mask(fz_context *ctx, fz_device *dev_, fz_function *tr) | |
| 488 { | |
| 489 fz_trace_device *dev = (fz_trace_device*)dev_; | |
| 490 fz_output *out = dev->out; | |
| 491 dev->depth--; | |
| 492 fz_trace_indent(ctx, out, dev->depth); | |
| 493 fz_write_printf(ctx, out, "</clip_mask%s>\n", tr ? " (with TR)" : ""); | |
| 494 dev->depth++; | |
| 495 } | |
| 496 | |
| 497 static void | |
| 498 fz_trace_begin_group(fz_context *ctx, fz_device *dev_, fz_rect bbox, fz_colorspace *cs, int isolated, int knockout, int blendmode, float alpha) | |
| 499 { | |
| 500 fz_trace_device *dev = (fz_trace_device*)dev_; | |
| 501 fz_output *out = dev->out; | |
| 502 fz_trace_indent(ctx, out, dev->depth); | |
| 503 fz_write_printf(ctx, out, "<group bbox=\"%g %g %g %g\" isolated=\"%d\" knockout=\"%d\" blendmode=\"%s\" alpha=\"%g\">\n", | |
| 504 bbox.x0, bbox.y0, bbox.x1, bbox.y1, | |
| 505 isolated, knockout, fz_blendmode_name(blendmode), alpha); | |
| 506 dev->depth++; | |
| 507 } | |
| 508 | |
| 509 static void | |
| 510 fz_trace_end_group(fz_context *ctx, fz_device *dev_) | |
| 511 { | |
| 512 fz_trace_device *dev = (fz_trace_device*)dev_; | |
| 513 fz_output *out = dev->out; | |
| 514 dev->depth--; | |
| 515 fz_trace_indent(ctx, out, dev->depth); | |
| 516 fz_write_printf(ctx, out, "</group>\n"); | |
| 517 } | |
| 518 | |
| 519 static int | |
| 520 fz_trace_begin_tile(fz_context *ctx, fz_device *dev_, fz_rect area, fz_rect view, float xstep, float ystep, fz_matrix ctm, int id, int doc_id) | |
| 521 { | |
| 522 fz_trace_device *dev = (fz_trace_device*)dev_; | |
| 523 fz_output *out = dev->out; | |
| 524 fz_trace_indent(ctx, out, dev->depth); | |
| 525 fz_write_printf(ctx, out, "<tile id=\"%d\" doc_id=\"%d\"", id, doc_id); | |
| 526 fz_write_printf(ctx, out, " area=\"%g %g %g %g\"", area.x0, area.y0, area.x1, area.y1); | |
| 527 fz_write_printf(ctx, out, " view=\"%g %g %g %g\"", view.x0, view.y0, view.x1, view.y1); | |
| 528 fz_write_printf(ctx, out, " xstep=\"%g\" ystep=\"%g\"", xstep, ystep); | |
| 529 fz_trace_matrix(ctx, out, ctm); | |
| 530 fz_write_printf(ctx, out, ">\n"); | |
| 531 dev->depth++; | |
| 532 return 0; | |
| 533 } | |
| 534 | |
| 535 static void | |
| 536 fz_trace_end_tile(fz_context *ctx, fz_device *dev_) | |
| 537 { | |
| 538 fz_trace_device *dev = (fz_trace_device*)dev_; | |
| 539 fz_output *out = dev->out; | |
| 540 dev->depth--; | |
| 541 fz_trace_indent(ctx, out, dev->depth); | |
| 542 fz_write_printf(ctx, out, "</tile>\n"); | |
| 543 } | |
| 544 | |
| 545 static void | |
| 546 fz_trace_begin_layer(fz_context *ctx, fz_device *dev_, const char *name) | |
| 547 { | |
| 548 fz_trace_device *dev = (fz_trace_device*)dev_; | |
| 549 fz_output *out = dev->out; | |
| 550 fz_trace_indent(ctx, out, dev->depth); | |
| 551 fz_write_printf(ctx, out, "<layer name=\"%s\">\n", name ? name : ""); | |
| 552 dev->depth++; | |
| 553 } | |
| 554 | |
| 555 static void | |
| 556 fz_trace_end_layer(fz_context *ctx, fz_device *dev_) | |
| 557 { | |
| 558 fz_trace_device *dev = (fz_trace_device*)dev_; | |
| 559 fz_output *out = dev->out; | |
| 560 dev->depth--; | |
| 561 fz_trace_indent(ctx, out, dev->depth); | |
| 562 fz_write_printf(ctx, out, "</layer>\n"); | |
| 563 } | |
| 564 | |
| 565 static void | |
| 566 fz_trace_begin_structure(fz_context *ctx, fz_device *dev_, fz_structure standard, const char *raw, int idx) | |
| 567 { | |
| 568 fz_trace_device *dev = (fz_trace_device*)dev_; | |
| 569 fz_output *out = dev->out; | |
| 570 const char *str = fz_structure_to_string(standard); | |
| 571 fz_trace_indent(ctx, out, dev->depth); | |
| 572 fz_write_printf(ctx, out, "<structure standard=\"%s\"", str); | |
| 573 if (raw == NULL) | |
| 574 raw = ""; | |
| 575 if (strcmp(str, raw)) | |
| 576 fz_write_printf(ctx, out, " raw=\"%s\"", raw); | |
| 577 if (idx != 0) | |
| 578 fz_write_printf(ctx, out, " idx=\"%d\"", idx); | |
| 579 fz_write_printf(ctx, out, ">\n"); | |
| 580 dev->depth++; | |
| 581 } | |
| 582 | |
| 583 static void | |
| 584 fz_trace_end_structure(fz_context *ctx, fz_device *dev_) | |
| 585 { | |
| 586 fz_trace_device *dev = (fz_trace_device*)dev_; | |
| 587 fz_output *out = dev->out; | |
| 588 dev->depth--; | |
| 589 fz_trace_indent(ctx, out, dev->depth); | |
| 590 fz_write_printf(ctx, out, "</structure>\n"); | |
| 591 } | |
| 592 | |
| 593 static const char * | |
| 594 metatext_type(fz_metatext meta) | |
| 595 { | |
| 596 switch (meta) | |
| 597 { | |
| 598 case FZ_METATEXT_ABBREVIATION: | |
| 599 return "abbreviation"; | |
| 600 case FZ_METATEXT_ACTUALTEXT: | |
| 601 return "actualtext"; | |
| 602 case FZ_METATEXT_ALT: | |
| 603 return "alt"; | |
| 604 case FZ_METATEXT_TITLE: | |
| 605 return "title"; | |
| 606 } | |
| 607 return "????"; | |
| 608 } | |
| 609 | |
| 610 static void | |
| 611 fz_trace_begin_metatext(fz_context *ctx, fz_device *dev_, fz_metatext meta, const char *txt) | |
| 612 { | |
| 613 fz_trace_device *dev = (fz_trace_device*)dev_; | |
| 614 fz_output *out = dev->out; | |
| 615 const char *type = metatext_type(meta); | |
| 616 fz_trace_indent(ctx, out, dev->depth); | |
| 617 fz_write_printf(ctx, out, "<metatext type=\"%s\" txt=\"%s\">\n", type, txt ? txt : ""); | |
| 618 dev->depth++; | |
| 619 } | |
| 620 | |
| 621 static void | |
| 622 fz_trace_end_metatext(fz_context *ctx, fz_device *dev_) | |
| 623 { | |
| 624 fz_trace_device *dev = (fz_trace_device*)dev_; | |
| 625 fz_output *out = dev->out; | |
| 626 dev->depth--; | |
| 627 fz_trace_indent(ctx, out, dev->depth); | |
| 628 fz_write_printf(ctx, out, "</metatext>\n"); | |
| 629 } | |
| 630 | |
| 631 static void | |
| 632 fz_trace_render_flags(fz_context *ctx, fz_device *dev_, int set, int clear) | |
| 633 { | |
| 634 fz_trace_device *dev = (fz_trace_device*)dev_; | |
| 635 fz_output *out = dev->out; | |
| 636 fz_trace_indent(ctx, out, dev->depth); | |
| 637 fz_write_printf(ctx, out, "<render_flags set=\"0x%x\" clear=\"0x%x\"/>\n", set, clear); | |
| 638 } | |
| 639 | |
| 640 static void | |
| 641 fz_trace_set_default_colorspaces(fz_context *ctx, fz_device *dev_, fz_default_colorspaces *dcs) | |
| 642 { | |
| 643 fz_trace_device *dev = (fz_trace_device*)dev_; | |
| 644 fz_output *out = dev->out; | |
| 645 fz_trace_indent(ctx, out, dev->depth); | |
| 646 fz_write_printf(ctx, out, "<set_default_colorspaces"); | |
| 647 fz_write_printf(ctx, out, " gray=\"%s\"", fz_colorspace_name(ctx, fz_default_gray(ctx, dcs))); | |
| 648 fz_write_printf(ctx, out, " rgb=\"%s\"", fz_colorspace_name(ctx, fz_default_rgb(ctx, dcs))); | |
| 649 fz_write_printf(ctx, out, " cmyk=\"%s\"", fz_colorspace_name(ctx, fz_default_cmyk(ctx, dcs))); | |
| 650 fz_write_printf(ctx, out, " oi=\"%s\"/>\n",fz_colorspace_name(ctx, fz_default_output_intent(ctx, dcs))); | |
| 651 } | |
| 652 | |
| 653 fz_device *fz_new_trace_device(fz_context *ctx, fz_output *out) | |
| 654 { | |
| 655 fz_trace_device *dev = fz_new_derived_device(ctx, fz_trace_device); | |
| 656 | |
| 657 dev->super.fill_path = fz_trace_fill_path; | |
| 658 dev->super.stroke_path = fz_trace_stroke_path; | |
| 659 dev->super.clip_path = fz_trace_clip_path; | |
| 660 dev->super.clip_stroke_path = fz_trace_clip_stroke_path; | |
| 661 | |
| 662 dev->super.fill_text = fz_trace_fill_text; | |
| 663 dev->super.stroke_text = fz_trace_stroke_text; | |
| 664 dev->super.clip_text = fz_trace_clip_text; | |
| 665 dev->super.clip_stroke_text = fz_trace_clip_stroke_text; | |
| 666 dev->super.ignore_text = fz_trace_ignore_text; | |
| 667 | |
| 668 dev->super.fill_shade = fz_trace_fill_shade; | |
| 669 dev->super.fill_image = fz_trace_fill_image; | |
| 670 dev->super.fill_image_mask = fz_trace_fill_image_mask; | |
| 671 dev->super.clip_image_mask = fz_trace_clip_image_mask; | |
| 672 | |
| 673 dev->super.pop_clip = fz_trace_pop_clip; | |
| 674 | |
| 675 dev->super.begin_mask = fz_trace_begin_mask; | |
| 676 dev->super.end_mask = fz_trace_end_mask; | |
| 677 dev->super.begin_group = fz_trace_begin_group; | |
| 678 dev->super.end_group = fz_trace_end_group; | |
| 679 | |
| 680 dev->super.begin_tile = fz_trace_begin_tile; | |
| 681 dev->super.end_tile = fz_trace_end_tile; | |
| 682 | |
| 683 dev->super.begin_layer = fz_trace_begin_layer; | |
| 684 dev->super.end_layer = fz_trace_end_layer; | |
| 685 | |
| 686 dev->super.begin_structure = fz_trace_begin_structure; | |
| 687 dev->super.end_structure = fz_trace_end_structure; | |
| 688 | |
| 689 dev->super.begin_metatext = fz_trace_begin_metatext; | |
| 690 dev->super.end_metatext = fz_trace_end_metatext; | |
| 691 | |
| 692 dev->super.render_flags = fz_trace_render_flags; | |
| 693 dev->super.set_default_colorspaces = fz_trace_set_default_colorspaces; | |
| 694 | |
| 695 dev->out = out; | |
| 696 | |
| 697 return (fz_device*)dev; | |
| 698 } |
