summaryrefslogtreecommitdiff
path: root/source/pdf/pdf-annot-edit.c
diff options
context:
space:
mode:
authorFred Ross-Perry <fred.ross-perry@artifex.com>2017-11-13 17:04:06 -0800
committerTor Andersson <tor.andersson@artifex.com>2017-11-22 23:09:51 +0100
commited28a166dace50d1a555689b9d5353e62a1b1e69 (patch)
tree67dca9996a83d5939b7e3e4a91da8685a4764291 /source/pdf/pdf-annot-edit.c
parent52b6e193ba376f46dec2ae3b8c316f2e08fefc13 (diff)
downloadmupdf-ed28a166dace50d1a555689b9d5353e62a1b1e69.tar.xz
jni/js: Use correct text encoding in annotation author and contents.
Also clarify that a copy of author/contents is returned, and that the caller must free them.
Diffstat (limited to 'source/pdf/pdf-annot-edit.c')
-rw-r--r--source/pdf/pdf-annot-edit.c55
1 files changed, 46 insertions, 9 deletions
diff --git a/source/pdf/pdf-annot-edit.c b/source/pdf/pdf-annot-edit.c
index 20aeff11..09e63002 100644
--- a/source/pdf/pdf-annot-edit.c
+++ b/source/pdf/pdf-annot-edit.c
@@ -259,17 +259,18 @@ pdf_set_annot_rect(fz_context *ctx, pdf_annot *annot, const fz_rect *rect)
pdf_dirty_annot(ctx, annot);
}
-const char *
-pdf_annot_contents(fz_context *ctx, pdf_annot *annot)
+char *
+pdf_copy_annot_contents(fz_context *ctx, pdf_annot *annot)
{
- return pdf_to_str_buf(ctx, pdf_dict_get(ctx, annot->obj, PDF_NAME_Contents));
+ return pdf_to_utf8(ctx, pdf_dict_get(ctx, annot->obj, PDF_NAME_Contents));
}
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)));
+ pdf_dict_put_drop(ctx, annot->obj, PDF_NAME_Contents,
+ pdf_new_text_string(ctx, doc, text));
pdf_dirty_annot(ctx, annot);
}
@@ -842,11 +843,25 @@ pdf_set_text_annot_position(fz_context *ctx, pdf_annot *annot, fz_point pt)
pdf_dict_put_drop(ctx, annot->obj, PDF_NAME_F, pdf_new_int(ctx, doc, flags));
}
-const char *
-pdf_annot_author(fz_context *ctx, pdf_annot *annot)
-{
- return pdf_to_str_buf(ctx, pdf_dict_get(ctx, annot->obj, PDF_NAME_T));
-}
+static pdf_obj *markup_subtypes[] = {
+ PDF_NAME_Text,
+ PDF_NAME_FreeText,
+ PDF_NAME_Line,
+ PDF_NAME_Square,
+ PDF_NAME_Circle,
+ PDF_NAME_Polygon,
+ PDF_NAME_PolyLine,
+ PDF_NAME_Highlight,
+ PDF_NAME_Underline,
+ PDF_NAME_Squiggly,
+ PDF_NAME_StrikeOut,
+ PDF_NAME_Stamp,
+ PDF_NAME_Caret,
+ PDF_NAME_Ink,
+ PDF_NAME_FileAttachment,
+ PDF_NAME_Sound,
+ NULL,
+};
const char *
pdf_annot_date(fz_context *ctx, pdf_annot *annot)
@@ -855,6 +870,28 @@ pdf_annot_date(fz_context *ctx, pdf_annot *annot)
return pdf_to_str_buf(ctx, pdf_dict_get(ctx, annot->obj, PDF_NAME_CreationDate));
}
+int
+pdf_annot_has_author(fz_context *ctx, pdf_annot *annot)
+{
+ return is_allowed_subtype(ctx, annot, PDF_NAME_T, markup_subtypes);
+}
+
+char *
+pdf_copy_annot_author(fz_context *ctx, pdf_annot *annot)
+{
+ check_allowed_subtypes(ctx, annot, PDF_NAME_T, markup_subtypes);
+ return pdf_to_utf8(ctx, pdf_dict_get(ctx, annot->obj, PDF_NAME_T));
+}
+
+void
+pdf_set_annot_author(fz_context *ctx, pdf_annot *annot, const char *author)
+{
+ pdf_document *doc = annot->page->doc;
+ check_allowed_subtypes(ctx, annot, PDF_NAME_T, markup_subtypes);
+ pdf_dict_put_drop(ctx, annot->obj, PDF_NAME_T, pdf_new_text_string(ctx, doc, author));
+ pdf_dirty_annot(ctx, annot);
+}
+
pdf_obj *
pdf_annot_irt(fz_context *ctx, pdf_annot *annot)
{