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 "render_int.h" | 7 #include "core/src/fpdfapi/fpdf_render/render_int.h" |
8 | 8 |
9 #include "core/include/fpdfapi/fpdf_module.h" | 9 #include "core/include/fpdfapi/fpdf_module.h" |
10 #include "core/include/fpdfapi/fpdf_render.h" | 10 #include "core/include/fpdfapi/fpdf_render.h" |
11 #include "core/include/fxge/fx_ge.h" | 11 #include "core/include/fxge/fx_ge.h" |
12 #include "core/src/fpdfapi/fpdf_page/pageint.h" | 12 #include "core/src/fpdfapi/fpdf_page/pageint.h" |
13 | 13 |
14 CPDF_DocRenderData::CPDF_DocRenderData(CPDF_Document* pPDFDoc) | 14 CPDF_DocRenderData::CPDF_DocRenderData(CPDF_Document* pPDFDoc) |
15 : m_pPDFDoc(pPDFDoc), m_pFontCache(new CFX_FontCache) {} | 15 : m_pPDFDoc(pPDFDoc), m_pFontCache(new CFX_FontCache) {} |
16 | 16 |
17 CPDF_DocRenderData::~CPDF_DocRenderData() { | 17 CPDF_DocRenderData::~CPDF_DocRenderData() { |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 void ClearDocData(CPDF_DocRenderData* p) override; | 80 void ClearDocData(CPDF_DocRenderData* p) override; |
81 | 81 |
82 CPDF_DocRenderData* GetRenderData() override { return &m_RenderData; } | 82 CPDF_DocRenderData* GetRenderData() override { return &m_RenderData; } |
83 | 83 |
84 CPDF_PageRenderCache* CreatePageCache(CPDF_Page* pPage) override { | 84 CPDF_PageRenderCache* CreatePageCache(CPDF_Page* pPage) override { |
85 return new CPDF_PageRenderCache(pPage); | 85 return new CPDF_PageRenderCache(pPage); |
86 } | 86 } |
87 | 87 |
88 void DestroyPageCache(CPDF_PageRenderCache* pCache) override; | 88 void DestroyPageCache(CPDF_PageRenderCache* pCache) override; |
89 | 89 |
90 CPDF_RenderConfig* GetConfig() override { return &m_RenderConfig; } | |
91 | |
92 CPDF_DocRenderData m_RenderData; | 90 CPDF_DocRenderData m_RenderData; |
93 CPDF_RenderConfig m_RenderConfig; | |
94 }; | 91 }; |
95 | 92 |
96 CPDF_DocRenderData* CPDF_RenderModule::CreateDocData(CPDF_Document* pDoc) { | 93 CPDF_DocRenderData* CPDF_RenderModule::CreateDocData(CPDF_Document* pDoc) { |
97 return new CPDF_DocRenderData(pDoc); | 94 return new CPDF_DocRenderData(pDoc); |
98 } | 95 } |
99 void CPDF_RenderModule::DestroyDocData(CPDF_DocRenderData* pDocData) { | 96 void CPDF_RenderModule::DestroyDocData(CPDF_DocRenderData* pDocData) { |
100 delete pDocData; | 97 delete pDocData; |
101 } | 98 } |
102 void CPDF_RenderModule::ClearDocData(CPDF_DocRenderData* p) { | 99 void CPDF_RenderModule::ClearDocData(CPDF_DocRenderData* p) { |
103 if (p) { | 100 if (p) { |
(...skipping 927 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1031 | 1028 |
1032 CPDF_ProgressiveRenderer::CPDF_ProgressiveRenderer( | 1029 CPDF_ProgressiveRenderer::CPDF_ProgressiveRenderer( |
1033 CPDF_RenderContext* pContext, | 1030 CPDF_RenderContext* pContext, |
1034 CFX_RenderDevice* pDevice, | 1031 CFX_RenderDevice* pDevice, |
1035 const CPDF_RenderOptions* pOptions) | 1032 const CPDF_RenderOptions* pOptions) |
1036 : m_Status(Ready), | 1033 : m_Status(Ready), |
1037 m_pContext(pContext), | 1034 m_pContext(pContext), |
1038 m_pDevice(pDevice), | 1035 m_pDevice(pDevice), |
1039 m_pOptions(pOptions), | 1036 m_pOptions(pOptions), |
1040 m_LayerIndex(0), | 1037 m_LayerIndex(0), |
1041 m_ObjectIndex(0), | 1038 m_pCurrentLayer(nullptr), |
1042 m_ObjectPos(nullptr), | 1039 m_LastObjectRendered(nullptr) {} |
1043 m_PrevLastPos(nullptr) { | |
1044 } | |
1045 | 1040 |
1046 CPDF_ProgressiveRenderer::~CPDF_ProgressiveRenderer() { | 1041 CPDF_ProgressiveRenderer::~CPDF_ProgressiveRenderer() { |
1047 if (m_pRenderStatus) | 1042 if (m_pRenderStatus) |
1048 m_pDevice->RestoreState(); | 1043 m_pDevice->RestoreState(); |
1049 } | 1044 } |
1050 | 1045 |
1051 void CPDF_ProgressiveRenderer::Start(IFX_Pause* pPause) { | 1046 void CPDF_ProgressiveRenderer::Start(IFX_Pause* pPause) { |
1052 if (!m_pContext || !m_pDevice || m_Status != Ready) { | 1047 if (!m_pContext || !m_pDevice || m_Status != Ready) { |
1053 m_Status = Failed; | 1048 m_Status = Failed; |
1054 return; | 1049 return; |
1055 } | 1050 } |
1056 m_Status = ToBeContinued; | 1051 m_Status = ToBeContinued; |
1057 Continue(pPause); | 1052 Continue(pPause); |
1058 } | 1053 } |
1059 | 1054 |
1060 void CPDF_ProgressiveRenderer::Continue(IFX_Pause* pPause) { | 1055 void CPDF_ProgressiveRenderer::Continue(IFX_Pause* pPause) { |
1061 if (m_Status != ToBeContinued) { | 1056 while (m_Status == ToBeContinued) { |
1062 return; | 1057 if (!m_pCurrentLayer) { |
1063 } | 1058 if (m_LayerIndex >= m_pContext->CountLayers()) { |
1064 FX_DWORD nLayers = m_pContext->CountLayers(); | 1059 m_Status = Done; |
1065 for (; m_LayerIndex < nLayers; m_LayerIndex++) { | 1060 return; |
1066 CPDF_RenderContext::Layer* pLayer = m_pContext->GetLayer(m_LayerIndex); | |
1067 FX_POSITION LastPos = pLayer->m_pObjectList->GetLastObjectPosition(); | |
1068 if (!m_ObjectPos) { | |
1069 if (LastPos == m_PrevLastPos) { | |
1070 if (!pLayer->m_pObjectList->IsParsed()) { | |
1071 pLayer->m_pObjectList->ContinueParse(pPause); | |
1072 if (!pLayer->m_pObjectList->IsParsed()) { | |
1073 return; | |
1074 } | |
1075 LastPos = pLayer->m_pObjectList->GetLastObjectPosition(); | |
1076 } | |
1077 } | 1061 } |
1078 if (LastPos == m_PrevLastPos) { | 1062 m_pCurrentLayer = m_pContext->GetLayer(m_LayerIndex); |
1079 if (m_pRenderStatus) { | 1063 m_LastObjectRendered = nullptr; |
1080 m_pRenderStatus.reset(); | |
1081 m_pDevice->RestoreState(); | |
1082 m_ObjectPos = NULL; | |
1083 m_PrevLastPos = NULL; | |
1084 } | |
1085 continue; | |
1086 } | |
1087 if (m_PrevLastPos) { | |
1088 m_ObjectPos = m_PrevLastPos; | |
1089 pLayer->m_pObjectList->GetNextObject(m_ObjectPos); | |
1090 } else { | |
1091 m_ObjectPos = pLayer->m_pObjectList->GetFirstObjectPosition(); | |
1092 } | |
1093 m_PrevLastPos = LastPos; | |
1094 } | |
1095 if (!m_pRenderStatus) { | |
1096 m_ObjectPos = pLayer->m_pObjectList->GetFirstObjectPosition(); | |
1097 m_ObjectIndex = 0; | |
1098 m_pRenderStatus.reset(new CPDF_RenderStatus()); | 1064 m_pRenderStatus.reset(new CPDF_RenderStatus()); |
1099 m_pRenderStatus->Initialize( | 1065 m_pRenderStatus->Initialize( |
1100 m_pContext, m_pDevice, NULL, NULL, NULL, NULL, m_pOptions, | 1066 m_pContext, m_pDevice, NULL, NULL, NULL, NULL, m_pOptions, |
1101 pLayer->m_pObjectList->m_Transparency, FALSE, NULL); | 1067 m_pCurrentLayer->m_pObjectList->m_Transparency, FALSE, NULL); |
1102 m_pDevice->SaveState(); | 1068 m_pDevice->SaveState(); |
1103 m_ClipRect = m_pDevice->GetClipBox(); | 1069 m_ClipRect = m_pDevice->GetClipBox(); |
1104 CFX_Matrix device2object; | 1070 CFX_Matrix device2object; |
1105 device2object.SetReverse(pLayer->m_Matrix); | 1071 device2object.SetReverse(m_pCurrentLayer->m_Matrix); |
1106 device2object.TransformRect(m_ClipRect); | 1072 device2object.TransformRect(m_ClipRect); |
1107 } | 1073 } |
1108 int objs_to_go = CPDF_ModuleMgr::Get() | 1074 FX_POSITION pos; |
1109 ->GetRenderModule() | 1075 if (m_LastObjectRendered) { |
1110 ->GetConfig() | 1076 pos = m_LastObjectRendered; |
1111 ->m_RenderStepLimit; | 1077 m_pCurrentLayer->m_pObjectList->GetNextObject(pos); |
1112 while (m_ObjectPos) { | 1078 } else { |
| 1079 pos = m_pCurrentLayer->m_pObjectList->GetFirstObjectPosition(); |
| 1080 } |
| 1081 int nObjsToGo = kStepLimit; |
| 1082 while (pos) { |
1113 CPDF_PageObject* pCurObj = | 1083 CPDF_PageObject* pCurObj = |
1114 pLayer->m_pObjectList->GetObjectAt(m_ObjectPos); | 1084 m_pCurrentLayer->m_pObjectList->GetObjectAt(pos); |
1115 if (pCurObj && pCurObj->m_Left <= m_ClipRect.right && | 1085 if (pCurObj && pCurObj->m_Left <= m_ClipRect.right && |
1116 pCurObj->m_Right >= m_ClipRect.left && | 1086 pCurObj->m_Right >= m_ClipRect.left && |
1117 pCurObj->m_Bottom <= m_ClipRect.top && | 1087 pCurObj->m_Bottom <= m_ClipRect.top && |
1118 pCurObj->m_Top >= m_ClipRect.bottom) { | 1088 pCurObj->m_Top >= m_ClipRect.bottom) { |
1119 if (m_pRenderStatus->ContinueSingleObject(pCurObj, &pLayer->m_Matrix, | 1089 if (m_pRenderStatus->ContinueSingleObject( |
1120 pPause)) { | 1090 pCurObj, &m_pCurrentLayer->m_Matrix, pPause)) { |
1121 return; | 1091 return; |
1122 } | 1092 } |
1123 if (pCurObj->m_Type == CPDF_PageObject::IMAGE && | 1093 if (pCurObj->m_Type == CPDF_PageObject::IMAGE && |
1124 m_pRenderStatus->m_Options.m_Flags & RENDER_LIMITEDIMAGECACHE) { | 1094 m_pRenderStatus->m_Options.m_Flags & RENDER_LIMITEDIMAGECACHE) { |
1125 m_pContext->GetPageCache()->CacheOptimization( | 1095 m_pContext->GetPageCache()->CacheOptimization( |
1126 m_pRenderStatus->m_Options.m_dwLimitCacheSize); | 1096 m_pRenderStatus->m_Options.m_dwLimitCacheSize); |
1127 } | 1097 } |
1128 if (pCurObj->m_Type == CPDF_PageObject::FORM || | 1098 if (pCurObj->m_Type == CPDF_PageObject::FORM || |
1129 pCurObj->m_Type == CPDF_PageObject::SHADING) { | 1099 pCurObj->m_Type == CPDF_PageObject::SHADING) { |
1130 objs_to_go = 0; | 1100 nObjsToGo = 0; |
1131 } else { | 1101 } else { |
1132 objs_to_go--; | 1102 --nObjsToGo; |
1133 } | 1103 } |
1134 } | 1104 } |
1135 m_ObjectIndex++; | 1105 m_LastObjectRendered = pos; |
1136 pLayer->m_pObjectList->GetNextObject(m_ObjectPos); | 1106 if (nObjsToGo == 0) { |
1137 if (objs_to_go == 0) { | 1107 if (pPause && pPause->NeedToPauseNow()) |
1138 if (pPause && pPause->NeedToPauseNow()) { | |
1139 return; | 1108 return; |
1140 } | 1109 nObjsToGo = kStepLimit; |
1141 objs_to_go = CPDF_ModuleMgr::Get() | |
1142 ->GetRenderModule() | |
1143 ->GetConfig() | |
1144 ->m_RenderStepLimit; | |
1145 } | 1110 } |
| 1111 m_pCurrentLayer->m_pObjectList->GetNextObject(pos); |
1146 } | 1112 } |
1147 if (!pLayer->m_pObjectList->IsParsed()) { | 1113 if (m_pCurrentLayer->m_pObjectList->IsParsed()) { |
1148 return; | 1114 m_pRenderStatus.reset(); |
1149 } | 1115 m_pDevice->RestoreState(); |
1150 m_pRenderStatus.reset(); | 1116 m_pCurrentLayer = nullptr; |
1151 m_pDevice->RestoreState(); | 1117 m_LastObjectRendered = nullptr; |
1152 m_ObjectPos = NULL; | |
1153 m_PrevLastPos = NULL; | |
1154 if (pPause && pPause->NeedToPauseNow()) { | |
1155 m_LayerIndex++; | 1118 m_LayerIndex++; |
1156 return; | 1119 if (pPause && pPause->NeedToPauseNow()) { |
| 1120 return; |
| 1121 } |
| 1122 } else { |
| 1123 m_pCurrentLayer->m_pObjectList->ContinueParse(pPause); |
| 1124 if (!m_pCurrentLayer->m_pObjectList->IsParsed()) |
| 1125 return; |
1157 } | 1126 } |
1158 } | 1127 } |
1159 m_Status = Done; | |
1160 } | 1128 } |
1161 int CPDF_ProgressiveRenderer::EstimateProgress() { | 1129 |
1162 if (!m_pContext) { | |
1163 return 0; | |
1164 } | |
1165 FX_DWORD nLayers = m_pContext->CountLayers(); | |
1166 int nTotal = 0; | |
1167 int nRendered = 0; | |
1168 for (FX_DWORD layer = 0; layer < nLayers; layer++) { | |
1169 CPDF_RenderContext::Layer* pLayer = m_pContext->GetLayer(layer); | |
1170 int nObjs = pLayer->m_pObjectList->CountObjects(); | |
1171 if (layer == m_LayerIndex) { | |
1172 nRendered += m_ObjectIndex; | |
1173 } else if (layer < m_LayerIndex) { | |
1174 nRendered += nObjs; | |
1175 } | |
1176 nTotal += nObjs; | |
1177 } | |
1178 if (nTotal == 0) { | |
1179 return 0; | |
1180 } | |
1181 return 100 * nRendered / nTotal; | |
1182 } | |
1183 CPDF_TransferFunc* CPDF_DocRenderData::GetTransferFunc(CPDF_Object* pObj) { | 1130 CPDF_TransferFunc* CPDF_DocRenderData::GetTransferFunc(CPDF_Object* pObj) { |
1184 if (!pObj) | 1131 if (!pObj) |
1185 return nullptr; | 1132 return nullptr; |
1186 | 1133 |
1187 auto it = m_TransferFuncMap.find(pObj); | 1134 auto it = m_TransferFuncMap.find(pObj); |
1188 if (it != m_TransferFuncMap.end()) { | 1135 if (it != m_TransferFuncMap.end()) { |
1189 CPDF_CountedObject<CPDF_TransferFunc>* pTransferCounter = it->second; | 1136 CPDF_CountedObject<CPDF_TransferFunc>* pTransferCounter = it->second; |
1190 return pTransferCounter->AddRef(); | 1137 return pTransferCounter->AddRef(); |
1191 } | 1138 } |
1192 | 1139 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1245 | 1192 |
1246 pTransfer->m_bIdentity = bIdentity; | 1193 pTransfer->m_bIdentity = bIdentity; |
1247 return pTransferCounter->AddRef(); | 1194 return pTransferCounter->AddRef(); |
1248 } | 1195 } |
1249 | 1196 |
1250 void CPDF_DocRenderData::ReleaseTransferFunc(CPDF_Object* pObj) { | 1197 void CPDF_DocRenderData::ReleaseTransferFunc(CPDF_Object* pObj) { |
1251 auto it = m_TransferFuncMap.find(pObj); | 1198 auto it = m_TransferFuncMap.find(pObj); |
1252 if (it != m_TransferFuncMap.end()) | 1199 if (it != m_TransferFuncMap.end()) |
1253 it->second->RemoveRef(); | 1200 it->second->RemoveRef(); |
1254 } | 1201 } |
1255 CPDF_RenderConfig::CPDF_RenderConfig() { | |
1256 m_HalftoneLimit = 0; | |
1257 m_RenderStepLimit = 100; | |
1258 } | |
1259 CPDF_RenderConfig::~CPDF_RenderConfig() {} | |
1260 | 1202 |
1261 CPDF_DeviceBuffer::CPDF_DeviceBuffer() | 1203 CPDF_DeviceBuffer::CPDF_DeviceBuffer() |
1262 : m_pDevice(nullptr), m_pContext(nullptr), m_pObject(nullptr) {} | 1204 : m_pDevice(nullptr), m_pContext(nullptr), m_pObject(nullptr) {} |
1263 | 1205 |
1264 CPDF_DeviceBuffer::~CPDF_DeviceBuffer() { | 1206 CPDF_DeviceBuffer::~CPDF_DeviceBuffer() { |
1265 } | 1207 } |
1266 | 1208 |
1267 FX_BOOL CPDF_DeviceBuffer::Initialize(CPDF_RenderContext* pContext, | 1209 FX_BOOL CPDF_DeviceBuffer::Initialize(CPDF_RenderContext* pContext, |
1268 CFX_RenderDevice* pDevice, | 1210 CFX_RenderDevice* pDevice, |
1269 FX_RECT* pRect, | 1211 FX_RECT* pRect, |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1398 item.GetParamType() == CPDF_ContentMarkItem::PropertiesDict) { | 1340 item.GetParamType() == CPDF_ContentMarkItem::PropertiesDict) { |
1399 CPDF_Dictionary* pOCG = | 1341 CPDF_Dictionary* pOCG = |
1400 ToDictionary(static_cast<CPDF_Object*>(item.GetParam())); | 1342 ToDictionary(static_cast<CPDF_Object*>(item.GetParam())); |
1401 if (!CheckOCGVisible(pOCG)) { | 1343 if (!CheckOCGVisible(pOCG)) { |
1402 return FALSE; | 1344 return FALSE; |
1403 } | 1345 } |
1404 } | 1346 } |
1405 } | 1347 } |
1406 return TRUE; | 1348 return TRUE; |
1407 } | 1349 } |
OLD | NEW |