Giter Site home page Giter Site logo

chris00 / ocaml-cairo Goto Github PK

View Code? Open in Web Editor NEW
54.0 6.0 8.0 3.27 MB

Binding to Cairo, a 2D Vector Graphics Library.

License: GNU Lesser General Public License v3.0

Makefile 0.22% OCaml 63.00% C 36.78%
cairo ocaml stroke drawing tutorial cairo-drawing dune ocaml-bindings

ocaml-cairo's Introduction

Continuous Integration

OCaml interface to Cairo

This is an OCaml binding for the Cairo library, a 2D graphics library with support for multiple output devices.

You can read the API of Cairo, Cairo_gtk, and Cairo_pango online.

Prerequisites

You need the development files of Cairo (see the conf-cairo package) and the OCaml package lablgtk2 (in the OPAM package lablgtk).

Compilation & Installation

The easier way to install this library — once the prerequisites are set up — is to use opam:

opam install cairo2

If you would like to compile from the sources, install Dune

opam install dune

and do:

dune build @install

or just make. You can then install it with:

dune install

Examples

You can read a version of the Cairo tutorial using this module. The code of this tutorial is available in the examples/ directory. To compile it, just do

dune build @examples

All the examples below are available (with some comments) by clicking on images in the tutorial.

Basic examples

  • stroke.ml shows how to draw (stroke) a simple rectangle on a PNG surface.

  • stroke.ml shows how to fill a simple rectangle on a PNG surface.

  • showtext.ml illustrates how to select a font and draw some text on a PNG surface.

  • paint.ml shows how to paint the current source everywhere within the current clip region.

  • mask.ml shows how to apply a radial transparency mask on top of a linear gradient.

  • setsourcergba.ml produces

    Source RGBA

  • setsourcegradient.ml shows how to use radial and linear patterns. It generates:

    Gradient

  • path_close.ml shows how to draw a closed path. It produces the PNG:

    close path

  • textextents.ml displays graphically the various dimensions one can request about text. It generates the PNG:

    text

  • text_extents.ml exemplifies drawing consecutive UTF-8 strings in a PDF file. Some helping lines are also added to show the text extents.

  • tips_ellipse.ml shows the action of dilation on the line width and how to properly draw ellipses. It generates the PNG:

    ellipse

  • tips_letter.ml illustrates the wrong way of centering characters based on their individual extents:

    letters

    Instead, one should combine them with the font extents as shown in tips_font.ml to have:

    fonts

Examples generating the images of the tutorial

ocaml-cairo's People

Contributors

antegallya avatar bobot avatar chris00 avatar drup avatar hcarty avatar kit-ty-kate avatar thelema avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

ocaml-cairo's Issues

Finalization function for cairo context needed

I'm drawing to GTK drawing areas using cairo. All drawing is done via a cairo context created within the expose event handler. However, I have run into 2 problems (which seem to be Mac-specific):

  • When the window containing the drawing area is closed, the program always crashes at the following minor GC (SIGSEGV in some GDK quartz backend function called by cairo_surface_destroy).

  • When the window is resized, the exposed region of the drawing area is not updated at all. I have no idea why.

(On Windows and Linux everything looks fine.)

However I have found a workaround: perform GC manually in order to finalize the cairo object when the expose event handler is done with it. However, this is inefficient, since all that's needed is calling the finalizer of the cairo object, which is to my knowledge not possible in OCaml. So I think it might be necessary to add a finalization function that allows the user to explicitly destroy the cairo object.

If the cairo context used for drawing is created outside the event handler, the program does not crash, but exposed regions don't get updated.

I'm fairly new to GTK and cairo so please correct me if I get something wrong.

Quartz module ?

Is that supposed to be available on osx. It doesn't seem to be here.

> opam info cairo2 -fversion
0.4.6

Question: "cannot use mapped file"

Hi,

I'm currently playing around with using ocaml-cairo as the renderer for a toy GUI project and calling of_data32 I get the error that a mapped file cannot be used.

Why is this the case? Is it a fundamental limitation with the cairo library, or with the Bigarray representation or something else?

Fatal error: exception Invalid_argument("Cairo.Image.get_data: not created from a bigarray")

I get this error when the data was created by Tsdl.Sdl.lock_texture (which uses Ctypes.bigarray_of_ptr internally):

let (data : Cairo.Image.data8), stream_pitch =
      match Sdl.lock_texture stream None Bigarray.int8_unsigned with
      | Error (`Msg e) -> failwith e;
      | Ok r -> r in
let surface = Cairo.Image.(create_for_data8 data ARGB32) ~w ~h in
Cairo.Image.get_data8 surface

leads to

Fatal error: exception Invalid_argument("Cairo.Image.get_data: not created from a bigarray")

Maybe @dbuenzli has an idea?

crash on macOS catalina

codemap from pfff (github.com/aryx/pfff) crashes on Catalina.
Here is the assertion failing:

Assertion failed: (!x_link_empty_p(&s->stack)), function CGGStackRestore, file /BuildRoot/Library/Caches/com.apple.xbs/Sources/CoreGraphics/CoreGraphics-1348.12.4.3/CoreGraphics/Context/CGGStack.c, line 74.
abort trap: 6

Have you seen something like that before?

My application is also using lablgtk2.

We need better documentation of how to produce image files

I helped a beginner trying to do some simple graphic stuff in OCaml this week-end, and the attempt to use ocaml-cairo was a total usability disaster -- Graphics is now used instead. In this issue, I'm trying to list the hurdles met along the way because I think they could all be fixed.

  1. There are two OPAM packages for cairo, cairo and cairo2, and I have no clue which one to use for which reason. You should at least be explicit in the README of this project about which of those packages you are -- cairo2. Explaining the difference between the two projects could also be very helpful.
  2. The examples/ directory is a very good idea, but currently it is very hard to use for beginners. Navigation on github is not intuitive, and there is no description of what each example does beside the filename. It would help a lot to have a list of the examples and a short description of them on the web somewhere (possibly directly in the README), maybe also showing some of the images produced by each example (but that is more work; a list would be a very good first step).
  3. There is an absolute lack of information about how to actually produce an image file. What said beginner wanted is to write a program to render Sudoku grids as images. The most important documentation for this is a code snippet that draws a rectangle and writes it in a .png file. The subject of writing image files is not discussed at all in the tutorial, and this should absolutely be fixed. What we did is to pick an example randomly (curve_to), and change it to produce a PNG instead of a PDF. You may see where this is going. We replaced Cairo.PDF.create by Cairo.PNG.create, fixed the resulting typing error in the obvious way (Cairo.PNG.create does not take dimension parameters), ran the program and got... a segfault. I was ashamed. I know this is not ocaml-cairo's fault, you bind an API in an unsafe language, but still this is quite embarrassing. This could be avoided by a comment in this example's source code that "if you want to create PNG files, see {this other example} instead" -- relatedly, a comment in diagram.ml about why the heck someone would create a SVG surface and then call Cairo.PNG.write on it could be helpful.

(Note that problem (3) is a consequence of problem (2): with clear indication of which example gives a minimum viable snippet to produce a PNG file, this whole mess would have been avoided.)

Undefined reference

Hi, please tell me what is the problem with linking?

(cd _build/default && /usr/bin/ocamlopt.opt -w @[email protected]@30..39@[email protected]@[email protected] -strict-sequence -strict-formats -short-paths -keep-locs -g -shared -linkall -I gtk -o gtk/cairo_gtk.cmxs gtk/cairo_gtk.cmxa) /usr/bin/x86_64-rosa-linux-gnu-ld: gtk/cairo_gtk.cmxs.startup.o: in function caml_curry4':
:(.text+0x4e): undefined reference to caml_call_gc' /usr/bin/x86_64-rosa-linux-gnu-ld: gtk/cairo_gtk.cmxs.startup.o: in function caml_curry4_1':
:(.text+0xde): undefined reference to caml_call_gc' /usr/bin/x86_64-rosa-linux-gnu-ld: gtk/cairo_gtk.cmxs.startup.o: in function caml_curry4_2':
:(.text+0x153): undefined reference to caml_call_gc' /usr/bin/x86_64-rosa-linux-gnu-ld: gtk/cairo_gtk.cmxs.startup.o: in function caml_curry2':
:(.text+0x1d3): undefined reference to caml_call_gc' /usr/bin/x86_64-rosa-linux-gnu-ld: gtk/cairo_gtk.a(cairo_gtk.o): in function camlCairo_gtk__fun_214':
:(.text+0x18): undefined reference to caml_c_call' /usr/bin/x86_64-rosa-linux-gnu-ld: gtk/cairo_gtk.a(cairo_gtk.o): in function camlCairo_gtk__fun_216':
:(.text+0x42): undefined reference to caml_c_call' /usr/bin/x86_64-rosa-linux-gnu-ld: gtk/cairo_gtk.a(cairo_gtk.o): in function camlCairo_gtk__fun_218':
:(.text+0x62): undefined reference to caml_c_call' /usr/bin/x86_64-rosa-linux-gnu-ld: gtk/cairo_gtk.a(cairo_gtk.o): in function camlCairo_gtk__fun_220':
:(.text+0x82): undefined reference to caml_c_call' /usr/bin/x86_64-rosa-linux-gnu-ld: gtk/cairo_gtk.a(cairo_gtk.o): in function camlCairo_gtk__fun_222':
:(.text+0x9f): undefined reference to caml_c_call' /usr/bin/x86_64-rosa-linux-gnu-ld: gtk/libcairo_gtk_stubs.a(cairo_gtk_stubs.o): in function caml_gdk_cairo_create':
/builddir/build/BUILD/cairo2-0.6.2/_build/default/gtk/cairo_gtk_stubs.c:65: undefined reference to Caml_state' /usr/bin/x86_64-rosa-linux-gnu-ld: /builddir/build/BUILD/cairo2-0.6.2/_build/default/gtk/cairo_gtk_stubs.c:68: undefined reference to caml_cairo_raise_Error'
/usr/bin/x86_64-rosa-linux-gnu-ld: /builddir/build/BUILD/cairo2-0.6.2/_build/default/gtk/cairo_gtk_stubs.c:69: undefined reference to caml_cairo_ops' /usr/bin/x86_64-rosa-linux-gnu-ld: /builddir/build/BUILD/cairo2-0.6.2/_build/default/gtk/cairo_gtk_stubs.c:69: undefined reference to caml_alloc_custom'
/usr/bin/x86_64-rosa-linux-gnu-ld: gtk/libcairo_gtk_stubs.a(cairo_gtk_stubs.o): in function caml_gdk_cairo_set_source_color': /builddir/build/BUILD/cairo2-0.6.2/_build/default/gtk/cairo_gtk_stubs.c:74: undefined reference to Caml_state'
/usr/bin/x86_64-rosa-linux-gnu-ld: /builddir/build/BUILD/cairo2-0.6.2/_build/default/gtk/cairo_gtk_stubs.c:74: undefined reference to caml_cairo_raise_Error' /usr/bin/x86_64-rosa-linux-gnu-ld: gtk/libcairo_gtk_stubs.a(cairo_gtk_stubs.o): in function caml_gdk_cairo_rectangle':
/builddir/build/BUILD/cairo2-0.6.2/_build/default/gtk/cairo_gtk_stubs.c:75: undefined reference to Caml_state' /usr/bin/x86_64-rosa-linux-gnu-ld: /builddir/build/BUILD/cairo2-0.6.2/_build/default/gtk/cairo_gtk_stubs.c:75: undefined reference to caml_cairo_raise_Error'
/usr/bin/x86_64-rosa-linux-gnu-ld: gtk/libcairo_gtk_stubs.a(cairo_gtk_stubs.o): in function caml_gdk_cairo_region': /builddir/build/BUILD/cairo2-0.6.2/_build/default/gtk/cairo_gtk_stubs.c:76: undefined reference to Caml_state'
/usr/bin/x86_64-rosa-linux-gnu-ld: /builddir/build/BUILD/cairo2-0.6.2/_build/default/gtk/cairo_gtk_stubs.c:76: undefined reference to GdkRegion_val' /usr/bin/x86_64-rosa-linux-gnu-ld: /builddir/build/BUILD/cairo2-0.6.2/_build/default/gtk/cairo_gtk_stubs.c:76: undefined reference to caml_cairo_raise_Error'
/usr/bin/x86_64-rosa-linux-gnu-ld: gtk/libcairo_gtk_stubs.a(cairo_gtk_stubs.o): in function caml_gdk_cairo_set_source_pixbuf': /builddir/build/BUILD/cairo2-0.6.2/_build/default/gtk/cairo_gtk_stubs.c:77: undefined reference to Caml_state'
/usr/bin/x86_64-rosa-linux-gnu-ld: /builddir/build/BUILD/cairo2-0.6.2/_build/default/gtk/cairo_gtk_stubs.c:77: undefined reference to caml_cairo_raise_Error' collect2: error: ld returned 1 exit status

Does not compile on cygwin

Ocaml-cairo does not compile on cygwin. The setup search for includes in C:\… which does not make sense (cygwin use the same file organisation as any unix).

I've found the cause in setup.ml:77 and setup.ml:88

The two functions should be replaced by those one :

let cairo_cflags =
  lazy(match cairo_cflags with
       | [] ->
         (match Sys.os_type with
          | "Cygwin"
          | "Unix" -> split_on_space(pkg_config "cairo" ["--cflags-only-I"])
          …

(** Compute the correct CLIBS for Cairo. *)
let cairo_clibs =
  lazy(match cairo_clibs with
       | [] ->
         (match Sys.os_type with
          | "Cygwin"
          | "Unix" -> split_on_space(pkg_config "cairo" ["--libs"])
          …

Library archives link freetype multiple times on macOS

It seems that cairo2.cmxa links freetype multiple times:

> ocamlobjinfo $(opam var lib)/cairo2/cairo.cmxa | grep 'Extra'
Extra C object files: -lcairo_stubs -L/opt/homebrew/opt/freetype/lib -lfreetype -L/opt/homebrew/Cellar/fontconfig/2.15.0/lib -L/opt/homebrew/opt/freetype/lib -lfontconfig -lfreetype -L/opt/homebrew/Cellar/cairo/1.18.2/lib -lcairo
Extra C options:

and that trips more recent macOS linkers, for example trying to compile this file I get:

> ocamlfind ocamlopt -package cairo2,gg,vg,vg.cairo -linkpkg min_cairo_mem.ml
ld: warning: ignoring duplicate libraries: '-lfreetype'
> dune --version
3.16.0
> > opam config report
# opam config report
# opam-version         2.2.1
# self-upgrade         no
# system               arch=arm64 os=macos os-distribution=homebrew os-version=14.6.1
# solver               builtin-mccs+glpk
# install-criteria     -removed,-count[avoid-version,changed],-count[version-lag,request],-count[version-lag,changed],-count[missing-depexts,changed],-changed
# upgrade-criteria     -removed,-count[avoid-version,changed],-count[version-lag,solution],-count[missing-depexts,changed],-new
# jobs                 9
# repositories         1 (http), 2 (version-controlled) (default repo at d94dfabfa84a67443fe03586e912f15966b28089)
# pinned               25 (git)
# current-switch       5.2.0
# invariant            ocaml-base-compiler = 5.2.0 | ocaml-system = 5.2.0
# compiler-packages    ocaml-base-compiler.5.2.0, ocaml-options-vanilla.1
# ocaml:native         true
# ocaml:native-tools   true
# ocaml:native-dynlink true
# ocaml:stubsdir       /Users/dbuenzli/.opam/5.2.0/lib/ocaml/stublibs:/Users/dbuenzli/.opam/5.2.0/lib/ocaml
# ocaml:preinstalled   false
# ocaml:compiler       5.2.0

cairo compilation messed up with opam prefix "4.03.0+flambda"

Hello

compilation of cairo fails with opam switch 4.03.0+flambda.
Cairo/autoconf looks for lablgtk2 directory, which is in my case /home/src/Ocaml/opam-ocaml-4.03.0/4.03.0+flambda/lib/lablgtk2/.
The problem seems to be the "+" (that comes from opam switch name), which seems to be translated to some other standard path name :

ocamlc.opt -ccopt "-g -pthread -I/usr/include/gtk-2.0 -I/usr/lib/x86_64-linux-gnu/gtk-2.0/include -I/usr/include/gio-unix-2.0/ -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng12 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/libpng12 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/home/src/Ocaml/opam-ocaml-4.03.0/4.03.0/home/src/Ocaml/opam-ocaml-4.03.0/4.03.0+flambda/lib/ocaml/flambda/lib/lablgtk2/" ml_cairo_lablgtk.c
ml_cairo_lablgtk.c:14:22: fatal error: wrappers.h: Aucun fichier ou dossier de ce type
#include "wrappers.h"

Best regards

Image.get_stride does not behave as documented

The generated documentation says :

val get_stride : Cairo.Surface.t -> int
Get the stride of the image surface in bytes.

But in the implementation, the stride is divided by 4 if the image is RGB24 or ARGB32, which is incorrect (the value returned by the underlying Cairo function is indeed the correct stride in bytes).
Shouldn't this behavior be reverted back to its original definition ? After all, the stride is used to compute the position of the beginning of a row ?

Error loading shared library on macOS

Library file seems to be missing:

ocsigenserver: ocsigen:main: Fatal - While loading /Users/boris/.opam/default/lib/cairo2/cairo.cma: error loading shared library: Dynlink.Error (Dynlink.Cannot_open_dll "Failure(\"dllcairo_stubs.so: dlopen(dllcairo_stubs.so, 10): image not found\")")
make: *** [test.byte] Error 52

$ ls /Users/boris/.opam/default/lib/cairo2/
META			cairo.cmi		cairo.cmx		cairo.ml		dune-package
cairo.a			cairo.cmt		cairo.cmxa		cairo.mli		libcairo_stubs.a
cairo.cma		cairo.cmti		cairo.cmxs		cairo_ocaml.h		opam

cairo2-pango dependency on lablgtk

I'm using cairo2-pango (in combination with cairo2, but that's it). Currently, cairo2-pango brings all of lablgtk as a dependency, which is a bit unfortunate. If I understand correctly, this is because because lablgtk binds bits of pango itself, and indeed, I'm using some functions from lablgtk's Pango module.

How hard would it be to make the dependencies of cairo2-pango more lightweight, possibly by separating the pango bindings from the rest of lablgtk?

License needs clarification (which linking exception?)

Hello,

the license header, for instance in the file "src/cairo.ml", says:

under the terms of the GNU Lesser General Public License version 3 or
later as published by the Free Software Foundation, with the special
exception on linking described in the file LICENSE

However, the file LICENSE.md (I guess that is the file you mean) contains an almost verbatim copy of the LGPL-3, the only difference being minor layout changes. There is no special exception on linking to be found in this file.

Segfault in image_create test

Building ocaml-cairo 0.6.1 with ocaml 4.10.0 beta1 on a Fedora Rawhide machine, tests/image_create.ml segfaults. Running with valgrind shows that the data array allocated on line 6 is deallocated in one of the Gc.compact() calls on line 17, leading to a segfault as cr is used in the next few lines. The build logs can be seen here: https://koji.fedoraproject.org/koji/taskinfo?taskID=40896397.

The problem appears to be that the result of create() is an opaque object, so OCaml finds no remaining references to data, allowing the garbage collector to reclaim it, even though cr still contains a pointer into its memory. Is this a problem with the test only, or does this imply that the interface should be changed to ensure that a reference to the array lives as long as the Surface object?

`Path.fold` not folding over contents of path (when `to_array` in non-empty)

type glyph_outline =
  { outer : (float * float) list
  ; inner : (float * float) list list
  }

let f (paths, ps, last_p) = function
    | MOVE_TO (x, y) -> paths, ps, (x, y)
    | LINE_TO (x, y) -> paths, last_p :: ps, (x, y)
    | CURVE_TO (x1, y1, x2, y2, x3, y3) ->
      let bez = Bezier2d.make' [| last_p; x1, y1; x2, y2; x3, y3 |] in
      paths, Bezier2d.curve ~rev:true ~endpoint:false ~init:ps bez, (x3, y3)
    | CLOSE_PATH -> (last_p :: ps) :: paths, [], last_p

let path_to_outlines path =
  let ps, _, _ = Path.fold path f ([], [], (0., 0.)) in
    List.rev_map (List.map @@ fun (x, y) -> x, -.y) ps

let pathdata_to_outlines data =
  let ps, _, _ = Array.fold_left f ([], [], (0., 0.)) data in
    List.rev_map (List.map @@ fun (x, y) -> x, -.y) ps

let glyph_outline ?(center = false) ?weight ~font char =
  let s = String.of_seq (Seq.return char)
  and cr = create (Image.create Image.A1 ~w:1 ~h:1) in
  select_font_face ?weight cr font;
  let te = text_extents cr s in
  if center
  then (
    let x = 0.5 -. (te.width /. 2.) -. te.x_bearing
    and y = 0.5 -. (te.height /. 2.) -. te.y_bearing in
    move_to cr x y );
  Path.text cr s;
  match pathdata_to_outlines Path.(to_array @@ copy cr) with
  (* match path_to_outlines (Path.copy cr) with *)
  | [] -> { outer = []; inner = [] }
  | outer :: inner -> { outer; inner }

The above example works as expected using the intermediate array, but using Path.fold directly (as in the commented match line) leads to an empty result.

I'm on ocaml v4.13.1, using cairo2 v0.6.2.

Thanks for providing these bindings! Very quick and simple to get started for my use case.

Can't compile on Windows / Diskuv

cairo2 doesn't compile on Windows / Diskuv / MSVC.

The preprocessor doesn't seem to support the vararg notation (args ...)

# C:\Users\frede\AppData\Local\opam\playground\.opam-switch\build\cairo2.0.6.2\_build\default\src\cairo_macros.h(178): error C2010: '.' : inattendu dans la liste de paramètres de macro
# cairo_stubs.c(1615): error C2010: '.' : inattendu dans la liste de paramètres de macro

The 178th line of cairo_macros.h is

#define RAISE_UNAVAILABLE(name, args ...)                               \

(inatendu means unexpected)

MSVC expect varargs writen as simply ... and the content is put in the __VA_ARGS__ token. See https://learn.microsoft.com/en-us/cpp/preprocessor/variadic-macros?view=msvc-170 these approch is compatible with gcc.

Ft and Pango modules

I was trying to migrate mlpost from cairo to cairo2 (backtracking/mlpost#8). Things are well namespaced, and it uses dune! great! But I'm quite puzzled by the presence or not of the module Ft. Where is it? It is not in the list of font to implement.

Can't compile Cairo2 on Windows (Diskuv)

I am trying to compile lablgtk3 and it fails at cairo2.

It seems the include path doesn't contains freetype.

I have the error:

# compiling c program:
# [...]
#  | #else
#  | const char *s1 = "BEGIN-1-false-END";
#  | #endif
#  |
# run: cl -nologo -O2 -Gy- -MD    -I C:\gtk\include\cairo -I C:/Users/frede/AppData/Local/Programs/DISKUV~1/lib/ocaml -FoC:\Users\frede\AppData\Local\Temp\build_8016ba_dune\ocaml-configurator6f6e1a\c-test-2\test.obj -c C:\Users\frede\AppData\Local\Temp\build_8016ba_dune\ocaml-configurator6f6e1a\c-test-2\test.c
# -> process exited with code 2
# -> stdout:
#  | test.c
#  | C:\gtk\include\cairo\cairo-ft.h(46): fatal error C1083: Impossible d'ouvrir le fichier include : 'ft2build.h' : No such file or directory
# -> stderr:
# Error: failed to compile program

My cairo-features.h file has a #define CAIRO_HAS_FT_FONT 1 line, but discover.ml fails to find it.

lablgtk dependency situation is unclear

This is a bug report about the README, essentially that I cannot understand what is going on. For background, I am the maintainer of unison which uses lablgtk(2) and is going to use lablgtk(3). This is a separate issue than #21.

It seems that this package can be built without lablgtk, and that results in the cairo bindings only. However the readme says that lablgtk is needed.

After building ocaml-cairo without lablgtk, I am able to build lablgtk3. While lablgtk3 does not document a dependency on ocaml-cairo, it fails to build without it.

Assuming the README is changed to say that lablgtk is optional and needed for ocaml-pango and ocaml-gtk, it should explain how one would choose whether to build those, particularly for packagers. It seems to be that lablgtk(2) and ttk2 in general are obsolete, and thus the gtk bindings in ocaml-cairo should not be built by default. I am unclear on the pango bindings, but if programs written for lablgtk3 work without them, then perhaps that is only of interest for programs written to use ocaml-cairo directly.

opam lablgtk package naming

Hello Chris,

cairo2-gtk currently depends on lablgtk2 while the lablgtk package is named lablgtk (without the 2)

regards

Segmentation Fault on new Cairo Error Status

Hello,

The following (pretty new) cairo error status (see cairo_status_t from cairo.h) are not managed in the OCaml type Cairo.status:

  • CAIRO_STATUS_PNG_ERROR
  • CAIRO_STATUS_FREETYPE_ERROR
  • CAIRO_STATUS_WIN32_GDI_ERROR
  • CAIRO_STATUS_TAG_ERROR

When this kind of error occurs (from C code), the C function caml_cairo_raise_Error from cairo_ocaml_types.h raises the exception Cairo.Error with an argument that is invalid regarding to the OCaml type Cairo.status. Then, the OCaml exception pretty printer, calling Cairo.error_of_status, segfaults.

I suggest to add these cases in the OCaml type Cairo.status and in the OCaml exception pretty printer Cairo.error_of_status, and maybe to add a check in the C function caml_cairo_raise_Error to manage future possible extensions of the C type cairo_status_t.

Thanks,
Benoît.

Image.create_for_data32 mixes width and height

Hi,

the function 'create_for_data32' mixes width and height: the first dimension of the Bigarray.Array2 should be the height and the second the width.

The following code produces a 8 by 4 pixels png file, with transparent pixels everywhere but for the white pixel (4, 0), but I expected it to be at (1, 0).

let main () =
  let ba = Bigarray.(Array2.create Int32 C_layout 8 4) in
  Bigarray.Array2.fill ba (Int32.zero);
  Bigarray.Array2.set ba 1 0 (Int32.minus_one);
  let surf = Cairo.Image.create_for_data32 ba in
  Cairo.PNG.write surf "test.png"

let () = main ()

The following code bypasses the bug:

let corrected () =
  (* switch widths and heights *)
  let width = 8 in
  let height = 4 in
  let ba = Bigarray.(Array2.create Int32 C_layout 4 8) in
  Bigarray.Array2.fill ba (Int32.zero);
  Bigarray.Array2.set ba 0 1 (Int32.minus_one);
  (* reinterpret data *)
  let gba = Bigarray.genarray_of_array2 ba in
  let ba = Bigarray.reshape_2 gba width height in
  let surf = Cairo.Image.create_for_data32 ba in
  Cairo.PNG.write surf "test2.png"

let () = corrected ()

License of tutorial.html is missing

Sorry to bother you again with a boring license question:

docs/tutorial.html is copyrighted Michael Urman. Has this document really been licensed by the copyright holder under the LGPL? If not, what is its license?

Version 0.6.4 cannot find pgkconf and ft2build.h

/usr/bin/pkgconf is present, why it's not found by which isn't clear to me. Running which pkgconf from cli and the correct path is returned.

The more puzzling part is c-test-2 and why /usr/include/cairo/cairo-ft.h says it cannot find ft2build.h. That file is present in /usr/include/freetype2/. AFAICT all the pathing is correct. As a check, I looked into for example grub2 and it finds ft2build.h with no problems.

pkgconf --cflags /usr/lib/pkgconfig/cairo-ft.pc returns;
-I/usr/include/cairo -I/usr/include/libpng16 -I/usr/include/freetype2 -I/usr/include/harfbuzz -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/pixman-1

pkgconf --libs /usr/lib/pkgconfig/cairo-ft.pc returns;
-lcairo -lfreetype

pkgconf --cflags /usr/lib/pkgconfig/cairo-fc.pc returns;
-I/usr/include/cairo -I/usr/include/libpng16 -I/usr/include/freetype2 -I/usr/include/harfbuzz -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/pixman-1

pkgconf --libs /usr/lib/pkgconfig/cairo-fc.pc returns;
-lcairo -lfontconfig -lfreetype

Running; dune build -p cairo2

File "src/dune", line 12, characters 0-132:
12 | (rule
13 | (targets c_flags.sexp c_library_flags.sexp cairo_ocaml.h)
14 | (deps cairo_ocaml.h.p)
15 | (action (run ../config/discover.exe)))
(cd _build/default/src && ../config/discover.exe)
which: /usr/bin/pkgconf
-> not found
compiling c program:
| #include <stdio.h>
| #include <cairo.h>
|
|
| #define DUNE_ABS(x) ((x >= 0)? x: -(x))
| #define DUNE_D0(x) ('0'+(DUNE_ABS(x)/1 )%10)
| #define DUNE_D1(x) ('0'+(DUNE_ABS(x)/10 )%10), DUNE_D0(x)
| #define DUNE_D2(x) ('0'+(DUNE_ABS(x)/100 )%10), DUNE_D1(x)
| #define DUNE_D3(x) ('0'+(DUNE_ABS(x)/1000 )%10), DUNE_D2(x)
| #define DUNE_D4(x) ('0'+(DUNE_ABS(x)/10000 )%10), DUNE_D3(x)
| #define DUNE_D5(x) ('0'+(DUNE_ABS(x)/100000 )%10), DUNE_D4(x)
| #define DUNE_D6(x) ('0'+(DUNE_ABS(x)/1000000 )%10), DUNE_D5(x)
| #define DUNE_D7(x) ('0'+(DUNE_ABS(x)/10000000 )%10), DUNE_D6(x)
| #define DUNE_D8(x) ('0'+(DUNE_ABS(x)/100000000 )%10), DUNE_D7(x)
| #define DUNE_D9(x) ('0'+(DUNE_ABS(x)/1000000000)%10), DUNE_D8(x)
| #define DUNE_SIGN(x) ((x >= 0)? '0': '-')
|
|
| const char s0[] = {
| 'B', 'E', 'G', 'I', 'N', '-', '0', '-',
| DUNE_SIGN((CAIRO_VERSION_MAJOR)),
| DUNE_D9((CAIRO_VERSION_MAJOR)),
| '-', 'E', 'N', 'D'
| };
|
|
| const char s1[] = {
| 'B', 'E', 'G', 'I', 'N', '-', '1', '-',
| DUNE_SIGN((CAIRO_VERSION_MINOR)),
| DUNE_D9((CAIRO_VERSION_MINOR)),
| '-', 'E', 'N', 'D'
| };
|
run: gcc -O2 -fno-strict-aliasing -fwrapv -pthread -g -fno-omit-frame-pointer -fPIC -O2 -march=native -pipe -Wp,-D_FORTIFY_SOURCE=2 -I/usr/include/cairo -I /usr/lib/ocaml -o /tmp/build_cf88f1_dune/ocaml-configuratord1e6f8/c-test-0/test.o -c /tmp/build_cf88f1_dune/ocaml-configuratord1e6f8/c-test-0/test.c -lm -lpthread
-> process exited with code 0
-> stdout:
-> stderr:
compiling c program:
| #include <stdio.h>
| #include <cairo-ft.h>
|
|
| #ifdef CAIRO_HAS_FT_FONT
| const char *s0 = "BEGIN-0-true-END";
| #else
| const char *s0 = "BEGIN-0-false-END";
| #endif
|
|
| #ifdef CAIRO_HAS_FC_FONT
| const char *s1 = "BEGIN-1-true-END";
| #else
| const char *s1 = "BEGIN-1-false-END";
| #endif
|
run: gcc -O2 -fno-strict-aliasing -fwrapv -pthread -g -fno-omit-frame-pointer -fPIC -O2 -march=native -pipe -Wp,-D_FORTIFY_SOURCE=2 -I/usr/include/cairo -I /usr/lib/ocaml -o /tmp/build_cf88f1_dune/ocaml-configuratord1e6f8/c-test-2/test.o -c /tmp/build_cf88f1_dune/ocaml-configuratord1e6f8/c-test-2/test.c -lm -lpthread
-> process exited with code 1
-> stdout:
-> stderr:
| In file included from /tmp/build_cf88f1_dune/ocaml-configuratord1e6f8/c-test-2/test.c:2:
| /usr/include/cairo/cairo-ft.h:46:10: fatal error: ft2build.h: No such file or directory
| 46 | #include <ft2build.h>
| | ^~~~~~~~~~~~
| compilation terminated.
Error: failed to compile program

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.