2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2005--2010 Han-Wen Nienhuys <hanwen@xs4all.nl>
6 LilyPond is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 LilyPond is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
20 #include "font-metric.hh"
24 #include "modified-font-metric.hh"
26 LY_DEFINE (ly_font_get_glyph
, "ly:font-get-glyph",
29 "Return a stencil from @var{font} for the glyph named @var{name}."
30 " If the glyph is not available, return an empty stencil.\n"
32 "Note that this command can only be used to access glyphs from"
33 " fonts loaded with @code{ly:system-font-load}; currently, this"
34 " means either the Emmentaler or Emmentaler-Brace "
35 " fonts, corresponding"
36 " to the font encodings @code{fetaMusic} and @code{fetaBraces},"
39 Font_metric
*fm
= unsmob_metrics (font
);
40 LY_ASSERT_SMOB (Font_metric
, font
, 1);
41 LY_ASSERT_TYPE (scm_is_string
, name
, 2);
43 Stencil m
= fm
->find_by_name (ly_scm2string (name
));
45 /* TODO: make optional argument for default if not found. */
46 return m
.smobbed_copy ();
49 LY_DEFINE (ly_font_glyph_name_to_index
, "ly:font-glyph-name-to-index",
52 "Return the index for @var{name} in @var{font}.\n"
54 "Note that this command can only be used to access glyphs from"
55 " fonts loaded with @code{ly:system-font-load}; currently, this"
56 " means either the Emmentaler or Emmentaler-Brace fonts, corresponding"
57 " to the font encodings @code{fetaMusic} and @code{fetaBraces},"
60 Font_metric
*fm
= unsmob_metrics (font
);
61 LY_ASSERT_SMOB (Font_metric
, font
, 1);
62 LY_ASSERT_TYPE (scm_is_string
, name
, 2);
64 return scm_from_int (fm
->name_to_index (ly_scm2string (name
)));
67 LY_DEFINE (ly_font_index_to_charcode
, "ly:font-index-to-charcode",
69 (SCM font
, SCM index
),
70 "Return the character code for @var{index} in @var{font}.\n"
72 "Note that this command can only be used to access glyphs from"
73 " fonts loaded with @code{ly:system-font-load}; currently, this"
74 " means either the Emmentaler or Emmentaler-Brace fonts, corresponding"
75 " to the font encodings @code{fetaMusic} and @code{fetaBraces},"
78 Font_metric
*fm
= unsmob_metrics (font
);
79 LY_ASSERT_SMOB (Font_metric
, font
, 1);
80 LY_ASSERT_TYPE (scm_is_integer
, index
, 2);
82 return scm_from_unsigned_integer (fm
->index_to_charcode (scm_to_int (index
)));
85 LY_DEFINE (ly_font_glyph_name_to_charcode
, "ly:font-glyph-name-to-charcode",
88 "Return the character code for glyph @var{name} in @var{font}.\n"
90 "Note that this command can only be used to access glyphs from"
91 " fonts loaded with @code{ly:system-font-load}; currently, this"
92 " means either the Emmentaler or Emmentaler-Brace fonts, corresponding"
93 " to the font encodings @code{fetaMusic} and @code{fetaBraces},"
96 Font_metric
*fm
= unsmob_metrics (font
);
97 LY_ASSERT_SMOB (Font_metric
, font
, 1);
98 LY_ASSERT_TYPE (scm_is_string
, name
, 2);
100 return scm_from_unsigned_integer (fm
->index_to_charcode (fm
->name_to_index (ly_scm2string (name
))));
104 TODO: when are non string retvals allowed?
106 LY_DEFINE (ly_font_file_name
, "ly:font-file-name",
109 "Given the font metric @var{font},"
110 " return the corresponding file name.")
112 LY_ASSERT_SMOB (Font_metric
, font
, 1);
114 Font_metric
*fm
= unsmob_metrics (font
);
115 SCM name
= fm
->font_file_name ();
120 LY_DEFINE (ly_font_name
, "ly:font-name",
123 "Given the font metric @var{font},"
124 " return the corresponding name.")
126 LY_ASSERT_SMOB (Font_metric
, font
, 1);
127 Font_metric
*fm
= unsmob_metrics (font
);
129 return ly_string2scm (fm
->font_name ());
132 LY_DEFINE (ly_font_magnification
, "ly:font-magnification", 1, 0, 0,
134 "Given the font metric @var{font}, return the"
135 " magnification, relative to the current output-scale.")
137 LY_ASSERT_SMOB (Font_metric
, font
, 1);
139 Font_metric
*fm
= unsmob_metrics (font
);
140 return scm_cdr (fm
->description_
);
143 LY_DEFINE (ly_font_design_size
, "ly:font-design-size", 1, 0, 0,
145 "Given the font metric @var{font}, return the"
146 " design size, relative to the current output-scale.")
148 LY_ASSERT_SMOB (Font_metric
, font
, 1);
150 Font_metric
*fm
= unsmob_metrics (font
);
151 return scm_from_double (fm
->design_size ());