2 font-metric.cc -- implement Font_metric
4 source file of the GNU LilyPond music typesetter
6 (c) 1999--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
8 Mats Bengtsson <matsb@s3.kth.se> (the ugly TeX parsing in text_dimension)
11 #include "font-metric.hh"
17 #include "dimensions.hh"
18 #include "modified-font-metric.hh"
19 #include "open-type-font.hh"
23 #include "ly-smobs.icc"
26 Font_metric::design_size () const
28 return 1.0 * point_constant
;
32 Font_metric::find_by_name (string s
) const
34 replace_all (&s
, '-', 'M');
35 int idx
= name_to_index (s
);
41 expr
= scm_list_3 (ly_symbol2scm ("named-glyph"),
44 b
= get_indexed_char (idx
);
51 Font_metric::Font_metric ()
53 description_
= SCM_EOL
;
58 Font_metric::Font_metric (Font_metric
const &)
62 Font_metric::~Font_metric ()
67 Font_metric::count () const
73 Font_metric::get_ascii_char (size_t) const
75 return Box (Interval (0, 0), Interval (0, 0));
79 Font_metric::get_indexed_char (size_t k
) const
81 return get_ascii_char (k
);
85 Font_metric::name_to_index (string
) const
91 Font_metric::get_indexed_wxwy (size_t) const
97 Font_metric::derived_mark () const
102 Font_metric::mark_smob (SCM s
)
104 Font_metric
*m
= (Font_metric
*) SCM_CELL_WORD_1 (s
);
106 return m
->description_
;
110 Font_metric::print_smob (SCM s
, SCM port
, scm_print_state
*)
112 Font_metric
*m
= unsmob_metrics (s
);
113 scm_puts ("#<", port
);
114 scm_puts (m
->class_name (), port
);
115 scm_puts (" ", port
);
116 scm_write (m
->description_
, port
);
117 scm_puts (">", port
);
121 IMPLEMENT_SMOBS (Font_metric
);
122 IMPLEMENT_DEFAULT_EQUAL_P (Font_metric
);
123 IMPLEMENT_TYPE_P (Font_metric
, "ly:font-metric?");
126 Font_metric::font_file_name () const
128 return scm_car (description_
);
132 Font_metric::font_name () const
134 string
s ("unknown");
139 Font_metric::index_to_ascii (size_t i
) const
145 Font_metric::index_to_charcode (size_t i
) const
147 return index_to_ascii (i
);
151 Font_metric::get_ascii_char_stencil (size_t code
) const
153 SCM at
= scm_list_3 (ly_symbol2scm ("char"), self_scm (),
154 scm_from_unsigned (code
));
155 Box b
= get_ascii_char (code
);
156 return Stencil (b
, at
);
160 Font_metric::get_indexed_char_stencil (size_t code
) const
162 size_t idx
= index_to_ascii (code
);
163 SCM at
= scm_list_3 (ly_symbol2scm ("char"), self_scm (),
164 scm_from_unsigned (idx
));
165 Box b
= get_indexed_char (code
);
166 return Stencil (b
, at
);
170 Font_metric::attachment_point (string
) const
172 return Offset (0, 0);
176 Font_metric::sub_fonts () const
182 Font_metric::word_stencil (string str
) const
184 return text_stencil (str
);
188 Font_metric::text_stencil (string str
) const
191 programming_error("Cannot get a text stencil from this font");
192 return Stencil (Box (), SCM_EOL
);
196 Font_metric::text_dimension (string
) const
198 return Box (Interval (0, 0), Interval (0, 0));