Fixes Issue 1504, allowing feather beam line breaking.
[lilypond/patrick.git] / lily / open-type-font-scheme.cc
blobfd48290aa000bf3ce958e2c5ea7a36fa9d840ca0
1 /*
2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2004--2011 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"
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}.")
28 LY_ASSERT_SMOB (Font_metric, font, 1);
30 Font_metric *fm = unsmob_metrics (font);
31 return fm->sub_fonts ();
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).")
39 Modified_font_metric *fm
40 = dynamic_cast<Modified_font_metric *> (unsmob_metrics (font));
41 Open_type_font *otf = fm
42 ? dynamic_cast<Open_type_font *> (fm->original_font ())
43 : dynamic_cast<Open_type_font *> (unsmob_metrics (font));
45 SCM_ASSERT_TYPE (otf, font, SCM_ARG1, __FUNCTION__, "OpenType font");
46 LY_ASSERT_TYPE (scm_is_string, glyph, 2);
48 SCM sym = scm_string_to_symbol (glyph);
49 return scm_hashq_ref (otf->get_char_table (), sym, SCM_EOL);
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}.")
57 Modified_font_metric *fm
58 = dynamic_cast<Modified_font_metric *> (unsmob_metrics (font));
59 Open_type_font *otf = fm
60 ? dynamic_cast<Open_type_font *> (fm->original_font ())
61 : dynamic_cast<Open_type_font *> (unsmob_metrics (font));
63 SCM_ASSERT_TYPE (otf, font, SCM_ARG1, __FUNCTION__, "OpenType font");
64 LY_ASSERT_TYPE (scm_is_string, tag, 2);
66 char ctag [5] = " ";
68 string tag_string = ly_scm2string (tag);
69 strncpy (ctag, tag_string.c_str (), tag_string.length ());
71 string tab = otf->get_otf_table (string (ctag));
73 return scm_from_locale_stringn ((char const *) tab.data (), tab.length ());
76 LY_DEFINE (ly_otf_font_p, "ly:otf-font?", 1, 0, 0,
77 (SCM font),
78 "Is @var{font} an OpenType font?")
80 Modified_font_metric *fm
81 = dynamic_cast<Modified_font_metric *> (unsmob_metrics (font));
82 Open_type_font *otf = fm
83 ? dynamic_cast<Open_type_font *> (fm->original_font ())
84 : dynamic_cast<Open_type_font *> (unsmob_metrics (font));
86 return scm_from_bool (otf);
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}.")
93 Modified_font_metric *fm
94 = dynamic_cast<Modified_font_metric *> (unsmob_metrics (font));
95 Open_type_font *otf = fm
96 ? dynamic_cast<Open_type_font *> (fm->original_font ())
97 : dynamic_cast<Open_type_font *> (unsmob_metrics (font));
99 SCM_ASSERT_TYPE (otf, font, SCM_ARG1, __FUNCTION__, "OpenType font");
101 return scm_from_int ((int) otf->count ());
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}.")
108 Modified_font_metric *fm
109 = dynamic_cast<Modified_font_metric *> (unsmob_metrics (font));
110 Open_type_font *otf = fm
111 ? dynamic_cast<Open_type_font *> (fm->original_font ())
112 : dynamic_cast<Open_type_font *> (unsmob_metrics (font));
114 SCM_ASSERT_TYPE (otf, font, SCM_ARG1, __FUNCTION__, "OpenType font");
116 return otf->glyph_list ();