Fix typo in convert-ly.
[lilypond.git] / lily / font-metric-scheme.cc
blobb06d419b99e4342e52d5ca8b7f4bdd55ba3cfbc2
1 /*
2 font-metric-scheme.cc -- implement Font_metric scheme bindings
4 source file of the GNU LilyPond music typesetter
6 (c) 2005--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
9 #include "font-metric.hh"
11 #include "warn.hh"
12 #include "stencil.hh"
13 #include "modified-font-metric.hh"
15 LY_DEFINE (ly_font_get_glyph, "ly:font-get-glyph",
16 2, 0, 0,
17 (SCM font, SCM name),
18 "Return a stencil from @var{font} for the glyph named @var{name}."
19 " If the glyph is not available, return an empty stencil.")
21 Font_metric *fm = unsmob_metrics (font);
22 LY_ASSERT_SMOB (Font_metric, font, 1);
23 LY_ASSERT_TYPE (scm_is_string, name, 2);
25 Stencil m = fm->find_by_name (ly_scm2string (name));
27 /* TODO: make optional argument for default if not found. */
28 return m.smobbed_copy ();
31 LY_DEFINE (ly_get_glyph, "ly:get-glyph",
32 2, 0, 0,
33 (SCM font, SCM index),
34 "Retrieve a stencil for the glyph numbered @var{index}"
35 " in @var{font}.")
37 Font_metric *fm = unsmob_metrics (font);
38 LY_ASSERT_SMOB (Font_metric, font, 1);
39 LY_ASSERT_TYPE (scm_is_number, index,2);
41 return fm->get_ascii_char_stencil (scm_to_int (index)).smobbed_copy ();
44 LY_DEFINE (ly_font_glyph_name_to_index, "ly:font-glyph-name-to-index",
45 2, 0, 0,
46 (SCM font, SCM name),
47 "Return the index for @var{name} in @var{font}.")
49 Font_metric *fm = unsmob_metrics (font);
50 LY_ASSERT_SMOB (Font_metric, font, 1);
51 LY_ASSERT_TYPE (scm_is_string, name, 2);
53 return scm_from_int (fm->name_to_index (ly_scm2string (name)));
56 LY_DEFINE (ly_font_index_to_charcode, "ly:font-index-to-charcode",
57 2, 0, 0,
58 (SCM font, SCM index),
59 "Return the character code for @var{index} in @var{font}.")
61 Font_metric *fm = unsmob_metrics (font);
62 LY_ASSERT_SMOB (Font_metric, font, 1);
63 LY_ASSERT_TYPE (scm_is_integer, index, 2);
65 return scm_from_unsigned_integer (fm->index_to_charcode (scm_to_int (index)));
68 LY_DEFINE (ly_font_glyph_name_to_charcode, "ly:font-glyph-name-to-charcode",
69 2, 0, 0,
70 (SCM font, SCM name),
71 "Return the character code for glyph @var{name} in @var{font}.")
73 Font_metric *fm = unsmob_metrics (font);
74 LY_ASSERT_SMOB (Font_metric, font, 1);
75 LY_ASSERT_TYPE (scm_is_string, name, 2);
77 return scm_from_unsigned_integer (fm->index_to_charcode (fm->name_to_index (ly_scm2string (name))));
80 LY_DEFINE (ly_text_dimension, "ly:text-dimension",
81 2, 0, 0,
82 (SCM font, SCM text),
83 "Given the font metric in @var{font} and the string @var{text},"
84 " compute the extents of that text in that font. The return"
85 " value is a pair of number-pairs.")
87 Box b;
88 Modified_font_metric *fm = dynamic_cast<Modified_font_metric *>
89 (unsmob_metrics (font));
91 LY_ASSERT_SMOB (Font_metric, font, 1);
92 LY_ASSERT_TYPE (scm_is_string, text, 2);
93 Stencil stc (fm->text_stencil (ly_scm2string (text)));
94 return scm_cons (ly_interval2scm (stc.extent (X_AXIS)),
95 ly_interval2scm (stc.extent (Y_AXIS)));
100 TODO: when are non string retvals allowed?
102 LY_DEFINE (ly_font_file_name, "ly:font-file-name",
103 1, 0, 0,
104 (SCM font),
105 "Given the font metric @var{font},"
106 " return the corresponding file name.")
108 LY_ASSERT_SMOB (Font_metric, font, 1);
110 Font_metric *fm = unsmob_metrics (font);
111 SCM name = fm->font_file_name ();
113 return name;
116 LY_DEFINE (ly_font_name, "ly:font-name",
117 1, 0, 0,
118 (SCM font),
119 "Given the font metric @var{font},"
120 " return the corresponding name.")
122 LY_ASSERT_SMOB (Font_metric, font, 1);
123 Font_metric *fm = unsmob_metrics (font);
125 return ly_string2scm (fm->font_name ());
128 LY_DEFINE (ly_font_magnification, "ly:font-magnification", 1, 0, 0,
129 (SCM font),
130 "Given the font metric @var{font}, return the"
131 " magnification, relative to the current output-scale.")
133 LY_ASSERT_SMOB (Font_metric, font, 1);
135 Font_metric *fm = unsmob_metrics (font);
136 return scm_cdr (fm->description_);
139 LY_DEFINE (ly_font_design_size, "ly:font-design-size", 1, 0, 0,
140 (SCM font),
141 "Given the font metric @var{font}, return the"
142 " design size, relative to the current output-scale.")
144 LY_ASSERT_SMOB (Font_metric, font, 1);
146 Font_metric *fm = unsmob_metrics (font);
147 return scm_from_double (fm->design_size ());