Bug 9189 - Dashed strokes too long in fallback images
Summary: Dashed strokes too long in fallback images
Status: RESOLVED FIXED
Alias: None
Product: cairo
Classification: Unclassified
Component: pdf backend (show other bugs)
Version: 1.3.2
Hardware: All All
: high normal
Assignee: Kristian Høgsberg
QA Contact: cairo-bugs mailing list
URL:
Whiteboard:
Keywords:
: 13411 17223 (view as bug list)
Depends on:
Blocks:
 
Reported: 2006-11-28 17:55 UTC by Aaron Spike
Modified: 2008-10-15 23:54 UTC (History)
2 users (show)

See Also:
i915 platform:
i915 features:


Attachments

Description Aaron Spike 2006-11-28 17:55:55 UTC
Tested on windows and linux with cairo versions as new as 1.3.5. Does not
exhibit itself with the image backend. But when gradient strokes are used in the
same PDF document with dashed strokes the dashed strokes are too long (ie 2x or 4x).

A minimal program that shows the error:

#include <cairo.h>
#include <cairo-pdf.h>

int main(int argc, char *argv[]);

int main(int argc, char *argv[])
{
        const char filename[] = "test.pdf";
        cairo_surface_t* cr_s;
        cairo_t* cr;
        cairo_pattern_t* pattern;

        cr_s = cairo_pdf_surface_create(filename, 600.0, 600.0);

        cr = cairo_create(cr_s);

        cairo_set_line_width (cr, 10.0);

        pattern = cairo_pattern_create_linear(0.0, 0.0, 0.0, 300.0);
        cairo_pattern_add_color_stop_rgba(pattern, 0.0, 0.0, 0.0, 0.0, 1.0);
        cairo_pattern_add_color_stop_rgba(pattern, 1.0, 0.0, 0.0, 0.0, 0.0);
        cairo_set_source(cr, pattern);

        cairo_move_to(cr, 0.0, 50.0);
        cairo_line_to(cr, 300.0, 50.0);
        cairo_stroke(cr);

        cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, 1.0);

        cairo_move_to(cr, 0.0, 100.0);
        cairo_line_to(cr, 300.0, 100.0);
        cairo_stroke(cr);

        const double dash_array[] = {50.0};
        cairo_set_dash(cr, dash_array, 1, 0.0);

        cairo_move_to(cr, 0.0, 150.0);
        cairo_line_to(cr, 300.0, 150.0);
        cairo_stroke(cr);

        cairo_show_page(cr);
        cairo_pattern_destroy(pattern);
        cairo_destroy (cr);
        cairo_surface_destroy (cr_s);

        return 0;
}
Comment 1 Carl Worth 2008-04-11 13:26:08 UTC
Sorry we've never replied here.

I just tested this with cairo 1.6.2 and it appears to be working just fine.

That is, with 1.6.2, we don't use fallbacks anymore for the gradients, so the bug is hidden.

I think the bug is likely still present with dashed lines and fallbacks, but it's going to be harder to hit, (since in 1.6 getting fallbacks in cairo-pdf is much harder).

So please upgrade to 1.6 and see if that doesn't fix your problems.

In the meantime, I'll leave this bug open so we can look into the "mis-sized dashing with PDF and fallbacks" issue.

-Carl
Comment 2 Chris Wilson 2008-09-28 13:11:13 UTC
*** Bug 17223 has been marked as a duplicate of this bug. ***
Comment 3 Chris Wilson 2008-09-28 13:52:19 UTC
*** Bug 13411 has been marked as a duplicate of this bug. ***
Comment 4 Paul Sephton 2008-09-29 05:08:01 UTC
This may a duplicate of bug 17723, but it's not at all "hidden".  I see Carl Worth says he tested the code in this bug report, and it "is working".  My problem, on the other hand is not noticeably absent.

It's quite easy to replicate- especially with printer surfaces.  Bug 17723 lists a 2-liner patch to fallback_resolution.c which demonstrates exactly how easy it is;  simply set the line style to dashed lines instead of solid lines in that example, and voila- an instant mess.

In fact in my opinion it's impossible to draw dashed lines to a printer context without this problem occurring, unless you set the fallback resolution of the surface to match the physical device resolution.

That means that for some win32 printers, the fallback resolution must be set to 1200x600 [inefficient], where for PDF and postscript, the fallback resolution must be set to 72x72 [insufficient].  Besides the fact that anything at 72x72 resolution looks like rubbish, the PDF/Postscript result is inconsistent with win32 output.

Of course, since there is a single fallback resolution for the whole surface, the inconsistency does not just apply to dashed lines;  If you adjust the fallback resolution to something nonsensical like 72x72 just to get the dashed lines working, the whole graphic is rendered in that resolution- not just dashed lines.

This is a major problem when producing output for printers where the graphic contains dashes.  

If anyone has any work-arounds in the interim, I would be most grateful.
Comment 5 Chris Wilson 2008-09-29 05:31:37 UTC
(In reply to comment #4)
> This may a duplicate of bug 17723, but it's not at all "hidden".  I see Carl
> Worth says he tested the code in this bug report, and it "is working".  My
> problem, on the other hand is not noticeably absent.

Indeed and the bug is now dutifully reported by the test suite and I've used your report as an example of how it still exists within cairo-win32-printing and affects users. So since it is now painfully obvious that cairo is broken, I hope to see a fix soon.
Comment 6 Paul Sephton 2008-09-29 05:42:01 UTC
Is there anything I can do to help fix the problem?  I did try digging into the code, but I am afraid it's rather above me.  Perhaps with some pointers as to where to look, or some hand-holding, I could do some of the drudge work?
Comment 7 Chris Wilson 2008-09-29 06:05:08 UTC
(In reply to comment #6)
> Is there anything I can do to help fix the problem?  I did try digging into the
> code, but I am afraid it's rather above me.  Perhaps with some pointers as to
> where to look, or some hand-holding, I could do some of the drudge work?

Well, we know the problem is stroking dashes under a fallback image so the issue is likely to be confined to _cairo_stroker_line_to_dashed() in src/cairo-path-stroke.c (and its inputs). If you are interested, I'd read through that function taking note of what matrices are used and then tracing back to see their construction. Then either you spot the problem straight-away, or you can start comparing the difference between difference fallback resolutions. If you can join us on irc, in #cairo on irc.freenode.net, we'll happily help you learn the code and assist in whatever way we can. 

Comment 8 Paul Sephton 2008-09-29 06:12:32 UTC
Thanks-  I'll get out my spade and go digging.  I will let you know what I find.


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.