[cairo-commit] 3 commits - src/cairo-ps-surface.c src/cairo-type1-subset.c

Adrian Johnson ajohnson at kemper.freedesktop.org
Sat Jan 11 02:38:35 PST 2014


 src/cairo-ps-surface.c   |  102 ++++++++++++++++++++++++++++-------------------
 src/cairo-type1-subset.c |    3 +
 2 files changed, 64 insertions(+), 41 deletions(-)

New commits:
commit b56b971141bf22ee3452b7f6f5e2dfd373b99e13
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Sat Jan 11 20:49:05 2014 +1030

    type1: strip space from end of font name

diff --git a/src/cairo-type1-subset.c b/src/cairo-type1-subset.c
index 3b2cc0a..47d85b2 100644
--- a/src/cairo-type1-subset.c
+++ b/src/cairo-type1-subset.c
@@ -420,6 +420,9 @@ cairo_type1_font_subset_get_fontname (cairo_type1_font_subset_t *font)
     if (end == NULL)
 	return CAIRO_INT_STATUS_UNSUPPORTED;
 
+    while (end > start && _cairo_isspace(end[-1]))
+	end--;
+
     s = malloc (end - start + 1);
     if (unlikely (s == NULL))
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
commit ee0e2b9272f6f21092fde7bee9b9237e682d4147
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Sat Jan 11 20:57:44 2014 +1030

    ps: add font DSC comments

diff --git a/src/cairo-ps-surface.c b/src/cairo-ps-surface.c
index f66c195..706e305 100644
--- a/src/cairo-ps-surface.c
+++ b/src/cairo-ps-surface.c
@@ -374,12 +374,11 @@ _cairo_ps_surface_emit_header (cairo_ps_surface_t *surface)
 
     _cairo_output_stream_printf (surface->final_stream,
 				 "%%%%EndProlog\n");
+    _cairo_output_stream_printf (surface->final_stream,
+				 "%%%%BeginSetup\n");
 
     num_comments = _cairo_array_num_elements (&surface->dsc_setup_comments);
     if (num_comments) {
-	_cairo_output_stream_printf (surface->final_stream,
-				     "%%%%BeginSetup\n");
-
 	comments = _cairo_array_index (&surface->dsc_setup_comments, 0);
 	for (i = 0; i < num_comments; i++) {
 	    _cairo_output_stream_printf (surface->final_stream,
@@ -387,9 +386,6 @@ _cairo_ps_surface_emit_header (cairo_ps_surface_t *surface)
 	    free (comments[i]);
 	    comments[i] = NULL;
 	}
-
-	_cairo_output_stream_printf (surface->final_stream,
-				     "%%%%EndSetup\n");
     }
 }
 
@@ -417,8 +413,13 @@ _cairo_ps_surface_emit_type1_font_subset (cairo_ps_surface_t		*surface,
 				 "%% _cairo_ps_surface_emit_type1_font_subset\n");
 #endif
 
+    _cairo_output_stream_printf (surface->final_stream,
+				 "%%%%BeginResource: font %s\n",
+				 subset.base_font);
     length = subset.header_length + subset.data_length + subset.trailer_length;
     _cairo_output_stream_write (surface->final_stream, subset.data, length);
+    _cairo_output_stream_printf (surface->final_stream,
+				 "%%%%EndResource\n");
 
     _cairo_type1_subset_fini (&subset);
 
@@ -441,15 +442,18 @@ _cairo_ps_surface_emit_type1_font_fallback (cairo_ps_surface_t		*surface,
     if (unlikely (status))
 	return status;
 
-    /* FIXME: Figure out document structure convention for fonts */
-
 #if DEBUG_PS
     _cairo_output_stream_printf (surface->final_stream,
 				 "%% _cairo_ps_surface_emit_type1_font_fallback\n");
 #endif
 
+    _cairo_output_stream_printf (surface->final_stream,
+				 "%%%%BeginResource: font %s\n",
+				 subset.base_font);
     length = subset.header_length + subset.data_length + subset.trailer_length;
     _cairo_output_stream_write (surface->final_stream, subset.data, length);
+    _cairo_output_stream_printf (surface->final_stream,
+				 "%%%%EndResource\n");
 
     _cairo_type1_fallback_fini (&subset);
 
@@ -478,6 +482,9 @@ _cairo_ps_surface_emit_truetype_font_subset (cairo_ps_surface_t		*surface,
 #endif
 
     _cairo_output_stream_printf (surface->final_stream,
+				 "%%%%BeginResource: font %s\n",
+				 subset.ps_name);
+    _cairo_output_stream_printf (surface->final_stream,
 				 "11 dict begin\n"
 				 "/FontType 42 def\n"
 				 "/FontName /%s def\n"
@@ -559,9 +566,11 @@ _cairo_ps_surface_emit_truetype_font_subset (cairo_ps_surface_t		*surface,
 				 "/f-%d-%d currentdict end definefont pop\n",
 				 font_subset->font_id,
 				 font_subset->subset_id);
-
+    _cairo_output_stream_printf (surface->final_stream,
+				 "%%%%EndResource\n");
     _cairo_truetype_subset_fini (&subset);
 
+
     return CAIRO_STATUS_SUCCESS;
 }
 
@@ -656,6 +665,8 @@ _cairo_ps_surface_emit_type3_font_subset (cairo_ps_surface_t		*surface,
 #endif
 
     _cairo_output_stream_printf (surface->final_stream,
+				 "%%%%BeginResource: font\n");
+    _cairo_output_stream_printf (surface->final_stream,
 				 "8 dict begin\n"
 				 "/FontType 3 def\n"
 				 "/FontMatrix [1 0 0 1 0 0] def\n"
@@ -735,6 +746,8 @@ _cairo_ps_surface_emit_type3_font_subset (cairo_ps_surface_t		*surface,
 				 - _cairo_fixed_to_double (font_bbox.p1.y),
 				 font_subset->font_id,
 				 font_subset->subset_id);
+    _cairo_output_stream_printf (surface->final_stream,
+				 "%%%%EndResource\n");
 
     return CAIRO_STATUS_SUCCESS;
 }
@@ -1598,6 +1611,9 @@ _cairo_ps_surface_finish (void *abstract_surface)
     if (unlikely (status))
 	goto CLEANUP;
 
+    _cairo_output_stream_printf (surface->final_stream,
+				 "%%%%EndSetup\n");
+
     status = _cairo_ps_surface_emit_body (surface);
     if (unlikely (status))
 	goto CLEANUP;
commit 2d3ee70ed37ed2120d5c5f75277172620e32084c
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Sat Jan 11 19:09:55 2014 +1030

    ps: cairo_set_page_size does not need to be in eps output

diff --git a/src/cairo-ps-surface.c b/src/cairo-ps-surface.c
index 5dd33fa..f66c195 100644
--- a/src/cairo-ps-surface.c
+++ b/src/cairo-ps-surface.c
@@ -335,38 +335,42 @@ _cairo_ps_surface_emit_header (cairo_ps_surface_t *surface)
 				 "      cairo_store_point /cairo_font where { pop cairo_selectfont } if } bind def\n"
 				 "/g { setgray } bind def\n"
 				 "/rg { setrgbcolor } bind def\n"
-				 "/d1 { setcachedevice } bind def\n"
-				 "/cairo_set_page_size {\n"
-				 "  %% Change paper size, but only if different from previous paper size otherwise\n"
-				 "  %% duplex fails. PLRM specifies a tolerance of 5 pts when matching paper size\n"
-				 "  %% so we use the same when checking if the size changes.\n"
-				 "  /setpagedevice where {\n"
-				 "    pop currentpagedevice\n"
-				 "    /PageSize known {\n"
-				 "      2 copy\n"
-				 "      currentpagedevice /PageSize get aload pop\n"
-				 "      exch 4 1 roll\n"
-				 "      sub abs 5 gt\n"
-				 "      3 1 roll\n"
-				 "      sub abs 5 gt\n"
-				 "      or\n"
-				 "    } {\n"
-				 "      true\n"
-				 "    } ifelse\n"
-				 "    {\n"
-				 "      2 array astore\n"
-				 "      2 dict begin\n"
-				 "        /PageSize exch def\n"
-				 "        /ImagingBBox null def\n"
-				 "      currentdict end\n"
-				 "      setpagedevice\n"
-				 "    } {\n"
-				 "      pop pop\n"
-				 "    } ifelse\n"
-				 "  } {\n"
-				 "    pop\n"
-				 "  } ifelse\n"
-				 "} def\n");
+				 "/d1 { setcachedevice } bind def\n");
+
+    if (!surface->eps) {
+	_cairo_output_stream_printf (surface->final_stream,
+				     "/cairo_set_page_size {\n"
+				     "  %% Change paper size, but only if different from previous paper size otherwise\n"
+				     "  %% duplex fails. PLRM specifies a tolerance of 5 pts when matching paper size\n"
+				     "  %% so we use the same when checking if the size changes.\n"
+				     "  /setpagedevice where {\n"
+				     "    pop currentpagedevice\n"
+				     "    /PageSize known {\n"
+				     "      2 copy\n"
+				     "      currentpagedevice /PageSize get aload pop\n"
+				     "      exch 4 1 roll\n"
+				     "      sub abs 5 gt\n"
+				     "      3 1 roll\n"
+				     "      sub abs 5 gt\n"
+				     "      or\n"
+				     "    } {\n"
+				     "      true\n"
+				     "    } ifelse\n"
+				     "    {\n"
+				     "      2 array astore\n"
+				     "      2 dict begin\n"
+				     "        /PageSize exch def\n"
+				     "        /ImagingBBox null def\n"
+				     "      currentdict end\n"
+				     "      setpagedevice\n"
+				     "    } {\n"
+				     "      pop pop\n"
+				     "    } ifelse\n"
+				     "  } {\n"
+				     "    pop\n"
+				     "  } ifelse\n"
+				     "} def\n");
+    }
 
     _cairo_output_stream_printf (surface->final_stream,
 				 "%%%%EndProlog\n");


More information about the cairo-commit mailing list