lilypond-0.1.11
[lilypond.git] / lily / dimen.cc
blob499d286cf2ae5f61b8a4e196597587c1f9fc40db
1 #include <ctype.h>
2 #include "dimen.hh"
3 #include "debug.hh"
4 #include "string.hh"
6 Real
7 parse_dimen (String dim)
9 int i=dim.length_i()-1;
10 char const *s = dim;
11 while (i > 0 && (isspace (s[i]) || isalpha (s[i])))
13 i--;
15 String unit (s + i+1);
16 return convert_dimen (dim.value_f(), unit);
20 Real
21 convert_dimen (Real quant, String unit)
23 if (unit == "cm")
24 return quant * CM_TO_PT;
25 if (unit == "pt")
26 return quant;
27 if (unit == "mm")
28 return quant*CM_TO_PT/10;
29 if (unit == "in")
30 return quant * INCH_TO_PT;
31 error ("unknown length unit: `" + unit+"'");
34 String
35 print_dimen (Real r)
37 String s (r, "%.3f");
38 s += "pt ";
39 return s;