factor/basis/core-text/core-text-tests.factor

38 lines
1.2 KiB
Factor
Raw Normal View History

2009-01-16 20:11:48 -05:00
! Copyright (C) 2009 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
2009-03-07 16:58:14 -05:00
USING: tools.test core-text core-text.fonts core-foundation
core-foundation.dictionaries destructors arrays kernel generalizations
locals math accessors core-foundation.utilities combinators hashtables colors
2009-03-07 16:58:14 -05:00
colors.constants ;
2009-01-16 20:11:48 -05:00
IN: core-text.tests
: test-font ( name -- font )
[ >cf &CFRelease 0.0 f CTFontCreateWithName ] with-destructors ;
2009-01-19 23:30:32 -05:00
[ ] [ "Helvetica" test-font CFRelease ] unit-test
2009-01-16 23:48:07 -05:00
[ ] [
[
kCTFontAttributeName "Helvetica" test-font &CFRelease 2array 1array
2009-01-16 23:48:07 -05:00
<CFDictionary> &CFRelease drop
] with-destructors
2009-01-19 23:30:32 -05:00
] unit-test
:: test-typographic-bounds ( string font -- ? )
2009-01-19 23:30:32 -05:00
[
font test-font &CFRelease :> ctfont
string ctfont COLOR: white <CTLine> &CFRelease :> ctline
ctfont ctline compute-line-metrics {
2009-01-19 23:30:32 -05:00
[ width>> float? ]
[ ascent>> float? ]
[ descent>> float? ]
[ leading>> float? ]
} cleave and and and
] with-destructors ;
[ t ] [ "Hello world" "Helvetica" test-typographic-bounds ] unit-test
2009-01-19 23:30:32 -05:00
[ t ] [ "Hello world" "Chicago" test-typographic-bounds ] unit-test
[ t ] [ "日本語" "Helvetica" test-typographic-bounds ] unit-test