Add FS_RECTF conversion functions.

Change-Id: I87fb109fdd121716a170df15c4762496c1ccb88c
Reviewed-on: https://pdfium-review.googlesource.com/17210
Commit-Queue: dsinclair <dsinclair@chromium.org>
Reviewed-by: dsinclair <dsinclair@chromium.org>
diff --git a/fpdfsdk/fpdf_transformpage.cpp b/fpdfsdk/fpdf_transformpage.cpp
index e8a2705..dcf19f2 100644
--- a/fpdfsdk/fpdf_transformpage.cpp
+++ b/fpdfsdk/fpdf_transformpage.cpp
@@ -112,8 +112,7 @@
 
   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 09bf42a..ec541f5 100644
--- a/fpdfsdk/fpdfannot.cpp
+++ b/fpdfsdk/fpdfannot.cpp
@@ -644,7 +644,7 @@
   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 @@
   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 c536c73..4d2942f 100644
--- a/fpdfsdk/fpdfdoc.cpp
+++ b/fpdfsdk/fpdfdoc.cpp
@@ -329,11 +329,7 @@
     return false;
   CPDF_Dictionary* pAnnotDict =
       ToDictionary(static_cast<CPDF_Object*>(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 b68b72e..c86a012 100644
--- a/fpdfsdk/fpdfview.cpp
+++ b/fpdfsdk/fpdfview.cpp
@@ -359,6 +359,17 @@
   return static_cast<CFX_DIBitmap*>(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<const FX_PATHPOINT*>(segment);
 }
@@ -1008,12 +1019,8 @@
   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 699fc8a..5fedbfc 100644
--- a/fpdfsdk/fpdfview_embeddertest.cpp
+++ b/fpdfsdk/fpdfview_embeddertest.cpp
@@ -388,23 +388,18 @@
   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 @@
   // 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 f52e57a..77c2315 100644
--- a/fpdfsdk/fsdk_define.h
+++ b/fpdfsdk/fsdk_define.h
@@ -75,6 +75,9 @@
 
 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,