summaryrefslogtreecommitdiffstats
path: root/otherlibs/labltk/builtin/builtini_GetPixel.ml
blob: c1ebdb17deb7d5a52afa24753ff17b40cddb56cf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
let cCAMLtoTKunits : units -> tkArgs = function
  | `Pix (foo) -> TkToken (string_of_int foo)
  | `Mm (foo)  -> TkToken(string_of_float foo^"m")
  | `In (foo)  -> TkToken(string_of_float foo^"i")
  | `Pt (foo) -> TkToken(string_of_float foo^"p")
  | `Cm (foo) -> TkToken(string_of_float foo^"c")

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)