flower-1.0.27
[lilypond.git] / src / dimen.cc
blob93077bd87b5b92e81ee4d05fd4739683ff2b5fa0
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.len()-1;
10 const char *s = dim;
11 while (i > 0 && (isspace(s[i]) || isalpha(s[i])) ){
12 i--;
14 String unit(s + i+1);
15 return convert_dimen(dim.fvalue(), unit);
19 Real
20 convert_dimen(Real quant, String unit)
22 if (unit == "cm")
23 return quant * CM_TO_PT;
24 if (unit == "pt")
25 return quant;
26 if (unit == "mm")
27 return quant*CM_TO_PT/10;
28 if (unit == "in")
29 return quant * INCH_TO_PT;
30 error ("unknown length unit: `" + unit+"'");
33 String
34 print_dimen(Real r)
36 String s(r);
37 s += "pt ";
38 return s;