summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2015-04-14 11:53:53 +0200
committerRobin Watts <robin.watts@artifex.com>2015-04-14 16:13:58 +0100
commita7be4a1caca767baa0ce0946792f3c3e9e150308 (patch)
tree76804ec000992a20fdf62bf962ef06df6750a0e8
parent1bc74dac2b251764d373c164e2b5235875f27901 (diff)
downloadmupdf-a7be4a1caca767baa0ce0946792f3c3e9e150308.tar.xz
Split fz_meta into separate querying functions.
Add fz_has_permission function to fz_document. Add fz_lookup_metadata function to fz_document. Remove fz_meta function from fz_document.
-rw-r--r--include/mupdf/fitz.h1
-rw-r--r--include/mupdf/fitz/document.h56
-rw-r--r--include/mupdf/fitz/meta.h80
-rw-r--r--include/mupdf/pdf/document.h21
-rw-r--r--platform/android/jni/mupdf.c2
-rw-r--r--platform/x11/win_main.c27
-rw-r--r--source/cbz/mucbz.c15
-rw-r--r--source/cbz/muimg.c15
-rw-r--r--source/cbz/mutiff.c15
-rw-r--r--source/fitz/document.c18
-rw-r--r--source/pdf/pdf-crypt.c24
-rw-r--r--source/pdf/pdf-xref.c98
-rw-r--r--source/xps/xps-zip.c15
13 files changed, 160 insertions, 227 deletions
diff --git a/include/mupdf/fitz.h b/include/mupdf/fitz.h
index 34c3ddff..450626fa 100644
--- a/include/mupdf/fitz.h
+++ b/include/mupdf/fitz.h
@@ -46,7 +46,6 @@
#include "mupdf/fitz/outline.h"
#include "mupdf/fitz/document.h"
#include "mupdf/fitz/annotation.h"
-#include "mupdf/fitz/meta.h"
#include "mupdf/fitz/write-document.h"
diff --git a/include/mupdf/fitz/document.h b/include/mupdf/fitz/document.h
index 9d8a60a6..9e81efbb 100644
--- a/include/mupdf/fitz/document.h
+++ b/include/mupdf/fitz/document.h
@@ -16,6 +16,7 @@ typedef struct fz_document_s fz_document;
typedef struct fz_document_handler_s fz_document_handler;
typedef struct fz_page_s fz_page;
typedef struct fz_annot_s fz_annot;
+typedef enum fz_permission_e fz_permission;
// TODO: move out of this interface (it's pdf specific)
typedef struct fz_write_options_s fz_write_options;
@@ -23,11 +24,12 @@ typedef struct fz_write_options_s fz_write_options;
typedef void (fz_document_close_fn)(fz_context *ctx, fz_document *doc);
typedef int (fz_document_needs_password_fn)(fz_context *ctx, fz_document *doc);
typedef int (fz_document_authenticate_password_fn)(fz_context *ctx, fz_document *doc, const char *password);
+typedef int (fz_document_has_permission_fn)(fz_context *ctx, fz_document *doc, fz_permission permission);
typedef fz_outline *(fz_document_load_outline_fn)(fz_context *ctx, fz_document *doc);
typedef void (fz_document_layout_fn)(fz_context *ctx, fz_document *doc, float w, float h, float em);
typedef int (fz_document_count_pages_fn)(fz_context *ctx, fz_document *doc);
typedef fz_page *(fz_document_load_page_fn)(fz_context *ctx, fz_document *doc, int number);
-typedef int (fz_document_meta_fn)(fz_context *ctx, fz_document *doc, int key, void *ptr, int size);
+typedef int (fz_document_lookup_metadata_fn)(fz_context *ctx, fz_document *doc, const char *key, char *buf, int size);
typedef void (fz_document_write_fn)(fz_context *ctx, fz_document *doc, char *filename, fz_write_options *opts);
typedef fz_link *(fz_page_load_links_fn)(fz_context *ctx, fz_page *page);
@@ -61,11 +63,12 @@ struct fz_document_s
fz_document_close_fn *close;
fz_document_needs_password_fn *needs_password;
fz_document_authenticate_password_fn *authenticate_password;
+ fz_document_has_permission_fn *has_permission;
fz_document_load_outline_fn *load_outline;
fz_document_layout_fn *layout;
fz_document_count_pages_fn *count_pages;
fz_document_load_page_fn *load_page;
- fz_document_meta_fn *meta;
+ fz_document_lookup_metadata_fn *lookup_metadata;
fz_document_write_fn *write;
int did_layout;
};
@@ -300,4 +303,53 @@ void fz_drop_page(fz_context *ctx, fz_page *page);
*/
fz_transition *fz_page_presentation(fz_context *ctx, fz_page *page, float *duration);
+/*
+ fz_has_permission: Check permission flags on document.
+*/
+int fz_has_permission(fz_context *ctx, fz_document *doc, fz_permission p);
+
+enum fz_permission_e
+{
+ FZ_PERMISSION_PRINT = 'p',
+ FZ_PERMISSION_COPY = 'c',
+ FZ_PERMISSION_EDIT = 'e',
+ FZ_PERMISSION_ANNOTATE = 'n',
+};
+
+/*
+ fz_lookup_metadata: Retrieve document meta data strings.
+
+ doc: The document to query.
+
+ key: Which meta data key to retrieve...
+
+ Basic information:
+ 'format' -- Document format and version.
+ 'encryption' -- Description of the encryption used.
+
+ From the document information dictionary:
+ 'info:Title'
+ 'info:Author'
+ 'info:Subject'
+ 'info:Keywords'
+ 'info:Creator'
+ 'info:Producer'
+ 'info:CreationDate'
+ 'info:ModDate'
+
+ buf: The buffer to hold the results (a nul-terminated UTF-8 string).
+
+ size: Size of 'buf'.
+
+ Returns the size of the output string (may be larger than 'size' if
+ the output was truncated), or -1 if the key is not recognized or found.
+*/
+int fz_lookup_metadata(fz_context *ctx, fz_document *doc, const char *key, char *buf, int size);
+
+#define FZ_META_FORMAT "format"
+#define FZ_META_ENCRYPTION "encryption"
+
+#define FZ_META_INFO_AUTHOR "info:Author"
+#define FZ_META_INFO_TITLE "info:Title"
+
#endif
diff --git a/include/mupdf/fitz/meta.h b/include/mupdf/fitz/meta.h
deleted file mode 100644
index 8075c3c6..00000000
--- a/include/mupdf/fitz/meta.h
+++ /dev/null
@@ -1,80 +0,0 @@
-#ifndef MUPDF_FITZ_META_H
-#define MUPDF_FITZ_META_H
-
-#include "mupdf/fitz/system.h"
-#include "mupdf/fitz/context.h"
-#include "mupdf/fitz/document.h"
-
-/*
- fz_meta: Perform a meta operation on a document.
-
- (In development - Subject to change in future versions)
-
- Meta operations provide a way to perform format specific
- operations on a document. The meta operation scheme is
- designed to be extensible so that new features can be
- transparently added in later versions of the library.
-
- doc: The document on which to perform the meta operation.
-
- key: The meta operation to try. If a particular operation
- is unsupported on a given document, the function will return
- FZ_META_UNKNOWN_KEY.
-
- ptr: An operation dependent (possibly NULL) pointer.
-
- size: An operation dependent integer. Often this will
- be the size of the block pointed to by ptr, but not always.
-
- Returns an operation dependent value; FZ_META_UNKNOWN_KEY
- always means "unknown operation for this document". In general
- FZ_META_OK should be used to indicate successful operation.
-*/
-int fz_meta(fz_context *ctx, fz_document *doc, int key, void *ptr, int size);
-
-enum
-{
- FZ_META_UNKNOWN_KEY = -1,
- FZ_META_OK = 0,
-
- /*
- ptr: Pointer to block (uninitialised on entry)
- size: Size of block (at least 64 bytes)
- Returns: Document format as a brief text string.
- All formats should support this.
- */
- FZ_META_FORMAT_INFO = 1,
-
- /*
- ptr: Pointer to block (uninitialised on entry)
- size: Size of block (at least 64 bytes)
- Returns: Encryption info as a brief text string.
- */
- FZ_META_CRYPT_INFO = 2,
-
- /*
- ptr: NULL
- size: Which permission to check
- Returns: 1 if permitted, 0 otherwise.
- */
- FZ_META_HAS_PERMISSION = 3,
-
- FZ_PERMISSION_PRINT = 0,
- FZ_PERMISSION_CHANGE = 1,
- FZ_PERMISSION_COPY = 2,
- FZ_PERMISSION_NOTES = 3,
-
- /*
- ptr: Pointer to block. First entry in the block is
- a pointer to a UTF8 string to lookup. The rest of the
- block is uninitialised on entry.
- size: size of the block in bytes.
- Returns: 0 if not found. 1 if found. The string
- result is copied into the block (truncated to size
- and NULL terminated)
-
- */
- FZ_META_INFO = 4,
-};
-
-#endif
diff --git a/include/mupdf/pdf/document.h b/include/mupdf/pdf/document.h
index 49f674a7..41ee6b07 100644
--- a/include/mupdf/pdf/document.h
+++ b/include/mupdf/pdf/document.h
@@ -104,25 +104,8 @@ pdf_document *pdf_specifics(fz_context *ctx, fz_document *doc);
int pdf_needs_password(fz_context *ctx, pdf_document *doc);
int pdf_authenticate_password(fz_context *ctx, pdf_document *doc, const char *pw);
-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
-};
-
-int pdf_has_permission(fz_context *ctx, pdf_document *doc, int p);
-
-/*
- Metadata interface.
-*/
-int pdf_meta(fz_context *ctx, pdf_document *doc, int key, void *ptr, int size);
+int pdf_has_permission(fz_context *ctx, pdf_document *doc, fz_permission p);
+int pdf_lookup_metadata(fz_context *ctx, pdf_document *doc, const char *key, char *ptr, int size);
fz_outline *pdf_load_outline(fz_context *ctx, pdf_document *doc);
diff --git a/platform/android/jni/mupdf.c b/platform/android/jni/mupdf.c
index 1cb50c54..d351ee6c 100644
--- a/platform/android/jni/mupdf.c
+++ b/platform/android/jni/mupdf.c
@@ -524,7 +524,7 @@ JNI_FN(MuPDFCore_fileFormatInternal)(JNIEnv * env, jobject thiz)
globals *glo = get_globals(env, thiz);
fz_context *ctx = glo->ctx;
- fz_meta(ctx, glo->doc, FZ_META_FORMAT_INFO, info, sizeof(info));
+ fz_lookup_metadata(ctx, glo->doc, FZ_META_FORMAT, info, sizeof(info));
return (*env)->NewStringUTF(env, info);
}
diff --git a/platform/x11/win_main.c b/platform/x11/win_main.c
index df29e022..6b5bbe05 100644
--- a/platform/x11/win_main.c
+++ b/platform/x11/win_main.c
@@ -452,7 +452,11 @@ dloginfoproc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
SetDlgItemTextW(hwnd, 0x10, wbuf);
- if (fz_meta(ctx, doc, FZ_META_FORMAT_INFO, buf, 256) < 0)
+ if (fz_lookup_metadata(ctx, doc, FZ_META_FORMAT, buf, sizeof buf) >= 0)
+ {
+ SetDlgItemTextA(hwnd, 0x11, buf);
+ }
+ else
{
SetDlgItemTextA(hwnd, 0x11, "Unknown");
SetDlgItemTextA(hwnd, 0x12, "None");
@@ -460,9 +464,7 @@ dloginfoproc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
return TRUE;
}
- SetDlgItemTextA(hwnd, 0x11, buf);
-
- if (fz_meta(ctx, doc, FZ_META_CRYPT_INFO, buf, 256) == 0)
+ if (fz_lookup_metadata(ctx, doc, FZ_META_ENCRYPTION, buf, sizeof buf) >= 0)
{
SetDlgItemTextA(hwnd, 0x12, buf);
}
@@ -470,26 +472,25 @@ dloginfoproc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
SetDlgItemTextA(hwnd, 0x12, "None");
}
+
buf[0] = 0;
- if (fz_meta(ctx, doc, FZ_META_HAS_PERMISSION, NULL, FZ_PERMISSION_PRINT) == 0)
+ if (fz_has_permission(ctx, doc, FZ_PERMISSION_PRINT))
strcat(buf, "print, ");
- if (fz_meta(ctx, doc, FZ_META_HAS_PERMISSION, NULL, FZ_PERMISSION_CHANGE) == 0)
- strcat(buf, "modify, ");
- if (fz_meta(ctx, doc, FZ_META_HAS_PERMISSION, NULL, FZ_PERMISSION_COPY) == 0)
+ if (fz_has_permission(ctx, doc, FZ_PERMISSION_COPY))
strcat(buf, "copy, ");
- if (fz_meta(ctx, doc, FZ_META_HAS_PERMISSION, NULL, FZ_PERMISSION_NOTES) == 0)
+ if (fz_has_permission(ctx, doc, FZ_PERMISSION_EDIT))
+ strcat(buf, "edit, ");
+ if (fz_has_permission(ctx, doc, FZ_PERMISSION_ANNOTATE))
strcat(buf, "annotate, ");
if (strlen(buf) > 2)
buf[strlen(buf)-2] = 0;
else
- strcpy(buf, "None");
+ strcpy(buf, "none");
SetDlgItemTextA(hwnd, 0x13, buf);
#define SETUTF8(ID, STRING) \
+ if (fz_lookup_metadata(ctx, doc, "info:" STRING, buf, sizeof buf) >= 0) \
{ \
- *(char **)buf = STRING; \
- if (fz_meta(ctx, doc, FZ_META_INFO, buf, 256) <= 0) \
- buf[0] = 0; \
MultiByteToWideChar(CP_UTF8, 0, buf, -1, bufx, nelem(bufx)); \
SetDlgItemTextW(hwnd, ID, bufx); \
}
diff --git a/source/cbz/mucbz.c b/source/cbz/mucbz.c
index c85cca45..14be8333 100644
--- a/source/cbz/mucbz.c
+++ b/source/cbz/mucbz.c
@@ -187,16 +187,11 @@ cbz_load_page(fz_context *ctx, cbz_document *doc, int number)
}
static int
-cbz_meta(fz_context *ctx, cbz_document *doc, int key, void *ptr, int size)
+cbz_lookup_metadata(fz_context *ctx, cbz_document *doc, const char *key, char *buf, int size)
{
- switch (key)
- {
- case FZ_META_FORMAT_INFO:
- sprintf((char *)ptr, "CBZ");
- return FZ_META_OK;
- default:
- return FZ_META_UNKNOWN_KEY;
- }
+ if (!strcmp(key, "format"))
+ return fz_strlcpy(buf, "CBZ", size);
+ return -1;
}
static cbz_document *
@@ -207,7 +202,7 @@ cbz_open_document_with_stream(fz_context *ctx, fz_stream *file)
doc->super.close = (fz_document_close_fn *)cbz_close_document;
doc->super.count_pages = (fz_document_count_pages_fn *)cbz_count_pages;
doc->super.load_page = (fz_document_load_page_fn *)cbz_load_page;
- doc->super.meta = (fz_document_meta_fn *)cbz_meta;
+ doc->super.lookup_metadata = (fz_document_lookup_metadata_fn *)cbz_lookup_metadata;
fz_try(ctx)
{
diff --git a/source/cbz/muimg.c b/source/cbz/muimg.c
index 169fec95..ac6997ee 100644
--- a/source/cbz/muimg.c
+++ b/source/cbz/muimg.c
@@ -82,16 +82,11 @@ img_load_page(fz_context *ctx, img_document *doc, int number)
}
static int
-img_meta(fz_context *ctx, img_document *doc, int key, void *ptr, int size)
+img_lookup_metadata(fz_context *ctx, img_document *doc, const char *key, char *buf, int size)
{
- switch(key)
- {
- case FZ_META_FORMAT_INFO:
- sprintf((char *)ptr, "IMAGE");
- return FZ_META_OK;
- default:
- return FZ_META_UNKNOWN_KEY;
- }
+ if (!strcmp(key, "format"))
+ return fz_strlcpy(buf, "Image", size);
+ return -1;
}
static img_document *
@@ -102,7 +97,7 @@ img_new_document(fz_context *ctx, fz_image *image)
doc->super.close = (fz_document_close_fn *)img_close_document;
doc->super.count_pages = (fz_document_count_pages_fn *)img_count_pages;
doc->super.load_page = (fz_document_load_page_fn *)img_load_page;
- doc->super.meta = (fz_document_meta_fn *)img_meta;
+ doc->super.lookup_metadata = (fz_document_lookup_metadata_fn *)img_lookup_metadata;
doc->image = fz_keep_image(ctx, image);
diff --git a/source/cbz/mutiff.c b/source/cbz/mutiff.c
index 3a30cc79..3749fb11 100644
--- a/source/cbz/mutiff.c
+++ b/source/cbz/mutiff.c
@@ -100,16 +100,11 @@ tiff_count_pages(fz_context *ctx, tiff_document *doc)
}
static int
-tiff_meta(fz_context *ctx, tiff_document *doc, int key, void *ptr, int size)
+tiff_lookup_metadata(fz_context *ctx, tiff_document *doc, const char *key, char *buf, int size)
{
- switch (key)
- {
- case FZ_META_FORMAT_INFO:
- sprintf((char *)ptr, "TIFF");
- return FZ_META_OK;
- default:
- return FZ_META_UNKNOWN_KEY;
- }
+ if (!strcmp(key, "format"))
+ return fz_strlcpy(buf, "TIFF", size);
+ return -1;
}
static void
@@ -129,7 +124,7 @@ tiff_open_document_with_stream(fz_context *ctx, fz_stream *file)
doc->super.close = (fz_document_close_fn *)tiff_close_document;
doc->super.count_pages = (fz_document_count_pages_fn *)tiff_count_pages;
doc->super.load_page = (fz_document_load_page_fn *)tiff_load_page;
- doc->super.meta = (fz_document_meta_fn *)tiff_meta;
+ doc->super.lookup_metadata = (fz_document_lookup_metadata_fn *)tiff_lookup_metadata;
fz_try(ctx)
{
diff --git a/source/fitz/document.c b/source/fitz/document.c
index 232aa931..78bd707c 100644
--- a/source/fitz/document.c
+++ b/source/fitz/document.c
@@ -194,6 +194,14 @@ fz_authenticate_password(fz_context *ctx, fz_document *doc, const char *password
return 1;
}
+int
+fz_has_permission(fz_context *ctx, fz_document *doc, fz_permission p)
+{
+ if (doc && doc->has_permission)
+ return doc->has_permission(ctx, doc, p);
+ return 1;
+}
+
fz_outline *
fz_load_outline(fz_context *ctx, fz_document *doc)
{
@@ -222,11 +230,13 @@ fz_count_pages(fz_context *ctx, fz_document *doc)
}
int
-fz_meta(fz_context *ctx, fz_document *doc, int key, void *ptr, int size)
+fz_lookup_metadata(fz_context *ctx, fz_document *doc, const char *key, char *buf, int size)
{
- if (doc && doc->meta)
- return doc->meta(ctx, doc, key, ptr, size);
- return FZ_META_UNKNOWN_KEY;
+ if (buf && size > 0)
+ buf[0] = 0;
+ if (doc && doc->lookup_metadata)
+ return doc->lookup_metadata(ctx, doc, key, buf, size);
+ return -1;
}
void
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;
diff --git a/source/xps/xps-zip.c b/source/xps/xps-zip.c
index 3759c4b6..0580378b 100644
--- a/source/xps/xps-zip.c
+++ b/source/xps/xps-zip.c
@@ -221,16 +221,11 @@ xps_close_document(fz_context *ctx, xps_document *doc)
}
static int
-xps_meta(fz_context *ctx, xps_document *doc, int key, void *ptr, int size)
+xps_lookup_metadata(fz_context *ctx, xps_document *doc, const char *key, char *buf, int size)
{
- switch (key)
- {
- case FZ_META_FORMAT_INFO:
- sprintf((char *)ptr, "XPS");
- return FZ_META_OK;
- default:
- return FZ_META_UNKNOWN_KEY;
- }
+ if (!strcmp(key, "format"))
+ return fz_strlcpy(buf, "XPS", size);
+ return -1;
}
static void
@@ -241,5 +236,5 @@ xps_init_document(fz_context *ctx, xps_document *doc)
doc->super.load_outline = (fz_document_load_outline_fn *)xps_load_outline;
doc->super.count_pages = (fz_document_count_pages_fn *)xps_count_pages;
doc->super.load_page = (fz_document_load_page_fn *)xps_load_page;
- doc->super.meta = (fz_document_meta_fn *)xps_meta;
+ doc->super.lookup_metadata = (fz_document_lookup_metadata_fn *)xps_lookup_metadata;
}