dev_trace.c 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. #include "fitz-internal.h"
  2. static void
  3. fz_trace_matrix(const fz_matrix *ctm)
  4. {
  5. printf(" matrix=\"%g %g %g %g %g %g\"",
  6. ctm->a, ctm->b, ctm->c, ctm->d, ctm->e, ctm->f);
  7. }
  8. static void
  9. fz_trace_trm(const fz_matrix *trm)
  10. {
  11. printf(" trm=\"%g %g %g %g\"",
  12. trm->a, trm->b, trm->c, trm->d);
  13. }
  14. static void
  15. fz_trace_color(fz_colorspace *colorspace, float *color, float alpha)
  16. {
  17. int i;
  18. printf(" colorspace=\"%s\" color=\"", colorspace->name);
  19. for (i = 0; i < colorspace->n; i++)
  20. printf("%s%g", i == 0 ? "" : " ", color[i]);
  21. printf("\"");
  22. if (alpha < 1)
  23. printf(" alpha=\"%g\"", alpha);
  24. }
  25. static void
  26. fz_trace_path(fz_path *path, int indent)
  27. {
  28. float x, y;
  29. int i = 0;
  30. int n;
  31. while (i < path->len)
  32. {
  33. for (n = 0; n < indent; n++)
  34. putchar(' ');
  35. switch (path->items[i++].k)
  36. {
  37. case FZ_MOVETO:
  38. x = path->items[i++].v;
  39. y = path->items[i++].v;
  40. printf("<moveto x=\"%g\" y=\"%g\"/>\n", x, y);
  41. break;
  42. case FZ_LINETO:
  43. x = path->items[i++].v;
  44. y = path->items[i++].v;
  45. printf("<lineto x=\"%g\" y=\"%g\"/>\n", x, y);
  46. break;
  47. case FZ_CURVETO:
  48. x = path->items[i++].v;
  49. y = path->items[i++].v;
  50. printf("<curveto x1=\"%g\" y1=\"%g\"", x, y);
  51. x = path->items[i++].v;
  52. y = path->items[i++].v;
  53. printf(" x2=\"%g\" y2=\"%g\"", x, y);
  54. x = path->items[i++].v;
  55. y = path->items[i++].v;
  56. printf(" x3=\"%g\" y3=\"%g\"/>\n", x, y);
  57. break;
  58. case FZ_CLOSE_PATH:
  59. printf("<closepath/>\n");
  60. break;
  61. }
  62. }
  63. }
  64. static void
  65. fz_trace_fill_path(fz_device *dev, fz_path *path, int even_odd, const fz_matrix *ctm,
  66. fz_colorspace *colorspace, float *color, float alpha)
  67. {
  68. printf("<fill_path");
  69. if (even_odd)
  70. printf(" winding=\"eofill\"");
  71. else
  72. printf(" winding=\"nonzero\"");
  73. fz_trace_color(colorspace, color, alpha);
  74. fz_trace_matrix(ctm);
  75. printf(">\n");
  76. fz_trace_path(path, 0);
  77. printf("</fill_path>\n");
  78. }
  79. static void
  80. fz_trace_stroke_path(fz_device *dev, fz_path *path, fz_stroke_state *stroke, const fz_matrix *ctm,
  81. fz_colorspace *colorspace, float *color, float alpha)
  82. {
  83. int i;
  84. printf("<stroke_path");
  85. printf(" linewidth=\"%g\"", stroke->linewidth);
  86. printf(" miterlimit=\"%g\"", stroke->miterlimit);
  87. printf(" linecap=\"%d,%d,%d\"", stroke->start_cap, stroke->dash_cap, stroke->end_cap);
  88. printf(" linejoin=\"%d\"", stroke->linejoin);
  89. if (stroke->dash_len)
  90. {
  91. printf(" dash_phase=\"%g\" dash=\"", stroke->dash_phase);
  92. for (i = 0; i < stroke->dash_len; i++)
  93. printf("%s%g", i > 0 ? " " : "", stroke->dash_list[i]);
  94. printf("\"");
  95. }
  96. fz_trace_color(colorspace, color, alpha);
  97. fz_trace_matrix(ctm);
  98. printf(">\n");
  99. fz_trace_path(path, 0);
  100. printf("</stroke_path>\n");
  101. }
  102. static void
  103. fz_trace_clip_path(fz_device *dev, fz_path *path, const fz_rect *rect, int even_odd, const fz_matrix *ctm)
  104. {
  105. printf("<clip_path");
  106. if (even_odd)
  107. printf(" winding=\"eofill\"");
  108. else
  109. printf(" winding=\"nonzero\"");
  110. fz_trace_matrix(ctm);
  111. printf(" contentbbox=\"%g %g %g %g\">\n", rect->x0, rect->y0, rect->x1, rect->y1);
  112. fz_trace_path(path, 0);
  113. printf("</clip_path>\n");
  114. }
  115. static void
  116. fz_trace_clip_stroke_path(fz_device *dev, fz_path *path, const fz_rect *rect, fz_stroke_state *stroke, const fz_matrix *ctm)
  117. {
  118. printf("<clip_stroke_path");
  119. fz_trace_matrix(ctm);
  120. printf(">\n");
  121. fz_trace_path(path, 0);
  122. printf("</clip_stroke_path>\n");
  123. }
  124. static void
  125. fz_trace_fill_text(fz_device *dev, fz_text *text, const fz_matrix *ctm,
  126. fz_colorspace *colorspace, float *color, float alpha)
  127. {
  128. printf("<fill_text font=\"%s\" wmode=\"%d\"", text->font->name, text->wmode);
  129. fz_trace_color(colorspace, color, alpha);
  130. fz_trace_matrix(ctm);
  131. fz_trace_trm(&text->trm);
  132. printf(">\n");
  133. fz_print_text(dev->ctx, stdout, text);
  134. printf("</fill_text>\n");
  135. }
  136. static void
  137. fz_trace_stroke_text(fz_device *dev, fz_text *text, fz_stroke_state *stroke, const fz_matrix *ctm,
  138. fz_colorspace *colorspace, float *color, float alpha)
  139. {
  140. printf("<stroke_text font=\"%s\" wmode=\"%d\"", text->font->name, text->wmode);
  141. fz_trace_color(colorspace, color, alpha);
  142. fz_trace_matrix(ctm);
  143. fz_trace_trm(&text->trm);
  144. printf(">\n");
  145. fz_print_text(dev->ctx, stdout, text);
  146. printf("</stroke_text>\n");
  147. }
  148. static void
  149. fz_trace_clip_text(fz_device *dev, fz_text *text, const fz_matrix *ctm, int accumulate)
  150. {
  151. printf("<clip_text font=\"%s\" wmode=\"%d\"", text->font->name, text->wmode);
  152. printf(" accumulate=\"%d\"", accumulate);
  153. fz_trace_matrix(ctm);
  154. fz_trace_trm(&text->trm);
  155. printf(">\n");
  156. fz_print_text(dev->ctx, stdout, text);
  157. printf("</clip_text>\n");
  158. }
  159. static void
  160. fz_trace_clip_stroke_text(fz_device *dev, fz_text *text, fz_stroke_state *stroke, const fz_matrix *ctm)
  161. {
  162. printf("<clip_stroke_text font=\"%s\" wmode=\"%d\"", text->font->name, text->wmode);
  163. fz_trace_matrix(ctm);
  164. fz_trace_trm(&text->trm);
  165. printf(">\n");
  166. fz_print_text(dev->ctx, stdout, text);
  167. printf("</clip_stroke_text>\n");
  168. }
  169. static void
  170. fz_trace_ignore_text(fz_device *dev, fz_text *text, const fz_matrix *ctm)
  171. {
  172. printf("<ignore_text font=\"%s\" wmode=\"%d\"", text->font->name, text->wmode);
  173. fz_trace_matrix(ctm);
  174. fz_trace_trm(&text->trm);
  175. printf(">\n");
  176. fz_print_text(dev->ctx, stdout, text);
  177. printf("</ignore_text>\n");
  178. }
  179. static void
  180. fz_trace_fill_image(fz_device *dev, fz_image *image, const fz_matrix *ctm, float alpha)
  181. {
  182. printf("<fill_image alpha=\"%g\"", alpha);
  183. fz_trace_matrix(ctm);
  184. printf(" width=\"%d\" height=\"%d\"", image->w, image->h);
  185. printf("/>\n");
  186. }
  187. static void
  188. fz_trace_fill_shade(fz_device *dev, fz_shade *shade, const fz_matrix *ctm, float alpha)
  189. {
  190. printf("<fill_shade alpha=\"%g\"", alpha);
  191. fz_trace_matrix(ctm);
  192. printf("/>\n");
  193. }
  194. static void
  195. fz_trace_fill_image_mask(fz_device *dev, fz_image *image, const fz_matrix *ctm,
  196. fz_colorspace *colorspace, float *color, float alpha)
  197. {
  198. printf("<fill_image_mask");
  199. fz_trace_matrix(ctm);
  200. fz_trace_color(colorspace, color, alpha);
  201. printf(" width=\"%d\" height=\"%d\"", image->w, image->h);
  202. printf("/>\n");
  203. }
  204. static void
  205. fz_trace_clip_image_mask(fz_device *dev, fz_image *image, const fz_rect *rect, const fz_matrix *ctm)
  206. {
  207. printf("<clip_image_mask");
  208. fz_trace_matrix(ctm);
  209. printf(" width=\"%d\" height=\"%d\"", image->w, image->h);
  210. printf("/>\n");
  211. }
  212. static void
  213. fz_trace_pop_clip(fz_device *dev)
  214. {
  215. printf("<pop_clip/>\n");
  216. }
  217. static void
  218. fz_trace_begin_mask(fz_device *dev, const fz_rect *bbox, int luminosity, fz_colorspace *colorspace, float *color)
  219. {
  220. printf("<mask bbox=\"%g %g %g %g\" s=\"%s\"",
  221. bbox->x0, bbox->y0, bbox->x1, bbox->y1,
  222. luminosity ? "luminosity" : "alpha");
  223. printf(">\n");
  224. }
  225. static void
  226. fz_trace_end_mask(fz_device *dev)
  227. {
  228. printf("</mask>\n");
  229. }
  230. static void
  231. fz_trace_begin_group(fz_device *dev, const fz_rect *bbox, int isolated, int knockout, int blendmode, float alpha)
  232. {
  233. printf("<group bbox=\"%g %g %g %g\" isolated=\"%d\" knockout=\"%d\" blendmode=\"%s\" alpha=\"%g\">\n",
  234. bbox->x0, bbox->y0, bbox->x1, bbox->y1,
  235. isolated, knockout, fz_blendmode_name(blendmode), alpha);
  236. }
  237. static void
  238. fz_trace_end_group(fz_device *dev)
  239. {
  240. printf("</group>\n");
  241. }
  242. static void
  243. fz_trace_begin_tile(fz_device *dev, const fz_rect *area, const fz_rect *view, float xstep, float ystep, const fz_matrix *ctm)
  244. {
  245. printf("<tile");
  246. printf(" area=\"%g %g %g %g\"", area->x0, area->y0, area->x1, area->y1);
  247. printf(" view=\"%g %g %g %g\"", view->x0, view->y0, view->x1, view->y1);
  248. printf(" xstep=\"%g\" ystep=\"%g\"", xstep, ystep);
  249. fz_trace_matrix(ctm);
  250. printf(">\n");
  251. }
  252. static void
  253. fz_trace_end_tile(fz_device *dev)
  254. {
  255. printf("</tile>\n");
  256. }
  257. fz_device *fz_new_trace_device(fz_context *ctx)
  258. {
  259. fz_device *dev = fz_new_device(ctx, NULL);
  260. dev->fill_path = fz_trace_fill_path;
  261. dev->stroke_path = fz_trace_stroke_path;
  262. dev->clip_path = fz_trace_clip_path;
  263. dev->clip_stroke_path = fz_trace_clip_stroke_path;
  264. dev->fill_text = fz_trace_fill_text;
  265. dev->stroke_text = fz_trace_stroke_text;
  266. dev->clip_text = fz_trace_clip_text;
  267. dev->clip_stroke_text = fz_trace_clip_stroke_text;
  268. dev->ignore_text = fz_trace_ignore_text;
  269. dev->fill_shade = fz_trace_fill_shade;
  270. dev->fill_image = fz_trace_fill_image;
  271. dev->fill_image_mask = fz_trace_fill_image_mask;
  272. dev->clip_image_mask = fz_trace_clip_image_mask;
  273. dev->pop_clip = fz_trace_pop_clip;
  274. dev->begin_mask = fz_trace_begin_mask;
  275. dev->end_mask = fz_trace_end_mask;
  276. dev->begin_group = fz_trace_begin_group;
  277. dev->end_group = fz_trace_end_group;
  278. dev->begin_tile = fz_trace_begin_tile;
  279. dev->end_tile = fz_trace_end_tile;
  280. return dev;
  281. }