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.

Any idea what wrong?

wxWidgets 3.1.0

wxPdfDocument 0.9.5

Windows 7

VS2015

Thanks very much.

## Problem Drawing Arcs to wxPDFDC

### Re: Problem Drawing Arcs to wxPDFDC

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

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.

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

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

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

Regards,

Ulrich

### Re: Problem Drawing Arcs to wxPDFDC

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

after your fix.

You can see that two of the four arcs now display correctly, but two are still wrong.

Thanks very much.

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

after your fix.

You can see that two of the four arcs now display correctly, but two are still wrong.

Thanks very much.

### Re: Problem Drawing Arcs to wxPDFDC

rsb wrote:Thanks, That did fix the initial problem I listed, however, It didn't fix everything.

I had already suspected that.

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.

Please download the current source code from wxPdfDocument at github and give a try again.

Regards,

Ulrich

### Re: Problem Drawing Arcs to wxPDFDC

Thank you. Looks very good, however circles are now not displaying.

First image is wxDC, second is PDFDC.

Thanks very much.

First image is wxDC, second is PDFDC.

Thanks very much.

### Re: Problem Drawing Arcs to wxPDFDC

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

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.

Thanks again very much.

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.

Thanks again very much.

### Re: Problem Drawing Arcs to wxPDFDC

rsb wrote:Thanks very much, That did it!

Glad to hear that.

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

Below is all we do before drawing.

int width = 5 ;

wxColour Colour = "Some Colour" ;

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

Thanks.

int width = 5 ;

wxColour Colour = "Some Colour" ;

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

Thanks.

### Re: Problem Drawing Arcs to wxPDFDC

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

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.

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

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

### Who is online

Users browsing this forum: Baidu [Spider] and 1 guest