]> git.donarmstrong.com Git - lilypond.git/blob - lily/open-type-font-scheme.cc
139150a7ccbf4230d0c84154c8975193d7d9b259
[lilypond.git] / lily / open-type-font-scheme.cc
1 /*
2   open-type-font.cc -- implement Open_type_font
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2004--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
8
9 #include "modified-font-metric.hh"
10 #include "open-type-font.hh"
11
12 LY_DEFINE (ly_font_sub_fonts, "ly:font-sub-fonts", 1, 0, 0,
13            (SCM font),
14            "Given the font metric @var{font} of an OpenType font, return the "
15            "names of the subfonts within @var{font}.")
16 {
17   LY_ASSERT_FIRST_SMOB (Font_metric, font);
18   Font_metric *fm = unsmob_metrics (font);
19   return fm->sub_fonts ();
20 }
21
22 LY_DEFINE (ly_otf_font_glyph_info, "ly:otf-font-glyph-info", 2, 0, 0,
23            (SCM font, SCM glyph),
24            "Given the font metric @var{font} of an OpenType font, return the "
25            "information about named glyph @var{glyph} (a string)")
26 {
27   Modified_font_metric *fm
28     = dynamic_cast<Modified_font_metric *> (unsmob_metrics (font));
29   Open_type_font *otf = dynamic_cast<Open_type_font *> (fm->original_font ());
30
31   LY_FUNC_NOTE_FIRST_ARG (font);
32   SCM_ASSERT_TYPE (otf, font, SCM_ARG1, __FUNCTION__, "OTF font-metric");
33   LY_ASSERT_TYPE(scm_is_string, 2);
34
35   SCM sym = scm_string_to_symbol (glyph);
36   return scm_hashq_ref (otf->get_char_table (), sym, SCM_EOL);
37 }
38
39 LY_DEFINE (ly_otf_font_table_data, "ly:otf-font-table-data", 2, 0, 0,
40            (SCM font, SCM tag),
41            "Extract a table @var{tag} from @var{font}. Return empty string for "
42            "non-existent @var{tag}.")
43 {
44   Modified_font_metric *fm
45     = dynamic_cast<Modified_font_metric *> (unsmob_metrics (font));
46
47   Open_type_font *otf = fm ? dynamic_cast<Open_type_font *> (fm->original_font ())
48     : dynamic_cast<Open_type_font *> (unsmob_metrics (font));
49
50   SCM_ASSERT_TYPE (otf, font, SCM_ARG1, __FUNCTION__, "Open type font");
51   LY_FUNC_NOTE_FIRST_ARG (font);
52   LY_ASSERT_TYPE (scm_is_string, 2);
53
54   char ctag [5] = "    ";
55
56   string tag_string = ly_scm2string (tag);
57   strncpy (ctag, tag_string.c_str (), tag_string.length ());
58
59   string tab = otf->get_otf_table (string (ctag));
60
61   return scm_from_locale_stringn ((char const *) tab.data (), tab.length ());
62 }
63
64 LY_DEFINE (ly_otf_font_p, "ly:otf-font?", 1, 0, 0,
65            (SCM font),
66            "Is @var{font} an OpenType font?")
67 {
68   Modified_font_metric *fm
69     = dynamic_cast<Modified_font_metric *> (unsmob_metrics (font));
70
71   Open_type_font *otf = fm ? dynamic_cast<Open_type_font *> (fm->original_font ())
72     : dynamic_cast<Open_type_font *> (unsmob_metrics (font));
73
74   return scm_from_bool (otf);
75 }
76
77 LY_DEFINE (ly_otf_glyph_list, "ly:otf-glyph-list",
78            1, 0, 0, (SCM font),
79            "Return a list of glyphnames for @var{font}.")
80 {
81   Modified_font_metric *fm
82     = dynamic_cast<Modified_font_metric *> (unsmob_metrics (font));
83
84   Open_type_font *otf = fm ? dynamic_cast<Open_type_font *> (fm->original_font ())
85     : dynamic_cast<Open_type_font *> (unsmob_metrics (font));
86
87
88   SCM_ASSERT_TYPE (otf, font, SCM_ARG1, __FUNCTION__, "OTF font");
89   return otf->glyph_list ();
90
91 }