diff options
author | Lei Zhang <thestig@chromium.org> | 2018-04-12 15:50:49 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-04-12 15:50:49 +0000 |
commit | c4242b24262d082f3ad70805aca779a3ff540c2c (patch) | |
tree | 5c9f666d4ae62ed728217bd8dcf3f3306905e328 | |
parent | 1c23a6d78c95ff0714cda6f642420e0502edac29 (diff) | |
download | pdfium-c4242b24262d082f3ad70805aca779a3ff540c2c.tar.xz |
Change GetDisplayMatrix methods to take FX_RECT.
Change-Id: I079bc3bf1242fd28fdd51930d9deb6efa34d7509
Reviewed-on: https://pdfium-review.googlesource.com/30055
Reviewed-by: dsinclair <dsinclair@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
-rw-r--r-- | core/fpdfapi/page/cpdf_page.cpp | 56 | ||||
-rw-r--r-- | core/fpdfapi/page/cpdf_page.h | 6 | ||||
-rw-r--r-- | core/fpdftext/cpdf_textpage.cpp | 6 | ||||
-rw-r--r-- | fpdfsdk/fpdf_formfill.cpp | 9 | ||||
-rw-r--r-- | fpdfsdk/fpdf_view.cpp | 20 | ||||
-rw-r--r-- | fpdfsdk/fpdfxfa/cpdfxfa_page.cpp | 18 | ||||
-rw-r--r-- | fpdfsdk/fpdfxfa/cpdfxfa_page.h | 7 |
7 files changed, 52 insertions, 70 deletions
diff --git a/core/fpdfapi/page/cpdf_page.cpp b/core/fpdfapi/page/cpdf_page.cpp index e5d7f381a5..eb1f0b535d 100644 --- a/core/fpdfapi/page/cpdf_page.cpp +++ b/core/fpdfapi/page/cpdf_page.cpp @@ -118,11 +118,7 @@ CFX_FloatRect CPDF_Page::GetBox(const ByteString& name) const { return box; } -CFX_Matrix CPDF_Page::GetDisplayMatrix(int xPos, - int yPos, - int xSize, - int ySize, - int iRotate) const { +CFX_Matrix CPDF_Page::GetDisplayMatrix(const FX_RECT& rect, int iRotate) const { if (m_PageSize.width == 0 || m_PageSize.height == 0) return CFX_Matrix(); @@ -136,41 +132,41 @@ CFX_Matrix CPDF_Page::GetDisplayMatrix(int xPos, // This code implicitly inverts the y-axis to account for page coordinates // pointing up and bitmap coordinates pointing down. (x0, y0) is the base // point, (x1, y1) is that point translated on y and (x2, y2) is the point - // translated on x. On iRotate = 0, y0 is (yPos + ySize) and the translation + // translated on x. On iRotate = 0, y0 is rect.bottom and the translation // to get y1 is performed as negative. This results in the desired // transformation. switch (iRotate) { case 0: - x0 = xPos; - y0 = yPos + ySize; - x1 = xPos; - y1 = yPos; - x2 = xPos + xSize; - y2 = yPos + ySize; + x0 = rect.left; + y0 = rect.bottom; + x1 = rect.left; + y1 = rect.top; + x2 = rect.right; + y2 = rect.bottom; break; case 1: - x0 = xPos; - y0 = yPos; - x1 = xPos + xSize; - y1 = yPos; - x2 = xPos; - y2 = yPos + ySize; + x0 = rect.left; + y0 = rect.top; + x1 = rect.right; + y1 = rect.top; + x2 = rect.left; + y2 = rect.bottom; break; case 2: - x0 = xPos + xSize; - y0 = yPos; - x1 = xPos + xSize; - y1 = yPos + ySize; - x2 = xPos; - y2 = yPos; + x0 = rect.right; + y0 = rect.top; + x1 = rect.right; + y1 = rect.bottom; + x2 = rect.left; + y2 = rect.top; break; case 3: - x0 = xPos + xSize; - y0 = yPos + ySize; - x1 = xPos; - y1 = yPos + ySize; - x2 = xPos + xSize; - y2 = yPos; + x0 = rect.right; + y0 = rect.bottom; + x1 = rect.left; + y1 = rect.bottom; + x2 = rect.right; + y2 = rect.top; break; } CFX_Matrix matrix = m_PageMatrix; diff --git a/core/fpdfapi/page/cpdf_page.h b/core/fpdfapi/page/cpdf_page.h index c7aa12e474..39c1b72c27 100644 --- a/core/fpdfapi/page/cpdf_page.h +++ b/core/fpdfapi/page/cpdf_page.h @@ -33,11 +33,7 @@ class CPDF_Page : public CPDF_PageObjectHolder { void ParseContent(); - CFX_Matrix GetDisplayMatrix(int xPos, - int yPos, - int xSize, - int ySize, - int iRotate) const; + CFX_Matrix GetDisplayMatrix(const FX_RECT& rect, int iRotate) const; float GetPageWidth() const { return m_PageSize.width; } float GetPageHeight() const { return m_PageSize.height; } diff --git a/core/fpdftext/cpdf_textpage.cpp b/core/fpdftext/cpdf_textpage.cpp index 91c92492cd..46c2a4e341 100644 --- a/core/fpdftext/cpdf_textpage.cpp +++ b/core/fpdftext/cpdf_textpage.cpp @@ -143,9 +143,9 @@ CPDF_TextPage::CPDF_TextPage(const CPDF_Page* pPage, FPDFText_Direction flags) m_bIsParsed(false), m_TextlineDir(TextOrientation::Unknown) { m_TextBuf.EstimateSize(0, 10240); - m_DisplayMatrix = - pPage->GetDisplayMatrix(0, 0, static_cast<int>(pPage->GetPageWidth()), - static_cast<int>(pPage->GetPageHeight()), 0); + const FX_RECT rect(0, 0, static_cast<int>(pPage->GetPageWidth()), + static_cast<int>(pPage->GetPageHeight())); + m_DisplayMatrix = pPage->GetDisplayMatrix(rect, 0); } CPDF_TextPage::~CPDF_TextPage() {} diff --git a/fpdfsdk/fpdf_formfill.cpp b/fpdfsdk/fpdf_formfill.cpp index 7b47259a12..912db878f8 100644 --- a/fpdfsdk/fpdf_formfill.cpp +++ b/fpdfsdk/fpdf_formfill.cpp @@ -150,9 +150,8 @@ void FFLCommon(FPDF_FORMHANDLE hHandle, return; #endif // PDF_ENABLE_XFA - CFX_Matrix matrix = - pPage->GetDisplayMatrix(start_x, start_y, size_x, size_y, rotate); - FX_RECT clip(start_x, start_y, start_x + size_x, start_y + size_y); + const FX_RECT rect(start_x, start_y, start_x + size_x, start_y + size_y); + CFX_Matrix matrix = pPage->GetDisplayMatrix(rect, rotate); auto pDevice = pdfium::MakeUnique<CFX_DefaultRenderDevice>(); #ifdef _SKIA_SUPPORT_ @@ -162,7 +161,7 @@ void FFLCommon(FPDF_FORMHANDLE hHandle, pDevice->Attach(holder, false, nullptr, false); { CFX_RenderDevice::StateRestorer restorer(pDevice.get()); - pDevice->SetClip_Rect(clip); + pDevice->SetClip_Rect(rect); CPDF_RenderOptions options; uint32_t option_flags = options.GetFlags(); @@ -182,7 +181,7 @@ void FFLCommon(FPDF_FORMHANDLE hHandle, options.SetOCContext( pdfium::MakeRetain<CPDF_OCContext>(pPDFDoc, CPDF_OCContext::View)); if (CPDFSDK_PageView* pPageView = pFormFillEnv->GetPageView(pPage, true)) - pPageView->PageView_OnDraw(pDevice.get(), &matrix, &options, clip); + pPageView->PageView_OnDraw(pDevice.get(), &matrix, &options, rect); #else // PDF_ENABLE_XFA options.SetOCContext(pdfium::MakeRetain<CPDF_OCContext>( pPage->m_pDocument.Get(), CPDF_OCContext::View)); diff --git a/fpdfsdk/fpdf_view.cpp b/fpdfsdk/fpdf_view.cpp index 2b4600dc8a..b04276ee51 100644 --- a/fpdfsdk/fpdf_view.cpp +++ b/fpdfsdk/fpdf_view.cpp @@ -657,8 +657,8 @@ FPDF_RenderPageBitmapWithMatrix(FPDF_BITMAP bitmap, clipping_rect = CFXFloatRectFromFSRECTF(*clipping); FX_RECT clip_rect = clipping_rect.ToFxRect(); - CFX_Matrix transform_matrix = pPage->GetDisplayMatrix( - 0, 0, pPage->GetPageWidth(), pPage->GetPageHeight(), 0); + const FX_RECT rect(0, 0, pPage->GetPageWidth(), pPage->GetPageHeight()); + CFX_Matrix transform_matrix = pPage->GetDisplayMatrix(rect, 0); if (matrix) { transform_matrix.Concat(CFX_Matrix(matrix->a, matrix->b, matrix->c, @@ -748,8 +748,8 @@ FPDF_EXPORT void FPDF_CALLCONV FPDF_DeviceToPage(FPDF_PAGE page, pPage->DeviceToPage(start_x, start_y, size_x, size_y, rotate, device_x, device_y, page_x, page_y); #else // PDF_ENABLE_XFA - CFX_Matrix page2device = - pPage->GetDisplayMatrix(start_x, start_y, size_x, size_y, rotate); + const FX_RECT rect(start_x, start_y, start_x + size_x, start_y + size_y); + 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))); @@ -778,8 +778,8 @@ FPDF_EXPORT void FPDF_CALLCONV FPDF_PageToDevice(FPDF_PAGE page, pPage->PageToDevice(start_x, start_y, size_x, size_y, rotate, page_x, page_y, device_x, device_y); #else // PDF_ENABLE_XFA - CFX_Matrix page2device = - pPage->GetDisplayMatrix(start_x, start_y, size_x, size_y, rotate); + const FX_RECT rect(start_x, start_y, start_x + size_x, start_y + size_y); + CFX_Matrix page2device = pPage->GetDisplayMatrix(rect, rotate); CFX_PointF pos = page2device.Transform( CFX_PointF(static_cast<float>(page_x), static_cast<float>(page_y))); @@ -898,11 +898,9 @@ void FPDF_RenderPage_Retail(CPDF_PageRenderContext* pContext, if (!pPage) return; - RenderPageImpl( - pContext, pPage, - pPage->GetDisplayMatrix(start_x, start_y, size_x, size_y, rotate), - FX_RECT(start_x, start_y, start_x + size_x, start_y + size_y), flags, - bNeedToRestore, pause); + const FX_RECT rect(start_x, start_y, start_x + size_x, start_y + size_y); + RenderPageImpl(pContext, pPage, pPage->GetDisplayMatrix(rect, rotate), rect, + flags, bNeedToRestore, pause); } FPDF_EXPORT int FPDF_CALLCONV FPDF_GetPageSizeByIndex(FPDF_DOCUMENT document, diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_page.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_page.cpp index 0b4e8f60ee..a43707a9cf 100644 --- a/fpdfsdk/fpdfxfa/cpdfxfa_page.cpp +++ b/fpdfsdk/fpdfxfa/cpdfxfa_page.cpp @@ -138,7 +138,8 @@ void CPDFXFA_Page::DeviceToPage(int start_x, if (!m_pPDFPage && !m_pXFAPageView) return; - CFX_PointF pos = GetDisplayMatrix(start_x, start_y, size_x, size_y, rotate) + const FX_RECT rect(start_x, start_y, start_x + size_x, start_y + size_y); + CFX_PointF pos = GetDisplayMatrix(rect, rotate) .GetInverse() .Transform(CFX_PointF(static_cast<float>(device_x), static_cast<float>(device_y))); @@ -159,8 +160,8 @@ void CPDFXFA_Page::PageToDevice(int start_x, if (!m_pPDFPage && !m_pXFAPageView) return; - CFX_Matrix page2device = - GetDisplayMatrix(start_x, start_y, size_x, size_y, rotate); + const FX_RECT rect(start_x, start_y, start_x + size_x, start_y + size_y); + CFX_Matrix page2device = GetDisplayMatrix(rect, rotate); CFX_PointF pos = page2device.Transform( CFX_PointF(static_cast<float>(page_x), static_cast<float>(page_y))); @@ -169,10 +170,7 @@ void CPDFXFA_Page::PageToDevice(int start_x, *device_y = FXSYS_round(pos.y); } -CFX_Matrix CPDFXFA_Page::GetDisplayMatrix(int xPos, - int yPos, - int xSize, - int ySize, +CFX_Matrix CPDFXFA_Page::GetDisplayMatrix(const FX_RECT& rect, int iRotate) const { if (!m_pPDFPage && !m_pXFAPageView) return CFX_Matrix(); @@ -182,13 +180,11 @@ CFX_Matrix CPDFXFA_Page::GetDisplayMatrix(int xPos, case FormType::kAcroForm: case FormType::kXFAForeground: if (m_pPDFPage) - return m_pPDFPage->GetDisplayMatrix(xPos, yPos, xSize, ySize, iRotate); + return m_pPDFPage->GetDisplayMatrix(rect, iRotate); FX_FALLTHROUGH; case FormType::kXFAFull: - if (m_pXFAPageView) { - FX_RECT rect = FX_RECT(xPos, yPos, xPos + xSize, yPos + ySize); + if (m_pXFAPageView) return m_pXFAPageView->GetDisplayMatrix(rect, iRotate); - } break; } diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_page.h b/fpdfsdk/fpdfxfa/cpdfxfa_page.h index f64d66b10c..bdb4791c87 100644 --- a/fpdfsdk/fpdfxfa/cpdfxfa_page.h +++ b/fpdfsdk/fpdfxfa/cpdfxfa_page.h @@ -18,6 +18,7 @@ class CPDFXFA_Context; class CPDF_Dictionary; class CPDF_Page; class CXFA_FFPageView; +struct FX_RECT; class CPDFXFA_Page : public Retainable { public: @@ -57,11 +58,7 @@ class CPDFXFA_Page : public Retainable { int* device_x, int* device_y); - CFX_Matrix GetDisplayMatrix(int xPos, - int yPos, - int xSize, - int ySize, - int iRotate) const; + CFX_Matrix GetDisplayMatrix(const FX_RECT& rect, int iRotate) const; protected: // Refcounted class. |