Skip to content

Commit

Permalink
Fix issue with patterns in templates
Browse files Browse the repository at this point in the history
If draw or fill patterns are used in templates they need to be registered with the template. Pattern references were missing from templates.
  • Loading branch information
utelle committed Sep 10, 2021
1 parent af8df8a commit 5446eec
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions include/wx/pdftemplate.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class WXDLLIMPEXP_PDFDOC wxPdfTemplate
wxPdfImageHashMap* m_images; ///< array of used images
wxPdfTemplatesMap* m_templates; ///< array of templates
wxPdfExtGStateMap* m_extGStates; ///< array of extended graphics states
wxPdfPatternMap* m_patterns; ///< array of patterns

wxPdfParser* m_parser; ///< Associated parser
wxPdfObject* m_resources; ///< Array of page resource objects
Expand Down
8 changes: 8 additions & 0 deletions src/pdfdocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2557,6 +2557,10 @@ wxPdfDocument::SetDrawPattern(const wxString& name)
{
OutAscii(m_drawColour.GetColour(true));
}
if (m_inTemplate)
{
(*(m_currentTemplate->m_patterns))[pattern->first] = pattern->second;
}
}
else
{
Expand Down Expand Up @@ -2652,6 +2656,10 @@ wxPdfDocument::SetFillPattern(const wxString& name)
{
OutAscii(m_fillColour.GetColour(false));
}
if (m_inTemplate)
{
(*(m_currentTemplate->m_patterns))[pattern->first] = pattern->second;
}
}
else
{
Expand Down
13 changes: 12 additions & 1 deletion src/pdfkernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1843,6 +1843,17 @@ wxPdfDocument::PutTemplates()
}
Out(">>");
}
// References to patterns
if (currentTemplate->m_patterns->size() > 0)
{
Out("/Pattern <<");
wxPdfPatternMap::iterator pattern;
for (pattern = currentTemplate->m_patterns->begin(); pattern != currentTemplate->m_patterns->end(); pattern++)
{
OutAscii(wxString::Format(wxS("/P%d %d 0 R"), pattern->second->GetIndex(), pattern->second->GetObjIndex()));
}
Out(">>");
}
Out(">>");
}

Expand Down Expand Up @@ -2424,10 +2435,10 @@ wxPdfDocument::PutResources()
PutShaders();
PutFonts();
PutImages();
PutPatterns();
PutTemplates();
PutImportedObjects();
PutSpotColours();
PutPatterns();
PutLayers();

// Resource dictionary
Expand Down
2 changes: 2 additions & 0 deletions src/pdftemplate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ wxPdfTemplate::wxPdfTemplate(int templateId)
m_images = new wxPdfImageHashMap();
m_templates = new wxPdfTemplatesMap();
m_extGStates = new wxPdfExtGStateMap();
m_patterns = new wxPdfPatternMap();

m_parser = NULL;
m_resources = NULL;
Expand All @@ -47,6 +48,7 @@ wxPdfTemplate::~wxPdfTemplate()
delete m_images;
delete m_templates;
delete m_extGStates;
delete m_patterns;

if (m_resources != NULL)
{
Expand Down

0 comments on commit 5446eec

Please sign in to comment.