dev_null.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. #include "fitz-internal.h"
  2. fz_device *
  3. fz_new_device(fz_context *ctx, void *user)
  4. {
  5. fz_device *dev = fz_malloc_struct(ctx, fz_device);
  6. dev->hints = 0;
  7. dev->flags = 0;
  8. dev->user = user;
  9. dev->ctx = ctx;
  10. dev->error_depth = 0;
  11. return dev;
  12. }
  13. void
  14. fz_free_device(fz_device *dev)
  15. {
  16. if (dev == NULL)
  17. return;
  18. if (dev->free_user)
  19. dev->free_user(dev);
  20. fz_free(dev->ctx, dev);
  21. }
  22. void
  23. fz_fill_path(fz_device *dev, fz_path *path, int even_odd, const fz_matrix *ctm,
  24. fz_colorspace *colorspace, float *color, float alpha)
  25. {
  26. if (dev->error_depth)
  27. return;
  28. if (dev->fill_path)
  29. dev->fill_path(dev, path, even_odd, ctm, colorspace, color, alpha);
  30. }
  31. void
  32. fz_stroke_path(fz_device *dev, fz_path *path, fz_stroke_state *stroke, const fz_matrix *ctm,
  33. fz_colorspace *colorspace, float *color, float alpha)
  34. {
  35. if (dev->error_depth)
  36. return;
  37. if (dev->stroke_path)
  38. dev->stroke_path(dev, path, stroke, ctm, colorspace, color, alpha);
  39. }
  40. void
  41. fz_clip_path(fz_device *dev, fz_path *path, const fz_rect *rect, int even_odd, const fz_matrix *ctm)
  42. {
  43. fz_context *ctx = dev->ctx;
  44. if (dev->error_depth)
  45. {
  46. dev->error_depth++;
  47. return;
  48. }
  49. fz_try(ctx)
  50. {
  51. if (dev->clip_path)
  52. dev->clip_path(dev, path, rect, even_odd, ctm);
  53. }
  54. fz_catch(ctx)
  55. {
  56. dev->error_depth = 1;
  57. strcpy(dev->errmess, fz_caught(ctx));
  58. /* Error swallowed */
  59. }
  60. }
  61. void
  62. fz_clip_stroke_path(fz_device *dev, fz_path *path, const fz_rect *rect, fz_stroke_state *stroke, const fz_matrix *ctm)
  63. {
  64. fz_context *ctx = dev->ctx;
  65. if (dev->error_depth)
  66. {
  67. dev->error_depth++;
  68. return;
  69. }
  70. fz_try(ctx)
  71. {
  72. if (dev->clip_stroke_path)
  73. dev->clip_stroke_path(dev, path, rect, stroke, ctm);
  74. }
  75. fz_catch(ctx)
  76. {
  77. dev->error_depth = 1;
  78. strcpy(dev->errmess, fz_caught(ctx));
  79. /* Error swallowed */
  80. }
  81. }
  82. void
  83. fz_fill_text(fz_device *dev, fz_text *text, const fz_matrix *ctm,
  84. fz_colorspace *colorspace, float *color, float alpha)
  85. {
  86. if (dev->error_depth)
  87. return;
  88. if (dev->fill_text)
  89. dev->fill_text(dev, text, ctm, colorspace, color, alpha);
  90. }
  91. void
  92. fz_stroke_text(fz_device *dev, fz_text *text, fz_stroke_state *stroke, const fz_matrix *ctm,
  93. fz_colorspace *colorspace, float *color, float alpha)
  94. {
  95. if (dev->error_depth)
  96. return;
  97. if (dev->stroke_text)
  98. dev->stroke_text(dev, text, stroke, ctm, colorspace, color, alpha);
  99. }
  100. void
  101. fz_clip_text(fz_device *dev, fz_text *text, const fz_matrix *ctm, int accumulate)
  102. {
  103. fz_context *ctx = dev->ctx;
  104. if (dev->error_depth)
  105. {
  106. if (accumulate == 0 || accumulate == 1)
  107. dev->error_depth++;
  108. return;
  109. }
  110. fz_try(ctx)
  111. {
  112. if (dev->clip_text)
  113. dev->clip_text(dev, text, ctm, accumulate);
  114. }
  115. fz_catch(ctx)
  116. {
  117. if (accumulate == 2)
  118. fz_rethrow(ctx);
  119. dev->error_depth = 1;
  120. strcpy(dev->errmess, fz_caught(ctx));
  121. /* Error swallowed */
  122. }
  123. }
  124. void
  125. fz_clip_stroke_text(fz_device *dev, fz_text *text, fz_stroke_state *stroke, const fz_matrix *ctm)
  126. {
  127. fz_context *ctx = dev->ctx;
  128. if (dev->error_depth)
  129. {
  130. dev->error_depth++;
  131. return;
  132. }
  133. fz_try(ctx)
  134. {
  135. if (dev->clip_stroke_text)
  136. dev->clip_stroke_text(dev, text, stroke, ctm);
  137. }
  138. fz_catch(ctx)
  139. {
  140. dev->error_depth = 1;
  141. strcpy(dev->errmess, fz_caught(ctx));
  142. /* Error swallowed */
  143. }
  144. }
  145. void
  146. fz_ignore_text(fz_device *dev, fz_text *text, const fz_matrix *ctm)
  147. {
  148. if (dev->error_depth)
  149. return;
  150. if (dev->ignore_text)
  151. dev->ignore_text(dev, text, ctm);
  152. }
  153. void
  154. fz_pop_clip(fz_device *dev)
  155. {
  156. if (dev->error_depth)
  157. {
  158. dev->error_depth--;
  159. if (dev->error_depth == 0)
  160. fz_throw(dev->ctx, "%s", dev->errmess);
  161. return;
  162. }
  163. if (dev->pop_clip)
  164. dev->pop_clip(dev);
  165. }
  166. void
  167. fz_fill_shade(fz_device *dev, fz_shade *shade, const fz_matrix *ctm, float alpha)
  168. {
  169. if (dev->error_depth)
  170. return;
  171. if (dev->fill_shade)
  172. dev->fill_shade(dev, shade, ctm, alpha);
  173. }
  174. void
  175. fz_fill_image(fz_device *dev, fz_image *image, const fz_matrix *ctm, float alpha)
  176. {
  177. if (dev->error_depth)
  178. return;
  179. if (dev->fill_image)
  180. dev->fill_image(dev, image, ctm, alpha);
  181. }
  182. void
  183. fz_fill_image_mask(fz_device *dev, fz_image *image, const fz_matrix *ctm,
  184. fz_colorspace *colorspace, float *color, float alpha)
  185. {
  186. if (dev->error_depth)
  187. return;
  188. if (dev->fill_image_mask)
  189. dev->fill_image_mask(dev, image, ctm, colorspace, color, alpha);
  190. }
  191. void
  192. fz_clip_image_mask(fz_device *dev, fz_image *image, const fz_rect *rect, const fz_matrix *ctm)
  193. {
  194. fz_context *ctx = dev->ctx;
  195. if (dev->error_depth)
  196. {
  197. dev->error_depth++;
  198. return;
  199. }
  200. fz_try(ctx)
  201. {
  202. if (dev->clip_image_mask)
  203. dev->clip_image_mask(dev, image, rect, ctm);
  204. }
  205. fz_catch(ctx)
  206. {
  207. dev->error_depth = 1;
  208. strcpy(dev->errmess, fz_caught(ctx));
  209. /* Error swallowed */
  210. }
  211. }
  212. void
  213. fz_begin_mask(fz_device *dev, const fz_rect *area, int luminosity, fz_colorspace *colorspace, float *bc)
  214. {
  215. fz_context *ctx = dev->ctx;
  216. if (dev->error_depth)
  217. {
  218. dev->error_depth++;
  219. return;
  220. }
  221. fz_try(ctx)
  222. {
  223. if (dev->begin_mask)
  224. dev->begin_mask(dev, area, luminosity, colorspace, bc);
  225. }
  226. fz_catch(ctx)
  227. {
  228. dev->error_depth = 1;
  229. strcpy(dev->errmess, fz_caught(ctx));
  230. /* Error swallowed */
  231. }
  232. }
  233. void
  234. fz_end_mask(fz_device *dev)
  235. {
  236. if (dev->error_depth)
  237. {
  238. /* Converts from mask to clip, so no change in stack depth */
  239. return;
  240. }
  241. if (dev->end_mask)
  242. dev->end_mask(dev);
  243. }
  244. void
  245. fz_begin_group(fz_device *dev, const fz_rect *area, int isolated, int knockout, int blendmode, float alpha)
  246. {
  247. fz_context *ctx = dev->ctx;
  248. if (dev->error_depth)
  249. {
  250. dev->error_depth++;
  251. return;
  252. }
  253. fz_try(ctx)
  254. {
  255. if (dev->begin_group)
  256. dev->begin_group(dev, area, isolated, knockout, blendmode, alpha);
  257. }
  258. fz_catch(ctx)
  259. {
  260. dev->error_depth = 1;
  261. strcpy(dev->errmess, fz_caught(ctx));
  262. /* Error swallowed */
  263. }
  264. }
  265. void
  266. fz_end_group(fz_device *dev)
  267. {
  268. if (dev->error_depth)
  269. {
  270. dev->error_depth--;
  271. if (dev->error_depth == 0)
  272. fz_throw(dev->ctx, "%s", dev->errmess);
  273. return;
  274. }
  275. if (dev->end_group)
  276. dev->end_group(dev);
  277. }
  278. void
  279. fz_begin_tile(fz_device *dev, const fz_rect *area, const fz_rect *view, float xstep, float ystep, const fz_matrix *ctm)
  280. {
  281. fz_context *ctx = dev->ctx;
  282. if (dev->error_depth)
  283. {
  284. dev->error_depth++;
  285. return;
  286. }
  287. fz_try(ctx)
  288. {
  289. if (dev->begin_tile)
  290. dev->begin_tile(dev, area, view, xstep, ystep, ctm);
  291. }
  292. fz_catch(ctx)
  293. {
  294. dev->error_depth = 1;
  295. strcpy(dev->errmess, fz_caught(ctx));
  296. /* Error swallowed */
  297. }
  298. }
  299. void
  300. fz_end_tile(fz_device *dev)
  301. {
  302. if (dev->error_depth)
  303. {
  304. dev->error_depth--;
  305. if (dev->error_depth == 0)
  306. fz_throw(dev->ctx, "%s", dev->errmess);
  307. return;
  308. }
  309. if (dev->end_tile)
  310. dev->end_tile(dev);
  311. }