[gs-cvs] rev 9377 - trunk/ghostpdl/xps

tor at ghostscript.com tor at ghostscript.com
Mon Jan 19 10:04:56 PST 2009


Author: tor
Date: 2009-01-19 10:04:56 -0800 (Mon, 19 Jan 2009)
New Revision: 9377

Modified:
   trunk/ghostpdl/xps/xpsdoc.c
   trunk/ghostpdl/xps/xpsglyphs.c
   trunk/ghostpdl/xps/xpstop.c
   trunk/ghostpdl/xps/xpszip.c
Log:
Make the content type maps a compile time option (they're not necessary, and take a lot of processing time to maintain). Fix some bugs in the handling of the part hash table.

Modified: trunk/ghostpdl/xps/xpsdoc.c
===================================================================
--- trunk/ghostpdl/xps/xpsdoc.c	2009-01-19 18:03:24 UTC (rev 9376)
+++ trunk/ghostpdl/xps/xpsdoc.c	2009-01-19 18:04:56 UTC (rev 9377)
@@ -28,25 +28,106 @@
 int xps_doc_trace = 0;
 
 /*
- * Content types are stored in two separate hash tables.
+ * Content types are stored in two lookup tables.
  * One contains Override entries, which map a part name to a type.
  * The other contains Default entries, which map a file extension to a type.
  */
 
+void xps_debug_type_map(xps_context_t *ctx, char *label, xps_type_map_t *node)
+{
+    while (node)
+    {
+	dprintf3("%s name=%s type=%s\n", label, node->name, node->type);
+	node = node->next;
+    }
+}
+
+static xps_type_map_t *
+xps_new_type_map(xps_context_t *ctx, char *name, char *type)
+{
+    xps_type_map_t *node;
+
+    node = xps_alloc(ctx, sizeof(xps_type_map_t));
+    if (!node)
+       goto cleanup;
+
+    node->name = xps_strdup(ctx, name);
+    node->type = xps_strdup(ctx, type);
+    node->next = NULL;
+
+    if (!node->name)
+	goto cleanup;
+    if (!node->type)
+	goto cleanup;
+
+    return node;
+
+cleanup:
+    if (node)
+    {
+	if (node->name)
+	    xps_free(ctx, node->name);
+	if (node->type)
+	    xps_free(ctx, node->type);
+	xps_free(ctx, node);
+    }
+    return NULL;
+}
+
+void
+xps_free_type_map(xps_context_t *ctx, xps_type_map_t *node)
+{
+    xps_type_map_t *next;
+    while (node)
+    {
+	next = node->next;
+	xps_free(ctx, node->name);
+	xps_free(ctx, node->type);
+	xps_free(ctx, node);
+	node = next;
+    }
+}
+
+static char *
+xps_lookup_type_map(xps_type_map_t *node, char *name)
+{
+    while (node)
+    {
+	if (strcmp(node->name, name) == 0)
+	    return node->type;
+	node = node->next;
+    }
+    return NULL;
+}
+
 static void
 xps_add_override(xps_context_t *ctx, char *part_name, char *content_type)
 {
-    if (ctx->overrides == NULL)
-	ctx->overrides = xps_hash_new(ctx);
-    xps_hash_insert(ctx, ctx->overrides, part_name, content_type);
+    xps_type_map_t *node;
+    if (!xps_lookup_type_map(ctx->overrides, part_name))
+    {
+	node = xps_new_type_map(ctx, part_name, content_type);
+	if (node)
+	{
+	    node->next = ctx->overrides;
+	    ctx->overrides = node;
+	}
+    }
 }
 
 static void
 xps_add_default(xps_context_t *ctx, char *extension, char *content_type)
 {
-    if (ctx->defaults == NULL)
-	ctx->defaults = xps_hash_new(ctx);
-    xps_hash_insert(ctx, ctx->defaults, extension, content_type);
+    xps_type_map_t *node;
+    if (!xps_lookup_type_map(ctx->defaults, extension))
+    {
+	node = xps_new_type_map(ctx, extension, content_type);
+	if (node)
+	{
+	    node->next = ctx->defaults;
+	    ctx->defaults = node;
+	}
+    }
 }
 
 char *
@@ -55,7 +136,7 @@
     char *extension;
     char *type;
 
-    type = xps_hash_lookup(ctx->overrides, partname);
+    type = xps_lookup_type_map(ctx->overrides, partname);
     if (type)
     {
 	return type;
@@ -65,7 +146,7 @@
     if (extension)
 	extension ++;
 
-    type = xps_hash_lookup(ctx->defaults, extension);
+    type = xps_lookup_type_map(ctx->defaults, extension);
     if (type)
     {
 	return type;
@@ -81,7 +162,6 @@
 
 void xps_debug_parts(xps_context_t *ctx)
 {
-#if 0
     xps_part_t *part = ctx->first_part;
     xps_relation_t *rel;
     while (part)
@@ -91,7 +171,6 @@
 	    dprintf2("     target=%s type=%s\n", rel->target, rel->type);
 	part = part->next;
     }
-#endif
 }
 
 int
@@ -308,7 +387,6 @@
 xps_free_used_parts(xps_context_t *ctx)
 {
     /* TODO: actually do what we should. for now we just free cached resources. */
-#if 0
     xps_part_t *part = ctx->first_part;
     while (part)
     {
@@ -316,7 +394,6 @@
 	xps_free_part_caches(ctx, part);
 	part = next;
     }
-#endif
 }
 
 /*
@@ -357,6 +434,8 @@
     xps_context_t *ctx = zp;
     int i;
 
+#ifdef XPS_LOAD_TYPE_MAPS
+
     if (!strcmp(name, "Default"))
     {
 	char *extension = NULL;
@@ -371,7 +450,7 @@
 	}
 
 	if (extension && type)
-	    xps_add_default(ctx, extension, xps_strdup(ctx, type));
+	    xps_add_default(ctx, extension, type);
     }
 
     if (!strcmp(name, "Override"))
@@ -388,9 +467,11 @@
 	}
 
 	if (partname && type)
-	    xps_add_override(ctx, partname, xps_strdup(ctx, type));
+	    xps_add_override(ctx, partname, type);
     }
 
+#endif
+
     if (!strcmp(name, "Relationship"))
     {
 	char srcbuf[1024];
@@ -715,7 +796,7 @@
     if (getenv("XPS_DOC_TRACE"))
 	xps_doc_trace = 1;
 
-    if (xps_doc_trace)
+    if (xps_doc_trace && part->complete)
 	dprintf2("doc: found part %s %s\n", part->name, part->complete ? "" : "(piece)");
 
     /*

Modified: trunk/ghostpdl/xps/xpsglyphs.c
===================================================================
--- trunk/ghostpdl/xps/xpsglyphs.c	2009-01-19 18:03:24 UTC (rev 9376)
+++ trunk/ghostpdl/xps/xpsglyphs.c	2009-01-19 18:04:56 UTC (rev 9377)
@@ -575,12 +575,14 @@
     if (!part)
 	return gs_throw1(-1, "cannot find font resource part '%s'", partname);
 
+    /* deobfuscate if necessary */
     if (!part->deobfuscated)
     {
-	/* deobfuscate if necessary */
+#ifdef  XPS_LOAD_TYPE_MAPS
 	parttype = xps_get_content_type(ctx, part->name);
 	if (parttype && !strcmp(parttype, "application/vnd.ms-package.obfuscated-opentype"))
 	    xps_deobfuscate_font_resource(ctx, part);
+#endif
 
 	/* stupid XPS files with content-types after the parts */
 	if (!parttype && strstr(part->name, ".odttf"))

Modified: trunk/ghostpdl/xps/xpstop.c
===================================================================
--- trunk/ghostpdl/xps/xpstop.c	2009-01-19 18:03:24 UTC (rev 9376)
+++ trunk/ghostpdl/xps/xpstop.c	2009-01-19 18:04:56 UTC (rev 9377)
@@ -25,11 +25,6 @@
 
 static int xps_install_halftone(xps_context_t *ctx, gx_device *pdevice);
 
-static inline void xps_free_imp(xps_context_t *ctx, void *ptr)
-{
-    xps_free(ctx, ptr);
-}
-
 #define XPS_PARSER_MIN_INPUT_SIZE 8192
 
 /*
@@ -122,7 +117,7 @@
     ctx->srgb = gs_cspace_new_DeviceRGB(ctx->memory);
     ctx->scrgb = gs_cspace_new_DeviceRGB(ctx->memory);
 
-    ctx->parts = xps_hash_new(ctx);
+    ctx->part_table = xps_hash_new(ctx);
 
     instance->pre_page_action = 0;
     instance->pre_page_closure = 0;
@@ -318,25 +313,30 @@
         xps_debug_parts(ctx);
     if (getenv("XPS_DEBUG_TYPES"))
     {
-	dputs("Defaults\n");
-        xps_hash_debug(ctx->defaults);
-	dputs("Overrides\n");
-        xps_hash_debug(ctx->overrides);
+        xps_debug_type_map(ctx, "Default", ctx->defaults);
+        xps_debug_type_map(ctx, "Override", ctx->overrides);
     }
     if (getenv("XPS_DEBUG_PAGES"))
         xps_debug_fixdocseq(ctx);
 
     /* Free XPS parsing stuff */
     {
-	xps_hash_free(ctx, ctx->parts, xps_free_part);
-	ctx->parts = NULL;
+	xps_part_t *part = ctx->first_part;
+	while (part)
+	{
+	    xps_part_t *next = part->next;
+	    xps_free_part(ctx, part);
+	    part = next;
+	}
 
-        xps_free_fixed_pages(ctx);
-        xps_free_fixed_documents(ctx);
+	xps_free_fixed_pages(ctx);
+	xps_free_fixed_documents(ctx);
 
-        xps_hash_free(ctx, ctx->overrides, xps_free_imp);
+        if (ctx->overrides)
+	    xps_free_type_map(ctx, ctx->overrides);
 	ctx->overrides = NULL;
-        xps_hash_free(ctx, ctx->defaults, xps_free_imp);
+        if (ctx->defaults)
+	    xps_free_type_map(ctx, ctx->defaults);
 	ctx->defaults = NULL;
     }
 

Modified: trunk/ghostpdl/xps/xpszip.c
===================================================================
--- trunk/ghostpdl/xps/xpszip.c	2009-01-19 18:03:24 UTC (rev 9376)
+++ trunk/ghostpdl/xps/xpszip.c	2009-01-19 18:04:56 UTC (rev 9377)
@@ -135,9 +135,15 @@
 	return NULL;
     }
 
+    part->next = NULL;
+
     /* add it to the list of parts */
-    xps_hash_insert(ctx, ctx->parts, name, part);
+    part->next = ctx->first_part;
+    ctx->first_part = part;
 
+    /* add it to the hash table of parts */
+    xps_hash_insert(ctx, ctx->part_table, part->name, part);
+
     return part;
 }
 
@@ -171,7 +177,7 @@
 xps_part_t *
 xps_find_part(xps_context_t *ctx, char *name)
 {
-    return xps_hash_lookup(ctx->parts, name);
+    return xps_hash_lookup(ctx->part_table, name);
 }
 
 static int
@@ -209,6 +215,7 @@
 	part = xps_new_part(ctx, ctx->zip_file_name, ctx->zip_uncompressed_size);
 	if (!part)
 	    return gs_rethrow(-1, "cannot create part buffer");
+
 	ctx->last_part = part; /* make it the current part */
     }
     else



More information about the gs-cvs mailing list