]> git.donarmstrong.com Git - lilypond.git/blob - src/dimen.cc
release: 0.0.37
[lilypond.git] / src / dimen.cc
1 #include <ctype.h>
2 #include "dimen.hh"
3 #include "debug.hh"
4 #include "string.hh"
5
6 Real
7 parse_dimen(String dim)
8 {
9     int i=dim.length_i()-1;
10     const char *s = dim;
11     while  (i > 0 && (isspace(s[i]) || isalpha(s[i])) ){
12         i--;
13     }
14     String unit(s + i+1);
15     return convert_dimen(dim.value_f(), unit); 
16 }
17
18
19 Real
20 convert_dimen(Real quant, String unit)
21 {
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+"'");
31 }
32
33 String
34 print_dimen(Real r)
35 {
36     String s(r);
37     s += "pt ";
38     return s;
39 }