[cairo] Gradient Transformation Problems
Me Myself
radracer59 at inbox.com
Tue Dec 11 12:52:31 PST 2007
I am seeing some differences when filling paths with gradients. I start out with two rectangle paths, one inside the other. Each one has a linear gradient from the top-left to bottom-right, and vice-versa for the inner rectangle.
The problem I am seeing is that if I take these two shapes and scale them (by 0.25, 0.5 in my test) I see a different result than if I manually calculate the points to the correct scaled values, without using cairo_scale().
Does anyone have any idea why this is happening?
To show you what I mean, I've attached a screenshot of the two rectangle gradients. The one on top uses cairo_scale() to create the rectangle points, and the one on bottom uses manual calculations to produce the scaled points.
I used CairoPad (thanks Hakki!) to create this test. Here is the code for it:
local M_PI = math.pi
local sqrt = math.sqrt
local floor = math.floor
local tan = math.tan
function snippet_normalize (cr, width, height)
cairo.scale (cr, width, height)
cairo.set_line_width (cr, 0.04)
end
function f_gradient(cr, width, height)
snippet_normalize (cr, width, height);
cairo.save (cr);
cairo.scale (cr, 0.25, 0.5);
local pat = cairo.pattern_create_linear (0.0, 0.0, 1.0, 1.0);
cairo.pattern_add_color_stop_rgba (pat, 1, 0, 0, 0, 1);
cairo.pattern_add_color_stop_rgba (pat, 0, 1, 1, 1, 1);
cairo.rectangle (cr, 0.0, 0.0, 1.0, 1.0);
cairo.set_source (cr, pat);
cairo.fill (cr);
cairo.pattern_destroy (pat);
local pat = cairo.pattern_create_linear (0.95, 0.95, 0.05, 0.05);
cairo.pattern_add_color_stop_rgba (pat, 1, 0, 0, 0, 1);
cairo.pattern_add_color_stop_rgba (pat, 0, 1, 1, 1, 1);
cairo.rectangle (cr, 0.05, 0.05, 0.90, 0.90);
cairo.set_source (cr, pat);
cairo.fill (cr);
cairo.pattern_destroy (pat);
cairo.restore(cr);
local pat = cairo.pattern_create_linear (0.0, 0.5, 0.25, 1.0);
cairo.pattern_add_color_stop_rgba (pat, 1, 0, 0, 0, 1);
cairo.pattern_add_color_stop_rgba (pat, 0, 1, 1, 1, 1);
cairo.rectangle (cr, 0.0, 0.5, 0.25, 0.5);
cairo.set_source (cr, pat);
cairo.fill (cr);
cairo.pattern_destroy (pat);
local pat = cairo.pattern_create_linear (0.2375, 0.975, 0.0125, 0.525);
cairo.pattern_add_color_stop_rgba (pat, 1, 0, 0, 0, 1);
cairo.pattern_add_color_stop_rgba (pat, 0, 1, 1, 1, 1);
cairo.rectangle (cr, 0.0125, 0.525, 0.225, 0.45);
cairo.set_source (cr, pat);
cairo.fill (cr);
cairo.pattern_destroy (pat);
end
f_gradient(cr, 600, 600)
____________________________________________________________
FREE ONLINE PHOTOSHARING - Share your photos online with your friends and family!
Visit http://www.inbox.com/photosharing to find out more!
-------------- next part --------------
A non-text attachment was scrubbed...
Name: gradient.png
Type: image/x-png
Size: 19132 bytes
Desc: not available
Url : http://lists.cairographics.org/archives/cairo/attachments/20071211/2fb8898d/attachment-0001.bin
More information about the cairo
mailing list