summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOlivier Andrieu <oandrieu@gmail.com>2005-01-26 00:54:14 +0000
committerHezekiah M. Carty <hcarty@atmos.umd.edu>2009-06-18 13:57:26 -0400
commit80b67ef8c98b8b32314b1a6c1a1ab70b42b3d032 (patch)
tree5e7ca67ed67bfaa0d892094b0b5c28873714fe86
parent2f8d01e49ad6b650aaf098f28fb918d31ec602e4 (diff)
Add PDF backend
* sync with Cairo snapshot 0.3.0
-rw-r--r--ChangeLog13
-rw-r--r--configure.ac2
-rw-r--r--src/cairo.ml23
-rw-r--r--src/cairo.mli51
-rw-r--r--src/cairo_channel.ml10
-rw-r--r--src/cairo_channel.mli4
-rw-r--r--src/cairo_ft.ml4
-rw-r--r--src/cairo_ft.mli6
-rw-r--r--src/ml_cairo.c131
-rw-r--r--src/ml_cairo.h8
-rw-r--r--src/ml_cairo_ft.c27
-rw-r--r--src/ml_cairo_gtkcairo.c16
-rw-r--r--src/ml_cairo_lablgtk.c3
-rw-r--r--src/ml_cairo_status.c48
-rw-r--r--support/ocaml.m414
15 files changed, 237 insertions, 123 deletions
diff --git a/ChangeLog b/ChangeLog
index 4c2d0a0..d2c62ad 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2005-01-26 Olivier Andrieu <oliv__a@users.sourceforge.net>
+
+ * configure.ac: require cairo 0.3.0
+ * support/ocaml.m4 : quote stuff to stop auto* moaning.
+
+ * src/cairo_channel.ml*: add .ml file, add convenience function
+ Cairo_channel.open_out.
+
+ * src/cairo.ml*, src/ml_cairo.c: add PDF backend, add status
+ querying functions, a Cairo.copy convenience function.
+
+ * src/*.c: some tidying.
+
2004-11-08 Olivier Andrieu <oliv__a@users.sourceforge.net>
* configure.ac: require Cairo 0.2.0
diff --git a/configure.ac b/configure.ac
index 8e16caf..1e9dc15 100644
--- a/configure.ac
+++ b/configure.ac
@@ -5,7 +5,7 @@ AC_CONFIG_AUX_DIR(support)
AC_PROG_OCAML()
# Check for cairo
-PKG_CHECK_MODULES(CAIRO, cairo >= 0.2.0)
+PKG_CHECK_MODULES(CAIRO, cairo >= 0.3.0)
# Optional GTK support (for the X11 backend)
AC_ARG_WITH(gtk,
diff --git a/src/cairo.ml b/src/cairo.ml
index c8e598e..de43d4d 100644
--- a/src/cairo.ml
+++ b/src/cairo.ml
@@ -1,5 +1,6 @@
type status =
- INVALID_RESTORE
+ NO_MEMORY
+ | INVALID_RESTORE
| INVALID_POP_GROUP
| NO_CURRENT_POINT
| INVALID_MATRIX
@@ -23,7 +24,8 @@ external create : unit -> t = "ml_cairo_create"
external destroy : cr:t -> unit = "ml_cairo_destroy"
external save : cr:t -> unit = "ml_cairo_save"
external restore : cr:t -> unit = "ml_cairo_restore"
-external copy : dest:t -> src:t -> unit = "ml_cairo_copy"
+external _copy : dest:t -> src:t -> unit = "ml_cairo_copy"
+let copy src = let dest = create () in _copy ~dest ~src ; dest
external set_target_surface :
cr:t -> surface:surface -> unit = "ml_cairo_set_target_surface"
external set_target_image :
@@ -32,6 +34,10 @@ external set_target_ps :
cr:t -> file:Cairo_channel.t -> width_inches:float -> height_inches:float ->
x_pixels_per_inch:float -> y_pixels_per_inch:float ->
unit = "ml_cairo_set_target_ps_bc" "ml_cairo_set_target_ps"
+external set_target_pdf :
+ cr:t -> file:Cairo_channel.t -> width_inches:float -> height_inches:float ->
+ x_pixels_per_inch:float -> y_pixels_per_inch:float ->
+ unit = "ml_cairo_set_target_pdf_bc" "ml_cairo_set_target_pdf"
external set_target_png :
cr:t -> file:Cairo_channel.t -> format -> width:int -> height:int -> unit = "ml_cairo_set_target_png"
@@ -58,9 +64,9 @@ external set_operator : cr:t -> op:operator -> unit = "ml_cairo_set_operator"
external set_rgb_color :
cr:t -> red:float -> green:float -> blue:float ->
unit = "ml_cairo_set_rgb_color"
-external set_alpha : cr:t -> alpha:float -> unit = "ml_cairo_set_alpha"
external set_pattern :
cr:t -> pattern:pattern -> unit = "ml_cairo_set_pattern"
+external set_alpha : cr:t -> alpha:float -> unit = "ml_cairo_set_alpha"
external set_tolerance :
cr:t -> tolerance:float -> unit = "ml_cairo_set_tolerance"
type fill_rule =
@@ -189,6 +195,7 @@ external show_surface :
external current_operator : cr:t -> operator = "ml_cairo_current_operator"
external current_rgb_color :
cr:t -> float * float * float = "ml_cairo_current_rgb_color"
+external current_pattern : cr:t -> pattern = "ml_cairo_current_pattern"
external current_alpha : cr:t -> float = "ml_cairo_current_alpha"
external current_tolerance : cr:t -> float = "ml_cairo_current_tolerance"
external current_point : cr:t -> point = "ml_cairo_current_point"
@@ -201,7 +208,10 @@ external current_matrix :
cr:t -> matrix:matrix -> unit = "ml_cairo_current_matrix"
external current_target_surface :
cr:t -> surface = "ml_cairo_current_target_surface"
-external current_pattern : cr:t -> pattern = "ml_cairo_current_pattern"
+
+external status : t -> status option = "ml_cairo_status"
+external status_string : t -> string = "ml_cairo_status_string"
+
external surface_create_for_image :
image -> surface = "ml_cairo_surface_create_for_image"
external surface_create_similar :
@@ -224,6 +234,7 @@ type filter =
| FILTER_GAUSSIAN
external surface_set_filter :
surface:surface -> filter:filter -> unit = "ml_cairo_surface_set_filter"
+external surface_get_filter : surface:surface -> filter = "ml_cairo_surface_get_filter"
external pattern_create_for_surface : surface -> pattern = "ml_cairo_pattern_create_for_surface"
external pattern_create_linear : x0:float -> y0:float -> x1:float -> y1:float -> pattern
= "ml_cairo_pattern_create_linear"
@@ -254,6 +265,10 @@ external ps_surface_create :
file:Cairo_channel.t -> width_inches:float -> height_inches:float ->
x_pixels_per_inch:float -> y_pixels_per_inch:float ->
surface = "ml_cairo_ps_surface_create"
+external pdf_surface_create :
+ file:Cairo_channel.t -> width_inches:float -> height_inches:float ->
+ x_pixels_per_inch:float -> y_pixels_per_inch:float ->
+ surface = "ml_cairo_pdf_surface_create"
external png_surface_create :
file:Cairo_channel.t -> format -> width:float -> height:float ->
surface = "ml_cairo_png_surface_create"
diff --git a/src/cairo.mli b/src/cairo.mli
index 1ee700f..1bf1608 100644
--- a/src/cairo.mli
+++ b/src/cairo.mli
@@ -4,7 +4,8 @@
(** {3 Error reporting} *)
type status =
- INVALID_RESTORE
+ NO_MEMORY
+ | INVALID_RESTORE
| INVALID_POP_GROUP
| NO_CURRENT_POINT
| INVALID_MATRIX
@@ -34,7 +35,11 @@ type format =
val create : unit -> t
external save : cr:t -> unit = "ml_cairo_save"
external restore : cr:t -> unit = "ml_cairo_restore"
-external copy : dest:t -> src:t -> unit = "ml_cairo_copy"
+external _copy : dest:t -> src:t -> unit = "ml_cairo_copy"
+val copy : t -> t
+
+external status : t -> status option = "ml_cairo_status"
+external status_string : t -> string = "ml_cairo_status_string"
external suspend_exn : t -> unit = "ml_cairo_suspend_exn"
(** The functions operating on cairo values normally raise an [Error] exception
@@ -57,6 +62,13 @@ external set_target_ps :
height_inches:float ->
x_pixels_per_inch:float -> y_pixels_per_inch:float -> unit
= "ml_cairo_set_target_ps_bc" "ml_cairo_set_target_ps"
+external set_target_pdf :
+ cr:t ->
+ file:Cairo_channel.t ->
+ width_inches:float ->
+ height_inches:float ->
+ x_pixels_per_inch:float -> y_pixels_per_inch:float -> unit
+ = "ml_cairo_set_target_pdf_bc" "ml_cairo_set_target_pdf"
external set_target_png :
cr:t -> file:Cairo_channel.t -> format -> width:int -> height:int -> unit = "ml_cairo_set_target_png"
external finalise_target : cr:t -> unit = "ml_cairo_finalise_target"
@@ -83,9 +95,9 @@ external set_operator : cr:t -> op:operator -> unit = "ml_cairo_set_operator"
external set_rgb_color :
cr:t -> red:float -> green:float -> blue:float -> unit
= "ml_cairo_set_rgb_color"
-external set_alpha : cr:t -> alpha:float -> unit = "ml_cairo_set_alpha"
external set_pattern : cr:t -> pattern:pattern -> unit
= "ml_cairo_set_pattern"
+external set_alpha : cr:t -> alpha:float -> unit = "ml_cairo_set_alpha"
external set_tolerance : cr:t -> tolerance:float -> unit
= "ml_cairo_set_tolerance"
type fill_rule = FILL_RULE_WINDING | FILL_RULE_EVEN_ODD
@@ -170,16 +182,6 @@ external in_fill : cr:t -> x:float -> y:float -> bool = "ml_cairo_in_fill"
external stroke_extents : cr:t -> float * float * float * float = "ml_cairo_stroke_extents"
external fill_extents : cr:t -> float * float * float * float = "ml_cairo_fill_extents"
-type flat_path = [
- | `MOVE_TO of point
- | `LINE_TO of point
- | `CLOSE ]
-type basic_path = [
- | flat_path
- | `CURVE_TO of point * point * point ]
-external fold_current_path : t -> ('a -> [> basic_path] -> 'a) -> 'a -> 'a = "ml_cairo_current_path"
-external fold_current_path_flat : t -> ('a -> [> flat_path] -> 'a) -> 'a -> 'a = "ml_cairo_current_path_flat"
-
(** {3 Misc stuff I don't know how to categorize} *)
external show_surface :
@@ -239,6 +241,7 @@ external glyph_path : t -> glyph array -> unit = "ml_cairo_glyph_path"
external current_operator : cr:t -> operator = "ml_cairo_current_operator"
external current_rgb_color : cr:t -> float * float * float
= "ml_cairo_current_rgb_color"
+external current_pattern : cr:t -> pattern = "ml_cairo_current_pattern"
external current_alpha : cr:t -> float = "ml_cairo_current_alpha"
external current_tolerance : cr:t -> float = "ml_cairo_current_tolerance"
external current_point : cr:t -> point = "ml_cairo_current_point"
@@ -251,7 +254,16 @@ external current_matrix : cr:t -> matrix:matrix -> unit
= "ml_cairo_current_matrix"
external current_target_surface : cr:t -> surface
= "ml_cairo_current_target_surface"
-external current_pattern : cr:t -> pattern = "ml_cairo_current_pattern"
+
+type flat_path = [
+ | `MOVE_TO of point
+ | `LINE_TO of point
+ | `CLOSE ]
+type basic_path = [
+ | flat_path
+ | `CURVE_TO of point * point * point ]
+external fold_current_path : t -> ('a -> [> basic_path] -> 'a) -> 'a -> 'a = "ml_cairo_current_path"
+external fold_current_path_flat : t -> ('a -> [> flat_path] -> 'a) -> 'a -> 'a = "ml_cairo_current_path_flat"
(** {3 Surface API} *)
@@ -275,6 +287,8 @@ type filter =
| FILTER_GAUSSIAN
external surface_set_filter : surface:surface -> filter:filter -> unit
= "ml_cairo_surface_set_filter"
+external surface_get_filter : surface:surface -> filter
+ = "ml_cairo_surface_get_filter"
external surface_finalise : surface -> unit = "ml_cairo_surface_finalise"
(** {4 Pattern functions} *)
@@ -322,6 +336,15 @@ external ps_surface_create :
x_pixels_per_inch:float -> y_pixels_per_inch:float -> surface
= "ml_cairo_ps_surface_create"
+(** {4 PDF surface} *)
+
+external pdf_surface_create :
+ file:Cairo_channel.t ->
+ width_inches:float ->
+ height_inches:float ->
+ x_pixels_per_inch:float -> y_pixels_per_inch:float -> surface
+ = "ml_cairo_pdf_surface_create"
+
(** {4 PNG surface} *)
external png_surface_create :
diff --git a/src/cairo_channel.ml b/src/cairo_channel.ml
new file mode 100644
index 0000000..cf36023
--- /dev/null
+++ b/src/cairo_channel.ml
@@ -0,0 +1,10 @@
+type t
+external of_out_channel : out_channel -> t = "ml_FILE_of_channel"
+external of_file_descr : Unix.file_descr -> t = "ml_FILE_of_file_descr"
+external close : t -> unit = "ml_fclose"
+
+let open_out fname =
+ let oc = Pervasives.open_out fname in
+ let c = of_out_channel oc in
+ close_out oc ;
+ c
diff --git a/src/cairo_channel.mli b/src/cairo_channel.mli
index 46cef25..92e81c5 100644
--- a/src/cairo_channel.mli
+++ b/src/cairo_channel.mli
@@ -1,6 +1,8 @@
-(** Support module for file-based backends (PostScript and PNG) *)
+(** Support module for file-based backends (PostScript, PDF and PNG) *)
type t
+
+val open_out : string -> t
external of_out_channel : out_channel -> t = "ml_FILE_of_channel"
external of_file_descr : Unix.file_descr -> t = "ml_FILE_of_file_descr"
external close : t -> unit = "ml_fclose"
diff --git a/src/cairo_ft.ml b/src/cairo_ft.ml
index 962e3a4..bd49f31 100644
--- a/src/cairo_ft.ml
+++ b/src/cairo_ft.ml
@@ -11,10 +11,10 @@ external done_freetype : ft_library -> unit = "ml_FT_Done_FreeType"
external new_face : ft_library -> ?index:int -> string -> ft_face = "ml_FT_New_Face"
external done_face : ft_face -> unit = "ml_FT_Done_Face"
-external font_create_for_ft_face : ft_face -> Cairo.font = "ml_cairo_ft_font_create_for_ft_face"
-
type fc_pattern
external fc_name_parse : string -> fc_pattern = "ml_FcNameParse"
external fc_name_unparse : fc_pattern -> string = "ml_FcNameUnparse"
external font_create : ft_library -> fc_pattern -> Cairo.font = "ml_cairo_ft_font_create"
+external font_create_for_ft_face : ft_face -> Cairo.font = "ml_cairo_ft_font_create_for_ft_face"
+external font_pattern : Cairo.font -> fc_pattern = "ml_cairo_ft_font_pattern"
diff --git a/src/cairo_ft.mli b/src/cairo_ft.mli
index d140c6b..f6eef0a 100644
--- a/src/cairo_ft.mli
+++ b/src/cairo_ft.mli
@@ -12,12 +12,12 @@ external new_face : ft_library -> ?index:int -> string -> ft_face
= "ml_FT_New_Face"
external done_face : ft_face -> unit = "ml_FT_Done_Face"
-external font_create_for_ft_face : ft_face -> Cairo.font
- = "ml_cairo_ft_font_create_for_ft_face"
-
type fc_pattern
external fc_name_parse : string -> fc_pattern = "ml_FcNameParse"
external fc_name_unparse : fc_pattern -> string = "ml_FcNameUnparse"
external font_create : ft_library -> fc_pattern -> Cairo.font
= "ml_cairo_ft_font_create"
+external font_create_for_ft_face : ft_face -> Cairo.font
+ = "ml_cairo_ft_font_create_for_ft_face"
+external font_pattern : Cairo.font -> fc_pattern = "ml_cairo_ft_font_pattern"
diff --git a/src/ml_cairo.c b/src/ml_cairo.c
index 1e80d89..e7a4e32 100644
--- a/src/ml_cairo.c
+++ b/src/ml_cairo.c
@@ -7,6 +7,17 @@
#include "ml_cairo_wrappers.h"
#include <cairo.h>
+/* import file-based backends */
+#ifdef CAIRO_HAS_PS_SURFACE
+# include <cairo-ps.h>
+#endif
+#ifdef CAIRO_HAS_PDF_SURFACE
+# include <cairo-pdf.h>
+#endif
+#ifdef CAIRO_HAS_PNG_SURFACE
+# include <cairo-png.h>
+#endif
+
#include "ml_cairo_channel.h"
#include "ml_cairo_status.h"
#include "ml_cairo.h"
@@ -39,10 +50,8 @@ Val_cairo_t (cairo_t * p)
}
Make_Val_final_pointer(cairo_surface_t, Ignore, cairo_surface_destroy, 20)
-#define cairo_surface_t_val(v) ((cairo_surface_t *)Pointer_val(v))
Make_Val_final_pointer(cairo_matrix_t, Ignore, cairo_matrix_destroy, 100)
-#define cairo_matrix_t_val(v) ((cairo_matrix_t *)Pointer_val(v))
Make_Val_final_pointer(cairo_pattern_t, Ignore, cairo_pattern_destroy, 20)
#define cairo_pattern_t_val(v) ((cairo_pattern_t *)Pointer_val(v))
@@ -73,7 +82,7 @@ ml_cairo_get_suspend_exn (value v_cr)
ML_0(cairo_create, Val_cairo_t)
-ML_1(cairo_destroy, cairo_t_val, Unit)
+/* ML_1(cairo_destroy, cairo_t_val, Unit) */
CAMLprim value
ml_cairo_save (value v_cr)
@@ -132,6 +141,25 @@ Unsupported(ml_cairo_set_target_ps)
#endif /* CAIRO_HAS_PS_SURFACE */
ML_bc6(cairo_set_target_ps)
+#ifdef CAIRO_HAS_PDF_SURFACE
+CAMLprim value
+ml_cairo_set_target_pdf (value v_cr, value v_file, value v_width_inches,
+ value v_height_inches, value v_x_pixels_per_inch,
+ value v_y_pixels_per_inch)
+{
+ cairo_set_target_pdf (cairo_t_val (v_cr), FILE_val (v_file),
+ Double_val (v_width_inches),
+ Double_val (v_height_inches),
+ Double_val (v_x_pixels_per_inch),
+ Double_val (v_y_pixels_per_inch));
+ check_cairo_status (v_cr);
+ return Val_unit;
+}
+#else
+Unsupported(ml_cairo_set_target_pdf)
+#endif /* CAIRO_HAS_PDF_SURFACE */
+ML_bc6(cairo_set_target_pdf)
+
#ifdef CAIRO_HAS_PNG_SURFACE
CAMLprim value
ml_cairo_set_target_png (value v_cr, value v_file, value v_format,
@@ -168,17 +196,17 @@ ml_cairo_set_rgb_color (value v_cr, value v_red, value v_green, value v_blue)
}
CAMLprim value
-ml_cairo_set_alpha (value v_cr, value v_alpha)
+ml_cairo_set_pattern (value v_cr, value v_pattern)
{
- cairo_set_alpha (cairo_t_val (v_cr), Double_val (v_alpha));
+ cairo_set_pattern (cairo_t_val (v_cr), cairo_pattern_t_val (v_pattern));
check_cairo_status (v_cr);
return Val_unit;
}
CAMLprim value
-ml_cairo_set_pattern (value v_cr, value v_pattern)
+ml_cairo_set_alpha (value v_cr, value v_alpha)
{
- cairo_set_pattern (cairo_t_val (v_cr), cairo_pattern_t_val (v_pattern));
+ cairo_set_alpha (cairo_t_val (v_cr), Double_val (v_alpha));
check_cairo_status (v_cr);
return Val_unit;
}
@@ -366,7 +394,6 @@ ml_cairo_inverse_transform_distance (value cr, value p)
return Val_unit;
}
-
CAMLprim value
ml_cairo_new_path (value v_cr)
{
@@ -515,7 +542,7 @@ ml_cairo_in_stroke (value v_cr, value v_x, value v_y)
c_ret =
cairo_in_stroke (cairo_t_val (v_cr), Double_val (v_x), Double_val (v_y));
check_cairo_status (v_cr);
- return Val_int (c_ret);
+ return Val_bool (c_ret);
}
CAMLprim value
@@ -525,7 +552,7 @@ ml_cairo_in_fill (value v_cr, value v_x, value v_y)
c_ret =
cairo_in_fill (cairo_t_val (v_cr), Double_val (v_x), Double_val (v_y));
check_cairo_status (v_cr);
- return Val_int (c_ret);
+ return Val_bool (c_ret);
}
CAMLprim value
@@ -565,28 +592,27 @@ ml_cairo_fill_extents (value v_cr)
}
CAMLprim value
-ml_cairo_clip (value v_cr)
+ml_cairo_init_clip (value v_cr)
{
- cairo_clip (cairo_t_val (v_cr));
+ cairo_init_clip (cairo_t_val (v_cr));
check_cairo_status (v_cr);
return Val_unit;
}
CAMLprim value
-ml_cairo_init_clip (value v_cr)
+ml_cairo_clip (value v_cr)
{
- cairo_init_clip (cairo_t_val (v_cr));
+ cairo_clip (cairo_t_val (v_cr));
check_cairo_status (v_cr);
return Val_unit;
}
Make_Val_final_pointer(cairo_font_t, Ignore, cairo_font_destroy, 20)
-#define cairo_font_t_val(v) ((cairo_font_t *)Pointer_val(v))
static void
cairo_glyph_t_val (cairo_glyph_t * _s, value _v)
{
- _s->index = Int_val (Field (_v, 0));
+ _s->index = Long_val (Field (_v, 0));
_s->x = Double_val (Field (_v, 1));
_s->y = Double_val (Field (_v, 2));
}
@@ -677,6 +703,7 @@ ml_cairo_current_font (value cr)
{
cairo_font_t *f = cairo_current_font (cairo_t_val (cr));
check_cairo_status (cr);
+ cairo_font_reference (f);
return Val_cairo_font_t (f);
}
@@ -741,7 +768,7 @@ ml_cairo_glyph_path (value v_ct, value v_glyphs)
return Val_unit;
}
-ML_1(cairo_font_destroy, cairo_font_t_val, Unit)
+/* ML_1(cairo_font_destroy, cairo_font_t_val, Unit) */
ML_2(cairo_font_set_transform, cairo_font_t_val, cairo_matrix_t_val, Unit)
ML_2(cairo_font_current_transform, cairo_font_t_val, cairo_matrix_t_val, Unit)
@@ -886,7 +913,20 @@ ml_cairo_current_target_surface (value cr)
return Val_cairo_surface_t (s);
}
-ML_1(cairo_status, cairo_t_val, Val_cairo_status_t)
+CAMLprim value
+ml_cairo_status (value v_cr)
+{
+ value v;
+ int status = cairo_status (cairo_t_val (v_cr));
+ if (status == CAIRO_STATUS_SUCCESS)
+ v = Val_unit;
+ else
+ {
+ v = alloc_small (1, 0);
+ Field (v, 0) = Val_int (status - 1);
+ }
+ return v;
+}
ML_1(cairo_status_string, cairo_t_val, copy_string)
CAMLprim value
@@ -902,7 +942,7 @@ ml_cairo_surface_create_for_image (value img)
}
ML_4(cairo_surface_create_similar, cairo_surface_t_val, cairo_format_t_val, Int_val, Int_val, Val_cairo_surface_t)
-ML_1(cairo_surface_destroy, cairo_surface_t_val, Unit)
+/* ML_1(cairo_surface_destroy, cairo_surface_t_val, Unit) */
ML_2(cairo_surface_set_repeat, cairo_surface_t_val, Int_val, Val_cairo_status_t)
ML_2(cairo_surface_set_matrix, cairo_surface_t_val, cairo_matrix_t_val, Val_cairo_status_t)
@@ -912,6 +952,7 @@ ML_2(cairo_surface_get_matrix, cairo_surface_t_val, cairo_matrix_t_val, Val_cair
#define Val_cairo_filter_t(v) Val_int(v)
ML_2(cairo_surface_set_filter, cairo_surface_t_val, cairo_filter_t_val, Val_cairo_status_t)
+ML_1(cairo_surface_get_filter, cairo_surface_t_val, Val_cairo_filter_t)
ML_3(cairo_image_surface_create, cairo_format_t_val, Int_val, Int_val, Val_cairo_surface_t)
@@ -934,14 +975,37 @@ ML_5(cairo_ps_surface_create, FILE_val, Double_val, Double_val, Double_val, Doub
Unsupported(ml_cairo_ps_surface_create)
#endif /* CAIRO_HAS_PS_SURFACE */
+#ifdef CAIRO_HAS_PDF_SURFACE
+ML_5(cairo_pdf_surface_create, FILE_val, Double_val, Double_val, Double_val, Double_val, Val_cairo_surface_t)
+#else
+Unsupported(ml_cairo_pdf_surface_create)
+#endif /* CAIRO_HAS_PDF_SURFACE */
+
#ifdef CAIRO_HAS_PNG_SURFACE
ML_4(cairo_png_surface_create, FILE_val, cairo_format_t_val, Double_val, Double_val, Val_cairo_surface_t)
#else
Unsupported(ml_cairo_png_surface_create)
#endif /* CAIRO_HAS_PNG_SURFACE */
+ML_1 (cairo_pattern_create_for_surface, cairo_surface_t_val, Val_cairo_pattern_t)
+ML_4 (cairo_pattern_create_linear, Double_val, Double_val, Double_val, Double_val, Val_cairo_pattern_t)
+ML_6 (cairo_pattern_create_radial, Double_val, Double_val, Double_val, Double_val, Double_val, Double_val, Val_cairo_pattern_t)
+ML_bc6 (cairo_pattern_create_radial)
+ML_6 (cairo_pattern_add_color_stop, cairo_pattern_t_val, Double_val, Double_val, Double_val, Double_val, Double_val, Val_cairo_status_t)
+ML_bc6 (cairo_pattern_add_color_stop)
+ML_2 (cairo_pattern_set_matrix, cairo_pattern_t_val, cairo_matrix_t_val, Val_cairo_status_t)
+ML_2 (cairo_pattern_get_matrix, cairo_pattern_t_val, cairo_matrix_t_val, Val_cairo_status_t)
+
+#define cairo_extend_t_val(v) ((cairo_extend_t) Int_val(v))
+#define Val_cairo_extend_t(v) Val_int(v)
+
+ML_2 (cairo_pattern_set_extend, cairo_pattern_t_val, cairo_extend_t_val, Val_cairo_status_t)
+ML_1 (cairo_pattern_get_extend, cairo_pattern_t_val, Val_cairo_extend_t)
+ML_2 (cairo_pattern_set_filter, cairo_pattern_t_val, cairo_filter_t_val, Val_cairo_status_t)
+ML_1 (cairo_pattern_get_filter, cairo_pattern_t_val, Val_cairo_filter_t)
+
ML_0(cairo_matrix_create, Val_cairo_matrix_t)
-ML_1(cairo_matrix_destroy, cairo_matrix_t_val, Unit)
+/* ML_1(cairo_matrix_destroy, cairo_matrix_t_val, Unit) */
ML_2(cairo_matrix_copy, cairo_matrix_t_val, cairo_matrix_t_val, Val_cairo_status_t)
ML_1(cairo_matrix_set_identity, cairo_matrix_t_val, Val_cairo_status_t)
CAMLprim value
@@ -985,25 +1049,27 @@ ML_3(cairo_matrix_multiply, cairo_matrix_t_val, cairo_matrix_t_val, cairo_matrix
CAMLprim value
ml_cairo_matrix_transform_distance (value m, value p)
{
+ cairo_status_t s;
double x, y;
x = Double_field (p, 0);
y = Double_field (p, 1);
- cairo_matrix_transform_distance (cairo_matrix_t_val (m), &x, &y);
+ s = cairo_matrix_transform_distance (cairo_matrix_t_val (m), &x, &y);
Store_double_field (p, 0, x);
Store_double_field (p, 1, y);
- return Val_unit;
+ return Val_cairo_status_t (s);
}
CAMLprim value
ml_cairo_matrix_transform_point (value m, value p)
{
+ cairo_status_t s;
double x, y;
x = Double_field (p, 0);
y = Double_field (p, 1);
- cairo_matrix_transform_point (cairo_matrix_t_val (m), &x, &y);
+ s = cairo_matrix_transform_point (cairo_matrix_t_val (m), &x, &y);
Store_double_field (p, 0, x);
Store_double_field (p, 1, y);
- return Val_unit;
+ return Val_cairo_status_t (s);
}
CAMLprim value
@@ -1021,20 +1087,3 @@ ml_cairo_surface_finalise (value s)
Store_pointer (s, NULL);
return Val_unit;
}
-
-ML_1 (cairo_pattern_create_for_surface, cairo_surface_t_val, Val_cairo_pattern_t)
-ML_4 (cairo_pattern_create_linear, Double_val, Double_val, Double_val, Double_val, Val_cairo_pattern_t)
-ML_6 (cairo_pattern_create_radial, Double_val, Double_val, Double_val, Double_val, Double_val, Double_val, Val_cairo_pattern_t)
-ML_bc6 (cairo_pattern_create_radial)
-ML_6 (cairo_pattern_add_color_stop, cairo_pattern_t_val, Double_val, Double_val, Double_val, Double_val, Double_val, Val_cairo_status_t)
-ML_bc6 (cairo_pattern_add_color_stop)
-ML_2(cairo_pattern_set_matrix, cairo_pattern_t_val, cairo_matrix_t_val, Val_cairo_status_t)
-ML_2(cairo_pattern_get_matrix, cairo_pattern_t_val, cairo_matrix_t_val, Val_cairo_status_t)
-
-#define cairo_extend_t_val(v) ((cairo_extend_t) Int_val(v))
-#define Val_cairo_extend_t(v) Val_int(v)
-
-ML_2 (cairo_pattern_set_extend, cairo_pattern_t_val, cairo_extend_t_val, Val_cairo_status_t)
-ML_1 (cairo_pattern_get_extend, cairo_pattern_t_val, Val_cairo_extend_t)
-ML_2 (cairo_pattern_set_filter, cairo_pattern_t_val, cairo_filter_t_val, Val_cairo_status_t)
-ML_1 (cairo_pattern_get_filter, cairo_pattern_t_val, Val_cairo_filter_t)
diff --git a/src/ml_cairo.h b/src/ml_cairo.h
index 68059b7..329afb4 100644
--- a/src/ml_cairo.h
+++ b/src/ml_cairo.h
@@ -3,10 +3,16 @@ struct ml_cairo {
int suspend_exn;
};
#define cairo_t_val(v) (((struct ml_cairo *) Data_custom_val(v))->cr)
+value Val_cairo_t (cairo_t *);
#define cairo_format_t_val(v) ((cairo_format_t) Int_val(v))
#define Val_cairo_format_t(v) Val_int(v)
+#define cairo_surface_t_val(v) ((cairo_surface_t *)Pointer_val(v))
value Val_cairo_surface_t (cairo_surface_t *);
+
+#define cairo_font_t_val(v) ((cairo_font_t *)Pointer_val(v))
value Val_cairo_font_t (cairo_font_t *);
-value Val_cairo_t (cairo_t *);
+
+#define cairo_matrix_t_val(v) ((cairo_matrix_t *)Pointer_val(v))
+value Val_cairo_matrix_t (cairo_matrix_t *);
diff --git a/src/ml_cairo_ft.c b/src/ml_cairo_ft.c
index 5de30a5..3bc164e 100644
--- a/src/ml_cairo_ft.c
+++ b/src/ml_cairo_ft.c
@@ -8,9 +8,16 @@
#include "ml_cairo_wrappers.h"
#include <cairo.h>
+#ifdef CAIRO_HAS_FT_FONT
+# include <cairo-ft.h>
+#endif
+
#include "ml_cairo.h"
#include "ml_cairo_status.h"
+#ifdef CAIRO_HAS_FT_FONT
+
+/* minimal Freetype interface */
static void
ml_raise_FT_Error (FT_Error err)
{
@@ -65,8 +72,7 @@ ml_FT_Done_Face (value face)
return Val_unit;
}
-ML_1 (cairo_ft_font_create_for_ft_face, FT_Face_val, Val_cairo_font_t)
-
+/* minimal Fontconfig interface */
Make_Val_final_pointer (FcPattern, Ignore, FcPatternDestroy, 10)
#define FcPattern_val(v) (FcPattern *)Pointer_val(v)
@@ -85,4 +91,21 @@ ml_FcNameUnparse (value patt)
return r;
}
+/* cairo Fontconfig/Freetype font backend */
ML_2 (cairo_ft_font_create, FT_Library_val, FcPattern_val, Val_cairo_font_t)
+ML_1 (cairo_ft_font_create_for_ft_face, FT_Face_val, Val_cairo_font_t)
+ML_1 (cairo_ft_font_pattern, cairo_font_t_val, Val_FcPattern)
+
+#else
+
+Unsupported (ml_FT_Init_FreeType)
+Unsupported (ml_FT_Done_FreeType)
+Unsupported (ml_FT_New_Face)
+Unsupported (ml_FT_Done_Face)
+Unsupported (ml_FcNameParse)
+Unsupported (ml_FcNameUnparse)
+Unsupported (ml_cairo_ft_font_create)
+Unsupported (ml_cairo_ft_font_create_for_ft_face)
+Unsupported (ml_cairo_ft_font_pattern)
+
+#endif /* CAIRO_HAS_FT_FONT */
diff --git a/src/ml_cairo_gtkcairo.c b/src/ml_cairo_gtkcairo.c
index d351833..caef361 100644
--- a/src/ml_cairo_gtkcairo.c
+++ b/src/ml_cairo_gtkcairo.c
@@ -8,19 +8,19 @@
#include "ml_cairo.h"
CAMLprim value
-ml_cairo_gtkcairo_init(value unit)
+ml_cairo_gtkcairo_init (value unit)
{
- GType t = gtk_cairo_get_type();
- return Val_GType(t);
+ GType t = gtk_cairo_get_type ();
+ return Val_GType (t);
}
#define GtkCairo_val(v) check_cast(GTK_CAIRO, v)
CAMLprim value
-ml_cairo_gtkcairo_get_cairo(value w)
+ml_cairo_gtkcairo_get_cairo (value w)
{
- GtkCairo *c = GtkCairo_val(w);
- cairo_t *cr = gtk_cairo_get_cairo(c);
- cairo_reference(cr);
- return Val_cairo_t(cr);
+ GtkCairo *c = GtkCairo_val (w);
+ cairo_t *cr = gtk_cairo_get_cairo (c);
+ cairo_reference (cr);
+ return Val_cairo_t (cr);
}
diff --git a/src/ml_cairo_lablgtk.c b/src/ml_cairo_lablgtk.c
index 6929e57..e5a022e 100644
--- a/src/ml_cairo_lablgtk.c
+++ b/src/ml_cairo_lablgtk.c
@@ -2,6 +2,9 @@
#include <gdk/gdkx.h>
#include <cairo.h>
+#ifdef CAIRO_HAS_XLIB_SURFACE
+# include <cairo-xlib.h>
+#endif
#include <caml/mlvalues.h>
#include <caml/alloc.h>
diff --git a/src/ml_cairo_status.c b/src/ml_cairo_status.c
index e47b4fc..e3b8041 100644
--- a/src/ml_cairo_status.c
+++ b/src/ml_cairo_status.c
@@ -6,45 +6,20 @@
#include "ml_cairo_status.h"
void
-cairo_treat_status (cairo_status_t s)
+cairo_treat_status (cairo_status_t status)
{
static value *cairo_exn;
- int status;
- switch (s)
+ if (status != CAIRO_STATUS_SUCCESS)
{
- case CAIRO_STATUS_SUCCESS:
- return;
- case CAIRO_STATUS_NO_MEMORY:
- raise_out_of_memory ();
- case CAIRO_STATUS_INVALID_RESTORE:
- status = 0;
- break;
- case CAIRO_STATUS_INVALID_POP_GROUP:
- status = 1;
- break;
- case CAIRO_STATUS_NO_CURRENT_POINT:
- status = 2;
- break;
- case CAIRO_STATUS_INVALID_MATRIX:
- status = 3;
- break;
- case CAIRO_STATUS_NO_TARGET_SURFACE:
- status = 4;
- break;
- case CAIRO_STATUS_NULL_POINTER:
- status = 5;
- break;
- }
-
- if (cairo_exn == NULL)
- {
- cairo_exn = caml_named_value ("cairo_status_exn");
if (cairo_exn == NULL)
- failwith ("cairo exception");
+ {
+ cairo_exn = caml_named_value ("cairo_status_exn");
+ if (cairo_exn == NULL)
+ failwith ("cairo exception");
+ }
+ raise_with_arg (*cairo_exn, Val_int (status - 1));
}
-
- raise_with_arg (*cairo_exn, Val_int (status));
}
void
@@ -52,10 +27,5 @@ check_cairo_status (value cr)
{
struct ml_cairo *ml_c = Data_custom_val (cr);
if (!ml_c->suspend_exn)
- {
- cairo_status_t status;
- status = cairo_status (ml_c->cr);
- if (status != CAIRO_STATUS_SUCCESS)
- cairo_treat_status (status);
- }
+ cairo_treat_status (cairo_status (ml_c->cr));
}
diff --git a/support/ocaml.m4 b/support/ocaml.m4
index 1211fe7..8804361 100644
--- a/support/ocaml.m4
+++ b/support/ocaml.m4
@@ -17,7 +17,7 @@ dnl
dnl OCAMLMKTOP
dnl OCAMLMKLIB
dnl OCAMLDOC
-AC_DEFUN(AC_PROG_OCAML,
+AC_DEFUN([AC_PROG_OCAML],
[dnl
# checking for ocamlc
AC_CHECK_PROG(OCAMLC,ocamlc,ocamlc,AC_MSG_ERROR(Cannot find ocamlc.))
@@ -94,7 +94,7 @@ dnl
dnl macro AC_PROG_OCAML_TOOLS will check OCamllex and OCamlyacc :
dnl OCAMLLEX "ocamllex" or "ocamllex.opt" if present
dnl OCAMLYACC "ocamlyac"
-AC_DEFUN(AC_PROG_OCAML_TOOLS,
+AC_DEFUN([AC_PROG_OCAML_TOOLS],
[dnl
# checking for ocamllex and ocamlyacc
AC_CHECK_PROG(OCAMLLEX,ocamllex,ocamllex,AC_MSG_ERROR(Cannot find ocamllex.))
@@ -114,7 +114,7 @@ dnl
dnl
dnl
dnl AC_PROG_CAMLP4 checks for Camlp4
-AC_DEFUN(AC_PROG_CAMLP4,
+AC_DEFUN([AC_PROG_CAMLP4],
[dnl
AC_REQUIRE([AC_PROG_OCAML])
# checking for camlp4
@@ -135,7 +135,7 @@ dnl
dnl
dnl macro AC_PROG_FINDLIB will check for the presence of
dnl ocamlfind if configure is called with --with-findlib
-AC_DEFUN(AC_PROG_FINDLIB,
+AC_DEFUN([AC_PROG_FINDLIB],
[dnl
AC_ARG_WITH(findlib,[ --with-findlib use findlib package system],
use_findlib="$withval")
@@ -153,7 +153,7 @@ dnl
dnl
dnl AC_CHECK_OCAML_PKG checks wether a findlib package is present
dnl defines pkg_name to name
-AC_DEFUN(AC_CHECK_OCAML_PKG,
+AC_DEFUN([AC_CHECK_OCAML_PKG],
[dnl
AC_REQUIRE([AC_PROG_FINDLIB])
if test "$use_findlib" = yes ; then
@@ -171,7 +171,7 @@ dnl
dnl
dnl
dnl AC_ARG_OCAML_INSTALLDIR adds a --with-installdir option
-AC_DEFUN(AC_ARG_OCAML_INSTALLDIR,
+AC_DEFUN([AC_ARG_OCAML_INSTALLDIR],
[dnl
AC_ARG_WITH(installdir,[ --with-installdir=DIR specify installation directory],INSTALLDIR="$withval")
if ! test "$INSTALLDIR" -o "$use_findlib" ; then
@@ -187,7 +187,7 @@ dnl 1 -> name (for printing)
dnl 2 -> env var name
dnl 3 -> module to check
dnl 4 -> default dirs
-AC_DEFUN(AC_CHECK_OCAML_MODULE,
+AC_DEFUN([AC_CHECK_OCAML_MODULE],
[dnl
AC_MSG_CHECKING($1 directory)
cat > conftest.ml <<EOF