]> gitweb.factorcode.org Git - factor.git/blob - basis/pango/pango.factor
add generation of records as STRUCT: with slots when the record is listed in IMPLEMEN...
[factor.git] / basis / pango / pango.factor
1 ! Copyright (C) 2009 Anton Gorenko.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors alien alien.syntax alien.c-types alien.destructors 
4 alien.strings alien.libraries arrays classes.struct combinators 
5 destructors fonts init kernel math math.rectangles memoize 
6 io.encodings.utf8 system
7 gir glib glib.ffi ;
8
9 << 
10 "pango" {
11     { [ os winnt? ] [ "libpango-1.0-0.dll" cdecl add-library ] }
12     { [ os macosx? ] [ "/opt/local/lib/libpango-1.0.0.dylib" cdecl add-library ] }
13     { [ os unix? ] [ drop ] }
14 } cond 
15 >>
16
17 IN: pango.ffi
18
19 TYPEDEF: void PangoLayoutRun ! не совсем верно
20 TYPEDEF: guint32 PangoGlyph
21
22 IN-GIR: pango vocab:pango/Pango-1.0.gir
23
24 IN: pango.ffi
25
26 FORGET: PangoRectangle
27
28 STRUCT: PangoRectangle
29     { x int }
30     { y int }
31     { width int }
32     { height int } ;
33
34 IN: pango
35
36 CONSTANT: PANGO_SCALE 1024
37
38 : pango>float ( n -- x ) PANGO_SCALE /f ; inline
39 : float>pango ( x -- n ) PANGO_SCALE * >integer ; inline
40
41 : PangoRectangle>rect ( PangoRectangle -- rect )
42     [ [ x>> pango>float ] [ y>> pango>float ] bi 2array ]
43     [ [ width>> pango>float ] [ height>> pango>float ] bi 2array ] bi
44     <rect> ;
45
46 DESTRUCTOR: pango_font_description_free
47
48 DESTRUCTOR: pango_layout_iter_free
49
50 ! перенести в ui.*?
51 MEMO: (cache-font-description) ( font -- description )
52     [
53         [ pango_font_description_new |pango_font_description_free ] dip {
54             [ name>> utf8 string>alien pango_font_description_set_family ]
55             [ size>> float>pango pango_font_description_set_size ]
56             [ bold?>> PANGO_WEIGHT_BOLD PANGO_WEIGHT_NORMAL ? pango_font_description_set_weight ]
57             [ italic?>> PANGO_STYLE_ITALIC PANGO_STYLE_NORMAL ? pango_font_description_set_style ]
58             [ drop ]
59         } 2cleave
60     ] with-destructors ;
61
62 : cache-font-description ( font -- description )
63     strip-font-colors (cache-font-description) ;
64
65 [ \ (cache-font-description) reset-memoized ] "pango" add-startup-hook
66