 : ttf-path ( name -- string )
     "/fonts/" swap ".ttf" 3append resource-path ;
 
-: (open-face) ( mapped-file -- face )
+: (open-face) ( path length -- face )
     #! We use FT_New_Memory_Face, not FT_New_Face, since
     #! FT_New_Face only takes an ASCII path name and causes
     #! problems on localized versions of Windows
-    freetype swap dup mapped-file-address swap length 0 f
-    <void*> [ FT_New_Memory_Face freetype-error ] keep *void* ;
+    freetype -rot 0 f <void*> [
+        FT_New_Memory_Face freetype-error
+    ] keep *void* ;
 
 : open-face ( font style -- face )
-    ttf-name ttf-path dup file-length
-    <mapped-file> (open-face) ;
-
-: dpi 72 ; inline
+    ttf-name ttf-path
+    dup file-contents >byte-array malloc-byte-array
+    swap file-length
+    (open-face) ;
+
+SYMBOL: dpi
+
+72 dpi set-global
 
 : ft-floor -6 shift ; inline
 


: (open-font) ( font -- open-font )
    first3 >r open-face dup 0 r> 6 shift
    dpi dpi FT_Set_Char_Size freetype-error <font> ;

M: freetype-renderer open-font ( font -- open-font )
    freetype drop open-fonts get [ (open-font) ] cache ;

USING: alien alien.c-types arrays io kernel libc math
math.vectors namespaces opengl opengl.gl prettyprint assocs
sequences io.files io.styles continuations freetype
ui.gadgets.worlds ui.render ui.backend byte-arrays ;
IN: ui.freetype

TUPLE: freetype-renderer ;
