diff options
author | Lei Zhang <thestig@chromium.org> | 2018-04-12 17:24:45 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-04-12 17:24:45 +0000 |
commit | 822886b0c4478eb339fc5e2ec89f3fbdd78d57be (patch) | |
tree | b51a1b4748fd8503beb05b4a22dd2d9d4740908a /fpdfsdk/fpdf_view.cpp | |
parent | 56cc5c12a7f569f218c44a6186cdc3676ea0793b (diff) | |
download | pdfium-822886b0c4478eb339fc5e2ec89f3fbdd78d57be.tar.xz |
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 <thestig@chromium.org>
Reviewed-by: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'fpdfsdk/fpdf_view.cpp')
-rw-r--r-- | fpdfsdk/fpdf_view.cpp | 62 |
1 files changed, 37 insertions, 25 deletions
diff --git a/fpdfsdk/fpdf_view.cpp b/fpdfsdk/fpdf_view.cpp index f39d80cab0..f2fa43f369 100644 --- a/fpdfsdk/fpdf_view.cpp +++ b/fpdfsdk/fpdf_view.cpp @@ -731,41 +731,53 @@ FPDF_EXPORT unsigned long FPDF_CALLCONV FPDF_GetLastError() { return GetLastError(); } -FPDF_EXPORT void FPDF_CALLCONV FPDF_DeviceToPage(FPDF_PAGE page, - int start_x, - int start_y, - int size_x, - int size_y, - int rotate, - int device_x, - int device_y, - double* page_x, - double* page_y) { +FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDF_DeviceToPage(FPDF_PAGE page, + int start_x, + int start_y, + int size_x, + int size_y, + int rotate, + int device_x, + int device_y, + double* page_x, + double* page_y) { if (!page || !page_x || !page_y) - return; + return false; UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); const FX_RECT rect(start_x, start_y, start_x + size_x, start_y + size_y); - pPage->DeviceToPage(rect, rotate, CFX_PointF(device_x, device_y), page_x, - page_y); + Optional<CFX_PointF> pos = + pPage->DeviceToPage(rect, rotate, CFX_PointF(device_x, device_y)); + if (!pos) + return false; + + *page_x = pos->x; + *page_y = pos->y; + return true; } -FPDF_EXPORT void FPDF_CALLCONV FPDF_PageToDevice(FPDF_PAGE page, - int start_x, - int start_y, - int size_x, - int size_y, - int rotate, - double page_x, - double page_y, - int* device_x, - int* device_y) { +FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDF_PageToDevice(FPDF_PAGE page, + int start_x, + int start_y, + int size_x, + int size_y, + int rotate, + double page_x, + double page_y, + int* device_x, + int* device_y) { if (!page || !device_x || !device_y) - return; + return false; UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); const FX_RECT rect(start_x, start_y, start_x + size_x, start_y + size_y); - pPage->PageToDevice(rect, rotate, page_x, page_y, device_x, device_y); + Optional<CFX_PointF> pos = pPage->PageToDevice(rect, rotate, page_x, page_y); + if (!pos) + return false; + + *device_x = FXSYS_round(pos->x); + *device_y = FXSYS_round(pos->y); + return true; } FPDF_EXPORT FPDF_BITMAP FPDF_CALLCONV FPDFBitmap_Create(int width, |