File: builtini_GetPixel.ml

package info (click to toggle)
labltk 8.06.15-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,972 kB
  • sloc: ml: 12,549; ansic: 1,005; makefile: 578; sh: 289; tcl: 2
file content (43 lines) | stat: -rw-r--r-- 1,446 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
##ifdef CAMLTK

let cCAMLtoTKunits = function
    Pixels (foo) -> TkToken (string_of_int foo)
  | Millimeters (foo)  -> TkToken(Printf.sprintf "%gm" foo)
  | Inches (foo)  -> TkToken(Printf.sprintf "%gi" foo)
  | PrinterPoint (foo) -> TkToken(Printf.sprintf "%gp" foo)
  | Centimeters (foo) -> TkToken(Printf.sprintf "%gc" foo)
;;

let cTKtoCAMLunits str =
  let len = String.length str in
  let num_part str = String.sub str 0 (len - 1) in
  match String.get str (pred len) with
    'c' -> Centimeters (float_of_string (num_part str))
  | 'i' -> Inches (float_of_string (num_part str))
  | 'm' -> Millimeters (float_of_string (num_part str))
  | 'p' -> PrinterPoint (float_of_string (num_part str))
  | _ -> Pixels(int_of_string str)
;;

##else

let cCAMLtoTKunits : units -> tkArgs = function
  | `Pix (foo) -> TkToken (string_of_int foo)
  | `Mm (foo)  -> TkToken(Printf.sprintf "%gm" foo)
  | `In (foo)  -> TkToken(Printf.sprintf "%gi" foo)
  | `Pt (foo) -> TkToken(Printf.sprintf "%gp" foo)
  | `Cm (foo) -> TkToken(Printf.sprintf "%gc" foo)
;;

let cTKtoCAMLunits str =
  let len = String.length str in
  let num_part str = String.sub str ~pos:0 ~len:(len - 1) in
  match String.get str (pred len) with
  | 'c' -> `Cm (float_of_string (num_part str))
  | 'i' -> `In (float_of_string (num_part str))
  | 'm' -> `Mm (float_of_string (num_part str))
  | 'p' -> `Pt (float_of_string (num_part str))
  | _ -> `Pix(int_of_string str)
;;

##endif