]> git.donarmstrong.com Git - lilypond.git/commitdiff
lilypond-0.0.4
authorfred <fred>
Fri, 18 Oct 1996 20:45:06 +0000 (20:45 +0000)
committerfred <fred>
Fri, 18 Oct 1996 20:45:06 +0000 (20:45 +0000)
dimen.cc [new file with mode: 0644]
dimen.hh [new file with mode: 0644]
lookupsyms.hh [new file with mode: 0644]
symtable.cc
tex.cc

diff --git a/dimen.cc b/dimen.cc
new file mode 100644 (file)
index 0000000..eb53756
--- /dev/null
+++ b/dimen.cc
@@ -0,0 +1,40 @@
+#include <ctype.h>
+#include "dimen.hh"
+#include "debug.hh"
+#include "string.hh"
+
+Real
+parse_dimen(String dim)
+{
+    int i=dim.len()-1;
+    const char *s = dim;
+    while  (i > 0 && (isspace(s[i]) || isalpha(s[i])) ){
+       i--;
+    }
+    String unit(s + i+1);
+    return convert_dimen(dim.fvalue(), unit); 
+}
+
+const Real CM_TO_PT=72/2.54;
+
+Real
+convert_dimen(Real quant, String unit)
+{
+    if (unit == "cm")
+       return quant * CM_TO_PT;
+    if (unit == "pt")
+       return quant;
+    if (unit == "mm")
+       return quant*CM_TO_PT/10;
+    if (unit == "in")
+       return quant * 72;
+    error ("unknown length unit: `" + unit+"'");
+}
+
+String
+print_dimen(Real r)
+{
+    String s(r);
+    s += "pt ";
+    return s;
+}
diff --git a/dimen.hh b/dimen.hh
new file mode 100644 (file)
index 0000000..4ee17ea
--- /dev/null
+++ b/dimen.hh
@@ -0,0 +1,12 @@
+#ifndef DIMEN_HH
+#define DIMEN_HH
+
+#include "real.hh"
+#include "string.hh"
+
+Real parse_dimen(String);
+Real convert_dimen(Real, String);
+String print_dimen(Real);
+
+#endif
+
diff --git a/lookupsyms.hh b/lookupsyms.hh
new file mode 100644 (file)
index 0000000..d4e0866
--- /dev/null
@@ -0,0 +1,18 @@
+/*
+  lilypond, (c) 1996 Han-Wen Nienhuys
+*/
+#ifndef LOOKUPSYMS_HH
+#define LOOKUPSYMS_HH
+
+#include "symbol.hh"
+
+struct Lookup {
+    static Parametric_symbol *linestaff(int n);
+    static Parametric_symbol *meter(String);
+    static Symbol ball(int);
+    static Symbol rest(int);
+    static Symbol bar(String);
+    static Symbol dots(int);
+};
+
+#endif
index 5d295d0be5aafacf5eb41d5f015b2385198e8d39..b4de607b8d3a54a574510a4817c6b3ea7bff3c21 100644 (file)
@@ -1,23 +1,24 @@
 #include "misc.hh"
+#include "dimen.hh"
 #include "debug.hh"
 #include "real.hh"
 #include "symbol.hh"
 #include "assoc.hh"
 #include "symtable.hh"
-#include "const.hh"
 
-static Symbol unknown;
 
 
-// scary! What if Symtable resizes on the fly...?
-const Symbol *
+
+
+Symbol 
 Symtable::lookup(String s) const
 {
     if (elt_query(s))
-       return &(*this)[s];
+       return (*this)[s];
     else {
+        Symbol unknown;
        WARN<<"Unknown symbol " << s <<'\n';
-       return &unknown;
+       return unknown;
     }
 }
 
@@ -54,7 +55,7 @@ Symtables::read()
             String tex=r[i++];
             svec<Real> dims;
             for (int j=0; j < 4; j++)
-                dims.add( r[i++].fvalue() *1.0/CM_TO_PT);
+                dims.add( parse_dimen(r[i++]));
             
             Symbol s(tex, Box(dims));
             (*sp)[id] = s;
@@ -63,56 +64,5 @@ Symtables::read()
      }
 }
 
-Symtables the_sym_tables("symbol.ini");
-
-
-const Symbol*
-Symbol::find_ball(int j)
-{
-    if (j > 4) j = 4;
-    Symtable * st = the_sym_tables("balls");
-    return st->lookup(String(j));
-}
 
-const Symbol*
-Symbol::find_rest(int j)
-{
-    return the_sym_tables("rests")->lookup(String(j));
-}
-const Symbol*
-Symbol::find_bar(String s)
-{
-    return the_sym_tables("bars")->lookup(s);
-}
-/****************************************************************/
-// bare bones.
 
-struct Linestaf_symbol : Stretchable_symbol {
-    int lines;
-    String operator ()(Real w);
-    Linestaf_symbol(int n) { lines = n;}
-    Interval height(Real) const { return Interval(0,lines*1/CM_TO_PT); }
-};
-
-
-
-// should be done in TeX
-String
-Linestaf_symbol::operator()(Real w)
-{
-    String s;
-    s += "\\hbox to 0pt{";
-    s+= "\\vbox to 0pt{";
-    for (int i=0; i<lines; i++) {
-       if (i) s+= "\\vskip1pt";
-       s+= "\\hrule width " + String(w* HOR_TO_PT) +"pt";
-    }
-    s+="\\vss}\\hss}";
-    return s;
-}
-
-const Stretchable_symbol *
-Stretchable_symbol::get_linestaff(int n)
-{
-    return new Linestaf_symbol(n);
-}
diff --git a/tex.cc b/tex.cc
index e11ebb90b826ed0b5a287461a6010bf57b7ab942..ae9dc1b5f3064bb2e9d7d6fc239a046394b4030c 100644 (file)
--- a/tex.cc
+++ b/tex.cc
@@ -1,28 +1,32 @@
-
+#include "dimen.hh"
 #include "tex.hh"
 #include "symbol.hh"
 #include "const.hh"
-/*
-    #TeXstring# should generate a TeX string to typeset the object in
-  a hbox or vbox of exactly the objects' dimension.
-*/
-
 
-/// #h# is in points
 String
 vstrut(Real h)
 {
-    return String("\\vrule height ") + h + "pt depth 0pt width 0pt";
+    return String("\\vrule height ") + print_dimen(h) + "depth 0pt width 0pt";
 }
 
 
-/// the staff with five lines.
- struct  Fiveline_staff: Stretchable_symbol {
-     String operator()(Real width) {
-       String s("\\normalebalk{ ");
-       s+=width * HOR_TO_PT;
-       s+= "pt}";
-       return s;
-    }    
-};
+static void
+substitute_arg(String& r, String arg)
+{
+    int p = r.pos('%');
+    if (!p ) return ;
+    else p--;
+    r = r.left(p) + arg + r.right(r.len() - p -1);
+}
+
 
+String
+substitute_args(String source, svec<String> args)    
+{
+    String retval (source);
+    for (int i = 0 ; i < args.sz(); i++)
+        substitute_arg(retval, args[i]);
+    while (retval.pos('%'))
+        substitute_arg(retval, "");
+    return retval;
+}