summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/fpdfapi/page/cpdf_page.cpp29
-rw-r--r--core/fpdfapi/page/cpdf_page.h19
-rw-r--r--fpdfsdk/fpdf_view.cpp62
-rw-r--r--fpdfsdk/fpdfxfa/cpdfxfa_page.cpp30
-rw-r--r--fpdfsdk/fpdfxfa/cpdfxfa_page.h19
-rw-r--r--public/fpdfview.h46
6 files changed, 99 insertions, 106 deletions
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<CFX_PointF> 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<CFX_PointF> 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<float>(page_x), static_cast<float>(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<CFX_PointF> DeviceToPage(const FX_RECT& rect,
+ int rotate,
+ const CFX_PointF& device_point) const;
+ Optional<CFX_PointF> PageToDevice(const FX_RECT& rect,
+ int rotate,
+ double page_x,
+ double page_y) const;
CFX_Matrix GetDisplayMatrix(const FX_RECT& rect, int iRotate) const;
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,
diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_page.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_page.cpp
index d4a6d95574..8fea85d72b 100644
--- a/fpdfsdk/fpdfxfa/cpdfxfa_page.cpp
+++ b/fpdfsdk/fpdfxfa/cpdfxfa_page.cpp
@@ -126,34 +126,28 @@ float CPDFXFA_Page::GetPageHeight() const {
return 0.0f;
}
-void CPDFXFA_Page::DeviceToPage(const FX_RECT& rect,
- int rotate,
- const CFX_PointF& device_point,
- double* page_x,
- double* page_y) const {
+Optional<CFX_PointF> CPDFXFA_Page::DeviceToPage(
+ const FX_RECT& rect,
+ int rotate,
+ const CFX_PointF& device_point) const {
if (!m_pPDFPage && !m_pXFAPageView)
- return;
+ return {};
CFX_PointF pos =
GetDisplayMatrix(rect, rotate).GetInverse().Transform(device_point);
- *page_x = pos.x;
- *page_y = pos.y;
+ return pos;
}
-void CPDFXFA_Page::PageToDevice(const FX_RECT& rect,
- int rotate,
- double page_x,
- double page_y,
- int* device_x,
- int* device_y) const {
+Optional<CFX_PointF> CPDFXFA_Page::PageToDevice(const FX_RECT& rect,
+ int rotate,
+ double page_x,
+ double page_y) const {
if (!m_pPDFPage && !m_pXFAPageView)
- return;
+ return {};
CFX_Matrix page2device = GetDisplayMatrix(rect, rotate);
- CFX_PointF pos = page2device.Transform(
+ return page2device.Transform(
CFX_PointF(static_cast<float>(page_x), static_cast<float>(page_y)));
- *device_x = FXSYS_round(pos.x);
- *device_y = FXSYS_round(pos.y);
}
CFX_Matrix CPDFXFA_Page::GetDisplayMatrix(const FX_RECT& rect,
diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_page.h b/fpdfsdk/fpdfxfa/cpdfxfa_page.h
index aef1b0b539..131e811b66 100644
--- a/fpdfsdk/fpdfxfa/cpdfxfa_page.h
+++ b/fpdfsdk/fpdfxfa/cpdfxfa_page.h
@@ -13,6 +13,7 @@
#include "core/fxcrt/fx_system.h"
#include "core/fxcrt/retain_ptr.h"
#include "core/fxcrt/unowned_ptr.h"
+#include "third_party/base/optional.h"
class CPDFXFA_Context;
class CPDF_Dictionary;
@@ -38,17 +39,13 @@ class CPDFXFA_Page : public Retainable {
float GetPageWidth() const;
float GetPageHeight() const;
- 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<CFX_PointF> DeviceToPage(const FX_RECT& rect,
+ int rotate,
+ const CFX_PointF& device_point) const;
+ Optional<CFX_PointF> PageToDevice(const FX_RECT& rect,
+ int rotate,
+ double page_x,
+ double page_y) const;
CFX_Matrix GetDisplayMatrix(const FX_RECT& rect, int iRotate) const;
diff --git a/public/fpdfview.h b/public/fpdfview.h
index 62b7b88410..2c93e962f3 100644
--- a/public/fpdfview.h
+++ b/public/fpdfview.h
@@ -736,7 +736,8 @@ FPDF_EXPORT void FPDF_CALLCONV FPDF_CloseDocument(FPDF_DOCUMENT document);
// page_y - A pointer to a double receiving the converted Y
// value in page coordinates.
// Return value:
-// None.
+// Returns true if the conversion succeeds, and |page_x| and |page_y|
+// successfully receives the converted coordinates.
// Comments:
// The page coordinate system has its origin at the left-bottom corner
// of the page, with the X-axis on the bottom going to the right, and
@@ -754,16 +755,16 @@ FPDF_EXPORT void FPDF_CALLCONV FPDF_CloseDocument(FPDF_DOCUMENT document);
// You must make sure the start_x, start_y, size_x, size_y
// and rotate parameters have exactly same values as you used in
// the FPDF_RenderPage() function call.
-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);
// Function: FPDF_PageToDevice
// Convert the page coordinates of a point to screen coordinates.
@@ -787,19 +788,20 @@ FPDF_EXPORT void FPDF_CALLCONV FPDF_DeviceToPage(FPDF_PAGE page,
// device_y - A pointer to an integer receiving the result Y
// value in device coordinates.
// Return value:
-// None.
+// Returns true if the conversion succeeds, and |device_x| and
+// |device_y| successfully receives the converted coordinates.
// Comments:
// See comments for FPDF_DeviceToPage().
-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);
// Function: FPDFBitmap_Create
// Create a device independent bitmap (FXDIB).