[cairo] ask for advice about cairo's user_font

Chris Wilson chris at chris-wilson.co.uk
Fri Jul 24 23:23:01 PDT 2009


On Fri, 2009-07-24 at 20:48 -0400, James Cloos wrote:
> ► obj 3’s stream adds a new line of code after the initial ‘q’:
> 
>     0 168 980 -168 re W n
> 
> which sets the clipping path to a rectangle starting at (0, 168) and
> extending to (0+980, 168-168) aka (980, 0).  Which is redundant (in
> this single-page case) given that the /MediaBox is [ 0 0 980 168 ].
> Is the addition of that extra pdf code a consequence of bed2701e1c89?

Yes, it is a consequence of the upper layer now being more pedantic in
specifying the clip bounds of all operations. For the PS backend I was
more confident in removing that extraneous clip - all it requires is to
detect and remove the rectclip covering the page bbox.

Try:

>From ffa636d51b5bdd05fd4d566f1c5a6497fcd3a5aa Mon Sep 17 00:00:00 2001
From: Chris Wilson <chris at chris-wilson.co.uk>
Date: Sat, 25 Jul 2009 07:19:22 +0100
Subject: [PATCH] [pdf] Eliminate redundant whole-page clip.

We do not need to emit a clip if it covers the whole page.
---
 src/cairo-pdf-surface.c |   16 ++++++++++++++++
 1 files changed, 16 insertions(+), 0 deletions(-)

diff --git a/src/cairo-pdf-surface.c b/src/cairo-pdf-surface.c
index 8cd4672..63a2d9b 100644
--- a/src/cairo-pdf-surface.c
+++ b/src/cairo-pdf-surface.c
@@ -244,6 +244,19 @@ _cairo_pdf_surface_set_size_internal
(cairo_pdf_surface_t *surface,
 						  &surface->cairo_to_pdf);
 }
 
+static cairo_bool_t
+_path_covers_bbox (cairo_pdf_surface_t *surface,
+		   cairo_path_fixed_t *path)
+{
+    cairo_box_t box;
+
+    return _cairo_path_fixed_is_rectangle (path, &box) &&
+	   box.p1.x <= 0 &&
+	   box.p1.y <= 0 &&
+	   box.p2.x >= _cairo_fixed_from_double (surface->width) &&
+	   box.p2.y >= _cairo_fixed_from_double (surface->height);
+}
+
 static cairo_status_t
 _cairo_pdf_surface_clipper_intersect_clip_path (cairo_surface_clipper_t
*clipper,
 						cairo_path_fixed_t	*path,
@@ -269,6 +282,9 @@ _cairo_pdf_surface_clipper_intersect_clip_path
(cairo_surface_clipper_t *clipper
 	return CAIRO_STATUS_SUCCESS;
     }
 
+    if (_path_covers_bbox (surface, path))
+	return CAIRO_STATUS_SUCCESS;
+
     return _cairo_pdf_operators_clip (&surface->pdf_operators, path,
fill_rule);
 }
 
-- 
1.6.3.3





More information about the cairo mailing list