summaryrefslogtreecommitdiff
path: root/dimen.cc
diff options
context:
space:
mode:
Diffstat (limited to 'dimen.cc')
-rw-r--r--dimen.cc40
1 files changed, 40 insertions, 0 deletions
diff --git a/dimen.cc b/dimen.cc
new file mode 100644
index 0000000000..eb53756b45
--- /dev/null
+++ b/dimen.cc
@@ -0,0 +1,40 @@
+#include <ctype.h>
+#include "dimen.hh"
+#include "debug.hh"
+#include "string.hh"
+
+Real
+parse_dimen(String dim)
+{
+ int i=dim.len()-1;
+ const char *s = dim;
+ while (i > 0 && (isspace(s[i]) || isalpha(s[i])) ){
+ i--;
+ }
+ String unit(s + i+1);
+ return convert_dimen(dim.fvalue(), unit);
+}
+
+const Real CM_TO_PT=72/2.54;
+
+Real
+convert_dimen(Real quant, String unit)
+{
+ if (unit == "cm")
+ return quant * CM_TO_PT;
+ if (unit == "pt")
+ return quant;
+ if (unit == "mm")
+ return quant*CM_TO_PT/10;
+ if (unit == "in")
+ return quant * 72;
+ error ("unknown length unit: `" + unit+"'");
+}
+
+String
+print_dimen(Real r)
+{
+ String s(r);
+ s += "pt ";
+ return s;
+}