]> gitweb.factorcode.org Git - factor.git/blob - extra/pdf/units/units.factor
b753889e818cd6b546539a62016e1f2006006009
[factor.git] / extra / pdf / units / units.factor
1 ! Copyright (C) 2011-2012 John Benediktsson
2 ! See http://factorcode.org/license.txt for BSD license
3
4 USING: ascii combinators kernel math math.parser sequences ;
5
6 IN: pdf.units
7
8 : inch ( n -- n' ) 72.0 * ;
9
10 : cm ( n -- n' ) inch 2.54 / ;
11
12 : mm ( n -- n' ) cm 0.1 * ;
13
14 : pica ( n -- n' ) 12.0 * ;
15
16 : string>points ( str -- n )
17     dup [ digit? ] find-last drop 1 + cut
18     [ string>number ] dip {
19         { "cm"   [ cm ] }
20         { "in"   [ inch ] }
21         { "pt"   [ ] }
22         { ""     [ ] }
23         { "mm"   [ mm ] }
24         { "pica" [ pica ] }
25         [ throw ]
26     } case ;