Use scalar instead of embedded_scm for context mod overrides.
[lilypond/mpolesky.git] / lily / modified-font-metric.cc
blob71b532d61883fb64d2ca4fc1906686c7d008bfc8
1 /*
2 modified-font-metric.cc -- declare Modified_font_metric
4 source file of the GNU LilyPond music typesetter
6 (c) 1999--2009 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
8 #include <cctype>
9 using namespace std;
11 #include "modified-font-metric.hh"
12 #include "pango-font.hh"
13 #include "warn.hh"
14 #include "stencil.hh"
15 #include "main.hh"
16 #include "program-option.hh"
18 Modified_font_metric::Modified_font_metric (Font_metric *fm,
19 Real magnification)
21 magnification_ = magnification;
23 SCM desc = fm->description_;
25 Real total_mag = magnification * scm_to_double (scm_cdr (desc));
26 assert (total_mag);
28 description_ = scm_cons (scm_car (desc), scm_from_double (total_mag));
29 orig_ = fm;
32 SCM
33 Modified_font_metric::make_scaled_font_metric (Font_metric *fm, Real scaling)
35 Modified_font_metric *sfm = new Modified_font_metric (fm, scaling);
36 return sfm->self_scm ();
39 Real
40 Modified_font_metric::design_size () const
42 return orig_->design_size ();
45 Box
46 Modified_font_metric::get_indexed_char (vsize i) const
48 Box b = orig_->get_indexed_char (i);
49 b.scale (magnification_);
50 return b;
53 Box
54 Modified_font_metric::get_ascii_char (vsize i) const
56 Box b = orig_->get_ascii_char (i);
57 b.scale (magnification_);
58 return b;
61 vsize
62 Modified_font_metric::count () const
64 return orig_->count ();
67 Offset
68 Modified_font_metric::attachment_point (string s) const
70 Offset o = orig_->attachment_point (s);
71 return o * magnification_;
74 Offset
75 Modified_font_metric::get_indexed_wxwy (vsize k) const
77 Offset o = orig_->get_indexed_wxwy (k);
78 return o * magnification_;
81 vsize
82 Modified_font_metric::name_to_index (string s) const
84 return orig_->name_to_index (s);
87 vsize
88 Modified_font_metric::index_to_charcode (vsize i) const
90 return orig_->index_to_charcode (i);
93 vsize
94 Modified_font_metric::index_to_ascii (vsize k) const
96 return orig_->index_to_ascii (k);
99 void
100 Modified_font_metric::derived_mark () const
104 Stencil
105 Modified_font_metric::text_stencil (string text, bool feta) const
107 Box b;
108 if (Pango_font *pf = dynamic_cast<Pango_font *> (orig_))
110 Stencil stc = pf->text_stencil (text, feta);
112 Box b = stc.extent_box ();
114 b.scale (magnification_);
115 Stencil scaled (b, stc.expr ());
116 return scaled;
119 return Font_metric::text_stencil (text, feta);
123 Modified_font_metric::text_dimension (string text) const
125 Box b;
126 Interval ydims;
127 Real w = 0.0;
129 for (ssize i = 0; i < text.length (); i++)
131 Box b = get_ascii_char ((unsigned char)text[i]);
133 w += b[X_AXIS].length ();
134 ydims.unite (b[Y_AXIS]);
136 if (ydims.is_empty ())
137 ydims = Interval (0, 0);
139 b = Box (Interval (0, w), ydims);
140 return b;
143 Font_metric *
144 Modified_font_metric::original_font () const
146 return orig_;
150 Modified_font_metric::sub_fonts () const
152 return orig_->sub_fonts ();
155 string
156 Modified_font_metric::font_name () const
158 return original_font ()->font_name ();