Read in SVG and render using cairo

100 views
Skip to first unread message

anmol....@gmail.com

unread,
Nov 3, 2020, 10:15:36 AM11/3/20
to fltk.general

Hi. I know I can read in SVG image using FL_SVG_Image(). However, this uses rasterize_image(); to convert the SVG to bitmap. Since FLTK supports Cairo, is there a way to read in the paths and map them to a cairo context instead ?
So the SVG gets mapped to Cairo commands not to a bitmap.

Manolo

unread,
Nov 3, 2020, 10:41:34 AM11/3/20
to fltk.general
Short answer: No.

However, I'd like to be sure you're aware of the new class Fl_SVG_File_Surface allowing
FLTK to record any graphics as SVG data (in 1.4 only).

anmol....@gmail.com

unread,
Nov 6, 2020, 7:47:54 AM11/6/20
to fltk.general
Hi Manolo. I took some time to read and understand this. The SVG data is limited by the fltk render functions i.e. rotate, scale etc. Cairo has a more extensive vector graphics feature set. Also, animations are not supported.
This is a very interesting feature and thanks for the dev team for putting it in.
Looking at Fl::cairo_cc(cairo_t *), can I draw into a cairo context with 2D vector primitives, and then pass it to fltk ? Will the drawn cairo operations be recognized by fltk ?

Ian MacArthur

unread,
Nov 6, 2020, 5:40:56 PM11/6/20
to fltkg...@googlegroups.com


> On 6 Nov 2020, at 12:47, anmol.mishra wrote:
>
> Looking at Fl::cairo_cc(cairo_t *), can I draw into a cairo context with 2D vector primitives, and then pass it to fltk ? Will the drawn cairo operations be recognized by fltk ?

The easiest thing might be to create a Fl_Cairo_Window as shown in cairo_test.cxx and then render the scene just using Cairo primitives.


That said, although Cairo does a nice job, I found it to be quite slow, so I ended up rendering the window content in GL instead - that was a lot more work to write the code (though modern GL might be easier... YMMV...) but the result was properly accelerated by the GPU and so was *much* faster.

And with appropriate fiddling with my GL textures and so forth I got some very nice anti-aliasing in the end, just as nice as Cairo. But that may not be any use for your application of course.



anmol....@gmail.com

unread,
Nov 6, 2020, 10:52:38 PM11/6/20
to fltk.general
In the docs we need to create Cairo context using fltk APIs then use Cairo commands.
However there is also cairo_cc. can I accept Cairo context created outside fltk and assign to local window using cairo_cc?

On Saturday, November 7, 2020 at 4:10:56 AM UTC+5:30 Ian MacArthur wrote:


> On 6 Nov 2020, at 12:47, anmol.mishra wrote:
>
> Looking at Fl::cairo_cc(cairo_t *), can I draw into a cairo context with 2D vector primitives, and then pass it to fltk ? Will the drawn cairo operations be recognized by fltk ?

The easiest thing might be to create a Fl_Cairo_Window as shown in cairo_test.cxx and then render the scene just using Cairo primitives.


That said, although Cairo does a nice job, I found it to be quite slow, so I ended up rendering the window content in GL instead 
Cairo has a gl backend as well 

janezz55

unread,
Nov 25, 2020, 1:24:09 AM11/25/20
to fltk.general
Check this out, maybe it will help you, should be portable ..., but I only tested under linux, does not need svg or cairo support linked into the library:

Reply all
Reply to author
Forward
0 new messages