static void page_merge(int page_from, int page_to, pdf_graft_map *graft_map) { pdf_obj *pageref = NULL; pdf_obj *page_dict; pdf_obj *obj = NULL, *ref = NULL; /* Include minimal number of objects for page. Do not include items that * reference other pages */ pdf_obj *known_page_objs[] = { PDF_NAME_Contents, PDF_NAME_Resources, PDF_NAME_MediaBox, PDF_NAME_CropBox, PDF_NAME_BleedBox, PDF_NAME_TrimBox, PDF_NAME_ArtBox, PDF_NAME_Rotate, PDF_NAME_UserUnit}; int n = nelem(known_page_objs); int i; int num; fz_var(obj); fz_var(ref); fz_try(ctx) { pageref = pdf_lookup_page_obj(ctx, doc_src, page_from - 1); /* Make a new dictionary and copy over the items from the source object to * the new dict that we want to deep copy. */ page_dict = pdf_new_dict(ctx, doc_des, 4); pdf_dict_put_drop(ctx, page_dict, PDF_NAME_Type, PDF_NAME_Page); for (i = 0; i < n; i++) { obj = pdf_dict_get(ctx, pageref, known_page_objs[i]); if (obj != NULL) pdf_dict_put_drop(ctx, page_dict, known_page_objs[i], pdf_graft_object(ctx, doc_des, doc_src, obj, graft_map)); } /* Add the dictionary */ obj = pdf_add_object_drop(ctx, doc_des, page_dict); /* Get indirect ref */ num = pdf_to_num(ctx, obj); ref = pdf_new_indirect(ctx, doc_des, num, 0); /* Insert */ pdf_insert_page(ctx, doc_des, page_to - 1, ref); } fz_always(ctx) { pdf_drop_obj(ctx, obj); pdf_drop_obj(ctx, ref); } fz_catch(ctx) { fz_rethrow(ctx); } }
void pdf_set_annot_quad_points(fz_context *ctx, pdf_annot *annot, int n, const float *v) { pdf_document *doc = annot->page->doc; fz_matrix page_ctm, inv_page_ctm; pdf_obj *quad_points; fz_point point; int i, k; // TODO: check annot type pdf_page_transform(ctx, annot->page, NULL, &page_ctm); fz_invert_matrix(&inv_page_ctm, &page_ctm); quad_points = pdf_new_array(ctx, doc, n * 8); for (i = 0; i < n; ++i) { for (k = 0; k < 4; ++k) { point.x = v[i * 8 + k * 2 + 0]; point.y = v[i * 8 + k * 2 + 1]; fz_transform_point(&point, &inv_page_ctm); pdf_array_push_drop(ctx, quad_points, pdf_new_real(ctx, doc, point.x)); pdf_array_push_drop(ctx, quad_points, pdf_new_real(ctx, doc, point.y)); } } pdf_dict_put_drop(ctx, annot->obj, PDF_NAME_QuadPoints, quad_points); annot->changed = 1; }
static int strip_outlines(fz_context *ctx, pdf_document *doc, pdf_obj *outlines, int page_count, int *page_object_nums, pdf_obj *names_list) { int nc; pdf_obj *first; pdf_obj *last; first = pdf_dict_get(ctx, outlines, PDF_NAME_First); if (first == NULL) nc = 0; else nc = strip_outline(ctx, doc, first, page_count, page_object_nums, names_list, &first, &last); if (nc == 0) { pdf_dict_del(ctx, outlines, PDF_NAME_First); pdf_dict_del(ctx, outlines, PDF_NAME_Last); pdf_dict_del(ctx, outlines, PDF_NAME_Count); } else { int old_count = pdf_to_int(ctx, pdf_dict_get(ctx, outlines, PDF_NAME_Count)); pdf_dict_put(ctx, outlines, PDF_NAME_First, first); pdf_dict_put(ctx, outlines, PDF_NAME_Last, last); pdf_dict_put_drop(ctx, outlines, PDF_NAME_Count, pdf_new_int(ctx, doc, old_count > 0 ? nc : -nc)); } return nc; }
void pdf_reorder_portfolio_schema(fz_context *ctx, pdf_document *doc, int entry, int new_pos) { pdf_portfolio **pp; pdf_portfolio *p; if (!doc) fz_throw(ctx, FZ_ERROR_GENERIC, "Bad pdf_portfolio_schema_info call"); if (doc->portfolio == NULL) load_portfolio(ctx, doc); /* Take p out */ pp = &doc->portfolio; while (*pp && entry > 0) pp = &(*pp)->next, entry--; p = *pp; if (p == NULL || entry) fz_throw(ctx, FZ_ERROR_GENERIC, "entry out of range in pdf_reorder_portfolio_schema"); *pp = p->next; /* Put p back in */ pp = &doc->portfolio; while (*pp && new_pos > 0) pp = &(*pp)->next, new_pos--; p->next = *pp; *pp = p; /* Rewrite the underlying orderings */ for (p = doc->portfolio, entry = 0; p; p = p->next, entry++) pdf_dict_put_drop(ctx, p->val, PDF_NAME_O, pdf_new_int(ctx, doc, entry)); }
void pdf_set_annot_contents(fz_context *ctx, pdf_annot *annot, const char *text) { pdf_document *doc = annot->page->doc; pdf_dict_put_drop(ctx, annot->obj, PDF_NAME_Contents, pdf_new_string(ctx, doc, text, strlen(text))); annot->changed = 1; }
void pdf_set_annot_flags(fz_context *ctx, pdf_annot *annot, int flags) { pdf_document *doc = annot->page->doc; pdf_dict_put_drop(ctx, annot->obj, PDF_NAME_F, pdf_new_int(ctx, doc, flags)); annot->changed = 1; }
void pdf_set_annot_icon_name(fz_context *ctx, pdf_annot *annot, const char *name) { pdf_document *doc = annot->page->doc; check_allowed_subtypes(ctx, annot, PDF_NAME_Name, icon_name_subtypes); pdf_dict_put_drop(ctx, annot->obj, PDF_NAME_Name, pdf_new_name(ctx, doc, name)); }
void pdf_add_annot_quad_point(fz_context *ctx, pdf_annot *annot, fz_rect bbox) { pdf_document *doc = annot->page->doc; fz_matrix page_ctm, inv_page_ctm; pdf_obj *quad_points; check_allowed_subtypes(ctx, annot, PDF_NAME(QuadPoints), quad_point_subtypes); pdf_page_transform(ctx, annot->page, NULL, &page_ctm); fz_invert_matrix(&inv_page_ctm, &page_ctm); quad_points = pdf_dict_get(ctx, annot->obj, PDF_NAME(QuadPoints)); if (!pdf_is_array(ctx, quad_points)) { quad_points = pdf_new_array(ctx, doc, 8); pdf_dict_put_drop(ctx, annot->obj, PDF_NAME(QuadPoints), quad_points); } /* Contrary to the specification, the points within a QuadPoint are NOT ordered * in a counterclockwise fashion. Experiments with Adobe's implementation * indicates a cross-wise ordering is intended: ul, ur, ll, lr. */ fz_transform_rect(&bbox, &inv_page_ctm); pdf_array_push_real(ctx, quad_points, bbox.x0); /* ul */ pdf_array_push_real(ctx, quad_points, bbox.y1); pdf_array_push_real(ctx, quad_points, bbox.x1); /* ur */ pdf_array_push_real(ctx, quad_points, bbox.y1); pdf_array_push_real(ctx, quad_points, bbox.x0); /* ll */ pdf_array_push_real(ctx, quad_points, bbox.y0); pdf_array_push_real(ctx, quad_points, bbox.x1); /* lr */ pdf_array_push_real(ctx, quad_points, bbox.y0); pdf_dirty_annot(ctx, annot); }
void pdf_set_annot_vertices(fz_context *ctx, pdf_annot *annot, int n, const float *v) { pdf_document *doc = annot->page->doc; fz_matrix page_ctm, inv_page_ctm; pdf_obj *vertices; fz_point point; int i; check_allowed_subtypes(ctx, annot, PDF_NAME_Vertices, vertices_subtypes); if (n <= 0 || !v) fz_throw(ctx, FZ_ERROR_GENERIC, "invalid number of vertices"); pdf_page_transform(ctx, annot->page, NULL, &page_ctm); fz_invert_matrix(&inv_page_ctm, &page_ctm); vertices = pdf_new_array(ctx, doc, n * 2); for (i = 0; i < n; ++i) { point.x = v[i * 2]; point.y = v[i * 2 + 1]; fz_transform_point(&point, &inv_page_ctm); pdf_array_push_drop(ctx, vertices, pdf_new_real(ctx, doc, point.x)); pdf_array_push_drop(ctx, vertices, pdf_new_real(ctx, doc, point.y)); } pdf_dict_put_drop(ctx, annot->obj, PDF_NAME_Vertices, vertices); annot->changed = 1; }
void pdf_set_annot_quad_points(fz_context *ctx, pdf_annot *annot, int n, const float *v) { pdf_document *doc = annot->page->doc; fz_matrix page_ctm, inv_page_ctm; pdf_obj *quad_points; fz_point point; int i, k; check_allowed_subtypes(ctx, annot, PDF_NAME_QuadPoints, quad_point_subtypes); if (n <= 0 || !v) fz_throw(ctx, FZ_ERROR_GENERIC, "invalid number of quadrilaterals"); pdf_page_transform(ctx, annot->page, NULL, &page_ctm); fz_invert_matrix(&inv_page_ctm, &page_ctm); quad_points = pdf_new_array(ctx, doc, n * 8); for (i = 0; i < n; ++i) { for (k = 0; k < 4; ++k) { point.x = v[i * 8 + k * 2 + 0]; point.y = v[i * 8 + k * 2 + 1]; fz_transform_point(&point, &inv_page_ctm); pdf_array_push_drop(ctx, quad_points, pdf_new_real(ctx, doc, point.x)); pdf_array_push_drop(ctx, quad_points, pdf_new_real(ctx, doc, point.y)); } } pdf_dict_put_drop(ctx, annot->obj, PDF_NAME_QuadPoints, quad_points); annot->changed = 1; }
void pdf_set_annot_ink_list(fz_context *ctx, pdf_annot *annot, int n, const int *count, const float *v) { pdf_document *doc = annot->page->doc; fz_matrix page_ctm, inv_page_ctm; pdf_obj *ink_list, *stroke; fz_point point; int i, k; check_allowed_subtypes(ctx, annot, PDF_NAME_InkList, ink_list_subtypes); pdf_page_transform(ctx, annot->page, NULL, &page_ctm); fz_invert_matrix(&inv_page_ctm, &page_ctm); // TODO: update Rect (in update appearance perhaps?) ink_list = pdf_new_array(ctx, doc, n); for (i = 0; i < n; ++i) { stroke = pdf_new_array(ctx, doc, count[i]); for (k = 0; k < count[i]; ++k) { point.x = *v++; point.y = *v++; fz_transform_point(&point, &inv_page_ctm); pdf_array_push_drop(ctx, stroke, pdf_new_real(ctx, doc, point.x)); pdf_array_push_drop(ctx, stroke, pdf_new_real(ctx, doc, point.y)); } pdf_array_push_drop(ctx, ink_list, stroke); } pdf_dict_put_drop(ctx, annot->obj, PDF_NAME_InkList, ink_list); annot->changed = 1; }
static void pdf_set_annot_color_imp(fz_context *ctx, pdf_annot *annot, pdf_obj *key, int n, const float color[4]) { pdf_document *doc = annot->page->doc; pdf_obj *obj = pdf_new_array(ctx, doc, 4); switch (n) { default: case 0: break; case 1: pdf_array_push_drop(ctx, obj, pdf_new_real(ctx, doc, color[0])); break; case 3: pdf_array_push_drop(ctx, obj, pdf_new_real(ctx, doc, color[0])); pdf_array_push_drop(ctx, obj, pdf_new_real(ctx, doc, color[1])); pdf_array_push_drop(ctx, obj, pdf_new_real(ctx, doc, color[2])); break; case 4: pdf_array_push_drop(ctx, obj, pdf_new_real(ctx, doc, color[0])); pdf_array_push_drop(ctx, obj, pdf_new_real(ctx, doc, color[1])); pdf_array_push_drop(ctx, obj, pdf_new_real(ctx, doc, color[2])); pdf_array_push_drop(ctx, obj, pdf_new_real(ctx, doc, color[3])); break; } pdf_dict_put_drop(ctx, annot->obj, key, obj); annot->changed = 1; }
void pdf_set_annot_ink_list(fz_context *ctx, pdf_annot *annot, int n, const int *count, const float *v) { pdf_document *doc = annot->page->doc; fz_matrix page_ctm, inv_page_ctm; pdf_obj *ink_list, *stroke; fz_point point; int i, k; if (pdf_annot_type(ctx, annot) != PDF_ANNOT_INK) fz_throw(ctx, FZ_ERROR_GENERIC, "cannot set InkList on non-ink annotations"); pdf_page_transform(ctx, annot->page, NULL, &page_ctm); fz_invert_matrix(&inv_page_ctm, &page_ctm); // TODO: update Rect (in update appearance perhaps?) ink_list = pdf_new_array(ctx, doc, n); for (i = 0; i < n; ++i) { stroke = pdf_new_array(ctx, doc, count[i]); for (k = 0; k < count[i]; ++k) { point.x = *v++; point.y = *v++; fz_transform_point(&point, &inv_page_ctm); pdf_array_push_drop(ctx, stroke, pdf_new_real(ctx, doc, point.x)); pdf_array_push_drop(ctx, stroke, pdf_new_real(ctx, doc, point.y)); } pdf_array_push_drop(ctx, ink_list, stroke); } pdf_dict_put_drop(ctx, annot->obj, PDF_NAME_InkList, ink_list); annot->changed = 1; }
static void page_merge(int page_from, int page_to, pdf_graft_map *graft_map) { pdf_obj *page_ref; pdf_obj *page_dict; pdf_obj *obj; pdf_obj *ref = NULL; int i; /* Copy as few key/value pairs as we can. Do not include items that reference other pages. */ static pdf_obj * const copy_list[] = { PDF_NAME_Contents, PDF_NAME_Resources, PDF_NAME_MediaBox, PDF_NAME_CropBox, PDF_NAME_BleedBox, PDF_NAME_TrimBox, PDF_NAME_ArtBox, PDF_NAME_Rotate, PDF_NAME_UserUnit }; fz_var(ref); fz_try(ctx) { page_ref = pdf_lookup_page_obj(ctx, doc_src, page_from - 1); pdf_flatten_inheritable_page_items(ctx, page_ref); /* Make a new page object dictionary to hold the items we copy from the source page. */ page_dict = pdf_new_dict(ctx, doc_des, 4); pdf_dict_put_drop(ctx, page_dict, PDF_NAME_Type, PDF_NAME_Page); for (i = 0; i < nelem(copy_list); i++) { obj = pdf_dict_get(ctx, page_ref, copy_list[i]); if (obj != NULL) pdf_dict_put_drop(ctx, page_dict, copy_list[i], pdf_graft_mapped_object(ctx, graft_map, obj)); } /* Add the page object to the destination document. */ ref = pdf_add_object_drop(ctx, doc_des, page_dict); /* Insert it into the page tree. */ pdf_insert_page(ctx, doc_des, page_to - 1, ref); } fz_always(ctx) { pdf_drop_obj(ctx, ref); } fz_catch(ctx) { fz_rethrow(ctx); } }
void pdf_set_annot_is_open(fz_context *ctx, pdf_annot *annot, int is_open) { pdf_document *doc = annot->page->doc; check_allowed_subtypes(ctx, annot, PDF_NAME_Open, open_subtypes); pdf_dict_put_drop(ctx, annot->obj, PDF_NAME_Open, pdf_new_bool(ctx, doc, is_open)); }
static int pdf_name_tree_insert(fz_context *ctx, pdf_document *doc, pdf_obj *tree, pdf_obj *key, pdf_obj *val) { find_data data; pdf_obj *names, *limits, *limit0, *limit1; data.key = key; data.found = NULL; data.found_index = 0; data.last = NULL; data.last_index = 0; data.entry = 0; pdf_name_tree_map(ctx, tree, find_position, &data); if (!data.found) { data.found = data.last; data.found_index = data.last_index; } if (!data.found) { /* Completely empty name tree! */ pdf_dict_put_drop(ctx, tree, PDF_NAME_Names, pdf_new_array(ctx, doc, 2)); pdf_dict_put_drop(ctx, tree, PDF_NAME_Limits, pdf_new_array(ctx, doc, 2)); data.found = tree; data.found_index = 0; } names = pdf_dict_get(ctx, data.found, PDF_NAME_Names); if (names == NULL) pdf_dict_put_drop(ctx, data.found, PDF_NAME_Names, (names = pdf_new_array(ctx, doc, 2))); pdf_array_insert(ctx, names, key, 2*data.found_index); pdf_array_insert(ctx, names, val, 2*data.found_index+1); limits = pdf_dict_get(ctx, data.found, PDF_NAME_Limits); if (limits == NULL) pdf_dict_put_drop(ctx, data.found, PDF_NAME_Limits, (limits = pdf_new_array(ctx, doc, 2))); limit0 = pdf_array_get(ctx, limits, 0); limit1 = pdf_array_get(ctx, limits, 1); if (!pdf_is_string(ctx, limit0) || data.found_index == 0) pdf_array_put(ctx, limits, 0, key); if (!pdf_is_string(ctx, limit1) || 2 * (data.found_index+1) == pdf_array_len(ctx, limits)) pdf_array_put(ctx, limits, 1, key); return data.entry; }
static void pdf_clean_stream_object(fz_context *ctx, pdf_document *doc, pdf_obj *obj, pdf_obj *orig_res, fz_cookie *cookie, int own_res, pdf_text_filter_fn *text_filter, pdf_after_text_object_fn *after_text, void *arg, int sanitize, int ascii) { pdf_processor *proc_buffer = NULL; pdf_processor *proc_filter = NULL; pdf_obj *res = NULL; pdf_obj *ref; fz_buffer *buffer; if (!obj) return; fz_var(res); fz_var(proc_buffer); fz_var(proc_filter); buffer = fz_new_buffer(ctx, 1024); fz_try(ctx) { if (own_res) { pdf_obj *r = pdf_dict_get(ctx, obj, PDF_NAME(Resources)); if (r) orig_res = r; } res = pdf_new_dict(ctx, doc, 1); proc_buffer = pdf_new_buffer_processor(ctx, buffer, ascii); proc_filter = pdf_new_filter_processor_with_text_filter(ctx, doc, proc_buffer, orig_res, res, text_filter, after_text, arg); pdf_process_contents(ctx, proc_filter, doc, orig_res, obj, cookie); pdf_close_processor(ctx, proc_filter); pdf_close_processor(ctx, proc_buffer); pdf_update_stream(ctx, doc, obj, buffer, 0); if (own_res) { ref = pdf_add_object(ctx, doc, res); pdf_dict_put_drop(ctx, obj, PDF_NAME(Resources), ref); } } fz_always(ctx) { pdf_drop_processor(ctx, proc_filter); pdf_drop_processor(ctx, proc_buffer); fz_drop_buffer(ctx, buffer); pdf_drop_obj(ctx, res); } fz_catch(ctx) { fz_rethrow(ctx); } }
static void pdf_dev_alpha(fz_context *ctx, pdf_device *pdev, float alpha, int stroke) { int i; pdf_document *doc = pdev->doc; gstate *gs = CURRENT_GSTATE(pdev); /* If the alpha is unchanged, nothing to do */ if (gs->alpha[stroke] == alpha) return; /* Have we sent such an alpha before? */ for (i = 0; i < pdev->num_alphas; i++) if (pdev->alphas[i].alpha == alpha && pdev->alphas[i].stroke == stroke) break; if (i == pdev->num_alphas) { pdf_obj *o; pdf_obj *ref = NULL; fz_var(ref); /* No. Need to make a new one */ if (pdev->num_alphas == pdev->max_alphas) { int newmax = pdev->max_alphas * 2; if (newmax == 0) newmax = 4; pdev->alphas = fz_resize_array(ctx, pdev->alphas, newmax, sizeof(*pdev->alphas)); pdev->max_alphas = newmax; } pdev->alphas[i].alpha = alpha; pdev->alphas[i].stroke = stroke; o = pdf_new_dict(ctx, doc, 1); fz_try(ctx) { char text[32]; pdf_dict_put_drop(ctx, o, (stroke ? PDF_NAME_CA : PDF_NAME_ca), pdf_new_real(ctx, doc, alpha)); ref = pdf_add_object(ctx, doc, o); fz_snprintf(text, sizeof(text), "ExtGState/Alp%d", i); pdf_dict_putp(ctx, pdev->resources, text, ref); } fz_always(ctx) { pdf_drop_obj(ctx, o); pdf_drop_obj(ctx, ref); } fz_catch(ctx) { fz_rethrow(ctx); } pdev->num_alphas++; }
void pdf_set_annot_line_ending_styles(fz_context *ctx, pdf_annot *annot, int start_style, int end_style) { pdf_document *doc = annot->page->doc; pdf_obj *style; check_allowed_subtypes(ctx, annot, PDF_NAME_LE, line_ending_subtypes); style = pdf_new_array(ctx, doc, 2); pdf_dict_put_drop(ctx, annot->obj, PDF_NAME_LE, style); pdf_array_put_drop(ctx, style, 0, line_ending_name(ctx, start_style)); pdf_array_put_drop(ctx, style, 1, line_ending_name(ctx, end_style)); }
void pdf_set_text_annot_position(fz_context *ctx, pdf_document *doc, pdf_annot *annot, fz_point pt) { fz_matrix ctm; fz_rect rect; int flags; fz_invert_matrix(&ctm, &annot->page->ctm); rect.x0 = pt.x; rect.x1 = pt.x + TEXT_ANNOT_SIZE; rect.y0 = pt.y; rect.y1 = pt.y + TEXT_ANNOT_SIZE; fz_transform_rect(&rect, &ctm); pdf_dict_put_drop(ctx, annot->obj, PDF_NAME_Rect, pdf_new_rect(ctx, doc, &rect)); flags = pdf_to_int(ctx, pdf_dict_get(ctx, annot->obj, PDF_NAME_F)); flags |= (F_NoZoom|F_NoRotate); pdf_dict_put_drop(ctx, annot->obj, PDF_NAME_F, pdf_new_int(ctx, doc, flags)); update_rect(ctx, annot); }
void pdf_set_text_annot_position(fz_context *ctx, pdf_annot *annot, fz_point pt) { pdf_document *doc = annot->page->doc; fz_matrix page_ctm, inv_page_ctm; fz_rect rect; int flags; pdf_page_transform(ctx, annot->page, NULL, &page_ctm); fz_invert_matrix(&inv_page_ctm, &page_ctm); rect.x0 = pt.x; rect.x1 = pt.x + TEXT_ANNOT_SIZE; rect.y0 = pt.y; rect.y1 = pt.y + TEXT_ANNOT_SIZE; fz_transform_rect(&rect, &inv_page_ctm); pdf_dict_put_drop(ctx, annot->obj, PDF_NAME_Rect, pdf_new_rect(ctx, doc, &rect)); flags = pdf_to_int(ctx, pdf_dict_get(ctx, annot->obj, PDF_NAME_F)); flags |= (PDF_ANNOT_IS_NO_ZOOM|PDF_ANNOT_IS_NO_ROTATE); pdf_dict_put_drop(ctx, annot->obj, PDF_NAME_F, pdf_new_int(ctx, doc, flags)); }
void pdf_set_annot_line_ending_styles(fz_context *ctx, pdf_annot *annot, enum pdf_line_ending start_style, enum pdf_line_ending end_style) { pdf_document *doc = annot->page->doc; pdf_obj *style; check_allowed_subtypes(ctx, annot, PDF_NAME(LE), line_ending_subtypes); style = pdf_new_array(ctx, doc, 2); pdf_dict_put_drop(ctx, annot->obj, PDF_NAME(LE), style); pdf_array_put_drop(ctx, style, 0, pdf_name_from_line_ending(ctx, start_style)); pdf_array_put_drop(ctx, style, 1, pdf_name_from_line_ending(ctx, end_style)); pdf_dirty_annot(ctx, annot); }
void pdf_set_annot_rect(fz_context *ctx, pdf_annot *annot, const fz_rect *rect) { pdf_document *doc = annot->page->doc; fz_rect trect = *rect; fz_matrix page_ctm, inv_page_ctm; pdf_page_transform(ctx, annot->page, NULL, &page_ctm); fz_invert_matrix(&inv_page_ctm, &page_ctm); fz_transform_rect(&trect, &inv_page_ctm); pdf_dict_put_drop(ctx, annot->obj, PDF_NAME_Rect, pdf_new_rect(ctx, doc, &trect)); annot->changed = 1; }
static void pdf_set_annot_color_imp(fz_context *ctx, pdf_annot *annot, pdf_obj *key, int n, const float color[4], pdf_obj **allowed) { pdf_document *doc = annot->page->doc; pdf_obj *arr; if (allowed) check_allowed_subtypes(ctx, annot, key, allowed); if (n != 0 && n != 1 && n != 3 && n != 4) fz_throw(ctx, FZ_ERROR_GENERIC, "color must be 0, 1, 3 or 4 components"); if (!color) fz_throw(ctx, FZ_ERROR_GENERIC, "no color given"); arr = pdf_new_array(ctx, doc, n); fz_try(ctx) { switch (n) { case 1: pdf_array_insert_drop(ctx, arr, pdf_new_real(ctx, doc, color[0]), 0); break; case 3: pdf_array_insert_drop(ctx, arr, pdf_new_real(ctx, doc, color[0]), 0); pdf_array_insert_drop(ctx, arr, pdf_new_real(ctx, doc, color[1]), 1); pdf_array_insert_drop(ctx, arr, pdf_new_real(ctx, doc, color[2]), 2); break; case 4: pdf_array_insert_drop(ctx, arr, pdf_new_real(ctx, doc, color[0]), 0); pdf_array_insert_drop(ctx, arr, pdf_new_real(ctx, doc, color[1]), 1); pdf_array_insert_drop(ctx, arr, pdf_new_real(ctx, doc, color[2]), 2); pdf_array_insert_drop(ctx, arr, pdf_new_real(ctx, doc, color[3]), 3); break; } } fz_catch(ctx) { pdf_drop_obj(ctx, arr); fz_rethrow(ctx); } pdf_dict_put_drop(ctx, annot->obj, key, arr); annot->changed = 1; }
void pdf_add_annot_ink_list(fz_context *ctx, pdf_annot *annot, int n, fz_point p[]) { pdf_document *doc = annot->page->doc; fz_matrix page_ctm, inv_page_ctm; pdf_obj *ink_list, *stroke; int i; check_allowed_subtypes(ctx, annot, PDF_NAME(InkList), ink_list_subtypes); pdf_page_transform(ctx, annot->page, NULL, &page_ctm); fz_invert_matrix(&inv_page_ctm, &page_ctm); ink_list = pdf_dict_get(ctx, annot->obj, PDF_NAME(InkList)); if (!pdf_is_array(ctx, ink_list)) { ink_list = pdf_new_array(ctx, doc, 10); pdf_dict_put_drop(ctx, annot->obj, PDF_NAME(InkList), ink_list); } stroke = pdf_new_array(ctx, doc, n * 2); fz_try(ctx) { for (i = 0; i < n; ++i) { fz_point tp = p[i]; fz_transform_point(&tp, &inv_page_ctm); pdf_array_push_real(ctx, stroke, tp.x); pdf_array_push_real(ctx, stroke, tp.y); } } fz_catch(ctx) { pdf_drop_obj(ctx, stroke); fz_rethrow(ctx); } pdf_array_push_drop(ctx, ink_list, stroke); pdf_dirty_annot(ctx, annot); }
static void copy_resource(fz_context *ctx, pdf_filter_processor *p, pdf_obj *key, const char *name) { pdf_obj *res, *obj; if (!name || name[0] == 0) return; res = pdf_dict_get(ctx, p->old_rdb, key); obj = pdf_dict_gets(ctx, res, name); if (obj) { res = pdf_dict_get(ctx, p->new_rdb, key); if (!res) { res = pdf_new_dict(ctx, p->doc, 1); pdf_dict_put_drop(ctx, p->new_rdb, key, res); } pdf_dict_putp(ctx, res, name, obj); } }
void pdf_set_annot_border(fz_context *ctx, pdf_annot *annot, float w) { pdf_document *doc = annot->page->doc; pdf_obj *border = pdf_dict_get(ctx, annot->obj, PDF_NAME_Border); if (pdf_is_array(ctx, border)) pdf_array_put_drop(ctx, border, 2, pdf_new_real(ctx, doc, w)); else { border = pdf_new_array(ctx, doc, 3); pdf_array_push_drop(ctx, border, pdf_new_real(ctx, doc, 0)); pdf_array_push_drop(ctx, border, pdf_new_real(ctx, doc, 0)); pdf_array_push_drop(ctx, border, pdf_new_real(ctx, doc, w)); pdf_dict_put_drop(ctx, annot->obj, PDF_NAME_Border, border); } /* Remove border style and effect dictionaries so they won't interfere. */ pdf_dict_del(ctx, annot->obj, PDF_NAME_BS); pdf_dict_del(ctx, annot->obj, PDF_NAME_BE); annot->changed = 1; }
void pdf_set_annot_line(fz_context *ctx, pdf_annot *annot, fz_point a, fz_point b) { fz_matrix page_ctm, inv_page_ctm; pdf_obj *line; check_allowed_subtypes(ctx, annot, PDF_NAME(L), line_subtypes); pdf_page_transform(ctx, annot->page, NULL, &page_ctm); fz_invert_matrix(&inv_page_ctm, &page_ctm); fz_transform_point(&a, &inv_page_ctm); fz_transform_point(&b, &inv_page_ctm); line = pdf_new_array(ctx, annot->page->doc, 4); pdf_dict_put_drop(ctx, annot->obj, PDF_NAME(L), line); pdf_array_push_real(ctx, line, a.x); pdf_array_push_real(ctx, line, a.y); pdf_array_push_real(ctx, line, b.x); pdf_array_push_real(ctx, line, b.y); pdf_dirty_annot(ctx, annot); }
void pdf_set_markup_annot_quadpoints(fz_context *ctx, pdf_document *doc, pdf_annot *annot, fz_point *qp, int n) { fz_matrix ctm; pdf_obj *arr = pdf_new_array(ctx, doc, n*2); int i; fz_invert_matrix(&ctm, &annot->page->ctm); pdf_dict_put_drop(ctx, annot->obj, PDF_NAME_QuadPoints, arr); for (i = 0; i < n; i++) { fz_point pt = qp[i]; pdf_obj *r; fz_transform_point(&pt, &ctm); r = pdf_new_real(ctx, doc, pt.x); pdf_array_push_drop(ctx, arr, r); r = pdf_new_real(ctx, doc, pt.y); pdf_array_push_drop(ctx, arr, r); } }
void pdf_add_annot_vertex(fz_context *ctx, pdf_annot *annot, fz_point p) { pdf_document *doc = annot->page->doc; fz_matrix page_ctm, inv_page_ctm; pdf_obj *vertices; check_allowed_subtypes(ctx, annot, PDF_NAME(Vertices), vertices_subtypes); pdf_page_transform(ctx, annot->page, NULL, &page_ctm); fz_invert_matrix(&inv_page_ctm, &page_ctm); vertices = pdf_dict_get(ctx, annot->obj, PDF_NAME(Vertices)); if (!pdf_is_array(ctx, vertices)) { vertices = pdf_new_array(ctx, doc, 32); pdf_dict_put_drop(ctx, annot->obj, PDF_NAME(Vertices), vertices); } fz_transform_point(&p, &inv_page_ctm); pdf_array_push_real(ctx, vertices, p.x); pdf_array_push_real(ctx, vertices, p.y); pdf_dirty_annot(ctx, annot); }