]> gitweb.factorcode.org Git - factor.git/blob - extra/cairo/pango/pango.factor
789044f6e1df3859df19ddc59bc31177861ae959
[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
6 USING: cairo.ffi alien.c-types math
7 alien.syntax system combinators alien ;
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 TYPEDEF: void* PangoCairoFont
19 TYPEDEF: void* PangoCairoFontMap
20 TYPEDEF: void* PangoFontMap
21
22 FUNCTION: PangoFontMap*
23 pango_cairo_font_map_new  ( ) ;
24
25 FUNCTION: PangoFontMap*
26 pango_cairo_font_map_new_for_font_type ( cairo_font_type_t fonttype ) ;
27
28 FUNCTION: PangoFontMap*
29 pango_cairo_font_map_get_default ( ) ;
30
31 FUNCTION: cairo_font_type_t
32 pango_cairo_font_map_get_font_type ( PangoCairoFontMap* fontmap ) ;
33
34 FUNCTION: void
35 pango_cairo_font_map_set_resolution ( PangoCairoFontMap* fontmap, double dpi ) ;
36
37 FUNCTION: double
38 pango_cairo_font_map_get_resolution ( PangoCairoFontMap* fontmap ) ;
39
40 FUNCTION: PangoContext*
41 pango_cairo_font_map_create_context ( PangoCairoFontMap* fontmap ) ;
42
43 FUNCTION: cairo_scaled_font_t*
44 pango_cairo_font_get_scaled_font ( PangoCairoFont* font ) ;
45
46 ! Update a Pango context for the current state of a cairo context
47 FUNCTION: void
48 pango_cairo_update_context ( cairo_t* cr, PangoContext* context ) ;
49
50 FUNCTION: void
51 pango_cairo_context_set_font_options ( PangoContext* context, cairo_font_options_t* options ) ;
52
53 FUNCTION: cairo_font_options_t*
54 pango_cairo_context_get_font_options ( PangoContext* context ) ;
55
56 FUNCTION: void
57 pango_cairo_context_set_resolution ( PangoContext* context, double dpi ) ;
58
59 FUNCTION: double
60 pango_cairo_context_get_resolution ( PangoContext* context ) ;
61
62 ! Convenience
63 FUNCTION: PangoLayout*
64 pango_cairo_create_layout ( cairo_t* cr ) ;
65
66 FUNCTION: void
67 pango_cairo_update_layout ( cairo_t* cr, PangoLayout* layout ) ;
68
69 ! Rendering
70 FUNCTION: void
71 pango_cairo_show_glyph_string ( cairo_t* cr, PangoFont* font, PangoGlyphString* glyphs ) ;
72
73 FUNCTION: void
74 pango_cairo_show_layout_line ( cairo_t* cr, PangoLayoutLine* line ) ;
75
76 FUNCTION: void
77 pango_cairo_show_layout ( cairo_t* cr, PangoLayout* layout ) ;
78
79 FUNCTION: void
80 pango_cairo_show_error_underline ( cairo_t* cr, double x, double y, double width, double height ) ;
81
82 ! Rendering to a path
83 FUNCTION: void
84 pango_cairo_glyph_string_path ( cairo_t* cr, PangoFont* font, PangoGlyphString* glyphs ) ;
85
86 FUNCTION: void
87 pango_cairo_layout_line_path  ( cairo_t* cr, PangoLayoutLine* line ) ;
88
89 FUNCTION: void
90 pango_cairo_layout_path ( cairo_t* cr, PangoLayout* layout ) ;
91
92 FUNCTION: void
93 pango_cairo_error_underline_path ( cairo_t* cr, double x, double y, double width, double height ) ;
94
95 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
96 ! Helpful functions from other parts of pango
97 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
98
99 : PANGO_SCALE 1024 ;
100
101 FUNCTION: void
102 pango_layout_set_text ( PangoLayout* layout, char* text, int length ) ;
103
104 FUNCTION: char*
105 pango_layout_get_text ( PangoLayout* layout ) ;
106
107 FUNCTION: void
108 pango_layout_get_size ( PangoLayout* layout, int* width, int* height ) ;
109
110 TYPEDEF: void* PangoFontDescription
111
112 FUNCTION: PangoFontDescription*
113 pango_font_description_from_string ( char* str ) ;
114
115 FUNCTION: char*
116 pango_font_description_to_string ( PangoFontDescription* desc ) ;
117
118 FUNCTION: char*
119 pango_font_description_to_filename ( PangoFontDescription* desc ) ;
120
121 FUNCTION: void
122 pango_layout_set_font_description ( PangoLayout* layout, PangoFontDescription* desc ) ;
123
124 FUNCTION: PangoFontDescription*
125 pango_layout_get_font_description ( PangoLayout* layout ) ;
126
127 FUNCTION: void
128 pango_layout_get_pixel_size ( PangoLayout* layout, int* width, int* height ) ;
129
130 FUNCTION: void
131 pango_font_description_free ( PangoFontDescription* desc ) ;
132
133 TYPEDEF: void* gpointer
134
135 FUNCTION: void
136 g_object_unref ( gpointer object ) ;
137
138 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
139 ! Higher level words and combinators
140 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
141
142 USING: destructors accessors namespaces kernel cairo ;
143
144 TUPLE: pango-layout alien ;
145 C: <pango-layout> pango-layout
146 M: pango-layout dispose ( alien -- ) alien>> g_object_unref ;
147
148 : layout ( -- pango-layout ) pango-layout get ;
149
150 : (with-pango) ( layout quot -- )
151     >r alien>> pango-layout r> with-variable ; inline
152
153 : with-pango ( quot -- )
154     cr pango_cairo_create_layout <pango-layout> swap
155     [ (with-pango) ] curry with-disposal ; inline
156
157 : pango-layout-get-pixel-size ( layout -- width height )
158     0 <int> 0 <int> [ pango_layout_get_pixel_size ] 2keep
159     [ *int ] bi@ ;
160
161 : dummy-pango ( quot -- )
162     >r CAIRO_FORMAT_ARGB32 0 0 cairo_image_surface_create
163     r> [ with-pango ] curry with-cairo-from-surface ; inline
164
165 : layout-size ( quot -- width height )
166     [ layout pango-layout-get-pixel-size ] compose dummy-pango ; inline
167
168 : layout-font ( str -- )
169     pango_font_description_from_string
170     dup zero? [ "pango: not a valid font." throw ] when
171     layout over pango_layout_set_font_description
172     pango_font_description_free ;
173
174 : layout-text ( str -- )
175     layout swap -1 pango_layout_set_text ;