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

* scm/lily-library.scm (char->unicode-index): Remove.

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

index 32af2a6bcaa1e4293e5642550c34a82cdae1166b..3e8e5c7b70b44a36f24f3f601b493296af547790 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2004-12-13  Jan Nieuwenhuizen  <janneke@gnu.org>
+
+       * lily/include/font-metric.hh (index_to_charcode): New function.
+
+       * lily/font-metric.cc (ly:font-glyph-name-to-charcode): Use it in
+       new function.
+       (ly:font-glyp-to-index): Remove.
+
+       * scm/lily-library.scm (char->unicode-index): Remove.
+
 2004-12-12  Han-Wen Nienhuys  <hanwen@xs4all.nl>
 
        * lily/open-type-font.cc (make_index_to_charcode_map): new method.
index be4a3a23b631dd3048f8b259a9d5b5c93a4a228b..be0d75343e96f2cc6c76b9c73d0a2f986c37f8b2 100644 (file)
@@ -161,7 +161,7 @@ LY_DEFINE (ly_get_glyph, "ly:get-glyph",
   return fm->get_ascii_char_stencil (scm_to_int (index)).smobbed_copy ();
 }
 
-LY_DEFINE (ly_font_get_glyph_index, "ly:font-get-glyph-index",
+LY_DEFINE (ly_font_glyph_name_to_index, "ly:font-glyph-name-to-index",
           2, 0, 0,
          (SCM font, SCM name),
           "Return the index for @{name} in @var{font}.")
@@ -173,6 +173,30 @@ LY_DEFINE (ly_font_get_glyph_index, "ly:font-get-glyph-index",
   return scm_from_int (fm->name_to_index (ly_scm2string (name)));
 }
 
+LY_DEFINE (ly_font_index_to_charcode, "ly:font-index-to-charcode",
+          2, 0, 0,
+         (SCM font, SCM index),
+          "Return the character code for @var{index} @var{font}.")
+{
+  Font_metric *fm = unsmob_metrics (font);
+  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)));
+}
+
+LY_DEFINE (ly_font_glyph_name_to_charcode, "ly:font-glyph-name-to-charcode",
+          2, 0, 0,
+         (SCM font, SCM name),
+          "Return the character code for glyph @{name} in @var{font}.")
+{
+  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");
+
+  return scm_from_unsigned_integer (fm->index_to_charcode (fm->name_to_index (ly_scm2string (name))));
+}
+
 LY_DEFINE (ly_text_dimension,"ly:text-dimension",
           2, 0, 0,
          (SCM font, SCM text),
@@ -256,11 +280,16 @@ Font_metric::index_to_ascii (int i) const
   return i;
 }
 
+unsigned
+Font_metric::index_to_charcode (int i) const
+{
+  return (unsigned) index_to_ascii (i);
+}
+
 Stencil
 Font_metric::get_ascii_char_stencil (int code) const
 {
-  SCM at = scm_list_3 (ly_symbol2scm ("char"),
-                      this->self_scm (),
+  SCM at = scm_list_3 (ly_symbol2scm ("char"), self_scm (),
                       scm_int2num (code));
   Box b = get_ascii_char (code);
   return Stencil (b, at);
index f9fe247f3d4c55ca98785e18162d5726ac0f73e1..ad56d8f931c80870a99c6ee7523287d1581b7a88 100644 (file)
@@ -26,6 +26,7 @@ public:
   virtual Box get_indexed_char (int index) const;
   virtual Box get_ascii_char (int ascii) const;
   virtual int name_to_index (String) const;
+  virtual unsigned index_to_charcode (int) const;
   virtual int index_to_ascii (int) const;
   virtual Real design_size () const;
   virtual Stencil find_by_name (String) const;
index 161ba4e6e490a8ff034b441cb6a36516115c2933..6d3046570a59c5c39847b730d3e8ee2b326de9df 100644 (file)
@@ -38,6 +38,7 @@ inline SCM scm_cadar (SCM x) { return SCM_CADAR (x); }
 #define SCM_VECTOR_REF(v, i) (SCM_VELTS ((v))[(i)])
 #define scm_from_bool(x) (x ? SCM_BOOL_T : SCM_BOOL_F)
 #define scm_from_int(x) SCM_MAKINUM (x)
+#define scm_from_unsigned_integer(x) scm_uint2num (x)
 #define scm_is_integer(x) SCM_INUMP (x)
 #define scm_is_string(x) SCM_STRINGP (x)
 #define scm_hash_table_p scm_vector_p
index e1260eafc765657f888e0a1d60c8b1d4e82272bc..5d041d307b79f3cd0d224c7effbab93785d6b76b 100644 (file)
@@ -30,6 +30,7 @@ public:
   virtual Offset attachment_point (String) const;
   virtual Box get_indexed_char (int) const;
   virtual int name_to_index (String) const;
+  virtual unsigned index_to_charcode (int) const;
   virtual void derived_mark () const;
 #if 0
   virtual int count () const;
index 5a9085ef4ed0fb91c752417fe4a3f74c14e4d906..2b474e11146a8f64e8d52d316a56194c259c3c26 100644 (file)
 #include <stdio.h>
 
 #include <freetype/tttables.h>
+
 #include "warn.hh"
 #include "open-type-font.hh"
 #include "dimensions.hh"
 
 
-const  Real point_constant = 1 PT;
+const Real point_constant = 1 PT;
 
 FT_Byte *
 load_table (char const *tag_str, FT_Face face, FT_ULong *length)
 {
   FT_ULong tag = FT_MAKE_TAG(tag_str[0], tag_str[1], tag_str[2], tag_str[3]);
-  
+
   int error_code = FT_Load_Sfnt_Table (face, tag, 0, NULL, length);
   if (!error_code)
     {
-      FT_Byte*buffer = (FT_Byte*) malloc (*length);
+      FT_Byte *buffer = (FT_Byte*) malloc (*length);
       if (buffer == NULL)
-       error ("Not enough memory");
+       error (_f ("Cannot allocate %d bytes", *length));
 
       error_code = FT_Load_Sfnt_Table (face, tag, 0, buffer, length );
       if (error_code)
@@ -39,15 +39,15 @@ load_table (char const *tag_str, FT_Face face, FT_ULong *length)
 
       return buffer;
     }
-  
-  return 0 ;
+
+  return 0;
 }
 
 SCM
 load_scheme_table (char const *tag_str, FT_Face face)
 {
   FT_ULong length = 0;
-  FT_Bytebuffer = load_table (tag_str, face, &length);
+  FT_Byte *buffer = load_table (tag_str, face, &length);
 
   SCM tab = SCM_EOL;
   if (buffer)
@@ -55,63 +55,67 @@ load_scheme_table (char const *tag_str, FT_Face face)
       String contents ((Byte const*)buffer, length);
       contents = "(quote (" +  contents + "))";
 
-      SCM alist = scm_c_eval_string (contents.to_str0());
+      SCM alist = scm_c_eval_string (contents.to_str0 ());
       tab = alist_to_hashq (alist);
       free (buffer);
     }
   return tab;
 }
-           
+       
 Index_to_charcode_map
 make_index_to_charcode_map (FT_Face face)
 {
   Index_to_charcode_map m;
-  FT_ULong  charcode;                                              
-  FT_UInt   gindex;                                                
-                                                                      
-  charcode = FT_Get_First_Char( face, &gindex );                   
-  while ( gindex != 0 )                                            
+  FT_ULong charcode;
+  FT_UInt gindex;
+
+  charcode = FT_Get_First_Char (face, &gindex);
+  while (gindex != 0)
     {
+      printf ("index -> code: %d %d \n", gindex, charcode);
       m[gindex] = charcode;
-      charcode = FT_Get_Next_Char( face, charcode, &gindex );        
+      charcode = FT_Get_Next_Char (face, charcode, &gindex);
     }
   return m;
-}                                                                  
+}
+
+Open_type_font::Open_type_font (FT_Face face)
+{
+  face_ = face;
+  lily_character_table_ = SCM_EOL;
+  lily_global_table_ = SCM_EOL;
+
+  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_);
+}
+
+Open_type_font::~Open_type_font()
+{
+  FT_Done_Face (face_);
+}
 
 SCM
 Open_type_font::make_otf (String str)
 {
   FT_Face face;
-  int error_code = FT_New_Face(freetype2_library, str.to_str0(),
-                              0, &face);
-  
+  int error_code = FT_New_Face(freetype2_library, str.to_str0 (), 0, &face);
+
   if (error_code == FT_Err_Unknown_File_Format)
     {
-      error("Unsupported font format");
+      error (_f ("Unsupported font format: %s", str.to_str0 ()));
     }
   else if (error_code)
     {
-      error ("Unknown error reading font file.");
+      error (_f ("Unknown error: %d reading font file: %s", error_code,
+                str.to_str0 ()));
     }
 
+  Open_type_font *otf = new Open_type_font (face);
 
-  Open_type_font * otf = new Open_type_font (face);
-
-    
   return otf->self_scm ();
 }
 
-Open_type_font::Open_type_font(FT_Face face)
-{
-  face_ = face;
-  lily_character_table_ = SCM_EOL;
-  lily_global_table_ = SCM_EOL;
-  
-  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_);  
-}
-
 void
 Open_type_font::derived_mark () const
 {
@@ -126,23 +130,16 @@ Open_type_font::attachment_point (String glyph_name) const
   SCM entry = scm_hashq_ref (lily_character_table_, sym, SCM_BOOL_F);
 
   Offset o;
-  if  (entry == SCM_BOOL_F)
+  if (entry == SCM_BOOL_F)
     return o;
 
   SCM char_alist = entry;
 
   SCM att_scm =scm_cdr (scm_assq (ly_symbol2scm ("attachment"), char_alist));
-  
-  return ly_scm2offset (att_scm);
-}
-
 
-Open_type_font::~Open_type_font()
-{
-  FT_Done_Face (face_);
+  return ly_scm2offset (att_scm);
 }
 
-
 Box
 Open_type_font::get_indexed_char (int signed_idx) const
 {
@@ -157,27 +154,29 @@ Open_type_font::get_indexed_char (int signed_idx) const
   Box b (Interval (-hb, m.width - hb),
         Interval (-vb, m.height - vb));
 
-  
-
-  b.scale (design_size() * Real (point_constant) / face_->units_per_EM);
+  b.scale (design_size () * Real (point_constant) / face_->units_per_EM);
   return b;
 }
 
 int
 Open_type_font::name_to_index (String nm) const
 {
-  char * nm_str = (char * )nm.to_str0 ();
-  int idx = FT_Get_Name_Index (face_, nm_str);
-
-  if (idx == 0)
-    return -1;
-  else
+  char *nm_str = (char*) nm.to_str0 ();
+  if (int idx = FT_Get_Name_Index (face_, nm_str))
     return idx;
+  return -1;
 }
 
+unsigned
+Open_type_font::index_to_charcode (int i) const
+{
+  return ((Open_type_font*) this)->index_to_charcode_map_[index_to_ascii (i)];
+}
 
 Real
 Open_type_font::design_size () const
 {
-  return point_constant * scm_to_double (scm_hashq_ref (lily_global_table_, ly_symbol2scm ("staffsize"), SCM_BOOL_F));
+  return point_constant
+    * scm_to_double (scm_hashq_ref (lily_global_table_,
+                                   ly_symbol2scm ("staffsize"), SCM_BOOL_F));
 }
index 29e3f476fc5ee9541e8de187ab37037b00da6693..287346d322a41b31618c5fda6c85b59917bbce9a 100644 (file)
@@ -343,23 +343,5 @@ possibly turned off."
          (ly:font-file-name font)))))
 
 (define-public (char->unicode-index font char)
-  ;;  (format (current-error-port) "UNICODE:~S:~S:~S\n"
-  ;;   font (ly:font-encoding font) (char->integer char))
-  ;; (force-output (current-error-port))
-  (+ (case (ly:font-encoding font)
-       ((fetaMusic) (- #xe000 #x20))
-       ((fetaBraces) (- #xe000 #x40))
-       ((fetaBraces) (- #xe000 #x40))
-       ;;(else 0))
-       ;; FIXME: bigcheese says FontSpecific
-       (else (if (string=? (font-family font) "bigcheese20")
-                ;;#xf000 0)))
-                ;; FIXME: hmm, why does name_to_index not return actual
-                ;; unicode mapping?
-
-                ;; ugh, we must know which font from bigcheese;
-                ;; feta-proper starts at 0xefc
-                ;; but we cannot display feta-nummer or feta-din characters
-                ;; this way
-                #xe0fc 0)))
-     (char->integer char)))
+  ;;(ly:font-index-to-charcode (char->integer char))
+   (char->integer char))
index 217640a0da171009279507934c5a1cda130f0425..acced8dd831e4340f11fcc5f3772851210f2ae39 100644 (file)
@@ -323,9 +323,9 @@ lilypond -fgnome input/simple-song.ly
 
 (define (named-glyph font name)
   (debugf "glyph:~S\n" name)
-  (debugf "index:~S\n" (ly:font-get-glyph-index font 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-get-glyph-index font name))))
+  (text font (integer->char (ly:font-glyph-name-to-charcode font name))))
 
 (define (polygon coords blotdiameter)
   (let*
@@ -360,11 +360,12 @@ lilypond -fgnome input/simple-song.ly
 
 (define (text font s)
   (define (pango-font-name font)
+    (stderr "FONT-NAME:~S\n" (ly:font-name font))
+    
     (let ((family (font-family font)))
       ;; Hmm, family is bigcheese20?
       (if (string=? family "bigcheese20")
-         (begin (debugf "BIGCHEESE\n")
-         "LilyPond, 20")
+         (format #f "~S, ~S" (ly:font-name font) (ly:font-design-size font))
          family)))
   
   (define (pango-font-size font)
@@ -404,4 +405,4 @@ lilypond -fgnome input/simple-song.ly
       #:size-set #t
       #:text (if (char? s)
                 (char->utf8-string font s)
-                (string->utf8-string font s)))))
\ No newline at end of file
+                (string->utf8-string font s)))))