]> git.donarmstrong.com Git - lilypond.git/blob - lily/open-type-font-scheme.cc
unsmob_pitch -> Pitch::unsmob and related
[lilypond.git] / lily / open-type-font-scheme.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2004--2014 Han-Wen Nienhuys <hanwen@xs4all.nl>
5
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.
10
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.
15
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/>.
18 */
19
20 #include "modified-font-metric.hh"
21 #include "open-type-font.hh"
22
23 LY_DEFINE (ly_font_sub_fonts, "ly:font-sub-fonts", 1, 0, 0,
24            (SCM font),
25            "Given the font metric @var{font} of an OpenType font, return the"
26            " names of the subfonts within @var{font}.")
27 {
28   LY_ASSERT_SMOB (Font_metric, font, 1);
29
30   Font_metric *fm = Font_metric::unsmob (font);
31   return fm->sub_fonts ();
32 }
33
34 LY_DEFINE (ly_otf_font_glyph_info, "ly:otf-font-glyph-info", 2, 0, 0,
35            (SCM font, SCM glyph),
36            "Given the font metric @var{font} of an OpenType font, return the"
37            " information about named glyph @var{glyph} (a string).")
38 {
39   Modified_font_metric *fm
40     = dynamic_cast<Modified_font_metric *> (Font_metric::unsmob (font));
41   Open_type_font *otf = fm
42                         ? dynamic_cast<Open_type_font *> (fm->original_font ())
43                         : dynamic_cast<Open_type_font *> (Font_metric::unsmob (font));
44
45   SCM_ASSERT_TYPE (otf, font, SCM_ARG1, __FUNCTION__, "OpenType font");
46   LY_ASSERT_TYPE (scm_is_string, glyph, 2);
47
48   SCM sym = scm_string_to_symbol (glyph);
49   return scm_hashq_ref (otf->get_char_table (), sym, SCM_EOL);
50 }
51
52 LY_DEFINE (ly_otf_font_table_data, "ly:otf-font-table-data", 2, 0, 0,
53            (SCM font, SCM tag),
54            "Extract a table @var{tag} from @var{font}.  Return empty string"
55            " for non-existent @var{tag}.")
56 {
57   Modified_font_metric *fm
58     = dynamic_cast<Modified_font_metric *> (Font_metric::unsmob (font));
59   Open_type_font *otf = fm
60                         ? dynamic_cast<Open_type_font *> (fm->original_font ())
61                         : dynamic_cast<Open_type_font *> (Font_metric::unsmob (font));
62
63   SCM_ASSERT_TYPE (otf, font, SCM_ARG1, __FUNCTION__, "OpenType font");
64   LY_ASSERT_TYPE (scm_is_string, tag, 2);
65
66   char ctag [5] = "    ";
67
68   string tag_string = ly_scm2string (tag);
69   strncpy (ctag, tag_string.c_str (), tag_string.length ());
70
71   string tab = otf->get_otf_table (string (ctag));
72
73   return scm_from_locale_stringn ((char const *) tab.data (), tab.length ());
74 }
75
76 LY_DEFINE (ly_otf_font_p, "ly:otf-font?", 1, 0, 0,
77            (SCM font),
78            "Is @var{font} an OpenType font?")
79 {
80   Modified_font_metric *fm
81     = dynamic_cast<Modified_font_metric *> (Font_metric::unsmob (font));
82   Open_type_font *otf = fm
83                         ? dynamic_cast<Open_type_font *> (fm->original_font ())
84                         : dynamic_cast<Open_type_font *> (Font_metric::unsmob (font));
85
86   return scm_from_bool (otf);
87 }
88
89 LY_DEFINE (ly_otf_glyph_count, "ly:otf-glyph-count", 1, 0, 0,
90            (SCM font),
91            "Return the number of glyphs in @var{font}.")
92 {
93   Modified_font_metric *fm
94     = dynamic_cast<Modified_font_metric *> (Font_metric::unsmob (font));
95   Open_type_font *otf = fm
96                         ? dynamic_cast<Open_type_font *> (fm->original_font ())
97                         : dynamic_cast<Open_type_font *> (Font_metric::unsmob (font));
98
99   SCM_ASSERT_TYPE (otf, font, SCM_ARG1, __FUNCTION__, "OpenType font");
100
101   return scm_from_int ((int) otf->count ());
102 }
103
104 LY_DEFINE (ly_otf_glyph_list, "ly:otf-glyph-list", 1, 0, 0,
105            (SCM font),
106            "Return a list of glyph names for @var{font}.")
107 {
108   Modified_font_metric *fm
109     = dynamic_cast<Modified_font_metric *> (Font_metric::unsmob (font));
110   Open_type_font *otf = fm
111                         ? dynamic_cast<Open_type_font *> (fm->original_font ())
112                         : dynamic_cast<Open_type_font *> (Font_metric::unsmob (font));
113
114   SCM_ASSERT_TYPE (otf, font, SCM_ARG1, __FUNCTION__, "OpenType font");
115
116   return otf->glyph_list ();
117 }