From d4e5d78bb7a3f8853c7ca3946b6c39932346c676 Mon Sep 17 00:00:00 2001 From: fred Date: Fri, 18 Oct 1996 20:45:07 +0000 Subject: [PATCH] lilypond-0.0.9 --- hdr/dimen.hh | 12 ++++++++++++ src/dimen.cc | 40 ++++++++++++++++++++++++++++++++++++++++ src/tex.cc | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 84 insertions(+) create mode 100644 hdr/dimen.hh create mode 100644 src/dimen.cc create mode 100644 src/tex.cc diff --git a/hdr/dimen.hh b/hdr/dimen.hh new file mode 100644 index 0000000000..4ee17ea140 --- /dev/null +++ b/hdr/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/src/dimen.cc b/src/dimen.cc new file mode 100644 index 0000000000..eb53756b45 --- /dev/null +++ b/src/dimen.cc @@ -0,0 +1,40 @@ +#include +#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 index 0000000000..ae9dc1b5f3 --- /dev/null +++ b/src/tex.cc @@ -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 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; +} -- 2.39.5