Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(872)

Side by Side Diff: core/fpdfapi/fpdf_render/fpdf_render.cpp

Issue 2120353004: copy graphics state fully (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: wip; remove byte order Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | core/fpdfapi/fpdf_render/fpdf_render_image.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/fpdf_render/render_int.h" 7 #include "core/fpdfapi/fpdf_render/render_int.h"
8 8
9 #include "core/fpdfapi/fpdf_font/cpdf_type3char.h" 9 #include "core/fpdfapi/fpdf_font/cpdf_type3char.h"
10 #include "core/fpdfapi/fpdf_font/cpdf_type3font.h" 10 #include "core/fpdfapi/fpdf_font/cpdf_type3font.h"
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 } else { 206 } else {
207 m_InitialStates.DefaultStates(); 207 m_InitialStates.DefaultStates();
208 } 208 }
209 m_pImageRenderer.reset(); 209 m_pImageRenderer.reset();
210 m_Transparency = transparency; 210 m_Transparency = transparency;
211 return TRUE; 211 return TRUE;
212 } 212 }
213 void CPDF_RenderStatus::RenderObjectList( 213 void CPDF_RenderStatus::RenderObjectList(
214 const CPDF_PageObjectHolder* pObjectHolder, 214 const CPDF_PageObjectHolder* pObjectHolder,
215 const CFX_Matrix* pObj2Device) { 215 const CFX_Matrix* pObj2Device) {
216 #if defined _SKIA_SUPPORT_
217 DebugVerifyDeviceIsPreMultiplied();
218 #endif
216 CFX_FloatRect clip_rect(m_pDevice->GetClipBox()); 219 CFX_FloatRect clip_rect(m_pDevice->GetClipBox());
217 CFX_Matrix device2object; 220 CFX_Matrix device2object;
218 device2object.SetReverse(*pObj2Device); 221 device2object.SetReverse(*pObj2Device);
219 device2object.TransformRect(clip_rect); 222 device2object.TransformRect(clip_rect);
220 223
221 for (const auto& pCurObj : *pObjectHolder->GetPageObjectList()) { 224 for (const auto& pCurObj : *pObjectHolder->GetPageObjectList()) {
222 if (pCurObj.get() == m_pStopObj) { 225 if (pCurObj.get() == m_pStopObj) {
223 m_bStopped = TRUE; 226 m_bStopped = TRUE;
224 return; 227 return;
225 } 228 }
226 if (!pCurObj) 229 if (!pCurObj)
227 continue; 230 continue;
228 231
229 if (pCurObj->m_Left > clip_rect.right || 232 if (pCurObj->m_Left > clip_rect.right ||
230 pCurObj->m_Right < clip_rect.left || 233 pCurObj->m_Right < clip_rect.left ||
231 pCurObj->m_Bottom > clip_rect.top || 234 pCurObj->m_Bottom > clip_rect.top ||
232 pCurObj->m_Top < clip_rect.bottom) { 235 pCurObj->m_Top < clip_rect.bottom) {
233 continue; 236 continue;
234 } 237 }
235 RenderSingleObject(pCurObj.get(), pObj2Device); 238 RenderSingleObject(pCurObj.get(), pObj2Device);
236 if (m_bStopped) 239 if (m_bStopped)
237 return; 240 return;
238 } 241 }
242 #if defined _SKIA_SUPPORT_
243 DebugVerifyDeviceIsPreMultiplied();
244 #endif
239 } 245 }
246
240 void CPDF_RenderStatus::RenderSingleObject(const CPDF_PageObject* pObj, 247 void CPDF_RenderStatus::RenderSingleObject(const CPDF_PageObject* pObj,
241 const CFX_Matrix* pObj2Device) { 248 const CFX_Matrix* pObj2Device) {
249 #if defined _SKIA_SUPPORT_
250 DebugVerifyDeviceIsPreMultiplied();
251 #endif
242 CFX_AutoRestorer<int> restorer(&s_CurrentRecursionDepth); 252 CFX_AutoRestorer<int> restorer(&s_CurrentRecursionDepth);
243 if (++s_CurrentRecursionDepth > kRenderMaxRecursionDepth) { 253 if (++s_CurrentRecursionDepth > kRenderMaxRecursionDepth) {
244 return; 254 return;
245 } 255 }
246 m_pCurObj = pObj; 256 m_pCurObj = pObj;
247 if (m_Options.m_pOCContext && pObj->m_ContentMark.NotNull()) { 257 if (m_Options.m_pOCContext && pObj->m_ContentMark.NotNull()) {
248 if (!m_Options.m_pOCContext->CheckObjectVisible(pObj)) { 258 if (!m_Options.m_pOCContext->CheckObjectVisible(pObj)) {
249 return; 259 return;
250 } 260 }
251 } 261 }
252 ProcessClipPath(pObj->m_ClipPath, pObj2Device); 262 ProcessClipPath(pObj->m_ClipPath, pObj2Device);
253 if (ProcessTransparency(pObj, pObj2Device)) { 263 if (ProcessTransparency(pObj, pObj2Device)) {
254 return; 264 return;
255 } 265 }
256 ProcessObjectNoClip(pObj, pObj2Device); 266 ProcessObjectNoClip(pObj, pObj2Device);
267 #if defined _SKIA_SUPPORT_
268 DebugVerifyDeviceIsPreMultiplied();
269 #endif
257 } 270 }
258 271
259 FX_BOOL CPDF_RenderStatus::ContinueSingleObject(const CPDF_PageObject* pObj, 272 FX_BOOL CPDF_RenderStatus::ContinueSingleObject(const CPDF_PageObject* pObj,
260 const CFX_Matrix* pObj2Device, 273 const CFX_Matrix* pObj2Device,
261 IFX_Pause* pPause) { 274 IFX_Pause* pPause) {
262 if (m_pImageRenderer) { 275 if (m_pImageRenderer) {
263 if (m_pImageRenderer->Continue(pPause)) 276 if (m_pImageRenderer->Continue(pPause))
264 return TRUE; 277 return TRUE;
265 278
266 if (!m_pImageRenderer->m_Result) 279 if (!m_pImageRenderer->m_Result)
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 rtClip.bottom = 325 rtClip.bottom =
313 rtClip.top + (int32_t)FXSYS_ceil((FX_FLOAT)rtClip.Height() * d); 326 rtClip.top + (int32_t)FXSYS_ceil((FX_FLOAT)rtClip.Height() * d);
314 } 327 }
315 } 328 }
316 rect.Intersect(rtClip); 329 rect.Intersect(rtClip);
317 return rect.IsEmpty(); 330 return rect.IsEmpty();
318 } 331 }
319 332
320 void CPDF_RenderStatus::ProcessObjectNoClip(const CPDF_PageObject* pObj, 333 void CPDF_RenderStatus::ProcessObjectNoClip(const CPDF_PageObject* pObj,
321 const CFX_Matrix* pObj2Device) { 334 const CFX_Matrix* pObj2Device) {
335 #if defined _SKIA_SUPPORT_
336 DebugVerifyDeviceIsPreMultiplied();
337 #endif
322 FX_BOOL bRet = FALSE; 338 FX_BOOL bRet = FALSE;
323 switch (pObj->GetType()) { 339 switch (pObj->GetType()) {
324 case CPDF_PageObject::TEXT: 340 case CPDF_PageObject::TEXT:
325 bRet = ProcessText(pObj->AsText(), pObj2Device, nullptr); 341 bRet = ProcessText(pObj->AsText(), pObj2Device, nullptr);
326 break; 342 break;
327 case CPDF_PageObject::PATH: 343 case CPDF_PageObject::PATH:
328 bRet = ProcessPath(pObj->AsPath(), pObj2Device); 344 bRet = ProcessPath(pObj->AsPath(), pObj2Device);
329 break; 345 break;
330 case CPDF_PageObject::IMAGE: 346 case CPDF_PageObject::IMAGE:
331 bRet = ProcessImage(pObj->AsImage(), pObj2Device); 347 bRet = ProcessImage(pObj->AsImage(), pObj2Device);
332 break; 348 break;
333 case CPDF_PageObject::SHADING: 349 case CPDF_PageObject::SHADING:
334 ProcessShading(pObj->AsShading(), pObj2Device); 350 ProcessShading(pObj->AsShading(), pObj2Device);
335 return; 351 return;
336 case CPDF_PageObject::FORM: 352 case CPDF_PageObject::FORM:
337 bRet = ProcessForm(pObj->AsForm(), pObj2Device); 353 bRet = ProcessForm(pObj->AsForm(), pObj2Device);
338 break; 354 break;
339 } 355 }
340 if (!bRet) 356 if (!bRet)
341 DrawObjWithBackground(pObj, pObj2Device); 357 DrawObjWithBackground(pObj, pObj2Device);
358 #if defined _SKIA_SUPPORT_
359 DebugVerifyDeviceIsPreMultiplied();
360 #endif
342 } 361 }
343 362
344 FX_BOOL CPDF_RenderStatus::DrawObjWithBlend(const CPDF_PageObject* pObj, 363 FX_BOOL CPDF_RenderStatus::DrawObjWithBlend(const CPDF_PageObject* pObj,
345 const CFX_Matrix* pObj2Device) { 364 const CFX_Matrix* pObj2Device) {
346 FX_BOOL bRet = FALSE; 365 FX_BOOL bRet = FALSE;
347 switch (pObj->GetType()) { 366 switch (pObj->GetType()) {
348 case CPDF_PageObject::PATH: 367 case CPDF_PageObject::PATH:
349 bRet = ProcessPath(pObj->AsPath(), pObj2Device); 368 bRet = ProcessPath(pObj->AsPath(), pObj2Device);
350 break; 369 break;
351 case CPDF_PageObject::IMAGE: 370 case CPDF_PageObject::IMAGE:
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 pFormResource = pFormObj->m_pForm->m_pFormDict->GetDictBy("Resources"); 408 pFormResource = pFormObj->m_pForm->m_pFormDict->GetDictBy("Resources");
390 } 409 }
391 } 410 }
392 CPDF_RenderStatus status; 411 CPDF_RenderStatus status;
393 status.Initialize(m_pContext, buffer.GetDevice(), buffer.GetMatrix(), nullptr, 412 status.Initialize(m_pContext, buffer.GetDevice(), buffer.GetMatrix(), nullptr,
394 nullptr, nullptr, &m_Options, m_Transparency, 413 nullptr, nullptr, &m_Options, m_Transparency,
395 m_bDropObjects, pFormResource); 414 m_bDropObjects, pFormResource);
396 status.RenderSingleObject(pObj, &matrix); 415 status.RenderSingleObject(pObj, &matrix);
397 buffer.OutputToDevice(); 416 buffer.OutputToDevice();
398 } 417 }
418
399 FX_BOOL CPDF_RenderStatus::ProcessForm(const CPDF_FormObject* pFormObj, 419 FX_BOOL CPDF_RenderStatus::ProcessForm(const CPDF_FormObject* pFormObj,
400 const CFX_Matrix* pObj2Device) { 420 const CFX_Matrix* pObj2Device) {
421 #if defined _SKIA_SUPPORT_
422 DebugVerifyDeviceIsPreMultiplied();
423 #endif
401 CPDF_Dictionary* pOC = pFormObj->m_pForm->m_pFormDict->GetDictBy("OC"); 424 CPDF_Dictionary* pOC = pFormObj->m_pForm->m_pFormDict->GetDictBy("OC");
402 if (pOC && m_Options.m_pOCContext && 425 if (pOC && m_Options.m_pOCContext &&
403 !m_Options.m_pOCContext->CheckOCGVisible(pOC)) { 426 !m_Options.m_pOCContext->CheckOCGVisible(pOC)) {
404 return TRUE; 427 return TRUE;
405 } 428 }
406 CFX_Matrix matrix = pFormObj->m_FormMatrix; 429 CFX_Matrix matrix = pFormObj->m_FormMatrix;
407 matrix.Concat(*pObj2Device); 430 matrix.Concat(*pObj2Device);
408 CPDF_Dictionary* pResources = nullptr; 431 CPDF_Dictionary* pResources = nullptr;
409 if (pFormObj->m_pForm && pFormObj->m_pForm->m_pFormDict) { 432 if (pFormObj->m_pForm && pFormObj->m_pForm->m_pFormDict) {
410 pResources = pFormObj->m_pForm->m_pFormDict->GetDictBy("Resources"); 433 pResources = pFormObj->m_pForm->m_pFormDict->GetDictBy("Resources");
411 } 434 }
412 CPDF_RenderStatus status; 435 CPDF_RenderStatus status;
413 status.Initialize(m_pContext, m_pDevice, nullptr, m_pStopObj, this, pFormObj, 436 status.Initialize(m_pContext, m_pDevice, nullptr, m_pStopObj, this, pFormObj,
414 &m_Options, m_Transparency, m_bDropObjects, pResources, 437 &m_Options, m_Transparency, m_bDropObjects, pResources,
415 FALSE); 438 FALSE);
416 status.m_curBlend = m_curBlend; 439 status.m_curBlend = m_curBlend;
417 m_pDevice->SaveState(); 440 m_pDevice->SaveState();
418 status.RenderObjectList(pFormObj->m_pForm, &matrix); 441 status.RenderObjectList(pFormObj->m_pForm, &matrix);
419 m_bStopped = status.m_bStopped; 442 m_bStopped = status.m_bStopped;
420 m_pDevice->RestoreState(false); 443 m_pDevice->RestoreState(false);
444 #if defined _SKIA_SUPPORT_
445 DebugVerifyDeviceIsPreMultiplied();
446 #endif
421 return TRUE; 447 return TRUE;
422 } 448 }
449
423 FX_BOOL IsAvailableMatrix(const CFX_Matrix& matrix) { 450 FX_BOOL IsAvailableMatrix(const CFX_Matrix& matrix) {
424 if (matrix.a == 0 || matrix.d == 0) { 451 if (matrix.a == 0 || matrix.d == 0) {
425 return matrix.b != 0 && matrix.c != 0; 452 return matrix.b != 0 && matrix.c != 0;
426 } 453 }
427 if (matrix.b == 0 || matrix.c == 0) { 454 if (matrix.b == 0 || matrix.c == 0) {
428 return matrix.a != 0 && matrix.d != 0; 455 return matrix.a != 0 && matrix.d != 0;
429 } 456 }
430 return TRUE; 457 return TRUE;
431 } 458 }
432 459
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
638 } 665 }
639 int fill_mode = pPathObj->m_FillType; 666 int fill_mode = pPathObj->m_FillType;
640 if (m_Options.m_Flags & RENDER_NOPATHSMOOTH) { 667 if (m_Options.m_Flags & RENDER_NOPATHSMOOTH) {
641 fill_mode |= FXFILL_NOPATHSMOOTH; 668 fill_mode |= FXFILL_NOPATHSMOOTH;
642 } 669 }
643 return m_pDevice->SetClip_PathFill(pPathObj->m_Path.GetObject(), &path_matrix, 670 return m_pDevice->SetClip_PathFill(pPathObj->m_Path.GetObject(), &path_matrix,
644 fill_mode); 671 fill_mode);
645 } 672 }
646 FX_BOOL CPDF_RenderStatus::ProcessTransparency(const CPDF_PageObject* pPageObj, 673 FX_BOOL CPDF_RenderStatus::ProcessTransparency(const CPDF_PageObject* pPageObj,
647 const CFX_Matrix* pObj2Device) { 674 const CFX_Matrix* pObj2Device) {
675 #if defined _SKIA_SUPPORT_
676 DebugVerifyDeviceIsPreMultiplied();
677 #endif
648 const CPDF_GeneralStateData* pGeneralState = 678 const CPDF_GeneralStateData* pGeneralState =
649 pPageObj->m_GeneralState.GetObject(); 679 pPageObj->m_GeneralState.GetObject();
650 int blend_type = 680 int blend_type =
651 pGeneralState ? pGeneralState->m_BlendType : FXDIB_BLEND_NORMAL; 681 pGeneralState ? pGeneralState->m_BlendType : FXDIB_BLEND_NORMAL;
652 if (blend_type == FXDIB_BLEND_UNSUPPORTED) { 682 if (blend_type == FXDIB_BLEND_UNSUPPORTED) {
653 return TRUE; 683 return TRUE;
654 } 684 }
655 CPDF_Dictionary* pSMaskDict = 685 CPDF_Dictionary* pSMaskDict =
656 pGeneralState ? ToDictionary(pGeneralState->m_pSoftMask) : nullptr; 686 pGeneralState ? ToDictionary(pGeneralState->m_pSoftMask) : nullptr;
657 if (pSMaskDict) { 687 if (pSMaskDict) {
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
738 FX_FLOAT scaleX = FXSYS_fabs(deviceCTM.a); 768 FX_FLOAT scaleX = FXSYS_fabs(deviceCTM.a);
739 FX_FLOAT scaleY = FXSYS_fabs(deviceCTM.d); 769 FX_FLOAT scaleY = FXSYS_fabs(deviceCTM.d);
740 int width = FXSYS_round((FX_FLOAT)rect.Width() * scaleX); 770 int width = FXSYS_round((FX_FLOAT)rect.Width() * scaleX);
741 int height = FXSYS_round((FX_FLOAT)rect.Height() * scaleY); 771 int height = FXSYS_round((FX_FLOAT)rect.Height() * scaleY);
742 CFX_FxgeDevice bitmap_device; 772 CFX_FxgeDevice bitmap_device;
743 std::unique_ptr<CFX_DIBitmap> oriDevice; 773 std::unique_ptr<CFX_DIBitmap> oriDevice;
744 if (!isolated && (m_pDevice->GetRenderCaps() & FXRC_GET_BITS)) { 774 if (!isolated && (m_pDevice->GetRenderCaps() & FXRC_GET_BITS)) {
745 oriDevice.reset(new CFX_DIBitmap); 775 oriDevice.reset(new CFX_DIBitmap);
746 if (!m_pDevice->CreateCompatibleBitmap(oriDevice.get(), width, height)) 776 if (!m_pDevice->CreateCompatibleBitmap(oriDevice.get(), width, height))
747 return TRUE; 777 return TRUE;
748
749 m_pDevice->GetDIBits(oriDevice.get(), rect.left, rect.top); 778 m_pDevice->GetDIBits(oriDevice.get(), rect.left, rect.top);
750 } 779 }
751 if (!bitmap_device.Create(width, height, FXDIB_Argb, oriDevice.get())) 780 if (!bitmap_device.Create(width, height, FXDIB_Argb, oriDevice.get()))
752 return TRUE; 781 return TRUE;
753
754 CFX_DIBitmap* bitmap = bitmap_device.GetBitmap(); 782 CFX_DIBitmap* bitmap = bitmap_device.GetBitmap();
755 bitmap->Clear(0); 783 bitmap->Clear(0);
756 CFX_Matrix new_matrix = *pObj2Device; 784 CFX_Matrix new_matrix = *pObj2Device;
757 new_matrix.TranslateI(-rect.left, -rect.top); 785 new_matrix.TranslateI(-rect.left, -rect.top);
758 new_matrix.Scale(scaleX, scaleY); 786 new_matrix.Scale(scaleX, scaleY);
759 std::unique_ptr<CFX_DIBitmap> pTextMask; 787 std::unique_ptr<CFX_DIBitmap> pTextMask;
760 if (bTextClip) { 788 if (bTextClip) {
761 pTextMask.reset(new CFX_DIBitmap); 789 pTextMask.reset(new CFX_DIBitmap);
762 if (!pTextMask->Create(width, height, FXDIB_8bppMask)) 790 if (!pTextMask->Create(width, height, FXDIB_8bppMask))
763 return TRUE; 791 return TRUE;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
806 bitmap->MultiplyAlpha(blitAlpha); 834 bitmap->MultiplyAlpha(blitAlpha);
807 blitAlpha = 255; 835 blitAlpha = 255;
808 #endif 836 #endif
809 } 837 }
810 Transparency = m_Transparency; 838 Transparency = m_Transparency;
811 if (pPageObj->IsForm()) { 839 if (pPageObj->IsForm()) {
812 Transparency |= PDFTRANS_GROUP; 840 Transparency |= PDFTRANS_GROUP;
813 } 841 }
814 CompositeDIBitmap(bitmap, rect.left, rect.top, 0, blitAlpha, blend_type, 842 CompositeDIBitmap(bitmap, rect.left, rect.top, 0, blitAlpha, blend_type,
815 Transparency); 843 Transparency);
844 #if defined _SKIA_SUPPORT_
845 DebugVerifyDeviceIsPreMultiplied();
846 #endif
816 return TRUE; 847 return TRUE;
817 } 848 }
818 849
819 CFX_DIBitmap* CPDF_RenderStatus::GetBackdrop(const CPDF_PageObject* pObj, 850 CFX_DIBitmap* CPDF_RenderStatus::GetBackdrop(const CPDF_PageObject* pObj,
820 const FX_RECT& rect, 851 const FX_RECT& rect,
821 int& left, 852 int& left,
822 int& top, 853 int& top,
823 FX_BOOL bBackAlphaRequired) { 854 FX_BOOL bBackAlphaRequired) {
824 FX_RECT bbox = rect; 855 FX_RECT bbox = rect;
825 bbox.Intersect(m_pDevice->GetClipBox()); 856 bbox.Intersect(m_pDevice->GetClipBox());
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after
1256 m_pContext->GetBackground(m_pBitmapDevice->GetBitmap(), m_pObject, pOptions, 1287 m_pContext->GetBackground(m_pBitmapDevice->GetBitmap(), m_pObject, pOptions,
1257 &m_Matrix); 1288 &m_Matrix);
1258 return TRUE; 1289 return TRUE;
1259 } 1290 }
1260 void CPDF_ScaledRenderBuffer::OutputToDevice() { 1291 void CPDF_ScaledRenderBuffer::OutputToDevice() {
1261 if (m_pBitmapDevice) { 1292 if (m_pBitmapDevice) {
1262 m_pDevice->StretchDIBits(m_pBitmapDevice->GetBitmap(), m_Rect.left, 1293 m_pDevice->StretchDIBits(m_pBitmapDevice->GetBitmap(), m_Rect.left,
1263 m_Rect.top, m_Rect.Width(), m_Rect.Height()); 1294 m_Rect.top, m_Rect.Width(), m_Rect.Height());
1264 } 1295 }
1265 } 1296 }
1297
1298 #if defined _SKIA_SUPPORT_
1299 void CPDF_RenderStatus::DebugVerifyDeviceIsPreMultiplied() const {
1300 m_pDevice->DebugVerifyBitmapIsPreMultiplied();
1301 }
1302 #endif
OLDNEW
« no previous file with comments | « no previous file | core/fpdfapi/fpdf_render/fpdf_render_image.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698