Remove incorrect FromDIP from wxSVGFileDC

Input for wxDC functions and constructor are in DPI-independent pixels, so no scaling should be performed.
This ensures the SVG will get the same size on every platform.
This commit is contained in:
Maarten Bent
2025-09-09 21:45:40 +02:00
parent d9b9473650
commit 8b3df6cee4
+6 -12
View File
@@ -24,7 +24,6 @@
#include "wx/filename.h"
#include "wx/mstream.h"
#include "wx/scopedarray.h"
#include "wx/display.h"
#include "wx/private/rescale.h"
#if wxUSE_MARKUP
@@ -530,8 +529,8 @@ void wxSVGFileDCImpl::Init(const wxString& filename, int width, int height,
m_gradientUniqueId = 0;
m_mm_to_pix_x = dpi / 25.4;
m_mm_to_pix_y = dpi / 25.4;
m_mm_to_pix_x = m_dpi / 25.4;
m_mm_to_pix_y = m_dpi / 25.4;
m_backgroundBrush = *wxTRANSPARENT_BRUSH;
m_textForegroundColour = *wxBLACK;
@@ -555,14 +554,12 @@ void wxSVGFileDCImpl::Init(const wxString& filename, int width, int height,
else
m_outfile.reset(new wxFileOutputStream(m_filename));
const wxSize dpiSize = FromDIP(wxSize(m_width, m_height));
wxString s;
s += wxS("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n");
s += wxS("<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.0//EN\" \"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd\">\n\n");
s += wxS("<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"");
s += wxString::Format(wxS(" width=\"%scm\" height=\"%scm\" viewBox=\"0 0 %d %d\">\n"),
NumStr(m_width / dpi * 2.54), NumStr(m_height / dpi * 2.54), dpiSize.GetWidth(), dpiSize.GetHeight());
NumStr(m_width / m_dpi * 2.54), NumStr(m_height / m_dpi * 2.54), m_width, m_height);
s += wxString::Format(wxS("<title>%s</title>\n"), title);
s += wxString(wxS("<desc>Picture generated by wxSVG ")) + wxSVGVersion + wxS("</desc>\n\n");
s += wxS("<g fill=\"black\" stroke=\"black\" stroke-width=\"1\">\n");
@@ -597,14 +594,12 @@ wxSize wxSVGFileDCImpl::GetPPI() const
wxSize wxSVGFileDCImpl::FromDIP(const wxSize& sz) const
{
const wxSize baseline = wxDisplay::GetStdPPI();
return wxRescaleCoord(sz).From(baseline).To(SVG_DPI);
return sz;
}
wxSize wxSVGFileDCImpl::ToDIP(const wxSize& sz) const
{
const wxSize baseline = wxDisplay::GetStdPPI();
return wxRescaleCoord(sz).From(SVG_DPI).To(baseline);
return sz;
}
void wxSVGFileDCImpl::Clear()
@@ -612,8 +607,7 @@ void wxSVGFileDCImpl::Clear()
{
wxDCBrushChanger setBackground(*GetOwner(), m_backgroundBrush);
wxDCPenChanger setTransp(*GetOwner(), *wxTRANSPARENT_PEN);
const wxSize dpiSize = FromDIP(wxSize(m_width, m_height));
DoDrawRectangle(0, 0, dpiSize.GetWidth(), dpiSize.GetHeight());
DoDrawRectangle(0, 0, m_width, m_height);
}
NewGraphicsIfNeeded();