Make a copy of the old ZipLib
[mono.git] / mcs / class / Mono.Cairo / Mono.Cairo / Cairo.cs
1 //
2 // Mono.Cairo.Cairo.cs
3 //
4 // Authors: Duncan Mak (duncan@ximian.com)
5 //          Hisham Mardam Bey (hisham.mardambey@gmail.com)
6 //
7 // (C) Ximian, Inc. 2003
8 //
9 // This is a simplistic binding of the Cairo API to C#. All functions
10 // in cairo.h are transcribed into their C# equivelants and all
11 // enumerations are also listed here.
12 //
13 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
14 //
15 // Permission is hereby granted, free of charge, to any person obtaining
16 // a copy of this software and associated documentation files (the
17 // "Software"), to deal in the Software without restriction, including
18 // without limitation the rights to use, copy, modify, merge, publish,
19 // distribute, sublicense, and/or sell copies of the Software, and to
20 // permit persons to whom the Software is furnished to do so, subject to
21 // the following conditions:
22 // 
23 // The above copyright notice and this permission notice shall be
24 // included in all copies or substantial portions of the Software.
25 // 
26 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
30 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
31 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
32 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 //
34
35 using System;
36 using System.Runtime.InteropServices;
37
38 namespace Cairo {
39
40         internal class CairoAPI
41         {
42                 internal const string CairoImp = "libcairo-2.dll";
43                 
44                 //
45                 // Manipulating state objects
46                 //
47                 [DllImport (CairoImp)]
48                 public static extern IntPtr cairo_create (IntPtr target);
49
50                 [DllImport (CairoImp)]
51                 public static extern void cairo_reference (IntPtr cr);
52
53                 [DllImport (CairoImp)]
54                 public static extern void cairo_destroy (IntPtr cr);
55
56                 [DllImport (CairoImp)]
57                 public static extern void cairo_save (IntPtr cr);                
58
59                 [DllImport (CairoImp)]
60                 public static extern void cairo_restore (IntPtr cr);
61
62                 //
63                 // Modify state
64                 //
65                 [DllImport (CairoImp)]
66                 public static extern IntPtr cairo_image_surface_create_for_data (
67                         IntPtr data, Cairo.Format format, int width, int height, int stride);
68
69                 [DllImport (CairoImp)]
70                 public static extern void cairo_set_operator (IntPtr cr, Cairo.Operator op);
71
72                 [DllImport (CairoImp)]
73                 public static extern void cairo_set_source_rgba (IntPtr cr, double red, double green, double blue, double alpha);
74                 
75                 [DllImport (CairoImp)]
76                 public static extern void cairo_set_source_rgb (IntPtr cr, double red, double green, double blue);              
77                                 
78                 [DllImport (CairoImp)]
79                 public static extern void cairo_set_source (IntPtr cr, IntPtr pattern);
80                 
81                 [DllImport (CairoImp)]
82                 public static extern IntPtr cairo_get_source (IntPtr cr);
83
84                 [DllImport (CairoImp)]
85                 public static extern void cairo_set_tolerance (IntPtr cr, double tolerance);
86
87                 [DllImport (CairoImp)]
88                 public static extern void cairo_set_fill_rule (IntPtr cr, Cairo.FillRule fill_rule);
89
90                 [DllImport (CairoImp)]
91                 public static extern void cairo_set_line_width (IntPtr cr, double width);
92
93                 [DllImport (CairoImp)]
94                 public static extern void cairo_set_line_cap (IntPtr cr, Cairo.LineCap line_cap);
95
96                 [DllImport (CairoImp)]
97                 public static extern void cairo_set_line_join (IntPtr cr, Cairo.LineJoin line_join);
98
99                 [DllImport (CairoImp)]
100                 public static extern void cairo_set_dash (IntPtr cr, double [] dashes, int ndash, double offset);
101
102                 [DllImport (CairoImp)]
103                 public static extern void cairo_set_miter_limit (IntPtr cr, double limit);
104
105                 [DllImport (CairoImp)]
106                 public static extern void cairo_translate (IntPtr cr, double tx, double ty);
107
108                 [DllImport (CairoImp)]
109                 public static extern void cairo_scale (IntPtr cr, double sx, double sy);
110
111                 [DllImport (CairoImp)]                
112                 public static extern void cairo_rotate (IntPtr cr, double angle);
113                 
114                 [DllImport (CairoImp)]
115                 public static extern void cairo_transform (IntPtr cr, Matrix matrix);
116                 
117                 [DllImport (CairoImp)]
118                 public static extern void cairo_set_matrix (IntPtr cr, Matrix matrix);
119                 
120                 [DllImport (CairoImp)]
121                 public static extern void cairo_identity_matrix (IntPtr cr);
122
123                 [DllImport (CairoImp)]
124                 public static extern void cairo_user_to_device (IntPtr cr, ref double x, ref double y);
125
126                 [DllImport (CairoImp)]
127                 public static extern void cairo_user_to_device_distance (IntPtr cr, ref double dx, ref double dy);
128
129                 [DllImport (CairoImp)]
130                 public static extern void cairo_device_to_user (IntPtr cr, ref double x, ref double y);
131
132                 [DllImport (CairoImp)]
133                 public static extern void cairo_device_to_user_distance (IntPtr cr, ref double dx, ref double dy);
134                 
135                 //
136                 // Path creation
137                 //
138                 [DllImport (CairoImp)]
139                 public static extern void cairo_new_path (IntPtr cr);
140                 
141                 [DllImport (CairoImp)]
142                 public static extern void cairo_move_to (IntPtr cr, double x, double y);
143
144                 [DllImport (CairoImp)]
145                 public static extern void cairo_line_to (IntPtr cr, double x, double y);
146
147                 [DllImport (CairoImp)]
148                 public static extern void cairo_curve_to (
149                         IntPtr cr, double x1, double y1, double x2, double y2, double x3, double y3);
150
151                 [DllImport (CairoImp)]
152                 public static extern void cairo_arc (
153                         IntPtr cr, double xc, double yc, double radius, double angel1, double angel2);
154
155                 [DllImport (CairoImp)]
156                 public static extern void cairo_arc_negative (
157                         IntPtr cr, double xc, double yc, double radius, double angel1, double angel2);
158                 
159                 [DllImport (CairoImp)]
160                 public static extern void cairo_rel_move_to (IntPtr cr, double dx, double dy);
161
162                 [DllImport (CairoImp)]
163                 public static extern void cairo_rel_line_to (IntPtr cr, double dx, double dy);
164
165                 [DllImport (CairoImp)]
166                 public static extern void cairo_rel_curve_to (
167                         IntPtr cr, double dx1, double dy1, double dx2, double dy2, double dx3, double dy3);
168
169                 [DllImport (CairoImp)]
170                 public static extern void cairo_rectangle (IntPtr cr, double x, double y, double width, double height);
171
172                 [DllImport (CairoImp)]
173                 public static extern void cairo_close_path (IntPtr cr);
174
175                 //
176                 // Painting
177                 //
178                 [DllImport (CairoImp)]
179                 public static extern void cairo_stroke (IntPtr cr);
180                 
181                 [DllImport (CairoImp)]
182                 public static extern void cairo_stroke_preserve (IntPtr cr);
183
184                 [DllImport (CairoImp)]
185                 public static extern void cairo_stroke_extents (IntPtr cr, double x1, double y1, double x2, double y2);
186
187                 [DllImport (CairoImp)]
188                 public static extern void cairo_fill (IntPtr cr);
189
190                 [DllImport (CairoImp)]
191                 public static extern void cairo_fill_extents (IntPtr cr, double x1, double y1, double x2, double y2);
192
193                 [DllImport (CairoImp)]
194                 public static extern void cairo_fill_preserve (IntPtr cr);
195                 
196                 [DllImport (CairoImp)]
197                 public static extern void cairo_copy_page (IntPtr cr);
198                 
199                 [DllImport (CairoImp)]
200                 public static extern void cairo_show_page (IntPtr cr);
201
202                 [DllImport (CairoImp)]
203                 public static extern void cairo_clip (IntPtr cr);
204
205                 [DllImport (CairoImp)]
206                 public static extern void cairo_clip_preserve (IntPtr cr);
207                 
208                 [DllImport (CairoImp)]
209                 public static extern void cairo_reset_clip (IntPtr cr);
210
211                 //
212                 // Font / Text
213                 //
214                 [DllImport (CairoImp)]
215                 public static extern void cairo_select_font_face (IntPtr cr, 
216                                                               string family, 
217                                                               FontSlant slant, 
218                                                               FontWeight weight);
219
220                 [DllImport (CairoImp)]
221                 public static extern void cairo_set_font_size (IntPtr cr,
222                                                              double size);
223                 
224                 [DllImport (CairoImp)]
225                 public static extern void cairo_set_font_matrix (IntPtr cr, Matrix matrix);
226                 
227                 [DllImport (CairoImp)]
228                 public static extern void cairo_show_text (IntPtr cr, string utf8);
229
230                 [DllImport (CairoImp)]
231                 public static extern void cairo_font_extents (IntPtr source, ref FontExtents extents);
232
233                 [DllImport (CairoImp)]
234                 public static extern void cairo_show_glyphs (IntPtr ct, IntPtr glyphs, int num_glyphs);
235
236                 [DllImport (CairoImp)]
237                 public static extern void cairo_text_path  (IntPtr ct, string utf8);
238
239                 [DllImport (CairoImp)]
240                 public static extern void cairo_text_extents  (IntPtr cr, string utf8, ref TextExtents extents);
241
242                 [DllImport (CairoImp)]
243                 public static extern void cairo_glyph_path (IntPtr ct, IntPtr glyphs, int num_glyphs);
244         
245                 //
246                 // Image
247                 //
248                 [DllImport (CairoImp)]
249                 public static extern void cairo_set_source_surface (IntPtr cr, IntPtr surface, int width, int height);
250                 
251                 [DllImport (CairoImp)]
252                 internal static extern void cairo_mask (IntPtr cr, IntPtr pattern);
253                 
254                                 [DllImport (CairoImp)]
255                 internal static extern void cairo_mask_surface (IntPtr cr, IntPtr surface, double x, double y);
256                                 
257                 [DllImport (CairoImp)]
258                 public static extern void cairo_paint (IntPtr cr);
259
260                 [DllImport (CairoImp)]
261                 public static extern void cairo_paint_with_alpha (IntPtr cr, double alpha);
262                 
263                 [DllImport (CairoImp)]
264                 public static extern IntPtr cairo_image_surface_create_from_png  (string filename);
265                 
266                 [DllImport (CairoImp)]
267                 public static extern int cairo_image_surface_get_width  (IntPtr surface);
268                 
269                 [DllImport (CairoImp)]
270                 public static extern int cairo_image_surface_get_height (IntPtr surface);
271                 
272                 //
273                 // query
274                 //
275                 [DllImport (CairoImp)]
276                 public static extern bool cairo_in_stroke (IntPtr cr, double x, double y);
277
278                 [DllImport (CairoImp)]
279                 public static extern bool cairo_in_fill (IntPtr cr, double x, double y);
280
281                 [DllImport (CairoImp)]
282                 public static extern Cairo.Operator cairo_get_operator (IntPtr cr);
283                 
284                 [DllImport (CairoImp)]
285                 public static extern double cairo_get_tolerance (IntPtr cr);
286
287                 [DllImport (CairoImp)]
288                 public static extern void cairo_get_current_point (
289                         IntPtr cr, out double x, out double y);
290
291                 [DllImport (CairoImp)]
292                 public static extern Cairo.FillRule cairo_get_fill_rule (IntPtr cr);
293
294                 [DllImport (CairoImp)]
295                 public static extern double cairo_get_line_width (IntPtr cr);
296
297                 [DllImport (CairoImp)]
298                 public static extern LineCap cairo_get_line_cap (IntPtr cr);
299
300                 [DllImport (CairoImp)]
301                 public static extern LineJoin cairo_get_line_join (IntPtr cr);
302
303                 [DllImport (CairoImp)]
304                 public static extern double cairo_get_miter_limit (IntPtr cr);
305
306                 [DllImport (CairoImp)]
307                 public static extern void cairo_get_matrix (IntPtr cr, Matrix matrix);
308
309                 [DllImport (CairoImp)]
310                 public static extern IntPtr cairo_get_target (IntPtr cr);
311                 
312                 //
313                 // Error status queries
314                 //
315                 [DllImport (CairoImp)]
316                 public static extern Cairo.Status cairo_status (IntPtr cr);
317
318                 //
319                 // Surface Manipulation
320                 //
321                 
322                 [DllImport (CairoImp)]
323                 public static extern IntPtr cairo_xlib_surface_create (IntPtr dpi,
324                         IntPtr win, IntPtr visual, int w, int h);
325
326                 [DllImport (CairoImp)]
327                 public static extern void cairo_xlib_surface_set_drawable (IntPtr surface, IntPtr drawable, int width, int height);
328                 
329                 [DllImport (CairoImp)]
330                 public static extern void cairo_xlib_surface_set_size (IntPtr surface, int width, int height);
331                 
332                 [DllImport (CairoImp)]                
333                 public static extern Cairo.Status cairo_surface_finish (IntPtr surface);
334                 
335                 [DllImport (CairoImp)]                
336                 internal static extern Cairo.Status cairo_surface_status (IntPtr surface);
337                 
338                 [DllImport (CairoImp)]                
339                 public static extern void cairo_surface_set_device_offset (IntPtr surface,
340                                                                        double x, double y);
341
342                 [DllImport (CairoImp)]                
343                 public static extern IntPtr cairo_image_surface_create_for_data (
344                         string data, Cairo.Format format, int width, int height, int stride);
345
346                 [DllImport (CairoImp)]
347                 public static extern IntPtr cairo_image_surface_create (Cairo.Format format, int width,
348                         int height);
349
350
351                 [DllImport (CairoImp)]
352                 public static extern IntPtr cairo_surface_create_similar (
353                         IntPtr surface, Cairo.Content content, int width, int height);
354
355                 [DllImport (CairoImp)]
356                 public static extern void cairo_surface_reference (IntPtr surface);
357
358                 [DllImport (CairoImp)]                
359                 public static extern void cairo_surface_destroy (IntPtr surface);
360
361                 [DllImport (CairoImp)]                
362                 public static extern void cairo_surface_write_to_png (IntPtr surface, string filename);
363
364                 [DllImport (CairoImp)]                
365                 public static extern IntPtr cairo_pdf_surface_create (string filename, double width, double height);
366
367                 [DllImport (CairoImp)]                
368                 public static extern void cairo_pdf_surface_set_dpi (IntPtr surface, double x_dpi, double y_dpi);
369
370                 [DllImport (CairoImp)]                
371                 public static extern IntPtr cairo_ps_surface_create (string filename, double width, double height);
372
373                 [DllImport (CairoImp)]                
374                 public static extern void cairo_ps_surface_set_dpi (IntPtr surface, double x_dpi, double y_dpi);
375                                 
376                 [DllImport (CairoImp)]                
377                 public static extern IntPtr cairo_win32_surface_create (IntPtr hdc);
378
379                 //
380                 // Matrix
381                 //
382                 
383                 [DllImport (CairoImp)]                
384                 public static extern void cairo_matrix_init_translate (Matrix matrix, double tx, double ty);
385                 
386                 [DllImport (CairoImp)]                
387                 public static extern void cairo_matrix_translate (Matrix matrix, double tx, double ty);
388                 
389                 [DllImport (CairoImp)]
390                 public static extern void cairo_matrix_init_identity (Matrix matrix);
391
392                 [DllImport (CairoImp)]                
393                 public static extern void cairo_matrix_init_scale (Matrix matrix, double sx, double sy);
394                 
395                 [DllImport (CairoImp)]                
396                 public static extern void cairo_matrix_scale (Matrix matrix, double sx, double sy);
397
398                 [DllImport (CairoImp)]
399                 public static extern void cairo_matrix_init_rotate (Matrix matrix, double radians);             
400                 
401                 [DllImport (CairoImp)]                                
402                 public static extern void cairo_matrix_rotate (Matrix matrix, double radians);
403
404                 [DllImport (CairoImp)]                                
405                 public static extern Cairo.Status cairo_matrix_invert (Matrix matrix);
406
407                 [DllImport (CairoImp)]                                
408                 public static extern void cairo_matrix_multiply (Matrix result, Matrix a, Matrix b);
409
410                 [DllImport (CairoImp)]                                
411                 public static extern void cairo_matrix_transform_distance (Matrix matrix, ref double dx, ref double dy);
412
413                 [DllImport (CairoImp)]                                
414                 public static extern void cairo_matrix_transform_point (Matrix matrix, ref double x, ref double y);
415
416                 //
417                 // Pattern functions
418                 //
419                 [DllImport (CairoImp)]
420                 public static extern IntPtr cairo_pattern_create_for_surface (IntPtr surface);
421
422                 [DllImport (CairoImp)]
423                 public static extern IntPtr cairo_pattern_create_linear (double x0, double y0,
424                         double x1, double y1);
425
426                 [DllImport (CairoImp)]
427                 public static extern IntPtr cairo_pattern_create_radial (double cx0, double cy0,
428                         double radius0, double cx1, double cy1, double radius1);
429                 
430                 [DllImport (CairoImp)]
431                 public static extern IntPtr cairo_pattern_create_rgb (double r, 
432                                                                   double g,
433                                                                   double b);
434                 
435                 [DllImport (CairoImp)]
436                 public static extern IntPtr cairo_pattern_create_rgba (double r, 
437                                                                   double g,
438                                                                   double b,
439                                                                   double a);            
440
441                 [DllImport (CairoImp)]
442                 public static extern void cairo_pattern_reference (IntPtr pattern);
443
444                 [DllImport (CairoImp)]
445                 public static extern void cairo_pattern_destroy (IntPtr pattern);
446
447                 [DllImport (CairoImp)]
448                 public static extern Status cairo_pattern_add_color_stop_rgba (IntPtr pattern,
449                         double offset, double red, double green, double blue, double alpha);
450                 
451                 [DllImport (CairoImp)]
452                 public static extern Status cairo_pattern_add_color_stop_rgb (IntPtr pattern,
453                         double offset, double red, double green, double blue);
454
455                 [DllImport (CairoImp)]
456                 public static extern Status cairo_pattern_set_matrix (IntPtr pattern, Matrix matrix);
457
458                 [DllImport (CairoImp)]
459                 public static extern Status cairo_pattern_get_matrix (IntPtr pattern, Matrix matrix);
460
461                 [DllImport (CairoImp)]
462                 public static extern Status cairo_pattern_set_extend (IntPtr pattern, Extend extend);
463
464                 [DllImport (CairoImp)]
465                 public static extern Extend cairo_pattern_get_extend (IntPtr pattern);
466
467                 [DllImport (CairoImp)]
468                 public static extern Status cairo_pattern_set_filter (IntPtr pattern, Filter filter);
469
470                 [DllImport (CairoImp)]
471                 public static extern Filter cairo_pattern_get_filter (IntPtr pattern);
472                 
473                 [DllImport (CairoImp)]
474                 public static extern Status cairo_pattern_status (IntPtr pattern);
475
476                                 [DllImport (CairoImp)]
477                                 public static extern void cairo_set_antialias (IntPtr cr, Antialias antialias);
478
479                                 [DllImport (CairoImp)]
480                                 public static extern Antialias cairo_get_antialias (IntPtr cr);
481
482         }
483
484         //
485         // Enumerations
486         //
487                 
488                 public enum Antialias {
489                                 Default,
490                                 None,
491                                 Gray,
492                                 Subpixel,
493                 }
494
495                 public enum Content {
496                         Color,
497                         Alpha,
498                         ColorAlpha,
499                 }
500                 
501         public enum Format {
502                 ARGB32 = 0,
503                 RGB24 = 1,
504                 A8 = 2,
505                 A1 = 4
506         }
507
508         public enum Operator {
509                 Clear,
510
511                 Source,
512                 Over,
513                 In,
514                 Out,
515                 Atop,
516
517                 Dest,
518                 DestOver,
519                 DestIn,
520                 DestOut,
521                 DestAtop,
522
523                 Xor,
524                 Add,
525                 Saturate,
526         }
527
528         public enum FillRule {
529                 Winding,
530                 EvenOdd
531         }
532
533         public enum LineCap {
534                 Butt, Round, Square
535         }
536
537         public enum LineJoin {
538                 Miter, Round, Bevel
539         }
540
541         public enum Status {
542                 Success = 0,
543                 NoMemory,
544                 InvalidRestore,
545                 InvalidPopGroup,
546                 NoCurrentPoint,
547                 InvalidMatrix,
548                                 InvalidStatus,
549                                 NullPointer,
550                                 InvalidString,
551                                 InvalidPathData,
552                                 ReadError,
553                                 WriteError,
554                                 SurfaceFinished,
555                                 SurfaceTypeMismatch,
556                                 PatternTypeMismatch,
557                                 InvalidContent,
558                                 InvalidFormat,
559                                 InvalidVisual,
560                                 FileNotFound,
561                                 InvalidDash
562         }
563
564         public enum Filter {
565                 Fast,
566                 Good,
567                 Best,
568                 Nearest,
569                 Bilinear,
570                 Gaussian,
571         }
572
573         public enum FontSlant {
574                 Normal  = 0,
575                 Italic  = 1,
576                 Oblique = 2
577         }
578
579         public enum FontWeight {
580                 Normal  = 0,
581                 Bold    = 1,
582         }
583
584         public enum Extend {
585                 None,
586                 Repeat,
587                 Reflect,
588         }
589
590         [StructLayout(LayoutKind.Sequential)]
591         public struct FontExtents
592         {
593                 public  double Ascent;
594                 public  double Descent;
595                 public  double Height;
596                 public  double MaxXAdvance;
597                 public  double MaxYAdvance;
598         }        
599    
600    
601         [StructLayout(LayoutKind.Sequential)]
602         public struct TextExtents
603         {
604                 public  double XBearing;
605                 public  double YBearing;
606                 public  double Width;
607                 public  double Height;
608                 public  double XAdvance;
609                 public  double YAdvance;
610         }
611
612         [StructLayout(LayoutKind.Sequential)]
613         public struct Glyph
614         {
615                 public  long Index;
616                 public  double X;
617                 public  double Y;
618         }
619 }