Skip to content

Commit d55b1aa

Browse files
committed
Prepare release of wxPdfDocument 1.0.0
- Implemented extended support for fill patterns (template based patterns, various hatch patterns) - Enhanced support for wxBrush styles in wxPdfDC (stipple and hatch styles)
1 parent 5446eec commit d55b1aa

11 files changed

Lines changed: 465 additions & 286 deletions

File tree

include/wx/pdfdocdef.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ Or you can send a mail to the author
6969
\section version Version history
7070
7171
<dl>
72-
<dt><b>1.0.0</b> - <i>December 2020 (planned)</i></dt>
72+
<dt><b>1.0.0</b> - <i>September 2021</i></dt>
7373
<dd>
7474
wxPdfDocument is compatible with wxWidgets versions 3.0.x and 3.1.x.
7575
@@ -79,11 +79,15 @@ General changes:<br>
7979
- Added transformation matrix support for wxPdfDC
8080
- Added attribute "char-spacing" for XML markup element "span"
8181
- Added maximum height attribute for table rows in XML markup
82+
- Implemented extended support for fill patterns (template based patterns, various hatch patterns)
83+
- Enhanced support for wxBrush styles in wxPdfDC (stipple and hatch styles)
8284
- Changed data type of image measures in XML markup (from integer to double)
8385
- Optimized wxPdfDC output (setting of pens, brushes, state changes)
8486
8587
Fixed bugs:<br>
8688
- Fixed issue with bitmap images in wxPdfDC (now using globally unique identifiers)
89+
- Fixed wxPdfDC issue with pen and brush color
90+
- Fixed issue with patterns in templates
8791
- Use the transparent background mode by default (relevant for alpha support in wxPdfDC)
8892
8993
</dd>

include/wx/pdfdocument.h

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -515,13 +515,35 @@ class WXDLLIMPEXP_PDFDOC wxPdfDocument
515515

516516
/// Add an image pattern
517517
/**
518-
* Add a pattern which can be reference in draw or fill pattern methods
518+
* Add an image pattern which can be referenced in draw or fill pattern methods
519519
* \param patternName the name of the pattern (case sensitive)
520-
* \param image the image to use for the pattern
520+
* \param image the image to be used as a pattern
521+
* \param width the display width of the pattern
522+
* \param height the display height of the pattern
523+
*/
524+
virtual bool AddPattern(const wxString& patternName, const wxImage& image, double width, double height);
525+
526+
/// Add a template based pattern
527+
/**
528+
* Add a template based pattern which can be referenced in draw or fill pattern methods
529+
* \param patternName the name of the pattern (case sensitive)
530+
* \param templateId the id of the template to be used as a pattern
531+
* \param width the display width of the pattern
532+
* \param height the display height of the pattern
533+
*/
534+
virtual bool AddPattern(const wxString& patternName, int templateId, double width, double height);
535+
536+
/// Add a hatched pattern
537+
/**
538+
* Add a hatched pattern which can be referenced in draw or fill pattern methods
539+
* \param patternName the name of the pattern (case sensitive)
540+
* \param patternStyle the pattern style to be used as a pattern
521541
* \param width the display width
522542
* \param height the display height
543+
* \param drawColour the foreground colour used for hatching
544+
* \param fillColour the background colour to fill the pattern background (optional)
523545
*/
524-
virtual bool AddPattern(const wxString& patternName, const wxImage& image, double width, double height);
546+
virtual bool AddPattern(const wxString& patternName, wxPdfPatternStyle patternStyle, double width, double height, const wxColour& drawColour, const wxColour& fillColour = wxColour());
525547

526548
/// Defines the colour used for all drawing operations.
527549
/**
@@ -2649,6 +2671,9 @@ class WXDLLIMPEXP_PDFDOC wxPdfDocument
26492671
/// Add spot colours
26502672
virtual void PutSpotColours();
26512673

2674+
/// Initialize object ids of patterns
2675+
virtual void InitPatternIds();
2676+
26522677
/// Add patterns
26532678
virtual void PutPatterns();
26542679

include/wx/pdfpattern.h

Lines changed: 43 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
// wxPdfDocument headers
1919
#include "wx/pdfdocdef.h"
20+
#include "wx/pdfproperties.h"
2021

2122
class WXDLLIMPEXP_FWD_PDFDOC wxPdfImage;
2223

@@ -32,6 +33,25 @@ class WXDLLIMPEXP_PDFDOC wxPdfPattern
3233
*/
3334
wxPdfPattern(int index, double width, double height);
3435

36+
/// Constructor for pattern
37+
/**
38+
* \param index The pattern index
39+
* \param width The pattern width
40+
* \param height The pattern height
41+
* \param templateId The id of the template to be used as a pattern
42+
*/
43+
wxPdfPattern(int index, double width, double height, int templateId);
44+
45+
/// Constructor for pattern
46+
/**
47+
* \param index The pattern index
48+
* \param width The pattern width
49+
* \param height The pattern height
50+
* \param drawColour The foreground colour to be used for hatching
51+
* \param fillColour The background colour to be used to fill the pattern background
52+
*/
53+
wxPdfPattern(int index, double width, double height, wxPdfPatternStyle patternStyle, const wxColour& drawColour, const wxColour& fillColour = wxColour());
54+
3555
/// Copy constructor
3656
wxPdfPattern(const wxPdfPattern& pattern);
3757

@@ -56,11 +76,34 @@ class WXDLLIMPEXP_PDFDOC wxPdfPattern
5676
/// Get pattern height
5777
double GetHeight() const {return m_height; };
5878

79+
/// Get template id
80+
int GetTemplateId() const { return m_templateId; }
81+
82+
/// Get pattern style
83+
wxPdfPatternStyle GetPatternStyle() const { return m_patternStyle; }
84+
85+
/// Get draw color
86+
wxColour GetDrawColour() const { return m_drawColour; }
87+
88+
/// Set fill color
89+
void SetFillColour(const wxColour& fillColour) { m_fillColour = fillColour; m_hasFillColour = true; }
90+
91+
/// Get fill color
92+
wxColour GetFillColour() const { return m_fillColour; }
93+
94+
/// Check whether fill color is set
95+
bool HasFillColour() const { return m_hasFillColour; }
96+
5997
private:
6098
int m_objIndex; ///< object index
6199
int m_index; ///< pattern index
62100

101+
wxPdfPatternStyle m_patternStyle; ///< pattern style
63102
wxPdfImage* m_image; ///< image
103+
int m_templateId; ///< template id
104+
wxColour m_drawColour; ///< foregorund colour
105+
wxColour m_fillColour; ///< background colour
106+
bool m_hasFillColour; ///< flag whether background colour is defined for the pattern
64107

65108
double m_width; ///< pattern width
66109
double m_height; ///< pattern height
@@ -70,32 +113,4 @@ class WXDLLIMPEXP_PDFDOC wxPdfPattern
70113
double m_matrix[6]; ///< transformation matrix
71114
};
72115

73-
#if 0
74-
Pattern dictionary Type 1
75-
-------------------------
76-
77-
/Type /Pattern
78-
/PatternType 1 - tiling pattern
79-
/PaintType 1 - colored
80-
2 - uncolored
81-
/TilingType 1 - constant spacing
82-
2 - no distortion
83-
3 - constant spacing faster tiling
84-
/BBox [ left bottom right top ]
85-
/XStep - horizontal spacing != 0
86-
/YStep - vertical spacing != 0
87-
/Resources
88-
/Matrix [1 0 0 1 0 0]
89-
90-
Pattern dictionary Type 2
91-
-------------------------
92-
93-
/Type /Pattern
94-
/PatternType 2 - shading pattern
95-
/Shading dictionary or stream
96-
/Matrix [1 0 0 1 0 0]
97-
/ExtGState dictionary
98-
99-
#endif
100-
101116
#endif

include/wx/pdfproperties.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,26 @@ enum wxPdfMarker
175175
wxPDF_MARKER_LAST // Marks the last available marker symbol; do not use!
176176
};
177177

178+
/// Pattern styles
179+
enum wxPdfPatternStyle
180+
{
181+
wxPDF_PATTERNSTYLE_NONE,
182+
wxPDF_PATTERNSTYLE_IMAGE,
183+
wxPDF_PATTERNSTYLE_TEMPLATE,
184+
// Hatch styles
185+
wxPDF_PATTERNSTYLE_FIRST_HATCH,
186+
wxPDF_PATTERNSTYLE_BDIAGONAL_HATCH = wxPDF_PATTERNSTYLE_FIRST_HATCH,
187+
wxPDF_PATTERNSTYLE_CROSSDIAG_HATCH,
188+
wxPDF_PATTERNSTYLE_FDIAGONAL_HATCH,
189+
wxPDF_PATTERNSTYLE_CROSS_HATCH,
190+
wxPDF_PATTERNSTYLE_HORIZONTAL_HATCH,
191+
wxPDF_PATTERNSTYLE_VERTICAL_HATCH,
192+
wxPDF_PATTERNSTYLE_HERRINGBONE_HATCH,
193+
wxPDF_PATTERNSTYLE_BASKETWEAVE_HATCH,
194+
wxPDF_PATTERNSTYLE_BRICK_HATCH,
195+
wxPDF_PATTERNSTYLE_LAST_HATCH = wxPDF_PATTERNSTYLE_BRICK_HATCH
196+
};
197+
178198
/// Linear gradient types
179199
enum wxPdfLinearGradientType
180200
{

samples/minimal/drawing.cpp

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,78 @@ drawing(bool testMode)
207207
pdf.SetFillColour(wxColour(200, 200, 200));
208208
pdf.RoundedRect(140, 255, 40, 30, 8.0, wxPDF_CORNER_TOP_RIGHT | wxPDF_CORNER_BOTTOM_RIGHT, wxPDF_STYLE_FILLDRAW);
209209

210+
// Examples of various fill patterns
211+
pdf.AddPage();
212+
213+
pdf.Text(10, 15, wxS("Fill pattern examples"));
214+
pdf.SetDrawColour(wxColour(0, 0, 0));
215+
216+
int tplHatch = pdf.BeginTemplate(0, 0, 4, 4);
217+
pdf.SetTextColour(0);
218+
pdf.SetDrawColour(wxColour(0, 0, 0));
219+
pdf.SetFillColour(wxColour(128, 128, 255));
220+
pdf.Circle(2, 2, 1.5, 0, 360, wxPDF_STYLE_FILLDRAW);
221+
pdf.SetFillColour(wxColour(128, 255, 128));
222+
pdf.Rect(2, 2, 1.75, 1.75, wxPDF_STYLE_FILLDRAW);
223+
pdf.EndTemplate();
224+
225+
pdf.AddPattern(wxS("hatch1"), wxPDF_PATTERNSTYLE_BDIAGONAL_HATCH, 1, 1, wxColour(224, 0, 0));
226+
pdf.AddPattern(wxS("hatch2"), wxPDF_PATTERNSTYLE_FDIAGONAL_HATCH, 2, 2, wxColour(160, 160, 0));
227+
pdf.AddPattern(wxS("hatch3"), wxPDF_PATTERNSTYLE_CROSSDIAG_HATCH, 4, 4, wxColour(224, 0, 224));
228+
pdf.AddPattern(wxS("hatch4"), wxPDF_PATTERNSTYLE_HORIZONTAL_HATCH, 1, 1, wxColour(255, 0, 0));
229+
pdf.AddPattern(wxS("hatch5"), wxPDF_PATTERNSTYLE_VERTICAL_HATCH, 2, 2, wxColour(0, 0, 255));
230+
pdf.AddPattern(wxS("hatch6"), wxPDF_PATTERNSTYLE_CROSS_HATCH, 4, 4, wxColour(0, 96, 0));
231+
pdf.AddPattern(wxS("hatch7"), wxPDF_PATTERNSTYLE_BRICK_HATCH, 2, 2, wxColour(96, 96, 96), wxColour(255, 192, 128));
232+
pdf.AddPattern(wxS("hatch8"), wxPDF_PATTERNSTYLE_HERRINGBONE_HATCH, 2, 2, wxColour(128, 128, 128));
233+
pdf.AddPattern(wxS("hatch9"), wxPDF_PATTERNSTYLE_BASKETWEAVE_HATCH, 2, 2, wxColour(224, 160, 96));
234+
235+
pdf.AddPattern(wxS("hatch10"), tplHatch, 4, 4);
236+
pdf.AddPattern(wxS("hatch11"), tplHatch, 6, 6);
237+
238+
pdf.Text(25, 25, wxS("BDiagonal"));
239+
pdf.SetFillPattern(wxS("hatch1"));
240+
pdf.Rect(25, 30, 25, 25, wxPDF_STYLE_FILLDRAW);
241+
242+
pdf.Text(75, 25, wxS("FDiagonal"));
243+
pdf.SetFillPattern(wxS("hatch2"));
244+
pdf.Rect(75, 30, 25, 25, wxPDF_STYLE_FILLDRAW);
245+
246+
pdf.Text(125, 25, wxS("CrossDiag"));
247+
pdf.SetFillPattern(wxS("hatch3"));
248+
pdf.Rect(125, 30, 25, 25, wxPDF_STYLE_FILLDRAW);
249+
250+
pdf.Text(25, 65, wxS("Horizontal"));
251+
pdf.SetFillPattern(wxS("hatch4"));
252+
pdf.Rect(25, 70, 25, 25, wxPDF_STYLE_FILLDRAW);
253+
254+
pdf.Text(75, 65, wxS("Vertical"));
255+
pdf.SetFillPattern(wxS("hatch5"));
256+
pdf.Rect(75, 70, 25, 25, wxPDF_STYLE_FILLDRAW);
257+
258+
pdf.Text(125, 65, wxS("Cross"));
259+
pdf.SetFillPattern(wxS("hatch6"));
260+
pdf.Rect(125, 70, 25, 25, wxPDF_STYLE_FILLDRAW);
261+
262+
pdf.Text(25, 105, wxS("Brick"));
263+
pdf.SetFillPattern(wxS("hatch7"));
264+
pdf.Rect(25, 110, 25, 25, wxPDF_STYLE_FILLDRAW);
265+
266+
pdf.Text(75, 105, wxS("HerringBone"));
267+
pdf.SetFillPattern(wxS("hatch8"));
268+
pdf.Rect(75, 110, 25, 25, wxPDF_STYLE_FILLDRAW);
269+
270+
pdf.Text(125, 105, wxS("BasketWeave"));
271+
pdf.SetFillPattern(wxS("hatch9"));
272+
pdf.Rect(125, 110, 25, 25, wxPDF_STYLE_FILLDRAW);
273+
274+
pdf.Text(25, 145, wxS("Template 1x"));
275+
pdf.SetFillPattern(wxS("hatch10"));
276+
pdf.Rect(25, 150, 40, 40, wxPDF_STYLE_FILLDRAW);
277+
278+
pdf.Text(75, 145, wxS("Template 2x"));
279+
pdf.SetFillPattern(wxS("hatch11"));
280+
pdf.Rect(75, 150, 40, 40, wxPDF_STYLE_FILLDRAW);
281+
210282
pdf.AddPage();
211283

212284
pdf.SetFont(wxS("Helvetica"), wxS("B"), 20);
@@ -275,6 +347,7 @@ drawing(bool testMode)
275347
pdf.SetTextColour(0);
276348

277349
pdf.AddPage();
350+
pdf.SetAutoPageBreak(false);
278351
pdf.SetFont(wxS("Helvetica"), wxS(""), 10);
279352
pdf.SetLineWidth(0.2);
280353
pdf.SetDrawColour(0);

samples/minimal/minimal.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,17 +151,10 @@ class PdfDocTutorial : public wxAppConsole
151151

152152
static const wxCmdLineEntryDesc cmdLineDesc[] =
153153
{
154-
#if wxCHECK_VERSION(2,9,0)
155154
{ wxCMD_LINE_OPTION, "s", "sampledir", "wxPdfDocument samples directory", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
156155
{ wxCMD_LINE_OPTION, "f", "fontdir", "wxPdfDocument font directory", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
157156
{ wxCMD_LINE_SWITCH, "t", "testmode", "Non-interactive testmode", wxCMD_LINE_VAL_NONE, wxCMD_LINE_PARAM_OPTIONAL },
158157
{ wxCMD_LINE_SWITCH, "h", "help", "Display help", wxCMD_LINE_VAL_NONE, wxCMD_LINE_OPTION_HELP },
159-
#else
160-
{ wxCMD_LINE_OPTION, wxS("s"), wxS("sampledir"), wxS("wxPdfDocument samples directory"), wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
161-
{ wxCMD_LINE_OPTION, wxS("f"), wxS("fontdir"), wxS("wxPdfDocument font directory"), wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
162-
{ wxCMD_LINE_SWITCH, wxS("t"), wxS("testmode"), wxS("Non-interactive testmode"), wxCMD_LINE_VAL_NONE, wxCMD_LINE_PARAM_OPTIONAL },
163-
{ wxCMD_LINE_SWITCH, wxS("h"), wxS("help"), wxS("Display help"), wxCMD_LINE_VAL_NONE, wxCMD_LINE_OPTION_HELP },
164-
#endif
165158
{ wxCMD_LINE_NONE }
166159
};
167160

0 commit comments

Comments
 (0)