lilypond-0.1.37
[lilypond.git] / lily / dimen.cc
blob5e85f4992d5b0157bc798ea4dff7d589c3a7d10b
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.ch_C ();
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;