[cairo] [PATCH] Add hex encode option to cairo-type1-fallback.c

Adrian Johnson ajohnson at redneon.com
Fri Sep 8 06:08:08 PDT 2006


The Type1 fallback code does not have the fix for the hex encoding
problem fixed in the Type 1 subsetting. Type 1 fonts embedded in PDF
files are required to use binary encoding instead of the hex encoding
used in PS. This patch corrects the problem in cairo-type1-fallback.c.

-------------- next part --------------
---
 src/cairo-pdf-surface.c                 |    2 +-
 src/cairo-ps-surface.c                  |    2 +-
 src/cairo-scaled-font-subsets-private.h |    5 ++++-
 src/cairo-type1-fallback.c              |   10 ++++++----
 4 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/src/cairo-pdf-surface.c b/src/cairo-pdf-surface.c
index 4ae8c6a..92befb3 100644
--- a/src/cairo-pdf-surface.c
+++ b/src/cairo-pdf-surface.c
@@ -1708,7 +1708,7 @@ _cairo_pdf_surface_emit_type1_fallback_f
 
     snprintf (name, sizeof name, "CairoFont-%d-%d",
 	      font_subset->font_id, font_subset->subset_id);
-    status = _cairo_type1_fallback_init (&subset, name, font_subset);
+    status = _cairo_type1_fallback_init (&subset, name, font_subset, FALSE);
     if (status)
 	return status;
 
diff --git a/src/cairo-ps-surface.c b/src/cairo-ps-surface.c
index 994d922..075e4c8 100644
--- a/src/cairo-ps-surface.c
+++ b/src/cairo-ps-surface.c
@@ -428,7 +428,7 @@ _cairo_ps_surface_emit_type1_font_fallba
 
     snprintf (name, sizeof name, "CairoFont-%d-%d",
 	      font_subset->font_id, font_subset->subset_id);
-    status = _cairo_type1_fallback_init (&subset, name, font_subset);
+    status = _cairo_type1_fallback_init (&subset, name, font_subset, TRUE);
     if (status)
 	return status;
 
diff --git a/src/cairo-scaled-font-subsets-private.h b/src/cairo-scaled-font-subsets-private.h
index d44ef56..12d66b8 100644
--- a/src/cairo-scaled-font-subsets-private.h
+++ b/src/cairo-scaled-font-subsets-private.h
@@ -272,6 +272,7 @@ _cairo_type1_subset_fini (cairo_type1_su
  * _cairo_type1_fallback_init:
  * @type1_subset: a #cairo_type1_subset_t to initialize
  * @font_subset: the #cairo_scaled_font_subset_t to initialize from
+ * @hex_encode: if true the encrypted portion of the font is hex encoded
  *
  * If possible (depending on the format of the underlying
  * cairo_scaled_font_t and the font backend in use) generate a type1
@@ -286,7 +287,9 @@ _cairo_type1_subset_fini (cairo_type1_su
 cairo_private cairo_status_t
 _cairo_type1_fallback_init (cairo_type1_subset_t		*type_subset,
 			  const char			*name,
-			  cairo_scaled_font_subset_t	*font_subset);
+                            cairo_scaled_font_subset_t	*font_subset,
+                          cairo_bool_t                   hex_encode);
+
 
 /**
  * _cairo_type1_fallback_fini:
diff --git a/src/cairo-type1-fallback.c b/src/cairo-type1-fallback.c
index 04337e3..31cdb16 100644
--- a/src/cairo-type1-fallback.c
+++ b/src/cairo-type1-fallback.c
@@ -65,7 +65,8 @@ typedef struct _cairo_type1_font {
 
 static cairo_status_t
 cairo_type1_font_create (cairo_scaled_font_subset_t  *scaled_font_subset,
-                         cairo_type1_font_t         **subset_return)
+                         cairo_type1_font_t         **subset_return,
+                         cairo_bool_t                 hex_encode)
 {
     cairo_type1_font_t *font;
     cairo_matrix_t font_matrix;
@@ -93,6 +94,7 @@ cairo_type1_font_create (cairo_scaled_fo
                            sizeof (int));
 
     _cairo_array_init (&font->contents, sizeof (unsigned char));
+    font->hex_encode = hex_encode;
     *subset_return = font;
     return CAIRO_STATUS_SUCCESS;
 }
@@ -493,7 +495,6 @@ cairo_type1_font_write_private_dict (cai
     cairo_output_stream_t *encrypted_output;
 
     font->eexec_key = private_dict_key;
-    font->hex_encode = TRUE;
     font->hex_column = 0;
     encrypted_output = _cairo_output_stream_create (
         cairo_type1_write_stream_encrypted,
@@ -606,14 +607,15 @@ cairo_type1_font_destroy (cairo_type1_fo
 cairo_status_t
 _cairo_type1_fallback_init (cairo_type1_subset_t	*type1_subset,
                             const char			*name,
-                            cairo_scaled_font_subset_t	*scaled_font_subset)
+                            cairo_scaled_font_subset_t	*scaled_font_subset,
+                            cairo_bool_t                 hex_encode)
 {
     cairo_type1_font_t *font;
     cairo_status_t status;
     unsigned long length;
     unsigned int i, len;
 
-    status = cairo_type1_font_create (scaled_font_subset, &font);
+    status = cairo_type1_font_create (scaled_font_subset, &font, hex_encode);
     if (status)
 	return status;
 
-- 
1.4.2



More information about the cairo mailing list