From dd65f89ae90be69f982ea41ce2ffafec7be328f8 Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Sun, 22 Jan 2006 18:46:37 +0000 Subject: [PATCH] * input/test/font-table.ly: use it. * lily/open-type-font.cc (glyph_list): new function. * lily/open-type-font-scheme.cc (LY_DEFINE): ly:otf-glyph-list function. * lily/ttf.cc: remove ly:font-glyph-list scheme function --- ChangeLog | 10 ++++++++++ input/test/font-table.ly | 4 +--- lily/font-config-scheme.cc | 34 ++++++++++++++++++++++++++++++++++ lily/include/open-type-font.hh | 3 ++- lily/open-type-font-scheme.cc | 16 ++++++++++++++++ lily/open-type-font.cc | 21 +++++++++++++++++++++ lily/ttf.cc | 32 -------------------------------- 7 files changed, 84 insertions(+), 36 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6e932bd105..45a5a2dc27 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2006-01-22 Han-Wen Nienhuys + + * input/test/font-table.ly: use it. + + * lily/open-type-font.cc (glyph_list): new function. + + * lily/open-type-font-scheme.cc (LY_DEFINE): ly:otf-glyph-list function. + + * lily/ttf.cc: remove ly:font-glyph-list scheme function + 2006-01-22 Nicolas Sceaux * ly/music-functions-init.ly (parallelMusic): new music function for parallel diff --git a/input/test/font-table.ly b/input/test/font-table.ly index a21d179141..6bb5ef83a2 100644 --- a/input/test/font-table.ly +++ b/input/test/font-table.ly @@ -56,9 +56,7 @@ #(let* ((lines (doc-chars - (ly:font-glyph-list (format "~a/fonts/otf/emmentaler-20.otf" - (getenv "LILYPONDPREFIX") - )) + (ly:otf-glyph-list (ly:font-load "emmentaler-20")) '())) (pages (group-lines (reverse lines)))) diff --git a/lily/font-config-scheme.cc b/lily/font-config-scheme.cc index 99e8f453c6..a31bfa6e69 100644 --- a/lily/font-config-scheme.cc +++ b/lily/font-config-scheme.cc @@ -8,6 +8,7 @@ */ #include "lily-guile.hh" +#include "string.hh" #include @@ -73,6 +74,37 @@ display_list (FcConfig *fcc) } +LY_DEFINE (ly_font_config_get_font_file, "ly:font-config-get-font-file", 1, 0, 0, + (SCM name), + "Get the file for font @var{name}") +{ + SCM_ASSERT_TYPE (scm_is_string (name), name, + SCM_ARG1, __FUNCTION__, "string"); + + + FcPattern*pat = FcPatternCreate (); + FcValue val; + + val.type = FcTypeString; + val.u.s = (const FcChar8*)ly_scm2string (name).to_str0 (); // FC_SLANT_ITALIC; + FcPatternAdd(pat, FC_FAMILY, val, FcFalse); + + FcResult result; + SCM scm_result = SCM_BOOL_F; + + FcConfigSubstitute (NULL, pat, FcMatchFont); + FcDefaultSubstitute (pat); + + pat = FcFontMatch(NULL, pat, &result); + FcChar8 *str = 0; + if (FcPatternGetString (pat, FC_FILE, 0, &str) == FcResultMatch) + scm_result = scm_makfrom0str ((char const*) str); + + FcPatternDestroy (pat); + + return scm_result; +} + LY_DEFINE (ly_font_config_display_fonts, "ly:font-config-display-fonts", 0, 0, 0, (), "Dump a list of all fonts visible to FontConfig.") @@ -82,3 +114,5 @@ LY_DEFINE (ly_font_config_display_fonts, "ly:font-config-display-fonts", 0, 0, 0 return SCM_UNSPECIFIED; } + + diff --git a/lily/include/open-type-font.hh b/lily/include/open-type-font.hh index 03cf0daaf2..c27c9a66ff 100644 --- a/lily/include/open-type-font.hh +++ b/lily/include/open-type-font.hh @@ -36,7 +36,8 @@ public: SCM get_subfonts () const; SCM get_global_table () const; SCM get_char_table () const; - + SCM glyph_list () const; + String get_otf_table (String tag) const; static SCM make_otf (String); virtual String font_name () const; diff --git a/lily/open-type-font-scheme.cc b/lily/open-type-font-scheme.cc index 44d3353770..43f8c32f8d 100644 --- a/lily/open-type-font-scheme.cc +++ b/lily/open-type-font-scheme.cc @@ -71,3 +71,19 @@ LY_DEFINE (ly_otf_font_p, "ly:otf-font?", 1, 0, 0, return scm_from_bool (otf); } + +LY_DEFINE (ly_otf_glyph_list, "ly:otf-glyph-list", + 1, 0, 0, (SCM font), + "Return a list of glyphnames for @var{font}.") +{ + Modified_font_metric *fm + = dynamic_cast (unsmob_metrics (font)); + + Open_type_font *otf = fm ? dynamic_cast (fm->original_font ()) + : dynamic_cast (unsmob_metrics (font)); + + + SCM_ASSERT_TYPE (otf,font, SCM_ARG1, __FUNCTION__, "OTF font"); + return otf->glyph_list (); + +} diff --git a/lily/open-type-font.cc b/lily/open-type-font.cc index aa7291dd70..85e38042f4 100644 --- a/lily/open-type-font.cc +++ b/lily/open-type-font.cc @@ -288,3 +288,24 @@ Open_type_font::font_name () const return FT_Get_Postscript_Name (face_); } + +SCM +Open_type_font::glyph_list () const +{ + SCM retval = SCM_EOL; + SCM *tail = &retval; + + for (int i = 0; i < face_->num_glyphs; i++) + { + const int len = 256; + char name[len]; + int code = FT_Get_Glyph_Name (face_, i, name, len); + if (code) + warning (_f ("FT_Get_Glyph_Name() returned error: %d", code)); + + *tail = scm_cons (scm_makfrom0str (name), SCM_EOL); + tail = SCM_CDRLOC (*tail); + } + + return retval; +} diff --git a/lily/ttf.cc b/lily/ttf.cc index 31fc47b07b..677f4d0179 100644 --- a/lily/ttf.cc +++ b/lily/ttf.cc @@ -163,38 +163,6 @@ create_type42_font (void *out, String name) FT_Done_Face (face); } -LY_DEFINE (ly_font_glyph_list, "ly:font-glyph-list", - 1, 0, 0, (SCM font_file_name), - "Return a list of glyphnames for @var{font-file-name}.") -{ - SCM_ASSERT_TYPE (scm_is_string (font_file_name), font_file_name, - SCM_ARG1, __FUNCTION__, "string"); - - String file_name = ly_scm2string (font_file_name); - if (be_verbose_global) - progress_indication ("[" + file_name); - - SCM retval = SCM_EOL; - SCM *tail = &retval; - - FT_Face face = open_ft_face (file_name); - for (int i = 0; i < face->num_glyphs; i++) - { - const int len = 256; - char name[len]; - int code = FT_Get_Glyph_Name (face, i, name, len); - if (code) - warning (_f ("FT_Get_Glyph_Name() returned error: %d", code)); - - *tail = scm_cons (scm_makfrom0str (name), SCM_EOL); - tail = SCM_CDRLOC (*tail); - } - - FT_Done_Face (face); - if (be_verbose_global) - progress_indication ("]"); - return retval; -} LY_DEFINE (ly_ttf_ps_name, "ly:ttf-ps-name", 1, 0, 0, (SCM ttf_file_name), -- 2.39.5