From 822886b0c4478eb339fc5e2ec89f3fbdd78d57be Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Thu, 12 Apr 2018 17:24:45 +0000 Subject: Add return value to FPDF_DeviceToPage(). Do the same for FPDF_PageToDevice(). Clean up the internal implementation as well. Change-Id: Ia207bfa779d144cb9f0310e768750ab10e603b8f Reviewed-on: https://pdfium-review.googlesource.com/17370 Commit-Queue: Lei Zhang Reviewed-by: dsinclair --- core/fpdfapi/page/cpdf_page.cpp | 29 ++++++++++------------------- core/fpdfapi/page/cpdf_page.h | 19 ++++++++----------- 2 files changed, 18 insertions(+), 30 deletions(-) (limited to 'core') diff --git a/core/fpdfapi/page/cpdf_page.cpp b/core/fpdfapi/page/cpdf_page.cpp index 06043ead35..259e8ce0fb 100644 --- a/core/fpdfapi/page/cpdf_page.cpp +++ b/core/fpdfapi/page/cpdf_page.cpp @@ -118,30 +118,21 @@ CFX_FloatRect CPDF_Page::GetBox(const ByteString& name) const { return box; } -void CPDF_Page::DeviceToPage(const FX_RECT& rect, - int rotate, - const CFX_PointF& device_point, - double* page_x, - double* page_y) const { +Optional CPDF_Page::DeviceToPage( + const FX_RECT& rect, + int rotate, + const CFX_PointF& device_point) const { CFX_Matrix page2device = GetDisplayMatrix(rect, rotate); - CFX_PointF pos = page2device.GetInverse().Transform(device_point); - - *page_x = pos.x; - *page_y = pos.y; + return page2device.GetInverse().Transform(device_point); } -void CPDF_Page::PageToDevice(const FX_RECT& rect, - int rotate, - double page_x, - double page_y, - int* device_x, - int* device_y) const { +Optional CPDF_Page::PageToDevice(const FX_RECT& rect, + int rotate, + double page_x, + double page_y) const { CFX_Matrix page2device = GetDisplayMatrix(rect, rotate); - CFX_PointF pos = page2device.Transform( + return page2device.Transform( CFX_PointF(static_cast(page_x), static_cast(page_y))); - - *device_x = FXSYS_round(pos.x); - *device_y = FXSYS_round(pos.y); } CFX_Matrix CPDF_Page::GetDisplayMatrix(const FX_RECT& rect, int iRotate) const { diff --git a/core/fpdfapi/page/cpdf_page.h b/core/fpdfapi/page/cpdf_page.h index d199ea41db..34c9ef45a8 100644 --- a/core/fpdfapi/page/cpdf_page.h +++ b/core/fpdfapi/page/cpdf_page.h @@ -12,6 +12,7 @@ #include "core/fpdfapi/page/cpdf_pageobjectholder.h" #include "core/fxcrt/fx_coordinates.h" #include "core/fxcrt/fx_system.h" +#include "third_party/base/optional.h" class CPDF_Dictionary; class CPDF_Document; @@ -33,17 +34,13 @@ class CPDF_Page : public CPDF_PageObjectHolder { void ParseContent(); - void DeviceToPage(const FX_RECT& rect, - int rotate, - const CFX_PointF& device_point, - double* page_x, - double* page_y) const; - void PageToDevice(const FX_RECT& rect, - int rotate, - double page_x, - double page_y, - int* device_x, - int* device_y) const; + Optional DeviceToPage(const FX_RECT& rect, + int rotate, + const CFX_PointF& device_point) const; + Optional PageToDevice(const FX_RECT& rect, + int rotate, + double page_x, + double page_y) const; CFX_Matrix GetDisplayMatrix(const FX_RECT& rect, int iRotate) const; -- cgit v1.2.3