From b424445078d0b2f16c461c66ec39b3ff0ff8d06f Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Tue, 15 Mar 2016 21:58:02 +0100 Subject: [PATCH] Improvements to printing text in wxSVGFileDC. 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 #17271. --- src/common/dcsvg.cpp | 55 ++++++++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 23 deletions(-) diff --git a/src/common/dcsvg.cpp b/src/common/dcsvg.cpp index 18e0ecff68..2ce4912543 100644 --- a/src/common/dcsvg.cpp +++ b/src/common/dcsvg.cpp @@ -365,7 +365,7 @@ void wxSVGFileDCImpl::DoDrawRotatedText(const wxString& sText, wxCoord x, wxCoor { //known bug; if the font is drawn in a scaled DC, it will not behave exactly as wxMSW NewGraphicsIfNeeded(); - wxString s, sTmp; + wxString s; // Get extent of whole text. wxCoord w, h, heightLine; @@ -376,11 +376,11 @@ void wxSVGFileDCImpl::DoDrawRotatedText(const wxString& sText, wxCoord x, wxCoor const double dx = heightLine * sin(rad); const double dy = heightLine * cos(rad); - // wxT("upper left") and wxT("upper right") + // wxS("upper left") and wxS("upper right") CalcBoundingBox(x, y); CalcBoundingBox((wxCoord)(x + w*cos(rad)), (wxCoord)(y - h*sin(rad))); - // wxT("bottom left") and wxT("bottom right") + // wxS("bottom left") and wxS("bottom right") CalcBoundingBox((wxCoord)(x + h*sin(rad)), (wxCoord)(y + h*cos(rad))); CalcBoundingBox((wxCoord)(x + h*sin(rad) + w*cos(rad)), (wxCoord)(y + h*cos(rad) - w*sin(rad))); @@ -388,12 +388,11 @@ void wxSVGFileDCImpl::DoDrawRotatedText(const wxString& sText, wxCoord x, wxCoor { // draw background first // just like DoDrawRectangle except we pass the text color to it and set the border to a 1 pixel wide text background - - sTmp.Printf ( wxT(" "), NumStr(-angle), x,y ); - s += sTmp + wxT("\n"); + s += wxString::Format(wxS(" "), NumStr(-angle), x, y); + s += wxS("\n"); write(s); } @@ -408,11 +407,13 @@ void wxSVGFileDCImpl::DoDrawRotatedText(const wxString& sText, wxCoord x, wxCoor int yy = y + wxRound(lineNum * dy) + (hh - desc) * cos(rad); //now do the text itself - s.Printf (wxT(" 0) s += wxT("style=\"font-family:") + sTmp + wxT("; "); - else s += wxT("style=\" "); + wxString fontName(m_font.GetFaceName()); + if (fontName.Len() > 0) + s += wxS("style=\"font-family:") + fontName + wxS("; "); + else + s += wxS("style=\" "); wxString fontweight; switch (m_font.GetWeight()) @@ -436,7 +437,7 @@ void wxSVGFileDCImpl::DoDrawRotatedText(const wxString& sText, wxCoord x, wxCoor wxASSERT_MSG(!fontweight.empty(), wxS("unknown font weight value")); - s += wxT("font-weight:") + fontweight + wxT("; "); + s += wxS("font-weight:") + fontweight + wxS("; "); wxString fontstyle; switch (m_font.GetStyle()) @@ -460,18 +461,26 @@ void wxSVGFileDCImpl::DoDrawRotatedText(const wxString& sText, wxCoord x, wxCoor wxASSERT_MSG(!fontstyle.empty(), wxS("unknown font style value")); - s += wxT("font-style:") + fontstyle + wxT("; "); + s += wxS("font-style:") + fontstyle + wxS("; "); - sTmp.Printf(wxT("font-size:%dpt; "), m_font.GetPointSize()); - s += sTmp; + wxString textDecoration; + if (m_font.GetUnderlined()) + textDecoration += wxS(" underline"); + if (m_font.GetStrikethrough()) + textDecoration += wxS(" line-through"); + if (textDecoration.IsEmpty()) + textDecoration = wxS(" none"); + + s += wxS("text-decoration:") + textDecoration + wxS("; "); + + s += wxString::Format(wxS("font-size:%dpt; "), m_font.GetPointSize()); //text will be solid, unless alpha value isn't opaque in the foreground colour s += wxBrushString(m_textForegroundColour) + wxPenString(m_textForegroundColour); - sTmp.Printf ( wxT("stroke-width:0;\" transform=\"rotate( %s %d %d ) \" >"), NumStr(-angle), xx, yy ); - s += sTmp + wxMarkupParser::Quote(lines[lineNum]) + wxT(" ") + wxT("\n"); - if (m_OK) - { - write(s); - } + s += wxString::Format(wxS("stroke-width:0;\" transform=\"rotate(%s %d %d)\""), NumStr(-angle), xx, yy); + s += wxS(" xml:space=\"preserve\">"); + s += wxMarkupParser::Quote(lines[lineNum]) + wxS("\n"); + + write(s); } }