3

Is it possible with cairo to fill a box or a polygon with a hatch (or arbitrary) pattern like below ? I didn't find informatinos in the cairo documentation or hackage.

hatch pattern

  • Are there built-in pattern in cairo ?
  • What are the functions to fill with patterns ?

I'm using haskell but a snippet in any language would be helpful.

JeanJouX
  • 2,555
  • 1
  • 25
  • 37
  • 2
    Not a full answer, but: perhaps you can [clip](http://hackage.haskell.org/package/cairo-0.13.0.6/docs/Graphics-Rendering-Cairo.html#v:clip) the shape you want to fill, then draw your pattern overtop some easily-computable larger region than the shape covers. – Daniel Wagner Feb 27 '15 at 00:46
  • This seems to do something similar by creating a pattern from an image and then tiling it into a shape: http://cairographics.org/samples/imagepattern/ – Cactus Feb 27 '15 at 01:44

1 Answers1

3
cairo_pattern_t *pattern = create_stipple ("lightgrey", (guchar *)stipple_data);
cairo_matrix_init_scale (&matrix, 1.0, 1.0);
cairo_pattern_set_matrix (pattern, &matrix);
some_shape = GOO_CANVAS_RECT (goo_canvas_rect_new (GOO_CANVAS_ITEM (group), 10.0, 10.0, 10.0, 10.0, "fill-pattern", pattern, "visibility", GOO_CANVAS_ITEM_INVISIBLE, NULL));
cairo_pattern_destroy (pattern);

Taken from one of my pet projects oregano @ github

ALso have a look at the cairo API reference which also covers generic pattern API

drahnr
  • 6,782
  • 5
  • 48
  • 75
  • I don't see the string "stipple" anywhere on the linked page, by the way. – Daniel Wagner Feb 27 '15 at 17:22
  • What stipple? The stipple is achieved by defining a patch of 8x8 size with manually defined data as done in oregano. `create_stipple` is a custom function doing exactly that as linked. – drahnr Feb 27 '15 at 17:36
  • You give a link and describe it as having "stipple details". But this is not obviously the case, as the link doesn't mention stipple at all. Perhaps you should change the link to point to documentation for your library, or update the description of the link to say what you expect people to find there. – Daniel Wagner Feb 27 '15 at 19:53
  • the link to the oregano file. The link to cairo pattern just is the _reference_ of what cairo already provides. – drahnr Feb 27 '15 at 20:38