Avoid generating streams with numbers in exponential format.

In cpdfsdk_appstream.cpp, use the helper functions from
cpdf_contentstream_write_utils.h to generate streams. Then float numbers
that are extremely large/small will be in a valid (non-exponential)
format.

Roll DEPS for testing/corpus to update expectations and make sure bots
remain green.

Bug: pdfium:1763
Change-Id: Ic4431024d7b1cdcf9c0310e9eb81006b16a3ef2c
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/96220
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Nigi <nigi@chromium.org>
diff --git a/DEPS b/DEPS
index d425edc..e749ead 100644
--- a/DEPS
+++ b/DEPS
@@ -122,7 +122,7 @@
   # Three lines of non-changing comments so that
   # the commit queue can handle CLs rolling pdfium_tests
   # and whatever else without interference from each other.
-  'pdfium_tests_revision': '666ca43e0d4c62220b11624011307e9ce5f4ea44',
+  'pdfium_tests_revision': '317dd8a84c65676c7ceb6c1dad0e54eaa0b71417',
   # Three lines of non-changing comments so that
   # the commit queue can handle CLs rolling skia
   # and whatever else without interference from each other.
diff --git a/fpdfsdk/cpdfsdk_appstream.cpp b/fpdfsdk/cpdfsdk_appstream.cpp
index 1336ec1..47443cb 100644
--- a/fpdfsdk/cpdfsdk_appstream.cpp
+++ b/fpdfsdk/cpdfsdk_appstream.cpp
@@ -15,6 +15,7 @@
 
 #include "constants/appearance.h"
 #include "constants/form_flags.h"
+#include "core/fpdfapi/edit/cpdf_contentstream_write_utils.h"
 #include "core/fpdfapi/font/cpdf_font.h"
 #include "core/fpdfapi/parser/cpdf_dictionary.h"
 #include "core/fpdfapi/parser/cpdf_document.h"
@@ -111,11 +112,11 @@
 };
 
 void WriteMove(fxcrt::ostringstream& stream, const CFX_PointF& point) {
-  stream << point.x << " " << point.y << " " << kMoveToOperator << "\n";
+  WritePoint(stream, point) << " " << kMoveToOperator << "\n";
 }
 
 void WriteLine(fxcrt::ostringstream& stream, const CFX_PointF& point) {
-  stream << point.x << " " << point.y << " " << kLineToOperator << "\n";
+  WritePoint(stream, point) << " " << kLineToOperator << "\n";
 }
 
 void WriteClosedLoop(fxcrt::ostringstream& stream,
@@ -130,14 +131,16 @@
                       const CFX_PointF& point1,
                       const CFX_PointF& point2,
                       const CFX_PointF& point3) {
-  stream << point1.x << " " << point1.y << " " << point2.x << " " << point2.y
-         << " " << point3.x << " " << point3.y << " " << kCurveToOperator
-         << "\n";
+  WritePoint(stream, point1) << " ";
+  WritePoint(stream, point2) << " ";
+  WritePoint(stream, point3) << " " << kCurveToOperator << "\n";
 }
 
 void WriteAppendRect(fxcrt::ostringstream& stream, const CFX_FloatRect& rect) {
-  stream << rect.left << " " << rect.bottom << " " << rect.Width() << " "
-         << rect.Height() << " " << kAppendRectOperator << "\n";
+  WriteFloat(stream, rect.left) << " ";
+  WriteFloat(stream, rect.bottom) << " ";
+  WriteFloat(stream, rect.Width()) << " ";
+  WriteFloat(stream, rect.Height()) << " " << kAppendRectOperator << "\n";
 }
 
 ByteString GetStrokeColorAppStream(const CFX_Color& color) {
@@ -346,17 +349,15 @@
   CFX_PointF pt2(0, fHeight / 2);
   CFX_PointF pt3(fWidth / 2, 0);
 
-  float px;
-  float py;
-
-  csAP << cos(fRotate) << " " << sin(fRotate) << " " << -sin(fRotate) << " "
-       << cos(fRotate) << " " << crBBox.left + fWidth / 2 << " "
-       << crBBox.bottom + fHeight / 2 << " " << kConcatMatrixOperator << "\n";
+  CFX_Matrix rotate_matrix(cos(fRotate), sin(fRotate), -sin(fRotate),
+                           cos(fRotate), crBBox.left + fWidth / 2,
+                           crBBox.bottom + fHeight / 2);
+  WriteMatrix(csAP, rotate_matrix) << " " << kConcatMatrixOperator << "\n";
 
   WriteMove(csAP, pt1);
 
-  px = pt2.x - pt1.x;
-  py = pt2.y - pt1.y;
+  float px = pt2.x - pt1.x;
+  float py = pt2.y - pt1.y;
 
   WriteBezierCurve(csAP, {pt1.x, pt1.y + py * FXSYS_BEZIER},
                    {pt2.x - px * FXSYS_BEZIER, pt2.y}, pt2);
@@ -649,8 +650,8 @@
         }
 
         if (ptNew.x != ptOld.x || ptNew.y != ptOld.y) {
-          sEditStream << ptNew.x - ptOld.x << " " << ptNew.y - ptOld.y << " "
-                      << kMoveTextPositionOperator << "\n";
+          WritePoint(sEditStream, {ptNew.x - ptOld.x, ptNew.y - ptOld.y})
+              << " " << kMoveTextPositionOperator << "\n";
 
           ptOld = ptNew;
         }
@@ -678,8 +679,8 @@
             CFX_PointF(word.ptWord.x + ptOffset.x, word.ptWord.y + ptOffset.y);
 
         if (ptNew.x != ptOld.x || ptNew.y != ptOld.y) {
-          sEditStream << ptNew.x - ptOld.x << " " << ptNew.y - ptOld.y << " "
-                      << kMoveTextPositionOperator << "\n";
+          WritePoint(sEditStream, {ptNew.x - ptOld.x, ptNew.y - ptOld.y})
+              << " " << kMoveTextPositionOperator << "\n";
           ptOld = ptNew;
         }
         if (word.nFontIndex != nCurFontIndex) {
@@ -735,11 +736,10 @@
     str << kSetNonZeroWindingClipOperator << " "
         << kEndPathNoFillOrStrokeOperator << "\n";
 
-    str << scale.x << " 0 0 " << scale.y << " " << rcPlate.left + offset.x
-        << " " << rcPlate.bottom + offset.y << " " << kConcatMatrixOperator
-        << "\n";
-    str << mt.a << " " << mt.b << " " << mt.c << " " << mt.d << " " << mt.e
-        << " " << mt.f << " " << kConcatMatrixOperator << "\n";
+    CFX_Matrix scale_matrix(scale.x, 0, 0, scale.y, rcPlate.left + offset.x,
+                            rcPlate.bottom + offset.y);
+    WriteMatrix(str, scale_matrix) << " " << kConcatMatrixOperator << "\n";
+    WriteMatrix(str, mt) << " " << kConcatMatrixOperator << "\n";
 
     str << "0 " << kSetGrayOperator << " 0 " << kSetGrayStrokedOperator << " 1 "
         << kSetLineWidthOperator << " /" << sAlias << " "
diff --git a/testing/resources/pixel/bug_736695_1_expected.pdf.0.png b/testing/resources/pixel/bug_736695_1_expected.pdf.0.png
index 99d7bd7..10bbb0d 100644
--- a/testing/resources/pixel/bug_736695_1_expected.pdf.0.png
+++ b/testing/resources/pixel/bug_736695_1_expected.pdf.0.png
Binary files differ
diff --git a/testing/resources/pixel/bug_736695_4_expected.pdf.0.png b/testing/resources/pixel/bug_736695_4_expected.pdf.0.png
index 99d7bd7..10bbb0d 100644
--- a/testing/resources/pixel/bug_736695_4_expected.pdf.0.png
+++ b/testing/resources/pixel/bug_736695_4_expected.pdf.0.png
Binary files differ