[cairo-commit] cairo-ocaml/src svg_cairo.mli, NONE, 1.1 svg_cairo.ml, NONE, 1.1 ml_svg_cairo.c, NONE, 1.1 ml_cairo_wrappers.h, 1.6, 1.7 ml_cairo_ft.c, 1.2, 1.3 ml_cairo.c, 1.17, 1.18 Makefile, 1.8, 1.9

Olivier Andrieu commit at pdx.freedesktop.org
Tue Mar 1 14:19:54 PST 2005


Committed by: oandrieu

Update of /cvs/cairo/cairo-ocaml/src
In directory gabe:/tmp/cvs-serv25584/src

Modified Files:
	ml_cairo_wrappers.h ml_cairo_ft.c ml_cairo.c Makefile 
Added Files:
	svg_cairo.mli svg_cairo.ml ml_svg_cairo.c 
Log Message:
add libsvg-cairo bindings


--- NEW FILE: svg_cairo.mli ---
type status =
    NO_MEMORY
  | IO_ERROR
  | FILE_NOT_FOUND
  | INVALID_VALUE
  | INVALID_CALL
  | PARSE_ERROR
exception Error of status
val init : unit

type t

external create  : unit -> t = "ml_svg_cairo_create"

external parse        : t -> string -> unit = "ml_svg_cairo_parse"
external parse_string : t -> string -> unit = "ml_svg_cairo_parse_buffer"

external parse_chunk_begin : t -> unit = "ml_svg_cairo_parse_chunk_begin"
external parse_chunk       : t -> string -> unit = "ml_svg_cairo_parse_chunk"
external parse_chunk_end   : t -> unit = "ml_svg_cairo_parse_chunk_end"

external render : t -> Cairo.t -> unit = "ml_svg_cairo_render"

external set_viewport_dimenstion : t -> int -> int -> unit = "ml_svg_cairo_set_viewport_dimension"

external get_size  : t -> int * int = "ml_svg_cairo_get_size"

--- NEW FILE: svg_cairo.ml ---
type status =
    NO_MEMORY
  | IO_ERROR
  | FILE_NOT_FOUND
  | INVALID_VALUE
  | INVALID_CALL
  | PARSE_ERROR
exception Error of status
let init = Callback.register "svg_cairo_status_exn" (Error NO_MEMORY)

type t

external create  : unit -> t = "ml_svg_cairo_create"

external parse        : t -> string -> unit = "ml_svg_cairo_parse"
external parse_string : t -> string -> unit = "ml_svg_cairo_parse_buffer"

external parse_chunk_begin : t -> unit = "ml_svg_cairo_parse_chunk_begin"
external parse_chunk       : t -> string -> unit = "ml_svg_cairo_parse_chunk"
external parse_chunk_end   : t -> unit = "ml_svg_cairo_parse_chunk_end"

external render : t -> Cairo.t -> unit = "ml_svg_cairo_render"

external set_viewport_dimenstion : t -> int -> int -> unit = "ml_svg_cairo_set_viewport_dimension"

external get_size  : t -> int * int = "ml_svg_cairo_get_size"

--- NEW FILE: ml_svg_cairo.c ---
#include <caml/alloc.h>
#include <caml/memory.h>
#include <caml/fail.h>
#include <caml/callback.h>
#include <caml/custom.h>

#include <svg-cairo.h>

#define report_null_pointer failwith("null pointer")
#include "ml_cairo_wrappers.h"
#include "ml_cairo.h"

static value
ml_svg_cairo_status (svg_cairo_status_t s)
{
  static value *exn;
  if (s == SVG_CAIRO_STATUS_SUCCESS)
    return Val_unit;
  if (exn == NULL)
    {
      exn = caml_named_value ("svg_cairo_status_exn");
      if (exn == NULL)
	failwith ("Svg_cairo exception not registered");
    }
  raise_with_arg (*exn, Val_int (s - 1));
}

Make_Val_final_pointer (svg_cairo_t, Id, svg_cairo_destroy, 100)
#define svg_cairo_t_val(v) (svg_cairo_t *)Pointer_val(v)

CAMLprim value
ml_svg_cairo_create (value unit)
{
  svg_cairo_status_t status;
  svg_cairo_t *s;
  status = svg_cairo_create (&s);
  ml_svg_cairo_status (status);
  return Val_svg_cairo_t (s);
}

ML_2 (svg_cairo_parse, svg_cairo_t_val, String_val, ml_svg_cairo_status)

CAMLprim value
ml_svg_cairo_parse_buffer (value s, value b)
{
  return ml_svg_cairo_status (svg_cairo_parse_buffer (svg_cairo_t_val (s),
						      String_val (b),
						      string_length (b)));
}

ML_1 (svg_cairo_parse_chunk_begin, svg_cairo_t_val, ml_svg_cairo_status)
CAMLprim value
ml_svg_cairo_parse_chunk (value s, value b)
{
  return ml_svg_cairo_status (svg_cairo_parse_chunk (svg_cairo_t_val (s),
						     String_val (b),
						     string_length (b)));
}
ML_1 (svg_cairo_parse_chunk_end, svg_cairo_t_val, ml_svg_cairo_status)

ML_2 (svg_cairo_render, svg_cairo_t_val, cairo_t_val, ml_svg_cairo_status)
ML_3 (svg_cairo_set_viewport_dimension, svg_cairo_t_val, Unsigned_int_val, Unsigned_int_val, ml_svg_cairo_status)

CAMLprim value
ml_svg_cairo_get_size (value s)
{
  int w, h;
  value r;
  svg_cairo_get_size (svg_cairo_t_val (s), &w, &h);
  r = alloc_small (2, 0);
  Field (r, 0) = Val_int (w);
  Field (r, 1) = Val_int (h);
  return r;
}

Index: ml_cairo_wrappers.h
===================================================================
RCS file: /cvs/cairo/cairo-ocaml/src/ml_cairo_wrappers.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- ml_cairo_wrappers.h	1 Nov 2004 15:50:28 -0000	1.6
+++ ml_cairo_wrappers.h	1 Mar 2005 22:19:52 -0000	1.7
@@ -13,7 +13,8 @@
 value Val_##type (type *p) \
 { value ret; if (!p) report_null_pointer; \
   ret = alloc_custom (&ml_custom_##type, sizeof(value), adv, 1000); \
-  Field(ret,1) = (value) p; init(p); return ret; }
+  p = init(p); \
+  Field(ret,1) = Val_bp (p); return ret; }
 
 static inline value Val_ptr(void *p)
 {
@@ -29,9 +30,11 @@
 #define Double_array_length(v) (Wosize_val(v) / Double_wosize)
 
 #define Option_val(v,conv,def) (Is_long(v) ? def : conv(Field((v),0)))
+#define StringOption_val(v) Option_val(v, String_val, NULL)
 
 #define Ignore(x)
 #define Unit(x) ((x), Val_unit)
+#define Id(x) (x)
 
 #define Unsupported(fun) \
 CAMLprim value fun() { failwith("Unsupported backend"); return Val_unit; }

Index: ml_cairo_ft.c
===================================================================
RCS file: /cvs/cairo/cairo-ocaml/src/ml_cairo_ft.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- ml_cairo_ft.c	26 Jan 2005 00:54:15 -0000	1.2
+++ ml_cairo_ft.c	1 Mar 2005 22:19:52 -0000	1.3
@@ -73,7 +73,7 @@
 }
 
 /* minimal Fontconfig interface */
-Make_Val_final_pointer (FcPattern, Ignore, FcPatternDestroy, 10)
+Make_Val_final_pointer (FcPattern, Id, FcPatternDestroy, 10)
 #define FcPattern_val(v) (FcPattern *)Pointer_val(v)
 
 ML_1 (FcNameParse, String_val, Val_FcPattern)

Index: ml_cairo.c
===================================================================
RCS file: /cvs/cairo/cairo-ocaml/src/ml_cairo.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- ml_cairo.c	26 Jan 2005 00:55:19 -0000	1.17
+++ ml_cairo.c	1 Mar 2005 22:19:52 -0000	1.18
@@ -49,11 +49,11 @@
   return ret;
 }
 
-Make_Val_final_pointer(cairo_surface_t, Ignore, cairo_surface_destroy, 20)
+Make_Val_final_pointer(cairo_surface_t, Id, cairo_surface_destroy, 20)
 
-Make_Val_final_pointer(cairo_matrix_t, Ignore, cairo_matrix_destroy, 100)
+Make_Val_final_pointer(cairo_matrix_t, Id, cairo_matrix_destroy, 100)
 
-Make_Val_final_pointer(cairo_pattern_t, Ignore, cairo_pattern_destroy, 20)
+Make_Val_final_pointer(cairo_pattern_t, Id, cairo_pattern_destroy, 20)
 #define cairo_pattern_t_val(v) ((cairo_pattern_t *)Pointer_val(v))
 
 CAMLprim value
@@ -607,7 +607,7 @@
   return Val_unit;
 }
 
-Make_Val_final_pointer(cairo_font_t, Ignore, cairo_font_destroy, 20)
+Make_Val_final_pointer(cairo_font_t, Id, cairo_font_destroy, 20)
 
 static void
 cairo_glyph_t_val (cairo_glyph_t * _s, value _v)

Index: Makefile
===================================================================
RCS file: /cvs/cairo/cairo-ocaml/src/Makefile,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- Makefile	30 Jan 2005 16:25:32 -0000	1.8
+++ Makefile	1 Mar 2005 22:19:52 -0000	1.9
@@ -10,7 +10,9 @@
 TARGETS += gtkcairo
 endif
 endif
-
+ifdef LIBSVG_CAIRO_CFLAGS
+TARGETS += svgcairo
+endif
 all : $(TARGETS) $(if $(OCAMLOPT),opt)
 opt : $(addsuffix .opt,$(TARGETS))
 
@@ -20,6 +22,8 @@
 lablgtk.opt : cairo_lablgtk.cmxa dllmlcairo_lablgtk.so
 gtkcairo     : gtkcairo.cma  libmlgtkcairo.a
 gtkcairo.opt : gtkcairo.cmxa dllmlgtkcairo.so
+svgcairo     : svg_cairo.cma libmlsvgcairo.a
+svgcairo.opt : svg_cairo.cmxa dllmlsvgcairo.so
 
 cairo_SRC = cairo_channel.mli cairo_channel.ml cairo.mli cairo.ml \
             cairo_bigarray.mli cairo_bigarray.ml \
@@ -54,9 +58,19 @@
 libmlgtkcairo.a dllmlgtkcairo.so : $(call cobjs,$(gtkcairo_SRC))
 	$(OCAMLMKLIB) -o gtkcairo -oc mlgtkcairo $^ $(GTKCAIRO_LIBS)
 
+svgcairo_SRC = svg_cairo.mli svg_cairo.ml ml_svg_cairo.c
+
+svg_cairo.cma : $(call mlobjs,$(svgcairo_SRC))
+	$(OCAMLMKLIB) -o svg_cairo -oc mlsvgcairo $^ $(LIBSVG_CAIRO_LIBS)
+svg_cairo.cmxa : $(call mloptobjs,$(svgcairo_SRC))
+	$(OCAMLMKLIB) -o svg_cairo -oc mlsvgcairo $^ $(LIBSVG_CAIRO_LIBS)
+libmlsvgcairo.a dllmlsvgcairo.so : $(call cobjs,$(svgcairo_SRC))
+	$(OCAMLMKLIB) -o svg_cairo -oc mlsvgcairo $^ $(LIBSVG_CAIRO_LIBS)
+
 $(call cobjs,$(cairo_SRC))    : CPPFLAGS+=$(CAIRO_CFLAGS)
 $(call cobjs,$(lablgtk_SRC))  : CPPFLAGS+=$(GDK_CFLAGS) -I$(C_LABLGTKDIR)
 $(call cobjs,$(gtkcairo_SRC)) : CPPFLAGS+=$(GTKCAIRO_CFLAGS) -I$(C_LABLGTKDIR)
+$(call cobjs,$(svgcairo_SRC))  : CPPFLAGS+=$(LIBSVG_CAIRO_CFLAGS)
 $(call mlobjs,$(lablgtk_SRC))  : INCFLAGS=-I $(LABLGTKDIR)
 $(call mlobjs,$(gtkcairo_SRC)) : INCFLAGS=-I $(LABLGTKDIR)
 $(call mlintfs,$(lablgtk_SRC))  : INCFLAGS=-I $(LABLGTKDIR)
@@ -82,6 +96,9 @@
 DOCFILES += cairo_gtkcairo.mli
 endif
 endif
+ifdef LIBSVG_CAIRO_CFLAGS
+DOCFILES += svg_cairo.mli
+endif
 doc: $(DOCFILES:%.mli=%.cmi)
 	mkdir -p ../doc/html
 	ocamldoc -v -html -d ../doc/html -t Cairo-ocaml $(if $(LABLGTKDIR),-I $(LABLGTKDIR)) $(DOCFILES) 




More information about the cairo-commit mailing list