1+ (* Js_of_ocaml library
2+ * http://www.ocsigen.org/js_of_ocaml/
3+ * Copyright (C) 2014 Hugo Heuzard
4+ * Copyright (C) 2014 Jérôme Vouillon
5+ *
6+ * This program is free software; you can redistribute it and/or modify
7+ * it under the terms of the GNU Lesser General Public License as published by
8+ * the Free Software Foundation, with linking exception;
9+ * either version 2.1 of the License, or (at your option) any later version.
10+ *
11+ * This program is distributed in the hope that it will be useful,
12+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+ * GNU Lesser General Public License for more details.
15+ *
16+ * You should have received a copy of the GNU Lesser General Public License
17+ * along with this program; if not, write to the Free Software
18+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19+ *)
20+
21+ (* * CSS Font Loading API binding
22+
23+ This is a partial binding to the CSS Font Loading API
24+ *)
25+
26+ open Js
27+
28+ class type fontFaceElement = object
29+ method family : js_string t readonly_prop
30+ method style : js_string t readonly_prop
31+ method weight : js_string t readonly_prop
32+ method stretch : js_string t readonly_prop
33+ method unicodeRange : js_string t readonly_prop
34+ method variant : js_string t readonly_prop
35+ method featureSettings : js_string t readonly_prop
36+ method display : js_string t readonly_prop
37+ method src : js_string t readonly_prop
38+ method status : js_string t readonly_prop
39+ method load : unit -> 'a meth
40+ end
41+
42+ class type fontFaceSet = object
43+ method add : fontFaceElement Js. t -> unit meth
44+ method check : js_string t -> js_string t -> bool meth
45+ method delete : fontFaceElement Js. t -> unit meth
46+ method load : unit -> 'a meth
47+ method ready : bool readonly_prop
48+ method status : js_string t readonly_prop
49+ end
50+
51+ let create_font_face (family : js_string Js.t ) (source : js_string Js.t ) =
52+ let family = Unsafe. coerce family in
53+ let source = Unsafe. coerce source in
54+ Unsafe. coerce @@ Unsafe. new_obj (Unsafe. pure_js_expr " FontFace" ) [|family; source|]
55+
56+ let load_and_then (font_face : fontFaceElement Js.t ) (f : unit -> unit ) =
57+ let f = Unsafe. inject @@ Js. wrap_meth_callback f in
58+ let js_promise = font_face##load () in
59+ Unsafe. meth_call js_promise " then" [|Unsafe. coerce f|]
0 commit comments