2 open-type-font.cc -- implement Open_type_font
4 source file of the GNU LilyPond music typesetter
6 (c) 2004--2009 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_SMOB (Font_metric
, font
, 1);
19 Font_metric
*fm
= unsmob_metrics (font
);
20 return fm
->sub_fonts ();
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).")
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
));
34 SCM_ASSERT_TYPE (otf
, font
, SCM_ARG1
, __FUNCTION__
, "OpenType font");
35 LY_ASSERT_TYPE (scm_is_string
, glyph
, 2);
37 SCM sym
= scm_string_to_symbol (glyph
);
38 return scm_hashq_ref (otf
->get_char_table (), sym
, SCM_EOL
);
41 LY_DEFINE (ly_otf_font_table_data
, "ly:otf-font-table-data", 2, 0, 0,
43 "Extract a table @var{tag} from @var{font}. Return empty string"
44 " for non-existent @var{tag}.")
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
));
52 SCM_ASSERT_TYPE (otf
, font
, SCM_ARG1
, __FUNCTION__
, "OpenType font");
53 LY_ASSERT_TYPE (scm_is_string
, tag
, 2);
57 string tag_string
= ly_scm2string (tag
);
58 strncpy (ctag
, tag_string
.c_str (), tag_string
.length ());
60 string tab
= otf
->get_otf_table (string (ctag
));
62 return scm_from_locale_stringn ((char const *) tab
.data (), tab
.length ());
65 LY_DEFINE (ly_otf_font_p
, "ly:otf-font?", 1, 0, 0,
67 "Is @var{font} an OpenType font?")
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
));
75 return scm_from_bool (otf
);
78 LY_DEFINE (ly_otf_glyph_count
, "ly:otf-glyph-count", 1, 0, 0,
80 "Return the the number of glyphs in @var{font}.")
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
));
88 SCM_ASSERT_TYPE (otf
, font
, SCM_ARG1
, __FUNCTION__
, "OpenType font");
90 return scm_from_int ((int) otf
->count ());
93 LY_DEFINE (ly_otf_glyph_list
, "ly:otf-glyph-list", 1, 0, 0,
95 "Return a list of glyph names for @var{font}.")
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
));
103 SCM_ASSERT_TYPE (otf
, font
, SCM_ARG1
, __FUNCTION__
, "OpenType font");
105 return otf
->glyph_list ();