From cd9049cb1206bd2295fb1909b0a48950217a6b8e Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Mon, 13 Dec 2004 18:13:27 +0000 Subject: [PATCH] * lily/font-metric.cc (ly:font-glyph-name-to-charcode): Use it in new function. (ly:font-glyph-to-index): Remove. * lily/font-metric.cc ("ly:font-glyph-name-to-charcode"): Bugfix: use original font. --- ChangeLog | 5 ++-- lily/font-metric.cc | 41 ++++++++++++++++++++++++++------- lily/include/open-type-font.hh | 6 +++-- lily/open-type-font.cc | 42 ++++++++++++++++++++++++++++------ scm/lily-library.scm | 3 +-- scm/output-gnome.scm | 21 +++++++++++++---- 6 files changed, 92 insertions(+), 26 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3e8e5c7b70..b339b7e0f4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,9 +4,10 @@ * lily/font-metric.cc (ly:font-glyph-name-to-charcode): Use it in new function. - (ly:font-glyp-to-index): Remove. + (ly:font-glyph-to-index): Remove. - * scm/lily-library.scm (char->unicode-index): Remove. + * lily/font-metric.cc ("ly:font-glyph-name-to-charcode"): Bugfix: + use original font. 2004-12-12 Han-Wen Nienhuys diff --git a/lily/font-metric.cc b/lily/font-metric.cc index be0d75343e..bbb38dc91a 100644 --- a/lily/font-metric.cc +++ b/lily/font-metric.cc @@ -14,9 +14,10 @@ #include #include "modified-font-metric.hh" +#include "open-type-font.hh" +#include "stencil.hh" #include "virtual-methods.hh" #include "warn.hh" -#include "stencil.hh" #include "ly-smobs.icc" @@ -182,7 +183,13 @@ LY_DEFINE (ly_font_index_to_charcode, "ly:font-index-to-charcode", SCM_ASSERT_TYPE (fm, font, SCM_ARG1, __FUNCTION__, "font-metric"); SCM_ASSERT_TYPE (scm_is_integer (index), index, SCM_ARG2, __FUNCTION__, "index"); - return scm_from_unsigned_integer (fm->index_to_charcode (ly_scm2int (index))); + unsigned charcode; + if (Modified_font_metric* mfm = dynamic_cast (fm)) + charcode = mfm->original_font ()->index_to_charcode (ly_scm2int (index)); + else + charcode = fm->index_to_charcode (ly_scm2int (index)); + + return scm_from_unsigned_integer (charcode); } LY_DEFINE (ly_font_glyph_name_to_charcode, "ly:font-glyph-name-to-charcode", @@ -193,8 +200,21 @@ LY_DEFINE (ly_font_glyph_name_to_charcode, "ly:font-glyph-name-to-charcode", Font_metric *fm = unsmob_metrics (font); SCM_ASSERT_TYPE (fm, font, SCM_ARG1, __FUNCTION__, "font-metric"); SCM_ASSERT_TYPE (scm_is_string (name), name, SCM_ARG2, __FUNCTION__, "string"); +#if 1 + unsigned charcode; + if (Modified_font_metric* mfm = dynamic_cast (fm)) + charcode = mfm->original_font ()->index_to_charcode (mfm->original_font ()->name_to_index (ly_scm2string (name))); + else + charcode = fm->index_to_charcode (fm->name_to_index (ly_scm2string (name))); +#else + unsigned charcode; + if (Modified_font_metric* mfm = dynamic_cast (fm)) + charcode = mfm->original_font ()->glyph_name_to_charcode (ly_scm2string (name)); + else + charcode = fm->glyph_name_to_charcode (ly_scm2string (name)); +#endif - return scm_from_unsigned_integer (fm->index_to_charcode (fm->name_to_index (ly_scm2string (name)))); + return scm_from_unsigned_integer (charcode); } LY_DEFINE (ly_text_dimension,"ly:text-dimension", @@ -243,11 +263,8 @@ LY_DEFINE (ly_font_name,"ly:font-name", if (Modified_font_metric* mfm = dynamic_cast (fm)) return ly_font_name (mfm->original_font ()->self_scm ()); else if (Adobe_font_metric* afm = dynamic_cast (fm)) - { - return scm_makfrom0str (afm->font_info_->gfi->fontName); - } - else - return SCM_BOOL_F; + return scm_makfrom0str (afm->font_info_->gfi->fontName); + return SCM_BOOL_F; } @@ -286,6 +303,14 @@ Font_metric::index_to_charcode (int i) const return (unsigned) index_to_ascii (i); } +#if 0 +unsigned +Font_metric::glyph_name_to_charcode (String glyph_name) const +{ + return (unsigned) index_to_ascii (name_to_index (glyph_name)); +} +#endif + Stencil Font_metric::get_ascii_char_stencil (int code) const { diff --git a/lily/include/open-type-font.hh b/lily/include/open-type-font.hh index 5d041d307b..fddb9b2ce8 100644 --- a/lily/include/open-type-font.hh +++ b/lily/include/open-type-font.hh @@ -15,6 +15,7 @@ #include "font-metric.hh" typedef std::map Index_to_charcode_map; +//typedef std::map Glyph_name_to_charcode_map; class Open_type_font : public Font_metric { @@ -23,13 +24,16 @@ class Open_type_font : public Font_metric SCM lily_character_table_; SCM lily_global_table_; Index_to_charcode_map index_to_charcode_map_; + //Glyph_name_to_charcode_map glyph_name_to_charcode_map_; Open_type_font (FT_Face); + public: static SCM make_otf (String); virtual ~Open_type_font(); virtual Offset attachment_point (String) const; virtual Box get_indexed_char (int) const; virtual int name_to_index (String) const; + //virtual unsigned glyph_name_to_charcode (String) const; virtual unsigned index_to_charcode (int) const; virtual void derived_mark () const; #if 0 @@ -41,6 +45,4 @@ public: virtual Real design_size () const; }; - #endif /* OPEN_TYPE_FONT_HH */ - diff --git a/lily/open-type-font.cc b/lily/open-type-font.cc index 2b474e1114..7d9b0e952d 100644 --- a/lily/open-type-font.cc +++ b/lily/open-type-font.cc @@ -61,7 +61,7 @@ load_scheme_table (char const *tag_str, FT_Face face) } return tab; } - + Index_to_charcode_map make_index_to_charcode_map (FT_Face face) { @@ -69,15 +69,34 @@ make_index_to_charcode_map (FT_Face face) FT_ULong charcode; FT_UInt gindex; - charcode = FT_Get_First_Char (face, &gindex); - while (gindex != 0) + for (charcode = FT_Get_First_Char (face, &gindex); gindex != 0; + charcode = FT_Get_Next_Char (face, charcode, &gindex)) + m[gindex] = charcode; + return m; +} + +#if 0 +Glyph_name_to_charcode_map +make_glyph_name_to_charcode_map (FT_Face face) +{ + Glyph_name_to_charcode_map m; + FT_ULong charcode; + FT_UInt gindex; + char buffer[1024]; + + for (charcode = FT_Get_First_Char (face, &gindex); gindex != 0; + charcode = FT_Get_Next_Char (face, charcode, &gindex)) { - printf ("index -> code: %d %d \n", gindex, charcode); - m[gindex] = charcode; - charcode = FT_Get_Next_Char (face, charcode, &gindex); + if (FT_Get_Glyph_Name (face, gindex, buffer, sizeof (buffer) - 1)) + { + programming_error ("no glyph name"); + continue; + } + m[String (buffer)] = charcode; } return m; } +#endif Open_type_font::Open_type_font (FT_Face face) { @@ -88,6 +107,7 @@ Open_type_font::Open_type_font (FT_Face face) lily_character_table_ = load_scheme_table ("LILC", face_); lily_global_table_ = load_scheme_table ("LILY", face_); index_to_charcode_map_ = make_index_to_charcode_map (face_); + //glyph_name_to_charcode_map_ = make_glyph_name_to_charcode_map (face_); } Open_type_font::~Open_type_font() @@ -170,8 +190,16 @@ Open_type_font::name_to_index (String nm) const unsigned Open_type_font::index_to_charcode (int i) const { - return ((Open_type_font*) this)->index_to_charcode_map_[index_to_ascii (i)]; + return ((Open_type_font*) this)->index_to_charcode_map_[i]; +} + +#if 0 +unsigned +Open_type_font::glyph_name_to_charcode (String glyph_name) const +{ + return ((Open_type_font*) this)->glyph_name_to_charcode_map_[glyph_name]; } +#endif Real Open_type_font::design_size () const diff --git a/scm/lily-library.scm b/scm/lily-library.scm index 287346d322..5dafe99744 100644 --- a/scm/lily-library.scm +++ b/scm/lily-library.scm @@ -343,5 +343,4 @@ possibly turned off." (ly:font-file-name font))))) (define-public (char->unicode-index font char) - ;;(ly:font-index-to-charcode (char->integer char)) - (char->integer char)) + (ly:font-index-to-charcode font (char->integer char))) diff --git a/scm/output-gnome.scm b/scm/output-gnome.scm index acced8dd83..92744346ca 100644 --- a/scm/output-gnome.scm +++ b/scm/output-gnome.scm @@ -166,6 +166,9 @@ lilypond -fgnome input/simple-song.ly (+ #x80 (modulo y #x40)))))) (else FIXME))) +(define (integer->utf8-string font integer) + (list->string (utf8 integer))) + (define (char->utf8-string font char) (list->string (utf8 (char->unicode-index font char)))) @@ -325,7 +328,7 @@ lilypond -fgnome input/simple-song.ly (debugf "glyph:~S\n" name) (debugf "index:~S\n" (ly:font-glyph-name-to-charcode font name)) (debugf "font:~S\n" (font-family font)) - (text font (integer->char (ly:font-glyph-name-to-charcode font name)))) + (text font (ly:font-glyph-name-to-charcode font name))) (define (polygon coords blotdiameter) (let* @@ -360,12 +363,18 @@ lilypond -fgnome input/simple-song.ly (define (text font s) (define (pango-font-name font) - (stderr "FONT-NAME:~S\n" (ly:font-name font)) + (stderr "FONT-NAME:~S:~S\n" (ly:font-name font) (ly:font-design-size font)) (let ((family (font-family font))) ;; Hmm, family is bigcheese20? - (if (string=? family "bigcheese20") - (format #f "~S, ~S" (ly:font-name font) (ly:font-design-size font)) + (if (string=? (substring family 0 (min (string-length family) 9)) + "bigcheese") + (begin + ;; FIXME: FONT-NAME:#f:8.85678704856787 + ;;(format #f "~S, ~S" (ly:font-name font) (ly:font-design-size font)) + (stderr "BIGCHEESE\n") + "LilyPond 20" + ) family))) (define (pango-font-size font) @@ -405,4 +414,6 @@ lilypond -fgnome input/simple-song.ly #:size-set #t #:text (if (char? s) (char->utf8-string font s) - (string->utf8-string font s))))) + (if (integer? s) + (integer->utf8-string font s) + (string->utf8-string font s)))))) -- 2.39.5