]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/ocaml/contrib/otherlibs/labltk/builtin/builtini_GetPixel.ml
update
[l4.git] / l4 / pkg / ocaml / contrib / otherlibs / labltk / builtin / builtini_GetPixel.ml
1 ##ifdef CAMLTK
2
3 let cCAMLtoTKunits = function
4     Pixels (foo) -> TkToken (string_of_int foo)
5   | Millimeters (foo)  -> TkToken(Printf.sprintf "%gm" foo)
6   | Inches (foo)  -> TkToken(Printf.sprintf "%gi" foo)
7   | PrinterPoint (foo) -> TkToken(Printf.sprintf "%gp" foo)
8   | Centimeters (foo) -> TkToken(Printf.sprintf "%gc" foo)
9 ;;
10
11 let cTKtoCAMLunits str = 
12   let len = String.length str in
13   let num_part str = String.sub str 0 (len - 1) in
14   match String.get str (pred len) with
15     'c' -> Centimeters (float_of_string (num_part str))
16   | 'i' -> Inches (float_of_string (num_part str))
17   | 'm' -> Millimeters (float_of_string (num_part str))
18   | 'p' -> PrinterPoint (float_of_string (num_part str))
19   | _ -> Pixels(int_of_string str)
20 ;;
21
22 ##else
23
24 let cCAMLtoTKunits : units -> tkArgs = function
25   | `Pix (foo) -> TkToken (string_of_int foo)
26   | `Mm (foo)  -> TkToken(Printf.sprintf "%gm" foo)
27   | `In (foo)  -> TkToken(Printf.sprintf "%gi" foo)
28   | `Pt (foo) -> TkToken(Printf.sprintf "%gp" foo)
29   | `Cm (foo) -> TkToken(Printf.sprintf "%gc" foo)
30 ;;
31
32 let cTKtoCAMLunits str = 
33   let len = String.length str in
34   let num_part str = String.sub str ~pos:0 ~len:(len - 1) in
35   match String.get str (pred len) with
36   | 'c' -> `Cm (float_of_string (num_part str))
37   | 'i' -> `In (float_of_string (num_part str))
38   | 'm' -> `Mm (float_of_string (num_part str))
39   | 'p' -> `Pt (float_of_string (num_part str))
40   | _ -> `Pix(int_of_string str)
41 ;;
42
43 ##endif