From: Han-Wen Nienhuys Date: Sun, 16 May 2004 22:46:36 +0000 (+0000) Subject: (ly_bookpaper_fonts): move from Paperdef X-Git-Tag: release/2.3.2~16 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=853303f6ec72641e842d58e68bc304c5afffcd13;p=lilypond.git (ly_bookpaper_fonts): move from Paperdef (find_scaled_font): move from Paper_def --- diff --git a/ChangeLog b/ChangeLog index ca8d5171b3..b19dacdc71 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,20 @@ +2004-05-17 Han-Wen Nienhuys + + + * lily/book-paper-def.cc (ly_bookpaper_fonts): move from Paperdef + (find_scaled_font): move from Paper_def + +2004-05-16 Han-Wen Nienhuys + + * lily/my-lily-parser.cc (LY_DEFINE): new function ly_parser_lookup + (LY_DEFINE): add SCM_ASSERT_TYPE everywhere. + + * po/fr.po: update po. + + * lily/include/book-paper-def.hh (class Book_paper_def): new file. + + * lily/book-paper-def.cc (print_smob): new file. + 2004-05-16 Heikki Junes * buildscripts/lilypond-words.py: search words also from diff --git a/lily/book-paper-def.cc b/lily/book-paper-def.cc new file mode 100644 index 0000000000..e79b158c4e --- /dev/null +++ b/lily/book-paper-def.cc @@ -0,0 +1,196 @@ +/* + book-paper-def.cc -- implement Book_paper_def + + source file of the GNU LilyPond music typesetter + + (c) 2004 Han-Wen Nienhuys + +*/ + +#include "paper-def.hh" +#include "dimensions.hh" +#include "book-paper-def.hh" +#include "ly-smobs.icc" +#include "font-metric.hh" +#include "virtual-font-metric.hh" +#include "scaled-font-metric.hh" + +IMPLEMENT_SMOBS (Book_paper_def); +IMPLEMENT_DEFAULT_EQUAL_P (Book_paper_def); + + +SCM +Book_paper_def::mark_smob (SCM m) +{ + Book_paper_def * mo = (Book_paper_def*) SCM_CELL_WORD_1 (m); + + return mo->scaled_fonts_; +} + +Font_metric* +Book_paper_def::find_scaled_font (Font_metric *f, Real m, SCM input_enc_name) +{ + Real lookup_mag = m; + if (!dynamic_cast (f)) + { + lookup_mag /= output_scale_; + } + + SCM sizes = scm_hashq_ref (scaled_fonts_, f->self_scm (), SCM_BOOL_F); + if (sizes != SCM_BOOL_F) + { + SCM met = scm_assoc (scm_make_real (lookup_mag), sizes); + if (ly_c_pair_p (met)) + return unsmob_metrics (ly_cdr (met)); + } + else + sizes = SCM_EOL; + + /* Hmm. We're chaining font - metrics. Should consider whether to + merge virtual-font and scaled_font. */ + SCM val = SCM_EOL; + if (Virtual_font_metric * vf = dynamic_cast (f)) + { + /* + For fontify_atom (), the magnification and name must be known + at the same time. That's impossible for + + Scaled (Virtual_font (Font1,Font2)) + + so we replace by + + Virtual_font (Scaled (Font1), Scaled (Font2)) + + */ + + SCM lst = SCM_EOL; + SCM *t = &lst; + for (SCM s = vf->get_font_list (); ly_c_pair_p (s); s = ly_cdr (s)) + { + Font_metric *scaled = find_scaled_font (unsmob_metrics (ly_car (s)), + m, input_enc_name); + *t = scm_cons (scaled->self_scm (), SCM_EOL); + t = SCM_CDRLOC(*t); + } + + vf = new Virtual_font_metric (lst); + val = vf->self_scm (); + } + else + { + if (!ly_c_symbol_p (input_enc_name)) + { +#if 0 + /* FIXME.*/ + SCM var = ly_module_lookup (scope_, ly_symbol2scm ("inputencoding")); + input_enc_name = scm_variable_ref (var); + +#endif + input_enc_name = ly_symbol2scm ("latin1"); + } + + val = Modified_font_metric::make_scaled_font_metric (input_enc_name, + f, lookup_mag); + } + + sizes = scm_acons (scm_make_real (lookup_mag), val, sizes); + scm_gc_unprotect_object (val); + scm_hashq_set_x (scaled_fonts_, f->self_scm (), sizes); + return unsmob_metrics (val); +} + + + +Book_paper_def::Book_paper_def () +{ + output_scale_ = 1.0; + scaled_fonts_ = SCM_EOL; + smobify_self (); + scaled_fonts_ = scm_c_make_hash_table (11); +} + +Book_paper_def::~Book_paper_def () +{ +} + + + + +LY_DEFINE(ly_make_bookpaper, "ly:make-bookpaper", + 1,0,0, + (SCM size), + "Make a paperbook, for staff space SIZE, which is in INTERNAL_UNIT.") +{ + Book_paper_def * bp = new Book_paper_def ; + + SCM_ASSERT_TYPE(ly_c_number_p (size), size, + SCM_ARG1, __FUNCTION__, "number"); + + + bp->output_scale_ = (ly_scm2double (size)) MM; + + return scm_gc_unprotect_object (bp->self_scm ()); +} + + +LY_DEFINE(ly_bookpaper_fonts, "ly:bookpaper-fonts", + 1,0,0, + (SCM bp), + "Return fonts scaled up BP") +{ + Book_paper_def * b = unsmob_bookpaper (bp); + + SCM_ASSERT_TYPE(b, bp, + SCM_ARG1, __FUNCTION__, "bookpaper"); + + SCM func = ly_scheme_function ("hash-table->alist"); + + SCM l = SCM_EOL; + for (SCM s = scm_call_1 (func, b->scaled_fonts_); ly_c_pair_p (s); s = ly_cdr (s)) + { + SCM entry = ly_car (s); + for (SCM t = ly_cdr (entry); ly_c_pair_p (t); t = ly_cdr (t)) + { + Font_metric *fm= unsmob_metrics (ly_cdar (t)); + + if (dynamic_cast (fm)) + l = scm_cons (fm->self_scm (), l); + } + } + return l; +} + + +LY_DEFINE(ly_bookpaper_outputscale, "ly:bookpaper-outputscale", + 1,0,0, + (SCM bp), + "Get outputscale for BP.") +{ + Book_paper_def * b = unsmob_bookpaper (bp); + + SCM_ASSERT_TYPE(b, bp, + SCM_ARG1, __FUNCTION__, "bookpaper"); + return scm_make_real (b->output_scale_); +} + +int +Book_paper_def::print_smob (SCM s, SCM p, scm_print_state*) +{ + scm_puts ("#", p); + return 1; +} + + +Paper_def * +Book_paper_def::scale_paper (Paper_def* pd) const +{ + SCM proc = ly_scheme_function ("scale-paper"); + SCM new_pap = scm_call_2 (proc, pd->self_scm (), self_scm ()); + + scm_gc_protect_object (new_pap); + + Paper_def* p = unsmob_paper (new_pap); + + p->bookpaper_ = (Book_paper_def*) this; + return p; +} diff --git a/lily/book.cc b/lily/book.cc index cf64b17455..4e804b7d52 100644 --- a/lily/book.cc +++ b/lily/book.cc @@ -8,6 +8,7 @@ #include +#include "book-paper-def.hh" #include "ly-smobs.icc" #include "stencil.hh" #include "book.hh" @@ -27,6 +28,7 @@ Book::Book () : Input () { + bookpaper_ = 0; header_ = SCM_EOL; assert (!scores_.size ()); smobify_self (); @@ -46,6 +48,9 @@ Book::mark_smob (SCM s) int score_count = book->scores_.size (); for (int i = 0; i < score_count; i++) scm_gc_mark (book->scores_[i]->self_scm ()); + + if (book->bookpaper_) + scm_gc_mark (book->bookpaper_->self_scm ()); return book->header_; } @@ -64,13 +69,15 @@ Book::process (String outname, Music_output_def *default_def, SCM header) for (int i = 0; i < score_count; i++) { Paper_def *paper = 0; - SCM systems = scores_[i]->book_rendering (outname, default_def, &paper); + SCM systems = scores_[i]->book_rendering (outname, + bookpaper_, + default_def, &paper); if (systems != SCM_UNDEFINED) { Score_lines sc; sc.paper_ = paper; sc.lines_ = systems; - sc.header_ =header; + sc.header_ = header; paper_book->score_lines_.push (sc); } @@ -88,7 +95,9 @@ Book::to_stencil (Music_output_def *default_def, SCM header) for (int i = 0; i < score_count; i++) { Paper_def *paper = 0; - SCM systems = scores_[i]->book_rendering ("", default_def, + SCM systems = scores_[i]->book_rendering ("", + bookpaper_, + default_def, &paper); if (systems != SCM_UNDEFINED) { diff --git a/lily/font-select.cc b/lily/font-select.cc index 3fa108f064..df98d77cee 100644 --- a/lily/font-select.cc +++ b/lily/font-select.cc @@ -9,6 +9,7 @@ #include +#include "book-paper-def.hh" #include "all-font-metrics.hh" #include "paper-def.hh" #include "font-interface.hh" @@ -83,7 +84,8 @@ get_font_by_design_size (Paper_def* paper, Real requested, } Font_metric *fm = unsmob_metrics (scm_force (SCM_VECTOR_REF (font_vector, i))); - return paper->find_scaled_font (fm, requested / size, input_encoding_name); + return paper->bookpaper_->find_scaled_font (fm, requested / size, input_encoding_name); + } @@ -127,7 +129,7 @@ select_encoded_font (Paper_def *paper, SCM chain, SCM encoding_name) Font_metric * fm = all_fonts_global->find_font (ly_scm2string (name)); - return paper->find_scaled_font (fm, rmag, encoding_name); + return paper->bookpaper_->find_scaled_font (fm, rmag, encoding_name); } else if (scm_instance_p (name)) { @@ -148,8 +150,6 @@ select_encoded_font (Paper_def *paper, SCM chain, SCM encoding_name) return 0; } - - Font_metric * select_font (Paper_def *paper, SCM chain) { diff --git a/lily/include/book.hh b/lily/include/book.hh index 7e65d51b21..67ff4dfa54 100644 --- a/lily/include/book.hh +++ b/lily/include/book.hh @@ -20,8 +20,9 @@ class Book : public Input public: SCM header_; + Book_paper_def *bookpaper_; + Link_array scores_; - Book (); void process (String outname, Music_output_def*, SCM header); diff --git a/lily/include/dimensions.hh b/lily/include/dimensions.hh index c5f54a17e7..a72361a6f4 100644 --- a/lily/include/dimensions.hh +++ b/lily/include/dimensions.hh @@ -36,6 +36,7 @@ const Real PT_TO_MM = (1.0/MM_TO_PT); #define CHAR *CHAR_TO_PT *PT_TO_MM #define INTERNAL_UNIT "mm" + #endif String print_dimen (Real); diff --git a/lily/include/lily-proto.hh b/lily/include/lily-proto.hh index 0e1dc356c1..f74f32d978 100644 --- a/lily/include/lily-proto.hh +++ b/lily/include/lily-proto.hh @@ -37,6 +37,7 @@ class Beaming_info_list; class Bezier; class Bezier_bow; class Book; +class Book_paper_def; class Break_algorithm; class Change_iterator; class Change_translator; diff --git a/lily/include/paper-def.hh b/lily/include/paper-def.hh index 466fa59b3a..f5ea1cacb4 100644 --- a/lily/include/paper-def.hh +++ b/lily/include/paper-def.hh @@ -47,9 +47,9 @@ class Paper_def : public Music_output_def { protected: VIRTUAL_COPY_CONSTRUCTOR (Music_output_def, Paper_def); - SCM scaled_fonts_; -public: +public: + Book_paper_def * bookpaper_; static int score_count_; Paper_def (); diff --git a/lily/include/paper-outputter.hh b/lily/include/paper-outputter.hh index 7cf2a75e5d..bbd67d495b 100644 --- a/lily/include/paper-outputter.hh +++ b/lily/include/paper-outputter.hh @@ -30,10 +30,9 @@ class Paper_outputter SCM output_module_; Protected_scm file_; String filename_; - Paper_def * paper_ ; // THIS IS BROKEN. void output_expr (SCM expr, Offset o); - void output_metadata (Paper_def*, SCM); + void output_metadata (Book_paper_def*, SCM); void output_music_output_def (Music_output_def* odef); public: @@ -43,7 +42,7 @@ public: void dump_scheme (SCM); void output_scheme (SCM scm); void output_stencil (Stencil); - void output_header (Paper_def*, SCM, int, bool); + void output_header (Book_paper_def*, SCM, int, bool); void output_line (SCM, Offset*, bool); void output_page (Page*, bool); }; diff --git a/lily/include/score.hh b/lily/include/score.hh index 2c9858948e..ca25c3d0f9 100644 --- a/lily/include/score.hh +++ b/lily/include/score.hh @@ -27,12 +27,13 @@ public: Score (); Score (Score const&); - SCM book_rendering (String, Music_output_def*, Paper_def**); + SCM book_rendering (String, Book_paper_def*, Music_output_def*, Paper_def**); }; + DECLARE_UNSMOB (Score, score); SCM ly_run_translator (SCM, SCM); SCM ly_render_output (SCM, SCM); -void default_rendering (SCM, SCM, SCM, SCM); +void default_rendering (SCM, SCM, SCM, SCM, SCM); #endif /* SCORE_HH */ diff --git a/lily/modified-font-metric.cc b/lily/modified-font-metric.cc new file mode 100644 index 0000000000..0210c86c55 --- /dev/null +++ b/lily/modified-font-metric.cc @@ -0,0 +1,303 @@ +/* + scaled-font-metric.cc -- declare Modified_font_metric + + source file of the GNU LilyPond music typesetter + + (c) 1999--2004 Han-Wen Nienhuys + + */ + +#include + +#include "warn.hh" +#include "scaled-font-metric.hh" +#include "string.hh" +#include "stencil.hh" + +Modified_font_metric::Modified_font_metric (String coding, Font_metric* m, Real magn) +{ + coding_vector_ = SCM_EOL; + coding_mapping_ = SCM_EOL; + coding_table_ = SCM_EOL; + coding_description_ = SCM_EOL; + + coding_scheme_ = coding; + magnification_ = magn; + + SCM desc = m->description_; + + Real total_mag = magn * ly_scm2double (ly_cdr (desc)); + assert (total_mag); + + description_ = scm_cons (ly_car (desc), scm_make_real (total_mag)); + orig_ = m; + + if (coding_scheme_ != "TeX" + && coding_scheme_ != "ASCII" + && coding_scheme_ != orig_->coding_scheme ()) + { + coding_vector_ = scm_call_1 (ly_scheme_function ("get-coding-vector"), + scm_makfrom0str (coding_scheme_.to_str0 ())); + + if (!ly_c_vector_p (coding_vector_)) + { + programming_error ("get-coding-vector should return vector"); + coding_vector_ = scm_c_make_vector (256, ly_symbol2scm (".notdef")); + } + + + coding_table_ = scm_call_1 (ly_scheme_function ("get-coding-table"), + scm_makfrom0str (orig_->coding_scheme ().to_str0 ())); + + coding_mapping_ = scm_call_2 (ly_scheme_function ("make-encoding-mapping"), + coding_vector_, + coding_table_); + + coding_description_= SCM_EOL; + + coding_description_ = scm_acons (ly_symbol2scm ("input-name"), + scm_makfrom0str (coding_scheme_.to_str0 ()), + coding_description_); + + coding_description_ = scm_acons (ly_symbol2scm ("input-vector"), + coding_vector_, coding_description_); + coding_description_ = scm_acons (ly_symbol2scm ("output-name"), + scm_makfrom0str (orig_->coding_scheme ().to_str0 ()), + coding_description_); + coding_description_ = scm_acons (ly_symbol2scm ("output-table"), + coding_table_, + coding_description_); + + coding_description_ = scm_acons (ly_symbol2scm ("char-mapping"), + coding_mapping_, + coding_description_); + } +} + + + +LY_DEFINE (ly_font_encoding_alist, "ly:font-encoding-alist", + 1, 0, 0, + (SCM font), + "Given the Modified_font_metric @var{font}, return an " + "alist. Keys are input-name, input-vector, " + "output-name, output-table, mapping.") +{ + Modified_font_metric *fm + = dynamic_cast (unsmob_metrics (font)); + + SCM_ASSERT_TYPE (fm, font, SCM_ARG1, __FUNCTION__, "Modified_font_metric"); + return fm->coding_description_; +} + +SCM +Modified_font_metric::make_scaled_font_metric (SCM coding, Font_metric *m, Real s) +{ + /* + UGOHR. + */ + if (ly_c_symbol_p (coding)) + coding = scm_symbol_to_string (coding); + + String scheme = ly_scm2string (coding); + + Modified_font_metric *sfm = new Modified_font_metric (scheme, m, s); + + return sfm->self_scm (); +} + +Real +Modified_font_metric::design_size () const +{ + return orig_->design_size (); +} + + +Box +Modified_font_metric::get_indexed_char (int i) const +{ + Box b = orig_->get_indexed_char (i); + b.scale (magnification_); + return b; +} + +Box +Modified_font_metric::get_ascii_char (int i) const +{ + Box b = orig_->get_ascii_char (i); + b.scale (magnification_); + return b; +} + +int +Modified_font_metric::count () const +{ + return orig_->count (); +} + +Offset +Modified_font_metric::get_indexed_wxwy (int k) const +{ + Offset o = orig_->get_indexed_wxwy (k); + return o * magnification_; +} + +int +Modified_font_metric::name_to_index (String s) const +{ + return orig_->name_to_index (s); +} + +int +Modified_font_metric::index_to_ascii (int k) const +{ + return orig_->index_to_ascii (k); +} + +String +Modified_font_metric::coding_scheme () const +{ + return coding_scheme_; +} + +void +Modified_font_metric::derived_mark () const +{ + scm_gc_mark (coding_vector_); + scm_gc_mark (coding_description_); + scm_gc_mark (coding_table_); + scm_gc_mark (coding_mapping_); +} + +Box +Modified_font_metric::tex_kludge (String text) const +{ + Interval ydims; + Real w=0.0; + + /* + TODO: put this klutchness behind ly:option switch. + */ + for (int i = 0; i < text.length (); i++) + { + switch (text[i]) + { + case '\\': + // accent marks use width of base letter + if (i +1 < text.length ()) + { + if (text[i+1]=='\'' || text[i+1]=='`' || text[i+1]=='"' || + text[i+1]=='^') + { + i++; + break; + } + // for string width \\ is a \ and \_ is a _. + if (text[i+1]=='\\' || text[i+1]=='_') + { + break; + } + } + + for (i++; (i < text.length ()) && !isspace (text[i]) + && text[i]!='{' && text[i]!='}'; i++) + ; + + // ugh. + i--; // Compensate for the increment in the outer loop! + break; + case '{': // Skip '{' and '}' + case '}': + break; + + default: + Box b = get_ascii_char ((unsigned char)text[i]); + + // Ugh, use the width of 'x' for unknown characters + if (b[X_AXIS].length () == 0) + b = get_ascii_char ((unsigned char)'x'); + + w += b[X_AXIS].length (); + ydims.unite (b[Y_AXIS]); + break; + } + } + + if (ydims.is_empty ()) + ydims = Interval (0, 0); + + return Box (Interval (0, w), ydims); +} + +Box +Modified_font_metric::text_dimension (String text) +{ + Box b; + if (coding_scheme_ == "TeX") + { + b = tex_kludge (text); + } + else if (coding_scheme_ == "ASCII" + || coding_scheme_ == orig_->coding_scheme ()) + { + Interval ydims; + + Real w=0.0; + + for (int i = 0; i < text.length (); i++) + { + Box b = get_ascii_char ((unsigned char)text[i]); + + w += b[X_AXIS].length (); + ydims.unite (b[Y_AXIS]); + } + if (ydims.is_empty ()) + ydims = Interval (0, 0); + + b = Box(Interval(0,w), ydims); + } + else + { + Interval ydims; + Real w = 0.0; + + for (int i = 0; i < text.length (); i++) + { + SCM sym = scm_vector_ref (coding_vector_, + SCM_MAKINUM((unsigned char) text[i])); + + Box char_box; + + if (!ly_c_symbol_p (sym)) + continue; + + char const * chars = SCM_SYMBOL_CHARS(sym); + + int idx = orig_->name_to_index (chars); + if (idx >= 0) + { + char_box = orig_->get_indexed_char (idx); + } + + char_box.scale (magnification_); + if (!char_box[X_AXIS].is_empty ()) + w += char_box[X_AXIS][RIGHT]; // length ? + + ydims.unite (char_box[Y_AXIS]); + } + + if (ydims.is_empty ()) + ydims = Interval (0, 0); + + + b = Box (Interval (0, w), ydims); + } + + return b; +} + +Font_metric* +Modified_font_metric::original_font () const +{ + return orig_; +} diff --git a/lily/my-lily-parser.cc b/lily/my-lily-parser.cc index 0d6aeb34bc..1680f3de4c 100644 --- a/lily/my-lily-parser.cc +++ b/lily/my-lily-parser.cc @@ -8,6 +8,7 @@ */ #include "book.hh" +#include "book-paper-def.hh" #include "file-name.hh" #include "file-path.hh" #include "lily-version.hh" @@ -325,11 +326,30 @@ LY_DEFINE(ly_parser_define, "ly:parser-define", (SCM parser_smob, SCM symbol, SCM val), "Bind SYMBOL to VAL in PARSER_SMOB's module.") { - SCM_ASSERT_TYPE (ly_c_symbol_p (symbol), symbol, SCM_ARG1, __FUNCTION__, "symbol"); My_lily_parser *parser = unsmob_my_lily_parser (parser_smob); + SCM_ASSERT_TYPE (ly_c_symbol_p (symbol), symbol, SCM_ARG2, __FUNCTION__, "symbol"); + SCM_ASSERT_TYPE (parser, parser_smob, SCM_ARG2, __FUNCTION__, "parser"); + + parser->lexer_->set_identifier (scm_symbol_to_string (symbol), val); return SCM_UNSPECIFIED; } +LY_DEFINE(ly_parser_lookup, "ly:parser-lookup", + 2, 0, 0, + (SCM parser_smob, SCM symbol), + "Lookup @var{symbol} in @var{parser_smob}'s module. Undefined is '().") +{ + My_lily_parser *parser = unsmob_my_lily_parser (parser_smob); + + SCM_ASSERT_TYPE (ly_c_symbol_p (symbol), symbol, SCM_ARG2, __FUNCTION__, "symbol"); + SCM_ASSERT_TYPE (parser, parser_smob, SCM_ARG2, __FUNCTION__, "parser"); + + SCM val= parser->lexer_->lookup_identifier (ly_scm2string (scm_symbol_to_string (symbol))); + if (val != SCM_UNDEFINED) + return val; + else + return SCM_EOL; +} LY_DEFINE (ly_parser_parse_string, "ly:parser-parse-string", 2, 0, 0, @@ -337,20 +357,13 @@ LY_DEFINE (ly_parser_parse_string, "ly:parser-parse-string", "Parse the string LY_CODE with PARSER_SMOB." "Upon failure, throw @code{ly-file-failed} key.") { -#if 0 - SCM_ASSERT_TYPE (ly_c_parser_p (parser), music, SCM_ARG1, __FUNCTION__, "parser"); -#endif - SCM_ASSERT_TYPE (ly_c_string_p (ly_code), ly_code, SCM_ARG1, __FUNCTION__, "string"); -#if 1 My_lily_parser *parser = unsmob_my_lily_parser (parser_smob); + + SCM_ASSERT_TYPE (parser, parser_smob, SCM_ARG1, __FUNCTION__, "parser"); + SCM_ASSERT_TYPE (ly_c_string_p (ly_code), ly_code, SCM_ARG2, __FUNCTION__, "string"); + parser->parse_string (ly_scm2string (ly_code)); -#else - My_lily_parser *parser = unsmob_my_lily_parser (parser_smob); - My_lily_parser *clone = new My_lily_parser (*parser); - clone->parse_string (ly_scm2string (ly_code)); - clone = 0; -#endif return SCM_UNSPECIFIED; } @@ -363,18 +376,31 @@ get_paper (My_lily_parser *parser) return paper ? paper->clone () : new Paper_def; } + +Book_paper_def* +get_bookpaper (My_lily_parser *parser) +{ + SCM id = parser->lexer_->lookup_identifier ("$defaultbookpaper"); + Book_paper_def *paper = unsmob_bookpaper (id); + return paper->clone (); +} + + +/* + TODO: move this to Scheme? Why take the parser arg, and all the back + & forth between scm and c++? + */ LY_DEFINE (ly_parser_print_score, "ly:parser-print-score", 2, 0, 0, (SCM parser_smob, SCM score_smob), "Print score, i.e., the classic way.") { -#if 0 - SCM_ASSERT_TYPE (ly_c_parser_p (parser), music, SCM_ARG1, __FUNCTION__, "parser"); - SCM_ASSERT_TYPE (ly_c_music_p (music), music, SCM_ARG1, __FUNCTION__, "music"); -#endif My_lily_parser *parser = unsmob_my_lily_parser (parser_smob); Score *score = unsmob_score (score_smob); + SCM_ASSERT_TYPE (parser, parser_smob, SCM_ARG1, __FUNCTION__, "parser"); + SCM_ASSERT_TYPE (score, score_smob, SCM_ARG2, __FUNCTION__, "score"); + SCM header = is_module (score->header_) ? score->header_ : parser->header_.to_SCM (); @@ -386,13 +412,16 @@ LY_DEFINE (ly_parser_print_score, "ly:parser-print-score", SCM os = scm_makfrom0str (outname.to_string ().to_str0 ()); for (int i = 0; i < score->defs_.size (); i++) - default_rendering (score->music_, score->defs_[i]->self_scm (), header, - os); + default_rendering (score->music_, score->defs_[i]->self_scm (), + get_bookpaper (parser)->self_scm (), + header, os); if (score->defs_.is_empty ()) { Music_output_def *paper = get_paper (parser); - default_rendering (score->music_, paper->self_scm (), header, os); + default_rendering (score->music_, paper->self_scm (), + get_bookpaper (parser)->self_scm (), + header, os); scm_gc_unprotect_object (paper->self_scm ()); } return SCM_UNDEFINED; @@ -403,12 +432,14 @@ LY_DEFINE (ly_parser_print_book, "ly:parser-print-book", (SCM parser_smob, SCM book_smob), "Print book.") { -#if 0 - SCM_ASSERT_TYPE (ly_c_parser_p (parser_smob), parser_smob, SCM_ARG1, __FUNCTION__, "parser_smob"); - SCM_ASSERT_TYPE (ly_c_music_p (book_smob), book_smob, SCM_ARG1, __FUNCTION__, "book_smob"); -#endif My_lily_parser *parser = unsmob_my_lily_parser (parser_smob); Book *book = unsmob_book (book_smob); + Book_paper_def *bp = unsmob_bookpaper (parser->lexer_->lookup_identifier ("$defaultbookpaper")); + + SCM_ASSERT_TYPE (parser, parser_smob, SCM_ARG1, __FUNCTION__, "Lilypond parser"); + SCM_ASSERT_TYPE (book, book_smob, SCM_ARG2, __FUNCTION__, "Book"); + + book->bookpaper_ = bp; // ugh. changing argument. SCM header = parser->header_; File_name outname (parser->output_basename_); diff --git a/lily/paper-book.cc b/lily/paper-book.cc index 048295b0a4..8fbc9fbd2d 100644 --- a/lily/paper-book.cc +++ b/lily/paper-book.cc @@ -89,7 +89,7 @@ Paper_book::output (String outname) Paper_def *paper = score_lines_[0].paper_; Paper_outputter *out = paper->get_paper_outputter (outname); int page_count = scm_ilength (pages); - out->output_header (paper, scopes (0), page_count, false); + out->output_header (paper->bookpaper_, scopes (0), page_count, false); for (SCM s = pages; s != SCM_EOL; s = ly_cdr (s)) { @@ -145,7 +145,7 @@ Paper_book::classic_output (String outname) int count = score_lines_.size (); Paper_def * p = score_lines_.top ().paper_; Paper_outputter *out = p->get_paper_outputter (outname); - out->output_header (p, scopes (count - 1), 0, true); + out->output_header (p->bookpaper_, scopes (count - 1), 0, true); SCM top_lines = score_lines_.top ().lines_; Paper_line *first = unsmob_paper_line (scm_vector_ref (top_lines, diff --git a/lily/paper-def.cc b/lily/paper-def.cc index b1b3a6d6e5..85cb00b73e 100644 --- a/lily/paper-def.cc +++ b/lily/paper-def.cc @@ -9,6 +9,7 @@ #include +#include "book-paper-def.hh" #include "virtual-font-metric.hh" #include "all-font-metrics.hh" #include "string.hh" @@ -29,17 +30,14 @@ Paper_def::Paper_def () { - /* Do not remove this statement, scm_make_hash_table may trigger GC. */ - scaled_fonts_ = SCM_EOL; - scaled_fonts_ = scm_c_make_hash_table (11); + bookpaper_ = 0; } Paper_def::Paper_def (Paper_def const&src) : Music_output_def (src) { /* Do not remove this statement, scm_make_hash_table may trigger GC. */ - scaled_fonts_ = SCM_EOL; - scaled_fonts_ = scm_c_make_hash_table (11); + bookpaper_ = 0; } Paper_def::~Paper_def () @@ -49,17 +47,15 @@ Paper_def::~Paper_def () void Paper_def::derived_mark () { - scm_gc_mark (scaled_fonts_); + if (bookpaper_) + scm_gc_mark (bookpaper_->self_scm ()); } Real Paper_def::get_dimension (SCM s) const { SCM val = lookup_variable (s); - SCM scale = lookup_variable (ly_symbol2scm ("outputscale")); - - Real sc = ly_scm2double (scale); - return ly_scm2double (val) / sc; + return ly_scm2double (val); } /* FIXME. This is broken until we have a generic way of @@ -79,98 +75,7 @@ Paper_def::get_paper_outputter (String outname) const progress_indication (_f ("paper output to `%s'...", outname == "-" ? String ("") : outname)); return new Paper_outputter (outname); -} - -Font_metric* -Paper_def::find_scaled_font (Font_metric *f, Real m, SCM input_enc_name) -{ - SCM scale_var = SCM_EOL; - Real lookup_mag = m; - if (!dynamic_cast (f)) - { - scale_var = ly_module_lookup (scope_, ly_symbol2scm ("outputscale")); - lookup_mag /= ly_scm2double (scm_variable_ref (scale_var)); - } - - SCM sizes = scm_hashq_ref (scaled_fonts_, f->self_scm (), SCM_BOOL_F); - if (sizes != SCM_BOOL_F) - { - SCM met = scm_assoc (scm_make_real (lookup_mag), sizes); - if (ly_c_pair_p (met)) - return unsmob_metrics (ly_cdr (met)); - } - else - sizes = SCM_EOL; - - /* Hmm. We're chaining font - metrics. Should consider whether to - merge virtual-font and scaled_font. */ - SCM val = SCM_EOL; - if (Virtual_font_metric * vf = dynamic_cast (f)) - { - /* - For fontify_atom (), the magnification and name must be known - at the same time. That's impossible for - - Scaled (Virtual_font (Font1,Font2)) - - so we replace by - - Virtual_font (Scaled (Font1), Scaled (Font2)) - - */ - - SCM lst = SCM_EOL; - SCM *t = &lst; - for (SCM s = vf->get_font_list (); ly_c_pair_p (s); s = ly_cdr (s)) - { - Font_metric *scaled = find_scaled_font (unsmob_metrics (ly_car (s)), - m, input_enc_name); - *t = scm_cons (scaled->self_scm (), SCM_EOL); - t = SCM_CDRLOC(*t); - } - - vf = new Virtual_font_metric (lst); - val = vf->self_scm (); - } - else - { - - if (!ly_c_symbol_p (input_enc_name)) - { - SCM var = ly_module_lookup (scope_, ly_symbol2scm ("inputencoding")); - input_enc_name = scm_variable_ref (var); - } - val = Modified_font_metric::make_scaled_font_metric (input_enc_name, - f, lookup_mag); - } - - sizes = scm_acons (scm_make_real (lookup_mag), val, sizes); - scm_gc_unprotect_object (val); - scm_hashq_set_x (scaled_fonts_, f->self_scm (), sizes); - return unsmob_metrics (val); -} - -/* Return alist to translate internally used fonts back to real-world - coordinates. */ -SCM -Paper_def::font_descriptions () const -{ - SCM func = ly_scheme_function ("hash-table->alist"); - - SCM l = SCM_EOL; - for (SCM s = scm_call_1 (func, scaled_fonts_); ly_c_pair_p (s); s = ly_cdr (s)) - { - SCM entry = ly_car (s); - for (SCM t = ly_cdr (entry); ly_c_pair_p (t); t = ly_cdr (t)) - { - Font_metric *fm= unsmob_metrics (ly_cdar (t)); - - if (dynamic_cast (fm)) - l = scm_cons (fm->self_scm (), l); - } - } - return l; } Paper_def* diff --git a/lily/paper-outputter.cc b/lily/paper-outputter.cc index 49351e11d3..318784259e 100644 --- a/lily/paper-outputter.cc +++ b/lily/paper-outputter.cc @@ -10,6 +10,7 @@ #include #include +#include "book-paper-def.hh" #include "array.hh" #include "dimensions.hh" #include "font-metric.hh" @@ -35,7 +36,6 @@ extern SCM stencil2line (Stencil* stil, bool is_title = false); Paper_outputter::Paper_outputter (String filename) { filename_ = filename; - paper_ = 0; file_ = scm_open_file (scm_makfrom0str (filename.to_str0 ()), scm_makfrom0str ("w")); @@ -56,7 +56,7 @@ Paper_outputter::output_scheme (SCM scm) } void -Paper_outputter::output_metadata (Paper_def *paper, SCM scopes) +Paper_outputter::output_metadata (Book_paper_def *paper, SCM scopes) { SCM fields = SCM_EOL; for (int i = dump_header_fieldnames_global.size (); i--; ) @@ -76,10 +76,12 @@ Paper_outputter::output_metadata (Paper_def *paper, SCM scopes) } void -Paper_outputter::output_header (Paper_def *paper, SCM scopes, int page_count, +Paper_outputter::output_header (Book_paper_def * bookpaper, + + SCM scopes, + int page_count, bool is_classic) { - paper_ = paper; // BROKEN BROKEN BROKEN. String creator = gnu_lilypond_version_string (); creator += " (http://lilypond.org)"; time_t t (time (0)); @@ -89,14 +91,14 @@ Paper_outputter::output_header (Paper_def *paper, SCM scopes, int page_count, output_scheme (scm_list_n (ly_symbol2scm ("header"), scm_makfrom0str (creator.to_str0 ()), scm_makfrom0str (time_stamp.to_str0 ()), - paper->self_scm (), + bookpaper->self_scm (), // FIXME. scm_int2num (page_count), ly_bool2scm (is_classic), SCM_UNDEFINED)); - output_metadata (paper, scopes); - output_music_output_def (paper); - + output_metadata (bookpaper, scopes); + output_scheme (scm_list_2 (ly_symbol2scm ("define-fonts"), + bookpaper->self_scm ())); output_scheme (scm_list_1 (ly_symbol2scm ("header-end"))); } @@ -162,13 +164,7 @@ paper_outputter_dump (void * po, SCM x) void Paper_outputter::output_stencil (Stencil stil) { - SCM fonts = find_expression_fonts (stil.expr ()); - - output_scheme (scm_list_3 (ly_symbol2scm ("define-fonts"), - paper_->self_scm (), - ly_quote_scm (ly_list_qsort_uniq_x (fonts)))); - - interpret_stencil_expression (stil.expr (), paper_outputter_dump, + interpret_stencil_expression (stil.expr (), paper_outputter_dump, (void*) this, Offset (0,0)); } diff --git a/lily/parser.yy b/lily/parser.yy index 89a1a02973..f31f99023e 100644 --- a/lily/parser.yy +++ b/lily/parser.yy @@ -26,6 +26,7 @@ TODO: #include "book.hh" +#include "book-paper-def.hh" #include "context-def.hh" #include "dimensions.hh" #include "event.hh" @@ -622,6 +623,7 @@ book_body: { $$ = new Book; $$->set_spot (THIS->here_input ()); + $$->bookpaper_ = unsmob_bookpaper (THIS->lexer_->lookup_identifier ("$defaultbookpaper")); } | book_body score_block { Score *score = $2; diff --git a/lily/scaled-font-metric.cc b/lily/scaled-font-metric.cc deleted file mode 100644 index 0210c86c55..0000000000 --- a/lily/scaled-font-metric.cc +++ /dev/null @@ -1,303 +0,0 @@ -/* - scaled-font-metric.cc -- declare Modified_font_metric - - source file of the GNU LilyPond music typesetter - - (c) 1999--2004 Han-Wen Nienhuys - - */ - -#include - -#include "warn.hh" -#include "scaled-font-metric.hh" -#include "string.hh" -#include "stencil.hh" - -Modified_font_metric::Modified_font_metric (String coding, Font_metric* m, Real magn) -{ - coding_vector_ = SCM_EOL; - coding_mapping_ = SCM_EOL; - coding_table_ = SCM_EOL; - coding_description_ = SCM_EOL; - - coding_scheme_ = coding; - magnification_ = magn; - - SCM desc = m->description_; - - Real total_mag = magn * ly_scm2double (ly_cdr (desc)); - assert (total_mag); - - description_ = scm_cons (ly_car (desc), scm_make_real (total_mag)); - orig_ = m; - - if (coding_scheme_ != "TeX" - && coding_scheme_ != "ASCII" - && coding_scheme_ != orig_->coding_scheme ()) - { - coding_vector_ = scm_call_1 (ly_scheme_function ("get-coding-vector"), - scm_makfrom0str (coding_scheme_.to_str0 ())); - - if (!ly_c_vector_p (coding_vector_)) - { - programming_error ("get-coding-vector should return vector"); - coding_vector_ = scm_c_make_vector (256, ly_symbol2scm (".notdef")); - } - - - coding_table_ = scm_call_1 (ly_scheme_function ("get-coding-table"), - scm_makfrom0str (orig_->coding_scheme ().to_str0 ())); - - coding_mapping_ = scm_call_2 (ly_scheme_function ("make-encoding-mapping"), - coding_vector_, - coding_table_); - - coding_description_= SCM_EOL; - - coding_description_ = scm_acons (ly_symbol2scm ("input-name"), - scm_makfrom0str (coding_scheme_.to_str0 ()), - coding_description_); - - coding_description_ = scm_acons (ly_symbol2scm ("input-vector"), - coding_vector_, coding_description_); - coding_description_ = scm_acons (ly_symbol2scm ("output-name"), - scm_makfrom0str (orig_->coding_scheme ().to_str0 ()), - coding_description_); - coding_description_ = scm_acons (ly_symbol2scm ("output-table"), - coding_table_, - coding_description_); - - coding_description_ = scm_acons (ly_symbol2scm ("char-mapping"), - coding_mapping_, - coding_description_); - } -} - - - -LY_DEFINE (ly_font_encoding_alist, "ly:font-encoding-alist", - 1, 0, 0, - (SCM font), - "Given the Modified_font_metric @var{font}, return an " - "alist. Keys are input-name, input-vector, " - "output-name, output-table, mapping.") -{ - Modified_font_metric *fm - = dynamic_cast (unsmob_metrics (font)); - - SCM_ASSERT_TYPE (fm, font, SCM_ARG1, __FUNCTION__, "Modified_font_metric"); - return fm->coding_description_; -} - -SCM -Modified_font_metric::make_scaled_font_metric (SCM coding, Font_metric *m, Real s) -{ - /* - UGOHR. - */ - if (ly_c_symbol_p (coding)) - coding = scm_symbol_to_string (coding); - - String scheme = ly_scm2string (coding); - - Modified_font_metric *sfm = new Modified_font_metric (scheme, m, s); - - return sfm->self_scm (); -} - -Real -Modified_font_metric::design_size () const -{ - return orig_->design_size (); -} - - -Box -Modified_font_metric::get_indexed_char (int i) const -{ - Box b = orig_->get_indexed_char (i); - b.scale (magnification_); - return b; -} - -Box -Modified_font_metric::get_ascii_char (int i) const -{ - Box b = orig_->get_ascii_char (i); - b.scale (magnification_); - return b; -} - -int -Modified_font_metric::count () const -{ - return orig_->count (); -} - -Offset -Modified_font_metric::get_indexed_wxwy (int k) const -{ - Offset o = orig_->get_indexed_wxwy (k); - return o * magnification_; -} - -int -Modified_font_metric::name_to_index (String s) const -{ - return orig_->name_to_index (s); -} - -int -Modified_font_metric::index_to_ascii (int k) const -{ - return orig_->index_to_ascii (k); -} - -String -Modified_font_metric::coding_scheme () const -{ - return coding_scheme_; -} - -void -Modified_font_metric::derived_mark () const -{ - scm_gc_mark (coding_vector_); - scm_gc_mark (coding_description_); - scm_gc_mark (coding_table_); - scm_gc_mark (coding_mapping_); -} - -Box -Modified_font_metric::tex_kludge (String text) const -{ - Interval ydims; - Real w=0.0; - - /* - TODO: put this klutchness behind ly:option switch. - */ - for (int i = 0; i < text.length (); i++) - { - switch (text[i]) - { - case '\\': - // accent marks use width of base letter - if (i +1 < text.length ()) - { - if (text[i+1]=='\'' || text[i+1]=='`' || text[i+1]=='"' || - text[i+1]=='^') - { - i++; - break; - } - // for string width \\ is a \ and \_ is a _. - if (text[i+1]=='\\' || text[i+1]=='_') - { - break; - } - } - - for (i++; (i < text.length ()) && !isspace (text[i]) - && text[i]!='{' && text[i]!='}'; i++) - ; - - // ugh. - i--; // Compensate for the increment in the outer loop! - break; - case '{': // Skip '{' and '}' - case '}': - break; - - default: - Box b = get_ascii_char ((unsigned char)text[i]); - - // Ugh, use the width of 'x' for unknown characters - if (b[X_AXIS].length () == 0) - b = get_ascii_char ((unsigned char)'x'); - - w += b[X_AXIS].length (); - ydims.unite (b[Y_AXIS]); - break; - } - } - - if (ydims.is_empty ()) - ydims = Interval (0, 0); - - return Box (Interval (0, w), ydims); -} - -Box -Modified_font_metric::text_dimension (String text) -{ - Box b; - if (coding_scheme_ == "TeX") - { - b = tex_kludge (text); - } - else if (coding_scheme_ == "ASCII" - || coding_scheme_ == orig_->coding_scheme ()) - { - Interval ydims; - - Real w=0.0; - - for (int i = 0; i < text.length (); i++) - { - Box b = get_ascii_char ((unsigned char)text[i]); - - w += b[X_AXIS].length (); - ydims.unite (b[Y_AXIS]); - } - if (ydims.is_empty ()) - ydims = Interval (0, 0); - - b = Box(Interval(0,w), ydims); - } - else - { - Interval ydims; - Real w = 0.0; - - for (int i = 0; i < text.length (); i++) - { - SCM sym = scm_vector_ref (coding_vector_, - SCM_MAKINUM((unsigned char) text[i])); - - Box char_box; - - if (!ly_c_symbol_p (sym)) - continue; - - char const * chars = SCM_SYMBOL_CHARS(sym); - - int idx = orig_->name_to_index (chars); - if (idx >= 0) - { - char_box = orig_->get_indexed_char (idx); - } - - char_box.scale (magnification_); - if (!char_box[X_AXIS].is_empty ()) - w += char_box[X_AXIS][RIGHT]; // length ? - - ydims.unite (char_box[Y_AXIS]); - } - - if (ydims.is_empty ()) - ydims = Interval (0, 0); - - - b = Box (Interval (0, w), ydims); - } - - return b; -} - -Font_metric* -Modified_font_metric::original_font () const -{ - return orig_; -} diff --git a/lily/score.cc b/lily/score.cc index b287028e24..18a43641d0 100644 --- a/lily/score.cc +++ b/lily/score.cc @@ -9,6 +9,7 @@ #include #include "book.hh" +#include "book-paper-def.hh" #include "cpu-timer.hh" #include "global-context.hh" #include "ly-module.hh" @@ -155,10 +156,20 @@ LY_DEFINE (ly_format_output, "ly:format-output", } void -default_rendering (SCM music, SCM outdef, SCM header, SCM outname) +default_rendering (SCM music, SCM outdef, + SCM book_outputdef, + SCM header, SCM outname) { SCM context = ly_run_translator (music, outdef); + Book_paper_def * bpd = unsmob_bookpaper (book_outputdef); + if (bpd && + unsmob_paper (outdef)) + { + outdef = bpd->scale_paper (unsmob_paper (outdef))->self_scm (); // mem + // leak. + } + if (Global_context *g = dynamic_cast (unsmob_context (context))) { @@ -182,9 +193,11 @@ default_rendering (SCM music, SCM outdef, SCM header, SCM outname) delete output; } } - + SCM -Score::book_rendering (String outname, Music_output_def *default_def, +Score::book_rendering (String outname, + Book_paper_def* paperbook, + Music_output_def *default_def, Paper_def **paper) { SCM out = scm_makfrom0str (outname.to_str0 ()); @@ -193,6 +206,11 @@ Score::book_rendering (String outname, Music_output_def *default_def, for (int i = 0; !i || i < outdef_count; i++) { Music_output_def *def = outdef_count ? defs_[i] : default_def; + if (Paper_def * pd = dynamic_cast (def)) + { + def = paperbook->scale_paper (pd); + } + if (!(no_paper_global_b && dynamic_cast (def))) { SCM context = ly_run_translator (music_, def->self_scm ()); diff --git a/ly/declarations-init.ly b/ly/declarations-init.ly index b7a4829df0..f0fc60ee7b 100644 --- a/ly/declarations-init.ly +++ b/ly/declarations-init.ly @@ -86,6 +86,14 @@ melismaEnd = #(make-span-event 'ManualMelismaEvent STOP) \include "engraver-init.ly" } +% +% 20pt staff, 5 pt = 1.75 mm +% + +#(define-public $defaultbookpaper (ly:make-bookpaper 1.7573)) + + + #(set-default-paper-size "a4") diff --git a/po/fr.po b/po/fr.po index 6424c799ee..96d4929c1b 100644 --- a/po/fr.po +++ b/po/fr.po @@ -1,5 +1,5 @@ # Messages français pour lilypond. -# Copyright © 2001 Free Software Foundation, Inc. +# Copyright © 2004 Free Software Foundation, Inc. # Michel Robitaille , traducteur depuis/since 1996. # msgid "" @@ -7,12 +7,13 @@ msgstr "" "Project-Id-Version: lilypond 2.2.0\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2004-03-31 16:22+0200\n" -"PO-Revision-Date: 2004-04-04 08:00-0500\n" +"PO-Revision-Date: 2004-05-10 08:00-0500\n" "Last-Translator: Michel Robitaille \n" "Language-Team: French \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=ISO-8859-1\n" "Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n > 1);\n" #: lilylib.py:60 msgid "lilylib module" diff --git a/ps/music-drawing-routines.ps b/ps/music-drawing-routines.ps index 39374dae21..5d39f3305d 100644 --- a/ps/music-drawing-routines.ps +++ b/ps/music-drawing-routines.ps @@ -3,8 +3,6 @@ % Functions for direct and embedded PostScript -/blot-diameter { lilypondpaperblotdiameter } bind def - /set_tex_dimen { cvr def } bind def @@ -20,12 +18,12 @@ % Nice rectangle with rounded corners /draw_box % breapth width depth height { - currentdict /testing known { +% currentdict /testing known { %% real thin lines for testing /blot 0.005 def - }{ - /blot blot-diameter def - } ifelse +% }{ +% /blot blot-diameter def +% } ifelse 0 setlinecap blot setlinewidth diff --git a/scm/lily.scm b/scm/lily.scm index 58c3a603e0..a1c81d4775 100644 --- a/scm/lily.scm +++ b/scm/lily.scm @@ -103,7 +103,10 @@ (ly:parser-print-book parser book))) (define-public (print-score-as-book parser score) - (let ((book (ly:score-bookify score))) + (let + ((book (ly:score-bookify score)) + ) + (ly:parser-print-book parser book))) (define-public (print-score parser score) diff --git a/scm/output-ps.scm b/scm/output-ps.scm index 22cce8d52b..4cc714fdec 100644 --- a/scm/output-ps.scm +++ b/scm/output-ps.scm @@ -263,7 +263,7 @@ " /Helvetica-Bold " ;; ugh " draw_ez_ball")) -(define (filledbox breapth width depth height) +(define (filledbox breapth width depth height) ; FIXME : use draw_round_box (string-append (ly:numbers->string (list breapth width depth height)) " draw_box")) @@ -369,7 +369,7 @@ "{\n" "set-ps-scale-to-lily-scale\n")) -(define (stem breapth width depth height) +(define (stem breapth width depth height) ; FIXME: use draw_round_box. (string-append (ly:numbers->string (list breapth width depth height)) " draw_box" )) diff --git a/scm/output-tex.scm b/scm/output-tex.scm index 4c0800a25b..77dd2053b4 100644 --- a/scm/output-tex.scm +++ b/scm/output-tex.scm @@ -69,10 +69,17 @@ (string-encode-integer (inexact->exact (round (* 1000 (ly:font-magnification font))))))) -(define (define-fonts paper font-list) +(define (define-fonts bookpaper) + (string-append + "\\def\\lilypondpaperunit{mm}" ;; UGH. FIXME. + (tex-number-def "lilypondpaper" 'outputscale + (number->string (exact->inexact + (ly:bookpaper-outputscale bookpaper)))) (apply string-append - (map (lambda (x) (font-load-command paper x)) font-list))) - + (map (lambda (x) (font-load-command bookpaper x)) + (ly:bookpaper-fonts bookpaper) + ))) +) (define (unknown) "%\n\\unknown\n") @@ -99,25 +106,25 @@ (string-append "\\def\\" prefix (symbol->tex-key key) (string->param number) "%\n")) -(define (output-paper-def pd) - (apply - string-append - (module-map - (lambda (sym var) - (let ((val (variable-ref var)) - (key (symbol->tex-key sym))) - - (cond - ((string? val) - (tex-string-def "lilypondpaper" sym val)) - ((number? val) - (tex-number-def "lilypondpaper" sym - (if (integer? val) - (number->string val) - (number->string (exact->inexact val))))) - (else "")))) - - (ly:output-def-scope pd)))) +(define (output-paper-def paper) + (apply + string-append + (module-map + (lambda (sym var) + (let ((val (variable-ref var)) + (key (symbol->tex-key sym))) + + (cond + ((string? val) + (tex-string-def "lilypondpaper" sym val)) + ((number? val) + (tex-number-def "lilypondpaper" sym + (if (integer? val) + (number->string val) + (number->string (exact->inexact val))))) + (else "")))) + + (ly:output-def-scope pd)))) (define (output-scopes paper scopes fields basename) (define (output-scope scope) @@ -174,7 +181,7 @@ (define (symmetric-x-triangle t w h) (embedded-ps (list 'symmetric-x-triangle t w h))) -(define (font-load-command paper font) +(define (font-load-command bookpaper font) (string-append "\\font\\" (font-command font) "=" (ly:font-filename font) @@ -182,7 +189,7 @@ (ly:number->string (inexact->exact (round (* 1000 (ly:font-magnification font) - (ly:paper-lookup paper 'outputscale))))) + (ly:bookpaper-outputscale bookpaper))))) "\n")) (define (ez-ball c l b) @@ -245,6 +252,7 @@ "\\lilypondspecial\n" "\\lilypondpostscript\n")) +; why paper? (define (header creator time-stamp paper page-count classic?) (string-append "% Generated by " creator "\n" diff --git a/scm/paper.scm b/scm/paper.scm index beb11e087e..15acb3ea76 100644 --- a/scm/paper.scm +++ b/scm/paper.scm @@ -13,7 +13,6 @@ (mm (eval 'mm m))) (module-define! m 'fonts (make-cmr-tree (/ sz (* 20 pt)))) - (module-define! m 'staffheight sz) (module-define! m 'staff-space ss) (module-define! m 'staffspace ss) @@ -21,10 +20,15 @@ ;; !! synchronize with feta-params.mf (module-define! m 'linethickness (+ (* 0.3 pt) (* 0.04 ss))) - (module-define! m 'outputscale ss) (module-define! m 'ledgerlinethickness (+ (* 0.5 pt) (/ ss 10))) (module-define! m 'blotdiameter (* 0.35 pt)) - (module-define! m 'interscoreline (* 4 mm)))) + (module-define! m 'interscoreline (* 4 mm)) + + (module-define! m 'dimension-variables + '(pt mm cm in staffheight staff-space + staffspace linethickness ledgerlinethickness + blotdiameter interscoreline)) + )) (define-public (set-global-staff-size sz) "Set the default staff size, where SZ is thought to be in PT." @@ -101,3 +105,22 @@ ;;; TODO: should raise (generic) exception with throw, and catch ;;; that in parse-scm.cc (ly:warn "Must use #(set-paper-size .. ) within \\paper { ... }"))) + +(define-public (scale-paper pap bookpap) + (let* + ((scale (ly:bookpaper-outputscale bookpap)) + (new-pap (ly:output-def-clone pap)) + (dim-vars (ly:paper-lookup pap 'dimension-variables)) + (scope (ly:output-def-scope new-pap)) + ) + + (for-each + (lambda (v) + (module-define! scope v + (* (ly:paper-lookup pap v) scale))) + + + dim-vars) + + new-pap + ))