]> git.donarmstrong.com Git - lilypond.git/blob - lily/dimen.cc
release: 0.1.11
[lilypond.git] / lily / 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   char const *s = dim;
11   while  (i > 0 && (isspace (s[i]) || isalpha (s[i])))
12     {
13       i--;
14     }
15   String unit (s + i+1);
16   return convert_dimen (dim.value_f(), unit); 
17 }
18
19
20 Real
21 convert_dimen (Real quant, String unit)
22 {
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+"'");
32 }
33
34 String
35 print_dimen (Real r)
36 {
37   String s (r, "%.3f");
38   s += "pt ";
39   return s;
40 }