[cairo] 16-bit precision issues in cairo

Vladimir Vukicevic vladimirv at gmail.com
Thu Aug 11 20:55:47 PDT 2005


We're running into some 16-bit precision issues within cairo with
Mozilla; we sometimes do things like fill a rectangle the size of the
entire body of the page, even if we only see a small portion of the
page.  (This is bad, but that's beside the point.)  We end up passing
clamped values down to X, which causes all sorts of broken rendering. 
This affects other surfaces also; for example, the following code:

#define FACT 1.0

    cairo_surface_t *s = cairo_ps_surface_create ("foo.ps", 100.0 *
FACT, 100.0 * FACT);
    cairo_t *c = cairo_create (s);

    cairo_new_path (c);
    cairo_set_source_rgba (c, 1.0, 0.0, 0.0, 1.0);
    cairo_rectangle (c, 50.0 * FACT, 50.0 * FACT, 40.0 * FACT, 40.0 * FACT);
    cairo_fill (c);
    cairo_show_page (c);

    cairo_destroy (c);
    cairo_surface_destroy (s);

generates:

1 0 0 setrgbcolor
50 50 moveto 90 50 lineto 90 10 lineto 50 10 lineto closepath
fill

However, if FACT is bumped up to 1000.0, we end up with:

-32768 132768 moveto 0 132768 lineto 0 100000 lineto -32768 100000
lineto closepath
fill

I'm not really sure how this can be fixed; in particular, I don't
really know how to fix our own usage, because doubles can represent
the values needed just fine, but then things get shoved into 16-bit
values for some of the fast paths (like fill_rectangles).  Any ideas?

    - Vlad



More information about the cairo mailing list