From 5547ff00446ba0ac2bdbd1fe3205c2fb8411bb2f Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Sat, 3 Apr 2004 11:43:06 +0000 Subject: [PATCH] * scm/output-tex.scm (font-command): use ly: functions to construct name. (define-fonts): don't use alist, just dump \font definitions. (font-load-command): calculate proper scaling by taking outputscale from paper argument. * lily/stencil-scheme.cc (fontify_atom): insert Font_metric into expression. * lily/paper-outputter.cc (output_header): pass paper arg to define-fonts * lily/paper-def.cc (font_descriptions): dump list of Scaled_font_metrics (find_scaled_font): take Font_metric argument, store Scaled_font_metrics in hash-table containing (size -> Scaled_font_metrics) alist. (get_dimension): rename from get_realvar * lily/font-metric.cc (LY_DEFINE): ly:font-design-size, ly:font-magnification, ly:font-name: new functions --- ChangeLog | 27 ++++++ lily/afm.cc | 10 ++- lily/all-font-metrics.cc | 13 +++ lily/ambitus.cc | 4 +- lily/arpeggio.cc | 2 +- lily/bar-line.cc | 4 +- lily/beam.cc | 4 +- lily/break-algorithm.cc | 4 +- lily/breathing-sign.cc | 8 +- lily/font-metric.cc | 36 ++++++++ lily/font-select.cc | 27 ++++-- lily/grob-interface.cc | 10 +-- lily/include/afm.hh | 3 +- lily/include/all-font-metrics.hh | 2 + lily/include/font-metric.hh | 9 +- lily/include/main.hh | 1 - lily/include/music-output-def.hh | 6 +- lily/include/paper-def.hh | 10 +-- lily/include/tfm.hh | 4 +- lily/include/virtual-font-metric.hh | 6 +- lily/lyric-extender.cc | 2 +- lily/lyric-hyphen.cc | 2 +- lily/main.cc | 1 - lily/mensural-ligature-engraver.cc | 2 +- lily/mensural-ligature.cc | 2 +- lily/multi-measure-rest.cc | 2 +- lily/music-output-def.cc | 15 ++-- lily/paper-book.cc | 14 +-- lily/paper-def.cc | 114 ++++++++++++++++-------- lily/paper-outputter.cc | 10 ++- lily/staff-symbol-referencer.cc | 2 +- lily/staff-symbol.cc | 4 +- lily/stem-tremolo.cc | 2 +- lily/stem.cc | 2 +- lily/stencil-scheme.cc | 2 +- lily/system-start-delimiter.cc | 2 +- lily/tfm.cc | 6 ++ lily/vaticana-ligature-engraver.cc | 2 +- lily/vaticana-ligature.cc | 4 +- lily/virtual-font-metric.cc | 52 +++++++++-- scm/font.scm | 131 ++++++++++++++++------------ scm/output-lib.scm | 2 +- scm/output-ps.scm | 8 +- scm/output-tex.scm | 65 ++++++-------- 44 files changed, 423 insertions(+), 215 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3224dc8f07..2e928348d7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,27 @@ +2004-04-03 Han-Wen Nienhuys + + * scm/output-tex.scm (font-command): use ly: functions to + construct name. + (define-fonts): don't use alist, just dump \font definitions. + (font-load-command): calculate proper scaling by taking + outputscale from paper argument. + + * lily/stencil-scheme.cc (fontify_atom): insert Font_metric into + expression. + + * lily/paper-outputter.cc (output_header): pass paper arg to + define-fonts + + * lily/paper-def.cc (font_descriptions): dump list of + Scaled_font_metrics + (find_scaled_font): take Font_metric argument, store + Scaled_font_metrics in hash-table containing (size -> + Scaled_font_metrics) alist. + (get_dimension): rename from get_realvar + + * lily/font-metric.cc (LY_DEFINE): ly:font-design-size, + ly:font-magnification, ly:font-name: new functions + 2004-04-03 Werner Lemberg * Documentation/user/dedication.itely, @@ -14,6 +38,9 @@ 2004-04-03 Han-Wen Nienhuys + * lily/include/font-metric.hh (struct Font_metric): add + design_size () method. + * buildscripts/mf-to-table.py (base): add DesignSize comment. * lily/afm.cc (read_afm_file): read design size. diff --git a/lily/afm.cc b/lily/afm.cc index b0787ac362..f24c80f7a8 100644 --- a/lily/afm.cc +++ b/lily/afm.cc @@ -206,11 +206,17 @@ Adobe_font_metric::find_by_name (String s) const } SCM at = (scm_list_n (ly_symbol2scm ("char"), - scm_int2num (cm->code), - SCM_UNDEFINED)); + scm_int2num (cm->code), + SCM_UNDEFINED)); // at= fontify_atom ((Font_metric*)this, at); Box b = afm_bbox_to_box (cm->charBBox); return Stencil (b, at); } + +Real +Adobe_font_metric::design_size () const +{ + return design_size_; +} diff --git a/lily/all-font-metrics.cc b/lily/all-font-metrics.cc index d2450498b3..8015be782f 100644 --- a/lily/all-font-metrics.cc +++ b/lily/all-font-metrics.cc @@ -212,4 +212,17 @@ All_font_metrics::find_font (String name) return 0; } +All_font_metrics *all_fonts_global; + + +LY_DEFINE (ly_font_load, "ly:font-load", 1, 0, 0, + (SCM name), + "Load the font @var{name}. ") +{ + SCM_ASSERT_TYPE (gh_string_p (name), name, SCM_ARG1, __FUNCTION__, "string"); + + Font_metric * fm = all_fonts_global->find_font (ly_scm2string (name)); + + return fm->self_scm (); +} diff --git a/lily/ambitus.cc b/lily/ambitus.cc index 9e5b145557..d2224744ac 100644 --- a/lily/ambitus.cc +++ b/lily/ambitus.cc @@ -213,8 +213,8 @@ Ambitus::print (SCM smob) if (to_boolean (me->get_property ("join-heads")) && ((p_max - p_min) >= 3)) { - Real linethickness = me->get_paper ()->get_realvar (ly_symbol2scm ("linethickness")); - Real blotdiameter = me->get_paper ()->get_realvar (ly_symbol2scm ("blotdiameter")); + Real linethickness = me->get_paper ()->get_dimension (ly_symbol2scm ("linethickness")); + Real blotdiameter = me->get_paper ()->get_dimension (ly_symbol2scm ("blotdiameter")); Interval x_extent = 0.5 * Interval (-linethickness, +linethickness); Interval y_extent = 0.5 * Interval (p_min + 1.35, p_max - 1.35); Box line_box (x_extent, y_extent); diff --git a/lily/arpeggio.cc b/lily/arpeggio.cc index 59966272ac..4bf7695e5b 100644 --- a/lily/arpeggio.cc +++ b/lily/arpeggio.cc @@ -123,7 +123,7 @@ Arpeggio::brew_chord_bracket (SCM smob) heads.unite (iv + ss->relative_coordinate (common, Y_AXIS) - my_y); } - Real lt = me->get_paper ()->get_realvar (ly_symbol2scm ("linethickness")); + Real lt = me->get_paper ()->get_dimension (ly_symbol2scm ("linethickness")); Real sp = 1.5 * Staff_symbol_referencer::staff_space (me); Real dy = heads.length () + sp; Real x = 0.7; diff --git a/lily/bar-line.cc b/lily/bar-line.cc index f7f1d7808c..9a7a2b30b1 100644 --- a/lily/bar-line.cc +++ b/lily/bar-line.cc @@ -52,7 +52,7 @@ Bar_line::compound_barline (Grob*me, String str, Real h) Real hair = robust_scm2double (me->get_property ("hair-thickness"), 1); Real fatline = robust_scm2double (me->get_property ("thick-thickness"), 1); - Real staffline = me->get_paper ()->get_realvar (ly_symbol2scm ("linethickness")); + Real staffline = me->get_paper ()->get_dimension (ly_symbol2scm ("linethickness")); Real staff_space = Staff_symbol_referencer::staff_space (me); kern *= staffline; @@ -142,7 +142,7 @@ Bar_line::compound_barline (Grob*me, String str, Real h) Stencil Bar_line::simple_barline (Grob *me,Real w, Real h) { - Real blot = me->get_paper ()->get_realvar (ly_symbol2scm ("blotdiameter")); + Real blot = me->get_paper ()->get_dimension (ly_symbol2scm ("blotdiameter")); return Lookup::round_filled_box (Box (Interval (0,w), Interval (-h/2, h/2)), blot); } diff --git a/lily/beam.cc b/lily/beam.cc index 130dc8f3e4..746d3ba60f 100644 --- a/lily/beam.cc +++ b/lily/beam.cc @@ -354,7 +354,7 @@ Beam::print (SCM grob) Real gap_length =robust_scm2double ( me->get_property ("gap"), 0.0); Stencil the_beam; - Real lt = me->get_paper ()->get_realvar (ly_symbol2scm ("linethickness")); + Real lt = me->get_paper ()->get_dimension (ly_symbol2scm ("linethickness")); for (int i = 0; i<= stems.size (); i++) { @@ -416,7 +416,7 @@ Beam::print (SCM grob) w += stem_width/ 2 ; - Real blot = me->get_paper ()->get_realvar (ly_symbol2scm ("blotdiameter")); + Real blot = me->get_paper ()->get_dimension (ly_symbol2scm ("blotdiameter")); Stencil whole = Lookup::beam (dydx, w, thick, blot); Stencil gapped; diff --git a/lily/break-algorithm.cc b/lily/break-algorithm.cc index 7176d928ff..5db8a7c08e 100644 --- a/lily/break-algorithm.cc +++ b/lily/break-algorithm.cc @@ -62,7 +62,7 @@ Break_algorithm::generate_spacing_problem (Link_array const &curline, /* this is hardcoded, but this shouldn't happen anyway. - used to be get_realvar (ly_symbol2scm ("loose_column_distance")); + used to be get_dimension (ly_symbol2scm ("loose_column_distance")); */ sp->default_space_ = 1.0; @@ -95,7 +95,7 @@ void Break_algorithm::set_pscore (Paper_score*s) { pscore_ = s; - linewidth_ = s->paper_->get_realvar (ly_symbol2scm ("linewidth")); + linewidth_ = s->paper_->get_dimension (ly_symbol2scm ("linewidth")); } Array diff --git a/lily/breathing-sign.cc b/lily/breathing-sign.cc index 489a32296f..565975359f 100644 --- a/lily/breathing-sign.cc +++ b/lily/breathing-sign.cc @@ -55,7 +55,7 @@ Breathing_sign::divisio_minima (SCM smob) else staff_size = 0.0; - Real blotdiameter = me->get_paper ()->get_realvar (ly_symbol2scm ("blotdiameter")); + Real blotdiameter = me->get_paper ()->get_dimension (ly_symbol2scm ("blotdiameter")); /* * Draw a small vertical line through the uppermost (or, depending @@ -88,7 +88,7 @@ Breathing_sign::divisio_maior (SCM smob) else staff_size = 0.0; - Real blotdiameter = me->get_paper ()->get_realvar (ly_symbol2scm ("blotdiameter")); + Real blotdiameter = me->get_paper ()->get_dimension (ly_symbol2scm ("blotdiameter")); /* * Draw a vertical line that is vertically centered in the staff @@ -128,7 +128,7 @@ Breathing_sign::divisio_maxima (SCM smob) else staff_size = 0.0; - Real blotdiameter = me->get_paper ()->get_realvar (ly_symbol2scm ("blotdiameter")); + Real blotdiameter = me->get_paper ()->get_dimension (ly_symbol2scm ("blotdiameter")); // like a "|" type bar Interval xdim (0, thickness); @@ -158,7 +158,7 @@ Breathing_sign::finalis (SCM smob) else staff_size = 0.0; - Real blotdiameter = me->get_paper ()->get_realvar (ly_symbol2scm ("blotdiameter")); + Real blotdiameter = me->get_paper ()->get_dimension (ly_symbol2scm ("blotdiameter")); // like a "||" type bar Interval xdim (0, thickness); diff --git a/lily/font-metric.cc b/lily/font-metric.cc index fb041fe3da..f8083f5952 100644 --- a/lily/font-metric.cc +++ b/lily/font-metric.cc @@ -18,6 +18,12 @@ #include "font-metric.hh" #include "string.hh" +Real +Font_metric::design_size () const +{ + return 1.0; +} + Box Font_metric::text_dimension (String text) const { @@ -210,6 +216,36 @@ LY_DEFINE (ly_text_dimension,"ly:text-dimension", 2 , 0, 0, return gh_cons (ly_interval2scm (b[X_AXIS]), ly_interval2scm (b[Y_AXIS])); } +LY_DEFINE (ly_font_name,"ly:font-name", 1 , 0, 0, + (SCM font), + "Given the font metric @var{font}, return the corresponding file name. ") +{ + Font_metric *fm = unsmob_metrics (font); + SCM_ASSERT_TYPE (fm, font, SCM_ARG1, __FUNCTION__, "font-metric"); + return gh_car (fm->description_); +} + +LY_DEFINE (ly_font_magnification,"ly:font-magnification", 1 , 0, 0, + (SCM font), + "Given the font metric @var{font}, return the " + "magnification, relative to the current outputscale.") +{ + Font_metric *fm = unsmob_metrics (font); + SCM_ASSERT_TYPE (fm, font, SCM_ARG1, __FUNCTION__, "font-metric"); + return gh_cdr (fm->description_); +} + +LY_DEFINE (ly_font_design_size,"ly:font-design-size", 1 , 0, 0, + (SCM font), + "Given the font metric @var{font}, return the " + "design size, relative to the current outputscale.") +{ + Font_metric *fm = unsmob_metrics (font); + SCM_ASSERT_TYPE (fm, font, SCM_ARG1, __FUNCTION__, "font-metric"); + return gh_cdr (fm->description_); +} + + Stencil Font_metric::get_ascii_char_stencil (int code) const { diff --git a/lily/font-select.cc b/lily/font-select.cc index 26d3cad0d3..2c1d7f1ec6 100644 --- a/lily/font-select.cc +++ b/lily/font-select.cc @@ -9,6 +9,7 @@ #include +#include "all-font-metrics.hh" #include "paper-def.hh" #include "font-interface.hh" #include "warn.hh" @@ -33,7 +34,7 @@ LY_DEFINE (ly_paper_get_number, "ly:paper-get-number", 2, 0, 0, { Paper_def *pap = unsmob_paper (paper); SCM_ASSERT_TYPE (pap, paper, SCM_ARG1, __FUNCTION__, "paper definition"); - return gh_double2scm (pap->get_realvar (name)); + return gh_double2scm (pap->get_dimension (name)); } bool @@ -42,6 +43,12 @@ wild_compare (SCM field_val, SCM val) return (val == SCM_BOOL_F || field_val == ly_symbol2scm ("*") || field_val == val); } + +/* + TODO: this triggers a great number of font-loads (feta11 upto + parmesan23). We could make a Delayed_load_font_metric for which the + design size is specced in advance. + */ Font_metric* get_font_by_design_size (Paper_def* paper, Real requested, SCM font_vector) @@ -53,7 +60,10 @@ get_font_by_design_size (Paper_def* paper, Real requested, for (; i < n; i++) { - size = gh_scm2double (gh_car (SCM_VECTOR_REF (font_vector, i))); + SCM entry = SCM_VECTOR_REF (font_vector, i); + Font_metric *fm = unsmob_metrics (scm_force (entry)); + size = fm->design_size (); + if (size > requested) break ; last_size = size; @@ -71,9 +81,9 @@ get_font_by_design_size (Paper_def* paper, Real requested, size = last_size; } } - - return paper->find_font (gh_cdr (SCM_VECTOR_REF (font_vector, i)), - requested / size); + + Font_metric *fm = unsmob_metrics (scm_force (SCM_VECTOR_REF (font_vector, i))); + return paper->find_scaled_font (fm, requested / size); } @@ -114,8 +124,11 @@ select_font (Paper_def *paper, SCM chain) SCM mag = ly_assoc_chain (ly_symbol2scm ("font-magnification"), chain); Real rmag = gh_pair_p (mag) ? robust_scm2double (gh_cdr (mag), 1.0) : 1; - - return paper->find_font (name, rmag); + + Font_metric * fm = all_fonts_global->find_font (ly_scm2string (name)); + + + return paper->find_scaled_font (fm, rmag); } else if (scm_instance_p (name)) { diff --git a/lily/grob-interface.cc b/lily/grob-interface.cc index 058a58bbf3..cf6ca2327d 100644 --- a/lily/grob-interface.cc +++ b/lily/grob-interface.cc @@ -70,8 +70,8 @@ check_interfaces_for_property (Grob const *me, SCM sym) SCM iface = scm_hashq_ref (all_ifaces , gh_car (ifs), SCM_BOOL_F); if (iface == SCM_BOOL_F) { - String msg = to_string ("Unknown interface `%s'", - ly_symbol2string (gh_car (ifs)).to_str0 ()); + String msg = to_string (_f ("Unknown interface `%s'", + ly_symbol2string (gh_car (ifs)).to_str0 ())); programming_error (msg); continue; } @@ -81,9 +81,9 @@ check_interfaces_for_property (Grob const *me, SCM sym) if (!found) { - String str = to_string ("Grob `%s' has no interface for property `%s'", - me->name ().to_str0 (), - ly_symbol2string (sym).to_str0 ()); + String str = to_string (_f ("Grob `%s' has no interface for property `%s'", + me->name ().to_str0 (), + ly_symbol2string (sym).to_str0 ())); programming_error (str); } } diff --git a/lily/include/afm.hh b/lily/include/afm.hh index ce374f03f5..96be58284a 100644 --- a/lily/include/afm.hh +++ b/lily/include/afm.hh @@ -19,7 +19,7 @@ #include "font-metric.hh" #include "parse-afm.hh" -struct Adobe_font_metric : Font_metric +struct Adobe_font_metric : Simple_font_metric { AFM_Font_info * font_inf_; @@ -35,6 +35,7 @@ struct Adobe_font_metric : Font_metric String to_string () const; ~Adobe_font_metric (); static SCM make_afm (AFM_Font_info*, unsigned, Real); + virtual Real design_size () const; unsigned int checksum_; Real design_size_; diff --git a/lily/include/all-font-metrics.hh b/lily/include/all-font-metrics.hh index 7174d16dbb..776a38d16f 100644 --- a/lily/include/all-font-metrics.hh +++ b/lily/include/all-font-metrics.hh @@ -34,5 +34,7 @@ public: SCM font_descriptions () const; }; +extern All_font_metrics *all_fonts_global; + #endif /* ALL_FONTS_HH */ diff --git a/lily/include/font-metric.hh b/lily/include/font-metric.hh index 4f8079f963..acf05d5d1a 100644 --- a/lily/include/font-metric.hh +++ b/lily/include/font-metric.hh @@ -28,7 +28,7 @@ public: virtual Box get_ascii_char (int ascii) const; virtual Box text_dimension (String) const; virtual int name_to_index (String) const; - + virtual Real design_size () const; virtual Stencil find_by_name (String) const; virtual Stencil get_indexed_char_stencil (int k) const; virtual Stencil get_ascii_char_stencil (int k) const; @@ -42,6 +42,13 @@ protected: Font_metric (); }; +struct Simple_font_metric : public Font_metric +{ +public: + +}; + + DECLARE_UNSMOB(Font_metric, metrics); #endif /* FONT_METRIC_HH */ diff --git a/lily/include/main.hh b/lily/include/main.hh index 5c5ed19e8c..b923465bd1 100644 --- a/lily/include/main.hh +++ b/lily/include/main.hh @@ -40,7 +40,6 @@ extern bool internal_type_checking_global_b; /* misc */ -extern All_font_metrics *all_fonts_global; extern Array failed_files; extern int exit_status_global; extern File_path global_path; diff --git a/lily/include/music-output-def.hh b/lily/include/music-output-def.hh index 53c9bdcf65..fd32745452 100644 --- a/lily/include/music-output-def.hh +++ b/lily/include/music-output-def.hh @@ -27,8 +27,8 @@ public: Input input_origin_; SCM scope_; - SCM scaled_fonts_; - + + virtual void derived_mark (); Music_output_def (Music_output_def const&); Music_output_def (); VIRTUAL_COPY_CONSTRUCTOR (Music_output_def, Music_output_def); @@ -37,7 +37,7 @@ public: void assign_context_def (SCM transdef); SCM find_context_def (SCM name) const; String outname_string () ; - SCM get_scmvar (String id)const; + SCM get_scmvar (String id) const; SCM lookup_variable (SCM sym) const; void set_variable (SCM, SCM sym); diff --git a/lily/include/paper-def.hh b/lily/include/paper-def.hh index 71f0ad1cce..7a2c84e73e 100644 --- a/lily/include/paper-def.hh +++ b/lily/include/paper-def.hh @@ -47,23 +47,23 @@ class Paper_def : public Music_output_def { protected: VIRTUAL_COPY_CONSTRUCTOR (Music_output_def, Paper_def); - + SCM scaled_fonts_; + public: static int score_count_; Paper_def (); Paper_def (Paper_def const&); virtual ~Paper_def (); + virtual void derived_mark (); Paper_outputter* get_paper_outputter (String) const; SCM font_descriptions () const; void reinit (); Interval line_dimensions_int (int) const; void output_settings (Paper_outputter*) const; - Font_metric *find_font (SCM name, Real mag); - - /* JUNKME */ - Real get_realvar (SCM symbol) const; + Font_metric *find_scaled_font (Font_metric *fm, Real mag); + Real get_dimension (SCM symbol) const; friend int yyparse (void*); }; diff --git a/lily/include/tfm.hh b/lily/include/tfm.hh index 5869aca159..2906149f9b 100644 --- a/lily/include/tfm.hh +++ b/lily/include/tfm.hh @@ -145,13 +145,15 @@ struct Tex_font_char_metric }; -class Tex_font_metric : public Font_metric +class Tex_font_metric : public Simple_font_metric { public: static SCM make_tfm (String filename); virtual int count () const; virtual Box get_ascii_char (int) const; + virtual Real design_size () const; + Tex_font_char_metric const *find_ascii (int ascii, bool warn=true) const; String to_string () const; diff --git a/lily/include/virtual-font-metric.hh b/lily/include/virtual-font-metric.hh index a3859954df..181c00820f 100644 --- a/lily/include/virtual-font-metric.hh +++ b/lily/include/virtual-font-metric.hh @@ -17,8 +17,9 @@ class Virtual_font_metric : public Font_metric { SCM font_list_; public: - Virtual_font_metric (SCM namelist, Real, Paper_def*); - + SCM get_font_list () const; + Virtual_font_metric (SCM namelist); + virtual Real design_size () const; virtual int count () const; virtual Box get_indexed_char (int ascii) const; virtual Box get_ascii_char (int ascii) const; @@ -27,7 +28,6 @@ public: virtual Offset get_indexed_wxwy (int) const; virtual int name_to_index (String)const; virtual Stencil find_by_name (String) const; - protected: virtual void derived_mark () const; }; diff --git a/lily/lyric-extender.cc b/lily/lyric-extender.cc index 92b1ca711a..9fda17d946 100644 --- a/lily/lyric-extender.cc +++ b/lily/lyric-extender.cc @@ -41,7 +41,7 @@ Lyric_extender::print (SCM smob) Grob *common = l->common_refpoint (r, X_AXIS); - Real sl = me->get_paper ()->get_realvar (ly_symbol2scm ("linethickness")); + Real sl = me->get_paper ()->get_dimension (ly_symbol2scm ("linethickness")); Link_array heads (Pointer_group_interface__extract_grobs (me, (Grob*)0, "heads")); diff --git a/lily/lyric-hyphen.cc b/lily/lyric-hyphen.cc index 98b2b22403..0f5460b4b8 100644 --- a/lily/lyric-hyphen.cc +++ b/lily/lyric-hyphen.cc @@ -44,7 +44,7 @@ Hyphen_spanner::print (SCM smob) } while (flip (&d) != LEFT); - Real lt = me->get_paper ()->get_realvar (ly_symbol2scm ("linethickness")); + Real lt = me->get_paper ()->get_dimension (ly_symbol2scm ("linethickness")); Real th = robust_scm2double (me->get_property ("thickness"), 1) * lt ; Real h = robust_scm2double (me->get_property ("height"), 0.5); diff --git a/lily/main.cc b/lily/main.cc index 80cf2a133a..50a46a1488 100644 --- a/lily/main.cc +++ b/lily/main.cc @@ -76,7 +76,6 @@ String init_scheme_code_string = "(begin #t "; * Miscellaneous global stuff. */ -All_font_metrics *all_fonts_global; int exit_status_global; File_path global_path; diff --git a/lily/mensural-ligature-engraver.cc b/lily/mensural-ligature-engraver.cc index 541df71401..0cc041843b 100644 --- a/lily/mensural-ligature-engraver.cc +++ b/lily/mensural-ligature-engraver.cc @@ -344,7 +344,7 @@ Mensural_ligature_engraver::propagate_properties (Spanner *ligature, Array primitives) { Real thickness = robust_scm2double (ligature->get_property ("thickness"), 1.4); - thickness *= ligature->get_paper ()->get_realvar (ly_symbol2scm ("linethickness")); + thickness *= ligature->get_paper ()->get_dimension (ly_symbol2scm ("linethickness")); Real head_width = Font_interface::get_default_font (ligature)-> diff --git a/lily/mensural-ligature.cc b/lily/mensural-ligature.cc index cbd404b32c..c0eb732a87 100644 --- a/lily/mensural-ligature.cc +++ b/lily/mensural-ligature.cc @@ -191,7 +191,7 @@ internal_brew_primitive (Grob *me, bool ledger_take_space) int join_left = gh_scm2int (join_left_scm); if (!join_left) programming_error (_f ("Mensural_ligature: (join_left == 0)")); - Real blotdiameter = (me->get_paper ()->get_realvar (ly_symbol2scm ("blotdiameter"))); + Real blotdiameter = (me->get_paper ()->get_dimension (ly_symbol2scm ("blotdiameter"))); Interval x_extent = Interval (0, thickness); Interval y_extent = (join_left > 0) ? Interval (-join_left * 0.5 * staff_space, 0) : diff --git a/lily/multi-measure-rest.cc b/lily/multi-measure-rest.cc index 51101be0e2..1a11fbde6b 100644 --- a/lily/multi-measure-rest.cc +++ b/lily/multi-measure-rest.cc @@ -185,7 +185,7 @@ Multi_measure_rest::big_rest (Grob *me, Real width) Real ss = Staff_symbol_referencer::staff_space (me); - Real slt = me->get_paper ()->get_realvar (ly_symbol2scm ("linethickness")); + Real slt = me->get_paper ()->get_dimension (ly_symbol2scm ("linethickness")); Real y = slt * thick_thick/2 * ss; Real ythick = hair_thick * slt * ss; Box b (Interval (0, 0 >? (width - 2 * ythick)), Interval (-y, y)); diff --git a/lily/music-output-def.cc b/lily/music-output-def.cc index e2c32b6dd2..3801ee954e 100644 --- a/lily/music-output-def.cc +++ b/lily/music-output-def.cc @@ -21,7 +21,6 @@ Music_output_def::Music_output_def () { - scaled_fonts_ = SCM_EOL; translator_tab_ = new Scheme_hash_table; scope_ = SCM_EOL; smobify_self (); @@ -38,14 +37,11 @@ Music_output_def::Music_output_def (Music_output_def const &s) { scope_ = SCM_EOL; translator_tab_ = 0; - scaled_fonts_ = SCM_EOL; smobify_self (); translator_tab_ = new Scheme_hash_table (*s.translator_tab_); scm_gc_unprotect_object (translator_tab_->self_scm ()); - scaled_fonts_ = scm_list_copy (s.scaled_fonts_); - scope_= ly_make_anonymous_module (); if (ly_module_p (s.scope_)) ly_import_module (scope_, s.scope_); @@ -61,9 +57,16 @@ Music_output_def::mark_smob (SCM m) Music_output_def * mo = (Music_output_def*) SCM_CELL_WORD_1 (m); if (mo->translator_tab_) scm_gc_mark (mo->translator_tab_->self_scm ()); - scm_gc_mark (mo->scope_); - return mo->scaled_fonts_; + mo->derived_mark (); + + return mo->scope_; +} + +void +Music_output_def::derived_mark () +{ + } void diff --git a/lily/paper-book.cc b/lily/paper-book.cc index ae8e547c1c..4ad319e120 100644 --- a/lily/paper-book.cc +++ b/lily/paper-book.cc @@ -86,13 +86,13 @@ Page::Page (Paper_def *paper, int number) lines_ = SCM_EOL; line_count_ = 0; - hsize_ = paper->get_realvar (ly_symbol2scm ("hsize")); - vsize_ = paper->get_realvar (ly_symbol2scm ("vsize")); - top_margin_ = paper->get_realvar (ly_symbol2scm ("top-margin")); - bottom_margin_ = paper->get_realvar (ly_symbol2scm ("bottom-margin")); - head_sep_ = paper->get_realvar (ly_symbol2scm ("head-sep")); - foot_sep_ = paper->get_realvar (ly_symbol2scm ("foot-sep")); - text_width_ = paper->get_realvar (ly_symbol2scm ("linewidth")); + hsize_ = paper->get_dimension (ly_symbol2scm ("hsize")); + vsize_ = paper->get_dimension (ly_symbol2scm ("vsize")); + top_margin_ = paper->get_dimension (ly_symbol2scm ("top-margin")); + bottom_margin_ = paper->get_dimension (ly_symbol2scm ("bottom-margin")); + head_sep_ = paper->get_dimension (ly_symbol2scm ("head-sep")); + foot_sep_ = paper->get_dimension (ly_symbol2scm ("foot-sep")); + text_width_ = paper->get_dimension (ly_symbol2scm ("linewidth")); left_margin_ = (hsize_ - text_width_) / 2; copyright_ = SCM_EOL; diff --git a/lily/paper-def.cc b/lily/paper-def.cc index 144a944a61..ffcc2409d1 100644 --- a/lily/paper-def.cc +++ b/lily/paper-def.cc @@ -30,6 +30,11 @@ Paper_def::Paper_def () { + scaled_fonts_ = SCM_EOL; + /* + don't remove above statement, scm_make_hash_table may trigger GC. + */ + scaled_fonts_ = scm_c_make_hash_table (11); } Paper_def::~Paper_def () @@ -39,10 +44,21 @@ Paper_def::~Paper_def () Paper_def::Paper_def (Paper_def const&src) : Music_output_def (src) { + scaled_fonts_ = SCM_EOL; + /* + don't remove above statement, scm_make_hash_table may trigger GC. + */ + scaled_fonts_ = scm_c_make_hash_table (11); +} + +void +Paper_def::derived_mark () +{ + scm_gc_mark (scaled_fonts_); } Real -Paper_def::get_realvar (SCM s) const +Paper_def::get_dimension (SCM s) const { SCM val = lookup_variable (s); SCM scale = lookup_variable (ly_symbol2scm ("outputscale")); @@ -58,8 +74,8 @@ Paper_def::get_realvar (SCM s) const Interval Paper_def::line_dimensions_int (int n) const { - Real lw = get_realvar (ly_symbol2scm ("linewidth")); - Real ind = n? 0.0:get_realvar (ly_symbol2scm ("indent")); + Real lw = get_dimension (ly_symbol2scm ("linewidth")); + Real ind = n? 0.0:get_dimension (ly_symbol2scm ("indent")); return Interval (ind, lw); } @@ -83,29 +99,53 @@ Paper_def::get_paper_outputter (String outname) const } -/* - Todo: use symbols and hashtable idx? -*/ + Font_metric * -Paper_def::find_font (SCM fn, Real m) +Paper_def::find_scaled_font (Font_metric *f, Real m) { - SCM key = gh_cons (fn, gh_double2scm (m)); - SCM met = scm_assoc (key, scaled_fonts_); - - if (gh_pair_p (met)) - return unsmob_metrics (ly_cdr (met)); + SCM sizes = scm_hashq_ref (scaled_fonts_, f->self_scm (), SCM_BOOL_F); + if (sizes != SCM_BOOL_F) + { + SCM met = scm_assoc (gh_double2scm (m), sizes); + if (gh_pair_p (met)) + return unsmob_metrics (ly_cdr (met)); + } + else + { + sizes = SCM_EOL; + } + /* Hmm. We're chaining font - metrics. Should consider wether to merge virtual-font and scaled_font. - */ - Font_metric* f=0; - if (gh_list_p (fn)) + */ + SCM val = SCM_EOL; + if (Virtual_font_metric * vf = dynamic_cast (f)) { - f = new Virtual_font_metric (fn, m, this); // TODO: GC protection. - - scaled_fonts_ = scm_acons (key, f->self_scm (), scaled_fonts_); - scm_gc_unprotect_object (f->self_scm ()); + /* + 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 l = SCM_EOL; + SCM *t = &l; + for (SCM s = vf->get_font_list (); gh_pair_p (s); s = gh_cdr (s)) + { + Font_metric*scaled + = find_scaled_font (unsmob_metrics (gh_car (s)), m); + *t = scm_cons (scaled->self_scm (), SCM_EOL); + t = SCM_CDRLOC(*t); + } + + vf = new Virtual_font_metric (l); + val = vf->self_scm (); } else { @@ -113,34 +153,38 @@ Paper_def::find_font (SCM fn, Real m) m /= gh_scm2double (scm_variable_ref (scale_var)); - f = all_fonts_global->find_font (ly_scm2string (fn)); - SCM val = Scaled_font_metric::make_scaled_font_metric (f, m); - scaled_fonts_ = scm_acons (key, val, scaled_fonts_); - scm_gc_unprotect_object (val); - - f = unsmob_metrics (val); + val = Scaled_font_metric::make_scaled_font_metric (f, m); } - return f; + sizes = scm_acons (gh_double2scm (m), 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 +Paper_def::font_descriptions () const { + SCM func = ly_scheme_function ("hash-table->alist"); + SCM l = SCM_EOL; - for (SCM s = scaled_fonts_; gh_pair_p (s); s = ly_cdr (s)) + for (SCM s = scm_call_1 (func, scaled_fonts_); gh_pair_p (s); s = ly_cdr (s)) { - SCM desc = ly_caar (s); - if (!gh_string_p (gh_car (desc))) - continue ; - - SCM mdesc = unsmob_metrics (ly_cdar (s))->description_; - - l = gh_cons (gh_cons (mdesc, desc), l); + SCM entry = gh_car (s); + for (SCM t = gh_cdr (entry); gh_pair_p (t); t = gh_cdr (t)) + { + Font_metric *fm= unsmob_metrics (gh_cdar (t)); + + if (dynamic_cast (fm)) + l = gh_cons (fm->self_scm (), l); + } } return l; } diff --git a/lily/paper-outputter.cc b/lily/paper-outputter.cc index 4882386cfc..a433270322 100644 --- a/lily/paper-outputter.cc +++ b/lily/paper-outputter.cc @@ -155,7 +155,15 @@ Paper_outputter::output_header (Paper_def *paper, SCM scopes, int page_count) output_music_output_def (paper); output_scheme (scm_list_1 (ly_symbol2scm ("header-end"))); - output_scheme (scm_list_2 (ly_symbol2scm ("define-fonts"), + + /* + TODO: maybe have Scheme extract the fonts directly from \paper? + + Alternatively, we could simply load the fonts on demand in the + output, and do away with this define-fonts step. + */ + output_scheme (scm_list_3 (ly_symbol2scm ("define-fonts"), + paper->self_scm (), ly_quote_scm (paper->font_descriptions ()))); } diff --git a/lily/staff-symbol-referencer.cc b/lily/staff-symbol-referencer.cc index 0a2b4faeec..37004624c7 100644 --- a/lily/staff-symbol-referencer.cc +++ b/lily/staff-symbol-referencer.cc @@ -56,7 +56,7 @@ Staff_symbol_referencer::line_thickness (Grob *me) Grob *st = get_staff_symbol (me); if (st) return Staff_symbol::get_line_thickness (st); - return me->get_paper ()->get_realvar (ly_symbol2scm ("linethickness")); + return me->get_paper ()->get_dimension (ly_symbol2scm ("linethickness")); } Real diff --git a/lily/staff-symbol.cc b/lily/staff-symbol.cc index 616cf613e9..744beabe60 100644 --- a/lily/staff-symbol.cc +++ b/lily/staff-symbol.cc @@ -64,7 +64,7 @@ Staff_symbol::print (SCM smob) while (flip (&d) !=LEFT); - Real t = me->get_paper ()->get_realvar (ly_symbol2scm ("linethickness")); + Real t = me->get_paper ()->get_dimension (ly_symbol2scm ("linethickness")); t *= robust_scm2double (me->get_property ("thickness"), 1.0); int l = Staff_symbol::line_count (me); @@ -110,7 +110,7 @@ Staff_symbol::staff_space (Grob*me) Real Staff_symbol::get_line_thickness (Grob* me) { - Real lt = me->get_paper ()->get_realvar (ly_symbol2scm ("linethickness")); + Real lt = me->get_paper ()->get_dimension (ly_symbol2scm ("linethickness")); return robust_scm2double (me->get_property ("thickness"), 1.0) * lt; } diff --git a/lily/stem-tremolo.cc b/lily/stem-tremolo.cc index d8c08c7bd9..48192b952e 100644 --- a/lily/stem-tremolo.cc +++ b/lily/stem-tremolo.cc @@ -82,7 +82,7 @@ Stem_tremolo::raw_stencil (Grob *me) Real ss = Staff_symbol_referencer::staff_space (me); Real thick = robust_scm2double (me->get_property ("beam-thickness"),1); Real width = robust_scm2double (me->get_property ("beam-width"),1); - Real blot = me->get_paper ()->get_realvar (ly_symbol2scm ("blotdiameter")); + Real blot = me->get_paper ()->get_dimension (ly_symbol2scm ("blotdiameter")); width *= ss; thick *= ss; diff --git a/lily/stem.cc b/lily/stem.cc index be9c8a265b..68c437ab1c 100644 --- a/lily/stem.cc +++ b/lily/stem.cc @@ -743,7 +743,7 @@ Stem::print (SCM smob) // URG Real stem_width = thickness (me); Real blot = - me->get_paper ()->get_realvar (ly_symbol2scm ("blotdiameter")); + me->get_paper ()->get_dimension (ly_symbol2scm ("blotdiameter")); Box b = Box (Interval (-stem_width/2, stem_width/2), Interval (stem_y[DOWN]*dy, stem_y[UP]*dy)); diff --git a/lily/stencil-scheme.cc b/lily/stencil-scheme.cc index 79ab518636..c920f639a0 100644 --- a/lily/stencil-scheme.cc +++ b/lily/stencil-scheme.cc @@ -217,7 +217,7 @@ fontify_atom (Font_metric const *met, SCM f) return f; else return scm_list_n (ly_symbol2scm ("fontify"), - ly_quote_scm (met->description_), f, SCM_UNDEFINED); + met->self_scm (), f, SCM_UNDEFINED); } LY_DEFINE (ly_fontify_atom,"ly:fontify-atom", diff --git a/lily/system-start-delimiter.cc b/lily/system-start-delimiter.cc index e61fa4e718..15d53268e6 100644 --- a/lily/system-start-delimiter.cc +++ b/lily/system-start-delimiter.cc @@ -62,7 +62,7 @@ Will not fix it since I'm not sure. Stencil System_start_delimiter::simple_bar (Grob*me,Real h) { - Real lt =me->get_paper ()->get_realvar (ly_symbol2scm ("linethickness")) ; + Real lt =me->get_paper ()->get_dimension (ly_symbol2scm ("linethickness")) ; Real w = lt * robust_scm2double (me->get_property ("thickness"), 1); return Lookup::round_filled_box (Box (Interval (0,w), Interval (-h/2, h/2)), lt); diff --git a/lily/tfm.cc b/lily/tfm.cc index 5529c0b189..5193af2978 100644 --- a/lily/tfm.cc +++ b/lily/tfm.cc @@ -133,3 +133,9 @@ Tex_font_metric::make_tfm (String fn) return tfm->self_scm (); } + +Real +Tex_font_metric::design_size ()const +{ + return info_.design_size; +} diff --git a/lily/vaticana-ligature-engraver.cc b/lily/vaticana-ligature-engraver.cc index 8fd1a60d90..77786a376f 100644 --- a/lily/vaticana-ligature-engraver.cc +++ b/lily/vaticana-ligature-engraver.cc @@ -155,7 +155,7 @@ Vaticana_ligature_engraver::align_heads (Array primitives, dynamic_cast (primitives[0].grob_)->get_column (); Real join_thickness = - thickness * column->get_paper ()->get_realvar (ly_symbol2scm ("linethickness")); + thickness * column->get_paper ()->get_dimension (ly_symbol2scm ("linethickness")); /* * Amount of extra space two put between some particular diff --git a/lily/vaticana-ligature.cc b/lily/vaticana-ligature.cc index 169be2404a..e5e98d2c47 100644 --- a/lily/vaticana-ligature.cc +++ b/lily/vaticana-ligature.cc @@ -230,10 +230,10 @@ vaticana_brew_primitive (Grob *me, bool ledger_take_space) Real thickness = robust_scm2double ( me->get_property ("thickness"), 1); Real line_thickness = - thickness * me->get_paper ()->get_realvar (ly_symbol2scm ("linethickness")); + thickness * me->get_paper ()->get_dimension (ly_symbol2scm ("linethickness")); Real blotdiameter = - (me->get_paper ()->get_realvar (ly_symbol2scm ("blotdiameter"))); + (me->get_paper ()->get_dimension (ly_symbol2scm ("blotdiameter"))); int pos = Staff_symbol_referencer::get_rounded_position (me); diff --git a/lily/virtual-font-metric.cc b/lily/virtual-font-metric.cc index ba4580e929..f34c1de032 100644 --- a/lily/virtual-font-metric.cc +++ b/lily/virtual-font-metric.cc @@ -17,21 +17,42 @@ source file of the GNU LilyPond music typesetter /* passing DEF is ughish. Should move into paperdef? */ -Virtual_font_metric::Virtual_font_metric (SCM name_list, - Real mag,Paper_def*def) +Virtual_font_metric::Virtual_font_metric (SCM font_list) { font_list_ = SCM_EOL; SCM *tail = &font_list_; - for (SCM s = name_list; gh_pair_p (s); s = gh_cdr (s)) + + SCM mag = SCM_EOL; + SCM name_list = SCM_EOL; + SCM *name_tail = &name_list; + + for (SCM s = font_list; gh_pair_p (s); s = gh_cdr (s)) { - SCM nm = gh_car (s); + if (Font_metric*fm = unsmob_metrics (gh_car (s))) + { + *tail = scm_cons (gh_car (s),SCM_EOL); + tail = SCM_CDRLOC (*tail); - Font_metric *fm = def->find_font (nm, mag); - *tail = scm_cons (fm->self_scm (),SCM_EOL); - tail = SCM_CDRLOC (*tail); + if (!gh_number_p (mag)) + { + mag = gh_cdr (fm->description_); // ugh. + } + + *name_tail = scm_cons (gh_car (fm->description_), SCM_EOL); + name_tail = SCM_CDRLOC (*name_tail); + } } + + description_ = scm_cons (name_list, mag); } +Real +Virtual_font_metric::design_size () const +{ + return unsmob_metrics (gh_car (font_list_))-> design_size (); +} + + void Virtual_font_metric::derived_mark ()const { @@ -154,4 +175,19 @@ Virtual_font_metric::get_indexed_char_stencil (int code) const return m; } - + + +SCM +Virtual_font_metric::get_font_list () const +{ + return font_list_; +} + +LY_DEFINE (ly_make_virtual_font, "ly:make-virtual-font", 0, 0, 1, + (SCM args), + "Make a virtual font metric from @var{args}, a list of font objects.") +{ + Virtual_font_metric *fm = new Virtual_font_metric (args); + + return scm_gc_unprotect_object (fm->self_scm ()); +} diff --git a/scm/font.scm b/scm/font.scm index ffe7b00ce5..1f1023514e 100644 --- a/scm/font.scm +++ b/scm/font.scm @@ -146,41 +146,60 @@ (list (cons 'font-encoding (car x))) (cons (* factor (cadr x)) (caddr x)))) - '((number 10 - #((3.82 . "feta-nummer4") - (5.5 . "feta-nummer6") - (8.0 . "feta-nummer8") - (10.0 . "feta-nummer10") - (12.0 . "feta-nummer12") - (16.0 . "feta-nummer16"))) - (dynamic 14.0 #((6.0 . "feta-din6") - (8.0 . "feta-din8") - (10.0 . "feta-din10") - (12.0 . "feta-din12") - (14.0 . "feta-din14") - (17.0 . "feta-din17") + `((number 10 + #(,(delay (ly:font-load "feta-nummer4")) + ,(delay (ly:font-load "feta-nummer6")) + ,(delay (ly:font-load "feta-nummer8")) + ,(delay (ly:font-load "feta-nummer10")) + ,(delay (ly:font-load "feta-nummer12")) + ,(delay (ly:font-load "feta-nummer16")))) + (dynamic 14.0 #(,(delay (ly:font-load "feta-din6")) + ,(delay (ly:font-load "feta-din8")) + ,(delay (ly:font-load "feta-din10")) + ,(delay (ly:font-load "feta-din12")) + ,(delay (ly:font-load "feta-din14")) + ,(delay (ly:font-load "feta-din17")) )) - (math 10 #((10.0 . "msam10"))) + (math 10 #(,(delay (ly:font-load "msam10")))) (music 20.0 - #((11.22 . ("feta11" "parmesan11")) - (12.60 . ("feta13" "parmesan13")) - (14.14 . ("feta14" "parmesan14")) - (15.87 . ("feta16" "parmesan16")) - (17.82 . ("feta18" "parmesan18")) - (20.0 . ("feta20" "parmesan20")) - (22.45 . ("feta23" "parmesan23")) - (25.20 . ("feta26" "parmesan26")) + #(,(delay (ly:make-virtual-font + (ly:font-load "feta11") + (ly:font-load "parmesan11"))) + ,(delay (ly:make-virtual-font + (ly:font-load "feta13") + (ly:font-load "parmesan13"))) + ,(delay (ly:make-virtual-font + (ly:font-load "feta14") + (ly:font-load "parmesan14"))) + ,(delay (ly:make-virtual-font + (ly:font-load "feta16") + (ly:font-load "parmesan16"))) + ,(delay (ly:make-virtual-font + (ly:font-load "feta18") + (ly:font-load "parmesan18"))) + ,(delay (ly:make-virtual-font + (ly:font-load "feta20") + (ly:font-load "parmesan20"))) + ,(delay (ly:make-virtual-font + (ly:font-load "feta23") + (ly:font-load "parmesan23"))) + ,(delay (ly:make-virtual-font + (ly:font-load "feta26") + (ly:font-load "parmesan26"))) )) - (braces 10 #((10.0 . ("feta-braces00" - "feta-braces10" - "feta-braces20" - "feta-braces30" - "feta-braces40" - "feta-braces50" - "feta-braces60" - "feta-braces70" - "feta-braces80")) - )))) + + (braces 10 #(,(delay + (ly:make-virtual-font + (ly:font-load "feta-braces00") + (ly:font-load "feta-braces10") + (ly:font-load "feta-braces20") + (ly:font-load "feta-braces30") + (ly:font-load "feta-braces40") + (ly:font-load "feta-braces50") + (ly:font-load "feta-braces60") + (ly:font-load "feta-braces70") + (ly:font-load "feta-braces80")) + ))))) (for-each (lambda (x) @@ -193,48 +212,48 @@ (cons (* factor (cadr x)) (cddr x)) )) - '((#(roman upright medium) . - (10.0 . #((6.0 . "cmr6") - (8.0 . "cmr8") - (10.0 . "cmr10") - (17.0 . "cmr17") + `((#(roman upright medium) . + (10.0 . #(,(delay (ly:font-load "cmr6")) + ,(delay (ly:font-load "cmr8")) + ,(delay (ly:font-load "cmr10")) + ,(delay (ly:font-load "cmr17")) ))) (#(roman upright bold) . - (10.0 . #((6.0 . "cmbx6") - (8.0 . "cmbx8") - (10.0 . "cmbx10") - (12.0 . "cmbx12") + (10.0 . #(,(delay (ly:font-load "cmbx6")) + ,(delay (ly:font-load "cmbx8")) + ,(delay (ly:font-load "cmbx10")) + ,(delay (ly:font-load "cmbx12")) ))) (#(roman italic medium) . - (10.0 . #((7.0 . "cmti7") - (10.0 . "cmti10") - (12.0 . "cmti12") + (10.0 . #(,(delay (ly:font-load "cmti7")) + ,(delay (ly:font-load "cmti10")) + ,(delay (ly:font-load "cmti12")) ))) (#(roman italic bold) . - (10.0 . #((8.0 . "cmbxti8") - (10.0 . "cmbxti10") - (14.0 . "cmbxti14") + (10.0 . #(,(delay (ly:font-load "cmbxti8")) + ,(delay (ly:font-load "cmbxti10")) + ,(delay (ly:font-load "cmbxti14")) ))) (#(roman caps medium) . - (10.0 . #((10.0 . "cmcsc10")))) + (10.0 . #(,(delay (ly:font-load "cmcsc10"))))) (#(roman upright bold-narrow ) . - (10.0 . #((10.0 . "cmb10") + (10.0 . #(,(delay (ly:font-load "cmb10")) ))) (#(sans upright medium) . - (10.0 . #((8.0 . "cmss8") - (10.0 . "cmss10") - (12.0 . "cmss12") - (17.0 . "cmss17") + (10.0 . #(,(delay (ly:font-load "cmss8")) + ,(delay (ly:font-load "cmss10")) + ,(delay (ly:font-load "cmss12")) + ,(delay (ly:font-load "cmss17")) ))) (#(typewriter upright medium) . - (10.0 . #((8.0 . "cmtt8") - (10.0 . "cmtt10") - (12.0 . "cmtt12") + (10.0 . #(,(delay (ly:font-load "cmtt8")) + ,(delay (ly:font-load "cmtt10")) + ,(delay (ly:font-load "cmtt12")) ))) )) n)) diff --git a/scm/output-lib.scm b/scm/output-lib.scm index 3c55c43659..c88dd2a033 100644 --- a/scm/output-lib.scm +++ b/scm/output-lib.scm @@ -20,7 +20,7 @@ (list-ref tuning (- string 1) ; remove 1 because list index starts at 0 and guitar string at 1. ) - ) ) ) + ))) (define-public (hammer-print-function grob) (let* ((note-collums (ly:grob-property grob 'note-columns)) diff --git a/scm/output-ps.scm b/scm/output-ps.scm index f3f2cc97b5..d4918db3a1 100644 --- a/scm/output-ps.scm +++ b/scm/output-ps.scm @@ -198,15 +198,15 @@ (else fontname))) ;; (define (font-load-command name-mag command) - (define (font-load-command lst) + (define (font-load-command fonts) (let* ((key-name-size (car lst)) (value (cdr lst)) (value-name-size (car value)) - (command (cdr value)) - (fontname (car value-name-size)) + (command (font-command font)) + (fontname (ly:font-name font)) (mangled (possibly-mangle-fontname fontname)) (encoding (assoc-get fontname font-encoding-alist)) - (designsize (fontname->designsize fontname)) + (designsize (ly:font-design-size font)) (fontsize (cdr value-name-size)) (scaling (* fontsize designsize))) diff --git a/scm/output-tex.scm b/scm/output-tex.scm index 7f8259d4a4..344c40e04b 100644 --- a/scm/output-tex.scm +++ b/scm/output-tex.scm @@ -10,10 +10,11 @@ (define-module (scm output-tex) #:re-export (quote) #:export (define-fonts + font-command + fontify unknown output-paper-def output-scopes - select-font blank dot beam @@ -61,40 +62,32 @@ ;;;;;;;; DOCUMENT ME! ;;;;;;;; -(define font-name-alist '()) - -(define (tex-encoded-fontswitch name-mag) - (let* ((iname-mag (car name-mag)) - (ename-mag (cdr name-mag))) - - (cons iname-mag - (cons ename-mag - (string-append "magfont" - (string-encode-integer - (hashq (car ename-mag) 1000000)) - "m" - (string-encode-integer - (inexact->exact (round (* 1000 (cdr ename-mag)))))))))) - -(define-public (define-fonts internal-external-name-mag-pairs) - (set! font-name-alist (map tex-encoded-fontswitch - internal-external-name-mag-pairs)) +(define (font-command font) + (string-append + "magfont" + (string-encode-integer + (hashq (ly:font-name font) 1000000)) + "m" + (string-encode-integer + (inexact->exact (round (* 1000 (ly:font-magnification font))))))) + +(define (define-fonts paper font-list) (apply string-append (map (lambda (x) - (font-load-command (car x) (cdr x))) - (map cdr font-name-alist)))) + (font-load-command paper x)) + font-list) + )) ;; ;; urg, how can exp be #unspecified? -- in sketch output ;; ;; set! returns # --hwn ;; -(define-public (fontify name-mag-pair exp) - (string-append (select-font name-mag-pair) +(define (fontify font exp) + (string-append "\\" (font-command font) exp)) - -(define-public (unknown) +(define (unknown) "%\n\\unknown\n") (define (symbol->tex-key sym) @@ -157,15 +150,6 @@ (apply string-append (map output-scope scopes))) -(define (select-font name-mag-pair) - (let ((c (assoc name-mag-pair font-name-alist))) - (if c - (string-append "\\" (cddr c)) - (begin - (ly:warn - (format "Programming error: No such font: ~S" name-mag-pair)) - "")))) - (define (blank) "") @@ -193,12 +177,15 @@ (define (symmetric-x-triangle t w h) (embedded-ps (list 'symmetric-x-triangle t w h))) -(define (font-load-command name-mag command) +(define (font-load-command paper font) (string-append - "\\font\\" command "=" - (car name-mag) + "\\font\\" (font-command font) "=" + (ly:font-name font) " scaled " - (ly:number->string (inexact->exact (round (* 1000 (cdr name-mag))))) + (ly:number->string (inexact->exact + (round (* 1000 + (ly:font-magnification font) + (ly:paper-lookup paper 'outputscale))))) "\n")) (define (ez-ball c l b) @@ -277,7 +264,7 @@ "\n\\" s "{" (ly:inexact->string i 10) "}" )) ;; FIXME: explain ploblem: need to do something to make this really safe. -(define-public (output-tex-string s) +(define (output-tex-string s) (if safe-mode? (regexp-substitute/global #f "\\\\" s 'pre "$\\backslash$" 'post) s)) -- 2.39.5