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 "molecule.hh"
15 #include "ly-smobs.icc"
16 #include "font-metric.hh"
20 Font_metric::text_dimension (String text) const
25 for (int i = 0; i < text.length_i (); i++)
31 for (i++; (i < text.length_i ()) && !isspace(text[i])
32 && text[i]!='{' && text[i]!='}'; i++)
35 i--; // Compensate for the increment in the outer loop!
37 case '{': // Skip '{' and '}'
42 Box b = get_char ((unsigned char)text[i]);
44 // Ugh, use the width of 'x' for unknown characters
45 if (b[X_AXIS].length () == 0)
46 b = get_char ((unsigned char)'x');
48 w += b[X_AXIS].length ();
49 ydims.unite (b[Y_AXIS]);
54 ydims = Interval (0,0);
56 return Box(Interval (0, w), ydims);
61 Scaled_font_metric::text_dimension (String t) const
63 Box b (orig_l_->text_dimension (t));
65 b.scale (magnification_f_);
69 Font_metric::~Font_metric ()
73 Font_metric::Font_metric ()
75 description_ = SCM_EOL;
80 Font_metric::Font_metric (Font_metric const &)
86 Font_metric::get_char (int )const
88 return Box (Interval(0,0),Interval (0,0));
93 Font_metric::mark_smob (SCM s)
95 Font_metric * m = (Font_metric*) SCM_CELL_WORD_1(s);
96 return m->description_;
100 Font_metric::print_smob (SCM s, SCM port, scm_print_state * )
102 Font_metric *m = unsmob_metrics (s);
103 scm_puts ("#<Font_metric ", port);
104 scm_write (m->description_, port);
105 scm_puts (">", port);
110 IMPLEMENT_UNSMOB (Font_metric, metrics);
111 IMPLEMENT_SMOBS (Font_metric);
112 IMPLEMENT_DEFAULT_EQUAL_P(Font_metric);
113 IMPLEMENT_TYPE_P (Font_metric, "font-metric?");
116 Font_metric::find_by_name (String) const