Merge branch 'wxsvgfiledc-improvements' of https://github.com/MaartenBent/wxWidgets

Many improvements in wxSVGFileDC to improve its support of wxDC API including:

- Enabled usage of clipping regions.
- Correctly draw polypolygons.
- Draw lines as one long line instead of many short lines.
- Drawing text improvements (position, multi-line, underlined, strike-through).
- Support more brush and pen styles.
- Add Saving as SVG to drawing sample.
- Implemented Clear().
- Set the SVG title.
- Produce valid svg/xml.
- Correctly draw ellipses and arcs.

See https://github.com/wxWidgets/wxWidgets/pull/215
This commit is contained in:
Vadim Zeitlin 2016-06-13 15:20:44 +02:00
commit 2297578cb4
5 changed files with 621 additions and 283 deletions

View File

@ -78,6 +78,7 @@ All:
All (GUI):
- Improve wxSVGFileDC to support more of wxDC API (Maarten Bent).
- Add support for wxAuiManager and wxAuiPaneInfo to XRC (Andrea Zanellato).
- Add support for wxSL_MIN_MAX_LABELS and wxSL_VALUE_LABEL to XRC (ousnius).
- Update Scintilla to v3.6.6 (Paul Kulchenko).

View File

@ -16,12 +16,7 @@
#if wxUSE_SVG
#define wxSVGVersion wxT("v0100")
#ifdef __BORLANDC__
#pragma warn -8008
#pragma warn -8066
#endif
#define wxSVGVersion wxT("v0101")
class WXDLLIMPEXP_FWD_BASE wxFileOutputStream;
@ -66,7 +61,8 @@ class WXDLLIMPEXP_CORE wxSVGFileDCImpl : public wxDCImpl
{
public:
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() );
virtual ~wxSVGFileDCImpl();
@ -81,20 +77,17 @@ public:
return -1;
}
virtual void Clear() wxOVERRIDE
{
wxFAIL_MSG(wxT("wxSVGFILEDC::Clear() Call not implemented \nNot sensible for an output file?"));
}
virtual void Clear() wxOVERRIDE;
virtual void DestroyClippingRegion() wxOVERRIDE;
virtual wxCoord GetCharHeight() const wxOVERRIDE;
virtual wxCoord GetCharWidth() const wxOVERRIDE;
virtual void SetClippingRegion(wxCoord WXUNUSED(x), wxCoord WXUNUSED(y),
wxCoord WXUNUSED(w), wxCoord WXUNUSED(h))
virtual void SetClippingRegion(wxCoord x, wxCoord y,
wxCoord w, wxCoord h)
{
wxFAIL_MSG(wxT("wxSVGFILEDC::SetClippingRegion not implemented"));
DoSetClippingRegion(x, y, w, h);
}
virtual void SetPalette(const wxPalette& WXUNUSED(palette)) wxOVERRIDE
@ -102,10 +95,10 @@ public:
wxFAIL_MSG(wxT("wxSVGFILEDC::SetPalette not implemented"));
}
virtual void GetClippingBox(wxCoord *WXUNUSED(x), wxCoord *WXUNUSED(y),
wxCoord *WXUNUSED(w), wxCoord *WXUNUSED(h))
virtual void GetClippingBox(wxCoord *x, wxCoord *y,
wxCoord *w, wxCoord *h)
{
wxFAIL_MSG(wxT("wxSVGFILEDC::GetClippingBox not implemented"));
DoGetClippingBox(x, y, w, h);
}
virtual void SetLogicalFunction(wxRasterOperationMode WXUNUSED(function)) wxOVERRIDE
@ -119,6 +112,24 @@ public:
return wxCOPY;
}
virtual void SetLogicalOrigin(wxCoord x, wxCoord y) wxOVERRIDE
{
wxDCImpl::SetLogicalOrigin(x, y);
m_graphics_changed = true;
}
virtual void SetDeviceOrigin(wxCoord x, wxCoord y) wxOVERRIDE
{
wxDCImpl::SetDeviceOrigin(x, y);
m_graphics_changed = true;
}
virtual void SetAxisOrientation(bool xLeftRight, bool yBottomUp) wxOVERRIDE
{
wxDCImpl::SetAxisOrientation(xLeftRight, yBottomUp);
m_graphics_changed = true;
}
virtual void SetBackground( const wxBrush &brush ) wxOVERRIDE;
virtual void SetBackgroundMode( int mode ) wxOVERRIDE;
virtual void SetBrush(const wxBrush& brush) wxOVERRIDE;
@ -169,6 +180,10 @@ private:
wxCoord xoffset, wxCoord yoffset,
wxPolygonFillMode fillStyle) wxOVERRIDE;
virtual void DoDrawPolyPolygon(int n, const int count[], const wxPoint points[],
wxCoord xoffset, wxCoord yoffset,
wxPolygonFillMode fillStyle) wxOVERRIDE;
virtual void DoDrawRectangle(wxCoord x, wxCoord y, wxCoord w, wxCoord h) wxOVERRIDE;
virtual void DoDrawRotatedText(const wxString& text, wxCoord x, wxCoord y,
@ -201,9 +216,10 @@ private:
wxCoord *externalLeading = NULL,
const wxFont *font = NULL) const wxOVERRIDE;
virtual void DoSetDeviceClippingRegion(const wxRegion& WXUNUSED(region)) wxOVERRIDE
virtual void DoSetDeviceClippingRegion(const wxRegion& region) wxOVERRIDE
{
wxFAIL_MSG(wxT("wxSVGFILEDC::DoSetDeviceClippingRegion not yet implemented"));
DoSetClippingRegion(region.GetBox().x, region.GetBox().y,
region.GetBox().width, region.GetBox().height);
}
virtual void DoSetClippingRegion(int x, int y, int width, int height) wxOVERRIDE;
@ -212,7 +228,8 @@ private:
virtual wxSize GetPPI() const wxOVERRIDE;
void Init (const wxString &filename, int width, int height, double dpi);
void Init (const wxString &filename, int width, int height,
double dpi, const wxString &title);
void write( const wxString &s );
@ -225,14 +242,14 @@ private:
// their current values in wxDC.
void DoStartNewGraphics();
wxFileOutputStream *m_outfile;
wxString m_filename;
int m_sub_images; // number of png format images we have
bool m_OK;
bool m_graphics_changed; // set by Set{Brush,Pen}()
int m_width, m_height;
double m_dpi;
wxSVGBitmapHandler* m_bmp_handler; // class to handle bitmaps
wxScopedPtr<wxFileOutputStream> m_outfile;
wxScopedPtr<wxSVGBitmapHandler> m_bmp_handler; // class to handle bitmaps
// The clipping nesting level is incremented by every call to
// SetClippingRegion() and reset when DestroyClippingRegion() is called.
@ -252,8 +269,9 @@ public:
wxSVGFileDC(const wxString& filename,
int width = 320,
int height = 240,
double dpi = 72.0)
: wxDC(new wxSVGFileDCImpl(this, filename, width, height, dpi))
double dpi = 72.0,
const wxString& title = wxString())
: wxDC(new wxSVGFileDCImpl(this, filename, width, height, dpi, title))
{
}

View File

@ -40,9 +40,11 @@ class wxSVGFileDC : public wxDC
public:
/**
Initializes a wxSVGFileDC with the given @a f filename with the given
@a Width and @a Height at @a dpi resolution.
@a Width and @a Height at @a dpi resolution, and an optional @a title.
The title provides a readable name for the SVG document.
*/
wxSVGFileDC(const wxString& filename, int width = 320, int height = 240, double dpi = 72);
wxSVGFileDC(const wxString& filename, int width = 320, int height = 240,
double dpi = 72, const wxString& title = wxString());
/**
Destructor.
@ -60,7 +62,7 @@ public:
void EndPage();
/**
This makes no sense in wxSVGFileDC and does nothing.
Draws a rectangle the size of the SVG using the wxDC::SetBackground() brush.
*/
void Clear();

View File

@ -39,6 +39,9 @@
#include "wx/filename.h"
#include "wx/metafile.h"
#include "wx/settings.h"
#if wxUSE_SVG
#include "wx/dcsvg.h"
#endif
// ----------------------------------------------------------------------------
// resources
@ -106,6 +109,7 @@ public:
void OnMouseUp(wxMouseEvent &event);
void ToShow(int show) { m_show = show; Refresh(); }
int GetPage() { return m_show; }
// set or remove the clipping region
void Clip(bool clip) { m_clip = clip; Refresh(); }
@ -120,6 +124,7 @@ public:
{ if ( !m_renderer ) return name.empty();
return m_renderer->GetName() == name;
}
wxGraphicsRenderer* GetRenderer() const { return m_renderer; }
#endif // wxUSE_GRAPHICS_CONTEXT
void UseBuffer(bool use) { m_useBuffer = use; Refresh(); }
@ -573,6 +578,8 @@ void MyCanvas::DrawTestPoly(wxDC& dc)
dc.DrawPolygon(WXSIZEOF(star), star, 0, 30);
dc.DrawPolygon(WXSIZEOF(star), star, 160, 30, wxWINDING_RULE);
wxBrush brushHatchGreen(*wxGREEN, wxBRUSHSTYLE_FDIAGONAL_HATCH);
dc.SetBrush(brushHatchGreen);
wxPoint star2[10];
star2[0] = wxPoint(0, 100);
star2[1] = wxPoint(-59, -81);
@ -901,7 +908,7 @@ void MyCanvas::DrawText(wxDC& dc)
wxCoord y = 150;
dc.SetLogicalFunction(wxINVERT);
// text drawing should ignore logical function
dc.DrawText( wxT("There should be a text below"), 110, 150 );
dc.DrawText( wxT("There should be a text below"), 110, y );
dc.DrawRectangle( 110, y, 100, height );
y += height;
@ -1836,7 +1843,7 @@ void MyCanvas::Draw(wxDC& pdc)
case File_ShowGradients:
DrawGradients(dc);
break;
case File_ShowSystemColours:
DrawSystemColours(dc);
break;
@ -2168,15 +2175,44 @@ void MyFrame::OnSave(wxCommandEvent& WXUNUSED(event))
wxFileDialog dlg(this, wxT("Save as bitmap"), wxT(""), wxT(""),
#if wxUSE_LIBPNG
wxT("PNG image (*.png)|*.png;*.PNG|")
#endif
#if wxUSE_SVG
wxT("SVG image (*.svg)|*.svg;*.SVG|")
#endif
wxT("Bitmap image (*.bmp)|*.bmp;*.BMP"),
wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
if (dlg.ShowModal() == wxID_OK)
{
wxBitmap bmp(500, 800);
wxMemoryDC mdc(bmp);
m_canvas->Draw(mdc);
bmp.ConvertToImage().SaveFile(dlg.GetPath());
int width, height;
m_canvas->GetVirtualSize(&width, &height);
#if wxUSE_SVG
wxString ext = dlg.GetPath().AfterLast('.').Lower();
if (ext.Lower() == wxT("svg"))
{
// Graphics screen can only be drawn using GraphicsContext
if (m_canvas->GetPage() == File_ShowGraphics) {
wxLogMessage("Graphics screen can not be saved as SVG.");
return;
}
#if wxUSE_GRAPHICS_CONTEXT
wxGraphicsRenderer* tempRenderer = m_canvas->GetRenderer();
m_canvas->UseGraphicRenderer(NULL);
#endif
wxSVGFileDC svgdc(dlg.GetPath(), width, height, 72, wxT("Drawing sample"));
svgdc.SetBitmapHandler(new wxSVGBitmapEmbedHandler());
m_canvas->Draw(svgdc);
#if wxUSE_GRAPHICS_CONTEXT
m_canvas->UseGraphicRenderer(tempRenderer);
#endif
}
else
#endif
{
wxBitmap bmp(width, height);
wxMemoryDC mdc(bmp);
m_canvas->Draw(mdc);
bmp.ConvertToImage().SaveFile(dlg.GetPath());
}
}
}

File diff suppressed because it is too large Load Diff