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)
15 #include "molecule.hh"
16 #include "ly-smobs.icc"
17 #include "font-metric.hh"
21 Font_metric::text_dimension (String text) const
26 for (int i = 0; i < text.length_i (); i++)
32 for (i++; (i < text.length_i ()) && !isspace(text[i])
33 && text[i]!='{' && text[i]!='}'; i++)
36 i--; // Compensate for the increment in the outer loop!
38 case '{': // Skip '{' and '}'
43 Box b = get_char ((unsigned char)text[i]);
45 // Ugh, use the width of 'x' for unknown characters
46 if (b[X_AXIS].length () == 0)
47 b = get_char ((unsigned char)'x');
49 w += b[X_AXIS].length ();
50 ydims.unite (b[Y_AXIS]);
55 ydims = Interval (0,0);
57 return Box(Interval (0, w), ydims);
62 Font_metric::~Font_metric ()
66 Font_metric::Font_metric ()
68 description_ = SCM_EOL;
73 Font_metric::Font_metric (Font_metric const &s)
79 Font_metric::get_char (int )const
81 return Box (Interval(0,0),Interval (0,0));
86 Font_metric::mark_smob (SCM s)
88 Font_metric * m = (Font_metric*) SCM_CELL_WORD_1(s);
89 return m->description_;
93 Font_metric::print_smob (SCM s, SCM port, scm_print_state * )
95 Font_metric *m = unsmob_metrics (s);
96 scm_puts ("#<Font_metric ", port);
97 scm_write (m->description_, port);
103 IMPLEMENT_UNSMOB (Font_metric, metrics);
104 IMPLEMENT_SMOBS (Font_metric);
105 IMPLEMENT_DEFAULT_EQUAL_P(Font_metric);
106 IMPLEMENT_TYPE_P (Font_metric, "font-metric?");
109 Font_metric::find_by_name (String) const
117 ly_find_glyph_by_name (SCM font, SCM name)
119 if (!unsmob_metrics (font) || !gh_string_p (name))
121 warning ("ly-find-glyph-by-name: invalid argument.");
123 return m.smobbed_copy ();
126 return unsmob_metrics (font)->find_by_name (ly_scm2string (name)).smobbed_copy ();
133 scm_make_gsubr ("ly-find-glyph-by-name", 2 , 0, 0, (Scheme_function_unknown) ly_find_glyph_by_name);
136 ADD_SCM_INIT_FUNC(font_metric_init, font_metric_init);