Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stroke defined by Cairo.jl doesn't scale #60

Open
lobingera opened this issue Jan 26, 2014 · 7 comments
Open

stroke defined by Cairo.jl doesn't scale #60

lobingera opened this issue Jan 26, 2014 · 7 comments

Comments

@lobingera
Copy link
Contributor

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.

@nolta
Copy link
Member

nolta commented Jan 30, 2014

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

@JeffBezanson
Copy link
Contributor

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?

@nolta
Copy link
Member

nolta commented Jan 30, 2014

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

@JeffBezanson
Copy link
Contributor

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

@nolta
Copy link
Member

nolta commented Jan 30, 2014

stroke_untransformed?

@lobingera
Copy link
Contributor Author

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
Copy link
Contributor Author

I encountered this again while trying to construct some examples that could go into #140.
Afaics not that many packages (on METADATA) actually use Cairo.jl for drawing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants