From a4ad01fe03ffdd1806d31a9d7bb820f6a69a0afb Mon Sep 17 00:00:00 2001 From: Nicolas Pena Date: Wed, 15 Feb 2017 16:26:48 -0500 Subject: Move generated graphics and font maps to CPDF_Page MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A new CPDF_PageContentGenerator is created for every call of FPDFPage_GenerateContent, so having the maps there will cause duplicated resources to be created every time this method is called. Thus it is better to move these to the page. Change-Id: I47804f79790fc5354f8a94b6387d66b65eda5a20 Reviewed-on: https://pdfium-review.googlesource.com/2717 Reviewed-by: Tom Sepez Commit-Queue: Nicolás Peña --- core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) (limited to 'core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp') diff --git a/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp b/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp index ff8b676de1..b5fe4c0f35 100644 --- a/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp +++ b/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp @@ -222,8 +222,8 @@ void CPDF_PageContentGenerator::ProcessGraphics(CFX_ByteTextBuf* buf, return; CFX_ByteString name; - auto it = m_GraphicsMap.find(graphD); - if (it != m_GraphicsMap.end()) { + auto it = m_pPage->m_GraphicsMap.find(graphD); + if (it != m_pPage->m_GraphicsMap.end()) { name = it->second; } else { auto gsDict = pdfium::MakeUnique(); @@ -232,23 +232,11 @@ void CPDF_PageContentGenerator::ProcessGraphics(CFX_ByteTextBuf* buf, CPDF_Object* pDict = m_pDocument->AddIndirectObject(std::move(gsDict)); uint32_t dwObjNum = pDict->GetObjNum(); name = RealizeResource(dwObjNum, "ExtGState"); - m_GraphicsMap[graphD] = name; + m_pPage->m_GraphicsMap[graphD] = name; } *buf << "/" << PDF_NameEncode(name) << " gs "; } -bool CPDF_PageContentGenerator::GraphicsData::operator<( - const GraphicsData& other) const { - if (fillAlpha != other.fillAlpha) - return fillAlpha < other.fillAlpha; - return strokeAlpha < other.strokeAlpha; -} - -bool CPDF_PageContentGenerator::FontData::operator<( - const FontData& other) const { - return baseFont < other.baseFont; -} - // This method adds text to the buffer, BT begins the text object, ET ends it. // Tm sets the text matrix (allows positioning and transforming text). // Tf sets the font name (from Font in Resources) and font size. @@ -262,9 +250,9 @@ void CPDF_PageContentGenerator::ProcessText(CFX_ByteTextBuf* buf, pFont = CPDF_Font::GetStockFont(m_pDocument, "Helvetica"); FontData fontD; fontD.baseFont = pFont->GetBaseFont(); - auto it = m_FontsMap.find(fontD); + auto it = m_pPage->m_FontsMap.find(fontD); CFX_ByteString dictName; - if (it != m_FontsMap.end()) { + if (it != m_pPage->m_FontsMap.end()) { dictName = it->second; } else { auto fontDict = pdfium::MakeUnique(); @@ -274,7 +262,7 @@ void CPDF_PageContentGenerator::ProcessText(CFX_ByteTextBuf* buf, CPDF_Object* pDict = m_pDocument->AddIndirectObject(std::move(fontDict)); uint32_t dwObjNum = pDict->GetObjNum(); dictName = RealizeResource(dwObjNum, "Font"); - m_FontsMap[fontD] = dictName; + m_pPage->m_FontsMap[fontD] = dictName; } *buf << "/" << PDF_NameEncode(dictName) << " " << pTextObj->GetFontSize() << " Tf "; -- cgit v1.2.3