-! Cairo binding
+! Bindings for Cairo library
+!  Copyright (c) 2007 Sampo Vuori
+!    License: http://factorcode.org/license.txt
+
+! Unimplemented:
+!  - most of the font stuff
+!  - most of the matrix stuff
+!  - most of the query functions
+
+
+USING: alien alien.syntax combinators system ;
+
 IN: cairo
-USING: alien alien.syntax ;
+
+: load-cairo-library ( -- )
+  "cairo" {
+	{ [ win32? ] [ "cairo.dll" ] }
+	{ [ macosx? ] [ "libcairo.dylib" ] }
+	{ [ unix? ] [ "libcairo.so.2" ] }
+  } cond "cdecl" add-library ; parsing
+
+load-cairo-library
 
 ! cairo_status_t
 C-ENUM:

    { "cairo_gstate_t*" "gstate" }
    { "uint" "status ! cairo_status_t" } ;

! cairo_format_t
C-ENUM:
    CAIRO_FORMAT_ARGB32

: cairo_create ( cairo_surface_t -- cairo_t )
    "cairo_t*" "cairo" "cairo_create" [ "void*" ] alien-invoke ;

: cairo_reference ( cairo_t -- cairo_t )
  	"cairo_t*" "cairo" "cairo_reference" [ "cairo_t*" ] alien-invoke ;

: cairo_destroy ( cairo_t -- )
    "void" "cairo" "cairo_destroy" [ "cairo_t*" ] alien-invoke ;

: cairo_save ( cairo_t -- )
  	"void" "cairo" "cairo_save" [ "cairo_t*" ] alien-invoke ;

: cairo_restore ( cairo_t -- )
  	"void" "cairo" "cairo_restore" [ "cairo_t*" ] alien-invoke ;

: cairo_set_operator ( cairo_t cairo_operator_t -- )
    "void" "cairo" "cairo_set_operator" [ "cairo_t*" "int" ] alien-invoke ;

: cairo_set_source ( cairo_t cairo_pattern_t -- )
    "void" "cairo" "cairo_set_source" [ "cairo_t*" "void*" ] alien-invoke ;

: cairo_set_source_rgb ( cairo_t red green blue -- )
    "void" "cairo" "cairo_set_source_rgb" [ "cairo_t*" "double" "double" "double" ] alien-invoke ;

: cairo_set_source_rgba ( cairo_t red green blue alpha -- )
    "void" "cairo" "cairo_set_source_rgb" [ "cairo_t*" "double" "double" "double" "double" ] alien-invoke ;

: cairo_set_source_surface ( cairo_t cairo_surface_t x y -- )
    "void" "cairo" "cairo_set_source_surface" [ "cairo_t*" "void*" "double" "double" ] alien-invoke ;

: cairo_set_tolerance ( cairo_t tolerance -- )
    "void" "cairo" "cairo_set_tolerance" [ "cairo_t*" "double" ] alien-invoke ;

: cairo_image_surface_create_for_data ( data format width height stride -- cairo_surface_t )
    "void*" "cairo" "cairo_image_surface_create_for_data" [ "void*" "uint" "int" "int" "int" ] alien-invoke ;
    

: cairo_set_antialias ( cairo_t cairo_antialias_t -- )
    "void" "cairo" "cairo_set_antialias" [ "cairo_t*" "int" ] alien-invoke ;
