lilypond-1.3.11
[lilypond.git] / lily / font-metric.cc
blob8c8a8e31a7f28e6062ff505971fc5ab0da123f12
1 /*
2 font-metric.cc -- implement Font_metric
4 source file of the GNU LilyPond music typesetter
6 (c) 1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 */
10 #include <math.h>
11 #include <ctype.h>
14 #include "font-metric.hh"
16 Box
17 Font_metric::text_dimension (String text) const
19 Interval ydims;
20 Real w=0.0;
22 for (int i = 0; i < text.length_i (); i++)
25 if (text[i]=='\\')
27 for (i++; (i < text.length_i ()) && isalpha(text[i]); i++)
29 // ugh.
30 i--; // Compensate for the increment in the outer loop!
32 else
34 Character_metric const *c = get_char ((unsigned char)text[i],false);
36 // Ugh, use the width of 'x' for unknown characters
37 if (c->dimensions()[X_AXIS].length () == 0)
38 c = get_char ((unsigned char)'x',false);
40 w += c->dimensions()[X_AXIS].length ();
41 ydims.unite (c->dimensions()[Y_AXIS]);
44 if (ydims.empty_b ())
45 ydims = Interval (0,0);
47 return Box(Interval (0, w), ydims);
51 Box
52 Scaled_font_metric::text_dimension (String t) const
54 Real realmag = pow (1.2, magstep_i_);
55 Box b (orig_l_->text_dimension (t));
57 return Box(b[X_AXIS]* realmag, b[Y_AXIS]*realmag);
61 Box
62 Character_metric::dimensions () const
64 return Box(Interval(0,0), Interval(0,0));
67 Font_metric::~Font_metric ()
71 Character_metric::~Character_metric()
75 Character_metric const *
76 Font_metric::get_char (int, bool)const
78 return 0;
81 Scaled_font_metric::Scaled_font_metric (Font_metric* m, int s)
83 magstep_i_ = s;
84 orig_l_ = m;
87 SCM
88 Font_metric::description () const
90 return gh_cons (ly_symbol2scm (name_str_.ch_C()), gh_int2scm (0));
94 SCM
95 Scaled_font_metric::description () const
97 SCM od = orig_l_->description ();
98 gh_set_cdr_x (od, gh_int2scm (magstep_i_));
99 return od;