New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
wxSVGFileDC improvements. #215
Conversation
423520f
to
488e15f
Compare
I had to remove the |
@@ -66,7 +66,8 @@ class WXDLLIMPEXP_CORE wxSVGFileDCImpl : public wxDCImpl | |||
{ | |||
public: | |||
wxSVGFileDCImpl( wxSVGFileDC *owner, const wxString &filename, | |||
int width=320, int height=240, double dpi=72.0 ); | |||
int width=320, int height=240, double dpi=72.0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should try to keep the code style consistent by using spaces around the assignment operator:
int width = 320, int height = 240, double dpi = 72.0
488e15f
to
6653e8e
Compare
Some modifications:
The text alignment was already fixed in the original code but I accidentally removed it when adding support for multi-line text. Commit below restores the original alignment fix using the text descent. |
97b16fd
to
a243ec4
Compare
@@ -66,7 +66,8 @@ class WXDLLIMPEXP_CORE wxSVGFileDCImpl : public wxDCImpl | |||
{ | |||
public: | |||
wxSVGFileDCImpl( wxSVGFileDC *owner, const wxString &filename, | |||
int width=320, int height=240, double dpi=72.0 ); | |||
int width = 320, int height = 240, double dpi = 72.0, | |||
const wxString &title = wxT("") ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hardly very important but it's better to use = wxString()
for the default value (in spite of the fact that most of the existing code doesn't do it).
Thanks, this definitely looks useful and it's great to have better SVG output support. If we could avoid adding more duplicated code (and I know there is already plenty of it), it would be really perfect... |
I addressed your comments in the new commits. The title is metadata, just like
If desired, I can rebase and cleanup some commits (as some changes have been replaced by newer commits). |
float w = pen.GetWidth(); | ||
if (pen.GetWidth() == 0) | ||
w = 1; | ||
w = w / 3; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder where do all these factors (3 here, 2, 5, 8, 10 below) come from? It would be nice to have a comment explaining it...
Sorry, I still have a few minor remarks, it would be great if you could please address them. Thanks again! |
b9914ce
to
9552250
Compare
Updated. Waiting for input on removing pointer of Relevant switch statements now include all enums. |
9552250
to
c50fd98
Compare
7d43f36
to
1e78471
Compare
#endif | ||
wxSVGFileDC svgdc(dlg.GetPath(), width, height, 72, wxT("Drawing sample")); | ||
svgdc.SetBitmapHandler(new wxSVGBitmapEmbedHandler()); | ||
m_canvas->Draw(svgdc); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This trick with swapping DC's doesn't work if "graphics screen" is displayed. In this case an empty image is saved and artefacts are displayed on the screen. It would be good to disable somehow the option to "save as SVG image" if graphics screen is active.
It was implemented 3 and half years ago in 614e38d. Close remaining clipping regions when closing the SVG file.
Each polygon in the poly-polygon needs to end with the start-point. The implementation is similar to the wxDCImpl implementation, except for the extra end points that are inserted.
Do not draw each line separately because the lines will not be connected. E.g. when editing a SVG, moving a point should also move the connecting lines.
Support underlined and strike-through text. Set the text length (see http://trac.wxwidgets.org/ticket/17271). Preserve leading and trailing white-space. Use wxS macro consistently. Closes wxWidgets#17271.
Draw a rectangle with the background colour and a transparent pen. Closes wxWidgets#15788.
Use the correct doc-type and specify the encoding. 'title' is not a valid attribute of <image> so remove it. Removed superfluous white-space and improved indenting in generated XML.
Changed the colour of the third star-polygon to test brush pattern with different colours. Use the width and height of the scroll panel as image size.
Override SetDeviceOrigin, SetLogicalOrigin and SetAxisOrientation from wxDC and mark the graphics as changed, so the correct transform translations are applied.
Ellipses with the same start and end point (circles) where not drawn because the angle becomes 0 degrees. Fixed by drawing two half circles. Do not close ellipses if a transparent brush is used (to match wxDC behavior). See issue wxWidgets#17557.
For some combinations of start and end angles, the wrong large-arc-flag was calculated. Fixed by correctly converting the wxDC angles to SVG angles (shift -90 degrees, and invert to clockwise direction). Arcs with the same start and end point (circles) where not drawn because the angle becomes 0 degrees. Fixed by drawing two half circles. Elliptic arcs with a non-transparent brush had an extra line from the center to the start point of the arc. Fixed by first drawing the arc without border, then only the border. Arcs with small angles would become invisible because the start and end point map to the same (integer) coordinate. Very large arcs would be distorted because the start and end point coordinates did not line up. Using floating point values resolves this. See issue wxWidgets#17557.
Consistent white-space usage. Use wxS macros for strings. Check if output stream is OK when writing. Removed unnecessary Borland pragmas.
1e78471
to
97c7ac4
Compare
I updated the commits to use wxS. Added an extra commit to clean-up the source code and use wxS instead of wxT. |
If there are no more comments/remarks/objections, I'm going to merge it soon. Thanks! |
…Bent/wxWidgets Many improvements in wxSVGFileDC to improve its support of wxDC API including: - Enabled usage of clipping regions. - Correctly draw polypolygons. - Draw lines as one long line instead of many short lines. - Drawing text improvements (position, multi-line, underlined, strike-through). - Support more brush and pen styles. - Add Saving as SVG to drawing sample. - Implemented Clear(). - Set the SVG title. - Produce valid svg/xml. - Correctly draw ellipses and arcs. See #215
The next wxPython release will still pull from WX_3_0_BRANCH. |
Sure, I can create a PR for 3.0 branch with all recent SVG changes. After comparing the headers I do have some concerns about ABI/API compatibility. I'll address them in the new PR. |
I can't thank you enough. These SVG fixes are badly needed on the wxPython side. |
I used the screens in the drawing sample and tried to fix most of the issues when saving them as SVG, including:
The commit messages have some more info.
There are a lot of commits to make the individual changes more obvious. I don't have any objection to squashing them together.
Screenshots as wxDC, SVG (old), SVG (new). I converted the SVGs to PNGs, hence the lower quality.
Brushes:
Lines:
Polygon:
Regions:
Text:
Circles:
SVG Arc Example: