Page 1 of 1

### Problem Drawing Arcs to wxPDFDC

Posted: Mon Mar 20, 2017 8:24 pm
Hello,

I'm drawing an arc using a wxDC object and it looks fine, (first picture). However,
when I draw the same arc using a wxPDFDC object, it's not right (second picture).
In the pictures, there are two arcs, the arc to the left of the plus sign in the first
picture is wrong in the PDF document.
DCArc.PNG (1.96 KiB) Viewed 4308 times
PDFArc.PNG (2.29 KiB) Viewed 4308 times
Any idea what wrong?

wxWidgets 3.1.0
wxPdfDocument 0.9.5
Windows 7
VS2015

Thanks very much.

### Re: Problem Drawing Arcs to wxPDFDC

Posted: Mon Mar 20, 2017 9:37 pm
rsb wrote:I'm drawing an arc using a wxDC object and it looks fine, (first picture). However,
when I draw the same arc using a wxPDFDC object, it's not right (second picture).
In the pictures, there are two arcs, the arc to the left of the plus sign in the first
picture is wrong in the PDF document.
Could you please provide the code you use to draw the arcs? This would help to analyze the problem. Thanks.

Regards,

Ulrich

### Re: Problem Drawing Arcs to wxPDFDC

Posted: Mon Mar 20, 2017 9:56 pm
Hope this is good enough:

if( start_angle < end_angle )
{
if( start_angle <= mid_angle && mid_angle <= end_angle )
dc.DrawArc(startPoint.x, startPoint.y, endPoint.x, endPoint.y, centerPoint.x, centerPoint.y);
else
dc.DrawArc(endPoint.x, endPoint.y, startPoint.x, startPoint.y, centerPoint.x, centerPoint.y);
}
else
{
if( end_angle <= mid_angle && mid_angle <= start_angle )
dc.DrawArc(endPoint.x, endPoint.y, startPoint.x, startPoint.y, centerPoint.x, centerPoint.y);
else
dc.DrawArc(startPoint.x, startPoint.y, endPoint.x, endPoint.y, centerPoint.x, centerPoint.y);
}

Start, mid and end angles are determined using:

start angle --> atan2((double) start.y - center.y,(double) start.x - center.x))
mid angle --> atan2((double) mid.y - center.y,(double) mid.x - center.x))
end angle --> atan2((double) end.y - center.y,(double) end.x - center.x))

Thanks.

### Re: Problem Drawing Arcs to wxPDFDC

Posted: Tue Mar 21, 2017 7:32 am
rsb wrote:Hope this is good enough:

if( start_angle < end_angle )
{
if( start_angle <= mid_angle && mid_angle <= end_angle )
dc.DrawArc(startPoint.x, startPoint.y, endPoint.x, endPoint.y, centerPoint.x, centerPoint.y);
else
dc.DrawArc(endPoint.x, endPoint.y, startPoint.x, startPoint.y, centerPoint.x, centerPoint.y);
}
else
{
if( end_angle <= mid_angle && mid_angle <= start_angle )
dc.DrawArc(endPoint.x, endPoint.y, startPoint.x, startPoint.y, centerPoint.x, centerPoint.y);
else
dc.DrawArc(startPoint.x, startPoint.y, endPoint.x, endPoint.y, centerPoint.x, centerPoint.y);
}

Start, mid and end angles are determined using:

start angle --> atan2((double) start.y - center.y,(double) start.x - center.x))
mid angle --> atan2((double) mid.y - center.y,(double) mid.x - center.x))
end angle --> atan2((double) end.y - center.y,(double) end.x - center.x))

Thanks.
Your given code draws only exactly 1 arc. Is the same code used to draw both arcs? If yes, you need 2 sets of points for start, mid, end, and center. I have no clue whether both sets share the same mid point or not, and how you derived the center points. Could you please provide a sample set of points showing the observed behaviour?

Obviously the problem has something to do with how the drawing direction of the arc is derived from the angles.

Regards,

Ulrich

### Re: Problem Drawing Arcs to wxPDFDC

Posted: Thu Mar 23, 2017 4:48 pm
Although I doubt that your code works correctly as given (I experienced always the wrong drawing direction on screen), I applied a small fix to the wxPdfDC implementation that hopefully fixes your problem without introducing new ones. Please download the current source code from wxPdfDocument at github and give it a try.

Regards,

Ulrich

### Re: Problem Drawing Arcs to wxPDFDC

Posted: Tue Mar 28, 2017 8:54 pm
Thanks, That did fix the initial problem I listed, however, It didn't fix everything.

Here's a test case that we use. The first image is the Screen DC,
The second is the PDF DC before your fix, the third is the PDF DC

You can see that two of the four arcs now display correctly, but two are still wrong.
ArcsWxDC.PNG (8.72 KiB) Viewed 4224 times
ArcsPDFBeforeFix.PNG (2.14 KiB) Viewed 4224 times
ArcsPDFAfterFix.PNG (3.92 KiB) Viewed 4224 times
Thanks very much.

### Re: Problem Drawing Arcs to wxPDFDC

Posted: Wed Mar 29, 2017 6:51 pm
rsb wrote:Thanks, That did fix the initial problem I listed, however, It didn't fix everything.
rsb wrote:Here's a test case that we use. [...]
Ok, I see. The underlying method for drawing the arcs in PDF, wxPdfDocument::Ellipse, did not handle the drawing direction correctly. I applied a fix, so that it should now operate as expected.

Regards,

Ulrich

### Re: Problem Drawing Arcs to wxPDFDC

Posted: Wed Mar 29, 2017 7:35 pm
Thank you. Looks very good, however circles are now not displaying.

First image is wxDC, second is PDFDC.
wxCircles.PNG (6.33 KiB) Viewed 4189 times
PDFCircles.PNG (1.2 KiB) Viewed 4189 times
Thanks very much.

### Re: Problem Drawing Arcs to wxPDFDC

Posted: Wed Mar 29, 2017 9:02 pm
rsb wrote:Thank you. Looks very good, however circles are now not displaying.
Arrggh ... that's the problem with hot fixes ... overlooking special cases.

I hope that now all cases are handled properly ...

Please download the current source code from wxPdfDocument at github (only file pdfgraphics.cpp changed) and give a try again.

Regards,

Ulrich

### Re: Problem Drawing Arcs to wxPDFDC

Posted: Wed Mar 29, 2017 10:19 pm
Thanks very much, That did it!

I've got one more issue that I was hoping you could take a look at.

The width of lines displayed in wxDC is not the same as in PDFDC.

It does look like there is some thickness to lines greater than one, but
it's not the same.
wxDCLineWidths.PNG (8.88 KiB) Viewed 4174 times
PDFLineWidths.PNG (5.21 KiB) Viewed 4174 times
Thanks again very much.

### Re: Problem Drawing Arcs to wxPDFDC

Posted: Thu Mar 30, 2017 2:52 pm
rsb wrote:Thanks very much, That did it!
rsb wrote:I've got one more issue that I was hoping you could take a look at.

The width of lines displayed in wxDC is not the same as in PDFDC.

It does look like there is some thickness to lines greater than one, but
it's not the same.
Unfortunately I was not able to reproduce this problem. I added a few circles with different line widths to the wxPdfDC sample coming with wxPdfDocument. The circles were shown in PDF with the same line widths as on screen.

Of course, my experiment doesn't prove that there is no problem in wxPdfDocument. It only shows that the problem may depend on the actual generating code.

If you could provide code for a minimal sample for which you experience the problem, I will further investigate the issue.

Regards,

Ulrich

### Re: Problem Drawing Arcs to wxPDFDC

Posted: Thu Mar 30, 2017 3:31 pm
Below is all we do before drawing.

int width = 5 ;
wxColour Colour = "Some Colour" ;

dc.SetPen(wxPen(Colour,width,wxSOLID)) ;

Thanks.

### Re: Problem Drawing Arcs to wxPDFDC

Posted: Thu Mar 30, 2017 4:04 pm
rsb wrote:Below is all we do before drawing.

int width = 5 ;
wxColour Colour = "Some Colour" ;

dc.SetPen(wxPen(Colour,width,wxSOLID)) ;
Well, as I said I added corresponding code to the wxPdfDC sample coming with wxPdfDocument. And I was not able to reproduce the problem you experienced. For me the sample produced correct PDF output.

A single line of code doesn't help to analyze the context. What do you expect?

I would need a complete minimal sample demonstrating the problem (if possible together with the generated PDF file). If you prefer, we can switch to private mail.

Regards,

Ulrich

### Re: Problem Drawing Arcs to wxPDFDC

Posted: Thu Mar 30, 2017 6:02 pm
Well, I'm not able to recreate the problem in the minimal sample either.

I can probably get around it by doubling the line width when using the pdf dc.

Thanks very much for your help.

### Re: Problem Drawing Arcs to wxPDFDC

Posted: Thu Mar 30, 2017 7:23 pm
rsb wrote:Well, I'm not able to recreate the problem in the minimal sample either.
As said this doesn't prove anything. Nevertheless there can be a bug in the wxPdfDC or wxPdfDocument code, for example, something like not remembering a pen state correctly.

Obviously in the context of your own code you experience the incorrect behaviour. So there is something fishy under the hood. And I certainly would like to find out, what's causing the problem for you, and whether it is related to wxPdfDocument or not.
rsb wrote:I can probably get around it by doubling the line width when using the pdf dc.
Maybe yes, maybe no. The problem with working around the issue like that might cause further problems later on, when you further extend your application.

The only chance I see to track down the problem is to strip down your own code as much as possible, so that it still produces the incorrect results, and then provide it to me for further inspection. I can't do more than offering my help, but it's up to you to decide.

Regards,

Ulrich