dcsvg.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/dcsvg.h
  3. // Purpose: wxSVGFileDC
  4. // Author: Chris Elliott
  5. // Modified by:
  6. // Created:
  7. // Copyright: (c) Chris Elliott
  8. // Licence: wxWindows licence
  9. /////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_DCSVG_H_
  11. #define _WX_DCSVG_H_
  12. #include "wx/string.h"
  13. #include "wx/dc.h"
  14. #if wxUSE_SVG
  15. #define wxSVGVersion wxT("v0100")
  16. #ifdef __BORLANDC__
  17. #pragma warn -8008
  18. #pragma warn -8066
  19. #endif
  20. class WXDLLIMPEXP_FWD_BASE wxFileOutputStream;
  21. class WXDLLIMPEXP_FWD_CORE wxSVGFileDC;
  22. class WXDLLIMPEXP_CORE wxSVGFileDCImpl : public wxDCImpl
  23. {
  24. public:
  25. wxSVGFileDCImpl( wxSVGFileDC *owner, const wxString &filename,
  26. int width=320, int height=240, double dpi=72.0 );
  27. virtual ~wxSVGFileDCImpl();
  28. bool IsOk() const { return m_OK; }
  29. virtual bool CanDrawBitmap() const { return true; }
  30. virtual bool CanGetTextExtent() const { return true; }
  31. virtual int GetDepth() const
  32. {
  33. wxFAIL_MSG(wxT("wxSVGFILEDC::GetDepth Call not implemented"));
  34. return -1;
  35. }
  36. virtual void Clear()
  37. {
  38. wxFAIL_MSG(wxT("wxSVGFILEDC::Clear() Call not implemented \nNot sensible for an output file?"));
  39. }
  40. virtual void DestroyClippingRegion();
  41. virtual wxCoord GetCharHeight() const;
  42. virtual wxCoord GetCharWidth() const;
  43. virtual void SetClippingRegion(wxCoord WXUNUSED(x), wxCoord WXUNUSED(y),
  44. wxCoord WXUNUSED(w), wxCoord WXUNUSED(h))
  45. {
  46. wxFAIL_MSG(wxT("wxSVGFILEDC::SetClippingRegion not implemented"));
  47. }
  48. virtual void SetPalette(const wxPalette& WXUNUSED(palette))
  49. {
  50. wxFAIL_MSG(wxT("wxSVGFILEDC::SetPalette not implemented"));
  51. }
  52. virtual void GetClippingBox(wxCoord *WXUNUSED(x), wxCoord *WXUNUSED(y),
  53. wxCoord *WXUNUSED(w), wxCoord *WXUNUSED(h))
  54. {
  55. wxFAIL_MSG(wxT("wxSVGFILEDC::GetClippingBox not implemented"));
  56. }
  57. virtual void SetLogicalFunction(wxRasterOperationMode WXUNUSED(function))
  58. {
  59. wxFAIL_MSG(wxT("wxSVGFILEDC::SetLogicalFunction Call not implemented"));
  60. }
  61. virtual wxRasterOperationMode GetLogicalFunction() const
  62. {
  63. wxFAIL_MSG(wxT("wxSVGFILEDC::GetLogicalFunction() not implemented"));
  64. return wxCOPY;
  65. }
  66. virtual void SetBackground( const wxBrush &brush );
  67. virtual void SetBackgroundMode( int mode );
  68. virtual void SetBrush(const wxBrush& brush);
  69. virtual void SetFont(const wxFont& font);
  70. virtual void SetPen(const wxPen& pen);
  71. virtual void* GetHandle() const { return NULL; }
  72. private:
  73. virtual bool DoGetPixel(wxCoord, wxCoord, wxColour *) const
  74. {
  75. wxFAIL_MSG(wxT("wxSVGFILEDC::DoGetPixel Call not implemented"));
  76. return true;
  77. }
  78. virtual bool DoBlit(wxCoord, wxCoord, wxCoord, wxCoord, wxDC *,
  79. wxCoord, wxCoord, wxRasterOperationMode = wxCOPY,
  80. bool = 0, int = -1, int = -1);
  81. virtual void DoCrossHair(wxCoord, wxCoord)
  82. {
  83. wxFAIL_MSG(wxT("wxSVGFILEDC::CrossHair Call not implemented"));
  84. }
  85. virtual void DoDrawArc(wxCoord, wxCoord, wxCoord, wxCoord, wxCoord, wxCoord);
  86. virtual void DoDrawBitmap(const wxBitmap &, wxCoord, wxCoord, bool = false);
  87. virtual void DoDrawCheckMark(wxCoord x, wxCoord y, wxCoord w, wxCoord h);
  88. virtual void DoDrawEllipse(wxCoord x, wxCoord y, wxCoord w, wxCoord h);
  89. virtual void DoDrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h,
  90. double sa, double ea);
  91. virtual void DoDrawIcon(const wxIcon &, wxCoord, wxCoord);
  92. virtual void DoDrawLine (wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2);
  93. virtual void DoDrawLines(int n, const wxPoint points[],
  94. wxCoord xoffset = 0, wxCoord yoffset = 0);
  95. virtual void DoDrawPoint(wxCoord, wxCoord);
  96. virtual void DoDrawPolygon(int n, const wxPoint points[],
  97. wxCoord xoffset, wxCoord yoffset,
  98. wxPolygonFillMode fillStyle);
  99. virtual void DoDrawRectangle(wxCoord x, wxCoord y, wxCoord w, wxCoord h);
  100. virtual void DoDrawRotatedText(const wxString& text, wxCoord x, wxCoord y,
  101. double angle);
  102. virtual void DoDrawRoundedRectangle(wxCoord x, wxCoord y,
  103. wxCoord w, wxCoord h,
  104. double radius = 20) ;
  105. virtual void DoDrawText(const wxString& text, wxCoord x, wxCoord y);
  106. virtual bool DoFloodFill(wxCoord WXUNUSED(x), wxCoord WXUNUSED(y),
  107. const wxColour& WXUNUSED(col),
  108. wxFloodFillStyle WXUNUSED(style) = wxFLOOD_SURFACE)
  109. {
  110. wxFAIL_MSG(wxT("wxSVGFILEDC::DoFloodFill Call not implemented"));
  111. return false;
  112. }
  113. virtual void DoGetSize(int * x, int *y) const
  114. {
  115. if ( x )
  116. *x = m_width;
  117. if ( y )
  118. *y = m_height;
  119. }
  120. virtual void DoGetTextExtent(const wxString& string, wxCoord *w, wxCoord *h,
  121. wxCoord *descent = NULL,
  122. wxCoord *externalLeading = NULL,
  123. const wxFont *font = NULL) const;
  124. virtual void DoSetDeviceClippingRegion(const wxRegion& WXUNUSED(region))
  125. {
  126. wxFAIL_MSG(wxT("wxSVGFILEDC::DoSetDeviceClippingRegion not yet implemented"));
  127. }
  128. virtual void DoSetClippingRegion(int x, int y, int width, int height);
  129. virtual void DoGetSizeMM( int *width, int *height ) const;
  130. virtual wxSize GetPPI() const;
  131. void Init (const wxString &filename, int width, int height, double dpi);
  132. void write( const wxString &s );
  133. private:
  134. // If m_graphics_changed is true, close the current <g> element and start a
  135. // new one for the last pen/brush change.
  136. void NewGraphicsIfNeeded();
  137. // Open a new graphics group setting up all the attributes according to
  138. // their current values in wxDC.
  139. void DoStartNewGraphics();
  140. wxFileOutputStream *m_outfile;
  141. wxString m_filename;
  142. int m_sub_images; // number of png format images we have
  143. bool m_OK;
  144. bool m_graphics_changed; // set by Set{Brush,Pen}()
  145. int m_width, m_height;
  146. double m_dpi;
  147. // The clipping nesting level is incremented by every call to
  148. // SetClippingRegion() and reset when DestroyClippingRegion() is called.
  149. size_t m_clipNestingLevel;
  150. // Unique ID for every clipping graphics group: this is simply always
  151. // incremented in each SetClippingRegion() call.
  152. size_t m_clipUniqueId;
  153. DECLARE_ABSTRACT_CLASS(wxSVGFileDCImpl)
  154. };
  155. class WXDLLIMPEXP_CORE wxSVGFileDC : public wxDC
  156. {
  157. public:
  158. wxSVGFileDC(const wxString& filename,
  159. int width = 320,
  160. int height = 240,
  161. double dpi = 72.0)
  162. : wxDC(new wxSVGFileDCImpl(this, filename, width, height, dpi))
  163. {
  164. }
  165. };
  166. #endif // wxUSE_SVG
  167. #endif // _WX_DCSVG_H_