]> git.donarmstrong.com Git - lilypond.git/commitdiff
* lily/font-metric.cc (ly:font-glyph-name-to-charcode): Use it in
authorJan Nieuwenhuizen <janneke@gnu.org>
Mon, 13 Dec 2004 18:13:27 +0000 (18:13 +0000)
committerJan Nieuwenhuizen <janneke@gnu.org>
Mon, 13 Dec 2004 18:13:27 +0000 (18:13 +0000)
new function.
(ly:font-glyph-to-index): Remove.

* lily/font-metric.cc ("ly:font-glyph-name-to-charcode"): Bugfix:
use original font.

ChangeLog
lily/font-metric.cc
lily/include/open-type-font.hh
lily/open-type-font.cc
scm/lily-library.scm
scm/output-gnome.scm

index 3e8e5c7b70b44a36f24f3f601b493296af547790..b339b7e0f4d57cc9ae0247323f7957d944f5349a 100644 (file)
--- 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  <hanwen@xs4all.nl>
 
index be0d75343e96f2cc6c76b9c73d0a2f986c37f8b2..bbb38dc91a346da4d93a49494ba11007f9347206 100644 (file)
 #include <cctype>
 
 #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<Modified_font_metric*> (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<Modified_font_metric*> (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<Modified_font_metric*> (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<Modified_font_metric*> (fm))
     return ly_font_name (mfm->original_font ()->self_scm ());
   else if (Adobe_font_metric* afm = dynamic_cast<Adobe_font_metric*> (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
 {
index 5d041d307b79f3cd0d224c7effbab93785d6b76b..fddb9b2ce8cee6c81fee5692e4177e51893bf4bf 100644 (file)
@@ -15,6 +15,7 @@
 #include "font-metric.hh"
 
 typedef std::map<FT_UInt, FT_ULong> Index_to_charcode_map;
+//typedef std::map<String, FT_ULong> 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 */
-
index 2b474e11146a8f64e8d52d316a56194c259c3c26..7d9b0e952dc3d168c1c9f693ae605c79ff13cd48 100644 (file)
@@ -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
index 287346d322a41b31618c5fda6c85b59917bbce9a..5dafe99744e7eeebd0d3ebb1c2e717a7391f2083 100644 (file)
@@ -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)))
index acced8dd831e4340f11fcc5f3772851210f2ae39..92744346ca460746da2d59fa357e6534be15a452 100644 (file)
@@ -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))))))