From 7d72c13c305aa175bddf8827e3cc9007ba927b51 Mon Sep 17 00:00:00 2001
From: Han-Wen Nienhuys <hanwen@xs4all.nl>
Date: Fri, 26 Jan 2007 16:45:32 +0100
Subject: [PATCH] eps inclusion: clip correctly, and strip binary data before
 examining.

---
 scm/stencil.scm | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/scm/stencil.scm b/scm/stencil.scm
index b2d425e6ea..320b54ee73 100644
--- a/scm/stencil.scm
+++ b/scm/stencil.scm
@@ -236,14 +236,21 @@ encloses the contents.
 (define-public (eps-file->stencil axis size file-name)
   (let*
       ((contents (ly:gulp-file file-name))
-       (bbox (get-postscript-bbox contents))
+       (bbox (get-postscript-bbox (car (string-split contents #\nul))))
        (bbox-size (if (= axis X)
 		      (- (list-ref bbox 2) (list-ref bbox 0))
 		      (- (list-ref bbox 3) (list-ref bbox 1))
 		      ))
        (factor (exact->inexact (/ size bbox-size)))
        (scaled-bbox
-	(map (lambda (x) (* factor x)) bbox)))
+	(map (lambda (x) (* factor x)) bbox))
+       (clip-rect-string (format
+			  "~a ~a ~a ~a rectclip"
+			  (list-ref bbox 0) 
+			  (list-ref bbox 1) 
+			  (- (list-ref bbox 2) (list-ref bbox 0))
+			  (- (list-ref bbox 3) (list-ref bbox 1)))))
+    
 
     (if bbox
 	(ly:make-stencil
@@ -255,9 +262,11 @@ encloses the contents.
 gsave
 currentpoint translate
 BeginEPSF
-~a ~a scale
+~a dup scale
+~a 
 %%BeginDocument: ~a
-" 	   factor factor
+" 	   factor clip-rect-string
+
 	   file-name
 	   )
 	   contents
-- 
2.39.5