2 modified-font-metric.cc -- declare Modified_font_metric
4 source file of the GNU LilyPond music typesetter
6 (c) 1999--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
10 #include "modified-font-metric.hh"
11 #include "pango-font.hh"
12 #include "text-metrics.hh"
18 Modified_font_metric::Modified_font_metric (Font_metric *fm,
21 magnification_ = magnification;
23 SCM desc = fm->description_;
25 Real total_mag = magnification * scm_to_double (scm_cdr (desc));
28 description_ = scm_cons (scm_car (desc), scm_from_double (total_mag));
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 ();
40 Modified_font_metric::design_size () const
42 return orig_->design_size ();
46 Modified_font_metric::get_indexed_char (int i) const
48 Box b = orig_->get_indexed_char (i);
49 b.scale (magnification_);
54 Modified_font_metric::get_ascii_char (int i) const
56 Box b = orig_->get_ascii_char (i);
57 b.scale (magnification_);
62 Modified_font_metric::count () const
64 return orig_->count ();
68 Modified_font_metric::attachment_point (String s) const
70 Offset o = orig_->attachment_point (s);
71 return o * magnification_;
75 Modified_font_metric::get_indexed_wxwy (int k) const
77 Offset o = orig_->get_indexed_wxwy (k);
78 return o * magnification_;
82 Modified_font_metric::name_to_index (String s) const
84 return orig_->name_to_index (s);
88 Modified_font_metric::index_to_charcode (int i) const
90 return orig_->index_to_charcode (i);
94 Modified_font_metric::index_to_ascii (int k) const
96 return orig_->index_to_ascii (k);
100 Modified_font_metric::derived_mark () const
104 /* TODO: put this klutchness behind ly:option switch. */
106 Modified_font_metric::tex_kludge (String text) const
110 for (int i = 0; i < text.length (); i++)
115 /* Accent marks use width of base letter */
116 if (i +1 < text.length ())
118 if (text[i + 1]=='\'' || text[i + 1]=='`' || text[i+1]=='"'
124 /* For string width \\ is a \ and \_ is a _. */
125 if (text[i + 1]=='\\' || text[i+1]=='_')
129 for (i++; (i < text.length ()) && !isspace (text[i])
130 && text[i]!='{' && text[i]!='}'; i++)
133 /* Compensate for the auto-increment in the outer loop. */
137 case '{': // Skip '{' and '}'
142 Box b = get_ascii_char ((unsigned char)text[i]);
144 /* Use the width of 'x' for unknown characters */
145 if (b[X_AXIS].length () == 0)
146 b = get_ascii_char ((unsigned char)'x');
148 w += b[X_AXIS].length ();
149 ydims.unite (b[Y_AXIS]);
154 if (ydims.is_empty ())
155 ydims = Interval (0, 0);
157 return Box (Interval (0, w), ydims);
161 Modified_font_metric::text_stencil (String text) const
164 if (Pango_font * pf = dynamic_cast<Pango_font*> (orig_))
166 Stencil stc = pf->text_stencil (text);
168 Box b = stc.extent_box ();
170 b.scale (magnification_);
171 Stencil scaled(b, stc.expr());
175 return Font_metric::text_stencil (text);
179 Modified_font_metric::text_dimension (String text) const
181 SCM stext = scm_makfrom0str (text.to_str0 ());
182 Box b = lookup_tex_text_dimension (orig_, stext);
183 if (!b[Y_AXIS].is_empty ())
185 b.scale (magnification_);
189 if (output_backend_global == "tex")
191 b = tex_kludge (text);
199 for (int i = 0; i < text.length (); i++)
201 Box b = get_ascii_char ((unsigned char)text[i]);
203 w += b[X_AXIS].length ();
204 ydims.unite (b[Y_AXIS]);
206 if (ydims.is_empty ())
207 ydims = Interval (0, 0);
209 b = Box (Interval (0, w), ydims);
214 Modified_font_metric::original_font () const
220 Modified_font_metric::sub_fonts () const
222 return orig_->sub_fonts ();
226 Modified_font_metric::font_name () const
228 return original_font ()->font_name ();