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