PDFsharp & MigraDoc Foundation
http://forum.pdfsharp.com/

rectangles drawn at the same x, y coord don't align
http://forum.pdfsharp.com/viewtopic.php?f=2&t=3283
Page 1 of 1

Author:  fatootie [ Tue Feb 02, 2016 1:01 am ]
Post subject:  rectangles drawn at the same x, y coord don't align

I have code similar to the following which draws two overlapping rectangles which share the same top-left corner coordinates.

Code:
  PdfDocument document = new PdfDocument();
  PdfPage page = document.AddPage();
  XGraphics gfx = XGraphics.FromPdfPage(page);
  gfx.DrawRectangle(XBrushes.Black, 11, 11, 0.5, 100);
  gfx.DrawRectangle(XBrushes.Red, 11, 11, 100, 0.5);


When I view the resulting PDF at 100% zoom, the top left corners of those rectangles appear to overshoot so that rather than making a clean corner they make a "+" shape.

Attachment:
RectanglesDontAlign.png
RectanglesDontAlign.png [ 8.87 KiB | Viewed 5618 times ]


This effect makes the output of my program look unprofessional. What am I doing wrong? If anyone has any insights I would be most grateful.

I attached a zip with the example source file.

Attachments:
File comment: Source, output pdf, and magnified screenshot showing the effect.
RectanglesDontAlign.zip [7.1 KiB]
Downloaded 561 times

Author:  Thomas Hoevel [ Wed Feb 03, 2016 9:08 am ]
Post subject:  Re: rectangles drawn at the same x, y coord don't align

Hi!
fatootie wrote:
This effect makes the output of my program look unprofessional.
If you think so.

In my experience Adobe Reader often shows such glitches. It's one pixel off at 100%, it's one pixel of at 1600%, it's one pixel off at 6400%.

Adobe Reader display options may also have an effect on this.

Author:  Thomas Hoevel [ Wed Feb 03, 2016 9:33 am ]
Post subject:  Re: rectangles drawn at the same x, y coord don't align

File looks fine with Chrome, Firefox, Reader (that MS thingy that comes with Windows 10), and Edge.
It looks correct with Adobe Reader 11 if the option "Enhance thin lines" under Preferences => Page Display is off.

It sometimes looks better if you specify the lower corner and use a negative height:
Code:
            gfx.DrawRectangle(XBrushes.Black, 20, 120, 0.5, -100);
            gfx.DrawRectangle(XBrushes.Red, 20, 20.5, 100, -0.5);


At 100% the inverted version looks correct, at 150% the original version looks correct and the inverted version overlaps, at 200% both look correct.
It is an Adobe Reader mystery and I guess you will have to live with it.
AFAIK you cannot control (override) the "Enhance thin lines" from a PDF file.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/