mirror of
https://github.com/wxWidgets/wxWidgets.git
synced 2026-08-17 08:53:06 +08:00
Save SVG files with the actual drawing size
First render to a temporary wxSVGFileDC, then use the size of the bounding box as input for the actual SVG size. Use a slightly larger size to account for lines drawn with a bigger wxPen width.
This commit is contained in:
@@ -2790,13 +2790,16 @@ void MyFrame::OnSave(wxCommandEvent& WXUNUSED(event))
|
||||
wxGraphicsRenderer* tempRenderer = m_canvas->GetRenderer();
|
||||
m_canvas->UseGraphicRenderer(nullptr);
|
||||
#endif
|
||||
wxSVGFileDC svgdc(dlg.GetPath(),
|
||||
canvasSize.GetWidth(),
|
||||
canvasSize.GetHeight(),
|
||||
72,
|
||||
"Drawing sample");
|
||||
svgdc.SetBitmapHandler(new wxSVGBitmapEmbedHandler());
|
||||
m_canvas->Draw(svgdc);
|
||||
wxSize svgSize;
|
||||
wxSVGFileDC tempSvgDC("", svgSize.x, svgSize.y, 72, "Drawing sample");
|
||||
m_canvas->Draw(tempSvgDC);
|
||||
|
||||
svgSize = wxSize(tempSvgDC.MaxX(), tempSvgDC.MaxY());
|
||||
svgSize.IncBy(15); // account for wxPen width exceeding bounds
|
||||
|
||||
wxSVGFileDC svgDC(dlg.GetPath(), svgSize.x, svgSize.y, 72, "Drawing sample");
|
||||
svgDC.SetBitmapHandler(new wxSVGBitmapEmbedHandler());
|
||||
m_canvas->Draw(svgDC);
|
||||
#if wxUSE_GRAPHICS_CONTEXT
|
||||
m_canvas->UseGraphicRenderer(tempRenderer);
|
||||
#endif
|
||||
|
||||
+10
-1
@@ -235,8 +235,17 @@ MyPage::MyPage(wxNotebook *parent, int index)
|
||||
|
||||
bool MyPage::OnSave(const wxString& filename)
|
||||
{
|
||||
wxSVGFileDC svgDC(filename, 600, 650, 72, pageNames[m_index]);
|
||||
wxSize svgSize;
|
||||
wxSVGFileDC tempSvgDC("", svgSize.x, svgSize.y, 72, pageNames[m_index]);
|
||||
OnDraw(tempSvgDC);
|
||||
|
||||
svgSize = wxSize(tempSvgDC.MaxX(), tempSvgDC.MaxY());
|
||||
svgSize.IncBy(15); // account for wxPen width exceeding bounds
|
||||
|
||||
wxSVGFileDC svgDC(filename, svgSize.x, svgSize.y, 72, pageNames[m_index]);
|
||||
svgDC.SetBitmapHandler(new wxSVGBitmapEmbedHandler());
|
||||
OnDraw(svgDC);
|
||||
|
||||
return svgDC.IsOk();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user