]> git.donarmstrong.com Git - lilypond.git/commitdiff
* lily/virtual-font-metric.cc: new file
authorHan-Wen Nienhuys <hanwen@xs4all.nl>
Sat, 31 Aug 2002 17:21:37 +0000 (17:21 +0000)
committerHan-Wen Nienhuys <hanwen@xs4all.nl>
Sat, 31 Aug 2002 17:21:37 +0000 (17:21 +0000)
* lily/include/virtual-font-metric.hh (class Virtual_font_metric):
new file

ChangeLog
lily/font-metric.cc
lily/include/font-metric.hh
lily/include/virtual-font-metric.hh [new file with mode: 0644]
lily/virtual-font-metric.cc [new file with mode: 0644]

index 0a3f3c9ba064e60d4d3254cf21eb3f52d2f8ac97..1abda0c5e06929327ee22a3b0fce1740b6f632d3 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2002-08-31  Han-Wen Nienhuys  <hanwen@cs.uu.nl>
 
+       * lily/virtual-font-metric.cc: new file
+
+       * lily/include/virtual-font-metric.hh (class Virtual_font_metric):
+       new file
+
        * scripts/lilypond-book.py: use old re's for python 2.2 as well
 
        * debian/control: Debian patches by Anthony Fok
index 8fd2a49931717a94369b6392c86314e45ca7d9be..4a5d1f7550414bcb4313999a19008595eefab55f 100644 (file)
@@ -103,10 +103,20 @@ Font_metric::get_char (int)const
 }
 
 
+void
+Font_metric::derived_mark ()
+{
+  
+}
+
+  
+
 SCM
 Font_metric::mark_smob (SCM s)
 {
   Font_metric * m = (Font_metric*) SCM_CELL_WORD_1 (s);
+
+  do_derived_mark();
   return m->description_;
 }
 
index e9f5598ece3893260e1c6eff8630e2bff3936c05..99e89cff6b1dd1f1f4883a1f99025bc312a1bb63 100644 (file)
@@ -26,11 +26,12 @@ public:
   virtual Box get_char (int ascii) const;
   virtual Box text_dimension (String)  const;
   virtual Molecule find_by_name (String) const;
-
   DECLARE_SMOBS (Font_metric,);
 private:
   Font_metric (Font_metric const&); // no copy.
 protected:
+  virtual void derived_mark();
+
   Font_metric ();
 };
 
diff --git a/lily/include/virtual-font-metric.hh b/lily/include/virtual-font-metric.hh
new file mode 100644 (file)
index 0000000..c65116f
--- /dev/null
@@ -0,0 +1,32 @@
+
+/*   
+virtual-font-metric.hh -- declare Virtual_font_metric
+
+source file of the GNU LilyPond music typesetter
+
+(c) 2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+
+ */
+
+#ifndef VIRTUAL_FONT_METRIC_HH
+#define VIRTUAL_FONT_METRIC_HH
+
+#include "font-metric.hh"
+
+class Virtual_font_metric : public Font_metric
+{
+  SCM font_list_;
+public:
+  Virtual_font_metric (SCM namelist);
+
+  virtual int count () const;
+  virtual Box get_char (int ascii) const;
+  virtual Molecule find_by_name (String) const;
+
+protected:
+  virtual void derived_mark();
+};
+
+
+#endif /* VIRTUAL_FONT_METRIC_HH */
+
diff --git a/lily/virtual-font-metric.cc b/lily/virtual-font-metric.cc
new file mode 100644 (file)
index 0000000..c0db6af
--- /dev/null
@@ -0,0 +1,83 @@
+/*   
+  virtual-font-metric.cc --  implement Virtual_font_metric
+
+source file of the GNU LilyPond music typesetter
+
+(c) 2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+
+ */
+
+#include "virtual-font-metric.hh"
+#include "all-font-metrics.hh"
+#include "main.hh"
+#include "molecule.hh"
+
+
+Virtual_font_metric::Virtual_font_metric (SCM name_list)
+  :
+  Font_metric(),
+    font_list_ (SCM_EOL)
+{
+  SCM *tail = &font_list_;
+  for (SCM s = name_list; gh_pair_p (s); s = gh_cdr (s))
+    {
+      SCM nm = gh_car (s);
+
+      Font_metric *fm = all_fonts_global->find_font (ly_scm2string (nm));
+      *tail =  scm_cons (fm->self_scm(), *tail);
+      tail = SCM_CDRLOC (*tail);
+    }
+}
+
+void
+Virtual_font_metric::derived_mark()
+{
+  scm_gc_mark (font_list_);
+
+}
+
+int
+Virtual_font_metric::count () const
+{
+  int k = 0;
+  for (SCM s = font_list_; gh_pair_p (s); s = gh_cdr (s))
+    {
+      k+= unsmob_metrics (gh_car (s))->count ();
+    }
+
+  return k;
+}
+
+Molecule
+Virtual_font_metric::find_by_name (String glyph) const
+{
+  Molecule m;  
+  for (SCM s = font_list_; m.empty_b () && gh_pair_p (s); s = gh_cdr (s))
+    {
+      m = unsmob_metrics (gh_car (s))->find_by_name (glyph);
+    }
+
+  return m;
+}
+  
+  
+
+Box
+Virtual_font_metric::get_char (int code)  const
+{
+  int last_k = 0;
+  for (SCM s = font_list_; gh_pair_p (s); s = gh_cdr (s))
+    {
+      Font_metric* fm = unsmob_metrics (gh_car (s));
+      int k = last_k + fm->count ();
+      if (last_k <= code && code < k)
+       {
+         return fm->get_char (code - last_k);
+       }
+      last_k = k;
+    }
+
+  
+  return Box();
+}
+