summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOlivier Andrieu <oandrieu@gmail.com>2005-08-10 23:45:14 +0000
committerHezekiah M. Carty <hcarty@atmos.umd.edu>2009-06-18 13:59:01 -0400
commitdd5f011670f73a6995ea78f2a187528a9e40f81f (patch)
treea00a3b32b4bfc0a6350909efee8f195f3e67c7ab
parentbbbb6bec592e96559209f020f6cfd5ea4a747ba8 (diff)
Bump to Cairo 0.6.0
* src/* : adapt to cairo-0.6.0 * Makefile, config.make.in, configure.ac: specify version number in the configure.ac file
-rw-r--r--Makefile1
-rw-r--r--README8
-rw-r--r--config.make.in2
-rw-r--r--configure.ac5
-rw-r--r--src/cairo.ml127
-rw-r--r--src/cairo.mli106
-rw-r--r--src/cairo_ft.ml2
-rw-r--r--src/cairo_ft.mli8
-rw-r--r--src/cairo_lablgtk.ml4
-rw-r--r--src/cairo_lablgtk.mli4
-rw-r--r--src/ml_cairo.c3
-rw-r--r--src/ml_cairo.h7
-rw-r--r--src/ml_cairo_font.c36
-rw-r--r--src/ml_cairo_ft.c6
-rw-r--r--src/ml_cairo_lablgtk.c86
-rw-r--r--src/ml_cairo_status.c4
-rw-r--r--src/ml_cairo_surface.c7
-rw-r--r--test/Makefile4
18 files changed, 337 insertions, 83 deletions
diff --git a/Makefile b/Makefile
index 1528cec..db27170 100644
--- a/Makefile
+++ b/Makefile
@@ -3,7 +3,6 @@ all opt doc install clean :
$(MAKE) -C src $@
-VERSION = 0.5.2
DISTSRC = aclocal.m4 config.make.in configure configure.ac Makefile Makefile.rules \
doc support/install-sh support/ocaml.m4 \
src/*.ml src/*.mli src/*.c src/*.h src/Makefile src/.depend_c \
diff --git a/README b/README
index 5eeeb35..8e999dc 100644
--- a/README
+++ b/README
@@ -10,12 +10,18 @@ Compiling
$ ./configure
$ make
+configure will try to detect a LablGTK installation by scanning some
+directories (+lablgtk2 and +lablgtk). If LablGTK is installed
+elsewhere, specify the path with the LABLGTKDIR environment variable.
+
+If you want to disable LablGTK support, run configure with
+--without-gtk option.
Dependencies
============
ocaml 3.08
- cairo 0.5.2
+ cairo 0.6.0
libsvg-cairo optional 0.1.5
LablGTK optional
diff --git a/config.make.in b/config.make.in
index 787bb17..a4f0da9 100644
--- a/config.make.in
+++ b/config.make.in
@@ -1,4 +1,6 @@
+VERSION = @PACKAGE_VERSION@
+
OCAMLC = @OCAMLC@
OCAMLOPT = @OCAMLOPT@
OCAMLMKLIB = @OCAMLMKLIB@
diff --git a/configure.ac b/configure.ac
index 03a133b..ce4b89e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,11 +1,12 @@
-AC_INIT(src/cairo.ml)
+AC_INIT(CAIRO_OCAML, 0.6.0.0)
+AC_CONFIG_SRCDIR(src/cairo.ml)
AC_CONFIG_AUX_DIR(support)
# Check for OCaml programs
AC_PROG_OCAML()
# Check for cairo
-PKG_CHECK_MODULES(CAIRO, cairo >= 0.5.2)
+PKG_CHECK_MODULES(CAIRO, cairo >= 0.6.0)
# Optional GTK support (for the X11 backend)
AC_ARG_WITH(gtk,
diff --git a/src/cairo.ml b/src/cairo.ml
index d40c25a..2215a85 100644
--- a/src/cairo.ml
+++ b/src/cairo.ml
@@ -22,6 +22,10 @@ type status =
| SURFACE_FINISHED
| SURFACE_TYPE_MISMATCH
| PATTERN_TYPE_MISMATCH
+ | INVALID_CONTENT
+ | INVALID_FORMAT
+ | INVALID_VISUAL
+ | FILE_NOT_FOUND
exception Error of status
let init = Callback.register_exception "cairo_status_exn" (Error NULL_POINTER)
@@ -149,17 +153,104 @@ type font_extents =
font_height : float;
max_x_advance : float;
max_y_advance : float }
-type font_weight =
- FONT_WEIGHT_NORMAL
- | FONT_WEIGHT_BOLD
type font_slant =
FONT_SLANT_NORMAL
| FONT_SLANT_ITALIC
| FONT_SLANT_OBLIQUE
+type font_weight =
+ FONT_WEIGHT_NORMAL
+ | FONT_WEIGHT_BOLD
+type antialias =
+ ANTIALIAS_DEFAULT
+ | ANTIALIAS_NONE
+ | ANTIALIAS_GRAY
+ | ANTIALIAS_SUBPIXEL
+type subpixel_order =
+ SUBPIXEL_ORDER_DEFAULT
+ | SUBPIXEL_ORDER_RGB
+ | SUBPIXEL_ORDER_BGR
+ | SUBPIXEL_ORDER_VRGB
+ | SUBPIXEL_ORDER_VBGR
+type hint_style =
+ HINT_STYLE_DEFAULT
+ | HINT_STYLE_NONE
+ | HINT_STYLE_SLIGHT
+ | HINT_STYLE_MEDIUM
+ | HINT_STYLE_FULL
+type hint_metrics =
+ HINT_METRICS_DEFAULT
+ | HINT_METRICS_OFF
+ | HINT_METRICS_ON
+
+module Font_Options = struct
+ type t
+ external create : unit -> t = "ml_cairo_font_options_create"
+ external merge : t -> t -> unit = "ml_cairo_font_options_merge"
+ external get_antialias : t -> antialias = "ml_cairo_font_options_get_antialias"
+ external set_antialias : t -> antialias -> unit = "ml_cairo_font_options_set_antialias"
+ external get_subpixel_order : t -> subpixel_order = "ml_cairo_font_options_get_subpixel_order"
+ external set_subpixel_order : t -> subpixel_order -> unit = "ml_cairo_font_options_set_subpixel_order"
+ external get_hint_style : t -> hint_style = "ml_cairo_font_options_get_hint_style"
+ external set_hint_style : t -> hint_style -> unit = "ml_cairo_font_options_set_hint_style"
+ external get_hint_metrics : t -> hint_metrics = "ml_cairo_font_options_get_hint_metrics"
+ external set_hint_metrics : t -> hint_metrics -> unit = "ml_cairo_font_options_set_hint_metrics"
+ type all =
+ [ `ANTIALIAS_DEFAULT
+ | `ANTIALIAS_GRAY
+ | `ANTIALIAS_NONE
+ | `ANTIALIAS_SUBPIXEL
+ | `HINT_METRICS_DEFAULT
+ | `HINT_METRICS_OFF
+ | `HINT_METRICS_ON
+ | `HINT_STYLE_DEFAULT
+ | `HINT_STYLE_FULL
+ | `HINT_STYLE_MEDIUM
+ | `HINT_STYLE_NONE
+ | `HINT_STYLE_SLIGHT
+ | `SUBPIXEL_ORDER_BGR
+ | `SUBPIXEL_ORDER_DEFAULT
+ | `SUBPIXEL_ORDER_RGB
+ | `SUBPIXEL_ORDER_VBGR
+ | `SUBPIXEL_ORDER_VRGB ]
+ let make l =
+ let o = create () in
+ List.iter (function
+ | `ANTIALIAS_DEFAULT -> set_antialias o ANTIALIAS_DEFAULT
+ | `ANTIALIAS_NONE -> set_antialias o ANTIALIAS_NONE
+ | `ANTIALIAS_GRAY -> set_antialias o ANTIALIAS_GRAY
+ | `ANTIALIAS_SUBPIXEL -> set_antialias o ANTIALIAS_SUBPIXEL
+ | `SUBPIXEL_ORDER_DEFAULT -> set_subpixel_order o SUBPIXEL_ORDER_DEFAULT
+ | `SUBPIXEL_ORDER_RGB -> set_subpixel_order o SUBPIXEL_ORDER_RGB
+ | `SUBPIXEL_ORDER_BGR -> set_subpixel_order o SUBPIXEL_ORDER_BGR
+ | `SUBPIXEL_ORDER_VRGB -> set_subpixel_order o SUBPIXEL_ORDER_VRGB
+ | `SUBPIXEL_ORDER_VBGR -> set_subpixel_order o SUBPIXEL_ORDER_VBGR
+ | `HINT_STYLE_DEFAULT -> set_hint_style o HINT_STYLE_DEFAULT
+ | `HINT_STYLE_NONE -> set_hint_style o HINT_STYLE_NONE
+ | `HINT_STYLE_SLIGHT -> set_hint_style o HINT_STYLE_SLIGHT
+ | `HINT_STYLE_MEDIUM -> set_hint_style o HINT_STYLE_MEDIUM
+ | `HINT_STYLE_FULL -> set_hint_style o HINT_STYLE_FULL
+ | `HINT_METRICS_DEFAULT -> set_hint_metrics o HINT_METRICS_DEFAULT
+ | `HINT_METRICS_OFF -> set_hint_metrics o HINT_METRICS_OFF
+ | `HINT_METRICS_ON -> set_hint_metrics o HINT_METRICS_ON)
+ l ;
+ o
+end
+
external select_font_face : t -> string -> font_slant -> font_weight -> unit = "ml_cairo_select_font_face"
external set_font_size : t -> float -> unit = "ml_cairo_set_font_size"
external set_font_matrix : t -> matrix -> unit = "ml_cairo_set_font_matrix"
external get_font_matrix : t -> matrix = "ml_cairo_get_font_matrix"
+external set_font_options : t -> Font_Options.t -> unit = "ml_cairo_set_font_matrix"
+external _get_font_options : t -> Font_Options.t -> unit = "ml_cairo_get_font_options"
+let merge_font_options cr o' =
+ let o = Font_Options.create () in
+ _get_font_options cr o ;
+ Font_Options.merge o o' ;
+ set_font_options cr o
+let get_font_options cr =
+ let o = Font_Options.create () in
+ _get_font_options cr o ;
+ o
external show_text : t -> string -> unit = "ml_cairo_show_text"
external show_glyphs : t -> glyph array -> unit = "ml_cairo_show_glyphs"
external get_font_face : t -> [`Any] font_face = "ml_cairo_get_font_face"
@@ -170,6 +261,15 @@ external glyph_extents : t -> glyph array -> text_extents = "ml_cairo_glyph_exte
external text_path : t -> string -> unit = "ml_cairo_text_path"
external glyph_path : t -> glyph array -> unit = "ml_cairo_glyph_path"
+(* scaled fonts *)
+module Scaled_Font = struct
+type -'a t
+
+external create : ([>`Any] as 'a) font_face -> matrix -> matrix -> Font_Options.t -> 'a t = "ml_cairo_scaled_font_create"
+external font_extents : [> `Any] t -> font_extents = "ml_cairo_scaled_font_extents"
+external glyph_extents : [> `Any] t -> glyph array -> text_extents = "ml_cairo_scaled_font_glyph_extents"
+end
+
external get_operator : t -> operator = "ml_cairo_get_operator"
external get_source : t -> [`Any] pattern = "ml_cairo_get_source"
external get_tolerance : t -> float = "ml_cairo_get_tolerance"
@@ -199,7 +299,11 @@ let append_path cr = function
| `CURVE_TO (p1, p2, p3) -> curve_to_point cr p1 p2 p3
external status : t -> status = "ml_cairo_status"
+external surface_status : [> `Any] surface -> status = "ml_cairo_surface_status"
external pattern_status : [> `Any] pattern -> status = "ml_cairo_pattern_status"
+external font_face_status : [> `Any] font_face -> status = "ml_cairo_font_face_status"
+external scaled_font_status : [> `Any] Scaled_Font.t -> status = "ml_cairo_scaled_font_status"
+external font_options_status : Font_Options.t -> status = "ml_cairo_font_options_status"
external string_of_status : status -> string = "ml_cairo_status_to_string"
@@ -214,6 +318,12 @@ external surface_create_similar : [> `Any] surface -> content -> width:int -> he
external surface_finish : [> `Any] surface -> unit = "ml_cairo_surface_finish"
+external _surface_get_font_options : [> `Any] surface -> Font_Options.t -> unit = "ml_cairo_surface_get_font_options"
+let surface_get_font_options s =
+ let o = Font_Options.create () in
+ _surface_get_font_options s o ;
+ o
+
external surface_set_device_offset : [> `Any] surface -> float -> float -> unit = "ml_cairo_surface_set_device_offset"
@@ -289,14 +399,3 @@ external multiply : matrix -> matrix -> matrix = "ml_cairo_matrix_multiply"
external transform_distance : matrix -> point -> point = "ml_cairo_matrix_transform_distance"
external transform_point : matrix -> point -> point = "ml_cairo_matrix_transform_point"
end
-
-
-
-(* fonts *)
-module Scaled_Font = struct
-type -'a t
-
-external create : ([>`Any] as 'a) font_face -> matrix -> matrix -> 'a t = "ml_cairo_scaled_font_create"
-external font_extents : [> `Any] t -> font_extents = "ml_cairo_scaled_font_extents"
-external glyph_extents : [> `Any] t -> glyph array -> text_extents = "ml_cairo_scaled_font_glyph_extents"
-end
diff --git a/src/cairo.mli b/src/cairo.mli
index 56164c1..e6804fd 100644
--- a/src/cairo.mli
+++ b/src/cairo.mli
@@ -26,6 +26,10 @@ type status =
| SURFACE_FINISHED
| SURFACE_TYPE_MISMATCH
| PATTERN_TYPE_MISMATCH
+ | INVALID_CONTENT
+ | INVALID_FORMAT
+ | INVALID_VISUAL
+ | FILE_NOT_FOUND
exception Error of status
val init : unit
@@ -50,10 +54,12 @@ external save : t -> unit = "ml_cairo_save"
external restore : t -> unit = "ml_cairo_restore"
external status : t -> status = "ml_cairo_status"
+external surface_status : [> `Any] surface -> status = "ml_cairo_surface_status"
external pattern_status : [> `Any] pattern -> status = "ml_cairo_pattern_status"
+external font_face_status : [> `Any] font_face -> status = "ml_cairo_font_face_status"
external string_of_status : status -> string = "ml_cairo_status_to_string"
-(** {4 Renderer state} *)
+(** {3 Renderer state} *)
type operator =
OPERATOR_CLEAR
@@ -101,7 +107,7 @@ external set_line_join : t -> line_join -> unit = "ml_cairo_set_line_join"
external set_dash : t -> float array -> float -> unit = "ml_cairo_set_dash"
external set_miter_limit : t -> float -> unit = "ml_cairo_set_miter_limit"
-(** {4 Transformations} *)
+(** {3 Transformations} *)
external translate : t -> tx:float -> ty:float -> unit = "ml_cairo_translate"
external scale : t -> sx:float -> sy:float -> unit = "ml_cairo_scale"
@@ -115,7 +121,7 @@ external user_to_device_distance : t -> point -> point = "ml_cairo_user_to_devic
external device_to_user : t -> point -> point = "ml_cairo_device_to_user"
external device_to_user_distance : t -> point -> point = "ml_cairo_device_to_user_distance"
-(** {4 Paths} *)
+(** {3 Paths} *)
external new_path : t -> unit = "ml_cairo_new_path"
external move_to : t -> x:float -> y:float -> unit = "ml_cairo_move_to"
@@ -172,18 +178,80 @@ type font_extents = {
max_x_advance : float;
max_y_advance : float;
}
-type font_weight =
- | FONT_WEIGHT_NORMAL
- | FONT_WEIGHT_BOLD
type font_slant =
| FONT_SLANT_NORMAL
| FONT_SLANT_ITALIC
| FONT_SLANT_OBLIQUE
+type font_weight =
+ | FONT_WEIGHT_NORMAL
+ | FONT_WEIGHT_BOLD
+
+type antialias =
+ ANTIALIAS_DEFAULT
+ | ANTIALIAS_NONE
+ | ANTIALIAS_GRAY
+ | ANTIALIAS_SUBPIXEL
+type subpixel_order =
+ SUBPIXEL_ORDER_DEFAULT
+ | SUBPIXEL_ORDER_RGB
+ | SUBPIXEL_ORDER_BGR
+ | SUBPIXEL_ORDER_VRGB
+ | SUBPIXEL_ORDER_VBGR
+type hint_style =
+ HINT_STYLE_DEFAULT
+ | HINT_STYLE_NONE
+ | HINT_STYLE_SLIGHT
+ | HINT_STYLE_MEDIUM
+ | HINT_STYLE_FULL
+type hint_metrics =
+ HINT_METRICS_DEFAULT
+ | HINT_METRICS_OFF
+ | HINT_METRICS_ON
+
+(** {4 Font options} *)
+
+(** Font options functions *)
+module Font_Options : sig
+ type t
+ external create : unit -> t = "ml_cairo_font_options_create"
+ external merge : t -> t -> unit = "ml_cairo_font_options_merge"
+ external get_antialias : t -> antialias = "ml_cairo_font_options_get_antialias"
+ external set_antialias : t -> antialias -> unit = "ml_cairo_font_options_set_antialias"
+ external get_subpixel_order : t -> subpixel_order = "ml_cairo_font_options_get_subpixel_order"
+ external set_subpixel_order : t -> subpixel_order -> unit = "ml_cairo_font_options_set_subpixel_order"
+ external get_hint_style : t -> hint_style = "ml_cairo_font_options_get_hint_style"
+ external set_hint_style : t -> hint_style -> unit = "ml_cairo_font_options_set_hint_style"
+ external get_hint_metrics : t -> hint_metrics = "ml_cairo_font_options_get_hint_metrics"
+ external set_hint_metrics : t -> hint_metrics -> unit = "ml_cairo_font_options_set_hint_metrics"
+
+ type all = [
+ `ANTIALIAS_DEFAULT
+ | `ANTIALIAS_GRAY
+ | `ANTIALIAS_NONE
+ | `ANTIALIAS_SUBPIXEL
+ | `HINT_METRICS_DEFAULT
+ | `HINT_METRICS_OFF
+ | `HINT_METRICS_ON
+ | `HINT_STYLE_DEFAULT
+ | `HINT_STYLE_FULL
+ | `HINT_STYLE_MEDIUM
+ | `HINT_STYLE_NONE
+ | `HINT_STYLE_SLIGHT
+ | `SUBPIXEL_ORDER_BGR
+ | `SUBPIXEL_ORDER_DEFAULT
+ | `SUBPIXEL_ORDER_RGB
+ | `SUBPIXEL_ORDER_VBGR
+ | `SUBPIXEL_ORDER_VRGB ]
+ val make : [< all] list -> t
+end
external select_font_face : t -> string -> font_slant -> font_weight -> unit = "ml_cairo_select_font_face"
external set_font_size : t -> float -> unit = "ml_cairo_set_font_size"
external set_font_matrix : t -> matrix -> unit = "ml_cairo_set_font_matrix"
external get_font_matrix : t -> matrix = "ml_cairo_get_font_matrix"
+external set_font_options : t -> Font_Options.t -> unit = "ml_cairo_set_font_matrix"
+val merge_font_options : t -> Font_Options.t -> unit
+val get_font_options : t -> Font_Options.t
external show_text : t -> string -> unit = "ml_cairo_show_text"
external show_glyphs : t -> glyph array -> unit = "ml_cairo_show_glyphs"
external get_font_face : t -> [`Any] font_face = "ml_cairo_get_font_face"
@@ -194,7 +262,18 @@ external glyph_extents : t -> glyph array -> text_extents = "ml_cairo_glyph_exte
external text_path : t -> string -> unit = "ml_cairo_text_path"
external glyph_path : t -> glyph array -> unit = "ml_cairo_glyph_path"
-(** {4 Renderer state querying} *)
+(** {4 Scaled Fonts API} *)
+
+(** Scaled fonts functions *)
+module Scaled_Font : sig
+type -'a t
+
+external create : ([>`Any] as 'a) font_face -> matrix -> matrix -> Font_Options.t -> 'a t = "ml_cairo_scaled_font_create"
+external font_extents : [> `Any] t -> font_extents = "ml_cairo_scaled_font_extents"
+external glyph_extents : [>`Any] t -> glyph array -> text_extents = "ml_cairo_scaled_font_glyph_extents"
+end
+
+(** {3 Renderer state querying} *)
external get_operator : t -> operator = "ml_cairo_get_operator"
external get_source : t -> [`Any] pattern = "ml_cairo_get_source"
@@ -247,7 +326,7 @@ external image_surface_create : format -> width:int -> height:int -> image_surfa
external image_surface_get_width : [>`Image] surface -> int = "ml_cairo_image_surface_get_width"
external image_surface_get_height : [>`Image] surface -> int = "ml_cairo_image_surface_get_height"
-(** {4 Patterns} *)
+(** {3 Patterns} *)
type solid_pattern = [`Any|`Solid] pattern
type surface_pattern = [`Any|`Surface] pattern
@@ -305,14 +384,3 @@ external multiply : matrix -> matrix -> matrix = "ml_cairo_matrix_multiply"
external transform_distance : matrix -> point -> point = "ml_cairo_matrix_transform_distance"
external transform_point : matrix -> point -> point = "ml_cairo_matrix_transform_point"
end
-
-(** {3 Scaled Fonts API} *)
-
-(** Scaled fonts functions *)
-module Scaled_Font : sig
-type -'a t
-
-external create : ([>`Any] as 'a) font_face -> matrix -> matrix -> 'a t = "ml_cairo_scaled_font_create"
-external font_extents : [> `Any] t -> font_extents = "ml_cairo_scaled_font_extents"
-external glyph_extents : [>`Any] t -> glyph array -> text_extents = "ml_cairo_scaled_font_glyph_extents"
-end
diff --git a/src/cairo_ft.ml b/src/cairo_ft.ml
index ad39356..3b27b59 100644
--- a/src/cairo_ft.ml
+++ b/src/cairo_ft.ml
@@ -19,7 +19,7 @@ external new_face : ft_library -> ?index:int -> string -> ft_face = "ml_FT_New_
external done_face : ft_face -> unit = "ml_FT_Done_Face"
type fc_pattern
-external fc_name_parse : string -> fc_pattern = "ml_FcNameParse"
+external fc_name_parse : ?options:Cairo.Font_Options.t -> string -> fc_pattern = "ml_FcNameParse"
external fc_name_unparse : fc_pattern -> string = "ml_FcNameUnparse"
type font_face = [`Any|`FT] Cairo.font_face
diff --git a/src/cairo_ft.mli b/src/cairo_ft.mli
index 296def5..d10c399 100644
--- a/src/cairo_ft.mli
+++ b/src/cairo_ft.mli
@@ -21,8 +21,12 @@ external new_face : ft_library -> ?index:int -> string -> ft_face
external done_face : ft_face -> unit = "ml_FT_Done_Face"
type fc_pattern
-external fc_name_parse : string -> fc_pattern = "ml_FcNameParse"
-(** this is a hack: this actually calls FcNameParse, FcConfigSubstitute,
+external fc_name_parse :
+ ?options:Cairo.Font_Options.t ->
+ string -> fc_pattern = "ml_FcNameParse"
+(** this is a hack: this actually calls
+ FcNameParse, FcConfigSubstitute,
+ cairo_ft_font_options_substitute,
FcDefaultSubstitute and FcFontMatch *)
external fc_name_unparse : fc_pattern -> string = "ml_FcNameUnparse"
diff --git a/src/cairo_lablgtk.ml b/src/cairo_lablgtk.ml
index c2857fd..07fd04a 100644
--- a/src/cairo_lablgtk.ml
+++ b/src/cairo_lablgtk.ml
@@ -13,3 +13,7 @@ external shuffle_pixels : GdkPixbuf.pixbuf -> unit = "ml_cairo_lablgtk_shuffle_
external surface_create : [> `drawable] Gobject.obj -> surface = "ml_cairo_xlib_surface_create"
external surface_set_size : [> `Xlib] Cairo.surface -> int -> int -> unit = "ml_cairo_xlib_surface_set_size"
+external surface_set_drawable :
+ [> `Xlib] Cairo.surface ->
+ [> `drawable] Gobject.obj ->
+ int -> int -> unit = "ml_cairo_xlib_surface_set_drawable"
diff --git a/src/cairo_lablgtk.mli b/src/cairo_lablgtk.mli
index 7d77839..be85d38 100644
--- a/src/cairo_lablgtk.mli
+++ b/src/cairo_lablgtk.mli
@@ -15,3 +15,7 @@ external shuffle_pixels : GdkPixbuf.pixbuf -> unit = "ml_cairo_lablgtk_shuffle_
external surface_create : [> `drawable] Gobject.obj -> surface = "ml_cairo_xlib_surface_create"
external surface_set_size : [> `Xlib] Cairo.surface -> int -> int -> unit = "ml_cairo_xlib_surface_set_size"
+external surface_set_drawable :
+ [> `Xlib] Cairo.surface ->
+ [> `drawable] Gobject.obj ->
+ int -> int -> unit = "ml_cairo_xlib_surface_set_drawable"
diff --git a/src/ml_cairo.c b/src/ml_cairo.c
index e83ec97..33b6972 100644
--- a/src/ml_cairo.c
+++ b/src/ml_cairo.c
@@ -313,6 +313,9 @@ ml_cairo_get_font_matrix (value v_cr)
#endif
}
+wML_1_cairo (set_font_options, cairo_font_options_t_val)
+wML_1_cairo (get_font_options, cairo_font_options_t_val)
+
wML_1_cairo(show_text, String_val)
cairo_glyph_t *
diff --git a/src/ml_cairo.h b/src/ml_cairo.h
index c3c2309..25a44f7 100644
--- a/src/ml_cairo.h
+++ b/src/ml_cairo.h
@@ -43,6 +43,9 @@ value Val_cairo_font_face_t (cairo_font_face_t *);
#define cairo_scaled_font_t_val(v) wPointer_val(cairo_scaled_font_t, v)
value Val_cairo_scaled_font_t (cairo_scaled_font_t *);
+#define cairo_font_options_t_val(v) wPointer_val(cairo_font_options_t, v)
+value Val_cairo_font_options_t (cairo_font_options_t *);
+
/* cairo_matrix */
#ifdef ARCH_ALIGN_DOUBLE
void ml_convert_cairo_matrix_in (value, cairo_matrix_t *);
@@ -63,7 +66,11 @@ value Val_cairo_text_extents (cairo_text_extents_t *);
void ml_cairo_treat_status (cairo_status_t) Noreturn;
#define cairo_treat_status(s) if (s != CAIRO_STATUS_SUCCESS) ml_cairo_treat_status (s)
#define check_cairo_status(cr) cairo_treat_status (cairo_status (cairo_t_val (cr)))
+#define check_surface_status(cr) cairo_treat_status (cairo_surface_status (cairo_surface_t_val (cr)))
#define check_pattern_status(cr) cairo_treat_status (cairo_pattern_status (cairo_pattern_t_val (cr)))
+#define check_font_face_status(cr) cairo_treat_status (cairo_font_face_status (cairo_font_face_t_val (cr)))
+#define check_scaled_font_status(cr) cairo_treat_status (cairo_scaled_font_status (cairo_scaled_font_t_val (cr)))
+#define check_font_options_status(cr) cairo_treat_status (cairo_font_options_status (cairo_font_options_t_val (cr)))
#define report_null_pointer() ml_cairo_treat_status (CAIRO_STATUS_NULL_POINTER)
/* stream callbacks */
diff --git a/src/ml_cairo_font.c b/src/ml_cairo_font.c
index 587362f..ac715de 100644
--- a/src/ml_cairo_font.c
+++ b/src/ml_cairo_font.c
@@ -12,24 +12,49 @@ wMake_Val_final_pointer(cairo_font_face_t, cairo_font_face_destroy, 0)
wMake_Val_final_pointer(cairo_scaled_font_t, cairo_scaled_font_destroy, 0)
+wMake_Val_final_pointer(cairo_font_options_t, cairo_font_options_destroy, 0)
+/* XXX: could be using cairo_font_options_equal and cairo_font_options_hash here ... */
+
/* font_face_reference */
/* font_face_destroy */
/* font_face_get_user_data */
/* font_face_set_user_data */
CAMLprim value
-ml_cairo_scaled_font_create (value f, value fmat, value ctm)
+ml_cairo_font_options_create (value unit)
+{
+ cairo_font_options_t *o = cairo_font_options_create();
+ cairo_treat_status (cairo_font_options_status (o));
+ return Val_cairo_font_options_t (o);
+}
+
+wML_2(cairo_font_options_merge, cairo_font_options_t_val, cairo_font_options_t_val, Unit)
+wML_2(cairo_font_options_set_antialias, cairo_font_options_t_val, Long_val, Unit)
+wML_1(cairo_font_options_get_antialias, cairo_font_options_t_val, Val_long)
+wML_2(cairo_font_options_set_subpixel_order, cairo_font_options_t_val, Long_val, Unit)
+wML_1(cairo_font_options_get_subpixel_order, cairo_font_options_t_val, Val_long)
+wML_2(cairo_font_options_set_hint_style, cairo_font_options_t_val, Long_val, Unit)
+wML_1(cairo_font_options_get_hint_style, cairo_font_options_t_val, Val_long)
+wML_2(cairo_font_options_set_hint_metrics, cairo_font_options_t_val, Long_val, Unit)
+wML_1(cairo_font_options_get_hint_metrics, cairo_font_options_t_val, Val_long)
+
+
+CAMLprim value
+ml_cairo_scaled_font_create (value f, value fmat, value ctm, value fo)
{
cairo_scaled_font_t *sf;
#ifndef ARCH_ALIGN_DOUBLE
sf = cairo_scaled_font_create (cairo_font_face_t_val (f),
cairo_matrix_t_val (fmat),
- cairo_matrix_t_val (ctm));
+ cairo_matrix_t_val (ctm),
+ cairo_font_options_t_val (fo));
#else
cairo_matrix_t c_fmat, c_ctm;
ml_convert_cairo_matrix_in (fmat, &c_fmat);
ml_convert_cairo_matrix_in (ctm, &c_ctm);
- sf = cairo_scaled_font_create (cairo_font_face_t_val (f), &c_fmat, &c_ctm);
+ sf = cairo_scaled_font_create (cairo_font_face_t_val (f),
+ &c_fmat, &c_ctm,
+ cairo_font_options_t_val (fo));
#endif
return Val_cairo_scaled_font_t (sf);
}
@@ -40,10 +65,9 @@ ml_cairo_scaled_font_create (value f, value fmat, value ctm)
CAMLprim value
ml_cairo_scaled_font_extents (value sf)
{
- cairo_status_t status;
cairo_font_extents_t e;
- status = cairo_scaled_font_extents (cairo_scaled_font_t_val (sf), &e);
- cairo_treat_status (status);
+ cairo_scaled_font_extents (cairo_scaled_font_t_val (sf), &e);
+ cairo_treat_status (cairo_scaled_font_status (cairo_scaled_font_t_val (sf)));
return Val_cairo_font_extents (&e);
}
diff --git a/src/ml_cairo_ft.c b/src/ml_cairo_ft.c
index cbb955f..916817a 100644
--- a/src/ml_cairo_ft.c
+++ b/src/ml_cairo_ft.c
@@ -82,12 +82,16 @@ wMake_Val_final_pointer (FcPattern, FcPatternDestroy, 10)
#define UString_val(v) ((unsigned char *) (v))
CAMLprim value
-ml_FcNameParse (value s)
+ml_FcNameParse (value fo, value s)
{
FcPattern *p1, *p2;
FcResult res;
p1 = FcNameParse (UString_val(s));
FcConfigSubstitute (NULL, p1, FcMatchPattern);
+ if (Is_block (fo))
+ {
+ cairo_ft_font_options_substitute (cairo_font_options_t_val (Field (fo, 0)), p1);
+ }
FcDefaultSubstitute (p1);
p2 = FcFontMatch (NULL, p1, &res);
FcPatternDestroy (p1);
diff --git a/src/ml_cairo_lablgtk.c b/src/ml_cairo_lablgtk.c
index 25b0d27..2d174de 100644
--- a/src/ml_cairo_lablgtk.c
+++ b/src/ml_cairo_lablgtk.c
@@ -78,47 +78,71 @@ ml_cairo_lablgtk_shuffle_pixels (value pb)
#if CAIRO_HAS_XLIB_SURFACE
+/* copied from pycairo, who got it from GTK+ */
+static cairo_surface_t *
+ml_gdk_cairo_surface_create (GdkDrawable *target)
+{
+ int width, height;
+ int x_off=0, y_off=0;
+ cairo_surface_t *surface;
+ GdkDrawable *drawable = target;
+ GdkVisual *visual;
+
+ if (GDK_IS_WINDOW(target)) {
+ /* query the window's backbuffer if it has one */
+ GdkWindow *window = GDK_WINDOW(target);
+ gdk_window_get_internal_paint_info (window,
+ &drawable, &x_off, &y_off);
+ }
+ visual = gdk_drawable_get_visual (drawable);
+ gdk_drawable_get_size (drawable, &width, &height);
+
+ if (visual) {
+ surface = cairo_xlib_surface_create (GDK_DRAWABLE_XDISPLAY (drawable),
+ GDK_DRAWABLE_XID (drawable),
+ GDK_VISUAL_XVISUAL (visual),
+ width, height);
+ } else if (gdk_drawable_get_depth (drawable) == 1) {
+ surface = cairo_xlib_surface_create_for_bitmap
+ (GDK_PIXMAP_XDISPLAY (drawable),
+ GDK_PIXMAP_XID (drawable),
+ GDK_SCREEN_XSCREEN (gdk_drawable_get_screen (drawable)),
+ width, height);
+ } else {
+ g_warning ("Using Cairo rendering requires the drawable argument to\n"
+ "have a specified colormap. All windows have a colormap,\n"
+ "however, pixmaps only have colormap by default if they\n"
+ "were created with a non-NULL window argument. Otherwise\n"
+ "a colormap must be set on them with "
+ "gdk_drawable_set_colormap");
+ return NULL;
+ }
+ cairo_surface_set_device_offset (surface, -x_off, -y_off);
+ return surface;
+}
+
CAMLprim value
ml_cairo_xlib_surface_create (value d)
{
- cairo_surface_t *surface;
- gint width, height;
- GdkDrawable *drawable = GdkDrawable_val(d);
- GdkVisual *visual = gdk_drawable_get_visual (drawable);
-
- gdk_drawable_get_size (drawable, &width, &height);
-
- if (visual)
- surface = cairo_xlib_surface_create (GDK_DRAWABLE_XDISPLAY (drawable),
- GDK_DRAWABLE_XID (drawable),
- GDK_VISUAL_XVISUAL (visual),
- width, height);
- else if (gdk_drawable_get_depth (drawable) == 1)
- surface =
- cairo_xlib_surface_create_for_bitmap (GDK_PIXMAP_XDISPLAY (drawable),
- GDK_PIXMAP_XID (drawable),
- width, height);
- else {
- g_warning ("Using Cairo rendering requires the drawable argument to\n"
- "have a specified colormap. All windows have a colormap,\n"
- "however, pixmaps only have colormap by default if they\n"
- "were created with a non-NULL window argument. Otherwise\n"
- "a colormap must be set on them with "
- "gdk_drawable_set_colormap");
- surface = NULL;
- }
-
- if (surface != NULL)
- ml_cairo_surface_set_image_data (surface, d);
-
- return Val_cairo_surface_t (surface);
+ return Val_cairo_surface_t (ml_gdk_cairo_surface_create (GdkDrawable_val(d)));
}
ML_3 (cairo_xlib_surface_set_size, cairo_surface_t_val, Int_val, Int_val, Unit)
+CAMLprim value
+ml_cairo_xlib_surface_set_drawable (value s, value d, value w, value h)
+{
+ cairo_xlib_surface_set_drawable (cairo_surface_t_val (s),
+ GDK_DRAWABLE_XID (GdkDrawable_val (d)),
+ Int_val (w),
+ Int_val (h));
+ return Val_unit;
+}
+
#else
Cairo_Unsupported(cairo_xlib_surface_create, "Xlib backend not supported");
Cairo_Unsupported(cairo_xlib_surface_set_size, "Xlib backend not supported");
+Cairo_Unsupported(cairo_xlib_surface_set_drawable, "Xlib backend not supported");
#endif /* CAIRO_HAS_XLIB_SURFACE */
diff --git a/src/ml_cairo_status.c b/src/ml_cairo_status.c
index 86aa4cc..1863ed5 100644
--- a/src/ml_cairo_status.c
+++ b/src/ml_cairo_status.c
@@ -9,7 +9,11 @@
#include "ml_cairo.h"
wML_1 (cairo_status, cairo_t_val, Val_int)
+wML_1 (cairo_surface_status, cairo_surface_t_val, Val_int)
wML_1 (cairo_pattern_status, cairo_pattern_t_val, Val_int)
+wML_1 (cairo_font_face_status, cairo_font_face_t_val, Val_int)
+wML_1 (cairo_scaled_font_status, cairo_scaled_font_t_val, Val_int)
+wML_1 (cairo_font_options_status, cairo_font_options_t_val, Val_int)
wML_1 (cairo_status_to_string, Int_val, caml_copy_string)
diff --git a/src/ml_cairo_surface.c b/src/ml_cairo_surface.c
index 26b55d0..493d76d 100644
--- a/src/ml_cairo_surface.c
+++ b/src/ml_cairo_surface.c
@@ -32,9 +32,8 @@ wML_4(cairo_surface_create_similar, \
CAMLprim value
ml_cairo_surface_finish (value surf)
{
- cairo_status_t s;
- s = cairo_surface_finish (cairo_surface_t_val (surf));
- cairo_treat_status (s);
+ cairo_surface_finish (cairo_surface_t_val (surf));
+ check_surface_status (surf);
return Val_unit;
}
@@ -86,4 +85,6 @@ ml_cairo_surface_set_image_data (cairo_surface_t *surf, value v)
/* surface_get_user_data */
+wML_2(cairo_surface_get_font_options, cairo_surface_t_val, cairo_font_options_t_val, Unit)
+
wML_3(cairo_surface_set_device_offset, cairo_surface_t_val, Double_val, Double_val, Unit)
diff --git a/test/Makefile b/test/Makefile
index af59a38..bc43bbc 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -36,10 +36,10 @@ spline : spline.ml
$(OCAMLOPT) -w s -o $@ -I ../src -I $(LABLGTKDIR) lablgtk.cmxa cairo.cmxa cairo_lablgtk.cmxa gtkInit.cmx $^
basket : basket.ml
- $(OCAMLOPT) -o $@ -I ../src -I $(LABLGTKDIR) bigarray.cmxa cairo.cmxa $^
+ $(OCAMLOPT) -o $@ -I ../src bigarray.cmxa cairo.cmxa $^
basket.b : basket.ml
- $(OCAMLC) -g -o $@ -I ../src -I $(LABLGTKDIR) bigarray.cma cairo.cma $^
+ $(OCAMLC) -g -o $@ -I ../src bigarray.cma cairo.cma $^
knockout : knockout.ml
$(OCAMLOPT) -o $@ -I ../src -I $(LABLGTKDIR) cairo.cmxa lablgtk.cmxa cairo_lablgtk.cmxa gtkInit.cmx $^