--- /dev/null
+#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;
+}
--- /dev/null
+#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
+
--- /dev/null
+/*
+ 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
#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;
}
}
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;
}
}
-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);
-}
-
+#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;
+}