Dealing with small gaps between shapes

19 views
Skip to first unread message

RB Whitaker

unread,
Nov 25, 2018, 2:45:29 AM11/25/18
to Prawn
I've attached a file to this. I don't know how that will show up here, but it illustrates my problem.

I'm running into a visual artifact that I'd like some expert opinions on how to address or at least work around.

I'm new to both Prawn and to Ruby.

Basically, I'm drawing two shapes that share an edge. In the math world, with no rounding errors, my two shapes would perfectly line up, and there would be no visual gap between the two shapes. But I'm assuming because of small rounding errors, I get tiny gaps between the two shapes. Never more than a hairline in size, and they may or may not be visible depending on the zoom level. (Zooming in doesn't guarantee they show up, nor does zooming out guarantee they go away.)

The artifact that I'm referring to is the little white line that cuts down into the shape in the attached image. There are basically three shapes there in the picture. One is a quarter circle, and the other two are rectangles that butt up against the edge of the quarter circle. So the two rectangles overlap a bit as well. 

I'm just wondering if anybody else out there has dealt with similar problems and has a good creative solution to it.

I tried drawing an outline around the circle, but even if I make the thickness really small, I get what I presume to be a similar artifact where I can see the edge poke out just a bit.

I also looked around for like an inflate or expand function, but I don't see it in the API. Maybe I just don't know what I'm looking for. Even if I found it though, I think it might have the same artifacts as drawing the outline.

I can't just do it all as one shape. Eventually, they'll need to be colored differently.


Untitled.png

RB Whitaker

unread,
Nov 25, 2018, 8:50:50 PM11/25/18
to Prawn
Both Chrome and Edge are showing those little hairline gaps between shapes. Acrobat Reader DC does a better job. I still occasionally see them. But they seem rarer there. I'm not sure if I should just chalk the hairlines up to bad rendering or keep trying to find a way to address the problem.

Edward Ellis

unread,
Nov 25, 2018, 11:31:01 PM11/25/18
to Prawn
It is hard to imagine the code you wrote to create this document by just looking at the image.  Any help we could provide would be suggested changes to the code that generated it.  Could you post the code here?

Alexander Mankuta

unread,
Nov 26, 2018, 4:24:55 AM11/26/18
to Prawn
Could you please upload an example script that demonstrates your issue?

RB Whitaker

unread,
Nov 26, 2018, 10:12:11 PM11/26/18
to Prawn
require 'prawn'
Prawn::Document::generate("output.pdf") do
5.times do |row|
5.times do |column|
fill do
move_to column*10, row*10
line_to (column+1)*10, row*10
line_to (column+1)*10, (row+1)*10
line_to column*10, (row+1)*10
end
end
end
end

RB Whitaker

unread,
Nov 26, 2018, 10:19:55 PM11/26/18
to Prawn
Got just a little ahead of myself there. I meant to post my description with the code sample.

I'm just drawing a bunch of squares (using line_to) in a grid pattern. Each square should, theoretically, line up exactly with the square right next to it. There should be no gaps between them. But I see little hairline gaps between them. They aren't in the same spot, depending on the zoom level, and as I zoom in and out, the gaps come and go between different squares. They never get wider than a thin hairline, regardless of how far I zoom in.

Having said that, I don't see it in all PDF viewers. If I open it in Acrobat Reader DC, I see no gaps with the sample code. I don't see gaps in Chrome either, though I think that's because when I installed Acrobat Reader it also installed a Chrome plugin as well. If I open it up in Edge, it's easy to see the hairline gaps between the shapes. There's enough of them that they can't be missed. At any zoom level.

There's a part of me that wants to just chalk it up to Edge just not being a very good PDF viewer, but I know there are going to be lots of people who view my PDFs that won't have Acrobat Reader installed, nor Chrome. So they'll see the hairline gaps. That's not very desirable.

I maybe should also mention that even with Acrobat Reader, in other scenarios besides this trivial example, I was still seeing the hairline gaps. They were just pretty rare. (And perhaps rare enough that I'd be willing to let it slide.)

Alexander Mankuta

unread,
Nov 27, 2018, 4:57:50 AM11/27/18
to Prawn
The code is relatively simple. Prawn would generate just a bunch of lines. It doesn't break thick lines into any smaller primitives and doesn't do pixel rendering.

I'm pretty convinced this is a rendering artifact and there's nothing you can do in Prawn to fix it.

RB Whitaker

unread,
Nov 27, 2018, 10:33:25 PM11/27/18
to Prawn
Yeah, that's more or less the conclusion I was coming to. I was just hoping. Oh well.
Reply all
Reply to author
Forward
0 new messages