]> git.donarmstrong.com Git - lilypond.git/blob - lily/open-type-font-scheme.cc
173eb56d3794880dcdc152ab1c77883a99e0ae3f
[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_SMOB (Font_metric, font, 1);
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   SCM_ASSERT_TYPE (otf, font, SCM_ARG1, __FUNCTION__, "OTF font-metric");
32   LY_ASSERT_TYPE (scm_is_string, glyph, 2);
33
34   SCM sym = scm_string_to_symbol (glyph);
35   return scm_hashq_ref (otf->get_char_table (), sym, SCM_EOL);
36 }
37
38 LY_DEFINE (ly_otf_font_table_data, "ly:otf-font-table-data", 2, 0, 0,
39            (SCM font, SCM tag),
40            "Extract a table @var{tag} from @var{font}.  Return empty string"
41            " for non-existent @var{tag}.")
42 {
43   Modified_font_metric *fm
44     = dynamic_cast<Modified_font_metric *> (unsmob_metrics (font));
45
46   Open_type_font *otf = fm ? dynamic_cast<Open_type_font *> (fm->original_font ())
47     : dynamic_cast<Open_type_font *> (unsmob_metrics (font));
48
49   SCM_ASSERT_TYPE (otf, font, SCM_ARG1, __FUNCTION__, "Open type font");
50   LY_ASSERT_TYPE (scm_is_string, tag, 2);
51
52   char ctag [5] = "    ";
53
54   string tag_string = ly_scm2string (tag);
55   strncpy (ctag, tag_string.c_str (), tag_string.length ());
56
57   string tab = otf->get_otf_table (string (ctag));
58
59   return scm_from_locale_stringn ((char const *) tab.data (), tab.length ());
60 }
61
62 LY_DEFINE (ly_otf_font_p, "ly:otf-font?", 1, 0, 0,
63            (SCM font),
64            "Is @var{font} an OpenType font?")
65 {
66   Modified_font_metric *fm
67     = dynamic_cast<Modified_font_metric *> (unsmob_metrics (font));
68
69   Open_type_font *otf = fm ? dynamic_cast<Open_type_font *> (fm->original_font ())
70     : dynamic_cast<Open_type_font *> (unsmob_metrics (font));
71
72   return scm_from_bool (otf);
73 }
74
75 LY_DEFINE (ly_otf_glyph_list, "ly:otf-glyph-list",
76            1, 0, 0, (SCM font),
77            "Return a list of glyph names for @var{font}.")
78 {
79   Modified_font_metric *fm
80     = dynamic_cast<Modified_font_metric *> (unsmob_metrics (font));
81
82   Open_type_font *otf = fm ? dynamic_cast<Open_type_font *> (fm->original_font ())
83     : dynamic_cast<Open_type_font *> (unsmob_metrics (font));
84
85
86   SCM_ASSERT_TYPE (otf, font, SCM_ARG1, __FUNCTION__, "OTF font");
87   return otf->glyph_list ();
88
89 }