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"
18 Font_metric::text_dimension (String text
) const
23 for (int i
= 0; i
< text
.length_i (); i
++)
29 for (i
++; (i
< text
.length_i ()) && !isspace(text
[i
])
30 && text
[i
]!='{' && text
[i
]!='}'; i
++)
33 i
--; // Compensate for the increment in the outer loop!
35 case '{': // Skip '{' and '}'
40 Box b
= get_char ((unsigned char)text
[i
],false);
42 // Ugh, use the width of 'x' for unknown characters
43 if (b
[X_AXIS
].length () == 0)
44 b
= get_char ((unsigned char)'x',false);
46 w
+= b
[X_AXIS
].length ();
47 ydims
.unite (b
[Y_AXIS
]);
52 ydims
= Interval (0,0);
54 return Box(Interval (0, w
), ydims
);
59 Scaled_font_metric::text_dimension (String t
) const
61 Real realmag
= pow (1.2, magstep_i_
);
62 Box
b (orig_l_
->text_dimension (t
));
64 return Box(b
[X_AXIS
]* realmag
, b
[Y_AXIS
]*realmag
);
67 Font_metric::~Font_metric ()
72 Font_metric::Font_metric ()
79 Font_metric::Font_metric (Font_metric
const &)
85 Font_metric::get_char (int, bool)const
87 return Box (Interval(0,0),Interval (0,0));
90 Scaled_font_metric::Scaled_font_metric (Font_metric
* m
, int s
)
97 Font_metric::description () const
99 return gh_cons (name_
, gh_int2scm (0));
104 Scaled_font_metric::description () const
106 SCM od
= orig_l_
->description ();
107 gh_set_cdr_x (od
, gh_int2scm (magstep_i_
));
113 Font_metric::do_smobify_self ()
118 Font_metric::mark_smob (SCM s
)
120 Font_metric
* m
= SMOB_TO_TYPE(Font_metric
, s
);
125 Font_metric::print_smob (SCM s
, SCM port
, scm_print_state
* )
127 Font_metric
*m
= unsmob_metrics (s
);
128 scm_puts ("#<Font_metric ", port
);
129 scm_display (m
->name_
, port
);
130 scm_puts (">", port
);
135 IMPLEMENT_UNSMOB (Font_metric
, metrics
);
136 IMPLEMENT_SMOBS (Font_metric
);