diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2010-04-27 16:43:52 +0000 |
---|---|---|
committer | Tor Andersson <tor.andersson@artifex.com> | 2010-04-27 16:43:52 +0000 |
commit | c7797fd480e6f519f3a7f661bdba2928dd74ea51 (patch) | |
tree | 2af6caefe0edb37dadc5544b4f10acd9f8b23040 /xps | |
parent | 7c2a8a556fd2b3b0144c382fd8c66ecbb3bcb9dd (diff) |
Continuation of r11139 -- update to the latest working version of xpsdoc.c.
git-svn-id: http://svn.ghostscript.com/ghostscript/trunk@11140 a1074d23-0009-0410-80fe-cf8c14f379e6
Diffstat (limited to 'xps')
-rw-r--r-- | xps/xpsdoc.c | 422 |
1 files changed, 210 insertions, 212 deletions
diff --git a/xps/xpsdoc.c b/xps/xpsdoc.c index ed1d0d3a6..47a62a567 100644 --- a/xps/xpsdoc.c +++ b/xps/xpsdoc.c @@ -20,22 +20,22 @@ xps_part_t * xps_new_part(xps_context_t *ctx, char *name, int size) { - xps_part_t *part; + xps_part_t *part; - part = xps_alloc(ctx, sizeof(xps_part_t)); - part->name = xps_strdup(ctx, name); - part->size = size; - part->data = xps_alloc(ctx, size); + part = xps_alloc(ctx, sizeof(xps_part_t)); + part->name = xps_strdup(ctx, name); + part->size = size; + part->data = xps_alloc(ctx, size); - return part; + return part; } void xps_free_part(xps_context_t *ctx, xps_part_t *part) { - xps_free(ctx, part->name); - xps_free(ctx, part->data); - xps_free(ctx, part); + xps_free(ctx, part->name); + xps_free(ctx, part->data); + xps_free(ctx, part); } /* @@ -46,135 +46,133 @@ xps_free_part(xps_context_t *ctx, xps_part_t *part) void xps_debug_fixdocseq(xps_context_t *ctx) { - xps_document_t *fixdoc = ctx->first_fixdoc; - xps_page_t *page = ctx->first_page; - - if (ctx->start_part) - dprintf1("start part %s\n", ctx->start_part); - - while (fixdoc) - { - dprintf1("fixdoc %s\n", fixdoc->name); - fixdoc = fixdoc->next; - } - - while (page) - { - dprintf3("page %s w=%d h=%d\n", page->name, page->width, page->height); - page = page->next; - } + xps_document_t *fixdoc = ctx->first_fixdoc; + xps_page_t *page = ctx->first_page; + + if (ctx->start_part) + dprintf1("start part %s\n", ctx->start_part); + + while (fixdoc) + { + dprintf1("fixdoc %s\n", fixdoc->name); + fixdoc = fixdoc->next; + } + + while (page) + { + dprintf3("page %s w=%d h=%d\n", page->name, page->width, page->height); + page = page->next; + } } static int xps_add_fixed_document(xps_context_t *ctx, char *name) { - xps_document_t *fixdoc; - - /* Check for duplicates first */ - for (fixdoc = ctx->first_fixdoc; fixdoc; fixdoc = fixdoc->next) - if (!strcmp(fixdoc->name, name)) - return 0; - - if (xps_doc_trace) - dprintf1("doc: adding fixdoc %s\n", name); - - fixdoc = xps_alloc(ctx, sizeof(xps_document_t)); - if (!fixdoc) - return -1; - - fixdoc->name = xps_strdup(ctx, name); - if (!fixdoc->name) - { - xps_free(ctx, fixdoc); - return -1; - } - - fixdoc->next = NULL; - - if (!ctx->first_fixdoc) - { - ctx->first_fixdoc = fixdoc; - ctx->last_fixdoc = fixdoc; - } - else - { - ctx->last_fixdoc->next = fixdoc; - ctx->last_fixdoc = fixdoc; - } - - return 0; + xps_document_t *fixdoc; + + /* Check for duplicates first */ + for (fixdoc = ctx->first_fixdoc; fixdoc; fixdoc = fixdoc->next) + if (!strcmp(fixdoc->name, name)) + return 0; + + if_debug1('|', "doc: adding fixdoc %s\n", name); + + fixdoc = xps_alloc(ctx, sizeof(xps_document_t)); + if (!fixdoc) + return -1; + + fixdoc->name = xps_strdup(ctx, name); + if (!fixdoc->name) + { + xps_free(ctx, fixdoc); + return -1; + } + + fixdoc->next = NULL; + + if (!ctx->first_fixdoc) + { + ctx->first_fixdoc = fixdoc; + ctx->last_fixdoc = fixdoc; + } + else + { + ctx->last_fixdoc->next = fixdoc; + ctx->last_fixdoc = fixdoc; + } + + return 0; } void xps_free_fixed_documents(xps_context_t *ctx) { - xps_document_t *node = ctx->first_fixdoc; - while (node) - { - xps_document_t *next = node->next; - xps_free(ctx, node->name); - xps_free(ctx, node); - node = next; - } - ctx->first_fixdoc = NULL; - ctx->last_fixdoc = NULL; + xps_document_t *node = ctx->first_fixdoc; + while (node) + { + xps_document_t *next = node->next; + xps_free(ctx, node->name); + xps_free(ctx, node); + node = next; + } + ctx->first_fixdoc = NULL; + ctx->last_fixdoc = NULL; } static int xps_add_fixed_page(xps_context_t *ctx, char *name, int width, int height) { - xps_page_t *page; - - /* Check for duplicates first */ - for (page = ctx->first_page; page; page = page->next) - if (!strcmp(page->name, name)) - return 0; - - if (xps_doc_trace) - dprintf1("doc: adding page %s\n", name); - - page = xps_alloc(ctx, sizeof(xps_page_t)); - if (!page) - return -1; - - page->name = xps_strdup(ctx, name); - if (!page->name) - { - xps_free(ctx, page); - return -1; - } - - page->width = width; - page->height = height; - page->next = NULL; - - if (!ctx->first_page) - { - ctx->first_page = page; - ctx->last_page = page; - } - else - { - ctx->last_page->next = page; - ctx->last_page = page; - } - - return 0; + xps_page_t *page; + + /* Check for duplicates first */ + for (page = ctx->first_page; page; page = page->next) + if (!strcmp(page->name, name)) + return 0; + + if_debug1('|', "doc: adding page %s\n", name); + + page = xps_alloc(ctx, sizeof(xps_page_t)); + if (!page) + return -1; + + page->name = xps_strdup(ctx, name); + if (!page->name) + { + xps_free(ctx, page); + return -1; + } + + page->width = width; + page->height = height; + page->next = NULL; + + if (!ctx->first_page) + { + ctx->first_page = page; + ctx->last_page = page; + } + else + { + ctx->last_page->next = page; + ctx->last_page = page; + } + + return 0; } void xps_free_fixed_pages(xps_context_t *ctx) { - xps_page_t *node = ctx->first_page; - while (node) - { - xps_page_t *next = node->next; - xps_free(ctx, node->name); - xps_free(ctx, node); - node = next; - } - ctx->first_page = NULL; - ctx->last_page = NULL; + xps_page_t *node = ctx->first_page; + while (node) + { + xps_page_t *next = node->next; + xps_free(ctx, node->name); + xps_free(ctx, node); + node = next; + } + ctx->first_page = NULL; + ctx->last_page = NULL; } /* @@ -186,112 +184,112 @@ xps_free_fixed_pages(xps_context_t *ctx) static void xps_parse_metadata_imp(void *zp, char *name, char **atts) { - xps_context_t *ctx = zp; - int i; - - if (!strcmp(name, "Relationship")) - { - char tgtbuf[1024]; - char *target = NULL; - char *type = NULL; - - for (i = 0; atts[i]; i += 2) - { - if (!strcmp(atts[i], "Target")) - target = atts[i + 1]; - if (!strcmp(atts[i], "Type")) - type = atts[i + 1]; - } - - if (target && type) - { - xps_absolute_path(tgtbuf, ctx->base_uri, target, sizeof tgtbuf); - if (!strcmp(type, REL_START_PART)) - ctx->start_part = xps_strdup(ctx, tgtbuf); - } - } - - if (!strcmp(name, "DocumentReference")) - { - char *source = NULL; - char srcbuf[1024]; - - for (i = 0; atts[i]; i += 2) - { - if (!strcmp(atts[i], "Source")) - source = atts[i + 1]; - } - - if (source) - { - xps_absolute_path(srcbuf, ctx->base_uri, source, sizeof srcbuf); - xps_add_fixed_document(ctx, srcbuf); - } - } - - if (!strcmp(name, "PageContent")) - { - char *source = NULL; - char srcbuf[1024]; - int width = 0; - int height = 0; - - for (i = 0; atts[i]; i += 2) - { - if (!strcmp(atts[i], "Source")) - source = atts[i + 1]; - if (!strcmp(atts[i], "Width")) - width = atoi(atts[i + 1]); - if (!strcmp(atts[i], "Height")) - height = atoi(atts[i + 1]); - } - - if (source) - { - xps_absolute_path(srcbuf, ctx->base_uri, source, sizeof srcbuf); - xps_add_fixed_page(ctx, srcbuf, width, height); - } - } + xps_context_t *ctx = zp; + int i; + + if (!strcmp(name, "Relationship")) + { + char tgtbuf[1024]; + char *target = NULL; + char *type = NULL; + + for (i = 0; atts[i]; i += 2) + { + if (!strcmp(atts[i], "Target")) + target = atts[i + 1]; + if (!strcmp(atts[i], "Type")) + type = atts[i + 1]; + } + + if (target && type) + { + xps_absolute_path(tgtbuf, ctx->base_uri, target, sizeof tgtbuf); + if (!strcmp(type, REL_START_PART)) + ctx->start_part = xps_strdup(ctx, tgtbuf); + } + } + + if (!strcmp(name, "DocumentReference")) + { + char *source = NULL; + char srcbuf[1024]; + + for (i = 0; atts[i]; i += 2) + { + if (!strcmp(atts[i], "Source")) + source = atts[i + 1]; + } + + if (source) + { + xps_absolute_path(srcbuf, ctx->base_uri, source, sizeof srcbuf); + xps_add_fixed_document(ctx, srcbuf); + } + } + + if (!strcmp(name, "PageContent")) + { + char *source = NULL; + char srcbuf[1024]; + int width = 0; + int height = 0; + + for (i = 0; atts[i]; i += 2) + { + if (!strcmp(atts[i], "Source")) + source = atts[i + 1]; + if (!strcmp(atts[i], "Width")) + width = atoi(atts[i + 1]); + if (!strcmp(atts[i], "Height")) + height = atoi(atts[i + 1]); + } + + if (source) + { + xps_absolute_path(srcbuf, ctx->base_uri, source, sizeof srcbuf); + xps_add_fixed_page(ctx, srcbuf, width, height); + } + } } int xps_parse_metadata(xps_context_t *ctx, xps_part_t *part) { - XML_Parser xp; - char buf[1024]; - char *s; + XML_Parser xp; + char buf[1024]; + char *s; - /* Save directory name part */ - xps_strlcpy(buf, part->name, sizeof buf); - s = strrchr(buf, '/'); - if (s) - s[0] = 0; + /* Save directory name part */ + xps_strlcpy(buf, part->name, sizeof buf); + s = strrchr(buf, '/'); + if (s) + s[0] = 0; - /* _rels parts are voodoo: their URI references are from - * the part they are associated with, not the actual _rels - * part being parsed. - */ - s = strstr(buf, "/_rels"); - if (s) - *s = 0; + /* _rels parts are voodoo: their URI references are from + * the part they are associated with, not the actual _rels + * part being parsed. + */ + s = strstr(buf, "/_rels"); + if (s) + *s = 0; - ctx->base_uri = buf; - ctx->part_uri = part->name; + ctx->base_uri = buf; + ctx->part_uri = part->name; - xp = XML_ParserCreate(NULL); - if (!xp) - return -1; + xp = XML_ParserCreate(NULL); + if (!xp) + return -1; - XML_SetUserData(xp, ctx); - XML_SetParamEntityParsing(xp, XML_PARAM_ENTITY_PARSING_NEVER); - XML_SetStartElementHandler(xp, (XML_StartElementHandler)xps_parse_metadata_imp); + XML_SetUserData(xp, ctx); + XML_SetParamEntityParsing(xp, XML_PARAM_ENTITY_PARSING_NEVER); + XML_SetStartElementHandler(xp, (XML_StartElementHandler)xps_parse_metadata_imp); - (void) XML_Parse(xp, (char*)part->data, part->size, 1); + (void) XML_Parse(xp, (char*)part->data, part->size, 1); - XML_ParserFree(xp); + XML_ParserFree(xp); - ctx->base_uri = NULL; - ctx->part_uri = NULL; + ctx->base_uri = NULL; + ctx->part_uri = NULL; - return 0; + return 0; } |