Reviewers: ,
Message:
Please note that *i* did the commit message - trying to interpret what
Etienne is trying to achieve, so if this is completely non-sensical,
blame me not him :)
Etienne knows this is a first 'draft' and sent me an email to say so,
any guidance would be appreciated:
---
From: Étienne Beaulé <beauleetien...@gmail.com>
To: James <p...@gnu.org>
Subject: Re: [Feature Request]: More flexible SVG snippet cropping
Date: Wed, 26 Jul 2017 20:24:41 -0300
I tried making a simple patch, but doesn't work. It's attached. I
wouldn't
know how, but if something like the "stack-stencils Y DOWN 0.0" section
from the output-preview-framework could be passed from output-framework
to
dump-page and there's a if statement for svg-begin for the -dcrop
option.
Guidance?
All the best
Étienne
Description:
Enhance the -dpreview method for SVG output
Issue 5165
Using SVG, the -dpreview option
has a limitation of only
outputting the first line.
This is a first attempt to merge the
dump-page and dump-preview methods
so that there is an option for
cropping pages that are not just
previews.
Please review this at https://codereview.appspot.com/326960043/
Affected files (+79, -0 lines):
M Documentation/usage/running.itely
M lily/paper-book.cc
M scm/framework-svg.scm
M scm/lily.scm
Index: Documentation/usage/running.itely
diff --git a/Documentation/usage/running.itely
b/Documentation/usage/running.itely
index
5ab8e1f37045abd4c4c4887c3b59a7a992a28a9d..b0c7ad2aa155f44877b14656505b98b2fdbb526f
100644
--- a/Documentation/usage/running.itely
+++ b/Documentation/usage/running.itely
@@ -677,6 +677,10 @@ See @ref{Point and click}.
@item @code{preview}
@tab @code{#f}
@tab Create preview images in addition to normal output.
+
+@item @code{crop}
+@tab @code{#f}
+@tab Match the size of the normal output to the typeset image for SVGs.
@end multitable
@noindent
Index: lily/paper-book.cc
diff --git a/lily/paper-book.cc b/lily/paper-book.cc
index
c17ed576f1895c0a91febb29164ea9987dda1b0f..f1787e99550f2bb09eb001188b69384c69e5f004
100644
--- a/lily/paper-book.cc
+++ b/lily/paper-book.cc
@@ -219,6 +219,25 @@ Paper_book::output (SCM output_channel)
warning (_f ("program option -dpreview not supported by backend
`%s'",
get_output_backend_name ()));
}
+
+ if (get_program_option ("crop"))
+ {
+ SCM framework
+ = ly_module_lookup (mod, ly_symbol2scm ("output-crop-framework"));
+
+ if (scm_is_true (framework))
+ {
+ SCM func = scm_variable_ref (framework);
+ scm_call_4 (func,
+ output_channel,
+ self_scm (),
+ scopes,
+ dump_fields ());
+ }
+ else
+ warning (_f ("program option -dcrop not supported by backend `%s'",
+ get_output_backend_name ()));
+ }
}
void
Index: scm/framework-svg.scm
diff --git a/scm/framework-svg.scm b/scm/framework-svg.scm
index
a4cf2e996055305dbeb36730dc78247b0a1016a4..729f7ad1898451731f72c0967dc784c140a67499
100644
--- a/scm/framework-svg.scm
+++ b/scm/framework-svg.scm
@@ -170,6 +170,37 @@ src: url('~a');
(dump (svg-end))
(ly:outputter-close outputter)))
+(define (dump-page-crop paper filename page page-number page-count stensil)
+ (let* ((outputter (ly:make-paper-outputter (open-file
filename "wb") 'svg))
+ (dump (lambda (str) (display str (ly:outputter-port outputter))))
+ (lookup (lambda (x) (ly:output-def-lookup paper x)))
+ (unit-length (lookup 'output-scale))
+ (x-extent (ly:stencil-extent stencil X))
+ (y-extent (ly:stencil-extent stencil Y))
+ (left-x (car x-extent))
+ (top-y (cdr y-extent))
+ (device-width (interval-length x-extent))
+ (device-height (interval-length y-extent))
+ (output-scale (* lily-unit->mm-factor unit-length))
+ (svg-width (* output-scale device-width))
+ (svg-height (* output-scale device-height)))
+
+ (if (ly:get-option 'svg-woff)
+ (module-define! (ly:outputter-module outputter) 'paper paper))
+ (dump (svg-begin svg-width svg-height
+ left-x (- top-y) device-width device-height))
+ (if (ly:get-option 'svg-woff)
+ (module-remove! (ly:outputter-module outputter) 'paper))
+ (if (ly:get-option 'svg-woff)
+ (dump (woff-header paper (dirname filename))))
+ (dump (comment (format #f "Page: ~S/~S" page-number page-count)))
+ (ly:outputter-output-scheme outputter
+ `(begin (set!
lily-unit-length ,unit-length)
+ ""))
+ (ly:outputter-dump-stencil outputter page)
+ (dump (svg-end))
+ (ly:outputter-close outputter)))
+
(define (output-framework basename book scopes fields)
(let* ((paper (ly:paper-book-paper book))
@@ -197,3 +228,25 @@ src: url('~a');
(map paper-system-stencil
(reverse to-dump-systems)))
(format #f "~a.preview.svg" basename))))
+
+(define (output-crop-framework basename book scopes fields)
+ (let* ((paper (ly:paper-book-paper book))
+ (systems (relevant-book-systems book))
+ (to-dump-systems (relevant-book-systems systems))
+ (page-stencils (map page-stencil (ly:paper-book-pages book)))
+ (page-number (1- (ly:output-def-lookup paper 'first-page-number)))
+ (page-count (length page-stencils))
+ (filename "")
+ (file-suffix (lambda (num)
+ (if (= page-count 1) "" (format #f "-crop-page-~a"
num)))))
+ (for-each
+ (lambda (page)
+ (set! page-number (1+ page-number))
+ (set! filename (format #f "~a~a.svg"
+ basename
+ (file-suffix page-number)))
+ (dump-page-crop paper filename page page-number page-count
+ (stack-stencils Y DOWN 0.0
+ (map paper-system-stencil
+ (reverse to-dump-systems)))))
+ page-stencils)))
Index: scm/lily.scm
diff --git a/scm/lily.scm b/scm/lily.scm
index
4b3c9c7e1c4cad55c64a53fe611d1effcf692612..ff0cb0e0acf15808d3dab7006d681fa734837770
100644
--- a/scm/lily.scm
+++ b/scm/lily.scm
@@ -338,6 +338,9 @@ to a music font.")
(preview
#f
"Create preview images also.")
+ (crop
+ #f
+ "Match the size of the output to the image.")
(print-pages
#t
"Print pages in the normal way.")
_______________________________________________
lilypond-devel mailing list
lilypond-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-devel