[cairo-commit] 2 commits - src/cairo-ps-surface.c src/cairo-ps-surface-private.h

Adrian Johnson ajohnson at kemper.freedesktop.org
Wed Jan 9 08:35:00 PST 2008


 src/cairo-ps-surface-private.h |    1 +
 src/cairo-ps-surface.c         |   26 +++++++++++++++++++-------
 2 files changed, 20 insertions(+), 7 deletions(-)

New commits:
commit 40142d4bf4184dcae21c85d909d33ddaa4822636
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Thu Jan 10 02:57:30 2008 +1030

    Set the PS level to to minimum required
    
    A problem with the previous commit for checking the PS level is that
    with the default PS level of 3 it prevents PS files from printing on
    Level 2 printers even if no Level 3 operators are used.
    
    As the PS header is created after the page content has been generated,
    it is easy to check the PS Level actually required and set this in the
    header and PS level check code.

diff --git a/src/cairo-ps-surface-private.h b/src/cairo-ps-surface-private.h
index d75f6c7..c42863a 100644
--- a/src/cairo-ps-surface-private.h
+++ b/src/cairo-ps-surface-private.h
@@ -78,6 +78,7 @@ typedef struct cairo_ps_surface {
     cairo_array_t *dsc_comment_target;
 
     cairo_ps_level_t ps_level;
+    cairo_ps_level_t ps_level_used;
 
     cairo_surface_t *paginated_surface;
 } cairo_ps_surface_t;
diff --git a/src/cairo-ps-surface.c b/src/cairo-ps-surface.c
index 33c0031..0bd7d6d 100644
--- a/src/cairo-ps-surface.c
+++ b/src/cairo-ps-surface.c
@@ -333,7 +333,7 @@ _cairo_ps_surface_emit_header (cairo_ps_surface_t *surface)
 
     now = time (NULL);
 
-    if (surface->ps_level == CAIRO_PS_LEVEL_2)
+    if (surface->ps_level_used == CAIRO_PS_LEVEL_2)
 	level = 2;
     else
 	level = 3;
@@ -975,6 +975,7 @@ _cairo_ps_surface_create_for_stream_internal (cairo_output_stream_t *stream,
 
     surface->eps = FALSE;
     surface->ps_level = CAIRO_PS_LEVEL_3;
+    surface->ps_level_used = CAIRO_PS_LEVEL_2;
     surface->width  = width;
     surface->height = height;
     surface->paginated_mode = CAIRO_PAGINATED_MODE_ANALYZE;
@@ -1666,10 +1667,12 @@ _cairo_ps_surface_analyze_surface_pattern_transparency (cairo_ps_surface_t
 	break;
 
     case CAIRO_IMAGE_HAS_BILEVEL_ALPHA:
-	if (surface->ps_level == CAIRO_PS_LEVEL_2)
+	if (surface->ps_level == CAIRO_PS_LEVEL_2) {
 	    status = CAIRO_INT_STATUS_FLATTEN_TRANSPARENCY;
-	else
+	} else {
+	    surface->ps_level_used = CAIRO_PS_LEVEL_3;
 	    status = CAIRO_STATUS_SUCCESS;
+	}
 	break;
 
     case CAIRO_IMAGE_HAS_ALPHA:
@@ -1732,6 +1735,7 @@ _gradient_pattern_supported (cairo_ps_surface_t    *surface,
     if (surface->ps_level == CAIRO_PS_LEVEL_2)
 	return FALSE;
 
+    surface->ps_level_used = CAIRO_PS_LEVEL_3;
     extend = cairo_pattern_get_extend (pattern);
 
     if (extend == CAIRO_EXTEND_REPEAT ||
commit 9bccc968466e6b83ceccb76680d5f54912424e8e
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Thu Jan 10 02:34:02 2008 +1030

    Add PS Level check to PS output
    
    http://bugzilla.mozilla.org/show_bug.cgi?id=406376
    
    reported problems with cairo PostScipt output printing black boxes
    instead of images. This was found to caused by printing Level 3
    PostScript to a Level 2 printer.
    
    Add some PostScript code to to the cairo PS prolog to check the
    language level of the printer. If the printer can not print the job, a
    message stating the required language level is printed and the job is
    aborted.

diff --git a/src/cairo-ps-surface.c b/src/cairo-ps-surface.c
index 0210002..33c0031 100644
--- a/src/cairo-ps-surface.c
+++ b/src/cairo-ps-surface.c
@@ -328,15 +328,15 @@ _cairo_ps_surface_emit_header (cairo_ps_surface_t *surface)
     time_t now;
     char **comments;
     int i, num_comments;
-    const char *level;
+    int level;
     const char *eps_header = "";
 
     now = time (NULL);
 
     if (surface->ps_level == CAIRO_PS_LEVEL_2)
-	level = "2";
+	level = 2;
     else
-	level = "3";
+	level = 3;
 
     if (surface->eps)
 	eps_header = " EPSF-3.0";
@@ -358,7 +358,7 @@ _cairo_ps_surface_emit_header (cairo_ps_surface_t *surface)
 
     _cairo_output_stream_printf (surface->final_stream,
 				 "%%%%DocumentData: Clean7Bit\n"
-				 "%%%%LanguageLevel: %s\n",
+				 "%%%%LanguageLevel: %d\n",
 				 level);
 
     num_comments = _cairo_array_num_elements (&surface->dsc_header_comments);
@@ -376,6 +376,14 @@ _cairo_ps_surface_emit_header (cairo_ps_surface_t *surface)
     _cairo_output_stream_printf (surface->final_stream,
 				 "%%%%BeginProlog\n");
 
+    _cairo_output_stream_printf (surface->final_stream,
+				 "/languagelevel where{pop languagelevel}{1}ifelse %d lt{/Helvetica\n"
+				 "findfont 12 scalefont setfont 50 500 moveto\n"
+				 "(This print job requires a PostScript Language Level %d printer.)show\n"
+				 "showpage quit}if\n",
+				 level,
+				 level);
+
     if (surface->eps) {
 	_cairo_output_stream_printf (surface->final_stream,
 				     "/cairo_eps_state save def\n"


More information about the cairo-commit mailing list