Problem displaying recorded cairo image

15 views
Skip to first unread message

david allen

unread,
Oct 26, 2020, 11:15:37 AM10/26/20
to fltk.general
## Background and Project Objective
I am developing a program for mathematical modeling. The program creates cairo images showing aspects of models fit to data. The bounding boxes of the images are not known in advance. Hence the image is written to an unbounded surface to be measured later. Code to setup a recording surface is

    cairo_surface_t* record =
        cairo_recording_surface_create(CAIRO_CONTENT_COLOR_ALPHA, NULL);
    cairo_t* cr = cairo_create(record);

The image code goes here.  The image is *measured* by

    cairo_rectangle_t rect;
    cairo_recording_surface_ink_extents(record,
                         &rect.x, &rect.y, &rect.width, &rect.height);

The surface can then be painted to any other type of surface. In my program, it is first shown on the screen and then, if satisfactory, exported to pdf.

## The Problem
I have attached a demo program. The recording phase and the export to pdf portions seem to work perfectly. The *display on screen* portion shows the image but with a corrupted background. I am using recent cairo and Linux Mint distributions. FLTK version is 1.4.0. I have not tried Mac or Windows. Hints for resolving this problem would be much appreciated.
record.cpp

imm

unread,
Oct 26, 2020, 12:29:10 PM10/26/20
to general fltk
On Mon, 26 Oct 2020 at 15:15, david allen wrote:
>
> ## Background and Project Objective
> I am developing a program for mathematical modeling. The program creates cairo images showing aspects of models fit to data. The bounding boxes of the images are not known in advance. Hence the image is written to an unbounded surface to be measured later. Code to setup a recording surface is
>
> cairo_surface_t* record =
> cairo_recording_surface_create(CAIRO_CONTENT_COLOR_ALPHA, NULL);

Hmm, I wonder if you need to "flatten" this surface before you render it?
That is, I wonder if the rendering into the Fl_Box is getting confused
by the alpha channel here? It's possible that the target at that point
is only RGB, not RGBA...

That is pure speculation however...

FWIW, I ran the code (on Ubuntu) and the first time worked fine, no
background corruption. Every subsequent time, I saw some corruption
however.

Also: From your description I had expected the fltk render to be sized
to fit the star (as the PDF is) but that did not seem to be the case,
the star was rendered in the top left corner of the window. Is that as
expected?

imm

unread,
Oct 26, 2020, 12:35:59 PM10/26/20
to general fltk
Huh! This is not relevant, but it just struck me that the drawing
origins are probably wrong - they are not allowing for the (7,7)
offset of the box within the window, so the clip region is slightly
outside the Fl_Box bounds.

I very much doubt that is important in terms of the observed behaviour though!

david allen

unread,
Oct 27, 2020, 11:01:28 AM10/27/20
to fltk.general
Thanks for the thoughts. I will try to do some compositing, though previous attempts have failed.

Anyway, thanks. And let me know if you have additional thoughts.

anmol....@gmail.com

unread,
Nov 6, 2020, 9:37:33 AM11/6/20
to fltk.general

Did this work, David?
Reply all
Reply to author
Forward
0 new messages