File: test_for_stream.ml

package info (click to toggle)
ocaml-cairo2 0.6.4%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 716 kB
  • sloc: ml: 2,955; ansic: 2,132; makefile: 24; sh: 17
file content (21 lines) | stat: -rw-r--r-- 623 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
open Printf

let make create fname =
  let fh = open_out fname in
  let surface = create (output_string fh) ~w:100. ~h:100. in
  let ctx = Cairo.create surface in

  Cairo.set_line_width ctx 1.;
  Cairo.move_to ctx 0. 0.;
  Cairo.line_to ctx 100. 100.;
  Cairo.stroke ctx;
  Cairo.Surface.finish surface; (* Important for the data to be written *)
  flush fh;
  close_out fh;
  printf "Wrote %S.\n" fname

let () =
  let tmp = Filename.get_temp_dir_name() in
  make Cairo.SVG.create_for_stream (Filename.concat tmp "cairo-test.svg");
  Gc.major();
  make Cairo.PDF.create_for_stream (Filename.concat tmp "cairo-test.pdf");