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