From 367e7de07ec33ad045500a04dc2a180390937b27 Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Tue, 31 Oct 2017 13:32:17 +0000 Subject: Add FS_RECTF conversion functions. Change-Id: I87fb109fdd121716a170df15c4762496c1ccb88c Reviewed-on: https://pdfium-review.googlesource.com/17210 Commit-Queue: dsinclair Reviewed-by: dsinclair --- fpdfsdk/fpdf_transformpage.cpp | 3 +-- fpdfsdk/fpdfannot.cpp | 8 ++------ fpdfsdk/fpdfdoc.cpp | 6 +----- fpdfsdk/fpdfview.cpp | 19 +++++++++++++------ fpdfsdk/fpdfview_embeddertest.cpp | 22 +++++++--------------- fpdfsdk/fsdk_define.h | 3 +++ 6 files changed, 27 insertions(+), 34 deletions(-) (limited to 'fpdfsdk') diff --git a/fpdfsdk/fpdf_transformpage.cpp b/fpdfsdk/fpdf_transformpage.cpp index e8a2705dd2..dcf19f2be7 100644 --- a/fpdfsdk/fpdf_transformpage.cpp +++ b/fpdfsdk/fpdf_transformpage.cpp @@ -112,8 +112,7 @@ FPDFPage_TransFormWithClip(FPDF_PAGE page, std::ostringstream textBuf; textBuf << "q "; - CFX_FloatRect rect(clipRect->left, clipRect->bottom, clipRect->right, - clipRect->top); + CFX_FloatRect rect = CFXFloatRectFromFSRECTF(*clipRect); rect.Normalize(); ByteString bsClipping; bsClipping.Format("%f %f %f %f re W* n ", rect.left, rect.bottom, diff --git a/fpdfsdk/fpdfannot.cpp b/fpdfsdk/fpdfannot.cpp index 09bf42af92..ec541f55d0 100644 --- a/fpdfsdk/fpdfannot.cpp +++ b/fpdfsdk/fpdfannot.cpp @@ -644,7 +644,7 @@ FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFAnnot_SetRect(FPDF_ANNOTATION annot, if (!pAnnotDict) return false; - CFX_FloatRect newRect(rect->left, rect->bottom, rect->right, rect->top); + CFX_FloatRect newRect = CFXFloatRectFromFSRECTF(*rect); // Update the "Rect" entry in the annotation dictionary. pAnnotDict->SetRectFor("Rect", newRect); @@ -674,11 +674,7 @@ FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFAnnot_GetRect(FPDF_ANNOTATION annot, if (!pAnnotDict) return false; - CFX_FloatRect rt = pAnnotDict->GetRectFor("Rect"); - rect->left = rt.left; - rect->bottom = rt.bottom; - rect->right = rt.right; - rect->top = rt.top; + FSRECTFFromCFXFloatRect(pAnnotDict->GetRectFor("Rect"), rect); return true; } diff --git a/fpdfsdk/fpdfdoc.cpp b/fpdfsdk/fpdfdoc.cpp index c536c73254..4d2942fb31 100644 --- a/fpdfsdk/fpdfdoc.cpp +++ b/fpdfsdk/fpdfdoc.cpp @@ -329,11 +329,7 @@ FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFLink_GetAnnotRect(FPDF_LINK linkAnnot, return false; CPDF_Dictionary* pAnnotDict = ToDictionary(static_cast(linkAnnot)); - CFX_FloatRect rt = pAnnotDict->GetRectFor("Rect"); - rect->left = rt.left; - rect->bottom = rt.bottom; - rect->right = rt.right; - rect->top = rt.top; + FSRECTFFromCFXFloatRect(pAnnotDict->GetRectFor("Rect"), rect); return true; } diff --git a/fpdfsdk/fpdfview.cpp b/fpdfsdk/fpdfview.cpp index b68b72ed93..c86a0123a1 100644 --- a/fpdfsdk/fpdfview.cpp +++ b/fpdfsdk/fpdfview.cpp @@ -359,6 +359,17 @@ CFX_DIBitmap* CFXBitmapFromFPDFBitmap(FPDF_BITMAP bitmap) { return static_cast(bitmap); } +CFX_FloatRect CFXFloatRectFromFSRECTF(const FS_RECTF& rect) { + return CFX_FloatRect(rect.left, rect.bottom, rect.right, rect.top); +} + +void FSRECTFFromCFXFloatRect(const CFX_FloatRect& rect, FS_RECTF* out_rect) { + out_rect->left = rect.left; + out_rect->top = rect.top; + out_rect->right = rect.right; + out_rect->bottom = rect.bottom; +} + const FX_PATHPOINT* FXPathPointFromFPDFPathSegment(FPDF_PATHSEGMENT segment) { return static_cast(segment); } @@ -1008,12 +1019,8 @@ FPDF_RenderPageBitmapWithMatrix(FPDF_BITMAP bitmap, pDevice->Attach(pBitmap, !!(flags & FPDF_REVERSE_BYTE_ORDER), nullptr, false); CFX_FloatRect clipping_rect; - if (clipping) { - clipping_rect.left = clipping->left; - clipping_rect.bottom = clipping->bottom; - clipping_rect.right = clipping->right; - clipping_rect.top = clipping->top; - } + if (clipping) + clipping_rect = CFXFloatRectFromFSRECTF(*clipping); FX_RECT clip_rect = clipping_rect.ToFxRect(); RenderPageImpl( pContext, pPage, diff --git a/fpdfsdk/fpdfview_embeddertest.cpp b/fpdfsdk/fpdfview_embeddertest.cpp index 699fc8a71b..5fedbfc5ec 100644 --- a/fpdfsdk/fpdfview_embeddertest.cpp +++ b/fpdfsdk/fpdfview_embeddertest.cpp @@ -388,23 +388,18 @@ TEST_F(FPDFViewEmbeddertest, FPDF_RenderPageBitmapWithMatrix) { CompareBitmap(bitmap, initial_width, initial_height, kRotatedMD5[0]); FPDFBitmap_Destroy(bitmap); - int width; - int height; - FS_RECTF rect; - rect.left = 0; - rect.top = 0; - FS_MATRIX matrix; - // Try the easy rotations: 0, 90, 180, 270 clockwise. The output should be the // same as FPDF_RenderPageBitmap with the appropriate rotation flag. Per PDF // spec section 4.2.2, a t degree rotation is represented by [cos(t) sin(t) // -sin(t) cos(t) 0 0] (matrix goes on the right in the multiplication). - rect.right = initial_width; - rect.bottom = initial_height; + FS_RECTF rect = {0, 0, initial_width, initial_height}; CFX_Matrix rot_matrices[4] = { CFX_Matrix(1, 0, 0, 1, 0, 0), CFX_Matrix(0, -1, 1, 0, 0, 0), CFX_Matrix(-1, 0, 0, -1, 0, 0), CFX_Matrix(0, 1, -1, 0, 0, 0)}; for (int rot = 0; rot < 4; ++rot) { + int width; + int height; + FS_MATRIX matrix; matrix.a = rot_matrices[rot].a; matrix.b = rot_matrices[rot].b; matrix.c = rot_matrices[rot].c; @@ -438,12 +433,9 @@ TEST_F(FPDFViewEmbeddertest, FPDF_RenderPageBitmapWithMatrix) { // out). pdfium:849 // Now render again with the image scaled smaller. - width = initial_width / 2; - height = initial_height / 2; - matrix.a = 0.5; - matrix.b = 0; - matrix.c = 0; - matrix.d = 0.5; + int width = initial_width / 2; + int height = initial_height / 2; + FS_MATRIX matrix = {0.5, 0, 0, 0.5, 0, 0}; rect.right = width; rect.bottom = height; diff --git a/fpdfsdk/fsdk_define.h b/fpdfsdk/fsdk_define.h index f52e57abcc..77c2315edd 100644 --- a/fpdfsdk/fsdk_define.h +++ b/fpdfsdk/fsdk_define.h @@ -75,6 +75,9 @@ ByteString CFXByteStringFromFPDFWideString(FPDF_WIDESTRING wide_string); CFX_DIBitmap* CFXBitmapFromFPDFBitmap(FPDF_BITMAP bitmap); +CFX_FloatRect CFXFloatRectFromFSRECTF(const FS_RECTF& rect); +void FSRECTFFromCFXFloatRect(const CFX_FloatRect& rect, FS_RECTF* out_rect); + const FX_PATHPOINT* FXPathPointFromFPDFPathSegment(FPDF_PATHSEGMENT segment); unsigned long Utf16EncodeMaybeCopyAndReturnLength(const WideString& text, -- cgit v1.2.3