Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(50)

Side by Side Diff: lily/output-def.cc

Issue 109051: Implement new handling for \paper margin settings.
Patch Set: Created 14 years, 7 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 music-output-def.cc -- implement Output_def 2 music-output-def.cc -- implement Output_def
3 3
4 source file of the GNU LilyPond music typesetter 4 source file of the GNU LilyPond music typesetter
5 5
6 (c) 1997--2009 Han-Wen Nienhuys <hanwen@xs4all.nl> 6 (c) 1997--2009 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */ 7 */
8 8
9 #include "output-def.hh" 9 #include "output-def.hh"
10 10
11 #include "context-def.hh" 11 #include "context-def.hh"
12 #include "file-path.hh" 12 #include "file-path.hh"
13 #include "global-context.hh" 13 #include "global-context.hh"
14 #include "international.hh"
14 #include "interval.hh" 15 #include "interval.hh"
15 #include "main.hh" 16 #include "main.hh"
16 #include "output-def.hh" 17 #include "output-def.hh"
17 #include "scm-hash.hh" 18 #include "scm-hash.hh"
18 #include "warn.hh" 19 #include "warn.hh"
19 20
20 #include "ly-smobs.icc" 21 #include "ly-smobs.icc"
21 22
22 #include "program-option.hh" 23 #include "program-option.hh"
23 24
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 { 122 {
122 return lookup_variable (ly_symbol2scm (s.c_str ())); 123 return lookup_variable (ly_symbol2scm (s.c_str ()));
123 } 124 }
124 125
125 void 126 void
126 Output_def::set_variable (SCM sym, SCM val) 127 Output_def::set_variable (SCM sym, SCM val)
127 { 128 {
128 scm_module_define (scope_, sym, val); 129 scm_module_define (scope_, sym, val);
129 } 130 }
130 131
131 ·· 132 void
133 Output_def::normalize ()
134 {
135 Real paper_width;
136 SCM scm_paper_width = c_variable ("paper-width");
137 ·
138 Real left_margin, left_margin_default;
139 SCM scm_left_margin_default = c_variable ("left-margin-default");
140 SCM scm_left_margin = c_variable ("left-margin");
141
142 Real right_margin, right_margin_default;
143 SCM scm_right_margin_default = c_variable ("right-margin-default");
144 SCM scm_right_margin = c_variable ("right-margin");
145
146 if (scm_paper_width != SCM_UNDEFINED·
Carl 2009/08/20 12:54:08 I'd prefer to see this and all of your checks for
Neil Puttock 2009/08/21 00:04:22 How about using scm_is_number () instead?
147 && scm_left_margin_default != SCM_UNDEFINED·
148 && scm_right_margin_default != SCM_UNDEFINED)·
149 {
150 paper_width = scm_to_double (scm_paper_width);
151 left_margin_default = scm_to_double (scm_left_margin_default);
152 right_margin_default = scm_to_double (scm_right_margin_default);·
153 }·
154 else
155 {
156 programming_error (_ ("called normalize() on paper with missing settings") );
Neil Puttock 2009/08/21 00:04:22 space after normalize programming errors aren't l
157 return;
158 }
159
160 Real line_width;
161 Real line_width_default = paper_width - left_margin_default - right_margin_def ault;
162 SCM scm_line_width = c_variable ("line-width");
163
164 if (scm_line_width != SCM_UNDEFINED)
165 {
166 line_width = scm_to_double (scm_line_width);
167 if (scm_left_margin != SCM_UNDEFINED)
168 {·
169 left_margin = scm_to_double (scm_left_margin);
170 right_margin = ((scm_right_margin != SCM_UNDEFINED)·
171 ? scm_to_double(scm_right_margin)·
Neil Puttock 2009/08/21 00:04:22 space after scm_to_double
172 : (paper_width - line_width - left_margin));
173 }
174 else if (scm_right_margin != SCM_UNDEFINED)·
175 {
176 right_margin = scm_to_double (scm_right_margin);
177 left_margin = paper_width - line_width - right_margin;·
178 }
179 else // Vertically center systems if only line-width is given.
180 {
181 left_margin = (paper_width - line_width) / 2;
182 right_margin = left_margin;
183 }
184 }
185 else
186 {
187 left_margin = ((scm_left_margin != SCM_UNDEFINED) ? scm_to_double(scm_left _margin) : left_margin_default);
188 right_margin = ((scm_right_margin != SCM_UNDEFINED) ? scm_to_double(scm_ri ght_margin) : right_margin_default);
189 line_width = paper_width - left_margin - right_margin;
190 }
191 ·
192 if (c_variable ("check-consistency") == SCM_BOOL_T)
Neil Puttock 2009/08/21 00:04:22 could use to_boolean here if (to_boolean (c_varia
193 {
194 // Consistency checks. If values don't match, set defaults.
195 if (abs(paper_width - line_width - left_margin - right_margin) > 1e-6)·
196 {
197 line_width = line_width_default;
198 left_margin = left_margin_default;
199 right_margin = right_margin_default;
200 warning (_ ("margins don't fit with line-width, setting default values "));··········
Neil Puttock 2009/08/21 00:04:22 don't -> do not
201 }·
202 else if ((left_margin < 0) || (right_margin < 0))
203 {
204 line_width = line_width_default;
205 left_margin = left_margin_default;
206 right_margin = right_margin_default;
207 warning (_ ("systems run off the page due to improper paper settings, setting default values"));
208 }
209 }
210
211 set_variable (ly_symbol2scm ("left-margin"), scm_from_double(left_margin));
Neil Puttock 2009/08/21 00:04:22 space after scm_from_double (same for following l
212 set_variable (ly_symbol2scm ("right-margin"), scm_from_double(right_margin));
213 set_variable (ly_symbol2scm ("line-width"), scm_from_double(line_width));
214 }
215 ·
132 /* FIXME. This is broken until we have a generic way of 216 /* FIXME. This is broken until we have a generic way of
133 putting lists inside the \layout block. */ 217 putting lists inside the \layout block. */
134 Interval 218 Interval
135 line_dimensions_int (Output_def *def, int n) 219 line_dimensions_int (Output_def *def, int n)
136 { 220 {
137 Real lw = def->get_dimension (ly_symbol2scm ("line-width")); 221 Real lw = def->get_dimension (ly_symbol2scm ("line-width"));
138 Real ind = n 222 Real ind = n
139 ? def->get_dimension (ly_symbol2scm ("short-indent")) 223 ? def->get_dimension (ly_symbol2scm ("short-indent"))
140 : def->get_dimension (ly_symbol2scm ("indent")); 224 : def->get_dimension (ly_symbol2scm ("indent"));
141 return Interval (ind, lw); 225 return Interval (ind, lw);
142 } 226 }
143 227
144 228
OLDNEW
« no previous file with comments | « lily/include/output-def.hh ('k') | lily/paper-book.cc » ('j') | ly/paper-defaults-init.ly » ('J')

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b