]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/font-metric.cc
Clean up buildscripts
[lilypond.git] / lily / font-metric.cc
index e542a73cfef7be6909798cb7caf474593726f48c..d9ccecbc91430826aae2eb90db2fdd400ac35217 100644 (file)
-/*   
-  font-metric.cc --  implement Font_metric
-  
+/*
+  font-metric.cc -- implement Font_metric
+
   source file of the GNU LilyPond music typesetter
-  
-  (c) 1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
-  
- */
 
-#include <math.h>
-#include <ctype.h>
+  (c) 1999--2008 Han-Wen Nienhuys <hanwen@xs4all.nl>
 
+  Mats Bengtsson <matsb@s3.kth.se> (the ugly TeX parsing in text_dimension)
+*/
 
 #include "font-metric.hh"
 
-Box
-Font_metric::text_dimension (String text) const
+#include <cmath>
+#include <cctype>
+using namespace std;
+
+#include "dimensions.hh"
+#include "modified-font-metric.hh"
+#include "open-type-font.hh"
+#include "stencil.hh"
+#include "warn.hh"
+
+#include "ly-smobs.icc"
+
+Real
+Font_metric::design_size () const
+{
+  return 1.0 * point_constant;
+}
+
+Stencil
+Font_metric::find_by_name (string s) const
 {
-  Interval ydims;
-  Real w=0.0;
-  
-  for (int i = 0; i < text.length_i (); i++) 
+  replace_all (&s, '-', 'M');
+  int idx = name_to_index (s);
+  Box b;
+
+  SCM expr = SCM_EOL;
+  if (idx >= 0)
     {
-      
-      if (text[i]=='\\') 
-       {
-         for (i++; (i < text.length_i ()) && isalpha(text[i]); i++)
-           ;
-         // ugh.
-         i--; // Compensate for the increment in the outer loop!
-       }
-      else
-       {
-         Character_metric const *c = get_char ((unsigned char)text[i],false);
-
-         // Ugh, use the width of 'x' for unknown characters
-         if (c->dimensions()[X_AXIS].length () == 0) 
-           c = get_char ((unsigned char)'x',false);
-         
-         w += c->dimensions()[X_AXIS].length ();
-         ydims.unite (c->dimensions()[Y_AXIS]);
-       }
+      expr = scm_list_3 (ly_symbol2scm ("named-glyph"),
+                        self_scm (),
+                        ly_string2scm (s));
+      b = get_indexed_char (idx);
     }
-  if (ydims.empty_b ())
-    ydims = Interval (0,0);
 
-  return Box(Interval (0, w), ydims);
+  Stencil q (b, expr);
+  return q;
 }
 
+Font_metric::Font_metric ()
+{
+  description_ = SCM_EOL;
+  self_scm_ = SCM_EOL;
+  smobify_self ();
+}
 
-Box
-Scaled_font_metric::text_dimension (String t) const
+Font_metric::Font_metric (Font_metric const &)
 {
-  Real realmag = pow (1.2, magstep_i_);
-  Box b (orig_l_->text_dimension (t));
+}
 
-  return Box(b[X_AXIS]* realmag, b[Y_AXIS]*realmag);
+Font_metric::~Font_metric ()
+{
 }
 
+size_t
+Font_metric::count () const
+{
+  return 0;
+}
 
 Box
-Character_metric::dimensions () const
+Font_metric::get_ascii_char (size_t) const
 {
-  return Box(Interval(0,0), Interval(0,0));
+  return Box (Interval (0, 0), Interval (0, 0));
 }
 
-Font_metric::~Font_metric ()
+Box
+Font_metric::get_indexed_char (size_t k) const
 {
-  unsmobify_self ();
+  return get_ascii_char (k);
 }
 
-Font_metric::Font_metric ()
+size_t
+Font_metric::name_to_index (string) const
 {
-  self_scm_ = SCM_EOL;
-  smobify_self ();
+  return (size_t)-1;
 }
 
-Font_metric::Font_metric (Font_metric const &)
+Offset
+Font_metric::get_indexed_wxwy (size_t) const
 {
+  return Offset (0, 0);
 }
 
-Character_metric::~Character_metric()
+void
+Font_metric::derived_mark () const
 {
 }
 
-Character_metric const *
-Font_metric::get_char (int, bool)const
+SCM
+Font_metric::mark_smob (SCM s)
 {
-  return 0;
+  Font_metric *m = (Font_metric *) SCM_CELL_WORD_1 (s);
+  m->derived_mark ();
+  return m->description_;
 }
 
-Scaled_font_metric::Scaled_font_metric (Font_metric* m, int s)
+int
+Font_metric::print_smob (SCM s, SCM port, scm_print_state *)
 {
-  magstep_i_ = s;
-  orig_l_ = m;
+  Font_metric *m = unsmob_metrics (s);
+  scm_puts ("#<", port);
+  scm_puts (m->class_name (), port);
+  scm_puts (" ", port);
+  scm_write (m->description_, port);
+  scm_puts (">", port);
+  return 1;
 }
 
+IMPLEMENT_SMOBS (Font_metric);
+IMPLEMENT_DEFAULT_EQUAL_P (Font_metric);
+IMPLEMENT_TYPE_P (Font_metric, "ly:font-metric?");
+
 SCM
-Font_metric::description () const
+Font_metric::font_file_name () const
 {
-  return gh_cons (ly_symbol2scm (name_str_.ch_C()), gh_int2scm (0));
+  return scm_car (description_);
 }
 
+string
+Font_metric::font_name () const
+{
+  string s ("unknown");
+  return s;
+}
 
-SCM
-Scaled_font_metric::description () const
+size_t
+Font_metric::index_to_ascii (size_t i) const
 {
-  SCM od = orig_l_->description ();
-  gh_set_cdr_x (od, gh_int2scm (magstep_i_));
-  return od;
+  return i;
 }
 
+size_t
+Font_metric::index_to_charcode (size_t i) const
+{
+  return index_to_ascii (i);
+}
 
-void
-Font_metric::do_smobify_self ()
+Stencil
+Font_metric::get_ascii_char_stencil (size_t code) const
+{
+  SCM at = scm_list_3 (ly_symbol2scm ("char"), self_scm (),
+                      scm_from_unsigned (code));
+  Box b = get_ascii_char (code);
+  return Stencil (b, at);
+}
+
+Stencil
+Font_metric::get_indexed_char_stencil (size_t code) const
 {
+  size_t idx = index_to_ascii (code);
+  SCM at = scm_list_3 (ly_symbol2scm ("char"), self_scm (),
+                      scm_from_unsigned (idx));
+  Box b = get_indexed_char (code);
+  return Stencil (b, at);
+}
+
+Offset
+Font_metric::attachment_point (string) const
+{
+  return Offset (0, 0);
 }
 
 SCM
-Font_metric::mark_smob (SCM s)
+Font_metric::sub_fonts () const
 {
   return SCM_EOL;
 }
 
-int
-Font_metric::print_smob (SCM s, SCM port, scm_print_state * )
+Stencil
+Font_metric::word_stencil (string str) const
 {
-  scm_puts ("#<Font_metric>", port);
-  
-  return 1;
+  return text_stencil (str);
 }
 
+Stencil
+Font_metric::text_stencil (string /* str */) const
+{
+  programming_error("Cannot get a text stencil from this font");
+  return Stencil (Box (), SCM_EOL);
+}
 
-
+Box
+Font_metric::text_dimension (string) const
+{
+  return Box (Interval (0, 0), Interval (0, 0));
+}