wxPdfDocument: Plotting a Rotated Rectangle

Talk here about issues with one of the components hosted at wxCode, or suggest features for it.
rsb
I live to help wx-kind
I live to help wx-kind
Posts: 164
Joined: Fri May 29, 2015 7:26 pm

wxPdfDocument: Plotting a Rotated Rectangle

Post by rsb » Tue Jul 14, 2020 3:45 pm

Hello,

In wxWidgets, we're using the wxAffineMatrix2D class to display a rotated rectangle. Below is a small sample of the
code we use. This code works great on a panel but when we use the wxPdfDC class, the rectangle disappears.
Is this the correct way to display a rotated rectangle in this library or is there another way.

Thanks,
RSB

We're using:
wxWidgets: 3.1.0
wxpdfdoc 0.9.5
Compiler: MSVC 14
Platform: Windows 10 (2004).

Code: Select all

        double radians = degree__convert_to_radian(360 - orientation) ;
        
        wxAffineMatrix2D mat = dc->GetTransformMatrix() ;
        mat.Translate(origin_position.x_coord, origin_position.y_coord);
        mat.Rotate(radians) ;
        dc->SetTransformMatrix(mat);
        dc->DrawRoundedRectangle(-width / 2, -height / 2, width, height, radius)  ;
        dc->ResetTransformMatrix();
Last edited by doublemax on Tue Jul 14, 2020 4:05 pm, edited 1 time in total.
Reason: make title more specific

utelle
Moderator
Moderator
Posts: 973
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Re: wxPdfDocument: Plotting a Rotated Rectangle

Post by utelle » Tue Jul 14, 2020 11:07 pm

rsb wrote:
Tue Jul 14, 2020 3:45 pm
In wxWidgets, we're using the wxAffineMatrix2D class to display a rotated rectangle. Below is a small sample of the
code we use. This code works great on a panel but when we use the wxPdfDC class, the rectangle disappears.
Is this the correct way to display a rotated rectangle in this library or is there another way.
Unfortunately, wxPdfDC currently does not support the use of a transformation matrix - although the wxPdfDocument class itself does support transformations.

In principle it shouldn't be too hard to add this functionality to wxPdfDC. I will look into this, but I can't predict how long it will take to implement this feature.

Regards,

Ulrich

utelle
Moderator
Moderator
Posts: 973
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Re: wxPdfDocument: Plotting a Rotated Rectangle

Post by utelle » Tue Aug 25, 2020 9:44 pm

rsb wrote:
Tue Jul 14, 2020 3:45 pm
In wxWidgets, we're using the wxAffineMatrix2D class to display a rotated rectangle. Below is a small sample of the
code we use. This code works great on a panel but when we use the wxPdfDC class, the rectangle disappears.
Is this the correct way to display a rotated rectangle in this library or is there another way.
The latest master of wxPdfDocument now supports the use of a transformation matrix. Please give it a try and report back, if you experience problems.

rsb
I live to help wx-kind
I live to help wx-kind
Posts: 164
Joined: Fri May 29, 2015 7:26 pm

Re: wxPdfDocument: Plotting a Rotated Rectangle

Post by rsb » Thu Sep 03, 2020 7:37 pm

Hi Utelle,

Thanks for updating, but does not seem to be working unless I'm doing something wrong.
I see the new functions so I believe I built it correctly but no output at all.
Rounded rectangles at 0 degree rotation display correctly.
Below is the code I'm using.

Thanks.

Code: Select all

wxAffineMatrix2D mat = dc->GetTransformMatrix() ;
mat.Translate(origin_position.x_coord, origin_position.y_coord);
mat.Rotate(radians) ;
dc->SetTransformMatrix(mat);
dc->DrawRoundedRectangle(-width / 2, -height / 2, width, height, radius)  ;
dc->ResetTransformMatrix();

utelle
Moderator
Moderator
Posts: 973
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Re: wxPdfDocument: Plotting a Rotated Rectangle

Post by utelle » Thu Sep 03, 2020 8:58 pm

rsb wrote:
Thu Sep 03, 2020 7:37 pm
Thanks for updating, but does not seem to be working unless I'm doing something wrong.
I see the new functions so I believe I built it correctly but no output at all.
Rounded rectangles at 0 degree rotation display correctly.
Well, I tested the new functions by adding calls to them locally in the DC sample coming with wxPdfDocument. The rotated rounded rectangles were visible on screen as well as in the resulting PDFs. That is, I'm pretty sure that the code works if used correctly.

Have you verified that pen and brush are set before drawing the rounded rectangle?

Which version of wxWidgets are you using? I tested with version 3.1.4. Have you debugged your application to verify that the new functions are actually called?
rsb wrote:
Thu Sep 03, 2020 7:37 pm
Below is the code I'm using.

Code: Select all

wxAffineMatrix2D mat = dc->GetTransformMatrix() ;
mat.Translate(origin_position.x_coord, origin_position.y_coord);
mat.Rotate(radians) ;
dc->SetTransformMatrix(mat);
dc->DrawRoundedRectangle(-width / 2, -height / 2, width, height, radius)  ;
dc->ResetTransformMatrix();
In principle, this code should work. The sequence of calls is the same as in my own tests.

Could you supply code for a minimal sample which exhibits the problem in your environment?

rsb
I live to help wx-kind
I live to help wx-kind
Posts: 164
Joined: Fri May 29, 2015 7:26 pm

Re: wxPdfDocument: Plotting a Rotated Rectangle

Post by rsb » Fri Sep 04, 2020 4:11 pm

Hi,

I was using wxWidgets 3.1.0, then upgraded to 3.1.4 but still don't see anything. I'm running
in debug and stepped into the wxpdfdoc code and I do see the new functions you added. It
looks fine on a wxWidgets panel so I assume the pen and brush are set correctly.
I also added wxUSE_DC_TRANSFORM_MATRIX to the project settings pre-processor definitions.
I'll try to come up with a test program.

Thanks for your help.

utelle
Moderator
Moderator
Posts: 973
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Re: wxPdfDocument: Plotting a Rotated Rectangle

Post by utelle » Fri Sep 04, 2020 5:19 pm

rsb wrote:
Fri Sep 04, 2020 4:11 pm
I was using wxWidgets 3.1.0, then upgraded to 3.1.4 but still don't see anything.
So obviously the problem you experience is not related to the wxWidgets version. Good to know, even though it doesn't solve the puzzle.
rsb wrote:
Fri Sep 04, 2020 4:11 pm
I'm running in debug and stepped into the wxpdfdoc code and I do see the new functions you added.
Seeing them is one thing, the other whether they are actually executed. Did you check that, too?
rsb wrote:
Fri Sep 04, 2020 4:11 pm
It looks fine on a wxWidgets panel so I assume the pen and brush are set correctly.
I also added wxUSE_DC_TRANSFORM_MATRIX to the project settings pre-processor definitions.
Now, this is really strange. I don't have the slightest idea, how to explain why you don't see the elements in the PDF.
rsb wrote:
Fri Sep 04, 2020 4:11 pm
I'll try to come up with a test program.
It would be great to have a small test program to reproduce the problem. This would help in analyzing the issue.

One test you could do, would be to take the DC sample coming with wxPdfDocument and add code for drawing a rotated rectangle.

And maybe you could send me one of your resulting PDF files - as PM if it is confidential. However, please use method SetCompression(false) on the wxPdfDocument instance, because that makes it easier for me to analyze the PDF content.
rsb wrote:
Fri Sep 04, 2020 4:11 pm
Thanks for your help.
You are welcome.

rsb
I live to help wx-kind
I live to help wx-kind
Posts: 164
Joined: Fri May 29, 2015 7:26 pm

Re: wxPdfDocument: Plotting a Rotated Rectangle

Post by rsb » Fri Sep 04, 2020 6:50 pm

Okay, I've added a screen shot of two rectangles, one rotated and one not as well
as two PDF files. One output from our GDI routines (TEST_GDI.pdf) and the other
from the wxPdfDoc library (TEST_PDF.pdf). Maybe it will shed some light on what is wrong.
Thanks.
Attachments
RoundedRectangleTest.7z
(23.38 KiB) Downloaded 28 times

utelle
Moderator
Moderator
Posts: 973
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Re: wxPdfDocument: Plotting a Rotated Rectangle

Post by utelle » Fri Sep 04, 2020 9:07 pm

rsb wrote:
Fri Sep 04, 2020 6:50 pm
Okay, I've added a screen shot of two rectangles, one rotated and one not as well
as two PDF files. One output from our GDI routines (TEST_GDI.pdf) and the other
from the wxPdfDoc library (TEST_PDF.pdf). Maybe it will shed some light on what is wrong.
Thanks. I'll take a look over the weekend.

utelle
Moderator
Moderator
Posts: 973
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Re: wxPdfDocument: Plotting a Rotated Rectangle

Post by utelle » Fri Sep 04, 2020 10:17 pm

rsb wrote:
Fri Sep 04, 2020 6:50 pm
Okay, I've added a screen shot of two rectangles, one rotated and one not as well
as two PDF files. One output from our GDI routines (TEST_GDI.pdf) and the other
from the wxPdfDoc library (TEST_PDF.pdf). Maybe it will shed some light on what is wrong.
I couldn't resist to check the PDF file immediately. :)

In principle, the rotated rectangle is in the PDF file. However, something went wrong with the transformation matrix. The x-y-translation is way too big. As a result the rectangle is moved to a position outside the page area and is therefore invisible.

My guess is that it is somehow necessary to apply a scale factor to the translation vector, before applying the PDF transformation matrix. That is, most likely method SetTransformMatrix of wxPdfDC will have to take scaling into account. Could you please let me know which mapping mode your application uses?

rsb
I live to help wx-kind
I live to help wx-kind
Posts: 164
Joined: Fri May 29, 2015 7:26 pm

Re: wxPdfDocument: Plotting a Rotated Rectangle

Post by rsb » Fri Sep 04, 2020 11:34 pm

We're using wxMM_TEXT.

Thanks.

utelle
Moderator
Moderator
Posts: 973
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Re: wxPdfDocument: Plotting a Rotated Rectangle

Post by utelle » Sat Sep 05, 2020 1:13 pm

rsb wrote:
Fri Sep 04, 2020 11:34 pm
We're using wxMM_TEXT.
The DC sample of wxPdfDocument uses wxMM_POINTS. However, due to the value of the default resolution this results in the same scaling factor as wxMM_TEXT. That is, this also doesn't explain the issue.

Could you please describe how you derive the translation vector of the transformation matrix? Maybe the calculation is related to screen resolution and would require adjustments for the PDF output. For example, if you have a hires screen you would have to adjust the wxPdfDC resolution. wxPdfDC uses A4 paper as the default medium size, and 72 pixel per inch as the default resolution. That is, the default width of the wxPdfDC canvas is 595 pixel. However, the x component of your translation vector is about 7,5 times larger.

rsb
I live to help wx-kind
I live to help wx-kind
Posts: 164
Joined: Fri May 29, 2015 7:26 pm

Re: wxPdfDocument: Plotting a Rotated Rectangle

Post by rsb » Sat Sep 05, 2020 9:59 pm

The origin is specified in display units. I'm seeing values of x: 6591 and y: 5946
and the rotation is in radians (5.49778).
The origin is the center of the rectangle.

Code: Select all

mat.Translate(origin_position.x_coord, origin_position.y_coord);
mat.Rotate(radians) ;
The PPI is 96 in the x and y direction, using the dc->GetPPI method.

utelle
Moderator
Moderator
Posts: 973
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Re: wxPdfDocument: Plotting a Rotated Rectangle

Post by utelle » Sat Sep 05, 2020 11:40 pm

rsb wrote:
Sat Sep 05, 2020 9:59 pm
The origin is specified in display units. I'm seeing values of x: 6591 and y: 5946
and the rotation is in radians (5.49778).
The origin is the center of the rectangle.
Well, if you use x: 6591 and y: 5946 as coordinates when drawing to a wxPdfDC with default settings, you are drawing outside the available page size, unless you adjust the wxPdfDC resolution. Which values do you get when calling GetSize on your display DC?
rsb wrote:
Sat Sep 05, 2020 9:59 pm

Code: Select all

mat.Translate(origin_position.x_coord, origin_position.y_coord);
mat.Rotate(radians) ;
The PPI is 96 in the x and y direction, using the dc->GetPPI method.
Let's take x: 6591. 6591 pixel / 96 ppi = 68,65625 inch = 174,387 cm. I can hardly believe that your screen width is really that large.

It will be necessary to set up the wxPdfDC properly, so that the page format and orientation as well as the resolution (ppi) allow to map the screen coordinates correctly to PDF coordinates. That will be a task of your application.

Most likely it will be also necessary to adjust the wxPdfDC by scaling the translation vector depending on mapping mode and resolution. That will be my part.

rsb
I live to help wx-kind
I live to help wx-kind
Posts: 164
Joined: Fri May 29, 2015 7:26 pm

Re: wxPdfDocument: Plotting a Rotated Rectangle

Post by rsb » Mon Sep 07, 2020 2:16 pm

I'm sorry Utelle, I got the PPI wrong. The screen DC returns 96, the wxPdfDC returns 1200.
GetSize() returns x: 13,200 and y: 10,200

Post Reply