]> git.donarmstrong.com Git - lilypond.git/blob - lily/open-type-font-scheme.cc
Issue 4550 (1/2) Avoid "using namespace std;" in included files
[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--2015 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 using std::string;
24
25 LY_DEFINE (ly_font_sub_fonts, "ly:font-sub-fonts", 1, 0, 0,
26            (SCM font),
27            "Given the font metric @var{font} of an OpenType font, return the"
28            " names of the subfonts within @var{font}.")
29 {
30   LY_ASSERT_SMOB (Font_metric, font, 1);
31
32   Font_metric *fm = unsmob<Font_metric> (font);
33   return fm->sub_fonts ();
34 }
35
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).")
40 {
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);
46
47   SCM_ASSERT_TYPE (otf, font, SCM_ARG1, __FUNCTION__, "OpenType font");
48   LY_ASSERT_TYPE (scm_is_string, glyph, 2);
49
50   SCM sym = scm_string_to_symbol (glyph);
51   return scm_hashq_ref (otf->get_char_table (), sym, SCM_EOL);
52 }
53
54 LY_DEFINE (ly_otf_font_table_data, "ly:otf-font-table-data", 2, 0, 0,
55            (SCM font, SCM tag),
56            "Extract a table @var{tag} from @var{font}.  Return empty string"
57            " for non-existent @var{tag}.")
58 {
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);
64
65   SCM_ASSERT_TYPE (otf, font, SCM_ARG1, __FUNCTION__, "OpenType font");
66   LY_ASSERT_TYPE (scm_is_string, tag, 2);
67
68   char ctag [5] = "    ";
69
70   string tag_string = ly_scm2string (tag);
71   strncpy (ctag, tag_string.c_str (), tag_string.length ());
72
73   string tab = otf->get_otf_table (string (ctag));
74
75   return scm_from_latin1_stringn ((char const *) tab.data (), tab.length ());
76 }
77
78 LY_DEFINE (ly_otf_font_p, "ly:otf-font?", 1, 0, 0,
79            (SCM font),
80            "Is @var{font} an OpenType font?")
81 {
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);
87
88   return scm_from_bool (otf);
89 }
90
91 LY_DEFINE (ly_otf_glyph_count, "ly:otf-glyph-count", 1, 0, 0,
92            (SCM font),
93            "Return the number of glyphs in @var{font}.")
94 {
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);
100
101   SCM_ASSERT_TYPE (otf, font, SCM_ARG1, __FUNCTION__, "OpenType font");
102
103   return scm_from_int ((int) otf->count ());
104 }
105
106 LY_DEFINE (ly_otf_glyph_list, "ly:otf-glyph-list", 1, 0, 0,
107            (SCM font),
108            "Return a list of glyph names for @var{font}.")
109 {
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);
115
116   SCM_ASSERT_TYPE (otf, font, SCM_ARG1, __FUNCTION__, "OpenType font");
117
118   return otf->glyph_list ();
119 }