1 | #include "mupdf/fitz.h" |
2 | #include "mupdf/pdf.h" |
3 | |
4 | fz_display_list * |
5 | pdf_new_display_list_from_annot(fz_context *ctx, pdf_annot *annot) |
6 | { |
7 | fz_display_list *list; |
8 | fz_device *dev = NULL; |
9 | |
10 | fz_var(dev); |
11 | |
12 | list = fz_new_display_list(ctx, pdf_bound_annot(ctx, annot)); |
13 | |
14 | fz_try(ctx) |
15 | { |
16 | dev = fz_new_list_device(ctx, list); |
17 | pdf_run_annot(ctx, annot, dev, fz_identity, NULL); |
18 | fz_close_device(ctx, dev); |
19 | } |
20 | fz_always(ctx) |
21 | { |
22 | fz_drop_device(ctx, dev); |
23 | } |
24 | fz_catch(ctx) |
25 | { |
26 | fz_drop_display_list(ctx, list); |
27 | fz_rethrow(ctx); |
28 | } |
29 | |
30 | return list; |
31 | } |
32 | |
33 | /* |
34 | Render an annotation suitable for blending on top of the opaque |
35 | pixmap returned by fz_new_pixmap_from_page_contents. |
36 | */ |
37 | fz_pixmap * |
38 | pdf_new_pixmap_from_annot(fz_context *ctx, pdf_annot *annot, fz_matrix ctm, fz_colorspace *cs, fz_separations *seps, int alpha) |
39 | { |
40 | fz_rect rect; |
41 | fz_irect bbox; |
42 | fz_pixmap *pix; |
43 | fz_device *dev = NULL; |
44 | |
45 | fz_var(dev); |
46 | |
47 | rect = pdf_bound_annot(ctx, annot); |
48 | rect = fz_transform_rect(rect, ctm); |
49 | bbox = fz_round_rect(rect); |
50 | |
51 | pix = fz_new_pixmap_with_bbox(ctx, cs, bbox, seps, alpha); |
52 | if (alpha) |
53 | fz_clear_pixmap(ctx, pix); |
54 | else |
55 | fz_clear_pixmap_with_value(ctx, pix, 0xFF); |
56 | |
57 | fz_try(ctx) |
58 | { |
59 | dev = fz_new_draw_device(ctx, ctm, pix); |
60 | pdf_run_annot(ctx, annot, dev, fz_identity, NULL); |
61 | fz_close_device(ctx, dev); |
62 | } |
63 | fz_always(ctx) |
64 | { |
65 | fz_drop_device(ctx, dev); |
66 | } |
67 | fz_catch(ctx) |
68 | { |
69 | fz_drop_pixmap(ctx, pix); |
70 | fz_rethrow(ctx); |
71 | } |
72 | |
73 | return pix; |
74 | } |
75 | |
76 | fz_stext_page * |
77 | pdf_new_stext_page_from_annot(fz_context *ctx, pdf_annot *annot, const fz_stext_options *options) |
78 | { |
79 | fz_stext_page *text; |
80 | fz_device *dev = NULL; |
81 | |
82 | fz_var(dev); |
83 | |
84 | if (annot == NULL) |
85 | return NULL; |
86 | |
87 | text = fz_new_stext_page(ctx, pdf_bound_annot(ctx, annot)); |
88 | fz_try(ctx) |
89 | { |
90 | dev = fz_new_stext_device(ctx, text, options); |
91 | pdf_run_annot(ctx, annot, dev, fz_identity, NULL); |
92 | fz_close_device(ctx, dev); |
93 | } |
94 | fz_always(ctx) |
95 | { |
96 | fz_drop_device(ctx, dev); |
97 | } |
98 | fz_catch(ctx) |
99 | { |
100 | fz_drop_stext_page(ctx, text); |
101 | fz_rethrow(ctx); |
102 | } |
103 | |
104 | return text; |
105 | } |
106 | |