2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2004--2015 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 "modified-font-metric.hh"
21 #include "open-type-font.hh"
25 LY_DEFINE (ly_font_sub_fonts, "ly:font-sub-fonts", 1, 0, 0,
27 "Given the font metric @var{font} of an OpenType font, return the"
28 " names of the subfonts within @var{font}.")
30 LY_ASSERT_SMOB (Font_metric, font, 1);
32 Font_metric *fm = unsmob<Font_metric> (font);
33 return fm->sub_fonts ();
36 LY_DEFINE (ly_otf_font_glyph_info, "ly:otf-font-glyph-info", 2, 0, 0,
37 (SCM font, SCM glyph),
38 "Given the font metric @var{font} of an OpenType font, return the"
39 " information about named glyph @var{glyph} (a string).")
41 Modified_font_metric *fm
42 = unsmob<Modified_font_metric> (font);
43 Open_type_font *otf = fm
44 ? dynamic_cast<Open_type_font *> (fm->original_font ())
45 : unsmob<Open_type_font> (font);
47 SCM_ASSERT_TYPE (otf, font, SCM_ARG1, __FUNCTION__, "OpenType font");
48 LY_ASSERT_TYPE (scm_is_string, glyph, 2);
50 SCM sym = scm_string_to_symbol (glyph);
51 return scm_hashq_ref (otf->get_char_table (), sym, SCM_EOL);
54 LY_DEFINE (ly_otf_font_table_data, "ly:otf-font-table-data", 2, 0, 0,
56 "Extract a table @var{tag} from @var{font}. Return empty string"
57 " for non-existent @var{tag}.")
59 Modified_font_metric *fm
60 = unsmob<Modified_font_metric> (font);
61 Open_type_font *otf = fm
62 ? dynamic_cast<Open_type_font *> (fm->original_font ())
63 : unsmob<Open_type_font> (font);
65 SCM_ASSERT_TYPE (otf, font, SCM_ARG1, __FUNCTION__, "OpenType font");
66 LY_ASSERT_TYPE (scm_is_string, tag, 2);
70 string tag_string = ly_scm2string (tag);
71 strncpy (ctag, tag_string.c_str (), tag_string.length ());
73 string tab = otf->get_otf_table (string (ctag));
75 return scm_from_latin1_stringn ((char const *) tab.data (), tab.length ());
78 LY_DEFINE (ly_otf_font_p, "ly:otf-font?", 1, 0, 0,
80 "Is @var{font} an OpenType font?")
82 Modified_font_metric *fm
83 = unsmob<Modified_font_metric> (font);
84 Open_type_font *otf = fm
85 ? dynamic_cast<Open_type_font *> (fm->original_font ())
86 : unsmob<Open_type_font> (font);
88 return scm_from_bool (otf);
91 LY_DEFINE (ly_otf_glyph_count, "ly:otf-glyph-count", 1, 0, 0,
93 "Return the number of glyphs in @var{font}.")
95 Modified_font_metric *fm
96 = unsmob<Modified_font_metric> (font);
97 Open_type_font *otf = fm
98 ? dynamic_cast<Open_type_font *> (fm->original_font ())
99 : unsmob<Open_type_font> (font);
101 SCM_ASSERT_TYPE (otf, font, SCM_ARG1, __FUNCTION__, "OpenType font");
103 return scm_from_int ((int) otf->count ());
106 LY_DEFINE (ly_otf_glyph_list, "ly:otf-glyph-list", 1, 0, 0,
108 "Return a list of glyph names for @var{font}.")
110 Modified_font_metric *fm
111 = unsmob<Modified_font_metric> (font);
112 Open_type_font *otf = fm
113 ? dynamic_cast<Open_type_font *> (fm->original_font ())
114 : unsmob<Open_type_font> (font);
116 SCM_ASSERT_TYPE (otf, font, SCM_ARG1, __FUNCTION__, "OpenType font");
118 return otf->glyph_list ();