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; }
void pdf_clear_annot_ink_list(fz_context *ctx, pdf_annot *annot) { check_allowed_subtypes(ctx, annot, PDF_NAME(InkList), ink_list_subtypes); pdf_dict_del(ctx, annot->obj, PDF_NAME(InkList)); pdf_dirty_annot(ctx, annot); }
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_author(fz_context *ctx, pdf_annot *annot, const char *author) { check_allowed_subtypes(ctx, annot, PDF_NAME(T), markup_subtypes); pdf_dict_put_text_string(ctx, annot->obj, PDF_NAME(T), author); pdf_dirty_annot(ctx, annot); }
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_annot_quad_point(fz_context *ctx, pdf_annot *annot, int idx, float v[8]) { pdf_obj *quad_points; pdf_obj *quad_point; fz_matrix page_ctm; int i; check_allowed_subtypes(ctx, annot, PDF_NAME_QuadPoints, quad_point_subtypes); quad_points = pdf_dict_get(ctx, annot->obj, PDF_NAME_QuadPoints); quad_point = pdf_array_get(ctx, quad_points, idx); pdf_page_transform(ctx, annot->page, NULL, &page_ctm); for (i = 0; i < 8; i += 2) { fz_point point; point.x = pdf_to_real(ctx, pdf_array_get(ctx, quad_point, i+0)); point.y = pdf_to_real(ctx, pdf_array_get(ctx, quad_point, i+1)); fz_transform_point(&point, &page_ctm); v[i+0] = point.x; v[i+1] = point.y; } }
void pdf_set_annot_icon_name(fz_context *ctx, pdf_annot *annot, const char *name) { check_allowed_subtypes(ctx, annot, PDF_NAME(Name), icon_name_subtypes); pdf_dict_put_name(ctx, annot->obj, PDF_NAME(Name), name); pdf_dirty_annot(ctx, annot); }
void pdf_annot_ink_list_stroke_vertex(fz_context *ctx, pdf_annot *annot, int i, int k, float v[2]) { pdf_obj *ink_list; pdf_obj *stroke; fz_matrix page_ctm; fz_point point = { 0, 0 }; check_allowed_subtypes(ctx, annot, PDF_NAME_InkList, ink_list_subtypes); ink_list = pdf_dict_get(ctx, annot->obj, PDF_NAME_InkList); stroke = pdf_array_get(ctx, ink_list, i); if (v) { pdf_page_transform(ctx, annot->page, NULL, &page_ctm); point.x = pdf_to_real(ctx, pdf_array_get(ctx, stroke, k * 2 + 0)); point.y = pdf_to_real(ctx, pdf_array_get(ctx, stroke, k * 2 + 1)); fz_transform_point(&point, &page_ctm); v[0] = point.x; v[1] = point.y; } }
void pdf_set_annot_is_open(fz_context *ctx, pdf_annot *annot, int is_open) { check_allowed_subtypes(ctx, annot, PDF_NAME(Open), open_subtypes); pdf_dict_put_bool(ctx, annot->obj, PDF_NAME(Open), is_open); pdf_dirty_annot(ctx, annot); }
void pdf_clear_annot_quad_points(fz_context *ctx, pdf_annot *annot) { check_allowed_subtypes(ctx, annot, PDF_NAME(QuadPoints), quad_point_subtypes); pdf_dict_del(ctx, annot->obj, PDF_NAME(QuadPoints)); pdf_dirty_annot(ctx, annot); }
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_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)); }
int pdf_annot_quad_point_count(fz_context *ctx, pdf_annot *annot) { pdf_obj *quad_points; check_allowed_subtypes(ctx, annot, PDF_NAME_QuadPoints, quad_point_subtypes); quad_points = pdf_dict_get(ctx, annot->obj, PDF_NAME_QuadPoints); return pdf_array_len(ctx, quad_points); }
int pdf_annot_ink_list_count(fz_context *ctx, pdf_annot *annot) { pdf_obj *ink_list; check_allowed_subtypes(ctx, annot, PDF_NAME_InkList, ink_list_subtypes); ink_list = pdf_dict_get(ctx, annot->obj, PDF_NAME_InkList); return pdf_array_len(ctx, ink_list); }
int pdf_annot_vertex_count(fz_context *ctx, pdf_annot *annot) { pdf_obj *vertices; check_allowed_subtypes(ctx, annot, PDF_NAME_Vertices, vertices_subtypes); vertices = pdf_dict_get(ctx, annot->obj, PDF_NAME_Vertices); return pdf_array_len(ctx, vertices) / 2; }
void pdf_annot_line_ending_styles(fz_context *ctx, pdf_annot *annot, int *start_style, int *end_style) { pdf_obj *style; check_allowed_subtypes(ctx, annot, PDF_NAME_LE, line_ending_subtypes); style = pdf_dict_get(ctx, annot->obj, PDF_NAME_LE); *start_style = line_ending_value(ctx, pdf_array_get(ctx, style, 0)); *end_style = line_ending_value(ctx, pdf_array_get(ctx, style, 1)); }
int pdf_annot_ink_list_stroke_count(fz_context *ctx, pdf_annot *annot, int i) { pdf_obj *ink_list; pdf_obj *stroke; check_allowed_subtypes(ctx, annot, PDF_NAME(InkList), ink_list_subtypes); ink_list = pdf_dict_get(ctx, annot->obj, PDF_NAME(InkList)); stroke = pdf_array_get(ctx, ink_list, i); return pdf_array_len(ctx, stroke) / 2; }
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_annot_modification_date(fz_context *ctx, pdf_annot *annot, int64_t secs) { char s[40]; check_allowed_subtypes(ctx, annot, PDF_NAME(M), markup_subtypes); pdf_format_date(ctx, s, sizeof s, secs); pdf_dict_put_string(ctx, annot->obj, PDF_NAME(M), s, strlen(s)); pdf_dirty_annot(ctx, annot); }
void pdf_annot_line_ending_styles(fz_context *ctx, pdf_annot *annot, enum pdf_line_ending *start_style, enum pdf_line_ending *end_style) { pdf_obj *style; check_allowed_subtypes(ctx, annot, PDF_NAME(LE), line_ending_subtypes); style = pdf_dict_get(ctx, annot->obj, PDF_NAME(LE)); *start_style = pdf_line_ending_from_name(ctx, pdf_array_get(ctx, style, 0)); *end_style = pdf_line_ending_from_name(ctx, pdf_array_get(ctx, style, 1)); }
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); }
static void pdf_annot_color_imp(fz_context *ctx, pdf_annot *annot, pdf_obj *key, int *n, float color[4], pdf_obj **allowed) { pdf_obj *arr; int len; if (allowed) check_allowed_subtypes(ctx, annot, key, allowed); arr = pdf_dict_get(ctx, annot->obj, key); len = pdf_array_len(ctx, arr); switch (len) { case 0: if (n) *n = 0; break; case 1: case 2: if (n) *n = 1; if (color) color[0] = pdf_to_real(ctx, pdf_array_get(ctx, arr, 0)); break; case 3: if (n) *n = 3; if (color) { color[0] = pdf_to_real(ctx, pdf_array_get(ctx, arr, 0)); color[1] = pdf_to_real(ctx, pdf_array_get(ctx, arr, 1)); color[2] = pdf_to_real(ctx, pdf_array_get(ctx, arr, 2)); } break; case 4: default: if (n) *n = 4; if (color) { color[0] = pdf_to_real(ctx, pdf_array_get(ctx, arr, 0)); color[1] = pdf_to_real(ctx, pdf_array_get(ctx, arr, 1)); color[2] = pdf_to_real(ctx, pdf_array_get(ctx, arr, 2)); color[3] = pdf_to_real(ctx, pdf_array_get(ctx, arr, 3)); } break; } }
void pdf_set_annot_vertex(fz_context *ctx, pdf_annot *annot, int i, fz_point p) { 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); fz_transform_point(&p, &inv_page_ctm); vertices = pdf_dict_get(ctx, annot->obj, PDF_NAME(Vertices)); pdf_array_put_drop(ctx, vertices, i * 2 + 0, pdf_new_real(ctx, p.x)); pdf_array_put_drop(ctx, vertices, i * 2 + 1, pdf_new_real(ctx, p.y)); }
void pdf_annot_line(fz_context *ctx, pdf_annot *annot, fz_point *a, fz_point *b) { fz_matrix page_ctm; pdf_obj *line; check_allowed_subtypes(ctx, annot, PDF_NAME(L), line_subtypes); pdf_page_transform(ctx, annot->page, NULL, &page_ctm); line = pdf_dict_get(ctx, annot->obj, PDF_NAME(L)); a->x = pdf_array_get_real(ctx, line, 0); a->y = pdf_array_get_real(ctx, line, 1); b->x = pdf_array_get_real(ctx, line, 2); b->y = pdf_array_get_real(ctx, line, 3); fz_transform_point(a, &page_ctm); fz_transform_point(b, &page_ctm); }
fz_point pdf_annot_vertex(fz_context *ctx, pdf_annot *annot, int i) { pdf_obj *vertices; fz_matrix page_ctm; fz_point point; check_allowed_subtypes(ctx, annot, PDF_NAME(Vertices), vertices_subtypes); vertices = pdf_dict_get(ctx, annot->obj, PDF_NAME(Vertices)); pdf_page_transform(ctx, annot->page, NULL, &page_ctm); point.x = pdf_array_get_real(ctx, vertices, i * 2); point.y = pdf_array_get_real(ctx, vertices, i * 2 + 1); fz_transform_point(&point, &page_ctm); return point; }
void pdf_annot_vertex(fz_context *ctx, pdf_annot *annot, int i, float v[2]) { pdf_obj *vertices; fz_matrix page_ctm; fz_point point; check_allowed_subtypes(ctx, annot, PDF_NAME_Vertices, vertices_subtypes); vertices = pdf_dict_get(ctx, annot->obj, PDF_NAME_Vertices); pdf_page_transform(ctx, annot->page, NULL, &page_ctm); point.x = pdf_to_real(ctx, pdf_array_get(ctx, vertices, i * 2)); point.y = pdf_to_real(ctx, pdf_array_get(ctx, vertices, i * 2 + 1)); fz_transform_point(&point, &page_ctm); v[0] = point.x; v[1] = point.y; }
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; }
const char * pdf_annot_icon_name(fz_context *ctx, pdf_annot *annot) { pdf_obj *name; check_allowed_subtypes(ctx, annot, PDF_NAME(Name), icon_name_subtypes); name = pdf_dict_get(ctx, annot->obj, PDF_NAME(Name)); if (!name) { pdf_obj *subtype = pdf_dict_get(ctx, annot->obj, PDF_NAME(Subtype)); if (pdf_name_eq(ctx, subtype, PDF_NAME(Text))) return "Note"; if (pdf_name_eq(ctx, subtype, PDF_NAME(Stamp))) return "Draft"; if (pdf_name_eq(ctx, subtype, PDF_NAME(FileAttachment))) return "PushPin"; if (pdf_name_eq(ctx, subtype, PDF_NAME(Sound))) return "Speaker"; } return pdf_to_name(ctx, name); }
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); }