]> git.donarmstrong.com Git - lilypond.git/blob - lily/open-type-font-scheme.cc
3ce37b6ef7c060f990a969f4efc6af9bcf0796d5
[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--2009 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_SMOB (Font_metric, font, 1);
18
19   Font_metric *fm = unsmob_metrics (font);
20   return fm->sub_fonts ();
21 }
22
23 LY_DEFINE (ly_otf_font_glyph_info, "ly:otf-font-glyph-info", 2, 0, 0,
24            (SCM font, SCM glyph),
25            "Given the font metric @var{font} of an OpenType font, return the"
26            " information about named glyph @var{glyph} (a string).")
27 {
28   Modified_font_metric *fm
29     = dynamic_cast<Modified_font_metric *> (unsmob_metrics (font));
30   Open_type_font *otf = fm
31     ? dynamic_cast<Open_type_font *> (fm->original_font ())
32     : dynamic_cast<Open_type_font *> (unsmob_metrics (font));
33
34   SCM_ASSERT_TYPE (otf, font, SCM_ARG1, __FUNCTION__, "OpenType font");
35   LY_ASSERT_TYPE (scm_is_string, glyph, 2);
36
37   SCM sym = scm_string_to_symbol (glyph);
38   return scm_hashq_ref (otf->get_char_table (), sym, SCM_EOL);
39 }
40
41 LY_DEFINE (ly_otf_font_table_data, "ly:otf-font-table-data", 2, 0, 0,
42            (SCM font, SCM tag),
43            "Extract a table @var{tag} from @var{font}.  Return empty string"
44            " for non-existent @var{tag}.")
45 {
46   Modified_font_metric *fm
47     = dynamic_cast<Modified_font_metric *> (unsmob_metrics (font));
48   Open_type_font *otf = fm
49     ? dynamic_cast<Open_type_font *> (fm->original_font ())
50     : dynamic_cast<Open_type_font *> (unsmob_metrics (font));
51
52   SCM_ASSERT_TYPE (otf, font, SCM_ARG1, __FUNCTION__, "OpenType font");
53   LY_ASSERT_TYPE (scm_is_string, tag, 2);
54
55   char ctag [5] = "    ";
56
57   string tag_string = ly_scm2string (tag);
58   strncpy (ctag, tag_string.c_str (), tag_string.length ());
59
60   string tab = otf->get_otf_table (string (ctag));
61
62   return scm_from_locale_stringn ((char const *) tab.data (), tab.length ());
63 }
64
65 LY_DEFINE (ly_otf_font_p, "ly:otf-font?", 1, 0, 0,
66            (SCM font),
67            "Is @var{font} an OpenType font?")
68 {
69   Modified_font_metric *fm
70     = dynamic_cast<Modified_font_metric *> (unsmob_metrics (font));
71   Open_type_font *otf = fm
72     ? dynamic_cast<Open_type_font *> (fm->original_font ())
73     : dynamic_cast<Open_type_font *> (unsmob_metrics (font));
74
75   return scm_from_bool (otf);
76 }
77
78 LY_DEFINE (ly_otf_glyph_count, "ly:otf-glyph-count", 1, 0, 0,
79            (SCM font),
80            "Return the the number of glyphs in @var{font}.")
81 {
82   Modified_font_metric *fm
83     = dynamic_cast<Modified_font_metric *> (unsmob_metrics (font));
84   Open_type_font *otf = fm
85     ? dynamic_cast<Open_type_font *> (fm->original_font ())
86     : dynamic_cast<Open_type_font *> (unsmob_metrics (font));
87
88   SCM_ASSERT_TYPE (otf, font, SCM_ARG1, __FUNCTION__, "OpenType font");
89
90   return scm_from_int ((int) otf->count ());
91 }
92
93 LY_DEFINE (ly_otf_glyph_list, "ly:otf-glyph-list", 1, 0, 0,
94            (SCM font),
95            "Return a list of glyph names for @var{font}.")
96 {
97   Modified_font_metric *fm
98     = dynamic_cast<Modified_font_metric *> (unsmob_metrics (font));
99   Open_type_font *otf = fm
100     ? dynamic_cast<Open_type_font *> (fm->original_font ())
101     : dynamic_cast<Open_type_font *> (unsmob_metrics (font));
102
103   SCM_ASSERT_TYPE (otf, font, SCM_ARG1, __FUNCTION__, "OpenType font");
104
105   return otf->glyph_list ();
106 }