Skip to content

Commit

Permalink
Prepare release of wxPdfDocument 1.0.0
Browse files Browse the repository at this point in the history
- Implemented extended support for fill patterns (template based patterns, various hatch patterns)
- Enhanced support for wxBrush styles in wxPdfDC (stipple and hatch styles)
  • Loading branch information
utelle committed Sep 14, 2021
1 parent 5446eec commit d55b1aa
Show file tree
Hide file tree
Showing 11 changed files with 465 additions and 286 deletions.
6 changes: 5 additions & 1 deletion include/wx/pdfdocdef.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Or you can send a mail to the author
\section version Version history
<dl>
<dt><b>1.0.0</b> - <i>December 2020 (planned)</i></dt>
<dt><b>1.0.0</b> - <i>September 2021</i></dt>
<dd>
wxPdfDocument is compatible with wxWidgets versions 3.0.x and 3.1.x.
Expand All @@ -79,11 +79,15 @@ General changes:<br>
- Added transformation matrix support for wxPdfDC
- Added attribute "char-spacing" for XML markup element "span"
- Added maximum height attribute for table rows in XML markup
- Implemented extended support for fill patterns (template based patterns, various hatch patterns)
- Enhanced support for wxBrush styles in wxPdfDC (stipple and hatch styles)
- Changed data type of image measures in XML markup (from integer to double)
- Optimized wxPdfDC output (setting of pens, brushes, state changes)
Fixed bugs:<br>
- Fixed issue with bitmap images in wxPdfDC (now using globally unique identifiers)
- Fixed wxPdfDC issue with pen and brush color
- Fixed issue with patterns in templates
- Use the transparent background mode by default (relevant for alpha support in wxPdfDC)
</dd>
Expand Down
31 changes: 28 additions & 3 deletions include/wx/pdfdocument.h
Original file line number Diff line number Diff line change
Expand Up @@ -515,13 +515,35 @@ class WXDLLIMPEXP_PDFDOC wxPdfDocument

/// Add an image pattern
/**
* Add a pattern which can be reference in draw or fill pattern methods
* Add an image pattern which can be referenced in draw or fill pattern methods
* \param patternName the name of the pattern (case sensitive)
* \param image the image to use for the pattern
* \param image the image to be used as a pattern
* \param width the display width of the pattern
* \param height the display height of the pattern
*/
virtual bool AddPattern(const wxString& patternName, const wxImage& image, double width, double height);

/// Add a template based pattern
/**
* Add a template based pattern which can be referenced in draw or fill pattern methods
* \param patternName the name of the pattern (case sensitive)
* \param templateId the id of the template to be used as a pattern
* \param width the display width of the pattern
* \param height the display height of the pattern
*/
virtual bool AddPattern(const wxString& patternName, int templateId, double width, double height);

/// Add a hatched pattern
/**
* Add a hatched pattern which can be referenced in draw or fill pattern methods
* \param patternName the name of the pattern (case sensitive)
* \param patternStyle the pattern style to be used as a pattern
* \param width the display width
* \param height the display height
* \param drawColour the foreground colour used for hatching
* \param fillColour the background colour to fill the pattern background (optional)
*/
virtual bool AddPattern(const wxString& patternName, const wxImage& image, double width, double height);
virtual bool AddPattern(const wxString& patternName, wxPdfPatternStyle patternStyle, double width, double height, const wxColour& drawColour, const wxColour& fillColour = wxColour());

/// Defines the colour used for all drawing operations.
/**
Expand Down Expand Up @@ -2649,6 +2671,9 @@ class WXDLLIMPEXP_PDFDOC wxPdfDocument
/// Add spot colours
virtual void PutSpotColours();

/// Initialize object ids of patterns
virtual void InitPatternIds();

/// Add patterns
virtual void PutPatterns();

Expand Down
71 changes: 43 additions & 28 deletions include/wx/pdfpattern.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

// wxPdfDocument headers
#include "wx/pdfdocdef.h"
#include "wx/pdfproperties.h"

class WXDLLIMPEXP_FWD_PDFDOC wxPdfImage;

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

/// Constructor for pattern
/**
* \param index The pattern index
* \param width The pattern width
* \param height The pattern height
* \param templateId The id of the template to be used as a pattern
*/
wxPdfPattern(int index, double width, double height, int templateId);

/// Constructor for pattern
/**
* \param index The pattern index
* \param width The pattern width
* \param height The pattern height
* \param drawColour The foreground colour to be used for hatching
* \param fillColour The background colour to be used to fill the pattern background
*/
wxPdfPattern(int index, double width, double height, wxPdfPatternStyle patternStyle, const wxColour& drawColour, const wxColour& fillColour = wxColour());

/// Copy constructor
wxPdfPattern(const wxPdfPattern& pattern);

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

/// Get template id
int GetTemplateId() const { return m_templateId; }

/// Get pattern style
wxPdfPatternStyle GetPatternStyle() const { return m_patternStyle; }

/// Get draw color
wxColour GetDrawColour() const { return m_drawColour; }

/// Set fill color
void SetFillColour(const wxColour& fillColour) { m_fillColour = fillColour; m_hasFillColour = true; }

/// Get fill color
wxColour GetFillColour() const { return m_fillColour; }

/// Check whether fill color is set
bool HasFillColour() const { return m_hasFillColour; }

private:
int m_objIndex; ///< object index
int m_index; ///< pattern index

wxPdfPatternStyle m_patternStyle; ///< pattern style
wxPdfImage* m_image; ///< image
int m_templateId; ///< template id
wxColour m_drawColour; ///< foregorund colour
wxColour m_fillColour; ///< background colour
bool m_hasFillColour; ///< flag whether background colour is defined for the pattern

double m_width; ///< pattern width
double m_height; ///< pattern height
Expand All @@ -70,32 +113,4 @@ class WXDLLIMPEXP_PDFDOC wxPdfPattern
double m_matrix[6]; ///< transformation matrix
};

#if 0
Pattern dictionary Type 1
-------------------------

/Type /Pattern
/PatternType 1 - tiling pattern
/PaintType 1 - colored
2 - uncolored
/TilingType 1 - constant spacing
2 - no distortion
3 - constant spacing faster tiling
/BBox [ left bottom right top ]
/XStep - horizontal spacing != 0
/YStep - vertical spacing != 0
/Resources
/Matrix [1 0 0 1 0 0]

Pattern dictionary Type 2
-------------------------

/Type /Pattern
/PatternType 2 - shading pattern
/Shading dictionary or stream
/Matrix [1 0 0 1 0 0]
/ExtGState dictionary

#endif

#endif
20 changes: 20 additions & 0 deletions include/wx/pdfproperties.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,26 @@ enum wxPdfMarker
wxPDF_MARKER_LAST // Marks the last available marker symbol; do not use!
};

/// Pattern styles
enum wxPdfPatternStyle
{
wxPDF_PATTERNSTYLE_NONE,
wxPDF_PATTERNSTYLE_IMAGE,
wxPDF_PATTERNSTYLE_TEMPLATE,
// Hatch styles
wxPDF_PATTERNSTYLE_FIRST_HATCH,
wxPDF_PATTERNSTYLE_BDIAGONAL_HATCH = wxPDF_PATTERNSTYLE_FIRST_HATCH,
wxPDF_PATTERNSTYLE_CROSSDIAG_HATCH,
wxPDF_PATTERNSTYLE_FDIAGONAL_HATCH,
wxPDF_PATTERNSTYLE_CROSS_HATCH,
wxPDF_PATTERNSTYLE_HORIZONTAL_HATCH,
wxPDF_PATTERNSTYLE_VERTICAL_HATCH,
wxPDF_PATTERNSTYLE_HERRINGBONE_HATCH,
wxPDF_PATTERNSTYLE_BASKETWEAVE_HATCH,
wxPDF_PATTERNSTYLE_BRICK_HATCH,
wxPDF_PATTERNSTYLE_LAST_HATCH = wxPDF_PATTERNSTYLE_BRICK_HATCH
};

/// Linear gradient types
enum wxPdfLinearGradientType
{
Expand Down
73 changes: 73 additions & 0 deletions samples/minimal/drawing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,78 @@ drawing(bool testMode)
pdf.SetFillColour(wxColour(200, 200, 200));
pdf.RoundedRect(140, 255, 40, 30, 8.0, wxPDF_CORNER_TOP_RIGHT | wxPDF_CORNER_BOTTOM_RIGHT, wxPDF_STYLE_FILLDRAW);

// Examples of various fill patterns
pdf.AddPage();

pdf.Text(10, 15, wxS("Fill pattern examples"));
pdf.SetDrawColour(wxColour(0, 0, 0));

int tplHatch = pdf.BeginTemplate(0, 0, 4, 4);
pdf.SetTextColour(0);
pdf.SetDrawColour(wxColour(0, 0, 0));
pdf.SetFillColour(wxColour(128, 128, 255));
pdf.Circle(2, 2, 1.5, 0, 360, wxPDF_STYLE_FILLDRAW);
pdf.SetFillColour(wxColour(128, 255, 128));
pdf.Rect(2, 2, 1.75, 1.75, wxPDF_STYLE_FILLDRAW);
pdf.EndTemplate();

pdf.AddPattern(wxS("hatch1"), wxPDF_PATTERNSTYLE_BDIAGONAL_HATCH, 1, 1, wxColour(224, 0, 0));
pdf.AddPattern(wxS("hatch2"), wxPDF_PATTERNSTYLE_FDIAGONAL_HATCH, 2, 2, wxColour(160, 160, 0));
pdf.AddPattern(wxS("hatch3"), wxPDF_PATTERNSTYLE_CROSSDIAG_HATCH, 4, 4, wxColour(224, 0, 224));
pdf.AddPattern(wxS("hatch4"), wxPDF_PATTERNSTYLE_HORIZONTAL_HATCH, 1, 1, wxColour(255, 0, 0));
pdf.AddPattern(wxS("hatch5"), wxPDF_PATTERNSTYLE_VERTICAL_HATCH, 2, 2, wxColour(0, 0, 255));
pdf.AddPattern(wxS("hatch6"), wxPDF_PATTERNSTYLE_CROSS_HATCH, 4, 4, wxColour(0, 96, 0));
pdf.AddPattern(wxS("hatch7"), wxPDF_PATTERNSTYLE_BRICK_HATCH, 2, 2, wxColour(96, 96, 96), wxColour(255, 192, 128));
pdf.AddPattern(wxS("hatch8"), wxPDF_PATTERNSTYLE_HERRINGBONE_HATCH, 2, 2, wxColour(128, 128, 128));
pdf.AddPattern(wxS("hatch9"), wxPDF_PATTERNSTYLE_BASKETWEAVE_HATCH, 2, 2, wxColour(224, 160, 96));

pdf.AddPattern(wxS("hatch10"), tplHatch, 4, 4);
pdf.AddPattern(wxS("hatch11"), tplHatch, 6, 6);

pdf.Text(25, 25, wxS("BDiagonal"));
pdf.SetFillPattern(wxS("hatch1"));
pdf.Rect(25, 30, 25, 25, wxPDF_STYLE_FILLDRAW);

pdf.Text(75, 25, wxS("FDiagonal"));
pdf.SetFillPattern(wxS("hatch2"));
pdf.Rect(75, 30, 25, 25, wxPDF_STYLE_FILLDRAW);

pdf.Text(125, 25, wxS("CrossDiag"));
pdf.SetFillPattern(wxS("hatch3"));
pdf.Rect(125, 30, 25, 25, wxPDF_STYLE_FILLDRAW);

pdf.Text(25, 65, wxS("Horizontal"));
pdf.SetFillPattern(wxS("hatch4"));
pdf.Rect(25, 70, 25, 25, wxPDF_STYLE_FILLDRAW);

pdf.Text(75, 65, wxS("Vertical"));
pdf.SetFillPattern(wxS("hatch5"));
pdf.Rect(75, 70, 25, 25, wxPDF_STYLE_FILLDRAW);

pdf.Text(125, 65, wxS("Cross"));
pdf.SetFillPattern(wxS("hatch6"));
pdf.Rect(125, 70, 25, 25, wxPDF_STYLE_FILLDRAW);

pdf.Text(25, 105, wxS("Brick"));
pdf.SetFillPattern(wxS("hatch7"));
pdf.Rect(25, 110, 25, 25, wxPDF_STYLE_FILLDRAW);

pdf.Text(75, 105, wxS("HerringBone"));
pdf.SetFillPattern(wxS("hatch8"));
pdf.Rect(75, 110, 25, 25, wxPDF_STYLE_FILLDRAW);

pdf.Text(125, 105, wxS("BasketWeave"));
pdf.SetFillPattern(wxS("hatch9"));
pdf.Rect(125, 110, 25, 25, wxPDF_STYLE_FILLDRAW);

pdf.Text(25, 145, wxS("Template 1x"));
pdf.SetFillPattern(wxS("hatch10"));
pdf.Rect(25, 150, 40, 40, wxPDF_STYLE_FILLDRAW);

pdf.Text(75, 145, wxS("Template 2x"));
pdf.SetFillPattern(wxS("hatch11"));
pdf.Rect(75, 150, 40, 40, wxPDF_STYLE_FILLDRAW);

pdf.AddPage();

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

pdf.AddPage();
pdf.SetAutoPageBreak(false);
pdf.SetFont(wxS("Helvetica"), wxS(""), 10);
pdf.SetLineWidth(0.2);
pdf.SetDrawColour(0);
Expand Down
7 changes: 0 additions & 7 deletions samples/minimal/minimal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,17 +151,10 @@ class PdfDocTutorial : public wxAppConsole

static const wxCmdLineEntryDesc cmdLineDesc[] =
{
#if wxCHECK_VERSION(2,9,0)
{ wxCMD_LINE_OPTION, "s", "sampledir", "wxPdfDocument samples directory", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
{ wxCMD_LINE_OPTION, "f", "fontdir", "wxPdfDocument font directory", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
{ wxCMD_LINE_SWITCH, "t", "testmode", "Non-interactive testmode", wxCMD_LINE_VAL_NONE, wxCMD_LINE_PARAM_OPTIONAL },
{ wxCMD_LINE_SWITCH, "h", "help", "Display help", wxCMD_LINE_VAL_NONE, wxCMD_LINE_OPTION_HELP },
#else
{ wxCMD_LINE_OPTION, wxS("s"), wxS("sampledir"), wxS("wxPdfDocument samples directory"), wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
{ wxCMD_LINE_OPTION, wxS("f"), wxS("fontdir"), wxS("wxPdfDocument font directory"), wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
{ wxCMD_LINE_SWITCH, wxS("t"), wxS("testmode"), wxS("Non-interactive testmode"), wxCMD_LINE_VAL_NONE, wxCMD_LINE_PARAM_OPTIONAL },
{ wxCMD_LINE_SWITCH, wxS("h"), wxS("help"), wxS("Display help"), wxCMD_LINE_VAL_NONE, wxCMD_LINE_OPTION_HELP },
#endif
{ wxCMD_LINE_NONE }
};

Expand Down
Loading

0 comments on commit d55b1aa

Please sign in to comment.