From 1123794330298b00a40ca35e9ada3ac2d6a664f3 Mon Sep 17 00:00:00 2001 From: xlou Date: Mon, 15 Oct 2018 21:38:42 +0000 Subject: Use CropBox instead of ArtBox or TrimBox FPDFPage_Flatten() used ArtBox as the BBbox of the newly created XObject, which in some situation, some content of the generated PDF are not visible. FPDF_ImportNPagesToOne() uses TrimBox as the BBbox of the newly created XObject, which in some cases, MediaBox and CropBox are scaled up, however TrimBox is not, which caused some content of the newly generated N-upped PDF not visible. Hence for the above two situations, we have chosen to use mostly commonly used CropBox. Bug:409670 Change-Id: Ifb82a6f881d7ce1802cf23c7e8e6f11cc76bf3e9 Reviewed-on: https://pdfium-review.googlesource.com/c/43987 Reviewed-by: Lei Zhang Commit-Queue: Shirleen Lou --- fpdfsdk/fpdf_flatten.cpp | 21 +++++++++------------ fpdfsdk/fpdf_ppo.cpp | 8 +------- 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/fpdfsdk/fpdf_flatten.cpp b/fpdfsdk/fpdf_flatten.cpp index ea701d9e1e..de396667f5 100644 --- a/fpdfsdk/fpdf_flatten.cpp +++ b/fpdfsdk/fpdf_flatten.cpp @@ -251,7 +251,6 @@ FPDF_EXPORT int FPDF_CALLCONV FPDFPage_Flatten(FPDF_PAGE page, int nFlag) { if (iRet == FLATTEN_NOTHINGTODO || iRet == FLATTEN_FAIL) return iRet; - CFX_FloatRect rcOriginalCB; CFX_FloatRect rcMerger = CalculateRect(&RectArray); CFX_FloatRect rcOriginalMB = pPageDict->GetRectFor(pdfium::page_object::kMediaBox); @@ -261,20 +260,19 @@ FPDF_EXPORT int FPDF_CALLCONV FPDFPage_Flatten(FPDF_PAGE page, int nFlag) { if (rcOriginalMB.IsEmpty()) rcOriginalMB = CFX_FloatRect(0.0f, 0.0f, 612.0f, 792.0f); + CFX_FloatRect rcOriginalCB; + if (pPageDict->KeyExist(pdfium::page_object::kCropBox)) + rcOriginalCB = pPageDict->GetRectFor(pdfium::page_object::kCropBox); + if (rcOriginalCB.IsEmpty()) + rcOriginalCB = rcOriginalMB; + rcMerger.left = std::max(rcMerger.left, rcOriginalMB.left); rcMerger.right = std::min(rcMerger.right, rcOriginalMB.right); rcMerger.bottom = std::max(rcMerger.bottom, rcOriginalMB.bottom); rcMerger.top = std::min(rcMerger.top, rcOriginalMB.top); - if (pPageDict->KeyExist("ArtBox")) - rcOriginalCB = pPageDict->GetRectFor("ArtBox"); - else - rcOriginalCB = rcOriginalMB; - - if (!rcOriginalMB.IsEmpty()) - pPageDict->SetRectFor(pdfium::page_object::kMediaBox, rcOriginalMB); - if (!rcOriginalCB.IsEmpty()) - pPageDict->SetRectFor("ArtBox", rcOriginalCB); + pPageDict->SetRectFor(pdfium::page_object::kMediaBox, rcOriginalMB); + pPageDict->SetRectFor(pdfium::page_object::kCropBox, rcOriginalCB); CPDF_Dictionary* pRes = pPageDict->GetDictFor(pdfium::page_object::kResources); @@ -314,8 +312,7 @@ FPDF_EXPORT int FPDF_CALLCONV FPDFPage_Flatten(FPDF_PAGE page, int nFlag) { pNewOXbjectDic->SetNewFor("Type", "XObject"); pNewOXbjectDic->SetNewFor("Subtype", "Form"); pNewOXbjectDic->SetNewFor("FormType", 1); - CFX_FloatRect rcBBox = pPageDict->GetRectFor(pdfium::page_object::kArtBox); - pNewOXbjectDic->SetRectFor("BBox", rcBBox); + pNewOXbjectDic->SetRectFor("BBox", rcOriginalCB); } for (size_t i = 0; i < ObjectArray.size(); ++i) { diff --git a/fpdfsdk/fpdf_ppo.cpp b/fpdfsdk/fpdf_ppo.cpp index 8f0b0c3d79..fd270d997c 100644 --- a/fpdfsdk/fpdf_ppo.cpp +++ b/fpdfsdk/fpdf_ppo.cpp @@ -185,12 +185,6 @@ CFX_FloatRect GetCropBox(const CPDF_Dictionary* pPageDict) { return GetMediaBox(pPageDict); } -CFX_FloatRect GetTrimBox(const CPDF_Dictionary* pPageDict) { - if (pPageDict->KeyExist("TrimBox")) - return pPageDict->GetRectFor("TrimBox"); - return GetCropBox(pPageDict); -} - const CPDF_Object* GetPageOrganizerPageContent( const CPDF_Dictionary* pPageDict) { return pPageDict @@ -702,7 +696,7 @@ uint32_t CPDF_NPageToOneExporter::MakeXObject( pNewXObjectDict->SetNewFor("Type", "XObject"); pNewXObjectDict->SetNewFor("Subtype", "Form"); pNewXObjectDict->SetNewFor("FormType", 1); - pNewXObjectDict->SetRectFor("BBox", GetTrimBox(pSrcPageDict)); + pNewXObjectDict->SetRectFor("BBox", GetCropBox(pSrcPageDict)); // TODO(xlou): add matrix field to pNewXObjectDict. if (const CPDF_Array* pSrcContentArray = ToArray(pSrcContentObj)) { -- cgit v1.2.3