From 9bc7a213b95439ab91183ac6684bf01e09ae60c1 Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Sat, 9 Jun 2018 00:06:06 +0000 Subject: Consolidate bounding box logic. Move all the checks into the shared helper functions for getting/setting bounding boxes. Change-Id: I6f597f478fd3510e0528d20a0a7820949600fd2a Reviewed-on: https://pdfium-review.googlesource.com/34692 Reviewed-by: Tom Sepez Commit-Queue: Lei Zhang --- fpdfsdk/fpdf_transformpage.cpp | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/fpdfsdk/fpdf_transformpage.cpp b/fpdfsdk/fpdf_transformpage.cpp index af6ac792fb..267b582a47 100644 --- a/fpdfsdk/fpdf_transformpage.cpp +++ b/fpdfsdk/fpdf_transformpage.cpp @@ -28,7 +28,8 @@ namespace { void SetBoundingBox(CPDF_Page* page, const ByteString& key, const CFX_FloatRect& rect) { - page->GetDict()->SetRectFor(key, rect); + if (page) + page->GetDict()->SetRectFor(key, rect); } bool GetBoundingBox(CPDF_Page* page, @@ -37,7 +38,7 @@ bool GetBoundingBox(CPDF_Page* page, float* bottom, float* right, float* top) { - if (!left || !bottom || !right || !top) + if (!page || !left || !bottom || !right || !top) return false; CPDF_Array* pArray = page->GetDict()->GetArrayFor(key); @@ -64,11 +65,7 @@ FPDF_EXPORT void FPDF_CALLCONV FPDFPage_SetMediaBox(FPDF_PAGE page, float bottom, float right, float top) { - CPDF_Page* pPage = CPDFPageFromFPDFPage(page); - if (!pPage) - return; - - SetBoundingBox(pPage, pdfium::page_object::kMediaBox, + SetBoundingBox(CPDFPageFromFPDFPage(page), pdfium::page_object::kMediaBox, CFX_FloatRect(left, bottom, right, top)); } @@ -77,11 +74,7 @@ FPDF_EXPORT void FPDF_CALLCONV FPDFPage_SetCropBox(FPDF_PAGE page, float bottom, float right, float top) { - CPDF_Page* pPage = CPDFPageFromFPDFPage(page); - if (!pPage) - return; - - SetBoundingBox(pPage, pdfium::page_object::kCropBox, + SetBoundingBox(CPDFPageFromFPDFPage(page), pdfium::page_object::kCropBox, CFX_FloatRect(left, bottom, right, top)); } @@ -90,9 +83,9 @@ FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPage_GetMediaBox(FPDF_PAGE page, float* bottom, float* right, float* top) { - CPDF_Page* pPage = CPDFPageFromFPDFPage(page); - return pPage && GetBoundingBox(pPage, pdfium::page_object::kMediaBox, left, - bottom, right, top); + return GetBoundingBox(CPDFPageFromFPDFPage(page), + pdfium::page_object::kMediaBox, left, bottom, right, + top); } FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPage_GetCropBox(FPDF_PAGE page, @@ -100,9 +93,9 @@ FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPage_GetCropBox(FPDF_PAGE page, float* bottom, float* right, float* top) { - CPDF_Page* pPage = CPDFPageFromFPDFPage(page); - return pPage && GetBoundingBox(pPage, pdfium::page_object::kCropBox, left, - bottom, right, top); + return GetBoundingBox(CPDFPageFromFPDFPage(page), + pdfium::page_object::kCropBox, left, bottom, right, + top); } FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV -- cgit v1.2.3