[cairo] [PATCH] PS/PDF improve efficiency of text output

Adrian Johnson ajohnson at redneon.com
Sun Jan 28 01:12:42 PST 2007


Carl Worth wrote:
> If we don't expect people to actually use this, how about we don't
> clutter up our advertised API with it? How about an environment
> variable such as CAIRO_DEBUG_DISABLE_COMPRESSION or so?

I like the idea of using an environment variable as the compression can
be controlled without recompiling. The attached patch implements this idea.

Environment variables could also be used to disable selected
subsetters for testing or working around buggy fonts or viewers.
eg
CAIRO_PS_DISABLE_TRUETYPE
CAIRO_PDF_DISABLE_TYPE1

-------------- next part --------------
>From 69b14c3348b315a64877edc895d1b6e6f27d7d54 Mon Sep 17 00:00:00 2001
From: Adrian Johnson <ajohnson at redneon.com>
Date: Sun, 28 Jan 2007 19:27:40 +1030
Subject: [PATCH] PDF: Add environment variable to disable compression

When the environment variable CAIRO_DEBUG_PDF_DISABLE_COMPRESSION
is define PDF compression will be disabled.
---
 src/cairo-pdf-surface.c |   11 +++++++++--
 1 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/src/cairo-pdf-surface.c b/src/cairo-pdf-surface.c
index bdfef00..cbffac7 100644
--- a/src/cairo-pdf-surface.c
+++ b/src/cairo-pdf-surface.c
@@ -46,6 +46,7 @@
 
 #include <time.h>
 #include <zlib.h>
+#include <stdlib.h>
 
 /* Issues:
  *
@@ -107,6 +108,7 @@ typedef struct _cairo_pdf_surface {
     /* Prefer the name "output" here to avoid confusion over the
      * structure within a PDF document known as a "stream". */
     cairo_output_stream_t *output;
+    cairo_bool_t compressed;
 
     double width;
     double height;
@@ -262,6 +264,11 @@ _cairo_pdf_surface_create_for_stream_int
 	return (cairo_surface_t*) &_cairo_surface_nil;
     }
 
+    if (getenv ("CAIRO_DEBUG_PDF_DISABLE_COMPRESSION") == NULL)
+        surface->compressed = TRUE;
+    else
+        surface->compressed = FALSE;
+
     _cairo_surface_init (&surface->base, &cairo_pdf_surface_backend,
 			 CAIRO_CONTENT_COLOR_ALPHA);
 
@@ -597,7 +604,7 @@ _cairo_pdf_surface_resume_content_stream
     cairo_pdf_resource_t stream;
 
     stream = _cairo_pdf_surface_open_stream (surface,
-                                             TRUE,
+                                             surface->compressed,
 					     "   /Type /XObject\r\n"
 					     "   /Subtype /Form\r\n"
 					     "   /BBox [ 0 0 %f %f ]\r\n",
@@ -614,7 +621,7 @@ _cairo_pdf_surface_start_page (void *abs
     cairo_pdf_resource_t stream;
 
     stream = _cairo_pdf_surface_open_stream (surface,
-                                             TRUE,
+                                             surface->compressed,
 					     "   /Type /XObject\r\n"
 					     "   /Subtype /Form\r\n"
 					     "   /BBox [ 0 0 %f %f ]\r\n",
-- 
1.4.3.4



More information about the cairo mailing list