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();
|
NewGraphicsIfNeeded();
|
||||||
wxString s, sTmp;
|
wxString s, sTmp;
|
||||||
|
|
||||||
// calculate bounding box
|
// Get extent of whole text.
|
||||||
wxCoord w, h, desc;
|
wxCoord w, h, heightLine;
|
||||||
DoGetTextExtent(sText, &w, &h, &desc);
|
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")
|
// wxT("upper left") and wxT("upper right")
|
||||||
CalcBoundingBox(x, y);
|
CalcBoundingBox(x, y);
|
||||||
@@ -394,74 +397,81 @@ void wxSVGFileDCImpl::DoDrawRotatedText(const wxString& sText, wxCoord x, wxCoor
|
|||||||
write(s);
|
write(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
// convert x,y to SVG text x,y (the coordinates of the text baseline)
|
// Draw all text line by line
|
||||||
x = (wxCoord)(x + (h-desc)*sin(rad));
|
const wxArrayString lines = wxSplit(sText, '\n', '\0');
|
||||||
y = (wxCoord)(y + (h-desc)*cos(rad));
|
for (size_t lineNum = 0; lineNum < lines.size(); lineNum++)
|
||||||
|
|
||||||
//now do the text itself
|
|
||||||
s.Printf (wxT(" <text x=\"%d\" y=\"%d\" "),x,y );
|
|
||||||
|
|
||||||
sTmp = m_font.GetFaceName();
|
|
||||||
if (sTmp.Len() > 0) s += wxT("style=\"font-family:") + sTmp + wxT("; ");
|
|
||||||
else s += wxT("style=\" ");
|
|
||||||
|
|
||||||
wxString fontweight;
|
|
||||||
switch ( m_font.GetWeight() )
|
|
||||||
{
|
{
|
||||||
case wxFONTWEIGHT_MAX:
|
// convert x,y to SVG text x,y (the coordinates of the text baseline)
|
||||||
wxFAIL_MSG( wxS("invalid font weight value") );
|
wxCoord ww, hh, desc;
|
||||||
wxFALLTHROUGH;
|
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);
|
||||||
|
|
||||||
case wxFONTWEIGHT_NORMAL:
|
//now do the text itself
|
||||||
fontweight = wxS("normal");
|
s.Printf (wxT(" <text x=\"%d\" y=\"%d\" "), xx, yy );
|
||||||
break;
|
|
||||||
|
|
||||||
case wxFONTWEIGHT_LIGHT:
|
sTmp = m_font.GetFaceName();
|
||||||
fontweight = wxS("lighter");
|
if (sTmp.Len() > 0) s += wxT("style=\"font-family:") + sTmp + wxT("; ");
|
||||||
break;
|
else s += wxT("style=\" ");
|
||||||
|
|
||||||
case wxFONTWEIGHT_BOLD:
|
wxString fontweight;
|
||||||
fontweight = wxS("bold");
|
switch (m_font.GetWeight())
|
||||||
break;
|
{
|
||||||
}
|
case wxFONTWEIGHT_MAX:
|
||||||
|
wxFAIL_MSG(wxS("invalid font weight value"));
|
||||||
|
wxFALLTHROUGH;
|
||||||
|
|
||||||
wxASSERT_MSG( !fontweight.empty(), wxS("unknown font weight value") );
|
case wxFONTWEIGHT_NORMAL:
|
||||||
|
fontweight = wxS("normal");
|
||||||
|
break;
|
||||||
|
|
||||||
s += wxT("font-weight:") + fontweight + wxT("; ");
|
case wxFONTWEIGHT_LIGHT:
|
||||||
|
fontweight = wxS("lighter");
|
||||||
|
break;
|
||||||
|
|
||||||
wxString fontstyle;
|
case wxFONTWEIGHT_BOLD:
|
||||||
switch ( m_font.GetStyle() )
|
fontweight = wxS("bold");
|
||||||
{
|
break;
|
||||||
case wxFONTSTYLE_MAX:
|
}
|
||||||
wxFAIL_MSG( wxS("invalid font style value") );
|
|
||||||
wxFALLTHROUGH;
|
|
||||||
|
|
||||||
case wxFONTSTYLE_NORMAL:
|
wxASSERT_MSG(!fontweight.empty(), wxS("unknown font weight value"));
|
||||||
fontstyle = wxS("normal");
|
|
||||||
break;
|
|
||||||
|
|
||||||
case wxFONTSTYLE_ITALIC:
|
s += wxT("font-weight:") + fontweight + wxT("; ");
|
||||||
fontstyle = wxS("italic");
|
|
||||||
break;
|
|
||||||
|
|
||||||
case wxFONTSTYLE_SLANT:
|
wxString fontstyle;
|
||||||
fontstyle = wxS("oblique");
|
switch (m_font.GetStyle())
|
||||||
break;
|
{
|
||||||
}
|
case wxFONTSTYLE_MAX:
|
||||||
|
wxFAIL_MSG(wxS("invalid font style value"));
|
||||||
|
wxFALLTHROUGH;
|
||||||
|
|
||||||
wxASSERT_MSG( !fontstyle.empty(), wxS("unknown font style value") );
|
case wxFONTSTYLE_NORMAL:
|
||||||
|
fontstyle = wxS("normal");
|
||||||
|
break;
|
||||||
|
|
||||||
s += wxT("font-style:") + fontstyle + wxT("; ");
|
case wxFONTSTYLE_ITALIC:
|
||||||
|
fontstyle = wxS("italic");
|
||||||
|
break;
|
||||||
|
|
||||||
sTmp.Printf (wxT("font-size:%dpt; "), m_font.GetPointSize() );
|
case wxFONTSTYLE_SLANT:
|
||||||
s += sTmp;
|
fontstyle = wxS("oblique");
|
||||||
//text will be solid, unless alpha value isn't opaque in the foreground colour
|
break;
|
||||||
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");
|
wxASSERT_MSG(!fontstyle.empty(), wxS("unknown font style value"));
|
||||||
if (m_OK)
|
|
||||||
{
|
s += wxT("font-style:") + fontstyle + wxT("; ");
|
||||||
write(s);
|
|
||||||
|
sTmp.Printf(wxT("font-size:%dpt; "), m_font.GetPointSize());
|
||||||
|
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), xx, yy );
|
||||||
|
s += sTmp + wxMarkupParser::Quote(lines[lineNum]) + wxT("</text> ") + wxT("\n");
|
||||||
|
if (m_OK)
|
||||||
|
{
|
||||||
|
write(s);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user