summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2018-04-12 16:35:49 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-04-12 16:35:49 +0000
commit56cc5c12a7f569f218c44a6186cdc3676ea0793b (patch)
treefd03d43e9e59d28554d7169f319f421dad6f8832
parenta105fa126cfc2de661dca824bd307aa329e22c9d (diff)
downloadpdfium-56cc5c12a7f569f218c44a6186cdc3676ea0793b.tar.xz
Add CPDF_Page::DeviceToPage() / PageToDevice().
Just like CPDFXFA_Page. Also mark the methods const. Change-Id: I6717b4b61a29663780f45bf872f76fe8e671df75 Reviewed-on: https://pdfium-review.googlesource.com/30132 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
-rw-r--r--core/fpdfapi/page/cpdf_page.cpp26
-rw-r--r--core/fpdfapi/page/cpdf_page.h12
-rw-r--r--fpdfsdk/fpdf_view.cpp19
-rw-r--r--fpdfsdk/fpdfxfa/cpdfxfa_page.cpp4
-rw-r--r--fpdfsdk/fpdfxfa/cpdfxfa_page.h4
5 files changed, 42 insertions, 23 deletions
diff --git a/core/fpdfapi/page/cpdf_page.cpp b/core/fpdfapi/page/cpdf_page.cpp
index eb1f0b535d..06043ead35 100644
--- a/core/fpdfapi/page/cpdf_page.cpp
+++ b/core/fpdfapi/page/cpdf_page.cpp
@@ -118,6 +118,32 @@ 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 {
+ CFX_Matrix page2device = GetDisplayMatrix(rect, rotate);
+ CFX_PointF pos = page2device.GetInverse().Transform(device_point);
+
+ *page_x = pos.x;
+ *page_y = pos.y;
+}
+
+void CPDF_Page::PageToDevice(const FX_RECT& rect,
+ int rotate,
+ double page_x,
+ double page_y,
+ int* device_x,
+ int* device_y) const {
+ CFX_Matrix page2device = GetDisplayMatrix(rect, rotate);
+ CFX_PointF pos = 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 {
if (m_PageSize.width == 0 || m_PageSize.height == 0)
return CFX_Matrix();
diff --git a/core/fpdfapi/page/cpdf_page.h b/core/fpdfapi/page/cpdf_page.h
index 39c1b72c27..d199ea41db 100644
--- a/core/fpdfapi/page/cpdf_page.h
+++ b/core/fpdfapi/page/cpdf_page.h
@@ -33,6 +33,18 @@ 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;
+
CFX_Matrix GetDisplayMatrix(const FX_RECT& rect, int iRotate) const;
float GetPageWidth() const { return m_PageSize.width; }
diff --git a/fpdfsdk/fpdf_view.cpp b/fpdfsdk/fpdf_view.cpp
index 51cfd8976b..f39d80cab0 100644
--- a/fpdfsdk/fpdf_view.cpp
+++ b/fpdfsdk/fpdf_view.cpp
@@ -746,18 +746,8 @@ FPDF_EXPORT void FPDF_CALLCONV FPDF_DeviceToPage(FPDF_PAGE page,
UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page);
const FX_RECT rect(start_x, start_y, start_x + size_x, start_y + size_y);
-#ifdef PDF_ENABLE_XFA
pPage->DeviceToPage(rect, rotate, CFX_PointF(device_x, device_y), page_x,
page_y);
-#else // PDF_ENABLE_XFA
- CFX_Matrix page2device = pPage->GetDisplayMatrix(rect, rotate);
-
- CFX_PointF pos = page2device.GetInverse().Transform(
- CFX_PointF(static_cast<float>(device_x), static_cast<float>(device_y)));
-
- *page_x = pos.x;
- *page_y = pos.y;
-#endif // PDF_ENABLE_XFA
}
FPDF_EXPORT void FPDF_CALLCONV FPDF_PageToDevice(FPDF_PAGE page,
@@ -775,16 +765,7 @@ FPDF_EXPORT void FPDF_CALLCONV FPDF_PageToDevice(FPDF_PAGE page,
UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page);
const FX_RECT rect(start_x, start_y, start_x + size_x, start_y + size_y);
-#ifdef PDF_ENABLE_XFA
pPage->PageToDevice(rect, rotate, page_x, page_y, device_x, device_y);
-#else // PDF_ENABLE_XFA
- CFX_Matrix page2device = pPage->GetDisplayMatrix(rect, rotate);
- CFX_PointF pos = 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);
-#endif // PDF_ENABLE_XFA
}
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 c3d5e18707..d4a6d95574 100644
--- a/fpdfsdk/fpdfxfa/cpdfxfa_page.cpp
+++ b/fpdfsdk/fpdfxfa/cpdfxfa_page.cpp
@@ -130,7 +130,7 @@ void CPDFXFA_Page::DeviceToPage(const FX_RECT& rect,
int rotate,
const CFX_PointF& device_point,
double* page_x,
- double* page_y) {
+ double* page_y) const {
if (!m_pPDFPage && !m_pXFAPageView)
return;
@@ -145,7 +145,7 @@ void CPDFXFA_Page::PageToDevice(const FX_RECT& rect,
double page_x,
double page_y,
int* device_x,
- int* device_y) {
+ int* device_y) const {
if (!m_pPDFPage && !m_pXFAPageView)
return;
diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_page.h b/fpdfsdk/fpdfxfa/cpdfxfa_page.h
index 0acec981c6..aef1b0b539 100644
--- a/fpdfsdk/fpdfxfa/cpdfxfa_page.h
+++ b/fpdfsdk/fpdfxfa/cpdfxfa_page.h
@@ -42,13 +42,13 @@ class CPDFXFA_Page : public Retainable {
int rotate,
const CFX_PointF& device_point,
double* page_x,
- double* page_y);
+ double* page_y) const;
void PageToDevice(const FX_RECT& rect,
int rotate,
double page_x,
double page_y,
int* device_x,
- int* device_y);
+ int* device_y) const;
CFX_Matrix GetDisplayMatrix(const FX_RECT& rect, int iRotate) const;