|
| 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 | + |
| 31 | + method style : js_string t readonly_prop |
| 32 | + |
| 33 | + method weight : js_string t readonly_prop |
| 34 | + |
| 35 | + method stretch : js_string t readonly_prop |
| 36 | + |
| 37 | + method unicodeRange : js_string t readonly_prop |
| 38 | + |
| 39 | + method variant : js_string t readonly_prop |
| 40 | + |
| 41 | + method featureSettings : js_string t readonly_prop |
| 42 | + |
| 43 | + method display : js_string t readonly_prop |
| 44 | + |
| 45 | + method src : js_string t readonly_prop |
| 46 | + |
| 47 | + method status : js_string t readonly_prop |
| 48 | + |
| 49 | + method load : unit -> 'a meth |
| 50 | +end |
| 51 | + |
| 52 | +class type fontFaceSet = object |
| 53 | + method add : fontFaceElement Js.t -> unit meth |
| 54 | + |
| 55 | + method check : js_string t -> js_string t -> bool meth |
| 56 | + |
| 57 | + method delete : fontFaceElement Js.t -> unit meth |
| 58 | + |
| 59 | + method load : unit -> 'a meth |
| 60 | + |
| 61 | + method ready : bool readonly_prop |
| 62 | + |
| 63 | + method status : js_string t readonly_prop |
| 64 | +end |
| 65 | + |
| 66 | +let constr : (js_string t -> js_string t -> fontFaceElement t) Js.constr = |
| 67 | + Unsafe.pure_js_expr "FontFace" |
| 68 | + |
| 69 | +let create_font_face (family : js_string Js.t) (source : js_string Js.t) = |
| 70 | + new%js constr family source |
| 71 | + |
| 72 | +let load_and_then (font_face : fontFaceElement Js.t) (f : unit -> unit) = |
| 73 | + let f = Unsafe.inject @@ Js.wrap_meth_callback f in |
| 74 | + let js_promise = font_face##load () in |
| 75 | + Unsafe.meth_call js_promise "then" [| Unsafe.coerce f |] |
0 commit comments