summaryrefslogtreecommitdiff
path: root/source/pdf
diff options
context:
space:
mode:
Diffstat (limited to 'source/pdf')
-rw-r--r--source/pdf/pdf-crypt.c24
-rw-r--r--source/pdf/pdf-xref.c98
2 files changed, 55 insertions, 67 deletions
diff --git a/source/pdf/pdf-crypt.c b/source/pdf/pdf-crypt.c
index 88e485ff..17419581 100644
--- a/source/pdf/pdf-crypt.c
+++ b/source/pdf/pdf-crypt.c
@@ -9,6 +9,19 @@ enum
PDF_CRYPT_UNKNOWN,
};
+enum
+{
+ PDF_PERM_PRINT = 1 << 2,
+ PDF_PERM_CHANGE = 1 << 3,
+ PDF_PERM_COPY = 1 << 4,
+ PDF_PERM_NOTES = 1 << 5,
+ PDF_PERM_FILL_FORM = 1 << 8,
+ PDF_PERM_ACCESSIBILITY = 1 << 9,
+ PDF_PERM_ASSEMBLE = 1 << 10,
+ PDF_PERM_HIGH_RES_PRINT = 1 << 11,
+ PDF_DEFAULT_PERM_FLAGS = 0xfffc
+};
+
typedef struct pdf_crypt_filter_s pdf_crypt_filter;
struct pdf_crypt_filter_s
@@ -765,11 +778,18 @@ pdf_needs_password(fz_context *ctx, pdf_document *doc)
}
int
-pdf_has_permission(fz_context *ctx, pdf_document *doc, int p)
+pdf_has_permission(fz_context *ctx, pdf_document *doc, fz_permission p)
{
if (!doc->crypt)
return 1;
- return doc->crypt->p & p;
+ switch (p)
+ {
+ case FZ_PERMISSION_PRINT: return doc->crypt->p & PDF_PERM_PRINT;
+ case FZ_PERMISSION_COPY: return doc->crypt->p & PDF_PERM_COPY;
+ case FZ_PERMISSION_EDIT: return doc->crypt->p & PDF_PERM_CHANGE;
+ case FZ_PERMISSION_ANNOTATE: return doc->crypt->p & PDF_PERM_NOTES;
+ }
+ return 1;
}
unsigned char *
diff --git a/source/pdf/pdf-xref.c b/source/pdf/pdf-xref.c
index 91faac35..0ec3b6d4 100644
--- a/source/pdf/pdf-xref.c
+++ b/source/pdf/pdf-xref.c
@@ -2155,77 +2155,44 @@ pdf_update_stream(fz_context *ctx, pdf_document *doc, pdf_obj *obj, fz_buffer *n
}
int
-pdf_meta(fz_context *ctx, pdf_document *doc, int key, void *ptr, int size)
-{
- switch (key)
- {
- /*
- ptr: Pointer to block (uninitialised on entry)
- size: Size of block (at least 64 bytes)
- Returns: Document format as a brief text string.
- */
- case FZ_META_FORMAT_INFO:
- sprintf((char *)ptr, "PDF %d.%d", doc->version/10, doc->version % 10);
- return FZ_META_OK;
- case FZ_META_CRYPT_INFO:
+pdf_lookup_metadata(fz_context *ctx, pdf_document *doc, const char *key, char *buf, int size)
+{
+ if (!strcmp(key, "format"))
+ return fz_snprintf(buf, size, "PDF %d.%d", doc->version/10, doc->version % 10);
+
+ if (!strcmp(key, "encryption"))
+ {
if (doc->crypt)
- sprintf((char *)ptr, "Standard V%d R%d %d-bit %s",
- pdf_crypt_version(ctx, doc),
- pdf_crypt_revision(ctx, doc),
- pdf_crypt_length(ctx, doc),
- pdf_crypt_method(ctx, doc));
+ return fz_snprintf(buf, size, "Standard V%d R%d %d-bit %s",
+ pdf_crypt_version(ctx, doc),
+ pdf_crypt_revision(ctx, doc),
+ pdf_crypt_length(ctx, doc),
+ pdf_crypt_method(ctx, doc));
else
- sprintf((char *)ptr, "None");
- return FZ_META_OK;
- case FZ_META_HAS_PERMISSION:
- {
- int i;
- switch (size)
- {
- case FZ_PERMISSION_PRINT:
- i = PDF_PERM_PRINT;
- break;
- case FZ_PERMISSION_CHANGE:
- i = PDF_PERM_CHANGE;
- break;
- case FZ_PERMISSION_COPY:
- i = PDF_PERM_COPY;
- break;
- case FZ_PERMISSION_NOTES:
- i = PDF_PERM_NOTES;
- break;
- default:
- return 0;
- }
- return pdf_has_permission(ctx, doc, i);
+ return fz_strlcpy(buf, "None", size);
}
- case FZ_META_INFO:
+
+ if (strstr(key, "info:") == key)
{
- pdf_obj *info = pdf_dict_get(ctx, pdf_trailer(ctx, doc), PDF_NAME_Info);
+ pdf_obj *info;
+ char *s;
+ int n;
+
+ info = pdf_dict_get(ctx, pdf_trailer(ctx, doc), PDF_NAME_Info);
if (!info)
- {
- if (ptr)
- *(char *)ptr = 0;
- return 0;
- }
- info = pdf_dict_gets(ctx, info, *(char **)ptr);
+ return -1;
+
+ info = pdf_dict_gets(ctx, info, key + 5);
if (!info)
- {
- if (ptr)
- *(char *)ptr = 0;
- return 0;
- }
- if (info && ptr && size)
- {
- char *utf8 = pdf_to_utf8(ctx, doc, info);
- fz_strlcpy(ptr, utf8, size);
- fz_free(ctx, utf8);
- }
- return 1;
- }
- default:
- return FZ_META_UNKNOWN_KEY;
+ return -1;
+
+ s = pdf_to_utf8(ctx, doc, info);
+ n = fz_strlcpy(buf, s, size);
+ fz_free(ctx, s);
+ return n;
}
+
+ return -1;
}
fz_transition *
@@ -2256,10 +2223,11 @@ pdf_new_document(fz_context *ctx, fz_stream *file)
doc->super.close = (fz_document_close_fn *)pdf_close_document;
doc->super.needs_password = (fz_document_needs_password_fn *)pdf_needs_password;
doc->super.authenticate_password = (fz_document_authenticate_password_fn *)pdf_authenticate_password;
+ doc->super.has_permission = (fz_document_has_permission_fn *)pdf_has_permission;
doc->super.load_outline = (fz_document_load_outline_fn *)pdf_load_outline;
doc->super.count_pages = (fz_document_count_pages_fn *)pdf_count_pages;
doc->super.load_page = (fz_document_load_page_fn *)pdf_load_page;
- doc->super.meta = (fz_document_meta_fn *)pdf_meta;
+ doc->super.lookup_metadata = (fz_document_lookup_metadata_fn *)pdf_lookup_metadata;
doc->super.write = (fz_document_write_fn *)pdf_write_document;
doc->update_appearance = pdf_update_appearance;