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>
13 #include "ly-smobs.icc"
14 #include "font-metric.hh"
17 Font_metric::text_dimension (String text
) const
22 for (int i
= 0; i
< text
.length_i (); i
++)
27 for (i
++; (i
< text
.length_i ()) && isalpha(text
[i
]); i
++)
30 i
--; // Compensate for the increment in the outer loop!
34 Box b
= get_char ((unsigned char)text
[i
],false);
36 // Ugh, use the width of 'x' for unknown characters
37 if (b
[X_AXIS
].length () == 0)
38 b
= get_char ((unsigned char)'x',false);
40 w
+= b
[X_AXIS
].length ();
41 ydims
.unite (b
[Y_AXIS
]);
45 ydims
= Interval (0,0);
47 return Box(Interval (0, w
), ydims
);
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
);
60 Font_metric::~Font_metric ()
65 Font_metric::Font_metric ()
72 Font_metric::Font_metric (Font_metric
const &)
79 Font_metric::get_char (int, bool)const
81 return Box (Interval(0,0),Interval (0,0));
84 Scaled_font_metric::Scaled_font_metric (Font_metric
* m
, int s
)
91 Font_metric::description () const
93 return gh_cons (name_
, gh_int2scm (0));
98 Scaled_font_metric::description () const
100 SCM od
= orig_l_
->description ();
101 gh_set_cdr_x (od
, gh_int2scm (magstep_i_
));
107 Font_metric::do_smobify_self ()
112 Font_metric::mark_smob (SCM s
)
114 Font_metric
* m
= SMOB_TO_TYPE(Font_metric
, s
);
119 Font_metric::print_smob (SCM s
, SCM port
, scm_print_state
* )
121 Font_metric
*m
= unsmob_metrics (s
);
122 scm_puts ("#<Font_metric ", port
);
123 scm_display (m
->name_
, port
);
124 scm_puts (">", port
);
128 IMPLEMENT_UNSMOB(Font_metric
, metrics
);