|
View:
New views
20 Messages
—
Rating Filter:
Alert me
|
| < Prev | 1 - 2 | Next > |
|
|
[PATCH] New margin handling - final versionHi all,
thanks to Joe's latest patch concerning the system-count issue I concatenated now all the changes in one patch and rewrote the commit message. Could please somebody run the regression test suite and build the docs to see if all bugs have gone. This doesn't include the margin scaling patch I posted recently for review. Regards, Michael From 5e0663dfcf01e68e26572ec7979b9580ab26ea5c Mon Sep 17 00:00:00 2001 From: =?utf-8?q?Michael=20K=C3=A4ppler?= <xmichael-k@...> Date: Wed, 9 Sep 2009 11:48:35 +0200 Subject: [PATCH] Introduce new handling for paper margin settings. * Make default margins accessible in ly/paper-defaults-init.ly * Introduce a new method: Output_def::normalize (). It checks, whether left-margin, right-margin and/or line-width are set. Afterwards it computes missing values or takes defaults, if necessary. There is no need to specify line-width manually now. * Make right-margin work * If only line-width is set, the current behaviour persists. (Systems are centered) * Output a warning if the margin values don't fit with each other * Modify lilypond-book to get rid of the (define line-width (- line-width 3\mm)) stuff and introduce line-width-cropping for compatibility. --- input/regression/paper-margins.ly | 60 +++++++++++ lily/book.cc | 1 + lily/include/output-def.hh | 3 +- lily/output-def.cc | 92 ++++++++++++++++- lily/paper-book.cc | 11 ++- ly/paper-defaults-init.ly | 206 ++++++++++++++++++++----------------- scm/paper.scm | 18 ++-- scripts/lilypond-book.py | 2 +- 8 files changed, 285 insertions(+), 108 deletions(-) create mode 100644 input/regression/paper-margins.ly diff --git a/input/regression/paper-margins.ly b/input/regression/paper-margins.ly new file mode 100644 index 0000000..2d9b5dc --- /dev/null +++ b/input/regression/paper-margins.ly @@ -0,0 +1,60 @@ +\version "2.13.4" + +\header { + texidoc = "Paper margin settings don't have to be complete. Missing values are added automatically, finally + everything is checked for consistency." +} + +#(set-default-paper-size "a4") + +someNotes = \relative c' { \repeat unfold 40 { c4 d e f }} + +\book { + \bookpart { + \paper { } + \markup { If no paper settings are specified, default values are used. } + \score { \someNotes } + } + \bookpart { + \paper { + left-margin = 40 \mm + } + \markup { You may also specify only some margins. Missing values are added, if possible. } + \markup { Here only left-margin is given, right-margin will remain default. } + \score { \someNotes } + } + \bookpart { + \paper { + right-margin = 40 \mm + } + \markup { Here only right-margin is given, left-margin will remain default. } + \score { \someNotes } + } + \bookpart { + \paper { + line-width = 100 \mm + } + \markup { If only line-width is given, the systems are vertically centered. } + \score { \someNotes } + } + \bookpart { + \paper { + left-margin = 20 \mm + right-margin = 40 \mm + line-width = 100 \mm + } + \markup { If you specify line-margin, right-margin and line-width, the values must be consistent. } + \markup { In case they are not, default margins are set and a warning is printed. } + \score { \someNotes } + } + \bookpart { + \paper { + left-margin = 20 \mm + right-margin = 40 \mm + line-width = 200 \mm + check-consistency = ##f + } + \markup { You can avoid this check with settings check-consistency to false in the paper block. } + \score { \someNotes } + } +} diff --git a/lily/book.cc b/lily/book.cc index 303af1b..86eeda1 100644 --- a/lily/book.cc +++ b/lily/book.cc @@ -277,6 +277,7 @@ Book::process (Output_def *default_paper, } else { + paper_book->paper_->normalize (); /* Process scores */ /* Render in order of parsing. */ for (SCM s = scm_reverse (scores_); scm_is_pair (s); s = scm_cdr (s)) diff --git a/lily/include/output-def.hh b/lily/include/output-def.hh index b683cc6..9e28d18 100644 --- a/lily/include/output-def.hh +++ b/lily/include/output-def.hh @@ -58,13 +58,14 @@ public: SCM c_variable (string id) const; SCM lookup_variable (SCM sym) const; void set_variable (SCM sym, SCM val); + void normalize (); Real get_dimension (SCM symbol) const; }; SCM get_font_table (Output_def *def); void assign_context_def (Output_def *m, SCM transdef); SCM find_context_def (Output_def const *m, SCM name); -Interval line_dimensions_int (Output_def*def, int); +Interval line_dimensions_int (Output_def *def, int); Font_metric *select_encoded_font (Output_def *layout, SCM chain); diff --git a/lily/output-def.cc b/lily/output-def.cc index f9fbda9..3f60861 100644 --- a/lily/output-def.cc +++ b/lily/output-def.cc @@ -11,6 +11,7 @@ #include "context-def.hh" #include "file-path.hh" #include "global-context.hh" +#include "international.hh" #include "interval.hh" #include "main.hh" #include "output-def.hh" @@ -128,7 +129,96 @@ Output_def::set_variable (SCM sym, SCM val) scm_module_define (scope_, sym, val); } - +void +Output_def::normalize () +{ + Real paper_width; + SCM scm_paper_width = c_variable ("paper-width"); + + Real left_margin, left_margin_default; + SCM scm_left_margin_default = c_variable ("left-margin-default"); + SCM scm_left_margin = c_variable ("left-margin"); + + Real right_margin, right_margin_default; + SCM scm_right_margin_default = c_variable ("right-margin-default"); + SCM scm_right_margin = c_variable ("right-margin"); + + if (scm_paper_width == SCM_UNDEFINED + || scm_left_margin_default == SCM_UNDEFINED + || scm_right_margin_default == SCM_UNDEFINED) + { + programming_error ("called normalize() on paper with missing settings"); + return; + } + else + { + paper_width = scm_to_double (scm_paper_width); + left_margin_default = scm_to_double (scm_left_margin_default); + right_margin_default = scm_to_double (scm_right_margin_default); + } + + Real line_width; + Real line_width_default = paper_width - left_margin_default - right_margin_default; + SCM scm_line_width = c_variable ("line-width"); + + if (scm_line_width == SCM_UNDEFINED) + { + left_margin = ((scm_left_margin == SCM_UNDEFINED) ? left_margin_default : scm_to_double(scm_left_margin)); + right_margin = ((scm_right_margin == SCM_UNDEFINED) ? right_margin_default : scm_to_double(scm_right_margin)); + line_width = paper_width - left_margin - right_margin; + } + else + { + line_width = scm_to_double (scm_line_width); + if (scm_left_margin == SCM_UNDEFINED) + { + if (scm_right_margin == SCM_UNDEFINED) // Vertically center systems if only line-width is given + { + left_margin = (paper_width - line_width) / 2; + right_margin = left_margin; + } + else + { + right_margin = scm_to_double (scm_right_margin); + left_margin = paper_width - line_width - right_margin; + } + } + else + { + left_margin = scm_to_double (scm_left_margin); + right_margin = ((scm_right_margin == SCM_UNDEFINED) + ? (paper_width - line_width - left_margin) + : scm_to_double (scm_right_margin)); + } + } + + if (to_boolean (c_variable ("check-consistency"))) + { + // Consistency checks. If values don't match, set defaults. + if (abs(paper_width - line_width - left_margin - right_margin) > 1e-6) + { + line_width = line_width_default; + left_margin = left_margin_default; + right_margin = right_margin_default; + warning (_ ("margins do not fit with line-width, setting default values")); + } + else if ((left_margin < 0) || (right_margin < 0)) + { + line_width = line_width_default; + left_margin = left_margin_default; + right_margin = right_margin_default; + warning (_ ("systems run off the page due to improper paper settings, setting default values")); + } + } + + // Lilypond-book needs the possibility to crop the line-width by a given amount + line_width = line_width - robust_scm2double (c_variable ("line-width-cropping"), 0); + + set_variable (ly_symbol2scm ("left-margin"), scm_from_double (left_margin)); + set_variable (ly_symbol2scm ("right-margin"), scm_from_double (right_margin)); + set_variable (ly_symbol2scm ("line-width"), scm_from_double (line_width)); +} + /* FIXME. This is broken until we have a generic way of putting lists inside the \layout block. */ Interval diff --git a/lily/paper-book.cc b/lily/paper-book.cc index 3db1321..12a7f09 100644 --- a/lily/paper-book.cc +++ b/lily/paper-book.cc @@ -159,12 +159,21 @@ Paper_book::output (SCM output_channel) { int first_page_number = robust_scm2int (paper_->c_variable ("first-page-number"), 1); int first_performance_number = 0; + + /* FIXME: We need a line-width for ps output (framework-ps.scm:92). If we don't have any, we take the paper-width + unless we know better which line-width to choose (e.g. if there are \bookparts with different line-widths) + and why we need it at all. */ + + if (paper_->c_variable ("line-width") == SCM_UNDEFINED) + paper_->set_variable (ly_symbol2scm ("line-width"), paper_->c_variable ("paper-width")); + if (!output_aux (output_channel, true, &first_page_number, &first_performance_number)) return; - + + SCM scopes = SCM_EOL; if (ly_is_module (header_)) scopes = scm_cons (header_, scopes); diff --git a/ly/paper-defaults-init.ly b/ly/paper-defaults-init.ly index 1ee92ed..d742115 100644 --- a/ly/paper-defaults-init.ly +++ b/ly/paper-defaults-init.ly @@ -1,96 +1,116 @@ \version "2.12.0" \paper { - %%% WARNING - %%% - %%% If you add any new dimensions, don't forget to update - %%% the dimension-variables variable. See paper.scm. - - unit = #(ly:unit) - mm = 1.0 - in = 25.4 - pt = #(/ in 72.27) - cm = #(* 10 mm) - - print-page-number = ##t - - %% - %% 20pt staff, 5 pt = 1.75 mm - %% - - output-scale = #1.7573 - - #(define-public book-title (marked-up-title 'bookTitleMarkup)) - #(define-public score-title (marked-up-title 'scoreTitleMarkup)) - - %% - %% ugh. hard coded? - %% - - #(layout-set-absolute-staff-size (* 20.0 pt)) - - - #(define-public score-title-properties - '((is-title . #t) - (is-book-title . #f))) - #(define-public book-title-properties - '((is-title . #t) - (is-book-title . #t))) - - %% Note: these are not scaled; they are in staff-spaces. - between-system-spacing = #'((space . 12) (minimum-distance . 8) (padding . 1)) - between-scores-system-spacing = #'((space . 14) (minimum-distance . 8) (padding . 1)) - after-title-spacing = #'((space . 2) (padding . 0.5)) - before-title-spacing = #'((space . 5) (padding . 0.5)) - between-title-spacing = #'((space . 1) (padding . 0.5)) - top-system-spacing = #'((space . 1) (padding . 1) (min-distance . 0)) - top-title-spacing = #'((space . 1) (padding . 1) (min-distance . 0)) - bottom-system-spacing = #'((space . 1) (padding . 1) (min-distance . 0) (stretchability . 5)) - - ragged-bottom = ##f - - %% - %% looks best for shorter scores. - %% - ragged-last-bottom = ##t - - %% - %% settings for the page breaker - %% - blank-last-page-force = 0 - blank-after-score-page-force = 2 - blank-page-force = 5 - - %% - %% To limit space between systems on a page with a lot of space left - %% - page-limit-inter-system-space = ##f - page-limit-inter-system-space-factor = 1.4 - - #(define font-defaults - '((font-encoding . fetaMusic))) - - %% - %% the font encoding `latin1' is a dummy value for Pango fonts - %% - #(define text-font-defaults - `((font-encoding . latin1) - (baseline-skip . 3) - (word-space . 0.6))) - - #(define page-breaking ly:optimal-breaking) - - #(define make-header (marked-up-headfoot 'oddHeaderMarkup 'evenHeaderMarkup)) - #(define make-footer (marked-up-headfoot 'oddFooterMarkup 'evenFooterMarkup)) - #(set-paper-dimension-variables (current-module)) - - \include "titling-init.ly" - - top-margin = 5 \mm - bottom-margin = 6 \mm - head-separation = 4 \mm - foot-separation = 4 \mm - - first-page-number = #1 - print-first-page-number =##f -} + + %%% WARNING + %%% + %%% If you add any new dimensions, don't forget to update + %%% the dimension-variables variable. See paper.scm. + + unit = #(ly:unit) + mm = 1.0 + in = 25.4 + pt = #(/ in 72.27) + cm = #(* 10 mm) + + print-page-number = ##t + + %% + %% 20pt staff, 5 pt = 1.75 mm + %% + + output-scale = #1.7573 + + #(define-public book-title (marked-up-title 'bookTitleMarkup)) + #(define-public score-title (marked-up-title 'scoreTitleMarkup)) + + %% + %% ugh. hard coded? + %% + + #(layout-set-absolute-staff-size (* 20.0 pt)) + + + #(define-public score-title-properties + '((is-title . #t) + (is-book-title . #f) + )) + #(define-public book-title-properties + '((is-title . #t) + (is-book-title . #t) + )) + + %% Note: these are not scaled; they are in staff-spaces. + between-system-spacing = #'((space . 12) (minimum-distance . 8) (padding . 1)) + between-scores-system-spacing = #'((space . 14) (minimum-distance . 8) (padding . 1)) + after-title-spacing = #'((space . 2) (padding . 0.5)) + before-title-spacing = #'((space . 5) (padding . 0.5)) + between-title-spacing = #'((space . 1) (padding . 0.5)) + top-system-spacing = #'((space . 1) (padding . 1) (min-distance . 0)) + top-title-spacing = #'((space . 1) (padding . 1) (min-distance . 0)) + bottom-system-spacing = #'((space . 1) (padding . 1) (min-distance . 0) (stretchability . 5)) + + ragged-bottom = ##f + + %% + %% looks best for shorter scores. + %% + ragged-last-bottom= ##t + + %% + %% settings for the page breaker + %% + blank-last-page-force = 0 + blank-after-score-page-force = 2 + blank-page-force = 5 + + %% + %% To limit space between systems on a page with a lot of space left + %% + page-limit-inter-system-space = ##f + page-limit-inter-system-space-factor = 1.4 + + #(define font-defaults + '((font-encoding . fetaMusic))) + + %% + %% the font encoding `latin1' is a dummy value for Pango fonts + %% + #(define text-font-defaults + `((font-encoding . latin1) + (baseline-skip . 3) + (word-space . 0.6))) + + #(define page-breaking ly:optimal-breaking) + + #(define write-page-layout (ly:get-option 'dump-tweaks)) + #(define system-maximum-stretch-procedure + (lambda (line) + (if (stretchable-line? line) + (let ((height (line-height line))) + (/ (* height height) 80.0)) + 0.0))) + +% #(define page-music-height default-page-music-height ) +% #(define page-make-stencil default-page-make-stencil ) + + #(define make-header (marked-up-headfoot 'oddHeaderMarkup 'evenHeaderMarkup)) + #(define make-footer (marked-up-headfoot 'oddFooterMarkup 'evenFooterMarkup)) + #(set-paper-dimension-variables (current-module)) + + \include "titling-init.ly" + + check-consistency = ##t + + top-margin = 5 \mm + bottom-margin = 6 \mm + + left-margin-default = 10 \mm + right-margin-default = 10 \mm + + head-separation = 4 \mm + foot-separation = 4 \mm + + first-page-number = #1 + print-first-page-number =##f + } diff --git a/scm/paper.scm b/scm/paper.scm index 48f4a46..ab26e44 100644 --- a/scm/paper.scm +++ b/scm/paper.scm @@ -16,13 +16,16 @@ indent ledger-line-thickness left-margin + left-margin-default line-thickness line-width + line-width-cropping mm paper-height paper-width pt right-margin + right-margin-default short-indent staff-height staff-space @@ -207,23 +210,16 @@ size. SZ is in points" ("f4" . (cons (* 210 mm) (* 330 mm))) )) -;; todo: take dimension arguments. +; todo: take dimension arguments. (define (set-paper-dimensions m w h) "M is a module (i.e. layout->scope_ )" - (let* ((mm (eval 'mm m))) + (begin + ;; page layout - what to do with (printer specific!) margin settings? (module-define! m 'paper-width w) (module-define! m 'paper-height h) - (module-define! m 'line-width (- w - (ly:modules-lookup (list m) 'left-margin (* 10 mm)) - (ly:modules-lookup (list m) 'right-margin (* 10 mm)))) - (module-define! m 'indent (/ w 14)) - (module-define! m 'short-indent 0) - - ;; page layout - what to do with (printer specific!) margin settings? - - )) + (module-define! m 'short-indent 0))) (define (internal-set-paper-size module name landscape?) (define (swap x) diff --git a/scripts/lilypond-book.py b/scripts/lilypond-book.py index dc035b4..0308ada 100644 --- a/scripts/lilypond-book.py +++ b/scripts/lilypond-book.py @@ -830,7 +830,7 @@ PREAMBLE_LY = '''%%%% Generated by %(program_name)s \paper { %(paper_string)s force-assignment = #"" - line-width = #(- line-width (* mm %(padding_mm)f)) + line-width-cropping = %(padding_mm)f \mm } \layout { -- 1.6.0.2 _______________________________________________ lilypond-devel mailing list lilypond-devel@... http://lists.gnu.org/mailman/listinfo/lilypond-devel |
|
|
Re: [PATCH] New margin handling - final version (updated)Hi all,
I've just removed some code from page.scm that becomes obsolete through the patch. I would be really happy if somebody could test this for regressions. The problem is that for me it takes more than 12 hours to run a "make doc" and for this time I can't do anything other. (Just to give you an impression about my system's slowness) Regards, Michael From 7235a6af9fc738cea7e35d0e5063f772c7e94af1 Mon Sep 17 00:00:00 2001 From: =?utf-8?q?Michael=20K=C3=A4ppler?= <xmichael-k@...> Date: Fri, 11 Sep 2009 12:06:37 +0200 Subject: [PATCH] Introduce new handling for paper margin settings. * Make default margins accessible in ly/paper-defaults-init.ly * Introduce a new method: Output_def::normalize (). It checks, whether left-margin, right-margin and/or line-width are set. Afterwards it computes missing values or takes defaults, if necessary. There is no need to specify line-width manually now. * Make right-margin work * If only line-width is set, the current behaviour persists. (Systems are centered) * Output a warning if the margin values don't fit with each other * Modify lilypond-book to get rid of the (define line-width (- line-width 3\mm)) stuff and introduce line-width-cropping for compatibility. --- input/regression/paper-margins.ly | 60 +++++++++++ lily/book.cc | 1 + lily/include/output-def.hh | 3 +- lily/output-def.cc | 92 ++++++++++++++++- lily/paper-book.cc | 11 ++- ly/paper-defaults-init.ly | 206 ++++++++++++++++++++----------------- scm/page.scm | 6 +- scm/paper.scm | 18 ++-- scripts/lilypond-book.py | 2 +- 9 files changed, 286 insertions(+), 113 deletions(-) create mode 100644 input/regression/paper-margins.ly diff --git a/input/regression/paper-margins.ly b/input/regression/paper-margins.ly new file mode 100644 index 0000000..2d9b5dc --- /dev/null +++ b/input/regression/paper-margins.ly @@ -0,0 +1,60 @@ +\version "2.13.4" + +\header { + texidoc = "Paper margin settings don't have to be complete. Missing values are added automatically, finally + everything is checked for consistency." +} + +#(set-default-paper-size "a4") + +someNotes = \relative c' { \repeat unfold 40 { c4 d e f }} + +\book { + \bookpart { + \paper { } + \markup { If no paper settings are specified, default values are used. } + \score { \someNotes } + } + \bookpart { + \paper { + left-margin = 40 \mm + } + \markup { You may also specify only some margins. Missing values are added, if possible. } + \markup { Here only left-margin is given, right-margin will remain default. } + \score { \someNotes } + } + \bookpart { + \paper { + right-margin = 40 \mm + } + \markup { Here only right-margin is given, left-margin will remain default. } + \score { \someNotes } + } + \bookpart { + \paper { + line-width = 100 \mm + } + \markup { If only line-width is given, the systems are vertically centered. } + \score { \someNotes } + } + \bookpart { + \paper { + left-margin = 20 \mm + right-margin = 40 \mm + line-width = 100 \mm + } + \markup { If you specify line-margin, right-margin and line-width, the values must be consistent. } + \markup { In case they are not, default margins are set and a warning is printed. } + \score { \someNotes } + } + \bookpart { + \paper { + left-margin = 20 \mm + right-margin = 40 \mm + line-width = 200 \mm + check-consistency = ##f + } + \markup { You can avoid this check with settings check-consistency to false in the paper block. } + \score { \someNotes } + } +} diff --git a/lily/book.cc b/lily/book.cc index 303af1b..86eeda1 100644 --- a/lily/book.cc +++ b/lily/book.cc @@ -277,6 +277,7 @@ Book::process (Output_def *default_paper, } else { + paper_book->paper_->normalize (); /* Process scores */ /* Render in order of parsing. */ for (SCM s = scm_reverse (scores_); scm_is_pair (s); s = scm_cdr (s)) diff --git a/lily/include/output-def.hh b/lily/include/output-def.hh index b683cc6..9e28d18 100644 --- a/lily/include/output-def.hh +++ b/lily/include/output-def.hh @@ -58,13 +58,14 @@ public: SCM c_variable (string id) const; SCM lookup_variable (SCM sym) const; void set_variable (SCM sym, SCM val); + void normalize (); Real get_dimension (SCM symbol) const; }; SCM get_font_table (Output_def *def); void assign_context_def (Output_def *m, SCM transdef); SCM find_context_def (Output_def const *m, SCM name); -Interval line_dimensions_int (Output_def*def, int); +Interval line_dimensions_int (Output_def *def, int); Font_metric *select_encoded_font (Output_def *layout, SCM chain); diff --git a/lily/output-def.cc b/lily/output-def.cc index f9fbda9..3f60861 100644 --- a/lily/output-def.cc +++ b/lily/output-def.cc @@ -11,6 +11,7 @@ #include "context-def.hh" #include "file-path.hh" #include "global-context.hh" +#include "international.hh" #include "interval.hh" #include "main.hh" #include "output-def.hh" @@ -128,7 +129,96 @@ Output_def::set_variable (SCM sym, SCM val) scm_module_define (scope_, sym, val); } - +void +Output_def::normalize () +{ + Real paper_width; + SCM scm_paper_width = c_variable ("paper-width"); + + Real left_margin, left_margin_default; + SCM scm_left_margin_default = c_variable ("left-margin-default"); + SCM scm_left_margin = c_variable ("left-margin"); + + Real right_margin, right_margin_default; + SCM scm_right_margin_default = c_variable ("right-margin-default"); + SCM scm_right_margin = c_variable ("right-margin"); + + if (scm_paper_width == SCM_UNDEFINED + || scm_left_margin_default == SCM_UNDEFINED + || scm_right_margin_default == SCM_UNDEFINED) + { + programming_error ("called normalize() on paper with missing settings"); + return; + } + else + { + paper_width = scm_to_double (scm_paper_width); + left_margin_default = scm_to_double (scm_left_margin_default); + right_margin_default = scm_to_double (scm_right_margin_default); + } + + Real line_width; + Real line_width_default = paper_width - left_margin_default - right_margin_default; + SCM scm_line_width = c_variable ("line-width"); + + if (scm_line_width == SCM_UNDEFINED) + { + left_margin = ((scm_left_margin == SCM_UNDEFINED) ? left_margin_default : scm_to_double(scm_left_margin)); + right_margin = ((scm_right_margin == SCM_UNDEFINED) ? right_margin_default : scm_to_double(scm_right_margin)); + line_width = paper_width - left_margin - right_margin; + } + else + { + line_width = scm_to_double (scm_line_width); + if (scm_left_margin == SCM_UNDEFINED) + { + if (scm_right_margin == SCM_UNDEFINED) // Vertically center systems if only line-width is given + { + left_margin = (paper_width - line_width) / 2; + right_margin = left_margin; + } + else + { + right_margin = scm_to_double (scm_right_margin); + left_margin = paper_width - line_width - right_margin; + } + } + else + { + left_margin = scm_to_double (scm_left_margin); + right_margin = ((scm_right_margin == SCM_UNDEFINED) + ? (paper_width - line_width - left_margin) + : scm_to_double (scm_right_margin)); + } + } + + if (to_boolean (c_variable ("check-consistency"))) + { + // Consistency checks. If values don't match, set defaults. + if (abs(paper_width - line_width - left_margin - right_margin) > 1e-6) + { + line_width = line_width_default; + left_margin = left_margin_default; + right_margin = right_margin_default; + warning (_ ("margins do not fit with line-width, setting default values")); + } + else if ((left_margin < 0) || (right_margin < 0)) + { + line_width = line_width_default; + left_margin = left_margin_default; + right_margin = right_margin_default; + warning (_ ("systems run off the page due to improper paper settings, setting default values")); + } + } + + // Lilypond-book needs the possibility to crop the line-width by a given amount + line_width = line_width - robust_scm2double (c_variable ("line-width-cropping"), 0); + + set_variable (ly_symbol2scm ("left-margin"), scm_from_double (left_margin)); + set_variable (ly_symbol2scm ("right-margin"), scm_from_double (right_margin)); + set_variable (ly_symbol2scm ("line-width"), scm_from_double (line_width)); +} + /* FIXME. This is broken until we have a generic way of putting lists inside the \layout block. */ Interval diff --git a/lily/paper-book.cc b/lily/paper-book.cc index 3db1321..12a7f09 100644 --- a/lily/paper-book.cc +++ b/lily/paper-book.cc @@ -159,12 +159,21 @@ Paper_book::output (SCM output_channel) { int first_page_number = robust_scm2int (paper_->c_variable ("first-page-number"), 1); int first_performance_number = 0; + + /* FIXME: We need a line-width for ps output (framework-ps.scm:92). If we don't have any, we take the paper-width + unless we know better which line-width to choose (e.g. if there are \bookparts with different line-widths) + and why we need it at all. */ + + if (paper_->c_variable ("line-width") == SCM_UNDEFINED) + paper_->set_variable (ly_symbol2scm ("line-width"), paper_->c_variable ("paper-width")); + if (!output_aux (output_channel, true, &first_page_number, &first_performance_number)) return; - + + SCM scopes = SCM_EOL; if (ly_is_module (header_)) scopes = scm_cons (header_, scopes); diff --git a/ly/paper-defaults-init.ly b/ly/paper-defaults-init.ly index 1ee92ed..d742115 100644 --- a/ly/paper-defaults-init.ly +++ b/ly/paper-defaults-init.ly @@ -1,96 +1,116 @@ \version "2.12.0" \paper { - %%% WARNING - %%% - %%% If you add any new dimensions, don't forget to update - %%% the dimension-variables variable. See paper.scm. - - unit = #(ly:unit) - mm = 1.0 - in = 25.4 - pt = #(/ in 72.27) - cm = #(* 10 mm) - - print-page-number = ##t - - %% - %% 20pt staff, 5 pt = 1.75 mm - %% - - output-scale = #1.7573 - - #(define-public book-title (marked-up-title 'bookTitleMarkup)) - #(define-public score-title (marked-up-title 'scoreTitleMarkup)) - - %% - %% ugh. hard coded? - %% - - #(layout-set-absolute-staff-size (* 20.0 pt)) - - - #(define-public score-title-properties - '((is-title . #t) - (is-book-title . #f))) - #(define-public book-title-properties - '((is-title . #t) - (is-book-title . #t))) - - %% Note: these are not scaled; they are in staff-spaces. - between-system-spacing = #'((space . 12) (minimum-distance . 8) (padding . 1)) - between-scores-system-spacing = #'((space . 14) (minimum-distance . 8) (padding . 1)) - after-title-spacing = #'((space . 2) (padding . 0.5)) - before-title-spacing = #'((space . 5) (padding . 0.5)) - between-title-spacing = #'((space . 1) (padding . 0.5)) - top-system-spacing = #'((space . 1) (padding . 1) (min-distance . 0)) - top-title-spacing = #'((space . 1) (padding . 1) (min-distance . 0)) - bottom-system-spacing = #'((space . 1) (padding . 1) (min-distance . 0) (stretchability . 5)) - - ragged-bottom = ##f - - %% - %% looks best for shorter scores. - %% - ragged-last-bottom = ##t - - %% - %% settings for the page breaker - %% - blank-last-page-force = 0 - blank-after-score-page-force = 2 - blank-page-force = 5 - - %% - %% To limit space between systems on a page with a lot of space left - %% - page-limit-inter-system-space = ##f - page-limit-inter-system-space-factor = 1.4 - - #(define font-defaults - '((font-encoding . fetaMusic))) - - %% - %% the font encoding `latin1' is a dummy value for Pango fonts - %% - #(define text-font-defaults - `((font-encoding . latin1) - (baseline-skip . 3) - (word-space . 0.6))) - - #(define page-breaking ly:optimal-breaking) - - #(define make-header (marked-up-headfoot 'oddHeaderMarkup 'evenHeaderMarkup)) - #(define make-footer (marked-up-headfoot 'oddFooterMarkup 'evenFooterMarkup)) - #(set-paper-dimension-variables (current-module)) - - \include "titling-init.ly" - - top-margin = 5 \mm - bottom-margin = 6 \mm - head-separation = 4 \mm - foot-separation = 4 \mm - - first-page-number = #1 - print-first-page-number =##f -} + + %%% WARNING + %%% + %%% If you add any new dimensions, don't forget to update + %%% the dimension-variables variable. See paper.scm. + + unit = #(ly:unit) + mm = 1.0 + in = 25.4 + pt = #(/ in 72.27) + cm = #(* 10 mm) + + print-page-number = ##t + + %% + %% 20pt staff, 5 pt = 1.75 mm + %% + + output-scale = #1.7573 + + #(define-public book-title (marked-up-title 'bookTitleMarkup)) + #(define-public score-title (marked-up-title 'scoreTitleMarkup)) + + %% + %% ugh. hard coded? + %% + + #(layout-set-absolute-staff-size (* 20.0 pt)) + + + #(define-public score-title-properties + '((is-title . #t) + (is-book-title . #f) + )) + #(define-public book-title-properties + '((is-title . #t) + (is-book-title . #t) + )) + + %% Note: these are not scaled; they are in staff-spaces. + between-system-spacing = #'((space . 12) (minimum-distance . 8) (padding . 1)) + between-scores-system-spacing = #'((space . 14) (minimum-distance . 8) (padding . 1)) + after-title-spacing = #'((space . 2) (padding . 0.5)) + before-title-spacing = #'((space . 5) (padding . 0.5)) + between-title-spacing = #'((space . 1) (padding . 0.5)) + top-system-spacing = #'((space . 1) (padding . 1) (min-distance . 0)) + top-title-spacing = #'((space . 1) (padding . 1) (min-distance . 0)) + bottom-system-spacing = #'((space . 1) (padding . 1) (min-distance . 0) (stretchability . 5)) + + ragged-bottom = ##f + + %% + %% looks best for shorter scores. + %% + ragged-last-bottom= ##t + + %% + %% settings for the page breaker + %% + blank-last-page-force = 0 + blank-after-score-page-force = 2 + blank-page-force = 5 + + %% + %% To limit space between systems on a page with a lot of space left + %% + page-limit-inter-system-space = ##f + page-limit-inter-system-space-factor = 1.4 + + #(define font-defaults + '((font-encoding . fetaMusic))) + + %% + %% the font encoding `latin1' is a dummy value for Pango fonts + %% + #(define text-font-defaults + `((font-encoding . latin1) + (baseline-skip . 3) + (word-space . 0.6))) + + #(define page-breaking ly:optimal-breaking) + + #(define write-page-layout (ly:get-option 'dump-tweaks)) + #(define system-maximum-stretch-procedure + (lambda (line) + (if (stretchable-line? line) + (let ((height (line-height line))) + (/ (* height height) 80.0)) + 0.0))) + +% #(define page-music-height default-page-music-height ) +% #(define page-make-stencil default-page-make-stencil ) + + #(define make-header (marked-up-headfoot 'oddHeaderMarkup 'evenHeaderMarkup)) + #(define make-footer (marked-up-headfoot 'oddFooterMarkup 'evenFooterMarkup)) + #(set-paper-dimension-variables (current-module)) + + \include "titling-init.ly" + + check-consistency = ##t + + top-margin = 5 \mm + bottom-margin = 6 \mm + + left-margin-default = 10 \mm + right-margin-default = 10 \mm + + head-separation = 4 \mm + foot-separation = 4 \mm + + first-page-number = #1 + print-first-page-number =##f + } diff --git a/scm/page.scm b/scm/page.scm index ca4e0d8..959402c 100644 --- a/scm/page.scm +++ b/scm/page.scm @@ -184,11 +184,7 @@ (let* ((paper-height (ly:output-def-lookup layout 'paper-height)) (paper-width (ly:output-def-lookup layout 'paper-width)) - (lmargin (ly:output-def-lookup layout 'left-margin #f)) - (left-margin (if lmargin - lmargin - (/ (- paper-width - (ly:output-def-lookup layout 'line-width)) 2))) + (left-margin (ly:output-def-lookup layout 'left-margin)) (bottom-edge (- paper-height (ly:output-def-lookup layout 'bottom-margin)) ) (top-margin (ly:output-def-lookup layout 'top-margin)) diff --git a/scm/paper.scm b/scm/paper.scm index 48f4a46..ab26e44 100644 --- a/scm/paper.scm +++ b/scm/paper.scm @@ -16,13 +16,16 @@ indent ledger-line-thickness left-margin + left-margin-default line-thickness line-width + line-width-cropping mm paper-height paper-width pt right-margin + right-margin-default short-indent staff-height staff-space @@ -207,23 +210,16 @@ size. SZ is in points" ("f4" . (cons (* 210 mm) (* 330 mm))) )) -;; todo: take dimension arguments. +; todo: take dimension arguments. (define (set-paper-dimensions m w h) "M is a module (i.e. layout->scope_ )" - (let* ((mm (eval 'mm m))) + (begin + ;; page layout - what to do with (printer specific!) margin settings? (module-define! m 'paper-width w) (module-define! m 'paper-height h) - (module-define! m 'line-width (- w - (ly:modules-lookup (list m) 'left-margin (* 10 mm)) - (ly:modules-lookup (list m) 'right-margin (* 10 mm)))) - (module-define! m 'indent (/ w 14)) - (module-define! m 'short-indent 0) - - ;; page layout - what to do with (printer specific!) margin settings? - - )) + (module-define! m 'short-indent 0))) (define (internal-set-paper-size module name landscape?) (define (swap x) diff --git a/scripts/lilypond-book.py b/scripts/lilypond-book.py index dc035b4..0308ada 100644 --- a/scripts/lilypond-book.py +++ b/scripts/lilypond-book.py @@ -830,7 +830,7 @@ PREAMBLE_LY = '''%%%% Generated by %(program_name)s \paper { %(paper_string)s force-assignment = #"" - line-width = #(- line-width (* mm %(padding_mm)f)) + line-width-cropping = %(padding_mm)f \mm } \layout { -- 1.6.0.2 _______________________________________________ lilypond-devel mailing list lilypond-devel@... http://lists.gnu.org/mailman/listinfo/lilypond-devel |
|
|
Re: [PATCH] New margin handling - final version (updated)2009/9/11 Michael Käppler <xmichael-k@...>:
> Hi all, > I've just removed some code from page.scm that becomes obsolete through the > patch. Just a few comments: Can you rebase your changes in paper-defaults-init.ly so they don't revert the changes made since your original patch? The regression test would probably benefit from being split into several separate tests, particularly the final check-consistency setting, which can then have #(ly:set-option 'warning-as-error #f) added to it in anticipation of the mythical time when we can switch this option on for regression testing. :) + line_width = line_width - robust_scm2double (c_variable ("line-width-cropping"), 0); line_width -= robust_scm2double (c_variable ("line-width-cropping"), 0); > I would be really happy if somebody could test this for regressions. The > problem is that for me it takes more than 12 hours to run a "make doc" and > for this time I can't do anything other. > (Just to give you an impression about my system's slowness) Ouch. I'm happy to run the tests again. I'll report back once it's completed. Regards, Neil _______________________________________________ lilypond-devel mailing list lilypond-devel@... http://lists.gnu.org/mailman/listinfo/lilypond-devel |
|
|
Re: [PATCH] New margin handling - final version (updated)2009/9/11 Neil Puttock <n.puttock@...>:
> I'm happy to run the tests again. I'll report back once it's completed. Hmm, not for the first time recently, the regression tests came back completely unchanged, which should be impossible (nothing to do with your patch, I think). There are some subtle spacing changes in the docs, but no breakages: quite often the line width is slightly shorter, resulting in tighter spacing (see the PNG for expressive-headword.ly attached, which is eleven pixels shorter than the current example on kainhofer.com). Regards, Neil _______________________________________________ lilypond-devel mailing list lilypond-devel@... http://lists.gnu.org/mailman/listinfo/lilypond-devel |
|
|
Re: [PATCH] New margin handling - final version (updated)Hi Neil,
I'm fine with all your comments... > The regression test would probably benefit from being split into > several separate tests, particularly the final check-consistency > setting, which can then have #(ly:set-option 'warning-as-error #f) > added to it in anticipation of the mythical time when we can switch > this option on for regression testing. :) > ...however, I don't really understand the benefit of splitting the regtest. Do you propose to have separate files for each combination of settings? And if warning-as-error was set to true, the regtest would fail. I don't think that is intended, since the >absence< of the warning would be wrong behaviour, not the appearance. Regards, Michael btw. thanks for running the tests. _______________________________________________ lilypond-devel mailing list lilypond-devel@... http://lists.gnu.org/mailman/listinfo/lilypond-devel |
|
|
Re: [PATCH] New margin handling - final version (updated)On Fri, Sep 11, 2009 at 3:33 PM, Michael Käppler <xmichael-k@...> wrote:
> Hi Neil, > I'm fine with all your comments... >> >> The regression test would probably benefit from being split into >> several separate tests, particularly the final check-consistency >> setting, which can then have #(ly:set-option 'warning-as-error #f) >> added to it in anticipation of the mythical time when we can switch >> this option on for regression testing. :) > > ...however, I don't really understand the benefit of splitting the regtest. > Do you propose to have separate files for each combination of settings? > > And if warning-as-error was set to true, the regtest would fail. I don't > think that is intended, since the >absence< of the warning would be wrong > behaviour, not the appearance. If you *want* the warning(s) for regtests, add #(ly:set-option 'warning-as-error #f) as Neil suggested. Eventually, this option will be set to #t for regtest compilation, thus the need for overriding the default behavior. Thanks, Patrick _______________________________________________ lilypond-devel mailing list lilypond-devel@... http://lists.gnu.org/mailman/listinfo/lilypond-devel |
|
|
Re: [PATCH] New margin handling - final version (updated)> There are some subtle spacing changes in the docs, but no breakages: > quite often the line width is slightly shorter, resulting in tighter > spacing (see the PNG for expressive-headword.ly attached, which is > eleven pixels shorter than the current example on kainhofer.com). > Maybe this is the same issue Trevor reported one hour ago? Regards, Michael _______________________________________________ lilypond-devel mailing list lilypond-devel@... http://lists.gnu.org/mailman/listinfo/lilypond-devel |
|
|
Re: [PATCH] New margin handling - final version (updated)Hi,
please look again. Regards, Michael From 33c05dd7df4000d7f25d2903e2555d9ca86c2e1f Mon Sep 17 00:00:00 2001 From: =?utf-8?q?Michael=20K=C3=A4ppler?= <xmichael-k@...> Date: Sat, 12 Sep 2009 01:47:00 +0200 Subject: [PATCH] Introduce new handling for paper margin settings. * Make default margins accessible in ly/paper-defaults-init.ly * Introduce a new method: Output_def::normalize (). It checks, whether left-margin, right-margin and/or line-width are set. Afterwards it computes missing values or takes defaults, if necessary. There is no need to specify line-width manually now. * Make right-margin work * If only line-width is set, the current behaviour persists. (Systems are centered) * Output a warning if the margin values don't fit with each other * Modify lilypond-book to get rid of the (define line-width (- line-width 3\mm)) stuff and introduce line-width-cropping for compatibility. --- input/regression/paper-margins-consistency.ly | 34 +++++++++ input/regression/paper-margins.ly | 39 +++++++++++ lily/book.cc | 1 + lily/include/output-def.hh | 3 +- lily/output-def.cc | 92 ++++++++++++++++++++++++- lily/paper-book.cc | 11 +++- ly/paper-defaults-init.ly | 8 ++- scm/page.scm | 6 +-- scm/paper.scm | 18 ++--- scripts/lilypond-book.py | 2 +- 10 files changed, 193 insertions(+), 21 deletions(-) create mode 100644 input/regression/paper-margins-consistency.ly create mode 100644 input/regression/paper-margins.ly diff --git a/input/regression/paper-margins-consistency.ly b/input/regression/paper-margins-consistency.ly new file mode 100644 index 0000000..0a809c5 --- /dev/null +++ b/input/regression/paper-margins-consistency.ly @@ -0,0 +1,34 @@ +\version "2.13.4" + +#(ly:set-option 'warning-as-error #f) + +\header { + texidoc = "Paper settings are checked for consistency, which can be avoided by the user." +} + +#(set-default-paper-size "a4") + +someNotes = \relative c' { \repeat unfold 40 { c4 d e f }} + +\book { + \bookpart { + \paper { + left-margin = 20 \mm + right-margin = 40 \mm + line-width = 100 \mm + } + \markup { If you specify line-margin, right-margin and line-width, the values must be consistent. } + \markup { In case they are not, default margins are set and a warning is printed. } + \score { \someNotes } + } + \bookpart { + \paper { + left-margin = 20 \mm + right-margin = 40 \mm + line-width = 200 \mm + check-consistency = ##f + } + \markup { You can avoid this check with settings check-consistency to false in the paper block. } + \score { \someNotes } + } +} diff --git a/input/regression/paper-margins.ly b/input/regression/paper-margins.ly new file mode 100644 index 0000000..a97fa88 --- /dev/null +++ b/input/regression/paper-margins.ly @@ -0,0 +1,39 @@ +\version "2.13.4" + +\header { + texidoc = "Paper margin settings don't have to be complete. Missing values are added automatically." +} + +#(set-default-paper-size "a4") + +someNotes = \relative c' { \repeat unfold 40 { c4 d e f }} + +\book { + \bookpart { + \paper { } + \markup { If no paper settings are specified, default values are used. } + \score { \someNotes } + } + \bookpart { + \paper { + left-margin = 40 \mm + } + \markup { You may also specify only some margins. Missing values are added, if possible. } + \markup { Here only left-margin is given, right-margin will remain default. } + \score { \someNotes } + } + \bookpart { + \paper { + right-margin = 40 \mm + } + \markup { Here only right-margin is given, left-margin will remain default. } + \score { \someNotes } + } + \bookpart { + \paper { + line-width = 100 \mm + } + \markup { If only line-width is given, the systems are vertically centered. } + \score { \someNotes } + } +} diff --git a/lily/book.cc b/lily/book.cc index 303af1b..86eeda1 100644 --- a/lily/book.cc +++ b/lily/book.cc @@ -277,6 +277,7 @@ Book::process (Output_def *default_paper, } else { + paper_book->paper_->normalize (); /* Process scores */ /* Render in order of parsing. */ for (SCM s = scm_reverse (scores_); scm_is_pair (s); s = scm_cdr (s)) diff --git a/lily/include/output-def.hh b/lily/include/output-def.hh index b683cc6..9e28d18 100644 --- a/lily/include/output-def.hh +++ b/lily/include/output-def.hh @@ -58,13 +58,14 @@ public: SCM c_variable (string id) const; SCM lookup_variable (SCM sym) const; void set_variable (SCM sym, SCM val); + void normalize (); Real get_dimension (SCM symbol) const; }; SCM get_font_table (Output_def *def); void assign_context_def (Output_def *m, SCM transdef); SCM find_context_def (Output_def const *m, SCM name); -Interval line_dimensions_int (Output_def*def, int); +Interval line_dimensions_int (Output_def *def, int); Font_metric *select_encoded_font (Output_def *layout, SCM chain); diff --git a/lily/output-def.cc b/lily/output-def.cc index f9fbda9..b7c742b 100644 --- a/lily/output-def.cc +++ b/lily/output-def.cc @@ -11,6 +11,7 @@ #include "context-def.hh" #include "file-path.hh" #include "global-context.hh" +#include "international.hh" #include "interval.hh" #include "main.hh" #include "output-def.hh" @@ -128,7 +129,96 @@ Output_def::set_variable (SCM sym, SCM val) scm_module_define (scope_, sym, val); } - +void +Output_def::normalize () +{ + Real paper_width; + SCM scm_paper_width = c_variable ("paper-width"); + + Real left_margin, left_margin_default; + SCM scm_left_margin_default = c_variable ("left-margin-default"); + SCM scm_left_margin = c_variable ("left-margin"); + + Real right_margin, right_margin_default; + SCM scm_right_margin_default = c_variable ("right-margin-default"); + SCM scm_right_margin = c_variable ("right-margin"); + + if (scm_paper_width == SCM_UNDEFINED + || scm_left_margin_default == SCM_UNDEFINED + || scm_right_margin_default == SCM_UNDEFINED) + { + programming_error ("called normalize() on paper with missing settings"); + return; + } + else + { + paper_width = scm_to_double (scm_paper_width); + left_margin_default = scm_to_double (scm_left_margin_default); + right_margin_default = scm_to_double (scm_right_margin_default); + } + + Real line_width; + Real line_width_default = paper_width - left_margin_default - right_margin_default; + SCM scm_line_width = c_variable ("line-width"); + + if (scm_line_width == SCM_UNDEFINED) + { + left_margin = ((scm_left_margin == SCM_UNDEFINED) ? left_margin_default : scm_to_double(scm_left_margin)); + right_margin = ((scm_right_margin == SCM_UNDEFINED) ? right_margin_default : scm_to_double(scm_right_margin)); + line_width = paper_width - left_margin - right_margin; + } + else + { + line_width = scm_to_double (scm_line_width); + if (scm_left_margin == SCM_UNDEFINED) + { + if (scm_right_margin == SCM_UNDEFINED) // Vertically center systems if only line-width is given + { + left_margin = (paper_width - line_width) / 2; + right_margin = left_margin; + } + else + { + right_margin = scm_to_double (scm_right_margin); + left_margin = paper_width - line_width - right_margin; + } + } + else + { + left_margin = scm_to_double (scm_left_margin); + right_margin = ((scm_right_margin == SCM_UNDEFINED) + ? (paper_width - line_width - left_margin) + : scm_to_double (scm_right_margin)); + } + } + + if (to_boolean (c_variable ("check-consistency"))) + { + // Consistency checks. If values don't match, set defaults. + if (abs(paper_width - line_width - left_margin - right_margin) > 1e-6) + { + line_width = line_width_default; + left_margin = left_margin_default; + right_margin = right_margin_default; + warning (_ ("margins do not fit with line-width, setting default values")); + } + else if ((left_margin < 0) || (right_margin < 0)) + { + line_width = line_width_default; + left_margin = left_margin_default; + right_margin = right_margin_default; + warning (_ ("systems run off the page due to improper paper settings, setting default values")); + } + } + + // Lilypond-book needs the possibility to crop the line-width by a given amount + line_width -= robust_scm2double (c_variable ("line-width-cropping"), 0); + + set_variable (ly_symbol2scm ("left-margin"), scm_from_double (left_margin)); + set_variable (ly_symbol2scm ("right-margin"), scm_from_double (right_margin)); + set_variable (ly_symbol2scm ("line-width"), scm_from_double (line_width)); +} + /* FIXME. This is broken until we have a generic way of putting lists inside the \layout block. */ Interval diff --git a/lily/paper-book.cc b/lily/paper-book.cc index 3db1321..12a7f09 100644 --- a/lily/paper-book.cc +++ b/lily/paper-book.cc @@ -159,12 +159,21 @@ Paper_book::output (SCM output_channel) { int first_page_number = robust_scm2int (paper_->c_variable ("first-page-number"), 1); int first_performance_number = 0; + + /* FIXME: We need a line-width for ps output (framework-ps.scm:92). If we don't have any, we take the paper-width + unless we know better which line-width to choose (e.g. if there are \bookparts with different line-widths) + and why we need it at all. */ + + if (paper_->c_variable ("line-width") == SCM_UNDEFINED) + paper_->set_variable (ly_symbol2scm ("line-width"), paper_->c_variable ("paper-width")); + if (!output_aux (output_channel, true, &first_page_number, &first_performance_number)) return; - + + SCM scopes = SCM_EOL; if (ly_is_module (header_)) scopes = scm_cons (header_, scopes); diff --git a/ly/paper-defaults-init.ly b/ly/paper-defaults-init.ly index 1ee92ed..4db5459 100644 --- a/ly/paper-defaults-init.ly +++ b/ly/paper-defaults-init.ly @@ -86,11 +86,17 @@ \include "titling-init.ly" + check-consistency = ##t + top-margin = 5 \mm bottom-margin = 6 \mm + + left-margin-default = 10 \mm + right-margin-default = 10 \mm + head-separation = 4 \mm foot-separation = 4 \mm first-page-number = #1 - print-first-page-number =##f + print-first-page-number = ##f } diff --git a/scm/page.scm b/scm/page.scm index ca4e0d8..959402c 100644 --- a/scm/page.scm +++ b/scm/page.scm @@ -184,11 +184,7 @@ (let* ((paper-height (ly:output-def-lookup layout 'paper-height)) (paper-width (ly:output-def-lookup layout 'paper-width)) - (lmargin (ly:output-def-lookup layout 'left-margin #f)) - (left-margin (if lmargin - lmargin - (/ (- paper-width - (ly:output-def-lookup layout 'line-width)) 2))) + (left-margin (ly:output-def-lookup layout 'left-margin)) (bottom-edge (- paper-height (ly:output-def-lookup layout 'bottom-margin)) ) (top-margin (ly:output-def-lookup layout 'top-margin)) diff --git a/scm/paper.scm b/scm/paper.scm index 48f4a46..ab26e44 100644 --- a/scm/paper.scm +++ b/scm/paper.scm @@ -16,13 +16,16 @@ indent ledger-line-thickness left-margin + left-margin-default line-thickness line-width + line-width-cropping mm paper-height paper-width pt right-margin + right-margin-default short-indent staff-height staff-space @@ -207,23 +210,16 @@ size. SZ is in points" ("f4" . (cons (* 210 mm) (* 330 mm))) )) -;; todo: take dimension arguments. +; todo: take dimension arguments. (define (set-paper-dimensions m w h) "M is a module (i.e. layout->scope_ )" - (let* ((mm (eval 'mm m))) + (begin + ;; page layout - what to do with (printer specific!) margin settings? (module-define! m 'paper-width w) (module-define! m 'paper-height h) - (module-define! m 'line-width (- w - (ly:modules-lookup (list m) 'left-margin (* 10 mm)) - (ly:modules-lookup (list m) 'right-margin (* 10 mm)))) - (module-define! m 'indent (/ w 14)) - (module-define! m 'short-indent 0) - - ;; page layout - what to do with (printer specific!) margin settings? - - )) + (module-define! m 'short-indent 0))) (define (internal-set-paper-size module name landscape?) (define (swap x) diff --git a/scripts/lilypond-book.py b/scripts/lilypond-book.py index dc035b4..0308ada 100644 --- a/scripts/lilypond-book.py +++ b/scripts/lilypond-book.py @@ -830,7 +830,7 @@ PREAMBLE_LY = '''%%%% Generated by %(program_name)s \paper { %(paper_string)s force-assignment = #"" - line-width = #(- line-width (* mm %(padding_mm)f)) + line-width-cropping = %(padding_mm)f \mm } \layout { -- 1.6.0.2 _______________________________________________ lilypond-devel mailing list lilypond-devel@... http://lists.gnu.org/mailman/listinfo/lilypond-devel |
|
|
Re: [PATCH] New margin handling - final version (updated)2009/9/11 Michael Käppler <xmichael-k@...>:
> ...however, I don't really understand the benefit of splitting the regtest. > Do you propose to have separate files for each combination of settings? It's recommended at the top of the regression testing page. In your snippet, there's a lot of markup documenting the desired behaviour, which would probably be better off moved into texidocs. > And if warning-as-error was set to true, the regtest would fail. I don't > think that is intended, since the >absence< of the warning would be wrong > behaviour, not the appearance. Patrick explains this more clearly. Since we will eventually want 'warning-as-error to be set, any test which should produce a warning message must have this option unset (which is a good reason for hiving it off to its own test, in case anything else breaks in the future). Regards, Neil _______________________________________________ lilypond-devel mailing list lilypond-devel@... http://lists.gnu.org/mailman/listinfo/lilypond-devel |
|
|
Re: [PATCH] New margin handling - final version (updated)2009/9/12 Michael Käppler <xmichael-k@...>:
> Maybe this is the same issue Trevor reported one hour ago? Unlikely, since a comparison of the snippet files shows they have the same paper settings. Regards, Neil _______________________________________________ lilypond-devel mailing list lilypond-devel@... http://lists.gnu.org/mailman/listinfo/lilypond-devel |
|
|
Re: [PATCH] New margin handling - final version (updated)Hi Neil,
> There are some subtle spacing changes in the docs, but no breakages: > quite often the line width is slightly shorter, resulting in tighter > spacing (see the PNG for expressive-headword.ly attached, which is > eleven pixels shorter than the current example on kainhofer.com). > now I know what's the reason. The attempt I made with line-width-cropping doesn't really work, since if there are several \paper blocks line-width-cropping affects all and breaks the other settings. Btw. I don't understand, why lilypond-book inserts no line-width value when called with fragment. What is the reason for this behaviour? Regards, Michael _______________________________________________ lilypond-devel mailing list lilypond-devel@... http://lists.gnu.org/mailman/listinfo/lilypond-devel |
|
|
Re: [PATCH] New margin handling - final version (updated)2009/9/13 Michael Käppler <xmichael-k@...>:
> now I know what's the reason. The attempt I made with line-width-cropping > doesn't really work, > since if there are several \paper blocks line-width-cropping affects all and > breaks the other settings. Ah, I see. Apart from this, the only other issue I've noticed relates to the website snippet granados.ly, which uses landscape format: it's severely compressed and produces a `cannot find line breaking that satisfies constraints' warning (it's also not centred on the page). > Btw. I don't understand, why lilypond-book inserts no line-width value when > called with fragment. > What is the reason for this behaviour? I'm not sure, to be honest. Regards, Neil _______________________________________________ lilypond-devel mailing list lilypond-devel@... http://lists.gnu.org/mailman/listinfo/lilypond-devel |
|
|
Re: [PATCH] New margin handling - final version (updated)Neil Puttock wrote Sunday, September 13, 2009 7:45 PM > > 2009/9/13 Michael Käppler <xmichael-k@...>: > >> Btw. I don't understand, why lilypond-book inserts no line-width >> value when >> called with fragment. >> What is the reason for this behaviour? > > I'm not sure, to be honest. I think lilypond-book inserts line-width only when 'quote' or 'lilyquote' is specified (or 'linewidth' itself, of course). Trevor _______________________________________________ lilypond-devel mailing list lilypond-devel@... http://lists.gnu.org/mailman/listinfo/lilypond-devel |
|
|
Re: [PATCH] New margin handling - final version (updated)> I think lilypond-book inserts line-width only when 'quote' or > 'lilyquote' is specified (or 'linewidth' itself, of course). I don't think so. Look at lilypond-book.py:951. This value preserves if no option is set. You can verify this by running this small tex file, if you want: \documentclass[a4paper]{scrreprt} \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} \begin{document} \begin{lilypond} \relative c' { c4 d8 e } \end{lilypond} \end{document} To raise another question: What's the reason that the default for left-padding is hardcoded with 3 mm and applied to every snipped unless something different is specified? Regards, Michael _______________________________________________ lilypond-devel mailing list lilypond-devel@... http://lists.gnu.org/mailman/listinfo/lilypond-devel |
|
|
Re: [PATCH] New margin handling - final version (updated)Hi Neil,
>> now I know what's the reason. The attempt I made with line-width-cropping >> doesn't really work, >> since if there are several \paper blocks line-width-cropping affects all and >> breaks the other settings. >> > > Ah, I see. > I have to admit the lilypond-book code is very difficult to understand. Hence I don't know if my attempts are acceptable, actually. The solution I now propose is to set a default line-width if there is none after option parsing. I think the reason why lilypond-book sets no line-width when called with fragment is that fragment implies ragged-right and on ragged-right, line-width is removed. Maybe it would be secure (and even better) to preserve line-width also with ragged-right. Thoughts? (I really want to switch to a faster system soon, so I can do regtests and docs compiling on my own.) > Apart from this, the only other issue I've noticed relates to the > website snippet granados.ly, which uses landscape format: it's > severely compressed and produces a `cannot find line breaking that > satisfies constraints' warning (it's also not centred on the page). > Hmm, I can't reproduce this here. Can you try again and send me an png if it still fails? Regards, Michael From 62df04e629ba03493a16f0201ffb95c8ffbcf252 Mon Sep 17 00:00:00 2001 From: =?utf-8?q?Michael=20K=C3=A4ppler?= <xmichael-k@...> Date: Sat, 12 Sep 2009 01:47:00 +0200 Subject: [PATCH] Introduce new handling for paper margin settings. * Make default margins accessible in ly/paper-defaults-init.ly * Introduce a new method: Output_def::normalize (). It checks, whether left-margin, right-margin and/or line-width are set. Afterwards it computes missing values or takes defaults, if necessary. There is no need to specify line-width manually now. * Make right-margin work * If only line-width is set, the current behaviour persists. (Systems are centered) * Output a warning if the margin values don't fit with each other or systems run off the page due to improper settings * Modify lilypond-book to set a default line-width in case there is no other to base on left-padding (This is ugly, though) --- input/regression/paper-margins-consistency.ly | 19 +++++ input/regression/paper-margins-left-margin.ly | 13 +++ input/regression/paper-margins-line-width.ly | 13 +++ input/regression/paper-margins-no-checks.ly | 18 +++++ input/regression/paper-margins-overrun.ly | 18 +++++ input/regression/paper-margins-right-margin.ly | 13 +++ input/regression/paper-margins.ly | 14 ++++ lily/book.cc | 1 + lily/include/output-def.hh | 3 +- lily/output-def.cc | 97 ++++++++++++++++++++++- lily/paper-book.cc | 11 +++- ly/paper-defaults-init.ly | 8 ++- scm/page.scm | 6 +- scm/paper.scm | 18 ++--- scripts/lilypond-book.py | 10 +++ 15 files changed, 238 insertions(+), 24 deletions(-) create mode 100644 input/regression/paper-margins-consistency.ly create mode 100644 input/regression/paper-margins-left-margin.ly create mode 100644 input/regression/paper-margins-line-width.ly create mode 100644 input/regression/paper-margins-no-checks.ly create mode 100644 input/regression/paper-margins-overrun.ly create mode 100644 input/regression/paper-margins-right-margin.ly create mode 100644 input/regression/paper-margins.ly diff --git a/input/regression/paper-margins-consistency.ly b/input/regression/paper-margins-consistency.ly new file mode 100644 index 0000000..237cd68 --- /dev/null +++ b/input/regression/paper-margins-consistency.ly @@ -0,0 +1,19 @@ +\version "2.13.4" + +#(ly:set-option 'warning-as-error #f) + +\header { + texidoc = "Margin values must fit the line-width, that means: paper-width = + line-width + left-margin + right-margin. In case they do not, default margins + are set and a warning is printed." +} + +someNotes = \relative c' { \repeat unfold 40 { c4 d e f }} + +\paper { + left-margin = 20 \mm + right-margin = 40 \mm + line-width = 100 \mm +} + +\score { \someNotes } diff --git a/input/regression/paper-margins-left-margin.ly b/input/regression/paper-margins-left-margin.ly new file mode 100644 index 0000000..bcae7c9 --- /dev/null +++ b/input/regression/paper-margins-left-margin.ly @@ -0,0 +1,13 @@ +\version "2.13.4" + +\header { + texidoc = "Here only left-margin is given, right-margin will remain default." +} + +someNotes = \relative c' { \repeat unfold 40 { c4 d e f }} + +\paper { + left-margin = 40 \mm +} + +\score { \someNotes } diff --git a/input/regression/paper-margins-line-width.ly b/input/regression/paper-margins-line-width.ly new file mode 100644 index 0000000..b741e6e --- /dev/null +++ b/input/regression/paper-margins-line-width.ly @@ -0,0 +1,13 @@ +\version "2.13.4" + +\header { + texidoc = "If only line-width is given, systems are vertically centered." +} + +someNotes = \relative c' { \repeat unfold 40 { c4 d e f }} + +\paper { + line-width = 100 \mm +} + +\score { \someNotes } diff --git a/input/regression/paper-margins-no-checks.ly b/input/regression/paper-margins-no-checks.ly new file mode 100644 index 0000000..e3ab459 --- /dev/null +++ b/input/regression/paper-margins-no-checks.ly @@ -0,0 +1,18 @@ +\version "2.13.4" + +\header { + texidoc = "All checks can be avoided by setting check-consistency to ##f in \paper." +} + +someNotes = \relative c' { \repeat unfold 40 { c4 d e f }} + +\paper { + left-margin = 20 \mm + right-margin = 40 \mm + line-width = 200 \mm + check-consistency = ##f +} + +\score { \someNotes } + + diff --git a/input/regression/paper-margins-overrun.ly b/input/regression/paper-margins-overrun.ly new file mode 100644 index 0000000..8db56ad --- /dev/null +++ b/input/regression/paper-margins-overrun.ly @@ -0,0 +1,18 @@ +\version "2.13.4" + +#(ly:set-option 'warning-as-error #f) + +\header { + texidoc = "Normally, margin settings must not cause systems to run off the page." +} + +#(set-default-paper-size "a4") + +someNotes = \relative c' { \repeat unfold 40 { c4 d e f }} + +\paper { + left-margin = 20 \mm + line-width = 200 \mm +} + +\score { \someNotes } diff --git a/input/regression/paper-margins-right-margin.ly b/input/regression/paper-margins-right-margin.ly new file mode 100644 index 0000000..6b50659 --- /dev/null +++ b/input/regression/paper-margins-right-margin.ly @@ -0,0 +1,13 @@ +\version "2.13.4" + +\header { + texidoc = "Here only right-margin is given, left-margin will remain default." +} + +someNotes = \relative c' { \repeat unfold 40 { c4 d e f }} + +\paper { + right-margin = 40 \mm +} + +\score { \someNotes } diff --git a/input/regression/paper-margins.ly b/input/regression/paper-margins.ly new file mode 100644 index 0000000..25e92b8 --- /dev/null +++ b/input/regression/paper-margins.ly @@ -0,0 +1,14 @@ +\version "2.13.4" + +\header { + texidoc = "Paper margin settings do not have to be complete. Missing values are + added automatically. If no paper settings are specified, default values are + used." +} + +someNotes = \relative c' { \repeat unfold 40 { c4 d e f }} + +\paper { } + +\score { \someNotes } + diff --git a/lily/book.cc b/lily/book.cc index 303af1b..86eeda1 100644 --- a/lily/book.cc +++ b/lily/book.cc @@ -277,6 +277,7 @@ Book::process (Output_def *default_paper, } else { + paper_book->paper_->normalize (); /* Process scores */ /* Render in order of parsing. */ for (SCM s = scm_reverse (scores_); scm_is_pair (s); s = scm_cdr (s)) diff --git a/lily/include/output-def.hh b/lily/include/output-def.hh index b683cc6..9e28d18 100644 --- a/lily/include/output-def.hh +++ b/lily/include/output-def.hh @@ -58,13 +58,14 @@ public: SCM c_variable (string id) const; SCM lookup_variable (SCM sym) const; void set_variable (SCM sym, SCM val); + void normalize (); Real get_dimension (SCM symbol) const; }; SCM get_font_table (Output_def *def); void assign_context_def (Output_def *m, SCM transdef); SCM find_context_def (Output_def const *m, SCM name); -Interval line_dimensions_int (Output_def*def, int); +Interval line_dimensions_int (Output_def *def, int); Font_metric *select_encoded_font (Output_def *layout, SCM chain); diff --git a/lily/output-def.cc b/lily/output-def.cc index f9fbda9..8ee7952 100644 --- a/lily/output-def.cc +++ b/lily/output-def.cc @@ -11,6 +11,7 @@ #include "context-def.hh" #include "file-path.hh" #include "global-context.hh" +#include "international.hh" #include "interval.hh" #include "main.hh" #include "output-def.hh" @@ -29,7 +30,7 @@ Output_def::Output_def () parent_ = 0; smobify_self (); - + scope_ = ly_make_anonymous_module (false); } @@ -75,7 +76,7 @@ assign_context_def (Output_def * m, SCM transdef) { SCM sym = tp->get_context_name (); m->set_variable (sym, transdef); - } + } } /* find the translator for NAME. NAME must be a symbol. */ @@ -109,10 +110,10 @@ Output_def::lookup_variable (SCM sym) const SCM var = ly_module_lookup (scope_, sym); if (SCM_VARIABLEP (var) && SCM_VARIABLE_REF (var) != SCM_UNDEFINED) return SCM_VARIABLE_REF (var); - + if (parent_) return parent_->lookup_variable (sym); - + return SCM_UNDEFINED; } @@ -128,7 +129,93 @@ Output_def::set_variable (SCM sym, SCM val) scm_module_define (scope_, sym, val); } - +void +Output_def::normalize () +{ + Real paper_width; + SCM scm_paper_width = c_variable ("paper-width"); + + Real left_margin, left_margin_default; + SCM scm_left_margin_default = c_variable ("left-margin-default"); + SCM scm_left_margin = c_variable ("left-margin"); + + Real right_margin, right_margin_default; + SCM scm_right_margin_default = c_variable ("right-margin-default"); + SCM scm_right_margin = c_variable ("right-margin"); + + if (scm_paper_width == SCM_UNDEFINED + || scm_left_margin_default == SCM_UNDEFINED + || scm_right_margin_default == SCM_UNDEFINED) + { + programming_error ("called normalize() on paper with missing settings"); + return; + } + else + { + paper_width = scm_to_double (scm_paper_width); + left_margin_default = scm_to_double (scm_left_margin_default); + right_margin_default = scm_to_double (scm_right_margin_default); + } + + Real line_width; + Real line_width_default = paper_width - left_margin_default - right_margin_default; + SCM scm_line_width = c_variable ("line-width"); + + if (scm_line_width == SCM_UNDEFINED) + { + left_margin = ((scm_left_margin == SCM_UNDEFINED) ? left_margin_default : scm_to_double(scm_left_margin)); + right_margin = ((scm_right_margin == SCM_UNDEFINED) ? right_margin_default : scm_to_double(scm_right_margin)); + line_width = paper_width - left_margin - right_margin; + } + else + { + line_width = scm_to_double (scm_line_width); + if (scm_left_margin == SCM_UNDEFINED) + { + if (scm_right_margin == SCM_UNDEFINED) // Vertically center systems if only line-width is given + { + left_margin = (paper_width - line_width) / 2; + right_margin = left_margin; + } + else + { + right_margin = scm_to_double (scm_right_margin); + left_margin = paper_width - line_width - right_margin; + } + } + else + { + left_margin = scm_to_double (scm_left_margin); + right_margin = ((scm_right_margin == SCM_UNDEFINED) + ? (paper_width - line_width - left_margin) + : scm_to_double (scm_right_margin)); + } + } + + if (to_boolean (c_variable ("check-consistency"))) + { + // Consistency checks. If values don't match, set defaults. + if (abs(paper_width - line_width - left_margin - right_margin) > 1e-6) + { + line_width = line_width_default; + left_margin = left_margin_default; + right_margin = right_margin_default; + warning (_ ("margins do not fit with line-width, setting default values")); + } + else if ((left_margin < 0) || (right_margin < 0)) + { + line_width = line_width_default; + left_margin = left_margin_default; + right_margin = right_margin_default; + warning (_ ("systems run off the page due to improper paper settings, setting default values")); + } + } + + set_variable (ly_symbol2scm ("left-margin"), scm_from_double (left_margin)); + set_variable (ly_symbol2scm ("right-margin"), scm_from_double (right_margin)); + set_variable (ly_symbol2scm ("line-width"), scm_from_double (line_width)); +} + /* FIXME. This is broken until we have a generic way of putting lists inside the \layout block. */ Interval diff --git a/lily/paper-book.cc b/lily/paper-book.cc index 3db1321..12a7f09 100644 --- a/lily/paper-book.cc +++ b/lily/paper-book.cc @@ -159,12 +159,21 @@ Paper_book::output (SCM output_channel) { int first_page_number = robust_scm2int (paper_->c_variable ("first-page-number"), 1); int first_performance_number = 0; + + /* FIXME: We need a line-width for ps output (framework-ps.scm:92). If we don't have any, we take the paper-width + unless we know better which line-width to choose (e.g. if there are \bookparts with different line-widths) + and why we need it at all. */ + + if (paper_->c_variable ("line-width") == SCM_UNDEFINED) + paper_->set_variable (ly_symbol2scm ("line-width"), paper_->c_variable ("paper-width")); + if (!output_aux (output_channel, true, &first_page_number, &first_performance_number)) return; - + + SCM scopes = SCM_EOL; if (ly_is_module (header_)) scopes = scm_cons (header_, scopes); diff --git a/ly/paper-defaults-init.ly b/ly/paper-defaults-init.ly index 1ee92ed..4db5459 100644 --- a/ly/paper-defaults-init.ly +++ b/ly/paper-defaults-init.ly @@ -86,11 +86,17 @@ \include "titling-init.ly" + check-consistency = ##t + top-margin = 5 \mm bottom-margin = 6 \mm + + left-margin-default = 10 \mm + right-margin-default = 10 \mm + head-separation = 4 \mm foot-separation = 4 \mm first-page-number = #1 - print-first-page-number =##f + print-first-page-number = ##f } diff --git a/scm/page.scm b/scm/page.scm index ca4e0d8..959402c 100644 --- a/scm/page.scm +++ b/scm/page.scm @@ -184,11 +184,7 @@ (let* ((paper-height (ly:output-def-lookup layout 'paper-height)) (paper-width (ly:output-def-lookup layout 'paper-width)) - (lmargin (ly:output-def-lookup layout 'left-margin #f)) - (left-margin (if lmargin - lmargin - (/ (- paper-width - (ly:output-def-lookup layout 'line-width)) 2))) + (left-margin (ly:output-def-lookup layout 'left-margin)) (bottom-edge (- paper-height (ly:output-def-lookup layout 'bottom-margin)) ) (top-margin (ly:output-def-lookup layout 'top-margin)) diff --git a/scm/paper.scm b/scm/paper.scm index 48f4a46..ab26e44 100644 --- a/scm/paper.scm +++ b/scm/paper.scm @@ -16,13 +16,16 @@ indent ledger-line-thickness left-margin + left-margin-default line-thickness line-width + line-width-cropping mm paper-height paper-width pt right-margin + right-margin-default short-indent staff-height staff-space @@ -207,23 +210,16 @@ size. SZ is in points" ("f4" . (cons (* 210 mm) (* 330 mm))) )) -;; todo: take dimension arguments. +; todo: take dimension arguments. (define (set-paper-dimensions m w h) "M is a module (i.e. layout->scope_ )" - (let* ((mm (eval 'mm m))) + (begin + ;; page layout - what to do with (printer specific!) margin settings? (module-define! m 'paper-width w) (module-define! m 'paper-height h) - (module-define! m 'line-width (- w - (ly:modules-lookup (list m) 'left-margin (* 10 mm)) - (ly:modules-lookup (list m) 'right-margin (* 10 mm)))) - (module-define! m 'indent (/ w 14)) - (module-define! m 'short-indent 0) - - ;; page layout - what to do with (printer specific!) margin settings? - - )) + (module-define! m 'short-indent 0))) (define (internal-set-paper-size module name landscape?) (define (swap x) diff --git a/scripts/lilypond-book.py b/scripts/lilypond-book.py index dc035b4..735415c 100644 --- a/scripts/lilypond-book.py +++ b/scripts/lilypond-book.py @@ -1124,6 +1124,16 @@ class LilypondSnippet (Snippet): else: del self.option_dict[QUOTE] + + # FIXME: This is really ugly. Every setting should be there only once, + # instead of having several line-width = foo / line-width = blah + # constructs. This would affect also QUOTE / LILYQUOTE, however. + if not LINE_WIDTH in self.option_dict: + if not QUOTE in self.option_dict: + if not LILYQUOTE in self.option_dict: + self.option_dict[LINE_WIDTH] = "#(- paper-width \ +left-margin-default right-margin-default)" + def compose_ly (self, code): if FRAGMENT in self.option_dict: body = FRAGMENT_LY -- 1.6.0.2 _______________________________________________ lilypond-devel mailing list lilypond-devel@... http://lists.gnu.org/mailman/listinfo/lilypond-devel |
|
|
Re: [PATCH] New margin handling - final version (updated)2009/9/14 Michael Käppler <xmichael-k@...>:
> Hmm, I can't reproduce this here. Can you try again and send me an png if it > still fails? It's still pretty bad; see the attached image. Regards, Neil _______________________________________________ lilypond-devel mailing list lilypond-devel@... http://lists.gnu.org/mailman/listinfo/lilypond-devel |
|
|
Re: [PATCH] New margin handling - final version (updated)Neil Puttock wrote:
> 2009/9/14 Michael Käppler <xmichael-k@...>: > > >> Hmm, I can't reproduce this here. Can you try again and send me an png if it >> still fails? >> > > It's still pretty bad; see the attached image. > This is weird. I've just checked out a fresh master, did a make clean and compiled. When compiling granados.ly, it looks (as I can compare this) exactly the same and it also outputs the warning "cannot find line breaking that satisfies ..." Let's sum up: - 2.13.3 definitely doesn't have this problem (but there were >many< changes since) - the git master I've just compiled gives the warning and the bad spacing - your git master compiles without warning and with proper spacing (?, please proof) - the example png at kainhofer.com looks fine, though I'm not sure if it's compiled with git, since it's on the new website preview. Regards, Michael _______________________________________________ lilypond-devel mailing list lilypond-devel@... http://lists.gnu.org/mailman/listinfo/lilypond-devel |
|
|
Re: [PATCH] New margin handling - final version (updated)2009/9/20 Michael Käppler <xmichael-k@...>:
> - your git master compiles without warning and with proper spacing (?, > please proof) Correct. I've just done a completely clean build, and it compiles without any problems (see attached output, which is taken from my local copy of this page: http://www.kainhofer.com/~lilypond/Documentation/general/Examples.html#Examples). As far as I can tell, it's identical to the kainhofer version. > - the example png at kainhofer.com looks fine, though I'm not sure if it's > compiled with git, since it's on the new website preview. Yep, it's a nightly build based on master, though only certain parts are rebuilt unless a clean build is forced (I doubt the Granados example is built from scratch every night). Regards, Neil _______________________________________________ lilypond-devel mailing list lilypond-devel@... http://lists.gnu.org/mailman/listinfo/lilypond-devel |
|
|
Re: [PATCH] New margin handling - final version (updated)Hi Neil,
now it's clear to me what happened. I concatenated the \paper blocks of granados.ly and example-header.ily together for testing. Because then the fixed line-width from example-header.ily won't be overwritten by (set-paper-size), it looked as compressed on master as on my testing branch. I fixed this now by removing any line-width setting when calling (set-paper-dimensions). Regards, Michael From 70ea27f30399183293e7b5db3cd0af466fd99680 Mon Sep 17 00:00:00 2001 From: =?utf-8?q?Michael=20K=C3=A4ppler?= <xmichael-k@...> Date: Sat, 12 Sep 2009 01:47:00 +0200 Subject: [PATCH] Introduce new handling for paper margin settings. * Make default margins accessible in ly/paper-defaults-init.ly * Introduce a new method: Output_def::normalize (). It checks, whether left-margin, right-margin and/or line-width are set. Afterwards it computes missing values or takes defaults, if necessary. There is no need to specify line-width manually now. * Make right-margin work * If only line-width is set, the current behaviour persists. (Systems are centered) * Output a warning if the margin values don't fit with each other or systems run off the page due to improper settings * Modify lilypond-book to set a default line-width in case there is no other to base on left-padding (This is ugly, though) --- input/regression/paper-margins-consistency.ly | 19 +++++ input/regression/paper-margins-left-margin.ly | 13 +++ input/regression/paper-margins-line-width.ly | 13 +++ input/regression/paper-margins-no-checks.ly | 18 +++++ input/regression/paper-margins-overrun.ly | 18 +++++ input/regression/paper-margins-right-margin.ly | 13 +++ input/regression/paper-margins.ly | 14 ++++ lily/book.cc | 1 + lily/include/output-def.hh | 3 +- lily/output-def.cc | 97 ++++++++++++++++++++++- lily/paper-book.cc | 11 +++- ly/paper-defaults-init.ly | 8 ++- scm/page.scm | 6 +- scm/paper.scm | 18 ++--- scripts/lilypond-book.py | 9 ++ 15 files changed, 237 insertions(+), 24 deletions(-) create mode 100644 input/regression/paper-margins-consistency.ly create mode 100644 input/regression/paper-margins-left-margin.ly create mode 100644 input/regression/paper-margins-line-width.ly create mode 100644 input/regression/paper-margins-no-checks.ly create mode 100644 input/regression/paper-margins-overrun.ly create mode 100644 input/regression/paper-margins-right-margin.ly create mode 100644 input/regression/paper-margins.ly diff --git a/input/regression/paper-margins-consistency.ly b/input/regression/paper-margins-consistency.ly new file mode 100644 index 0000000..237cd68 --- /dev/null +++ b/input/regression/paper-margins-consistency.ly @@ -0,0 +1,19 @@ +\version "2.13.4" + +#(ly:set-option 'warning-as-error #f) + +\header { + texidoc = "Margin values must fit the line-width, that means: paper-width = + line-width + left-margin + right-margin. In case they do not, default margins + are set and a warning is printed." +} + +someNotes = \relative c' { \repeat unfold 40 { c4 d e f }} + +\paper { + left-margin = 20 \mm + right-margin = 40 \mm + line-width = 100 \mm +} + +\score { \someNotes } diff --git a/input/regression/paper-margins-left-margin.ly b/input/regression/paper-margins-left-margin.ly new file mode 100644 index 0000000..bcae7c9 --- /dev/null +++ b/input/regression/paper-margins-left-margin.ly @@ -0,0 +1,13 @@ +\version "2.13.4" + +\header { + texidoc = "Here only left-margin is given, right-margin will remain default." +} + +someNotes = \relative c' { \repeat unfold 40 { c4 d e f }} + +\paper { + left-margin = 40 \mm +} + +\score { \someNotes } diff --git a/input/regression/paper-margins-line-width.ly b/input/regression/paper-margins-line-width.ly new file mode 100644 index 0000000..b741e6e --- /dev/null +++ b/input/regression/paper-margins-line-width.ly @@ -0,0 +1,13 @@ +\version "2.13.4" + +\header { + texidoc = "If only line-width is given, systems are vertically centered." +} + +someNotes = \relative c' { \repeat unfold 40 { c4 d e f }} + +\paper { + line-width = 100 \mm +} + +\score { \someNotes } diff --git a/input/regression/paper-margins-no-checks.ly b/input/regression/paper-margins-no-checks.ly new file mode 100644 index 0000000..e3ab459 --- /dev/null +++ b/input/regression/paper-margins-no-checks.ly @@ -0,0 +1,18 @@ +\version "2.13.4" + +\header { + texidoc = "All checks can be avoided by setting check-consistency to ##f in \paper." +} + +someNotes = \relative c' { \repeat unfold 40 { c4 d e f }} + +\paper { + left-margin = 20 \mm + right-margin = 40 \mm + line-width = 200 \mm + check-consistency = ##f +} + +\score { \someNotes } + + diff --git a/input/regression/paper-margins-overrun.ly b/input/regression/paper-margins-overrun.ly new file mode 100644 index 0000000..8db56ad --- /dev/null +++ b/input/regression/paper-margins-overrun.ly @@ -0,0 +1,18 @@ +\version "2.13.4" + +#(ly:set-option 'warning-as-error #f) + +\header { + texidoc = "Normally, margin settings must not cause systems to run off the page." +} + +#(set-default-paper-size "a4") + +someNotes = \relative c' { \repeat unfold 40 { c4 d e f }} + +\paper { + left-margin = 20 \mm + line-width = 200 \mm +} + +\score { \someNotes } diff --git a/input/regression/paper-margins-right-margin.ly b/input/regression/paper-margins-right-margin.ly new file mode 100644 index 0000000..6b50659 --- /dev/null +++ b/input/regression/paper-margins-right-margin.ly @@ -0,0 +1,13 @@ +\version "2.13.4" + +\header { + texidoc = "Here only right-margin is given, left-margin will remain default." +} + +someNotes = \relative c' { \repeat unfold 40 { c4 d e f }} + +\paper { + right-margin = 40 \mm +} + +\score { \someNotes } diff --git a/input/regression/paper-margins.ly b/input/regression/paper-margins.ly new file mode 100644 index 0000000..25e92b8 --- /dev/null +++ b/input/regression/paper-margins.ly @@ -0,0 +1,14 @@ +\version "2.13.4" + +\header { + texidoc = "Paper margin settings do not have to be complete. Missing values are + added automatically. If no paper settings are specified, default values are + used." +} + +someNotes = \relative c' { \repeat unfold 40 { c4 d e f }} + +\paper { } + +\score { \someNotes } + diff --git a/lily/book.cc b/lily/book.cc index 303af1b..86eeda1 100644 --- a/lily/book.cc +++ b/lily/book.cc @@ -277,6 +277,7 @@ Book::process (Output_def *default_paper, } else { + paper_book->paper_->normalize (); /* Process scores */ /* Render in order of parsing. */ for (SCM s = scm_reverse (scores_); scm_is_pair (s); s = scm_cdr (s)) diff --git a/lily/include/output-def.hh b/lily/include/output-def.hh index b683cc6..9e28d18 100644 --- a/lily/include/output-def.hh +++ b/lily/include/output-def.hh @@ -58,13 +58,14 @@ public: SCM c_variable (string id) const; SCM lookup_variable (SCM sym) const; void set_variable (SCM sym, SCM val); + void normalize (); Real get_dimension (SCM symbol) const; }; SCM get_font_table (Output_def *def); void assign_context_def (Output_def *m, SCM transdef); SCM find_context_def (Output_def const *m, SCM name); -Interval line_dimensions_int (Output_def*def, int); +Interval line_dimensions_int (Output_def *def, int); Font_metric *select_encoded_font (Output_def *layout, SCM chain); diff --git a/lily/output-def.cc b/lily/output-def.cc index f9fbda9..8ee7952 100644 --- a/lily/output-def.cc +++ b/lily/output-def.cc @@ -11,6 +11,7 @@ #include "context-def.hh" #include "file-path.hh" #include "global-context.hh" +#include "international.hh" #include "interval.hh" #include "main.hh" #include "output-def.hh" @@ -29,7 +30,7 @@ Output_def::Output_def () parent_ = 0; smobify_self (); - + scope_ = ly_make_anonymous_module (false); } @@ -75,7 +76,7 @@ assign_context_def (Output_def * m, SCM transdef) { SCM sym = tp->get_context_name (); m->set_variable (sym, transdef); - } + } } /* find the translator for NAME. NAME must be a symbol. */ @@ -109,10 +110,10 @@ Output_def::lookup_variable (SCM sym) const SCM var = ly_module_lookup (scope_, sym); if (SCM_VARIABLEP (var) && SCM_VARIABLE_REF (var) != SCM_UNDEFINED) return SCM_VARIABLE_REF (var); - + if (parent_) return parent_->lookup_variable (sym); - + return SCM_UNDEFINED; } @@ -128,7 +129,93 @@ Output_def::set_variable (SCM sym, SCM val) scm_module_define (scope_, sym, val); } - +void +Output_def::normalize () +{ + Real paper_width; + SCM scm_paper_width = c_variable ("paper-width"); + + Real left_margin, left_margin_default; + SCM scm_left_margin_default = c_variable ("left-margin-default"); + SCM scm_left_margin = c_variable ("left-margin"); + + Real right_margin, right_margin_default; + SCM scm_right_margin_default = c_variable ("right-margin-default"); + SCM scm_right_margin = c_variable ("right-margin"); + + if (scm_paper_width == SCM_UNDEFINED + || scm_left_margin_default == SCM_UNDEFINED + || scm_right_margin_default == SCM_UNDEFINED) + { + programming_error ("called normalize() on paper with missing settings"); + return; + } + else + { + paper_width = scm_to_double (scm_paper_width); + left_margin_default = scm_to_double (scm_left_margin_default); + right_margin_default = scm_to_double (scm_right_margin_default); + } + + Real line_width; + Real line_width_default = paper_width - left_margin_default - right_margin_default; + SCM scm_line_width = c_variable ("line-width"); + + if (scm_line_width == SCM_UNDEFINED) + { + left_margin = ((scm_left_margin == SCM_UNDEFINED) ? left_margin_default : scm_to_double(scm_left_margin)); + right_margin = ((scm_right_margin == SCM_UNDEFINED) ? right_margin_default : scm_to_double(scm_right_margin)); + line_width = paper_width - left_margin - right_margin; + } + else + { + line_width = scm_to_double (scm_line_width); + if (scm_left_margin == SCM_UNDEFINED) + { + if (scm_right_margin == SCM_UNDEFINED) // Vertically center systems if only line-width is given + { + left_margin = (paper_width - line_width) / 2; + right_margin = left_margin; + } + else + { + right_margin = scm_to_double (scm_right_margin); + left_margin = paper_width - line_width - right_margin; + } + } + else + { + left_margin = scm_to_double (scm_left_margin); + right_margin = ((scm_right_margin == SCM_UNDEFINED) + ? (paper_width - line_width - left_margin) + : scm_to_double (scm_right_margin)); + } + } + + if (to_boolean (c_variable ("check-consistency"))) + { + // Consistency checks. If values don't match, set defaults. + if (abs(paper_width - line_width - left_margin - right_margin) > 1e-6) + { + line_width = line_width_default; + left_margin = left_margin_default; + right_margin = right_margin_default; + warning (_ ("margins do not fit with line-width, setting default values")); + } + else if ((left_margin < 0) || (right_margin < 0)) + { + line_width = line_width_default; + left_margin = left_margin_default; + right_margin = right_margin_default; + warning (_ ("systems run off the page due to improper paper settings, setting default values")); + } + } + + set_variable (ly_symbol2scm ("left-margin"), scm_from_double (left_margin)); + set_variable (ly_symbol2scm ("right-margin"), scm_from_double (right_margin)); + set_variable (ly_symbol2scm ("line-width"), scm_from_double (line_width)); +} + /* FIXME. This is broken until we have a generic way of putting lists inside the \layout block. */ Interval diff --git a/lily/paper-book.cc b/lily/paper-book.cc index 3db1321..12a7f09 100644 --- a/lily/paper-book.cc +++ b/lily/paper-book.cc @@ -159,12 +159,21 @@ Paper_book::output (SCM output_channel) { int first_page_number = robust_scm2int (paper_->c_variable ("first-page-number"), 1); int first_performance_number = 0; + + /* FIXME: We need a line-width for ps output (framework-ps.scm:92). If we don't have any, we take the paper-width + unless we know better which line-width to choose (e.g. if there are \bookparts with different line-widths) + and why we need it at all. */ + + if (paper_->c_variable ("line-width") == SCM_UNDEFINED) + paper_->set_variable (ly_symbol2scm ("line-width"), paper_->c_variable ("paper-width")); + if (!output_aux (output_channel, true, &first_page_number, &first_performance_number)) return; - + + SCM scopes = SCM_EOL; if (ly_is_module (header_)) scopes = scm_cons (header_, scopes); diff --git a/ly/paper-defaults-init.ly b/ly/paper-defaults-init.ly index 1ee92ed..4db5459 100644 --- a/ly/paper-defaults-init.ly +++ b/ly/paper-defaults-init.ly @@ -86,11 +86,17 @@ \include "titling-init.ly" + check-consistency = ##t + top-margin = 5 \mm bottom-margin = 6 \mm + + left-margin-default = 10 \mm + right-margin-default = 10 \mm + head-separation = 4 \mm foot-separation = 4 \mm first-page-number = #1 - print-first-page-number =##f + print-first-page-number = ##f } diff --git a/scm/page.scm b/scm/page.scm index ca4e0d8..959402c 100644 --- a/scm/page.scm +++ b/scm/page.scm @@ -184,11 +184,7 @@ (let* ((paper-height (ly:output-def-lookup layout 'paper-height)) (paper-width (ly:output-def-lookup layout 'paper-width)) - (lmargin (ly:output-def-lookup layout 'left-margin #f)) - (left-margin (if lmargin - lmargin - (/ (- paper-width - (ly:output-def-lookup layout 'line-width)) 2))) + (left-margin (ly:output-def-lookup layout 'left-margin)) (bottom-edge (- paper-height (ly:output-def-lookup layout 'bottom-margin)) ) (top-margin (ly:output-def-lookup layout 'top-margin)) diff --git a/scm/paper.scm b/scm/paper.scm index 01fa8c0..1eb3b59 100644 --- a/scm/paper.scm +++ b/scm/paper.scm @@ -16,6 +16,7 @@ indent ledger-line-thickness left-margin + left-margin-default line-thickness line-width mm @@ -23,6 +24,7 @@ paper-width pt right-margin + right-margin-default short-indent staff-height staff-space @@ -207,23 +209,17 @@ size. SZ is in points" ("f4" . (cons (* 210 mm) (* 330 mm))) )) -;; todo: take dimension arguments. +; todo: take dimension arguments. (define (set-paper-dimensions m w h) "M is a module (i.e. layout->scope_ )" - (let* ((mm (eval 'mm m))) + (begin + ;; page layout - what to do with (printer specific!) margin settings? (module-define! m 'paper-width w) (module-define! m 'paper-height h) - (module-define! m 'line-width (- w - (ly:modules-lookup (list m) 'left-margin (* 10 mm)) - (ly:modules-lookup (list m) 'right-margin (* 10 mm)))) - (module-define! m 'indent (/ w 14)) - (module-define! m 'short-indent 0) - - ;; page layout - what to do with (printer specific!) margin settings? - - )) + (module-define! m 'short-indent 0)) + (module-remove! m 'line-width)) (define (internal-set-paper-size module name landscape?) (define (swap x) diff --git a/scripts/lilypond-book.py b/scripts/lilypond-book.py index 8223864..f123c93 100644 --- a/scripts/lilypond-book.py +++ b/scripts/lilypond-book.py @@ -1116,6 +1116,15 @@ class LilypondSnippet (Snippet): if not INDENT in self.option_dict: self.option_dict[INDENT] = '0\\mm' + # FIXME: This is really ugly. Every setting should be there only once, + # instead of having several line-width = foo / line-width = blah + # constructs. This would affect also QUOTE / LILYQUOTE, however. + if not LINE_WIDTH in self.option_dict: + if not QUOTE in self.option_dict: + if not LILYQUOTE in self.option_dict: + self.option_dict[LINE_WIDTH] = "#(- paper-width \ +left-margin-default right-margin-default)" + def compose_ly (self, code): if FRAGMENT in self.option_dict: body = FRAGMENT_LY -- 1.6.0.2 _______________________________________________ lilypond-devel mailing list lilypond-devel@... http://lists.gnu.org/mailman/listinfo/lilypond-devel |
|
|
Re: [PATCH] New margin handling - final version (updated)2009/9/22 Michael Käppler <xmichael-k@...>:
> now it's clear to me what happened. > I concatenated the \paper blocks of granados.ly and example-header.ily > together for testing. Because then the fixed line-width from > example-header.ily won't be overwritten by (set-paper-size), it looked as > compressed on master as on my testing branch. I never had that problem since I lazily ran it directly from the source folder. :) I've just finished a regtest check and clean docs build, and as far as I can tell, everything looks fine; there are no warnings reported for any of the A6-size paper tests, and all the snippets I compared are virtually indistinguishable. Regards, Neil _______________________________________________ lilypond-devel mailing list lilypond-devel@... http://lists.gnu.org/mailman/listinfo/lilypond-devel |
| < Prev | 1 - 2 | Next > |
| Free embeddable forum powered by Nabble | Forum Help |