2 font-metric.cc -- implement Font_metric
4 source file of the GNU LilyPond music typesetter
6 (c) 1999--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 Mats Bengtsson <matsb@s3.kth.se> (the ugly TeX parsing in text_dimension)
14 #include "ly-smobs.icc"
15 #include "font-metric.hh"
19 Font_metric::text_dimension (String text) const
24 for (int i = 0; i < text.length_i (); i++)
30 for (i++; (i < text.length_i ()) && !isspace(text[i])
31 && text[i]!='{' && text[i]!='}'; i++)
34 i--; // Compensate for the increment in the outer loop!
36 case '{': // Skip '{' and '}'
41 Box b = get_char ((unsigned char)text[i],false);
43 // Ugh, use the width of 'x' for unknown characters
44 if (b[X_AXIS].length () == 0)
45 b = get_char ((unsigned char)'x',false);
47 w += b[X_AXIS].length ();
48 ydims.unite (b[Y_AXIS]);
53 ydims = Interval (0,0);
55 return Box(Interval (0, w), ydims);
60 Scaled_font_metric::text_dimension (String t) const
62 Real realmag = pow (1.2, magstep_i_);
63 Box b (orig_l_->text_dimension (t));
65 return Box(b[X_AXIS]* realmag, b[Y_AXIS]*realmag);
68 Font_metric::~Font_metric ()
73 Font_metric::Font_metric ()
80 Font_metric::Font_metric (Font_metric const &)
86 Font_metric::get_char (int, bool)const
88 return Box (Interval(0,0),Interval (0,0));
91 Scaled_font_metric::Scaled_font_metric (Font_metric* m, int s)
98 Font_metric::description () const
100 return gh_cons (name_, gh_int2scm (0));
105 Scaled_font_metric::description () const
107 SCM od = orig_l_->description ();
108 gh_set_cdr_x (od, gh_int2scm (magstep_i_));
114 Font_metric::do_smobify_self ()
119 Font_metric::mark_smob (SCM s)
121 Font_metric * m = SMOB_TO_TYPE(Font_metric, s);
126 Font_metric::print_smob (SCM s, SCM port, scm_print_state * )
128 Font_metric *m = unsmob_metrics (s);
129 scm_puts ("#<Font_metric ", port);
130 scm_display (m->name_, port);
131 scm_puts (">", port);
136 IMPLEMENT_UNSMOB (Font_metric, metrics);
137 IMPLEMENT_SMOBS (Font_metric);