Move fonts to basis/bitstream-vera

Use ui.cocoa.text instead of ui.freetype on Mac OS X
Update deploy tool to not copy fonts/ directory on Mac OS X
db4
Slava Pestov 2009-01-20 14:31:09 -06:00
parent e6e831c577
commit 25b0512fd6
27 changed files with 96 additions and 35 deletions

View File

@ -10,6 +10,4 @@ IN: bootstrap.ui
{ [ os unix? ] [ "x11" ] } { [ os unix? ] [ "x11" ] }
} cond } cond
] unless* "ui." prepend require ] unless* "ui." prepend require
"ui.freetype" require
] when ] when

View File

@ -4,7 +4,7 @@ USING: alien alien.syntax kernel system combinators ;
IN: freetype IN: freetype
<< "freetype" { << "freetype" {
{ [ os macosx? ] [ "@executable_path/../Frameworks/libfreetype.6.dylib" "cdecl" add-library ] } { [ os macosx? ] [ "libfreetype.6.dylib" "cdecl" add-library ] }
{ [ os windows? ] [ "freetype6.dll" "cdecl" add-library ] } { [ os windows? ] [ "freetype6.dll" "cdecl" add-library ] }
{ [ t ] [ drop ] } { [ t ] [ drop ] }
} cond >> } cond >>

View File

@ -1,4 +1,4 @@
! Copyright (C) 2007, 2008 Slava Pestov. ! Copyright (C) 2007, 2009 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: io io.files io.files.info.unix io.pathnames USING: io io.files io.files.info.unix io.pathnames
io.directories io.directories.hierarchy kernel namespaces make io.directories io.directories.hierarchy kernel namespaces make
@ -35,9 +35,6 @@ IN: tools.deploy.macosx
: copy-dll ( bundle-name -- ) : copy-dll ( bundle-name -- )
"Frameworks/libfactor.dylib" copy-bundle-dir ; "Frameworks/libfactor.dylib" copy-bundle-dir ;
: copy-freetype ( bundle-name -- )
deploy-ui? get [ "Frameworks" copy-bundle-dir ] [ drop ] if ;
: copy-nib ( bundle-name -- ) : copy-nib ( bundle-name -- )
deploy-ui? get [ deploy-ui? get [
"Resources/English.lproj/MiniFactor.nib" copy-bundle-dir "Resources/English.lproj/MiniFactor.nib" copy-bundle-dir
@ -45,13 +42,11 @@ IN: tools.deploy.macosx
: create-app-dir ( vocab bundle-name -- vm ) : create-app-dir ( vocab bundle-name -- vm )
[ [
nip { nip
[ copy-dll ] [ copy-dll ]
[ copy-freetype ] [ copy-nib ]
[ copy-nib ] [ "Contents/Resources" append-path make-directories ]
[ "Contents/Resources/" copy-fonts ] tri
[ "Contents/Resources" append-path make-directories ]
} cleave
] ]
[ create-app-plist ] [ create-app-plist ]
[ "Contents/MacOS/" append-path "" copy-vm ] 2tri [ "Contents/MacOS/" append-path "" copy-vm ] 2tri

View File

@ -7,8 +7,8 @@ cocoa.windows cocoa.classes cocoa.nibs sequences system ui
ui.backend ui.clipboards ui.gadgets ui.gadgets.worlds ui.backend ui.clipboards ui.gadgets ui.gadgets.worlds
ui.cocoa.views core-foundation core-foundation.run-loop ui.cocoa.views core-foundation core-foundation.run-loop
core-graphics.types threads math.geometry.rect fry libc core-graphics.types threads math.geometry.rect fry libc
generalizations alien.c-types cocoa.views combinators generalizations alien.c-types cocoa.views ui.cocoa.text
io.thread ; combinators io.thread ;
IN: ui.cocoa IN: ui.cocoa
TUPLE: handle ; TUPLE: handle ;

View File

@ -0,0 +1 @@
Slava Pestov

View File

@ -0,0 +1 @@
UI text rendering implementation using Mac OS X Core Text

View File

@ -0,0 +1 @@
unportable

View File

@ -0,0 +1,4 @@
! Copyright (C) 2009 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: tools.test ui.cocoa.text ;
IN: ui.cocoa.text.tests

View File

@ -0,0 +1,60 @@
! Copyright (C) 2009 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: assocs accessors alien core-graphics.types core-text kernel
namespaces sequences ui.gadgets.worlds ui.render opengl opengl.gl ;
IN: ui.cocoa.text
SINGLETON: core-text-renderer
CONSTANT: font-names
H{
{ "monospace" "Monaco" }
{ "sans-serif" "Helvetica" }
{ "serif" "Times" }
}
USING: classes.algebra unicode.case.private ;
: font-name/size ( font -- name size )
[ first font-names at-default ] [ third ] bi ;
M: core-text-renderer open-font
dup alien? [ font-name/size cached-font ] unless ;
: string-dim ( open-font string -- dim )
swap cached-line dim>> ;
M: core-text-renderer string-width ( open-font string -- w )
string-dim first ;
M: core-text-renderer string-height ( open-font string -- h )
[ " " ] when-empty string-dim second ;
TUPLE: line-texture line texture age ;
: <line-texture> ( line -- texture )
dup [ dim>> ] [ bitmap>> ] bi GL_RGBA make-texture
0 \ line-texture boa ;
: line-texture ( string open-font -- texture )
world get fonts>> [ cached-line <line-texture> ] 2cache ;
: draw-line-texture ( line-texture -- )
GL_TEXTURE_2D [
GL_TEXTURE_BIT [
GL_TEXTURE_COORD_ARRAY [
GL_TEXTURE_2D over texture>> glBindTexture
init-texture rect-texture-coords
line>> dim>> fill-rect-vertices (gl-fill-rect)
GL_TEXTURE_2D 0 glBindTexture
] do-enabled-client-state
] do-attribs
] do-enabled ;
M: core-text-renderer draw-string ( font string loc -- )
[ swap open-font line-texture draw-line-texture ] with-translation ;
M: core-text-renderer x>offset ( x font string -- n )
swap cached-line swap 0 <CGPoint> CTLineGetStringIndexForPosition ;
core-text-renderer font-renderer set-global

View File

@ -7,7 +7,7 @@ ui.gadgets.worlds ui.render ui.backend byte-arrays accessors
locals specialized-arrays.direct.uchar ; locals specialized-arrays.direct.uchar ;
IN: ui.freetype IN: ui.freetype
TUPLE: freetype-renderer ; SINGLETON: freetype-renderer
SYMBOL: open-fonts SYMBOL: open-fonts
@ -61,7 +61,7 @@ M: freetype-renderer free-fonts ( world -- )
} at ; } at ;
: ttf-path ( name -- string ) : ttf-path ( name -- string )
"resource:fonts/" ".ttf" surround ; "resource:basis/bitstream-vera/" ".ttf" surround ;
: (open-face) ( path length -- 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
@ -223,4 +223,4 @@ M: freetype-renderer x>offset ( x font string -- n )
[ run-char-widths [ <= ] with find drop ] keep swap [ run-char-widths [ <= ] with find drop ] keep swap
[ ] [ length ] ?if ; [ ] [ length ] ?if ;
T{ freetype-renderer } font-renderer set-global freetype-renderer font-renderer set-global

View File

@ -1 +1 @@
UI text rendering implementation based on FreeType UI text rendering implementation using FreeType

View File

@ -0,0 +1 @@
unportable

View File

@ -174,7 +174,7 @@ M: editor ungraft*
line-translation gl-translate ; line-translation gl-translate ;
: draw-line ( editor str -- ) : draw-line ( editor str -- )
[ font>> ] dip { 0 0 } draw-string ; [ font>> ] dip { 0 0 } draw-text ;
: first-visible-line ( editor -- n ) : first-visible-line ( editor -- n )
[ [

View File

@ -142,7 +142,7 @@ M: table layout*
: draw-column ( font column width align -- ) : draw-column ( font column width align -- )
over [ over [
[ 2dup ] 2dip column-loc draw-string [ 2dup ] 2dip column-loc draw-text
] dip table-gap + 0 2array gl-translate ; ] dip table-gap + 0 2array gl-translate ;
: draw-row ( columns widths align font -- ) : draw-row ( columns widths align font -- )

View File

@ -39,7 +39,7 @@ HELP: world
{ { $snippet "status" } " - a " { $link model } " holding a string to be displayed in the world's status bar." } { { $snippet "status" } " - a " { $link model } " holding a string to be displayed in the world's status bar." }
{ { $snippet "focus" } " - the current owner of the keyboard focus in the world." } { { $snippet "focus" } " - the current owner of the keyboard focus in the world." }
{ { $snippet "focused?" } " - a boolean indicating if the native window containing the world has keyboard focus." } { { $snippet "focused?" } " - a boolean indicating if the native window containing the world has keyboard focus." }
{ { $snippet "fonts" } " - a hashtable mapping font instances to vectors of " { $link sprite } " instances." } { { $snippet "fonts" } " - a hashtable used by the " { $link font-renderer } "." }
{ { $snippet "handle" } " - a backend-specific native handle representing the native window containing the world, or " { $link f } " if the world is not grafted." } { { $snippet "handle" } " - a backend-specific native handle representing the native window containing the world, or " { $link f } " if the world is not grafted." }
{ { $snippet "window-loc" } " - the on-screen location of the native window containing the world. The co-ordinate system here is backend-specific." } { { $snippet "window-loc" } " - the on-screen location of the native window containing the world. The co-ordinate system here is backend-specific." }
} }

View File

@ -3,14 +3,14 @@
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: alien alien.c-types alien.strings arrays assocs ui USING: alien alien.c-types alien.strings arrays assocs ui
ui.gadgets ui.backend ui.clipboards ui.gadgets.worlds ui.gadgets ui.backend ui.clipboards ui.gadgets.worlds
ui.gestures ui.event-loop io kernel math math.vectors namespaces ui.gestures ui.event-loop ui.freetype io kernel math
make sequences strings vectors words windows.kernel32 math.vectors namespaces make sequences strings vectors words
windows.gdi32 windows.user32 windows.opengl32 windows.messages windows.kernel32 windows.gdi32 windows.user32 windows.opengl32
windows.types windows.nt windows threads libc combinators fry windows.messages windows.types windows.nt windows threads libc
combinators.short-circuit continuations command-line shuffle combinators fry combinators.short-circuit continuations
opengl ui.render ascii math.bitwise locals accessors command-line shuffle opengl ui.render ascii math.bitwise locals
math.geometry.rect math.order ascii calendar io.encodings.utf16n accessors math.geometry.rect math.order ascii calendar
; io.encodings.utf16n ;
IN: ui.windows IN: ui.windows
SINGLETON: windows-ui-backend SINGLETON: windows-ui-backend

View File

@ -2,10 +2,10 @@
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: accessors alien alien.c-types arrays ui ui.gadgets USING: accessors alien alien.c-types arrays ui ui.gadgets
ui.gestures ui.backend ui.clipboards ui.gadgets.worlds ui.render ui.gestures ui.backend ui.clipboards ui.gadgets.worlds ui.render
ui.event-loop assocs kernel math namespaces opengl sequences ui.event-loop ui.freetype assocs kernel math namespaces opengl
strings x11.xlib x11.events x11.xim x11.glx x11.clipboard sequences strings x11.xlib x11.events x11.xim x11.glx
x11.constants x11.windows io.encodings.string io.encodings.ascii x11.clipboard x11.constants x11.windows io.encodings.string
io.encodings.utf8 combinators command-line io.encodings.ascii io.encodings.utf8 combinators command-line
math.vectors classes.tuple opengl.gl threads math.geometry.rect math.vectors classes.tuple opengl.gl threads math.geometry.rect
environment ascii ; environment ascii ;
IN: ui.x11 IN: ui.x11