summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorHenrique Nakashima <hnakashima@chromium.org>2018-06-13 17:36:56 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-06-13 17:36:56 +0000
commitc2b34d2adc6c987d882b4173265697917df74f54 (patch)
tree413de391f01a3f81f03b55516491bb69ee29091b /core
parent5f032995b3d7f874eafbd9dc4a56e8f08fbfa87d (diff)
downloadpdfium-c2b34d2adc6c987d882b4173265697917df74f54.tar.xz
Refactor GetOrCreateDefaultGraphics out of ProcessDefaultGraphics.
GetOrCreateDefaultGraphics() has a side effect, and it needs to be called regardless of whether a stream is generated of not. Failing to do so causes default graphics to not exist in some cases. Bug: pdfium:1051 Change-Id: I039cb6b755cc15c8ca667c92e581d085f3f2a124 Reviewed-on: https://pdfium-review.googlesource.com/35010 Commit-Queue: Henrique Nakashima <hnakashima@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'core')
-rw-r--r--core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp34
-rw-r--r--core/fpdfapi/edit/cpdf_pagecontentgenerator.h3
2 files changed, 22 insertions, 15 deletions
diff --git a/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp b/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp
index e3a8674afe..19994fa57f 100644
--- a/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp
+++ b/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp
@@ -130,7 +130,7 @@ void CPDF_PageContentGenerator::UpdateContentStreams(
ByteString CPDF_PageContentGenerator::RealizeResource(
const CPDF_Object* pResource,
- const ByteString& bsType) {
+ const ByteString& bsType) const {
ASSERT(pResource);
if (!m_pObjHolder->m_pResources) {
m_pObjHolder->m_pResources = m_pDocument->NewIndirect<CPDF_Dictionary>();
@@ -343,24 +343,30 @@ void CPDF_PageContentGenerator::ProcessDefaultGraphics(
*buf << "0 0 0 RG 0 0 0 rg 1 w "
<< static_cast<int>(CFX_GraphStateData::LineCapButt) << " J "
<< static_cast<int>(CFX_GraphStateData::LineJoinMiter) << " j\n";
+ ByteString name = GetOrCreateDefaultGraphics();
+ *buf << "/" << PDF_NameEncode(name).c_str() << " gs ";
+}
+
+ByteString CPDF_PageContentGenerator::GetOrCreateDefaultGraphics() const {
GraphicsData defaultGraphics;
defaultGraphics.fillAlpha = 1.0f;
defaultGraphics.strokeAlpha = 1.0f;
defaultGraphics.blendType = FXDIB_BLEND_NORMAL;
auto it = m_pObjHolder->m_GraphicsMap.find(defaultGraphics);
- ByteString name;
- if (it != m_pObjHolder->m_GraphicsMap.end()) {
- name = it->second;
- } else {
- auto gsDict = pdfium::MakeUnique<CPDF_Dictionary>();
- gsDict->SetNewFor<CPDF_Number>("ca", defaultGraphics.fillAlpha);
- gsDict->SetNewFor<CPDF_Number>("CA", defaultGraphics.strokeAlpha);
- gsDict->SetNewFor<CPDF_Name>("BM", "Normal");
- CPDF_Object* pDict = m_pDocument->AddIndirectObject(std::move(gsDict));
- name = RealizeResource(pDict, "ExtGState");
- m_pObjHolder->m_GraphicsMap[defaultGraphics] = name;
- }
- *buf << "/" << PDF_NameEncode(name).c_str() << " gs ";
+
+ // If default graphics already exists, return it.
+ if (it != m_pObjHolder->m_GraphicsMap.end())
+ return it->second;
+
+ // Otherwise, create them.
+ auto gsDict = pdfium::MakeUnique<CPDF_Dictionary>();
+ gsDict->SetNewFor<CPDF_Number>("ca", defaultGraphics.fillAlpha);
+ gsDict->SetNewFor<CPDF_Number>("CA", defaultGraphics.strokeAlpha);
+ gsDict->SetNewFor<CPDF_Name>("BM", "Normal");
+ CPDF_Object* pDict = m_pDocument->AddIndirectObject(std::move(gsDict));
+ ByteString name = RealizeResource(pDict, "ExtGState");
+ m_pObjHolder->m_GraphicsMap[defaultGraphics] = name;
+ return name;
}
// This method adds text to the buffer, BT begins the text object, ET ends it.
diff --git a/core/fpdfapi/edit/cpdf_pagecontentgenerator.h b/core/fpdfapi/edit/cpdf_pagecontentgenerator.h
index 677d29267b..04adf1c1d2 100644
--- a/core/fpdfapi/edit/cpdf_pagecontentgenerator.h
+++ b/core/fpdfapi/edit/cpdf_pagecontentgenerator.h
@@ -40,8 +40,9 @@ class CPDF_PageContentGenerator {
void ProcessGraphics(std::ostringstream* buf, CPDF_PageObject* pPageObj);
void ProcessDefaultGraphics(std::ostringstream* buf);
void ProcessText(std::ostringstream* buf, CPDF_TextObject* pTextObj);
+ ByteString GetOrCreateDefaultGraphics() const;
ByteString RealizeResource(const CPDF_Object* pResource,
- const ByteString& bsType);
+ const ByteString& bsType) const;
// Returns a map from content stream index to new stream data. Unmodified
// streams are not touched.