[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Add '-dcrop' option to ps and svg backends (issue 329990043 by address@h

From: beauleetienne0
Subject: Add '-dcrop' option to ps and svg backends (issue 329990043 by address@hidden)
Date: Fri, 11 Aug 2017 08:33:46 -0700

Reviewers: ,

This change supersedes Issue 326960043 with an entry to changes.tely.

Add '-dcrop' option to ps and svg backends

This change allows the output of scores in the format provided by the
'-dpreview' option but including all systems, not just the first.

This would allow for easier SVG use in HTML, without the need for
cropping snippets. Further, SVG is an HTML standard, and its vector
nature makes its use unparalleled for the web. This change would allow
SVG use in 'lilypond-book' in the future.

Please review this at

Affected files (+55, -1 lines):
  M Documentation/changes.tely
  M Documentation/usage/running.itely
  M lily/
  M scm/framework-ps.scm
  M scm/framework-svg.scm
  M scm/lily.scm

Index: Documentation/changes.tely
diff --git a/Documentation/changes.tely b/Documentation/changes.tely
index 482bbbdd659d598db0ef027dc0336ccce51bf063..3428a084944f3585bfbeef417e229c8ec3bdaa19 100644
--- a/Documentation/changes.tely
+++ b/Documentation/changes.tely
@@ -62,6 +62,10 @@ which scares away people.
 @end ignore

+An argument, @code{-dcrop}, has been added, formatting @code{SVG} and
address@hidden output without margins or page-breaks.
 It is now possible to move systems with reference to their current
 position using the @code{extra-offset} subproperty of
 @code{NonMusicalPaperColumn.line-break-system-details}.  Both vertical
Index: Documentation/usage/running.itely
diff --git a/Documentation/usage/running.itely b/Documentation/usage/running.itely index 4eeabc80dc587e6c033cebe160b6d8e66ffe3bb5..1fe748d93a2f3099808810f395b5d46b615184c3 100644
--- a/Documentation/usage/running.itely
+++ b/Documentation/usage/running.itely
@@ -505,6 +505,10 @@ in case an SVG viewer is unable to handle them. When using
 block.  See @ruser{Extracting fragments of music}.  No fragments are
 extracted though if used with the @option{-dno-print-pages} option.

address@hidden @code{crop}
address@hidden @code{#f}
address@hidden Match the size of the normal output to the typeset image.
 @item @code{datadir}
 @tab Prefix for data files (read-only).
@@ -672,7 +676,7 @@ To suppress the usual output, use the @option{-dprint-pages} or
 @item @code{print-pages}
 @tab @code{#t}
 @tab Generate full pages, the default.  @option{-dno-print-pages} is
-useful in combination with @option{-dpreview}.
+useful in combination with @option{-dpreview} or @option{-dcrop}.

 @item @code{profile-property-accesses}
 @tab @code{#f}
Index: lily/
diff --git a/lily/ b/lily/
index c17ed576f1895c0a91febb29164ea9987dda1b0f..f1787e99550f2bb09eb001188b69384c69e5f004 100644
--- a/lily/
+++ b/lily/
@@ -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 ()));
+    }

Index: scm/framework-ps.scm
diff --git a/scm/framework-ps.scm b/scm/framework-ps.scm
index 2cd9b5edc619bd6e067081cbbd521a30a65ef386..a9c5de2823dfc32271cf484f0f4d2dcc40f073b6 100644
--- a/scm/framework-ps.scm
+++ b/scm/framework-ps.scm
@@ -866,6 +866,22 @@ mark {ly~a_stream} /CLOSE pdfmark

+(define-public (output-crop-framework basename book scopes fields)
+  (let* ((paper (ly:paper-book-paper book))
+         (systems (relevant-book-systems book)))
+    (dump-stencil-as-EPS paper
+                         (stack-stencils Y DOWN 0.0
+                                         (map paper-system-stencil
+                                              (reverse (reverse systems))))
+                         (format #f "~a.cropped" basename)
+                         #t)
+    (postprocess-output book framework-ps-module
+                        (cons "png" (ly:output-formats))
+                        (format #f "~a.cropped" basename)
+                        (format #f "~a.cropped.eps" basename)
+                        #t
+                        )))

 (define (output-width-height defs)
Index: scm/framework-svg.scm
diff --git a/scm/framework-svg.scm b/scm/framework-svg.scm
index a4cf2e996055305dbeb36730dc78247b0a1016a4..85cbe1c2c11bb52a4473a6757de4b150819a525b 100644
--- a/scm/framework-svg.scm
+++ b/scm/framework-svg.scm
@@ -197,3 +197,11 @@ 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))
+         (page-stencils (stack-stencils Y DOWN 0.0
+                                        (map paper-system-stencil
+ (reverse (reverse systems)))))) + (dump-preview paper page-stencils (format #f "~a.cropped.svg" basename))))
Index: scm/lily.scm
diff --git a/scm/lily.scm b/scm/lily.scm
index 4b3c9c7e1c4cad55c64a53fe611d1effcf692612..5e727f1a5892cbb4de4d067f53e719ab3e9fcaf8 100644
--- a/scm/lily.scm
+++ b/scm/lily.scm
@@ -228,6 +228,9 @@ EPS backend.")
      "Generate cut-out snippets of a score.")
+    (crop
+     #f
+     "Match the size of the normal output to the typeset image.")
      "LilyPond prefix for data files (read-only).")

reply via email to

[Prev in Thread] Current Thread [Next in Thread]