Process review comments in wxSVGFileDC

This commit is contained in:
Maarten Bent
2019-08-21 21:15:38 +02:00
parent 64be484db2
commit 75486529e3
2 changed files with 59 additions and 53 deletions

View File

@@ -85,9 +85,9 @@ public:
class WXDLLIMPEXP_CORE wxSVGFileDCImpl : public wxDCImpl class WXDLLIMPEXP_CORE wxSVGFileDCImpl : public wxDCImpl
{ {
public: public:
wxSVGFileDCImpl(wxSVGFileDC *owner, const wxString &filename, wxSVGFileDCImpl(wxSVGFileDC* owner, const wxString& filename,
int width = 320, int height = 240, double dpi = 72.0, int width = 320, int height = 240, double dpi = 72.0,
const wxString &title = wxString()); const wxString& title = wxString());
virtual ~wxSVGFileDCImpl(); virtual ~wxSVGFileDCImpl();
@@ -110,7 +110,7 @@ public:
virtual wxCoord GetCharWidth() const wxOVERRIDE; virtual wxCoord GetCharWidth() const wxOVERRIDE;
#if wxUSE_PALETTE #if wxUSE_PALETTE
virtual void SetPalette(const wxPalette& WXUNUSED(palette)) wxOVERRIDE virtual void SetPalette(const wxPalette& WXUNUSED(palette)) wxOVERRIDE
{ {
wxFAIL_MSG(wxT("wxSVGFILEDC::SetPalette not implemented")); wxFAIL_MSG(wxT("wxSVGFILEDC::SetPalette not implemented"));
} }
@@ -145,7 +145,7 @@ public:
m_graphics_changed = true; m_graphics_changed = true;
} }
virtual void SetBackground(const wxBrush &brush) wxOVERRIDE; virtual void SetBackground(const wxBrush& brush) wxOVERRIDE;
virtual void SetBackgroundMode(int mode) wxOVERRIDE; virtual void SetBackgroundMode(int mode) wxOVERRIDE;
virtual void SetBrush(const wxBrush& brush) wxOVERRIDE; virtual void SetBrush(const wxBrush& brush) wxOVERRIDE;
virtual void SetFont(const wxFont& font) wxOVERRIDE; virtual void SetFont(const wxFont& font) wxOVERRIDE;
@@ -158,13 +158,13 @@ public:
void SetShapeRenderingMode(wxSVGShapeRenderingMode renderingMode); void SetShapeRenderingMode(wxSVGShapeRenderingMode renderingMode);
private: private:
virtual bool DoGetPixel(wxCoord, wxCoord, wxColour *) const wxOVERRIDE virtual bool DoGetPixel(wxCoord, wxCoord, wxColour*) const wxOVERRIDE
{ {
wxFAIL_MSG(wxT("wxSVGFILEDC::DoGetPixel Call not implemented")); wxFAIL_MSG(wxT("wxSVGFILEDC::DoGetPixel Call not implemented"));
return true; return true;
} }
virtual bool DoBlit(wxCoord, wxCoord, wxCoord, wxCoord, wxDC *, virtual bool DoBlit(wxCoord, wxCoord, wxCoord, wxCoord, wxDC*,
wxCoord, wxCoord, wxRasterOperationMode = wxCOPY, wxCoord, wxCoord, wxRasterOperationMode = wxCOPY,
bool = 0, int = -1, int = -1) wxOVERRIDE; bool = 0, int = -1, int = -1) wxOVERRIDE;
@@ -175,7 +175,7 @@ private:
virtual void DoDrawArc(wxCoord, wxCoord, wxCoord, wxCoord, wxCoord, wxCoord) wxOVERRIDE; virtual void DoDrawArc(wxCoord, wxCoord, wxCoord, wxCoord, wxCoord, wxCoord) wxOVERRIDE;
virtual void DoDrawBitmap(const wxBitmap &, wxCoord, wxCoord, bool = false) wxOVERRIDE; virtual void DoDrawBitmap(const wxBitmap&, wxCoord, wxCoord, bool = false) wxOVERRIDE;
virtual void DoDrawCheckMark(wxCoord x, wxCoord y, wxCoord w, wxCoord h) wxOVERRIDE; virtual void DoDrawCheckMark(wxCoord x, wxCoord y, wxCoord w, wxCoord h) wxOVERRIDE;
@@ -184,7 +184,7 @@ private:
virtual void DoDrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h, virtual void DoDrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h,
double sa, double ea) wxOVERRIDE; double sa, double ea) wxOVERRIDE;
virtual void DoDrawIcon(const wxIcon &, wxCoord, wxCoord) wxOVERRIDE; virtual void DoDrawIcon(const wxIcon&, wxCoord, wxCoord) wxOVERRIDE;
virtual void DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2) wxOVERRIDE; virtual void DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2) wxOVERRIDE;
@@ -226,11 +226,11 @@ private:
wxDirection nDirection = wxEAST) wxOVERRIDE; wxDirection nDirection = wxEAST) wxOVERRIDE;
virtual void DoGradientFillConcentric(const wxRect& rect, virtual void DoGradientFillConcentric(const wxRect& rect,
const wxColour& initialColour, const wxColour& initialColour,
const wxColour& destColour, const wxColour& destColour,
const wxPoint& circleCenter) wxOVERRIDE; const wxPoint& circleCenter) wxOVERRIDE;
virtual void DoGetSize(int * x, int *y) const wxOVERRIDE virtual void DoGetSize(int* x, int*y) const wxOVERRIDE
{ {
if ( x ) if ( x )
*x = m_width; *x = m_width;
@@ -238,10 +238,10 @@ private:
*y = m_height; *y = m_height;
} }
virtual void DoGetTextExtent(const wxString& string, wxCoord *w, wxCoord *h, virtual void DoGetTextExtent(const wxString& string, wxCoord* w, wxCoord* h,
wxCoord *descent = NULL, wxCoord* descent = NULL,
wxCoord *externalLeading = NULL, wxCoord* externalLeading = NULL,
const wxFont *font = NULL) const wxOVERRIDE; const wxFont* font = NULL) const wxOVERRIDE;
virtual void DoSetDeviceClippingRegion(const wxRegion& region) wxOVERRIDE virtual void DoSetDeviceClippingRegion(const wxRegion& region) wxOVERRIDE
{ {
@@ -251,14 +251,14 @@ private:
virtual void DoSetClippingRegion(int x, int y, int width, int height) wxOVERRIDE; virtual void DoSetClippingRegion(int x, int y, int width, int height) wxOVERRIDE;
virtual void DoGetSizeMM(int *width, int *height) const wxOVERRIDE; virtual void DoGetSizeMM(int* width, int* height) const wxOVERRIDE;
virtual wxSize GetPPI() const wxOVERRIDE; virtual wxSize GetPPI() const wxOVERRIDE;
void Init(const wxString &filename, int width, int height, void Init(const wxString& filename, int width, int height,
double dpi, const wxString &title); double dpi, const wxString& title);
void write(const wxString &s); void write(const wxString& s);
private: private:
// If m_graphics_changed is true, close the current <g> element and start a // If m_graphics_changed is true, close the current <g> element and start a

View File

@@ -46,9 +46,10 @@ namespace
// C locale (i.e. always using "." for the decimal separator) and with the // C locale (i.e. always using "." for the decimal separator) and with the
// fixed precision (which is 2 for some unknown reason but this is what it was // fixed precision (which is 2 for some unknown reason but this is what it was
// in this code originally). // in this code originally).
inline wxString NumStr(double const& f) inline wxString NumStr(const double f)
{ {
if ( f == 0 ) if ( f == 0 )
// prevent -0.00
return wxS("0.00"); return wxS("0.00");
else else
return wxString::FromCDouble(f, 2); return wxString::FromCDouble(f, 2);
@@ -56,7 +57,7 @@ inline wxString NumStr(double const& f)
// Return the colour representation as HTML-like "#rrggbb" string and also // Return the colour representation as HTML-like "#rrggbb" string and also
// returns its alpha as opacity number in 0..1 range. // returns its alpha as opacity number in 0..1 range.
wxString Col2SVG(wxColour c, float *opacity = NULL) wxString Col2SVG(wxColour c, float* opacity = NULL)
{ {
if ( c.Alpha() != wxALPHA_OPAQUE ) if ( c.Alpha() != wxALPHA_OPAQUE )
{ {
@@ -70,13 +71,13 @@ wxString Col2SVG(wxColour c, float *opacity = NULL)
else // No alpha. else // No alpha.
{ {
if ( opacity ) if ( opacity )
*opacity = 1.; *opacity = 1.0f;
} }
return c.GetAsString(wxC2S_HTML_SYNTAX); return c.GetAsString(wxC2S_HTML_SYNTAX);
} }
wxString wxStrokeString(wxColour const& c, int style = wxPENSTYLE_SOLID) wxString wxStrokeString(const wxColour& c, int style = wxPENSTYLE_SOLID)
{ {
float opacity; float opacity;
wxString s = wxS("stroke:") + Col2SVG(c, &opacity) + wxS(";"); wxString s = wxS("stroke:") + Col2SVG(c, &opacity) + wxS(";");
@@ -102,7 +103,7 @@ wxString wxStrokeString(wxColour const& c, int style = wxPENSTYLE_SOLID)
return s; return s;
} }
wxString wxFillString(wxColour c, int style = wxBRUSHSTYLE_SOLID) wxString wxFillString(const wxColour& c, int style = wxBRUSHSTYLE_SOLID)
{ {
float opacity; float opacity;
wxString s = wxS("fill:") + Col2SVG(c, &opacity) + wxS(";"); wxString s = wxS("fill:") + Col2SVG(c, &opacity) + wxS(";");
@@ -129,7 +130,7 @@ wxString wxFillString(wxColour c, int style = wxBRUSHSTYLE_SOLID)
return s; return s;
} }
wxString wxGetPenPattern(wxPen const& pen) wxString wxGetPenPattern(const wxPen& pen)
{ {
wxString s; wxString s;
@@ -160,7 +161,7 @@ wxString wxGetPenPattern(wxPen const& pen)
case wxPENSTYLE_USER_DASH: case wxPENSTYLE_USER_DASH:
{ {
s = wxS("stroke-dasharray=\""); s = wxS("stroke-dasharray=\"");
wxDash *dashes; wxDash* dashes;
int count = pen.GetDashes(&dashes); int count = pen.GetDashes(&dashes);
if ((dashes != NULL) && (count > 0)) if ((dashes != NULL) && (count > 0))
{ {
@@ -194,7 +195,7 @@ wxString wxGetPenPattern(wxPen const& pen)
return s; return s;
} }
wxString wxGetPenStyle(wxPen const& pen) wxString wxGetPenStyle(const wxPen& pen)
{ {
wxString penStyle; wxString penStyle;
@@ -231,7 +232,7 @@ wxString wxGetPenStyle(wxPen const& pen)
return penStyle; return penStyle;
} }
wxString wxGetBrushStyleName(wxBrush const& brush) wxString wxGetBrushStyleName(const wxBrush& brush)
{ {
wxString brushStyle; wxString brushStyle;
@@ -270,21 +271,22 @@ wxString wxGetBrushStyleName(wxBrush const& brush)
return brushStyle; return brushStyle;
} }
wxString wxGetBrushFill(wxBrush const& brush) wxString wxGetBrushFill(const wxBrush& brush)
{ {
wxString s; wxString s;
wxString brushStyle = wxGetBrushStyleName(brush); wxString brushStyle = wxGetBrushStyleName(brush);
if (!brushStyle.IsEmpty()) if (!brushStyle.empty())
s = wxS("fill=\"url(#") + brushStyle + Col2SVG(brush.GetColour()).substr(1) + wxS(")\""); s = wxS("fill=\"url(#") + brushStyle + Col2SVG(brush.GetColour()).substr(1) + wxS(")\"");
return s; return s;
} }
wxString wxRenderMode(wxSVGShapeRenderingMode const& style) wxString wxRenderMode(const wxSVGShapeRenderingMode style)
{ {
wxString mode; wxString mode;
switch (style) { switch (style)
{
case wxSVG_SHAPE_RENDERING_OPTIMIZE_SPEED: case wxSVG_SHAPE_RENDERING_OPTIMIZE_SPEED:
mode = wxS("optimizeSpeed"); mode = wxS("optimizeSpeed");
break; break;
@@ -295,7 +297,6 @@ wxString wxRenderMode(wxSVGShapeRenderingMode const& style)
mode = wxS("geometricPrecision"); mode = wxS("geometricPrecision");
break; break;
case wxSVG_SHAPE_RENDERING_AUTO: case wxSVG_SHAPE_RENDERING_AUTO:
default:
mode = wxS("auto"); mode = wxS("auto");
break; break;
} }
@@ -304,12 +305,12 @@ wxString wxRenderMode(wxSVGShapeRenderingMode const& style)
return s; return s;
} }
wxString wxCreateBrushFill(wxBrush& brush, wxSVGShapeRenderingMode mode) wxString wxCreateBrushFill(const wxBrush& brush, wxSVGShapeRenderingMode mode)
{ {
wxString s; wxString s;
wxString patternName = wxGetBrushStyleName(brush); wxString patternName = wxGetBrushStyleName(brush);
if (!patternName.IsEmpty()) if (!patternName.empty())
{ {
wxString pattern; wxString pattern;
switch (brush.GetStyle()) switch (brush.GetStyle())
@@ -412,7 +413,7 @@ wxSVGBitmapEmbedHandler::ProcessBitmap(const wxBitmap& bmp,
// write to the SVG file // write to the SVG file
const wxCharBuffer buf = s.utf8_str(); const wxCharBuffer buf = s.utf8_str();
stream.Write(buf, strlen((const char *)buf)); stream.Write(buf, strlen((const char*)buf));
return stream.IsOk(); return stream.IsOk();
} }
@@ -437,7 +438,7 @@ wxSVGBitmapFileHandler::ProcessBitmap(const wxBitmap& bmp,
{ {
sPNG.SetFullName(wxString::Format("%s%simage%d.png", sPNG.SetFullName(wxString::Format("%s%simage%d.png",
sPNG.GetName(), sPNG.GetName(),
sPNG.GetName().IsEmpty() ? "" : "_", sPNG.GetName().empty() ? "" : "_",
sub_images++)); sub_images++));
} }
while ( sPNG.FileExists() ); while ( sPNG.FileExists() );
@@ -480,15 +481,15 @@ void wxSVGFileDC::SetShapeRenderingMode(wxSVGShapeRenderingMode renderingMode)
wxIMPLEMENT_ABSTRACT_CLASS(wxSVGFileDCImpl, wxDCImpl); wxIMPLEMENT_ABSTRACT_CLASS(wxSVGFileDCImpl, wxDCImpl);
wxSVGFileDCImpl::wxSVGFileDCImpl(wxSVGFileDC *owner, const wxString &filename, wxSVGFileDCImpl::wxSVGFileDCImpl(wxSVGFileDC* owner, const wxString& filename,
int width, int height, double dpi, const wxString &title) int width, int height, double dpi, const wxString& title)
: wxDCImpl(owner) : wxDCImpl(owner)
{ {
Init(filename, width, height, dpi, title); Init(filename, width, height, dpi, title);
} }
void wxSVGFileDCImpl::Init(const wxString &filename, int Width, int Height, void wxSVGFileDCImpl::Init(const wxString& filename, int Width, int Height,
double dpi, const wxString &title) double dpi, const wxString& title)
{ {
m_width = Width; m_width = Width;
m_height = Height; m_height = Height;
@@ -522,7 +523,7 @@ void wxSVGFileDCImpl::Init(const wxString &filename, int Width, int Height,
m_bmp_handler.reset(); m_bmp_handler.reset();
if ( m_filename.IsEmpty() ) if ( m_filename.empty() )
m_outfile.reset(); m_outfile.reset();
else else
m_outfile.reset(new wxFileOutputStream(m_filename)); m_outfile.reset(new wxFileOutputStream(m_filename));
@@ -550,7 +551,7 @@ wxSVGFileDCImpl::~wxSVGFileDCImpl()
write(s); write(s);
} }
void wxSVGFileDCImpl::DoGetSizeMM(int *width, int *height) const void wxSVGFileDCImpl::DoGetSizeMM(int* width, int* height) const
{ {
if (width) if (width)
*width = wxRound( (double)m_width / GetMMToPXx() ); *width = wxRound( (double)m_width / GetMMToPXx() );
@@ -683,7 +684,7 @@ void wxSVGFileDCImpl::DoDrawRotatedText(const wxString& sText, wxCoord x, wxCoor
textDecoration += wxS(" underline"); textDecoration += wxS(" underline");
if (m_font.GetStrikethrough()) if (m_font.GetStrikethrough())
textDecoration += wxS(" line-through"); textDecoration += wxS(" line-through");
if (textDecoration.IsEmpty()) if (textDecoration.empty())
textDecoration = wxS(" none"); textDecoration = wxS(" none");
wxString style = wxS("style=\""); wxString style = wxS("style=\"");
@@ -792,7 +793,7 @@ void wxSVGFileDCImpl::DoDrawPolygon(int n, const wxPoint points[],
s += wxString::Format(wxS("\" %s %s %s style=\"fill-rule:%s;\"/>\n"), s += wxString::Format(wxS("\" %s %s %s style=\"fill-rule:%s;\"/>\n"),
wxRenderMode(m_renderingMode), wxGetPenPattern(m_pen), wxGetBrushFill(m_brush), wxRenderMode(m_renderingMode), wxGetPenPattern(m_pen), wxGetBrushFill(m_brush),
(fillStyle == wxODDEVEN_RULE) ? wxS("evenodd") : wxS("nonzero")); fillStyle == wxODDEVEN_RULE ? wxS("evenodd") : wxS("nonzero"));
write(s); write(s);
} }
@@ -1155,7 +1156,12 @@ void wxSVGFileDCImpl::DestroyClippingRegion()
wxDCImpl::DestroyClippingRegion(); wxDCImpl::DestroyClippingRegion();
} }
void wxSVGFileDCImpl::DoGetTextExtent(const wxString& string, wxCoord *w, wxCoord *h, wxCoord *descent, wxCoord *externalLeading, const wxFont *font) const void wxSVGFileDCImpl::DoGetTextExtent(const wxString& string,
wxCoord* w,
wxCoord* h,
wxCoord* descent,
wxCoord* externalLeading,
const wxFont* font) const
{ {
wxScreenDC sDC; wxScreenDC sDC;
wxSetScaledScreenDCFont(sDC, font ? *font : m_font); wxSetScaledScreenDCFont(sDC, font ? *font : m_font);
@@ -1185,7 +1191,7 @@ wxCoord wxSVGFileDCImpl::GetCharWidth() const
// wxSVGFileDCImpl - set functions // wxSVGFileDCImpl - set functions
// ---------------------------------------------------------- // ----------------------------------------------------------
void wxSVGFileDCImpl::SetBackground(const wxBrush &brush) void wxSVGFileDCImpl::SetBackground(const wxBrush& brush)
{ {
m_backgroundBrush = brush; m_backgroundBrush = brush;
} }
@@ -1212,7 +1218,7 @@ void wxSVGFileDCImpl::SetBrush(const wxBrush& brush)
m_graphics_changed = true; m_graphics_changed = true;
wxString pattern = wxCreateBrushFill(m_brush, m_renderingMode); wxString pattern = wxCreateBrushFill(m_brush, m_renderingMode);
if ( !pattern.IsEmpty() ) if ( !pattern.empty() )
{ {
NewGraphicsIfNeeded(); NewGraphicsIfNeeded();
@@ -1285,7 +1291,7 @@ bool wxSVGFileDCImpl::DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoor
return false; return false;
} }
void wxSVGFileDCImpl::DoDrawIcon(const class wxIcon & myIcon, wxCoord x, wxCoord y) void wxSVGFileDCImpl::DoDrawIcon(const wxIcon& myIcon, wxCoord x, wxCoord y)
{ {
wxBitmap myBitmap(myIcon.GetWidth(), myIcon.GetHeight()); wxBitmap myBitmap(myIcon.GetWidth(), myIcon.GetHeight());
wxMemoryDC memDC; wxMemoryDC memDC;
@@ -1295,7 +1301,7 @@ void wxSVGFileDCImpl::DoDrawIcon(const class wxIcon & myIcon, wxCoord x, wxCoord
DoDrawBitmap(myBitmap, x, y); DoDrawBitmap(myBitmap, x, y);
} }
void wxSVGFileDCImpl::DoDrawBitmap(const class wxBitmap & bmp, wxCoord x, wxCoord y, bool WXUNUSED(bTransparent) /*=0*/) void wxSVGFileDCImpl::DoDrawBitmap(const wxBitmap& bmp, wxCoord x, wxCoord y, bool WXUNUSED(bTransparent))
{ {
NewGraphicsIfNeeded(); NewGraphicsIfNeeded();
@@ -1311,14 +1317,14 @@ void wxSVGFileDCImpl::DoDrawBitmap(const class wxBitmap & bmp, wxCoord x, wxCoor
m_OK = m_outfile->IsOk(); m_OK = m_outfile->IsOk();
} }
void wxSVGFileDCImpl::write(const wxString &s) void wxSVGFileDCImpl::write(const wxString& s)
{ {
m_OK = m_outfile && m_outfile->IsOk(); m_OK = m_outfile && m_outfile->IsOk();
if (!m_OK) if (!m_OK)
return; return;
const wxCharBuffer buf = s.utf8_str(); const wxCharBuffer buf = s.utf8_str();
m_outfile->Write(buf, strlen((const char *)buf)); m_outfile->Write(buf, strlen((const char*)buf));
m_OK = m_outfile->IsOk(); m_OK = m_outfile->IsOk();
} }