From: <hez...@us...> - 2014-07-03 14:46:22
|
Revision: 13134 http://sourceforge.net/p/plplot/code/13134 Author: hezekiahcarty Date: 2014-07-03 14:46:13 +0000 (Thu, 03 Jul 2014) Log Message: ----------- Switch to a different OCaml Cairo binding ("cairo2" in opam) This is a more actively maintained binding to the Cairo library. It is unfortunately not packaged for Debian at this time so interested users would need to install the library through opam. opam is generally the recommended way to install and manage OCaml libraries (this cpan, pip, etc) so this isn't a particularly serious limitation. Modified Paths: -------------- trunk/bindings/ocaml/plcairo/CMakeLists.txt trunk/bindings/ocaml/plcairo/plcairo.ml trunk/bindings/ocaml/plcairo/plcairo.mli trunk/cmake/modules/ocaml.cmake trunk/examples/ocaml/CMakeLists.txt trunk/examples/ocaml/xgtk_interface.ml Modified: trunk/bindings/ocaml/plcairo/CMakeLists.txt =================================================================== --- trunk/bindings/ocaml/plcairo/CMakeLists.txt 2014-07-03 14:40:58 UTC (rev 13133) +++ trunk/bindings/ocaml/plcairo/CMakeLists.txt 2014-07-03 14:46:13 UTC (rev 13134) @@ -56,7 +56,7 @@ ${CMAKE_CURRENT_BINARY_DIR}/plcairo.cmi # ocamlc *.mli source file must be in ${CMAKE_CURRENT_BINARY_DIR}. COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/plcairo.mli ${CMAKE_CURRENT_BINARY_DIR}/plcairo.mli - COMMAND ${OCAMLFIND} ocamlc -package cairo -c ${CMAKE_CURRENT_BINARY_DIR}/plcairo.mli + COMMAND ${OCAMLFIND} ocamlc -package cairo2 -c ${CMAKE_CURRENT_BINARY_DIR}/plcairo.mli DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/plcairo.mli WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} @@ -74,7 +74,7 @@ # ocamlc and ocamlopt *.ml source file must be in # ${CMAKE_CURRENT_BINARY_DIR}. COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/plcairo.ml ${CMAKE_CURRENT_BINARY_DIR}/plcairo.ml - COMMAND ${OCAMLFIND} ocamlc -package cairo -I ${PATH_TO_PLPLOT_CMA} plplot.cma -c ${CMAKE_CURRENT_BINARY_DIR}/plcairo.ml + COMMAND ${OCAMLFIND} ocamlc -package cairo2 -I ${PATH_TO_PLPLOT_CMA} plplot.cma -c ${CMAKE_CURRENT_BINARY_DIR}/plcairo.ml DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/plcairo.ml ${CMAKE_CURRENT_BINARY_DIR}/plcairo.cmi @@ -118,7 +118,7 @@ # ocamlc and ocamlopt *.ml source file must be in # ${CMAKE_CURRENT_BINARY_DIR}. COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/plcairo.ml ${CMAKE_CURRENT_BINARY_DIR}/plcairo.ml - COMMAND ${OCAMLFIND} ocamlopt -package cairo -I ${PATH_TO_PLPLOT_CMXA} -c ${CMAKE_CURRENT_BINARY_DIR}/plcairo.ml + COMMAND ${OCAMLFIND} ocamlopt -package cairo2 -I ${PATH_TO_PLPLOT_CMXA} -c ${CMAKE_CURRENT_BINARY_DIR}/plcairo.ml DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/plcairo.ml ${CMAKE_CURRENT_BINARY_DIR}/plcairo.cmi @@ -193,7 +193,7 @@ # comments in the source file. Source can be a .ml or a .mli. add_custom_command( OUTPUT ${OCAMLDOC_FILES} - COMMAND ${OCAMLFIND} doc -package cairo -html ${CMAKE_CURRENT_SOURCE_DIR}/plcairo.mli + COMMAND ${OCAMLFIND} doc -package cairo2 -html ${CMAKE_CURRENT_SOURCE_DIR}/plcairo.mli DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/plcairo.mli WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} Modified: trunk/bindings/ocaml/plcairo/plcairo.ml =================================================================== --- trunk/bindings/ocaml/plcairo/plcairo.ml 2014-07-03 14:40:58 UTC (rev 13133) +++ trunk/bindings/ocaml/plcairo/plcairo.ml 2014-07-03 14:46:13 UTC (rev 13134) @@ -40,22 +40,22 @@ end (** A record to keep track of the Cairo surface and context information *) -type ('a, 'b) t = { +type 'a t = { width : float; (** Width in device units *) height : float; (** Height in device units *) - surface : 'a Cairo.surface; (** Cairo surface to plot to *) - context : Cairo.t; (** Cairo context to plot to *) - file : 'b option; (** An optional file name or stream for the plot output *) + surface : Cairo.Surface.t; (** Cairo surface to plot to *) + context : Cairo.context; (** Cairo context to plot to *) + file : 'a option; (** An optional file name or stream for the plot output *) clear : bool; (** Should each new page be cleared? *) plstream : int; (** PLplot stream number associated with this plot *) } (** Types of Cairo surfaces available for {!init}. *) -type ('a, 'b) plcairo_sfc_t = - width:int -> height:int -> string option -> 'a option * 'b Cairo.surface +type 'a plcairo_sfc_t = + width:int -> height:int -> string option -> 'a option * Cairo.Surface.t (** Provide PLplot with a Cairo context to plot on. *) -external plset_cairo_context : Cairo.t -> unit = "ml_set_plplot_cairo_context" +external plset_cairo_context : Cairo.context -> unit = "ml_set_plplot_cairo_context" (** Get the various components of a {!t} instance *) let plget_dims t = t.width, t.height @@ -66,7 +66,7 @@ (** [plblit_to_cairo ?xoff ?yoff ?scale_by plcairo dest] *) let plblit_to_cairo ?(xoff = 0.0) ?(yoff = 0.0) ?scale_by t dest = - let sx, sy = + let x, y = match scale_by with | None -> 1.0, 1.0 | Some scale -> ( @@ -78,7 +78,7 @@ in Cairo.save dest; begin - Cairo.scale ~sx ~sy dest; + Cairo.scale ~x ~y dest; Cairo.set_source_surface dest t.surface xoff yoff; Cairo.paint dest; end; @@ -96,8 +96,8 @@ surface. Leave the background transparent, so only the plotted image is transfered over to the main plot surface. *) let img_sfc = - Cairo.image_surface_create - Cairo.FORMAT_ARGB32 + Cairo.Image.create + Cairo.Image.ARGB32 ~width:(int_of_float t.width) ~height:(int_of_float t.height) in @@ -115,11 +115,7 @@ f (); (* Blit the raster image on to the main plot surface *) Cairo.set_source_surface t.context img_sfc 0.0 0.0; - let () = - match alpha with - | None -> Cairo.paint t.context - | Some a -> Cairo.paint_with_alpha t.context a - in + Cairo.paint ?alpha t.context; (* Now set PLplot back to using the proper plot context. *) plset_cairo_context t.context; Cairo.set_matrix t.context t_matrix; @@ -177,9 +173,10 @@ | None -> raise (Invalid_argument "plpscairo needs a filename") in Some outfile, - Cairo_ps.surface_create_for_channel outfile - ~width_in_points:(float_of_int width) - ~height_in_points:(float_of_int height) + Cairo.PS.create_for_stream + ~output:(fun bytes -> output_string outfile bytes) + ~width:(float_of_int width) + ~height:(float_of_int height) let plpdfcairo ~width ~height filename = let outfile = @@ -188,22 +185,23 @@ | None -> raise (Invalid_argument "plpdfcairo needs a filename") in Some outfile, - Cairo_pdf.surface_create_for_channel outfile - ~width_in_points:(float_of_int width) - ~height_in_points:(float_of_int height) + Cairo.PDF.create_for_stream + ~output:(fun bytes -> output_string outfile bytes) + ~width:(float_of_int width) + ~height:(float_of_int height) let plimagecairo ~width ~height (filename : string option) = filename, - Cairo.image_surface_create Cairo.FORMAT_RGB24 ~width ~height + Cairo.Image.create Cairo.Image.RGB24 ~width ~height let plimagecairo_rgba ~width ~height (filename : string option) = filename, - Cairo.image_surface_create Cairo.FORMAT_ARGB32 ~width ~height + Cairo.Image.create Cairo.Image.ARGB32 ~width ~height (** [plinit_cairo ?filename ?clear ?pre (width, height) init] creates a Cairo context and associates it with a new PLplot stream. *) let plinit_cairo ?filename ?(clear = false) ?pre - (width, height) (init : ('a, 'b) plcairo_sfc_t) = + (width, height) (init : 'a plcairo_sfc_t) = let file, sfc = init ~width ~height filename in let context = Cairo.create sfc in (* Associate the Cairo context with PLplot, then initialize PLplot *) @@ -238,7 +236,7 @@ (** [plcairo_finish t] calls [Cairo.surface_finish] on the Cairo surface associated with [t]. *) let plcairo_finish t = - Cairo.surface_finish t.surface; + Cairo.Surface.finish t.surface; () (** [plsave_cairo_image ?filename t] saves the plot surface in [t] @@ -257,7 +255,7 @@ | None -> invalid_arg "No filename associated with this plot" ) in - Cairo_png.surface_write_to_file t.surface output_filename; + Cairo.PNG.write t.surface output_filename; () (** [plsave_cairo ?filename t] is like {!plsave_cairo_image} but for Modified: trunk/bindings/ocaml/plcairo/plcairo.mli =================================================================== --- trunk/bindings/ocaml/plcairo/plcairo.mli 2014-07-03 14:40:58 UTC (rev 13133) +++ trunk/bindings/ocaml/plcairo/plcairo.mli 2014-07-03 14:46:13 UTC (rev 13134) @@ -18,29 +18,29 @@ *) (** A record to keep track of the Cairo surface and context information *) -type ('a, 'b) t +type 'a t (** Types of Cairo surfaces available for {!plinit_cairo}. *) -type ('a, 'b) plcairo_sfc_t +type 'a plcairo_sfc_t (** Provide PLplot with a Cairo context to plot on. *) -external plset_cairo_context : Cairo.t -> unit +external plset_cairo_context : Cairo.context -> unit = "ml_set_plplot_cairo_context" (** Get the [(width, height)] of the surface in device units. *) -val plget_dims : ('a, 'b) t -> float * float +val plget_dims : 'a t -> float * float (** Get the Cairo surface associated with [t]. *) -val plget_surface : ('a, 'b) t -> 'a Cairo.surface +val plget_surface : 'a t -> Cairo.Surface.t (** Get the Cairo context associated with [t]. *) -val plget_context : ('a, 'b) t -> Cairo.t +val plget_context : 'a t -> Cairo.context (** Get the PLplot stream number associated with [t]. *) -val plget_stream : ('a, 'b) t -> int +val plget_stream : 'a t -> int (** Get the output (filename, output stream or nothing) associated with [t]. *) -val plget_output : ('a, 'b) t -> 'b option +val plget_output : 'a t -> 'a option (** [plblit_to_cairo ?xoff ?yoff ?scale_by plcairo dest] blits the contents of [plcairo] to [dest]. @@ -50,7 +50,7 @@ ?xoff:float -> ?yoff:float -> ?scale_by:[< `both of float * float | `height of float | `width of float ] -> - ([> `Any ], 'a) t -> Cairo.t -> unit + 'a t -> Cairo.context -> unit (** [plrasterize ?alpha t f] applies the plotting function [f ()] to [t], with the difference that the output will be rasterized for all plot @@ -61,20 +61,20 @@ Note that the plotting done by [f ()] will not be antialiased by default. *) val plrasterize : ?alpha:float -> - ?antialias:Cairo.antialias -> ('a, 'b) t -> (unit -> 'c) -> unit + ?antialias:Cairo.antialias -> 'a t -> (unit -> 'b) -> unit (** [plcairo_new_page t] will advance the Cairo context associated with [t] to a new page, for devices which support this. *) -val plcairo_new_page : ('a, 'b) t -> unit +val plcairo_new_page : 'a t -> unit (** The following 4 functions provide a relatively simple way to setup an appropriate Cairo surface for use with this library and the extcairo driver. They should be passed as the [init] argument to the [plinit_cairo] function.*) -val plpscairo : (out_channel, [ `Any | `PS ]) plcairo_sfc_t -val plpdfcairo : (out_channel, [ `Any | `PDF ]) plcairo_sfc_t -val plimagecairo : (string, [ `Any | `Image ]) plcairo_sfc_t -val plimagecairo_rgba : (string, [ `Any | `Image ]) plcairo_sfc_t +val plpscairo : out_channel plcairo_sfc_t +val plpdfcairo : out_channel plcairo_sfc_t +val plimagecairo : string plcairo_sfc_t +val plimagecairo_rgba : string plcairo_sfc_t (** [plinit_cairo ?filename ?clear ?pre (width, height) init] creates a Cairo context and associates it with a new PLplot stream. *) @@ -82,15 +82,15 @@ ?filename:string -> ?clear:bool -> ?pre:(unit -> unit) -> - int * int -> ('a, [> `Any ] as 'b) plcairo_sfc_t -> ('b, 'a) t + int * int -> 'a plcairo_sfc_t -> 'a t (** [plcairo_make_active t] sets PLplot to using the plot stream associated with [t] the active plot stream. *) -val plcairo_make_active : ('a, 'b) t -> unit +val plcairo_make_active : 'a t -> unit (** [plcairo_finish t] calls [Cairo.surface_finish] on the Cairo surface associated with [t]. *) -val plcairo_finish : ([> `Any ], 'a) t -> unit +val plcairo_finish : 'a t -> unit (** [plsave_cairo_image ?filename t] saves the plot surface in [t] as a png to its associated file. If [filename] is given then the file is @@ -98,14 +98,14 @@ [Plplot.plend1] should be called first or the plotting may not be complete! Raises [Invalid_argument "No filename associated with this plot"] if no filename is provided and [t] does not have a filename associated with it. *) -val plsave_cairo_image : ?filename:string -> ([> `Any ], string) t -> unit +val plsave_cairo_image : ?filename:string -> string t -> unit (** [plsave_cairo ?filename t] is like {!plsave_cairo_image} but for non-image surfaces. *) -val plsave_cairo : ([> `Any ], out_channel) t -> unit +val plsave_cairo : out_channel t -> unit (** NOTE: This function will almost definitely change in a future revision. [plcairo_copy_plot t driver filename] copies the plot stream from [t] to a new output stream, using the plot driver [driver], saving the output to [filename]. *) -val plcairo_copy_plot : ('a, 'b) t -> string -> string -> unit +val plcairo_copy_plot : 'a t -> string -> string -> unit Modified: trunk/cmake/modules/ocaml.cmake =================================================================== --- trunk/cmake/modules/ocaml.cmake 2014-07-03 14:40:58 UTC (rev 13133) +++ trunk/cmake/modules/ocaml.cmake 2014-07-03 14:46:13 UTC (rev 13134) @@ -200,7 +200,7 @@ set(text_cairo "module C = Cairo") file(WRITE ${CMAKE_BINARY_DIR}/test_cairo.ml ${text_cairo}) execute_process( - COMMAND ${OCAMLFIND} c -package cairo -linkpkg test_cairo.ml -o test_cairo + COMMAND ${OCAMLFIND} c -package cairo2 -linkpkg test_cairo.ml -o test_cairo WORKING_DIRECTORY ${CMAKE_BINARY_DIR} RESULT_VARIABLE OCAML_HAS_CAIRO_RC OUTPUT_QUIET @@ -239,25 +239,25 @@ endif(OCAML_HAS_CAIRO) if(OCAML_HAS_CAIRO) - option(OCAML_HAS_GTK "OCaml has the cairo.lablgtk2 package" ON) + option(OCAML_HAS_GTK "OCaml has the cairo2.lablgtk2 package" ON) else(OCAML_HAS_CAIRO) message(STATUS "WARNING:" "Cairo OCaml library not found. Disabling lablgtk2 support") - set(OCAML_HAS_GTK OFF CACHE BOOL "OCaml has the cairo.lablgtk2 package" FORCE) + set(OCAML_HAS_GTK OFF CACHE BOOL "OCaml has the cairo2.lablgtk2 package" FORCE) endif(OCAML_HAS_CAIRO) if(DROP_GTK_PLUS_2_BUILDS) - set(OCAML_HAS_GTK OFF CACHE BOOL "OCaml has the cairo.lablgtk2 package" FORCE) + set(OCAML_HAS_GTK OFF CACHE BOOL "OCaml has the cairo2.lablgtk2 package" FORCE) endif(DROP_GTK_PLUS_2_BUILDS) if(OCAML_HAS_GTK) set(text_gtk "module G = Gtk - module C = Cairo_lablgtk" + module C = Cairo_gtk" ) file (WRITE ${CMAKE_BINARY_DIR}/test_gtk.ml ${text_gtk}) execute_process( - COMMAND ${OCAMLFIND} c -package cairo.lablgtk2 -linkpkg test_gtk.ml -o test_gtk + COMMAND ${OCAMLFIND} c -package cairo2.lablgtk2 -linkpkg test_gtk.ml -o test_gtk WORKING_DIRECTORY ${CMAKE_BINARY_DIR} RESULT_VARIABLE OCAML_HAS_GTK_RC OUTPUT_QUIET @@ -265,7 +265,7 @@ ) # non-zero return code indicates errors. if(OCAML_HAS_GTK_RC) - set(OCAML_HAS_GTK OFF CACHE BOOL "OCaml has the cairo.lablgtk2 package" FORCE) + set(OCAML_HAS_GTK OFF CACHE BOOL "OCaml has the cairo2.lablgtk2 package" FORCE) endif(OCAML_HAS_GTK_RC) endif(OCAML_HAS_GTK) @@ -279,11 +279,11 @@ message(STATUS "WARNING:" "ocamlfind not available. Disabling Plcairo module and lablgtk2 support") set(OCAML_HAS_CAIRO OFF CACHE BOOL "OCaml has the cairo package" FORCE) - set(OCAML_HAS_GTK OFF CACHE BOOL "OCaml has the cairo.lablgtk2 package" FORCE) + set(OCAML_HAS_GTK OFF CACHE BOOL "OCaml has the cairo2.lablgtk2 package" FORCE) endif(OCAMLFIND) else(ENABLE_ocaml) message(STATUS "WARNING:" "ENABLE_ocaml is OFF so disabling Plcairo module and lablgtk2 support") set(OCAML_HAS_CAIRO OFF CACHE BOOL "OCaml has the cairo package" FORCE) - set(OCAML_HAS_GTK OFF CACHE BOOL "OCaml has the cairo.lablgtk2 package" FORCE) + set(OCAML_HAS_GTK OFF CACHE BOOL "OCaml has the cairo2.lablgtk2 package" FORCE) endif(ENABLE_ocaml) Modified: trunk/examples/ocaml/CMakeLists.txt =================================================================== --- trunk/examples/ocaml/CMakeLists.txt 2014-07-03 14:40:58 UTC (rev 13133) +++ trunk/examples/ocaml/CMakeLists.txt 2014-07-03 14:46:13 UTC (rev 13134) @@ -254,7 +254,7 @@ add_custom_command( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${EXECUTABLE_NAME} COMMAND ${OCAMLFIND} ${ocaml_compiler} - -package cairo.lablgtk2 + -package cairo2.lablgtk2 -linkpkg -g -I ${I_OPTION_PLPLOT} Modified: trunk/examples/ocaml/xgtk_interface.ml =================================================================== --- trunk/examples/ocaml/xgtk_interface.ml 2014-07-03 14:40:58 UTC (rev 13133) +++ trunk/examples/ocaml/xgtk_interface.ml 2014-07-03 14:46:13 UTC (rev 13134) @@ -34,7 +34,7 @@ (** Get a Cairo context from the Gtk drawing area. *) let get_cairo w = - Cairo_lablgtk.create w#misc#window + Cairo_gtk.create w#misc#window (** Callback to redraw the plot contents. If the window is resized then the plot will be stretched to fit the new window dimensions. *) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |