| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #include "core/fpdfapi/render/render_int.h" | 7 #include "core/fpdfapi/render/render_int.h" |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| 11 #include "core/fpdfapi/cpdf_modulemgr.h" | 11 #include "core/fpdfapi/cpdf_modulemgr.h" |
| 12 #include "core/fpdfapi/font/cpdf_type3char.h" | 12 #include "core/fpdfapi/font/cpdf_type3char.h" |
| 13 #include "core/fpdfapi/font/cpdf_type3font.h" | 13 #include "core/fpdfapi/font/cpdf_type3font.h" |
| 14 #include "core/fpdfapi/page/cpdf_docpagedata.h" | 14 #include "core/fpdfapi/page/cpdf_docpagedata.h" |
| 15 #include "core/fpdfapi/page/cpdf_form.h" | 15 #include "core/fpdfapi/page/cpdf_form.h" |
| 16 #include "core/fpdfapi/page/cpdf_formobject.h" | 16 #include "core/fpdfapi/page/cpdf_formobject.h" |
| 17 #include "core/fpdfapi/page/cpdf_graphicstates.h" | 17 #include "core/fpdfapi/page/cpdf_graphicstates.h" |
| 18 #include "core/fpdfapi/page/cpdf_image.h" | 18 #include "core/fpdfapi/page/cpdf_image.h" |
| 19 #include "core/fpdfapi/page/cpdf_imageobject.h" | 19 #include "core/fpdfapi/page/cpdf_imageobject.h" |
| 20 #include "core/fpdfapi/page/cpdf_page.h" | 20 #include "core/fpdfapi/page/cpdf_page.h" |
| 21 #include "core/fpdfapi/page/cpdf_pageobject.h" | 21 #include "core/fpdfapi/page/cpdf_pageobject.h" |
| 22 #include "core/fpdfapi/page/cpdf_pathobject.h" | 22 #include "core/fpdfapi/page/cpdf_pathobject.h" |
| 23 #include "core/fpdfapi/page/cpdf_textobject.h" | 23 #include "core/fpdfapi/page/cpdf_textobject.h" |
| 24 #include "core/fpdfapi/page/pageint.h" | 24 #include "core/fpdfapi/page/pageint.h" |
| 25 #include "core/fpdfapi/parser/cpdf_array.h" | 25 #include "core/fpdfapi/parser/cpdf_array.h" |
| 26 #include "core/fpdfapi/parser/cpdf_dictionary.h" | 26 #include "core/fpdfapi/parser/cpdf_dictionary.h" |
| 27 #include "core/fpdfapi/parser/cpdf_document.h" | 27 #include "core/fpdfapi/parser/cpdf_document.h" |
| 28 #include "core/fpdfapi/render/cpdf_docrenderdata.h" |
| 28 #include "core/fpdfapi/render/cpdf_pagerendercache.h" | 29 #include "core/fpdfapi/render/cpdf_pagerendercache.h" |
| 29 #include "core/fpdfapi/render/cpdf_progressiverenderer.h" | 30 #include "core/fpdfapi/render/cpdf_progressiverenderer.h" |
| 30 #include "core/fpdfapi/render/cpdf_renderoptions.h" | 31 #include "core/fpdfapi/render/cpdf_renderoptions.h" |
| 31 #include "core/fpdfapi/render/cpdf_textrenderer.h" | 32 #include "core/fpdfapi/render/cpdf_textrenderer.h" |
| 32 #include "core/fpdfapi/render/cpdf_type3cache.h" | 33 #include "core/fpdfapi/render/cpdf_type3cache.h" |
| 33 #include "core/fpdfdoc/cpdf_occontext.h" | 34 #include "core/fpdfdoc/cpdf_occontext.h" |
| 34 #include "core/fxge/cfx_fxgedevice.h" | 35 #include "core/fxge/cfx_fxgedevice.h" |
| 35 #include "core/fxge/cfx_graphstatedata.h" | 36 #include "core/fxge/cfx_graphstatedata.h" |
| 36 #include "core/fxge/cfx_pathdata.h" | 37 #include "core/fxge/cfx_pathdata.h" |
| 37 #include "core/fxge/cfx_renderdevice.h" | 38 #include "core/fxge/cfx_renderdevice.h" |
| 38 | 39 |
| 39 CPDF_DocRenderData::CPDF_DocRenderData(CPDF_Document* pPDFDoc) | |
| 40 : m_pPDFDoc(pPDFDoc) {} | |
| 41 | |
| 42 CPDF_DocRenderData::~CPDF_DocRenderData() { | |
| 43 Clear(true); | |
| 44 } | |
| 45 | |
| 46 void CPDF_DocRenderData::Clear(bool bRelease) { | |
| 47 for (auto it = m_Type3FaceMap.begin(); it != m_Type3FaceMap.end();) { | |
| 48 auto curr_it = it++; | |
| 49 CPDF_CountedObject<CPDF_Type3Cache>* cache = curr_it->second; | |
| 50 if (bRelease || cache->use_count() < 2) { | |
| 51 delete cache->get(); | |
| 52 delete cache; | |
| 53 m_Type3FaceMap.erase(curr_it); | |
| 54 } | |
| 55 } | |
| 56 | |
| 57 for (auto it = m_TransferFuncMap.begin(); it != m_TransferFuncMap.end();) { | |
| 58 auto curr_it = it++; | |
| 59 CPDF_CountedObject<CPDF_TransferFunc>* value = curr_it->second; | |
| 60 if (bRelease || value->use_count() < 2) { | |
| 61 delete value->get(); | |
| 62 delete value; | |
| 63 m_TransferFuncMap.erase(curr_it); | |
| 64 } | |
| 65 } | |
| 66 } | |
| 67 | |
| 68 CPDF_Type3Cache* CPDF_DocRenderData::GetCachedType3(CPDF_Type3Font* pFont) { | |
| 69 CPDF_CountedObject<CPDF_Type3Cache>* pCache; | |
| 70 auto it = m_Type3FaceMap.find(pFont); | |
| 71 if (it == m_Type3FaceMap.end()) { | |
| 72 CPDF_Type3Cache* pType3 = new CPDF_Type3Cache(pFont); | |
| 73 pCache = new CPDF_CountedObject<CPDF_Type3Cache>(pType3); | |
| 74 m_Type3FaceMap[pFont] = pCache; | |
| 75 } else { | |
| 76 pCache = it->second; | |
| 77 } | |
| 78 return pCache->AddRef(); | |
| 79 } | |
| 80 | |
| 81 void CPDF_DocRenderData::ReleaseCachedType3(CPDF_Type3Font* pFont) { | |
| 82 auto it = m_Type3FaceMap.find(pFont); | |
| 83 if (it != m_Type3FaceMap.end()) { | |
| 84 it->second->RemoveRef(); | |
| 85 if (it->second->use_count() < 2) { | |
| 86 delete it->second->get(); | |
| 87 delete it->second; | |
| 88 m_Type3FaceMap.erase(it); | |
| 89 } | |
| 90 } | |
| 91 } | |
| 92 | |
| 93 CPDF_RenderOptions::CPDF_RenderOptions() | 40 CPDF_RenderOptions::CPDF_RenderOptions() |
| 94 : m_ColorMode(RENDER_COLOR_NORMAL), | 41 : m_ColorMode(RENDER_COLOR_NORMAL), |
| 95 m_Flags(RENDER_CLEARTYPE), | 42 m_Flags(RENDER_CLEARTYPE), |
| 96 m_Interpolation(0), | 43 m_Interpolation(0), |
| 97 m_AddFlags(0), | 44 m_AddFlags(0), |
| 98 m_pOCContext(nullptr), | 45 m_pOCContext(nullptr), |
| 99 m_dwLimitCacheSize(1024 * 1024 * 100), | 46 m_dwLimitCacheSize(1024 * 1024 * 100), |
| 100 m_HalftoneLimit(-1), | 47 m_HalftoneLimit(-1), |
| 101 m_bDrawAnnots(false) {} | 48 m_bDrawAnnots(false) {} |
| 102 | 49 |
| (...skipping 977 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1080 return; | 1027 return; |
| 1081 } | 1028 } |
| 1082 } else { | 1029 } else { |
| 1083 m_pCurrentLayer->m_pObjectHolder->ContinueParse(pPause); | 1030 m_pCurrentLayer->m_pObjectHolder->ContinueParse(pPause); |
| 1084 if (!m_pCurrentLayer->m_pObjectHolder->IsParsed()) | 1031 if (!m_pCurrentLayer->m_pObjectHolder->IsParsed()) |
| 1085 return; | 1032 return; |
| 1086 } | 1033 } |
| 1087 } | 1034 } |
| 1088 } | 1035 } |
| 1089 | 1036 |
| 1090 CPDF_TransferFunc* CPDF_DocRenderData::GetTransferFunc(CPDF_Object* pObj) { | |
| 1091 if (!pObj) | |
| 1092 return nullptr; | |
| 1093 | |
| 1094 auto it = m_TransferFuncMap.find(pObj); | |
| 1095 if (it != m_TransferFuncMap.end()) { | |
| 1096 CPDF_CountedObject<CPDF_TransferFunc>* pTransferCounter = it->second; | |
| 1097 return pTransferCounter->AddRef(); | |
| 1098 } | |
| 1099 | |
| 1100 std::unique_ptr<CPDF_Function> pFuncs[3]; | |
| 1101 bool bUniTransfer = true; | |
| 1102 bool bIdentity = true; | |
| 1103 if (CPDF_Array* pArray = pObj->AsArray()) { | |
| 1104 bUniTransfer = false; | |
| 1105 if (pArray->GetCount() < 3) | |
| 1106 return nullptr; | |
| 1107 | |
| 1108 for (uint32_t i = 0; i < 3; ++i) { | |
| 1109 pFuncs[2 - i] = CPDF_Function::Load(pArray->GetDirectObjectAt(i)); | |
| 1110 if (!pFuncs[2 - i]) | |
| 1111 return nullptr; | |
| 1112 } | |
| 1113 } else { | |
| 1114 pFuncs[0] = CPDF_Function::Load(pObj); | |
| 1115 if (!pFuncs[0]) | |
| 1116 return nullptr; | |
| 1117 } | |
| 1118 CPDF_TransferFunc* pTransfer = new CPDF_TransferFunc(m_pPDFDoc); | |
| 1119 CPDF_CountedObject<CPDF_TransferFunc>* pTransferCounter = | |
| 1120 new CPDF_CountedObject<CPDF_TransferFunc>(pTransfer); | |
| 1121 m_TransferFuncMap[pObj] = pTransferCounter; | |
| 1122 static const int kMaxOutputs = 16; | |
| 1123 FX_FLOAT output[kMaxOutputs]; | |
| 1124 FXSYS_memset(output, 0, sizeof(output)); | |
| 1125 FX_FLOAT input; | |
| 1126 int noutput; | |
| 1127 for (int v = 0; v < 256; ++v) { | |
| 1128 input = (FX_FLOAT)v / 255.0f; | |
| 1129 if (bUniTransfer) { | |
| 1130 if (pFuncs[0] && pFuncs[0]->CountOutputs() <= kMaxOutputs) | |
| 1131 pFuncs[0]->Call(&input, 1, output, noutput); | |
| 1132 int o = FXSYS_round(output[0] * 255); | |
| 1133 if (o != v) | |
| 1134 bIdentity = false; | |
| 1135 for (int i = 0; i < 3; ++i) { | |
| 1136 pTransfer->m_Samples[i * 256 + v] = o; | |
| 1137 } | |
| 1138 } else { | |
| 1139 for (int i = 0; i < 3; ++i) { | |
| 1140 if (pFuncs[i] && pFuncs[i]->CountOutputs() <= kMaxOutputs) { | |
| 1141 pFuncs[i]->Call(&input, 1, output, noutput); | |
| 1142 int o = FXSYS_round(output[0] * 255); | |
| 1143 if (o != v) | |
| 1144 bIdentity = false; | |
| 1145 pTransfer->m_Samples[i * 256 + v] = o; | |
| 1146 } else { | |
| 1147 pTransfer->m_Samples[i * 256 + v] = v; | |
| 1148 } | |
| 1149 } | |
| 1150 } | |
| 1151 } | |
| 1152 | |
| 1153 pTransfer->m_bIdentity = bIdentity; | |
| 1154 return pTransferCounter->AddRef(); | |
| 1155 } | |
| 1156 | |
| 1157 void CPDF_DocRenderData::ReleaseTransferFunc(CPDF_Object* pObj) { | |
| 1158 auto it = m_TransferFuncMap.find(pObj); | |
| 1159 if (it != m_TransferFuncMap.end()) { | |
| 1160 it->second->RemoveRef(); | |
| 1161 if (it->second->use_count() < 2) { | |
| 1162 delete it->second->get(); | |
| 1163 delete it->second; | |
| 1164 m_TransferFuncMap.erase(it); | |
| 1165 } | |
| 1166 } | |
| 1167 } | |
| 1168 | |
| 1169 CPDF_DeviceBuffer::CPDF_DeviceBuffer() | 1037 CPDF_DeviceBuffer::CPDF_DeviceBuffer() |
| 1170 : m_pDevice(nullptr), m_pContext(nullptr), m_pObject(nullptr) {} | 1038 : m_pDevice(nullptr), m_pContext(nullptr), m_pObject(nullptr) {} |
| 1171 | 1039 |
| 1172 CPDF_DeviceBuffer::~CPDF_DeviceBuffer() {} | 1040 CPDF_DeviceBuffer::~CPDF_DeviceBuffer() {} |
| 1173 | 1041 |
| 1174 bool CPDF_DeviceBuffer::Initialize(CPDF_RenderContext* pContext, | 1042 bool CPDF_DeviceBuffer::Initialize(CPDF_RenderContext* pContext, |
| 1175 CFX_RenderDevice* pDevice, | 1043 CFX_RenderDevice* pDevice, |
| 1176 FX_RECT* pRect, | 1044 FX_RECT* pRect, |
| 1177 const CPDF_PageObject* pObj, | 1045 const CPDF_PageObject* pObj, |
| 1178 int max_dpi) { | 1046 int max_dpi) { |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1293 m_pDevice->StretchDIBits(m_pBitmapDevice->GetBitmap(), m_Rect.left, | 1161 m_pDevice->StretchDIBits(m_pBitmapDevice->GetBitmap(), m_Rect.left, |
| 1294 m_Rect.top, m_Rect.Width(), m_Rect.Height()); | 1162 m_Rect.top, m_Rect.Width(), m_Rect.Height()); |
| 1295 } | 1163 } |
| 1296 } | 1164 } |
| 1297 | 1165 |
| 1298 #if defined _SKIA_SUPPORT_ | 1166 #if defined _SKIA_SUPPORT_ |
| 1299 void CPDF_RenderStatus::DebugVerifyDeviceIsPreMultiplied() const { | 1167 void CPDF_RenderStatus::DebugVerifyDeviceIsPreMultiplied() const { |
| 1300 m_pDevice->DebugVerifyBitmapIsPreMultiplied(); | 1168 m_pDevice->DebugVerifyBitmapIsPreMultiplied(); |
| 1301 } | 1169 } |
| 1302 #endif | 1170 #endif |
| OLD | NEW |