From: <hez...@us...> - 2010-09-18 18:44:03
|
Revision: 11191 http://plplot.svn.sourceforge.net/plplot/?rev=11191&view=rev Author: hezekiahcarty Date: 2010-09-18 18:43:57 +0000 (Sat, 18 Sep 2010) Log Message: ----------- Add ?pre parameter to OCaml Plcairo initialization This allows a user to specify a function which should be called before the plot initializes. It can be used, for example, to set the plot background color or to parse and apply PLplot-related command line arguments. Modified Paths: -------------- trunk/bindings/ocaml/plcairo/plcairo.ml trunk/bindings/ocaml/plcairo/plcairo.mli Modified: trunk/bindings/ocaml/plcairo/plcairo.ml =================================================================== --- trunk/bindings/ocaml/plcairo/plcairo.ml 2010-09-16 17:44:09 UTC (rev 11190) +++ trunk/bindings/ocaml/plcairo/plcairo.ml 2010-09-18 18:43:57 UTC (rev 11191) @@ -1,5 +1,5 @@ (* -Copyright 2008, 2009 Hezekiah M. Carty +Copyright 2008, 2009, 2010 Hezekiah M. Carty This file is part of PLplot. @@ -22,6 +22,23 @@ open Plplot open Printf +module Option = struct + let may f o = + match o with + | Some x -> f x + | None -> () + + let default x_default o = + match o with + | Some x -> x + | None -> x_default + + let map_default f x_default o = + match o with + | Some x -> f x + | None -> x_default +end + (** A record to keep track of the Cairo surface and context information *) type ('a, 'b) t = { width : float; (** Width in device units *) @@ -183,9 +200,9 @@ filename, Cairo.image_surface_create Cairo.FORMAT_ARGB32 ~width ~height -(** [plinit_cairo ?filename ?clear (width, height) init] creates a Cairo +(** [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) +let plinit_cairo ?filename ?(clear = false) ?pre (width, height) (init : ('a, 'b) plcairo_sfc_t) = let file, sfc = init ~width ~height filename in let context = Cairo.create sfc in @@ -194,6 +211,7 @@ let new_stream = plmkstrm () in plsdev "extcairo"; plsetopt "geometry" (sprintf "%dx%d" width height); + Option.may (fun f -> f ()) pre; plinit (); (* Associate our new Cairo context with the PLplot stream. *) plset_cairo_context context; Modified: trunk/bindings/ocaml/plcairo/plcairo.mli =================================================================== --- trunk/bindings/ocaml/plcairo/plcairo.mli 2010-09-16 17:44:09 UTC (rev 11190) +++ trunk/bindings/ocaml/plcairo/plcairo.mli 2010-09-18 18:43:57 UTC (rev 11191) @@ -1,3 +1,22 @@ +(* +Copyright 2008, 2009, 2010 Hezekiah M. Carty + +This file is part of PLplot. + +PLplot is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +PLplot is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with PLplot. If not, see <http://www.gnu.org/licenses/>. +*) + (** A record to keep track of the Cairo surface and context information *) type ('a, 'b) t @@ -57,11 +76,12 @@ val plimagecairo : (string, [ `Any | `Image ]) plcairo_sfc_t val plimagecairo_rgba : (string, [ `Any | `Image ]) plcairo_sfc_t -(** [plinit_cairo ?filename ?clear (width, height) init] creates a Cairo +(** [plinit_cairo ?filename ?clear ?pre (width, height) init] creates a Cairo context and associates it with a new PLplot stream. *) val plinit_cairo : ?filename:string -> ?clear:bool -> + ?pre:(unit -> unit) -> int * int -> ('a, [> `Any ] as 'b) plcairo_sfc_t -> ('b, 'a) t (** [plcairo_make_active t] sets PLplot to using the plot stream associated This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |