Support multi-line text in wxSVGFileDC.
This commit is contained in:
@@ -367,11 +367,14 @@ void wxSVGFileDCImpl::DoDrawRotatedText(const wxString& sText, wxCoord x, wxCoor
|
||||
NewGraphicsIfNeeded();
|
||||
wxString s, sTmp;
|
||||
|
||||
// calculate bounding box
|
||||
wxCoord w, h, desc;
|
||||
DoGetTextExtent(sText, &w, &h, &desc);
|
||||
// Get extent of whole text.
|
||||
wxCoord w, h, heightLine;
|
||||
GetOwner()->GetMultiLineTextExtent(sText, &w, &h, &heightLine);
|
||||
|
||||
double rad = wxDegToRad(angle);
|
||||
// Compute the shift for the origin of the next line.
|
||||
const double rad = wxDegToRad(angle);
|
||||
const double dx = heightLine * sin(rad);
|
||||
const double dy = heightLine * cos(rad);
|
||||
|
||||
// wxT("upper left") and wxT("upper right")
|
||||
CalcBoundingBox(x, y);
|
||||
@@ -394,12 +397,18 @@ void wxSVGFileDCImpl::DoDrawRotatedText(const wxString& sText, wxCoord x, wxCoor
|
||||
write(s);
|
||||
}
|
||||
|
||||
// Draw all text line by line
|
||||
const wxArrayString lines = wxSplit(sText, '\n', '\0');
|
||||
for (size_t lineNum = 0; lineNum < lines.size(); lineNum++)
|
||||
{
|
||||
// convert x,y to SVG text x,y (the coordinates of the text baseline)
|
||||
x = (wxCoord)(x + (h-desc)*sin(rad));
|
||||
y = (wxCoord)(y + (h-desc)*cos(rad));
|
||||
wxCoord ww, hh, desc;
|
||||
DoGetTextExtent(lines[lineNum], &ww, &hh, &desc);
|
||||
int xx = x + wxRound(lineNum * dx) + (hh - desc) * sin(rad);
|
||||
int yy = y + wxRound(lineNum * dy) + (hh - desc) * cos(rad);
|
||||
|
||||
//now do the text itself
|
||||
s.Printf (wxT(" <text x=\"%d\" y=\"%d\" "),x,y );
|
||||
s.Printf (wxT(" <text x=\"%d\" y=\"%d\" "), xx, yy );
|
||||
|
||||
sTmp = m_font.GetFaceName();
|
||||
if (sTmp.Len() > 0) s += wxT("style=\"font-family:") + sTmp + wxT("; ");
|
||||
@@ -457,13 +466,14 @@ void wxSVGFileDCImpl::DoDrawRotatedText(const wxString& sText, wxCoord x, wxCoor
|
||||
s += sTmp;
|
||||
//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), x,y );
|
||||
s += sTmp + wxMarkupParser::Quote(sText) + wxT("</text> ") + wxT("\n");
|
||||
sTmp.Printf ( wxT("stroke-width:0;\" transform=\"rotate( %s %d %d ) \" >"), NumStr(-angle), xx, yy );
|
||||
s += sTmp + wxMarkupParser::Quote(lines[lineNum]) + wxT("</text> ") + wxT("\n");
|
||||
if (m_OK)
|
||||
{
|
||||
write(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void wxSVGFileDCImpl::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
|
||||
{
|
||||
|
Reference in New Issue
Block a user