Make dpi configurable and eliminate ui.freetype => io.mmap dependency

db4
Slava Pestov 2008-01-29 00:37:24 -06:00
parent 330d59b934
commit 55fee86717
1 changed files with 14 additions and 8 deletions

22
extra/ui/freetype/freetype.factor Normal file → Executable file
View File

@ -3,7 +3,7 @@
USING: alien alien.c-types arrays io kernel libc math USING: alien alien.c-types arrays io kernel libc math
math.vectors namespaces opengl opengl.gl prettyprint assocs math.vectors namespaces opengl opengl.gl prettyprint assocs
sequences io.files io.styles continuations freetype sequences io.files io.styles continuations freetype
ui.gadgets.worlds ui.render ui.backend io.mmap ; ui.gadgets.worlds ui.render ui.backend byte-arrays ;
IN: ui.freetype IN: ui.freetype
TUPLE: freetype-renderer ; TUPLE: freetype-renderer ;
@ -63,18 +63,23 @@ M: freetype-renderer free-fonts ( world -- )
: ttf-path ( name -- string ) : ttf-path ( name -- string )
"/fonts/" swap ".ttf" 3append resource-path ; "/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 #! We use FT_New_Memory_Face, not FT_New_Face, since
#! FT_New_Face only takes an ASCII path name and causes #! FT_New_Face only takes an ASCII path name and causes
#! problems on localized versions of Windows #! problems on localized versions of Windows
freetype swap dup mapped-file-address swap length 0 f freetype -rot 0 f <void*> [
<void*> [ FT_New_Memory_Face freetype-error ] keep *void* ; FT_New_Memory_Face freetype-error
] keep *void* ;
: open-face ( font style -- face ) : open-face ( font style -- face )
ttf-name ttf-path dup file-length ttf-name ttf-path
<mapped-file> (open-face) ; dup file-contents >byte-array malloc-byte-array
swap file-length
(open-face) ;
: dpi 72 ; inline SYMBOL: dpi
72 dpi set-global
: ft-floor -6 shift ; inline : ft-floor -6 shift ; inline
@ -101,7 +106,8 @@ M: freetype-renderer free-fonts ( world -- )
: (open-font) ( font -- open-font ) : (open-font) ( font -- open-font )
first3 >r open-face dup 0 r> 6 shift first3 >r open-face dup 0 r> 6 shift
dpi dpi FT_Set_Char_Size freetype-error <font> ; dpi get-global dpi get-global FT_Set_Char_Size
freetype-error <font> ;
M: freetype-renderer open-font ( font -- open-font ) M: freetype-renderer open-font ( font -- open-font )
freetype drop open-fonts get [ (open-font) ] cache ; freetype drop open-fonts get [ (open-font) ] cache ;