]> gitweb.factorcode.org Git - factor.git/blob - extra/cairo/pango/pango.factor
Separated out cairo.pango into extra/pango and pango.fonts
[factor.git] / extra / cairo / pango / pango.factor
1 ! Copyright (C) 2008 Matthew Willis.
2 ! See http://factorcode.org/license.txt for BSD license.
3 !
4 ! pangocairo bindings, from pango/pangocairo.h
5 USING: cairo.ffi alien.c-types math
6 alien.syntax system combinators alien
7 pango pango.fonts ;
8 IN: cairo.pango
9
10 << "pangocairo" {
11 !    { [ os winnt? ] [ "libpangocairo-1.dll" ] }
12 !    { [ os macosx? ] [ "libpangocairo.dylib" ] }
13     { [ os unix? ] [ "libpangocairo-1.0.so" ] }
14 } cond "cdecl" add-library >>
15
16 LIBRARY: pangocairo
17
18 FUNCTION: PangoFontMap*
19 pango_cairo_font_map_new  ( ) ;
20
21 FUNCTION: PangoFontMap*
22 pango_cairo_font_map_new_for_font_type ( cairo_font_type_t fonttype ) ;
23
24 FUNCTION: PangoFontMap*
25 pango_cairo_font_map_get_default ( ) ;
26
27 FUNCTION: cairo_font_type_t
28 pango_cairo_font_map_get_font_type ( PangoCairoFontMap* fontmap ) ;
29
30 FUNCTION: void
31 pango_cairo_font_map_set_resolution ( PangoCairoFontMap* fontmap, double dpi ) ;
32
33 FUNCTION: double
34 pango_cairo_font_map_get_resolution ( PangoCairoFontMap* fontmap ) ;
35
36 FUNCTION: PangoContext*
37 pango_cairo_font_map_create_context ( PangoCairoFontMap* fontmap ) ;
38
39 FUNCTION: cairo_scaled_font_t*
40 pango_cairo_font_get_scaled_font ( PangoCairoFont* font ) ;
41
42 ! Update a Pango context for the current state of a cairo context
43 FUNCTION: void
44 pango_cairo_update_context ( cairo_t* cr, PangoContext* context ) ;
45
46 FUNCTION: void
47 pango_cairo_context_set_font_options ( PangoContext* context, cairo_font_options_t* options ) ;
48
49 FUNCTION: cairo_font_options_t*
50 pango_cairo_context_get_font_options ( PangoContext* context ) ;
51
52 FUNCTION: void
53 pango_cairo_context_set_resolution ( PangoContext* context, double dpi ) ;
54
55 FUNCTION: double
56 pango_cairo_context_get_resolution ( PangoContext* context ) ;
57
58 ! Convenience
59 FUNCTION: PangoLayout*
60 pango_cairo_create_layout ( cairo_t* cr ) ;
61
62 FUNCTION: void
63 pango_cairo_update_layout ( cairo_t* cr, PangoLayout* layout ) ;
64
65 ! Rendering
66 FUNCTION: void
67 pango_cairo_show_glyph_string ( cairo_t* cr, PangoFont* font, PangoGlyphString* glyphs ) ;
68
69 FUNCTION: void
70 pango_cairo_show_layout_line ( cairo_t* cr, PangoLayoutLine* line ) ;
71
72 FUNCTION: void
73 pango_cairo_show_layout ( cairo_t* cr, PangoLayout* layout ) ;
74
75 FUNCTION: void
76 pango_cairo_show_error_underline ( cairo_t* cr, double x, double y, double width, double height ) ;
77
78 ! Rendering to a path
79 FUNCTION: void
80 pango_cairo_glyph_string_path ( cairo_t* cr, PangoFont* font, PangoGlyphString* glyphs ) ;
81
82 FUNCTION: void
83 pango_cairo_layout_line_path  ( cairo_t* cr, PangoLayoutLine* line ) ;
84
85 FUNCTION: void
86 pango_cairo_layout_path ( cairo_t* cr, PangoLayout* layout ) ;
87
88 FUNCTION: void
89 pango_cairo_error_underline_path ( cairo_t* cr, double x, double y, double width, double height ) ;
90
91 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
92 ! Higher level words and combinators
93 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
94
95 USING: destructors accessors namespaces kernel cairo ;
96
97 TUPLE: pango-layout alien ;
98 C: <pango-layout> pango-layout
99 M: pango-layout dispose ( alien -- ) alien>> g_object_unref ;
100
101 : layout ( -- pango-layout ) pango-layout get ;
102
103 : (with-pango) ( layout quot -- )
104     >r alien>> pango-layout r> with-variable ; inline
105
106 : with-pango ( quot -- )
107     cr pango_cairo_create_layout <pango-layout> swap
108     [ (with-pango) ] curry with-disposal ; inline
109
110 : pango-layout-get-pixel-size ( layout -- width height )
111     0 <int> 0 <int> [ pango_layout_get_pixel_size ] 2keep
112     [ *int ] bi@ ;
113
114 : dummy-pango ( quot -- )
115     >r CAIRO_FORMAT_ARGB32 0 0 cairo_image_surface_create
116     r> [ with-pango ] curry with-cairo-from-surface ; inline
117
118 : layout-size ( quot -- width height )
119     [ layout pango-layout-get-pixel-size ] compose dummy-pango ; inline
120
121 : layout-font ( str -- )
122     pango_font_description_from_string
123     dup zero? [ "pango: not a valid font." throw ] when
124     layout over pango_layout_set_font_description
125     pango_font_description_free ;
126
127 : layout-text ( str -- )
128     layout swap -1 pango_layout_set_text ;
129
130 : families ( -- families )
131     pango_cairo_font_map_get_default list-families ;