1 | #include "mupdf/fitz.h" |
2 | #include "mupdf/pdf.h" |
3 | |
4 | pdf_obj * |
5 | pdf_xobject_resources(fz_context *ctx, pdf_obj *xobj) |
6 | { |
7 | return pdf_dict_get(ctx, xobj, PDF_NAME(Resources)); |
8 | } |
9 | |
10 | fz_rect |
11 | pdf_xobject_bbox(fz_context *ctx, pdf_obj *xobj) |
12 | { |
13 | return pdf_dict_get_rect(ctx, xobj, PDF_NAME(BBox)); |
14 | } |
15 | |
16 | fz_matrix |
17 | pdf_xobject_matrix(fz_context *ctx, pdf_obj *xobj) |
18 | { |
19 | return pdf_dict_get_matrix(ctx, xobj, PDF_NAME(Matrix)); |
20 | } |
21 | |
22 | int pdf_xobject_isolated(fz_context *ctx, pdf_obj *xobj) |
23 | { |
24 | pdf_obj *group = pdf_dict_get(ctx, xobj, PDF_NAME(Group)); |
25 | if (group) |
26 | return pdf_dict_get_bool(ctx, group, PDF_NAME(I)); |
27 | return 0; |
28 | } |
29 | |
30 | int pdf_xobject_knockout(fz_context *ctx, pdf_obj *xobj) |
31 | { |
32 | pdf_obj *group = pdf_dict_get(ctx, xobj, PDF_NAME(Group)); |
33 | if (group) |
34 | return pdf_dict_get_bool(ctx, group, PDF_NAME(K)); |
35 | return 0; |
36 | } |
37 | |
38 | int pdf_xobject_transparency(fz_context *ctx, pdf_obj *xobj) |
39 | { |
40 | pdf_obj *group = pdf_dict_get(ctx, xobj, PDF_NAME(Group)); |
41 | if (group) |
42 | if (pdf_name_eq(ctx, pdf_dict_get(ctx, group, PDF_NAME(S)), PDF_NAME(Transparency))) |
43 | return 1; |
44 | return 0; |
45 | } |
46 | |
47 | fz_colorspace * |
48 | pdf_xobject_colorspace(fz_context *ctx, pdf_obj *xobj) |
49 | { |
50 | pdf_obj *group = pdf_dict_get(ctx, xobj, PDF_NAME(Group)); |
51 | if (group) |
52 | { |
53 | pdf_obj *cs = pdf_dict_get(ctx, group, PDF_NAME(CS)); |
54 | if (cs) |
55 | { |
56 | fz_colorspace *colorspace = NULL; |
57 | fz_try(ctx) |
58 | colorspace = pdf_load_colorspace(ctx, cs); |
59 | fz_catch(ctx) |
60 | { |
61 | fz_rethrow_if(ctx, FZ_ERROR_TRYLATER); |
62 | fz_warn(ctx, "Ignoring XObject blending colorspace." ); |
63 | } |
64 | if (!fz_is_valid_blend_colorspace(ctx, colorspace)) |
65 | { |
66 | fz_warn(ctx, "Ignoring invalid XObject blending colorspace: %s." , colorspace->name); |
67 | fz_drop_colorspace(ctx, colorspace); |
68 | return NULL; |
69 | } |
70 | return colorspace; |
71 | } |
72 | } |
73 | return NULL; |
74 | } |
75 | |
76 | pdf_obj * |
77 | pdf_new_xobject(fz_context *ctx, pdf_document *doc, fz_rect bbox, fz_matrix matrix, pdf_obj *res, fz_buffer *contents) |
78 | { |
79 | pdf_obj *ind = NULL; |
80 | pdf_obj *form = pdf_new_dict(ctx, doc, 5); |
81 | fz_try(ctx) |
82 | { |
83 | pdf_dict_put(ctx, form, PDF_NAME(Type), PDF_NAME(XObject)); |
84 | pdf_dict_put(ctx, form, PDF_NAME(Subtype), PDF_NAME(Form)); |
85 | pdf_dict_put_rect(ctx, form, PDF_NAME(BBox), bbox); |
86 | pdf_dict_put_matrix(ctx, form, PDF_NAME(Matrix), matrix); |
87 | if (res) |
88 | pdf_dict_put(ctx, form, PDF_NAME(Resources), res); |
89 | ind = pdf_add_stream(ctx, doc, contents, form, 0); |
90 | } |
91 | fz_always(ctx) |
92 | pdf_drop_obj(ctx, form); |
93 | fz_catch(ctx) |
94 | fz_rethrow(ctx); |
95 | return ind; |
96 | } |
97 | |
98 | void |
99 | pdf_update_xobject(fz_context *ctx, pdf_document *doc, pdf_obj *form, fz_rect bbox, fz_matrix matrix, pdf_obj *res, fz_buffer *contents) |
100 | { |
101 | pdf_dict_put_rect(ctx, form, PDF_NAME(BBox), bbox); |
102 | pdf_dict_put_matrix(ctx, form, PDF_NAME(Matrix), matrix); |
103 | if (res) |
104 | pdf_dict_put(ctx, form, PDF_NAME(Resources), res); |
105 | else |
106 | pdf_dict_del(ctx, form, PDF_NAME(Resources)); |
107 | pdf_update_stream(ctx, doc, form, contents, 0); |
108 | } |
109 | |