summaryrefslogtreecommitdiff
path: root/xps
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2012-01-06 15:03:53 +0000
committerRobin Watts <robin.watts@artifex.com>2012-01-06 15:07:05 +0000
commitd6fab6582c26c133589c83134e76e7a29ff57962 (patch)
tree8400088a29440ae22254f845adc162c9bf012703 /xps
parent95f29c10759bc42e940869f1a0d2f82db16f8709 (diff)
downloadmupdf-d6fab6582c26c133589c83134e76e7a29ff57962.tar.xz
XPS tweaks/fixes.
xps_parse_resource_dictionary can now warn and return NULL when reading an empty dictionary, rather than throwing an error. Various bits of code are therefore updated to check for a NULL return value. We should cope better with multiple Resource dictionaries. Tweak to the zip file handling when looking for parts. Again, all from (or inspired by) Zenikos patch.
Diffstat (limited to 'xps')
-rw-r--r--xps/xps_resource.c5
-rw-r--r--xps/xps_tile.c11
-rw-r--r--xps/xps_zip.c6
3 files changed, 17 insertions, 5 deletions
diff --git a/xps/xps_resource.c b/xps/xps_resource.c
index fad60488..cfac562d 100644
--- a/xps/xps_resource.c
+++ b/xps/xps_resource.c
@@ -80,7 +80,8 @@ xps_parse_remote_resource_dictionary(xps_document *doc, char *base_uri, char *so
s[1] = 0;
dict = xps_parse_resource_dictionary(doc, part_uri, xml);
- dict->base_xml = xml; /* pass on ownership */
+ if (dict)
+ dict->base_xml = xml; /* pass on ownership */
return dict;
}
@@ -119,7 +120,7 @@ xps_parse_resource_dictionary(xps_document *doc, char *base_uri, xml_element *ro
if (head)
head->base_uri = fz_strdup(doc->ctx, base_uri);
else
- fz_throw(doc->ctx, "empty resource dictionary");
+ fz_warn(doc->ctx, "empty resource dictionary");
return head;
}
diff --git a/xps/xps_tile.c b/xps/xps_tile.c
index 04c613a4..1acdd369 100644
--- a/xps/xps_tile.c
+++ b/xps/xps_tile.c
@@ -269,11 +269,16 @@ xps_parse_canvas(xps_document *doc, fz_matrix ctm, fz_rect area, char *base_uri,
for (node = xml_down(root); node; node = xml_next(node))
{
+ /* FIXME: Sumatra warns of memory leak here where we have multiple
+ * Canvas.Resources. */
if (!strcmp(xml_tag(node), "Canvas.Resources") && xml_down(node))
{
new_dict = xps_parse_resource_dictionary(doc, base_uri, xml_down(node));
- new_dict->parent = dict;
- dict = new_dict;
+ if (new_dict)
+ {
+ new_dict->parent = dict;
+ dict = new_dict;
+ }
}
if (!strcmp(xml_tag(node), "Canvas.RenderTransform"))
@@ -341,6 +346,8 @@ xps_parse_fixed_page(xps_document *doc, fz_matrix ctm, xps_page *page)
for (node = xml_down(page->root); node; node = xml_next(node))
{
+ /* FIXME: Sumatra warns of memory leak here where we have multiple
+ * FixedPage.Resources. */
if (!strcmp(xml_tag(node), "FixedPage.Resources") && xml_down(node))
dict = xps_parse_resource_dictionary(doc, base_uri, xml_down(node));
xps_parse_element(doc, ctm, area, base_uri, dict, node);
diff --git a/xps/xps_zip.c b/xps/xps_zip.c
index 7bc90319..04e37f4f 100644
--- a/xps/xps_zip.c
+++ b/xps/xps_zip.c
@@ -256,6 +256,7 @@ xps_read_zip_part(xps_document *doc, char *partname)
xps_part *part;
int count, size, offset, i;
char *name;
+ int seen_last = 0;
name = partname;
if (name[0] == '/')
@@ -273,7 +274,7 @@ xps_read_zip_part(xps_document *doc, char *partname)
/* Count the number of pieces and their total size */
count = 0;
size = 0;
- while (1)
+ while (!seen_last)
{
sprintf(buf, "%s/[%d].piece", name, count);
ent = xps_find_zip_entry(doc, buf);
@@ -281,12 +282,15 @@ xps_read_zip_part(xps_document *doc, char *partname)
{
sprintf(buf, "%s/[%d].last.piece", name, count);
ent = xps_find_zip_entry(doc, buf);
+ seen_last = (ent != NULL);
}
if (!ent)
break;
count ++;
size += ent->usize;
}
+ if (!seen_last)
+ fz_throw(doc->ctx, "cannot find all pieces for part '%s'", partname);
/* Inflate the pieces */
if (count)