Use floating point positions in wxSVGFileDC DrawRotatedText and DrawEllipse

This commit is contained in:
Maarten Bent
2019-08-10 20:52:15 +02:00
parent 9412aea1f6
commit 75f08dfd51

View File

@@ -668,15 +668,15 @@ void wxSVGFileDCImpl::DoDrawRotatedText(const wxString& sText, wxCoord x, wxCoor
const wxArrayString lines = wxSplit(sText, '\n', '\0'); const wxArrayString lines = wxSplit(sText, '\n', '\0');
for (size_t lineNum = 0; lineNum < lines.size(); lineNum++) for (size_t lineNum = 0; lineNum < lines.size(); lineNum++)
{ {
const int xRect = x + wxRound(lineNum * dx); const double xRect = x + lineNum * dx;
const int yRect = y + wxRound(lineNum * dy); const double yRect = y + lineNum * dy;
// convert x,y to SVG text x,y (the coordinates of the text baseline) // convert x,y to SVG text x,y (the coordinates of the text baseline)
wxCoord ww, hh, desc; wxCoord ww, hh, desc;
wxString const& line = lines[lineNum]; wxString const& line = lines[lineNum];
DoGetTextExtent(line, &ww, &hh, &desc); DoGetTextExtent(line, &ww, &hh, &desc);
const int xText = xRect + (hh - desc) * sin(rad); const double xText = xRect + (hh - desc) * sin(rad);
const int yText = yRect + (hh - desc) * cos(rad); const double yText = yRect + (hh - desc) * cos(rad);
if (m_backgroundMode == wxBRUSHSTYLE_SOLID) if (m_backgroundMode == wxBRUSHSTYLE_SOLID)
{ {
@@ -687,23 +687,23 @@ void wxSVGFileDCImpl::DoDrawRotatedText(const wxString& sText, wxCoord x, wxCoor
wxStrokeString(m_textBackgroundColour)); wxStrokeString(m_textBackgroundColour));
const wxString rectTransform = wxString::Format( const wxString rectTransform = wxString::Format(
wxS("transform=\"rotate(%s %d %d)\""), wxS("transform=\"rotate(%s %s %s)\""),
NumStr(-angle), xRect, yRect); NumStr(-angle), NumStr(xRect), NumStr(yRect));
s = wxString::Format( s = wxString::Format(
wxS(" <rect x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" %s %s/>\n"), wxS(" <rect x=\"%s\" y=\"%s\" width=\"%d\" height=\"%d\" %s %s/>\n"),
xRect, yRect, ww, hh, rectStyle, rectTransform); NumStr(xRect), NumStr(yRect), ww, hh, rectStyle, rectTransform);
write(s); write(s);
} }
const wxString transform = wxString::Format( const wxString transform = wxString::Format(
wxS("transform=\"rotate(%s %d %d)\""), wxS("transform=\"rotate(%s %s %s)\""),
NumStr(-angle), xText, yText); NumStr(-angle), NumStr(xText), NumStr(yText));
s = wxString::Format( s = wxString::Format(
wxS(" <text x=\"%d\" y=\"%d\" textLength=\"%d\" %s %s>%s</text>\n"), wxS(" <text x=\"%s\" y=\"%s\" textLength=\"%d\" %s %s>%s</text>\n"),
xText, yText, ww, style, transform, NumStr(xText), NumStr(yText), ww, style, transform,
#if wxUSE_MARKUP #if wxUSE_MARKUP
wxMarkupParser::Quote(line) wxMarkupParser::Quote(line)
#else #else
@@ -804,12 +804,12 @@ void wxSVGFileDCImpl::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord
{ {
NewGraphicsIfNeeded(); NewGraphicsIfNeeded();
int rh = height / 2; const double rh = height / 2.0;
int rw = width / 2; const double rw = width / 2.0;
wxString s; wxString s;
s = wxString::Format(wxS(" <ellipse cx=\"%d\" cy=\"%d\" rx=\"%d\" ry=\"%d\" %s"), s = wxString::Format(wxS(" <ellipse cx=\"%s\" cy=\"%s\" rx=\"%s\" ry=\"%s\" %s"),
x + rw, y + rh, rw, rh, wxGetPenPattern(m_pen)); NumStr(x + rw), NumStr(y + rh), NumStr(rw), NumStr(rh), wxGetPenPattern(m_pen));
s += wxS("/>\n"); s += wxS("/>\n");
write(s); write(s);