Cairo.jl icon indicating copy to clipboard operation
Cairo.jl copied to clipboard

stroke defined by Cairo.jl doesn't scale

Open lobingera opened this issue 11 years ago • 7 comments

Hello,

i guess this is called a feature, but it's not expected looking at plain cairo (e.g. porting c-code to julia).

If i run this:

using Base
using Cairo

using Cairo
c = CairoRGBSurface(256,256);
cr = CairoContext(c);

save(cr);
set_source_rgb(cr,0.8,0.8,0.8); 
paint(cr);
restore(cr);

# unscaled
save(cr);
move_to(cr,20,100);
line_to(cr,236,100);
set_line_width(cr,2.0);
stroke(cr);
restore(cr);
# scaled, julia stroke
save(cr);
scale(cr,10,10);
move_to(cr,2,12);
line_to(cr,23.6,12);
set_line_width(cr,2.0);
stroke(cr);
restore(cr);
# scaled, cairo stroke
save(cr);
scale(cr,10,10);
move_to(cr,2,14);
line_to(cr,23.6,14);
set_line_width(cr,2.0);
ccall((:cairo_stroke,Cairo._jl_libcairo),Void, (Ptr{Void},), cr.ptr)
restore(cr);

## mark picture with current date
move_to(cr,0.0,12.0);
set_source_rgb (cr, 0,0,0);
show_text(cr,strftime(time()));
write_to_png(c,"stroke_test.png");

stroke_test

i get the first two lines with a width of 2.0, but the third with the scaling applied.

lobingera avatar Jan 26 '14 13:01 lobingera

cc @JeffBezanson, since this behavior was introduced in 863e4104423893770edc6e997b8d649cc8d37ed0.

nolta avatar Jan 30 '14 03:01 nolta

Quite right; I made the unorthodox choice to have stroke not be scaled by default. Having outlines scale along with shapes is one of the small gotchas in the cairo API IMO. The problem arises when you want to draw lines (e.g. for a plot) in a highly transformed coordinate system, and the lines come out crazy.

I made stroke_transformed do the normal Cairo thing. But, I totally understand if people would rather have the standard behavior and make the bindings more faithful to the original. Maybe we can introduce a new function like line or outline with my behavior?

JeffBezanson avatar Jan 30 '14 03:01 JeffBezanson

I totally understand the rationale, but it's probably better to make wrappers as "transparent" as possible.

nolta avatar Jan 30 '14 04:01 nolta

I'm fine with that. Let's think of a new name for the un-transformed stroke function.

JeffBezanson avatar Jan 30 '14 05:01 JeffBezanson

stroke_untransformed?

nolta avatar Jan 30 '14 18:01 nolta

The scaling/transformation issues are discussed right now in the cairo develpment also, as there seems to be a proposal to make cairo a C++ standard(?) and some people comment, that they like also to see changes like this and that (and scaling for set_line_width shows up there).

One note: The solution in Cairo.jl just uses cairo_identity_matrix, so unscaled to the device coordinate system. I have the feeling, that this is correct for drawing something on the screen, for other output media (like PDFSurface) an initial transformation might apply.

lobingera avatar Jan 31 '14 14:01 lobingera

I encountered this again while trying to construct some examples that could go into https://github.com/JuliaGraphics/Cairo.jl/issues/140. Afaics not that many packages (on METADATA) actually use Cairo.jl for drawing.

lobingera avatar Jun 26 '16 12:06 lobingera