summaryrefslogtreecommitdiff
path: root/source/xps
diff options
context:
space:
mode:
Diffstat (limited to 'source/xps')
-rw-r--r--source/xps/xps-doc.c4
-rw-r--r--source/xps/xps-glyphs.c15
-rw-r--r--source/xps/xps-image.c5
-rw-r--r--source/xps/xps-imp.h3
-rw-r--r--source/xps/xps-outline.c2
-rw-r--r--source/xps/xps-resource.c2
-rw-r--r--source/xps/xps-zip.c20
7 files changed, 19 insertions, 32 deletions
diff --git a/source/xps/xps-doc.c b/source/xps/xps-doc.c
index 8197f505..8f708bf7 100644
--- a/source/xps/xps-doc.c
+++ b/source/xps/xps-doc.c
@@ -276,7 +276,7 @@ xps_parse_metadata(fz_context *ctx, xps_document *doc, xps_part *part, xps_fixdo
doc->base_uri = buf;
doc->part_uri = part->name;
- root = fz_parse_xml(ctx, part->data, part->size, 0);
+ root = fz_parse_xml(ctx, part->data, 0);
xps_parse_metadata_imp(ctx, doc, root, fixdoc);
fz_drop_xml(ctx, root);
@@ -353,7 +353,7 @@ xps_load_fixed_page(fz_context *ctx, xps_document *doc, xps_fixpage *page)
part = xps_read_part(ctx, doc, page->name);
fz_try(ctx)
{
- root = fz_parse_xml(ctx, part->data, part->size, 0);
+ root = fz_parse_xml(ctx, part->data, 0);
}
fz_always(ctx)
{
diff --git a/source/xps/xps-glyphs.c b/source/xps/xps-glyphs.c
index 0ea1ab9d..98a44217 100644
--- a/source/xps/xps-glyphs.c
+++ b/source/xps/xps-glyphs.c
@@ -98,10 +98,13 @@ xps_deobfuscate_font_resource(fz_context *ctx, xps_document *doc, xps_part *part
{
unsigned char buf[33];
unsigned char key[16];
+ unsigned char *data;
+ size_t size;
char *p;
int i;
- if (part->size < 32)
+ size = fz_buffer_storage(ctx, part->data, &data);
+ if (size < 32)
{
fz_warn(ctx, "insufficient data for font deobfuscation");
return;
@@ -129,8 +132,8 @@ xps_deobfuscate_font_resource(fz_context *ctx, xps_document *doc, xps_part *part
for (i = 0; i < 16; i++)
{
- part->data[i] ^= key[15-i];
- part->data[i+16] ^= key[15-i];
+ data[i] ^= key[15-i];
+ data[i+16] ^= key[15-i];
}
}
@@ -224,14 +227,10 @@ xps_lookup_font(fz_context *ctx, xps_document *doc, char *base_uri, char *font_u
fz_try(ctx)
{
- buf = fz_new_buffer_from_data(ctx, part->data, part->size);
- /* part->data is now owned by buf */
- part->data = NULL;
- font = fz_new_font_from_buffer(ctx, NULL, buf, subfontid, 1);
+ font = fz_new_font_from_buffer(ctx, NULL, part->data, subfontid, 1);
}
fz_always(ctx)
{
- fz_drop_buffer(ctx, buf);
xps_drop_part(ctx, doc, part);
}
fz_catch(ctx)
diff --git a/source/xps/xps-image.c b/source/xps/xps-image.c
index 83f7ac0d..aa495566 100644
--- a/source/xps/xps-image.c
+++ b/source/xps/xps-image.c
@@ -4,10 +4,7 @@
static fz_image *
xps_load_image(fz_context *ctx, xps_document *doc, xps_part *part)
{
- /* Ownership of data always passes in here */
- unsigned char *data = part->data;
- part->data = NULL;
- return fz_new_image_from_data(ctx, data, part->size);
+ return fz_new_image_from_buffer(ctx, part->data);
}
/* FIXME: area unused! */
diff --git a/source/xps/xps-imp.h b/source/xps/xps-imp.h
index 2ba78a50..5db36c5f 100644
--- a/source/xps/xps-imp.h
+++ b/source/xps/xps-imp.h
@@ -54,8 +54,7 @@ typedef struct xps_part_s xps_part;
struct xps_part_s
{
char *name;
- size_t size;
- unsigned char *data;
+ fz_buffer *data;
};
int xps_has_part(fz_context *ctx, xps_document *doc, char *partname);
diff --git a/source/xps/xps-outline.c b/source/xps/xps-outline.c
index bcb16509..472af0c3 100644
--- a/source/xps/xps-outline.c
+++ b/source/xps/xps-outline.c
@@ -86,7 +86,7 @@ xps_load_document_structure(fz_context *ctx, xps_document *doc, xps_fixdoc *fixd
part = xps_read_part(ctx, doc, fixdoc->outline);
fz_try(ctx)
{
- root = fz_parse_xml(ctx, part->data, part->size, 0);
+ root = fz_parse_xml(ctx, part->data, 0);
}
fz_always(ctx)
{
diff --git a/source/xps/xps-resource.c b/source/xps/xps-resource.c
index c0212e3f..139d5b5c 100644
--- a/source/xps/xps-resource.c
+++ b/source/xps/xps-resource.c
@@ -67,7 +67,7 @@ xps_parse_remote_resource_dictionary(fz_context *ctx, xps_document *doc, char *b
part = xps_read_part(ctx, doc, part_name);
fz_try(ctx)
{
- xml = fz_parse_xml(ctx, part->data, part->size, 0);
+ xml = fz_parse_xml(ctx, part->data, 0);
}
fz_always(ctx)
{
diff --git a/source/xps/xps-zip.c b/source/xps/xps-zip.c
index fe1dcce8..fe363b34 100644
--- a/source/xps/xps-zip.c
+++ b/source/xps/xps-zip.c
@@ -3,8 +3,8 @@
static void xps_init_document(fz_context *ctx, xps_document *doc);
-xps_part *
-xps_new_part(fz_context *ctx, xps_document *doc, char *name, unsigned char *data, size_t size)
+static xps_part *
+xps_new_part(fz_context *ctx, xps_document *doc, char *name, fz_buffer *data)
{
xps_part *part;
@@ -12,13 +12,11 @@ xps_new_part(fz_context *ctx, xps_document *doc, char *name, unsigned char *data
fz_try(ctx)
{
part->name = fz_strdup(ctx, name);
- part->data = data;
- part->size = size;
+ part->data = data; /* take ownership of buffer */
}
fz_catch(ctx)
{
- fz_free(ctx, part->name);
- fz_free(ctx, part->data);
+ fz_drop_buffer(ctx, data);
fz_free(ctx, part);
fz_rethrow(ctx);
}
@@ -30,7 +28,7 @@ void
xps_drop_part(fz_context *ctx, xps_document *doc, xps_part *part)
{
fz_free(ctx, part->name);
- fz_free(ctx, part->data);
+ fz_drop_buffer(ctx, part->data);
fz_free(ctx, part);
}
@@ -43,8 +41,6 @@ xps_read_part(fz_context *ctx, xps_document *doc, char *partname)
fz_archive *zip = doc->zip;
fz_buffer *buf, *tmp;
char path[2048];
- unsigned char *data;
- size_t size;
int count;
char *name;
int seen_last;
@@ -92,11 +88,7 @@ xps_read_part(fz_context *ctx, xps_document *doc, char *partname)
}
}
- fz_terminate_buffer(ctx, buf); /* zero-terminate */
- size = fz_buffer_extract(ctx, buf, &data); /* take over the data ('size' excludes the zero terminator) */
- fz_drop_buffer(ctx, buf);
-
- return xps_new_part(ctx, doc, partname, data, size);
+ return xps_new_part(ctx, doc, partname, buf);
}
int