1 /* ***** BEGIN LICENSE BLOCK *****
2  * Version: MPL 1.1
3  *
4  * The contents of this file are subject to the Mozilla Public License Version
5  * 1.1 (the "License"); you may not use this file except in compliance with
6  * the License. You may obtain a copy of the License at
7  * http://www.mozilla.org/MPL/
8  *
9  * Software distributed under the License is distributed on an "AS IS" basis,
10  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11  * for the specific language governing rights and limitations under the
12  * License.
13  *
14  * Contributor(s):
15  *
16  * IBM
17  * -  Binding to permit interfacing between Cairo and SWT
18  * -  Copyright (C) 2005 IBM Corp.  All Rights Reserved.
19  *
20  * ***** END LICENSE BLOCK ***** */
21 /* Port to the D programming language:
22  *     Frank Benoit <benoit@tionex.de>
23  */
24 module org.eclipse.swt.internal.cairo.Cairo;
25 
26 import java.lang.all;
27 
28 import  org.eclipse.swt.internal.c.cairo;
29 import  org.eclipse.swt.internal.c.cairo_xlib;
30 import  org.eclipse.swt.internal.c.cairo_ps;
31 import  org.eclipse.swt.internal.c.cairo_pdf;
32 import  org.eclipse.swt.internal.c.Xlib;
33 import  org.eclipse.swt.internal.Platform;
34 
35 version(Tango){
36     import tango.core.Traits;
37 } else { // Phobos
38     import std.traits;
39 }
40 
41 public alias org.eclipse.swt.internal.c.cairo.cairo_t cairo_t;
42 public alias org.eclipse.swt.internal.c.cairo.cairo_pattern_t cairo_pattern_t;
43 public alias org.eclipse.swt.internal.c.cairo.cairo_surface_t cairo_surface_t;
44 public alias org.eclipse.swt.internal.c.cairo.cairo_text_extents_t cairo_text_extents_t;
45 public alias org.eclipse.swt.internal.c.cairo.cairo_font_extents_t cairo_font_extents_t;
46 public alias org.eclipse.swt.internal.c.cairo.cairo_matrix_t cairo_matrix_t;
47 public alias org.eclipse.swt.internal.c.cairo.cairo_path_t cairo_path_t;
48 public alias org.eclipse.swt.internal.c.cairo.cairo_path_data_t cairo_path_data_t;
49 
50 /++++
51 private extern(C) {
52 cairo_surface_t *
53 cairo_xlib_surface_create (void     *dpy,
54                XID/*Drawable*/ drawable,
55                Visual      *visual,
56                int      width,
57                int      height);
58 }
59 ++++/
60 
61 private int CAIRO_VERSION_ENCODE(int major, int minor, int micro) {
62     return ((major) * 10000)
63         + ((minor) *   100)
64         + ((micro) *     1);
65 }
66 
67 template NameOfFunc(alias f) {
68     // Note: highly dependent on the .stringof formatting
69     // the value begins with "& " which is why the first two chars are cut off
70     version( LDC ){
71         // stringof in LLVMDC is "&foobar"
72         const char[] NameOfFunc = (&f).stringof[1 .. $];
73     }
74     else{
75         // stringof in DMD is "& foobar"
76         const char[] NameOfFunc = (&f).stringof[2 .. $];
77     }
78 }
79 
80 template ForwardGtkCairoCFunc( alias cFunc ) {
81     version(Tango){
82         alias ParameterTupleOf!(cFunc) P;
83         alias ReturnTypeOf!(cFunc) R;
84         mixin("public static R " ~ NameOfFunc!(cFunc) ~ "( P p ){
85                 lock.lock();
86                 scope(exit) lock.unlock();
87                 return cFunc(p);
88                 }");
89     } else { // Phobos
90         alias ParameterTypeTuple!(cFunc) P;
91         alias ReturnType!(cFunc) R;
92         mixin("public static R " ~ NameOfFunc!(cFunc) ~ "( P p ){
93                 lock.lock();
94                 scope(exit) lock.unlock();
95                 return cFunc(p);
96                 }");
97     }
98 }
99 
100 public class Cairo : Platform {
101 
102     /** Constants */
103     public static const int CAIRO_ANTIALIAS_DEFAULT = 0;
104     public static const int CAIRO_ANTIALIAS_NONE = 1;
105     public static const int CAIRO_ANTIALIAS_GRAY = 2;
106     public static const int CAIRO_ANTIALIAS_SUBPIXEL = 3;
107     public static const int CAIRO_FORMAT_ARGB32 = 0;
108     public static const int CAIRO_FORMAT_RGB24 = 1;
109     public static const int CAIRO_FORMAT_A8 = 2;
110     public static const int CAIRO_FORMAT_A1 = 3;
111     public static const int CAIRO_OPERATOR_CLEAR = 0;
112     public static const int CAIRO_OPERATOR_SRC = 1;
113     public static const int CAIRO_OPERATOR_DST = 2;
114     public static const int CAIRO_OPERATOR_OVER = 3;
115     public static const int CAIRO_OPERATOR_OVER_REVERSE = 4;
116     public static const int CAIRO_OPERATOR_IN = 5;
117     public static const int CAIRO_OPERATOR_IN_REVERSE = 6;
118     public static const int CAIRO_OPERATOR_OUT = 7;
119     public static const int CAIRO_OPERATOR_OUT_REVERSE = 8;
120     public static const int CAIRO_OPERATOR_ATOP = 9;
121     public static const int CAIRO_OPERATOR_ATOP_REVERSE = 10;
122     public static const int CAIRO_OPERATOR_XOR = 11;
123     public static const int CAIRO_OPERATOR_ADD = 12;
124     public static const int CAIRO_OPERATOR_SATURATE = 13;
125     public static const int CAIRO_FILL_RULE_WINDING = 0;
126     public static const int CAIRO_FILL_RULE_EVEN_ODD = 1;
127     public static const int CAIRO_LINE_CAP_BUTT = 0;
128     public static const int CAIRO_LINE_CAP_ROUND = 1;
129     public static const int CAIRO_LINE_CAP_SQUARE = 2;
130     public static const int CAIRO_LINE_JOIN_MITER = 0;
131     public static const int CAIRO_LINE_JOIN_ROUND = 1;
132     public static const int CAIRO_LINE_JOIN_BEVEL = 2;
133     public static const int CAIRO_FONT_SLANT_NORMAL = 0;
134     public static const int CAIRO_FONT_SLANT_ITALIC = 1;
135     public static const int CAIRO_FONT_SLANT_OBLIQUE = 2;
136     public static const int CAIRO_FONT_WEIGHT_NORMAL = 0;
137     public static const int CAIRO_FONT_WEIGHT_BOLD = 1;
138     public static const int CAIRO_STATUS_SUCCESS = 0;
139     public static const int CAIRO_STATUS_NO_MEMORY = 1;
140     public static const int CAIRO_STATUS_INVALID_RESTORE = 2;
141     public static const int CAIRO_STATUS_INVALID_POP_GROUP = 3;
142     public static const int CAIRO_STATUS_NO_CURRENT_POINT = 4;
143     public static const int CAIRO_STATUS_INVALID_MATRIX = 5;
144     public static const int CAIRO_STATUS_NO_TARGET_SURFACE = 6;
145     public static const int CAIRO_STATUS_NULL_POINTER =7;
146     public static const int CAIRO_SURFACE_TYPE_IMAGE = 0;
147     public static const int CAIRO_SURFACE_TYPE_PDF = 1;
148     public static const int CAIRO_SURFACE_TYPE_PS = 2;
149     public static const int CAIRO_SURFACE_TYPE_XLIB = 3;
150     public static const int CAIRO_SURFACE_TYPE_XCB = 4;
151     public static const int CAIRO_SURFACE_TYPE_GLITZ = 5;
152     public static const int CAIRO_SURFACE_TYPE_QUARTZ = 6;
153     public static const int CAIRO_SURFACE_TYPE_WIN32 = 7;
154     public static const int CAIRO_SURFACE_TYPE_BEOS = 8;
155     public static const int CAIRO_SURFACE_TYPE_DIRECTFB = 9;
156     public static const int CAIRO_SURFACE_TYPE_SVG = 10;
157     public static const int CAIRO_FILTER_FAST = 0;
158     public static const int CAIRO_FILTER_GOOD = 1;
159     public static const int CAIRO_FILTER_BEST = 2;
160     public static const int CAIRO_FILTER_NEAREST = 3;
161     public static const int CAIRO_FILTER_BILINEAR = 4;
162     public static const int CAIRO_FILTER_GAUSSIAN = 5;
163     public static const int CAIRO_EXTEND_NONE = 0;
164     public static const int CAIRO_EXTEND_REPEAT = 1;
165     public static const int CAIRO_EXTEND_REFLECT = 2;
166     public static const int CAIRO_EXTEND_PAD = 3;
167     public static const int CAIRO_PATH_MOVE_TO = 0;
168     public static const int CAIRO_PATH_LINE_TO = 1;
169     public static const int CAIRO_PATH_CURVE_TO = 2;
170     public static const int CAIRO_PATH_CLOSE_PATH = 3;
171 
172     mixin ForwardGtkCairoCFunc!(.CAIRO_VERSION_ENCODE);
173     mixin ForwardGtkCairoCFunc!(.cairo_append_path);
174     mixin ForwardGtkCairoCFunc!(.cairo_arc);
175     mixin ForwardGtkCairoCFunc!(.cairo_arc_negative);
176     mixin ForwardGtkCairoCFunc!(.cairo_clip);
177     mixin ForwardGtkCairoCFunc!(.cairo_clip_preserve);
178     mixin ForwardGtkCairoCFunc!(.cairo_close_path);
179     mixin ForwardGtkCairoCFunc!(.cairo_copy_page);
180     mixin ForwardGtkCairoCFunc!(.cairo_copy_path);
181     mixin ForwardGtkCairoCFunc!(.cairo_copy_path_flat);
182     mixin ForwardGtkCairoCFunc!(.cairo_create);
183     mixin ForwardGtkCairoCFunc!(.cairo_curve_to);
184     mixin ForwardGtkCairoCFunc!(.cairo_destroy);
185     mixin ForwardGtkCairoCFunc!(.cairo_device_to_user);
186     mixin ForwardGtkCairoCFunc!(.cairo_device_to_user_distance);
187     mixin ForwardGtkCairoCFunc!(.cairo_fill);
188     mixin ForwardGtkCairoCFunc!(.cairo_fill_extents);
189     mixin ForwardGtkCairoCFunc!(.cairo_fill_preserve);
190     mixin ForwardGtkCairoCFunc!(.cairo_font_extents);
191     mixin ForwardGtkCairoCFunc!(.cairo_font_options_create);
192     mixin ForwardGtkCairoCFunc!(.cairo_font_options_destroy);
193     mixin ForwardGtkCairoCFunc!(.cairo_font_options_get_antialias);
194     mixin ForwardGtkCairoCFunc!(.cairo_font_options_set_antialias);
195     mixin ForwardGtkCairoCFunc!(.cairo_get_antialias);
196     mixin ForwardGtkCairoCFunc!(.cairo_get_current_point);
197     mixin ForwardGtkCairoCFunc!(.cairo_get_fill_rule);
198     mixin ForwardGtkCairoCFunc!(.cairo_get_font_face);
199     mixin ForwardGtkCairoCFunc!(.cairo_get_font_matrix);
200     mixin ForwardGtkCairoCFunc!(.cairo_get_font_options);
201     mixin ForwardGtkCairoCFunc!(.cairo_get_line_cap);
202     mixin ForwardGtkCairoCFunc!(.cairo_get_line_join);
203     mixin ForwardGtkCairoCFunc!(.cairo_get_line_width);
204     mixin ForwardGtkCairoCFunc!(.cairo_get_matrix);
205     mixin ForwardGtkCairoCFunc!(.cairo_get_miter_limit);
206     mixin ForwardGtkCairoCFunc!(.cairo_get_operator);
207     mixin ForwardGtkCairoCFunc!(.cairo_get_source);
208     mixin ForwardGtkCairoCFunc!(.cairo_get_target);
209     mixin ForwardGtkCairoCFunc!(.cairo_get_tolerance);
210     mixin ForwardGtkCairoCFunc!(.cairo_glyph_extents);
211     mixin ForwardGtkCairoCFunc!(.cairo_glyph_path);
212     mixin ForwardGtkCairoCFunc!(.cairo_identity_matrix);
213     mixin ForwardGtkCairoCFunc!(.cairo_image_surface_create);
214     mixin ForwardGtkCairoCFunc!(.cairo_image_surface_create_for_data);
215     mixin ForwardGtkCairoCFunc!(.cairo_image_surface_get_height);
216     mixin ForwardGtkCairoCFunc!(.cairo_image_surface_get_width);
217     mixin ForwardGtkCairoCFunc!(.cairo_in_fill);
218     mixin ForwardGtkCairoCFunc!(.cairo_in_stroke);
219     mixin ForwardGtkCairoCFunc!(.cairo_line_to);
220     mixin ForwardGtkCairoCFunc!(.cairo_mask);
221     mixin ForwardGtkCairoCFunc!(.cairo_mask_surface);
222     mixin ForwardGtkCairoCFunc!(.cairo_matrix_init);
223     mixin ForwardGtkCairoCFunc!(.cairo_matrix_init_identity);
224     mixin ForwardGtkCairoCFunc!(.cairo_matrix_init_rotate);
225     mixin ForwardGtkCairoCFunc!(.cairo_matrix_init_scale);
226     mixin ForwardGtkCairoCFunc!(.cairo_matrix_init_translate);
227     mixin ForwardGtkCairoCFunc!(.cairo_matrix_invert);
228     mixin ForwardGtkCairoCFunc!(.cairo_matrix_multiply);
229     mixin ForwardGtkCairoCFunc!(.cairo_matrix_rotate);
230     mixin ForwardGtkCairoCFunc!(.cairo_matrix_scale);
231     mixin ForwardGtkCairoCFunc!(.cairo_matrix_transform_distance);
232     mixin ForwardGtkCairoCFunc!(.cairo_matrix_transform_point);
233     mixin ForwardGtkCairoCFunc!(.cairo_matrix_translate);
234     mixin ForwardGtkCairoCFunc!(.cairo_move_to);
235     mixin ForwardGtkCairoCFunc!(.cairo_new_path);
236     mixin ForwardGtkCairoCFunc!(.cairo_paint);
237     mixin ForwardGtkCairoCFunc!(.cairo_paint_with_alpha);
238     mixin ForwardGtkCairoCFunc!(.cairo_path_destroy);
239     mixin ForwardGtkCairoCFunc!(.cairo_pattern_add_color_stop_rgb);
240     mixin ForwardGtkCairoCFunc!(.cairo_pattern_add_color_stop_rgba);
241     mixin ForwardGtkCairoCFunc!(.cairo_pattern_create_for_surface);
242     mixin ForwardGtkCairoCFunc!(.cairo_pattern_create_linear);
243     mixin ForwardGtkCairoCFunc!(.cairo_pattern_create_radial);
244     mixin ForwardGtkCairoCFunc!(.cairo_pattern_destroy);
245     mixin ForwardGtkCairoCFunc!(.cairo_pattern_get_extend);
246     mixin ForwardGtkCairoCFunc!(.cairo_pattern_get_filter);
247     mixin ForwardGtkCairoCFunc!(.cairo_pattern_get_matrix);
248     mixin ForwardGtkCairoCFunc!(.cairo_pattern_reference);
249     mixin ForwardGtkCairoCFunc!(.cairo_pattern_set_extend);
250     mixin ForwardGtkCairoCFunc!(.cairo_pattern_set_filter);
251     mixin ForwardGtkCairoCFunc!(.cairo_pattern_set_matrix);
252     mixin ForwardGtkCairoCFunc!(.cairo_pdf_surface_set_size);
253     mixin ForwardGtkCairoCFunc!(.cairo_ps_surface_set_size);
254     mixin ForwardGtkCairoCFunc!(.cairo_rectangle);
255     mixin ForwardGtkCairoCFunc!(.cairo_reference);
256     mixin ForwardGtkCairoCFunc!(.cairo_rel_curve_to);
257     mixin ForwardGtkCairoCFunc!(.cairo_rel_line_to);
258     mixin ForwardGtkCairoCFunc!(.cairo_rel_move_to);
259     mixin ForwardGtkCairoCFunc!(.cairo_reset_clip);
260     mixin ForwardGtkCairoCFunc!(.cairo_restore);
261     mixin ForwardGtkCairoCFunc!(.cairo_rotate);
262     mixin ForwardGtkCairoCFunc!(.cairo_save);
263     mixin ForwardGtkCairoCFunc!(.cairo_scale);
264     mixin ForwardGtkCairoCFunc!(.cairo_select_font_face);
265     mixin ForwardGtkCairoCFunc!(.cairo_set_antialias);
266     mixin ForwardGtkCairoCFunc!(.cairo_set_dash);
267     mixin ForwardGtkCairoCFunc!(.cairo_set_fill_rule);
268     mixin ForwardGtkCairoCFunc!(.cairo_set_font_face);
269     mixin ForwardGtkCairoCFunc!(.cairo_set_font_matrix);
270     mixin ForwardGtkCairoCFunc!(.cairo_set_font_options);
271     mixin ForwardGtkCairoCFunc!(.cairo_set_font_size);
272     mixin ForwardGtkCairoCFunc!(.cairo_set_line_cap);
273     mixin ForwardGtkCairoCFunc!(.cairo_set_line_join);
274     mixin ForwardGtkCairoCFunc!(.cairo_set_line_width);
275     mixin ForwardGtkCairoCFunc!(.cairo_set_matrix);
276     mixin ForwardGtkCairoCFunc!(.cairo_set_miter_limit);
277     mixin ForwardGtkCairoCFunc!(.cairo_set_operator);
278     mixin ForwardGtkCairoCFunc!(.cairo_set_source);
279     mixin ForwardGtkCairoCFunc!(.cairo_set_source_rgb);
280     mixin ForwardGtkCairoCFunc!(.cairo_set_source_rgba);
281     mixin ForwardGtkCairoCFunc!(.cairo_set_source_surface);
282     mixin ForwardGtkCairoCFunc!(.cairo_set_tolerance);
283     mixin ForwardGtkCairoCFunc!(.cairo_show_glyphs);
284     mixin ForwardGtkCairoCFunc!(.cairo_show_page);
285     mixin ForwardGtkCairoCFunc!(.cairo_show_text);
286     mixin ForwardGtkCairoCFunc!(.cairo_status);
287     mixin ForwardGtkCairoCFunc!(.cairo_status_to_string);
288     mixin ForwardGtkCairoCFunc!(.cairo_stroke);
289     mixin ForwardGtkCairoCFunc!(.cairo_stroke_extents);
290     mixin ForwardGtkCairoCFunc!(.cairo_stroke_preserve);
291     mixin ForwardGtkCairoCFunc!(.cairo_surface_create_similar);
292     mixin ForwardGtkCairoCFunc!(.cairo_surface_destroy);
293     mixin ForwardGtkCairoCFunc!(.cairo_surface_finish);
294     mixin ForwardGtkCairoCFunc!(.cairo_surface_get_type);
295     mixin ForwardGtkCairoCFunc!(.cairo_surface_get_user_data);
296     mixin ForwardGtkCairoCFunc!(.cairo_surface_reference);
297     mixin ForwardGtkCairoCFunc!(.cairo_surface_set_device_offset);
298     mixin ForwardGtkCairoCFunc!(.cairo_surface_set_fallback_resolution);
299     mixin ForwardGtkCairoCFunc!(.cairo_surface_set_user_data);
300     mixin ForwardGtkCairoCFunc!(.cairo_text_extents);
301     mixin ForwardGtkCairoCFunc!(.cairo_text_path);
302     mixin ForwardGtkCairoCFunc!(.cairo_transform);
303     mixin ForwardGtkCairoCFunc!(.cairo_translate);
304     mixin ForwardGtkCairoCFunc!(.cairo_user_to_device);
305     mixin ForwardGtkCairoCFunc!(.cairo_user_to_device_distance);
306     mixin ForwardGtkCairoCFunc!(.cairo_version);
307     mixin ForwardGtkCairoCFunc!(.cairo_xlib_surface_create);
308     /++/
309     mixin ForwardGtkCairoCFunc!(.cairo_xlib_surface_create_for_bitmap);
310     mixin ForwardGtkCairoCFunc!(.cairo_xlib_surface_set_size);
311 /++/
312 }