diff options
-rw-r--r-- | BUILD.gn | 2 | ||||
-rw-r--r-- | core/fpdfapi/page/cpdf_generalstate.cpp | 1 | ||||
-rw-r--r-- | core/fpdfapi/parser/cpdf_document.cpp | 1 | ||||
-rw-r--r-- | core/fpdfapi/render/cpdf_docrenderdata.cpp | 153 | ||||
-rw-r--r-- | core/fpdfapi/render/cpdf_docrenderdata.h | 43 | ||||
-rw-r--r-- | core/fpdfapi/render/fpdf_render.cpp | 134 | ||||
-rw-r--r-- | core/fpdfapi/render/fpdf_render_text.cpp | 1 | ||||
-rw-r--r-- | core/fpdfapi/render/render_int.h | 21 |
8 files changed, 202 insertions, 154 deletions
@@ -534,6 +534,8 @@ static_library("fpdfapi") { "core/fpdfapi/parser/fpdf_parser_decode.h", "core/fpdfapi/parser/fpdf_parser_utility.cpp", "core/fpdfapi/parser/fpdf_parser_utility.h", + "core/fpdfapi/render/cpdf_docrenderdata.cpp", + "core/fpdfapi/render/cpdf_docrenderdata.h", "core/fpdfapi/render/cpdf_pagerendercache.h", "core/fpdfapi/render/cpdf_progressiverenderer.h", "core/fpdfapi/render/cpdf_rendercontext.h", diff --git a/core/fpdfapi/page/cpdf_generalstate.cpp b/core/fpdfapi/page/cpdf_generalstate.cpp index e8be18e2fa..33e8e5ecb4 100644 --- a/core/fpdfapi/page/cpdf_generalstate.cpp +++ b/core/fpdfapi/page/cpdf_generalstate.cpp @@ -7,6 +7,7 @@ #include "core/fpdfapi/page/cpdf_generalstate.h" #include "core/fpdfapi/parser/cpdf_document.h" +#include "core/fpdfapi/render/cpdf_docrenderdata.h" #include "core/fpdfapi/render/render_int.h" namespace { diff --git a/core/fpdfapi/parser/cpdf_document.cpp b/core/fpdfapi/parser/cpdf_document.cpp index c7f99fa6ef..bafeefe6fc 100644 --- a/core/fpdfapi/parser/cpdf_document.cpp +++ b/core/fpdfapi/parser/cpdf_document.cpp @@ -23,6 +23,7 @@ #include "core/fpdfapi/parser/cpdf_parser.h" #include "core/fpdfapi/parser/cpdf_reference.h" #include "core/fpdfapi/parser/cpdf_stream.h" +#include "core/fpdfapi/render/cpdf_docrenderdata.h" #include "core/fpdfapi/render/render_int.h" #include "core/fxcodec/JBig2_DocumentContext.h" #include "core/fxge/cfx_unicodeencoding.h" diff --git a/core/fpdfapi/render/cpdf_docrenderdata.cpp b/core/fpdfapi/render/cpdf_docrenderdata.cpp new file mode 100644 index 0000000000..9a1691711b --- /dev/null +++ b/core/fpdfapi/render/cpdf_docrenderdata.cpp @@ -0,0 +1,153 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "core/fpdfapi/render/cpdf_docrenderdata.h" + +#include <memory> + +#include "core/fpdfapi/font/cpdf_type3font.h" +#include "core/fpdfapi/page/pageint.h" +#include "core/fpdfapi/parser/cpdf_array.h" +#include "core/fpdfapi/parser/cpdf_document.h" +#include "core/fpdfapi/render/cpdf_type3cache.h" +#include "core/fpdfapi/render/render_int.h" + +namespace { + +const int kMaxOutputs = 16; + +} // namespace + +CPDF_DocRenderData::CPDF_DocRenderData(CPDF_Document* pPDFDoc) + : m_pPDFDoc(pPDFDoc) {} + +CPDF_DocRenderData::~CPDF_DocRenderData() { + Clear(true); +} + +void CPDF_DocRenderData::Clear(bool bRelease) { + for (auto it = m_Type3FaceMap.begin(); it != m_Type3FaceMap.end();) { + auto curr_it = it++; + CPDF_CountedObject<CPDF_Type3Cache>* cache = curr_it->second; + if (bRelease || cache->use_count() < 2) { + delete cache->get(); + delete cache; + m_Type3FaceMap.erase(curr_it); + } + } + + for (auto it = m_TransferFuncMap.begin(); it != m_TransferFuncMap.end();) { + auto curr_it = it++; + CPDF_CountedObject<CPDF_TransferFunc>* value = curr_it->second; + if (bRelease || value->use_count() < 2) { + delete value->get(); + delete value; + m_TransferFuncMap.erase(curr_it); + } + } +} + +CPDF_Type3Cache* CPDF_DocRenderData::GetCachedType3(CPDF_Type3Font* pFont) { + CPDF_CountedObject<CPDF_Type3Cache>* pCache; + auto it = m_Type3FaceMap.find(pFont); + if (it == m_Type3FaceMap.end()) { + CPDF_Type3Cache* pType3 = new CPDF_Type3Cache(pFont); + pCache = new CPDF_CountedObject<CPDF_Type3Cache>(pType3); + m_Type3FaceMap[pFont] = pCache; + } else { + pCache = it->second; + } + return pCache->AddRef(); +} + +void CPDF_DocRenderData::ReleaseCachedType3(CPDF_Type3Font* pFont) { + auto it = m_Type3FaceMap.find(pFont); + if (it != m_Type3FaceMap.end()) { + it->second->RemoveRef(); + if (it->second->use_count() < 2) { + delete it->second->get(); + delete it->second; + m_Type3FaceMap.erase(it); + } + } +} + +CPDF_TransferFunc* CPDF_DocRenderData::GetTransferFunc(CPDF_Object* pObj) { + if (!pObj) + return nullptr; + + auto it = m_TransferFuncMap.find(pObj); + if (it != m_TransferFuncMap.end()) { + CPDF_CountedObject<CPDF_TransferFunc>* pTransferCounter = it->second; + return pTransferCounter->AddRef(); + } + + std::unique_ptr<CPDF_Function> pFuncs[3]; + bool bUniTransfer = true; + bool bIdentity = true; + if (CPDF_Array* pArray = pObj->AsArray()) { + bUniTransfer = false; + if (pArray->GetCount() < 3) + return nullptr; + + for (uint32_t i = 0; i < 3; ++i) { + pFuncs[2 - i] = CPDF_Function::Load(pArray->GetDirectObjectAt(i)); + if (!pFuncs[2 - i]) + return nullptr; + } + } else { + pFuncs[0] = CPDF_Function::Load(pObj); + if (!pFuncs[0]) + return nullptr; + } + CPDF_TransferFunc* pTransfer = new CPDF_TransferFunc(m_pPDFDoc); + CPDF_CountedObject<CPDF_TransferFunc>* pTransferCounter = + new CPDF_CountedObject<CPDF_TransferFunc>(pTransfer); + m_TransferFuncMap[pObj] = pTransferCounter; + FX_FLOAT output[kMaxOutputs]; + FXSYS_memset(output, 0, sizeof(output)); + FX_FLOAT input; + int noutput; + for (int v = 0; v < 256; ++v) { + input = (FX_FLOAT)v / 255.0f; + if (bUniTransfer) { + if (pFuncs[0] && pFuncs[0]->CountOutputs() <= kMaxOutputs) + pFuncs[0]->Call(&input, 1, output, noutput); + int o = FXSYS_round(output[0] * 255); + if (o != v) + bIdentity = false; + for (int i = 0; i < 3; ++i) + pTransfer->m_Samples[i * 256 + v] = o; + continue; + } + for (int i = 0; i < 3; ++i) { + if (!pFuncs[i] || pFuncs[i]->CountOutputs() > kMaxOutputs) { + pTransfer->m_Samples[i * 256 + v] = v; + continue; + } + pFuncs[i]->Call(&input, 1, output, noutput); + int o = FXSYS_round(output[0] * 255); + if (o != v) + bIdentity = false; + pTransfer->m_Samples[i * 256 + v] = o; + } + } + + pTransfer->m_bIdentity = bIdentity; + return pTransferCounter->AddRef(); +} + +void CPDF_DocRenderData::ReleaseTransferFunc(CPDF_Object* pObj) { + auto it = m_TransferFuncMap.find(pObj); + if (it != m_TransferFuncMap.end()) { + it->second->RemoveRef(); + if (it->second->use_count() < 2) { + delete it->second->get(); + delete it->second; + m_TransferFuncMap.erase(it); + } + } +} diff --git a/core/fpdfapi/render/cpdf_docrenderdata.h b/core/fpdfapi/render/cpdf_docrenderdata.h new file mode 100644 index 0000000000..a8f4167a8d --- /dev/null +++ b/core/fpdfapi/render/cpdf_docrenderdata.h @@ -0,0 +1,43 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef CORE_FPDFAPI_RENDER_CPDF_DOCRENDERDATA_H_ +#define CORE_FPDFAPI_RENDER_CPDF_DOCRENDERDATA_H_ + +#include <map> + +#include "core/fpdfapi/page/cpdf_countedobject.h" + +class CPDF_Document; +class CPDF_Font; +class CPDF_Object; +class CPDF_TransferFunc; +class CPDF_Type3Cache; +class CPDF_Type3Font; + +class CPDF_DocRenderData { + public: + explicit CPDF_DocRenderData(CPDF_Document* pPDFDoc); + ~CPDF_DocRenderData(); + + CPDF_Type3Cache* GetCachedType3(CPDF_Type3Font* pFont); + void ReleaseCachedType3(CPDF_Type3Font* pFont); + CPDF_TransferFunc* GetTransferFunc(CPDF_Object* pObj); + void ReleaseTransferFunc(CPDF_Object* pObj); + void Clear(bool bRelease); + + private: + using CPDF_Type3CacheMap = + std::map<CPDF_Font*, CPDF_CountedObject<CPDF_Type3Cache>*>; + using CPDF_TransferFuncMap = + std::map<CPDF_Object*, CPDF_CountedObject<CPDF_TransferFunc>*>; + + CPDF_Document* m_pPDFDoc; // Not Owned + CPDF_Type3CacheMap m_Type3FaceMap; + CPDF_TransferFuncMap m_TransferFuncMap; +}; + +#endif // CORE_FPDFAPI_RENDER_CPDF_DOCRENDERDATA_H_ diff --git a/core/fpdfapi/render/fpdf_render.cpp b/core/fpdfapi/render/fpdf_render.cpp index e4abb7e832..ca9e059171 100644 --- a/core/fpdfapi/render/fpdf_render.cpp +++ b/core/fpdfapi/render/fpdf_render.cpp @@ -25,6 +25,7 @@ #include "core/fpdfapi/parser/cpdf_array.h" #include "core/fpdfapi/parser/cpdf_dictionary.h" #include "core/fpdfapi/parser/cpdf_document.h" +#include "core/fpdfapi/render/cpdf_docrenderdata.h" #include "core/fpdfapi/render/cpdf_pagerendercache.h" #include "core/fpdfapi/render/cpdf_progressiverenderer.h" #include "core/fpdfapi/render/cpdf_renderoptions.h" @@ -36,60 +37,6 @@ #include "core/fxge/cfx_pathdata.h" #include "core/fxge/cfx_renderdevice.h" -CPDF_DocRenderData::CPDF_DocRenderData(CPDF_Document* pPDFDoc) - : m_pPDFDoc(pPDFDoc) {} - -CPDF_DocRenderData::~CPDF_DocRenderData() { - Clear(true); -} - -void CPDF_DocRenderData::Clear(bool bRelease) { - for (auto it = m_Type3FaceMap.begin(); it != m_Type3FaceMap.end();) { - auto curr_it = it++; - CPDF_CountedObject<CPDF_Type3Cache>* cache = curr_it->second; - if (bRelease || cache->use_count() < 2) { - delete cache->get(); - delete cache; - m_Type3FaceMap.erase(curr_it); - } - } - - for (auto it = m_TransferFuncMap.begin(); it != m_TransferFuncMap.end();) { - auto curr_it = it++; - CPDF_CountedObject<CPDF_TransferFunc>* value = curr_it->second; - if (bRelease || value->use_count() < 2) { - delete value->get(); - delete value; - m_TransferFuncMap.erase(curr_it); - } - } -} - -CPDF_Type3Cache* CPDF_DocRenderData::GetCachedType3(CPDF_Type3Font* pFont) { - CPDF_CountedObject<CPDF_Type3Cache>* pCache; - auto it = m_Type3FaceMap.find(pFont); - if (it == m_Type3FaceMap.end()) { - CPDF_Type3Cache* pType3 = new CPDF_Type3Cache(pFont); - pCache = new CPDF_CountedObject<CPDF_Type3Cache>(pType3); - m_Type3FaceMap[pFont] = pCache; - } else { - pCache = it->second; - } - return pCache->AddRef(); -} - -void CPDF_DocRenderData::ReleaseCachedType3(CPDF_Type3Font* pFont) { - auto it = m_Type3FaceMap.find(pFont); - if (it != m_Type3FaceMap.end()) { - it->second->RemoveRef(); - if (it->second->use_count() < 2) { - delete it->second->get(); - delete it->second; - m_Type3FaceMap.erase(it); - } - } -} - CPDF_RenderOptions::CPDF_RenderOptions() : m_ColorMode(RENDER_COLOR_NORMAL), m_Flags(RENDER_CLEARTYPE), @@ -1087,85 +1034,6 @@ void CPDF_ProgressiveRenderer::Continue(IFX_Pause* pPause) { } } -CPDF_TransferFunc* CPDF_DocRenderData::GetTransferFunc(CPDF_Object* pObj) { - if (!pObj) - return nullptr; - - auto it = m_TransferFuncMap.find(pObj); - if (it != m_TransferFuncMap.end()) { - CPDF_CountedObject<CPDF_TransferFunc>* pTransferCounter = it->second; - return pTransferCounter->AddRef(); - } - - std::unique_ptr<CPDF_Function> pFuncs[3]; - bool bUniTransfer = true; - bool bIdentity = true; - if (CPDF_Array* pArray = pObj->AsArray()) { - bUniTransfer = false; - if (pArray->GetCount() < 3) - return nullptr; - - for (uint32_t i = 0; i < 3; ++i) { - pFuncs[2 - i] = CPDF_Function::Load(pArray->GetDirectObjectAt(i)); - if (!pFuncs[2 - i]) - return nullptr; - } - } else { - pFuncs[0] = CPDF_Function::Load(pObj); - if (!pFuncs[0]) - return nullptr; - } - CPDF_TransferFunc* pTransfer = new CPDF_TransferFunc(m_pPDFDoc); - CPDF_CountedObject<CPDF_TransferFunc>* pTransferCounter = - new CPDF_CountedObject<CPDF_TransferFunc>(pTransfer); - m_TransferFuncMap[pObj] = pTransferCounter; - static const int kMaxOutputs = 16; - FX_FLOAT output[kMaxOutputs]; - FXSYS_memset(output, 0, sizeof(output)); - FX_FLOAT input; - int noutput; - for (int v = 0; v < 256; ++v) { - input = (FX_FLOAT)v / 255.0f; - if (bUniTransfer) { - if (pFuncs[0] && pFuncs[0]->CountOutputs() <= kMaxOutputs) - pFuncs[0]->Call(&input, 1, output, noutput); - int o = FXSYS_round(output[0] * 255); - if (o != v) - bIdentity = false; - for (int i = 0; i < 3; ++i) { - pTransfer->m_Samples[i * 256 + v] = o; - } - } else { - for (int i = 0; i < 3; ++i) { - if (pFuncs[i] && pFuncs[i]->CountOutputs() <= kMaxOutputs) { - pFuncs[i]->Call(&input, 1, output, noutput); - int o = FXSYS_round(output[0] * 255); - if (o != v) - bIdentity = false; - pTransfer->m_Samples[i * 256 + v] = o; - } else { - pTransfer->m_Samples[i * 256 + v] = v; - } - } - } - } - - pTransfer->m_bIdentity = bIdentity; - return pTransferCounter->AddRef(); -} - -void CPDF_DocRenderData::ReleaseTransferFunc(CPDF_Object* pObj) { - auto it = m_TransferFuncMap.find(pObj); - if (it != m_TransferFuncMap.end()) { - it->second->RemoveRef(); - if (it->second->use_count() < 2) { - delete it->second->get(); - delete it->second; - m_TransferFuncMap.erase(it); - } - } -} - CPDF_DeviceBuffer::CPDF_DeviceBuffer() : m_pDevice(nullptr), m_pContext(nullptr), m_pObject(nullptr) {} diff --git a/core/fpdfapi/render/fpdf_render_text.cpp b/core/fpdfapi/render/fpdf_render_text.cpp index 86fac2d90f..bf1d95ff74 100644 --- a/core/fpdfapi/render/fpdf_render_text.cpp +++ b/core/fpdfapi/render/fpdf_render_text.cpp @@ -20,6 +20,7 @@ #include "core/fpdfapi/page/cpdf_textobject.h" #include "core/fpdfapi/parser/cpdf_dictionary.h" #include "core/fpdfapi/parser/cpdf_document.h" +#include "core/fpdfapi/render/cpdf_docrenderdata.h" #include "core/fpdfapi/render/cpdf_renderoptions.h" #include "core/fpdfapi/render/cpdf_textrenderer.h" #include "core/fpdfapi/render/cpdf_type3cache.h" diff --git a/core/fpdfapi/render/render_int.h b/core/fpdfapi/render/render_int.h index e6090e8ebe..a8c8a580de 100644 --- a/core/fpdfapi/render/render_int.h +++ b/core/fpdfapi/render/render_int.h @@ -63,27 +63,6 @@ class CPDF_TransferFunc { uint8_t m_Samples[256 * 3]; }; -class CPDF_DocRenderData { - public: - explicit CPDF_DocRenderData(CPDF_Document* pPDFDoc); - ~CPDF_DocRenderData(); - CPDF_Type3Cache* GetCachedType3(CPDF_Type3Font* pFont); - CPDF_TransferFunc* GetTransferFunc(CPDF_Object* pObj); - void Clear(bool bRelease = false); - void ReleaseCachedType3(CPDF_Type3Font* pFont); - void ReleaseTransferFunc(CPDF_Object* pObj); - - private: - using CPDF_Type3CacheMap = - std::map<CPDF_Font*, CPDF_CountedObject<CPDF_Type3Cache>*>; - using CPDF_TransferFuncMap = - std::map<CPDF_Object*, CPDF_CountedObject<CPDF_TransferFunc>*>; - - CPDF_Document* m_pPDFDoc; - CPDF_Type3CacheMap m_Type3FaceMap; - CPDF_TransferFuncMap m_TransferFuncMap; -}; - class CPDF_RenderStatus { public: CPDF_RenderStatus(); |