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

diff --git a/hdr/dimen.hh b/hdr/dimen.hh
new file mode 100644 (file)
index 0000000..4ee17ea
--- /dev/null
@@ -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/src/dimen.cc b/src/dimen.cc
new file mode 100644 (file)
index 0000000..eb53756
--- /dev/null
@@ -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/src/tex.cc b/src/tex.cc
new file mode 100644 (file)
index 0000000..ae9dc1b
--- /dev/null
@@ -0,0 +1,32 @@
+#include "dimen.hh"
+#include "tex.hh"
+#include "symbol.hh"
+#include "const.hh"
+
+String
+vstrut(Real h)
+{
+    return String("\\vrule height ") + print_dimen(h) + "depth 0pt width 0pt";
+}
+
+
+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;
+}