2 open-type-font.cc -- implement Open_type_font
4 source file of the GNU LilyPond music typesetter
6 (c) 2004--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
9 #include "modified-font-metric.hh"
10 #include "open-type-font.hh"
12 LY_DEFINE (ly_font_sub_fonts, "ly:font-sub-fonts", 1, 0, 0,
14 "Given the font metric @var{font} of an OpenType font, return the "
15 "names of the subfonts within @var{font}.")
17 LY_ASSERT_FIRST_SMOB (Font_metric, font);
18 Font_metric *fm = unsmob_metrics (font);
19 return fm->sub_fonts ();
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)")
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 ());
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);
35 SCM sym = scm_string_to_symbol (glyph);
36 return scm_hashq_ref (otf->get_char_table (), sym, SCM_EOL);
39 LY_DEFINE (ly_otf_font_table_data, "ly:otf-font-table-data", 2, 0, 0,
41 "Extract a table @var{tag} from @var{font}. Return empty string for "
42 "non-existent @var{tag}.")
44 Modified_font_metric *fm
45 = dynamic_cast<Modified_font_metric *> (unsmob_metrics (font));
47 Open_type_font *otf = fm ? dynamic_cast<Open_type_font *> (fm->original_font ())
48 : dynamic_cast<Open_type_font *> (unsmob_metrics (font));
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);
56 string tag_string = ly_scm2string (tag);
57 strncpy (ctag, tag_string.c_str (), tag_string.length ());
59 string tab = otf->get_otf_table (string (ctag));
61 return scm_from_locale_stringn ((char const *) tab.data (), tab.length ());
64 LY_DEFINE (ly_otf_font_p, "ly:otf-font?", 1, 0, 0,
66 "Is @var{font} an OpenType font?")
68 Modified_font_metric *fm
69 = dynamic_cast<Modified_font_metric *> (unsmob_metrics (font));
71 Open_type_font *otf = fm ? dynamic_cast<Open_type_font *> (fm->original_font ())
72 : dynamic_cast<Open_type_font *> (unsmob_metrics (font));
74 return scm_from_bool (otf);
77 LY_DEFINE (ly_otf_glyph_list, "ly:otf-glyph-list",
79 "Return a list of glyphnames for @var{font}.")
81 Modified_font_metric *fm
82 = dynamic_cast<Modified_font_metric *> (unsmob_metrics (font));
84 Open_type_font *otf = fm ? dynamic_cast<Open_type_font *> (fm->original_font ())
85 : dynamic_cast<Open_type_font *> (unsmob_metrics (font));
88 SCM_ASSERT_TYPE (otf, font, SCM_ARG1, __FUNCTION__, "OTF font");
89 return otf->glyph_list ();