Bug 1331760 - convert dom/svg from nsTextFormatter to AppendPrintf; r?froydnj draft
authorTom Tromey <tom@tromey.com>
Tue, 12 Sep 2017 15:40:09 -0600
changeset 696382 77b75782e874de87498d946eb826528d858fea70
parent 696381 f8241fe4b165fbe6630ae68dc7fdccd51a180944
child 696383 699ced0046bf9cf61710483055dbee343c91199c
push id88695
push userbmo:ttromey@mozilla.com
push dateFri, 10 Nov 2017 15:13:25 +0000
reviewersfroydnj
bugs1331760
milestone58.0a1
Bug 1331760 - convert dom/svg from nsTextFormatter to AppendPrintf; r?froydnj MozReview-Commit-ID: 1HCl8ZkXRQ9
dom/svg/SVGLength.cpp
dom/svg/SVGNumberList.cpp
dom/svg/SVGPathSegUtils.cpp
dom/svg/SVGPointList.cpp
dom/svg/nsSVGAngle.cpp
dom/svg/nsSVGLength2.cpp
dom/svg/nsSVGTransform.cpp
dom/svg/nsSVGViewBox.cpp
--- a/dom/svg/SVGLength.cpp
+++ b/dom/svg/SVGLength.cpp
@@ -4,31 +4,31 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/ArrayUtils.h"
 
 #include "SVGLength.h"
 #include "nsSVGElement.h"
 #include "mozilla/dom/SVGSVGElement.h"
-#include "nsTextFormatter.h"
 #include "SVGContentUtils.h"
 #include <limits>
 #include <algorithm>
 
 namespace mozilla {
 
 // Declare some helpers defined below:
 static void GetUnitString(nsAString& unit, uint16_t unitType);
 static uint16_t GetUnitTypeForString(const nsAString& unitStr);
 
 void
 SVGLength::GetValueAsString(nsAString &aValue) const
 {
-  nsTextFormatter::ssprintf(aValue, u"%g", (double)mValue);
+  aValue.Truncate();
+  aValue.AppendPrintf("%g", (double)mValue);
 
   nsAutoString unitString;
   GetUnitString(unitString, mUnit);
   aValue.Append(unitString);
 }
 
 bool
 SVGLength::SetValueFromString(const nsAString &aString)
--- a/dom/svg/SVGNumberList.cpp
+++ b/dom/svg/SVGNumberList.cpp
@@ -4,17 +4,16 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/ArrayUtils.h"
 
 #include "SVGNumberList.h"
 #include "nsCharSeparatedTokenizer.h"
 #include "nsString.h"
-#include "nsTextFormatter.h"
 #include "SVGContentUtils.h"
 
 namespace mozilla {
 
 nsresult
 SVGNumberList::CopyFrom(const SVGNumberList& rhs)
 {
   if (!mNumbers.Assign(rhs.mNumbers, fallible)) {
@@ -22,26 +21,22 @@ SVGNumberList::CopyFrom(const SVGNumberL
   }
   return NS_OK;
 }
 
 void
 SVGNumberList::GetValueAsString(nsAString& aValue) const
 {
   aValue.Truncate();
-  char16_t buf[24];
   uint32_t last = mNumbers.Length() - 1;
   for (uint32_t i = 0; i < mNumbers.Length(); ++i) {
     // Would like to use aValue.AppendPrintf("%f", mNumbers[i]), but it's not
     // possible to always avoid trailing zeros.
-    nsTextFormatter::snprintf(buf, ArrayLength(buf),
-                              u"%g",
-                              double(mNumbers[i]));
     // We ignore OOM, since it's not useful for us to return an error.
-    aValue.Append(buf);
+    aValue.AppendPrintf("%g", double(mNumbers[i]));
     if (i != last) {
       aValue.Append(' ');
     }
   }
 }
 
 nsresult
 SVGNumberList::SetValueFromString(const nsAString& aValue)
--- a/dom/svg/SVGPathSegUtils.cpp
+++ b/dom/svg/SVGPathSegUtils.cpp
@@ -5,17 +5,16 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/ArrayUtils.h" // MOZ_ARRAY_LENGTH
 
 #include "SVGPathSegUtils.h"
 
 #include "gfx2DGlue.h"
 #include "nsSVGPathDataParser.h"
-#include "nsTextFormatter.h"
 
 using namespace mozilla;
 using namespace mozilla::gfx;
 
 static const float PATH_SEG_LENGTH_TOLERANCE = 0.0000001f;
 static const uint32_t MAX_RECURSION = 10;
 
 
@@ -28,50 +27,46 @@ SVGPathSegUtils::GetValueAsString(const 
                 "Update GetValueAsString for the new value.");
   static_assert(NS_SVG_PATH_SEG_MAX_ARGS == 7,
                 "Add another case to the switch below.");
 
   uint32_t type = DecodeType(aSeg[0]);
   char16_t typeAsChar = GetPathSegTypeAsLetter(type);
 
   // Special case arcs:
+  aValue.Truncate();
   if (IsArcType(type)) {
     bool largeArcFlag = aSeg[4] != 0.0f;
     bool sweepFlag = aSeg[5] != 0.0f;
-    nsTextFormatter::ssprintf(aValue,
-                              u"%c%g,%g %g %d,%d %g,%g",
-                              typeAsChar, aSeg[1], aSeg[2], aSeg[3],
-                              largeArcFlag, sweepFlag, aSeg[6], aSeg[7]);
+    aValue.AppendPrintf("%c%g,%g %g %d,%d %g,%g",
+                        typeAsChar, aSeg[1], aSeg[2], aSeg[3],
+                        largeArcFlag, sweepFlag, aSeg[6], aSeg[7]);
   } else {
 
     switch (ArgCountForType(type)) {
     case 0:
       aValue = typeAsChar;
       break;
 
     case 1:
-      nsTextFormatter::ssprintf(aValue, u"%c%g",
-                                typeAsChar, aSeg[1]);
+      aValue.AppendPrintf("%c%g", typeAsChar, aSeg[1]);
       break;
 
     case 2:
-      nsTextFormatter::ssprintf(aValue, u"%c%g,%g",
-                                typeAsChar, aSeg[1], aSeg[2]);
+      aValue.AppendPrintf("%c%g,%g", typeAsChar, aSeg[1], aSeg[2]);
       break;
 
     case 4:
-      nsTextFormatter::ssprintf(aValue, u"%c%g,%g %g,%g",
-                                typeAsChar, aSeg[1], aSeg[2], aSeg[3], aSeg[4]);
+      aValue.AppendPrintf("%c%g,%g %g,%g", typeAsChar, aSeg[1], aSeg[2], aSeg[3], aSeg[4]);
       break;
 
     case 6:
-      nsTextFormatter::ssprintf(aValue,
-                                u"%c%g,%g %g,%g %g,%g",
-                                typeAsChar, aSeg[1], aSeg[2], aSeg[3], aSeg[4],
-                                aSeg[5], aSeg[6]);
+      aValue.AppendPrintf("%c%g,%g %g,%g %g,%g",
+                          typeAsChar, aSeg[1], aSeg[2], aSeg[3], aSeg[4],
+                          aSeg[5], aSeg[6]);
       break;
 
     default:
       MOZ_ASSERT(false, "Unknown segment type");
       aValue = u"<unknown-segment-type>";
       return;
     }
   }
--- a/dom/svg/SVGPointList.cpp
+++ b/dom/svg/SVGPointList.cpp
@@ -3,17 +3,16 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/ArrayUtils.h"
 
 #include "SVGPointList.h"
 #include "nsCharSeparatedTokenizer.h"
-#include "nsTextFormatter.h"
 #include "SVGContentUtils.h"
 
 namespace mozilla {
 
 nsresult
 SVGPointList::CopyFrom(const SVGPointList& rhs)
 {
   if (!mItems.Assign(rhs.mItems, fallible)) {
@@ -21,26 +20,23 @@ SVGPointList::CopyFrom(const SVGPointLis
   }
   return NS_OK;
 }
 
 void
 SVGPointList::GetValueAsString(nsAString& aValue) const
 {
   aValue.Truncate();
-  char16_t buf[50];
   uint32_t last = mItems.Length() - 1;
   for (uint32_t i = 0; i < mItems.Length(); ++i) {
     // Would like to use aValue.AppendPrintf("%f,%f", item.mX, item.mY),
     // but it's not possible to always avoid trailing zeros.
-    nsTextFormatter::snprintf(buf, ArrayLength(buf),
-                              u"%g,%g",
-                              double(mItems[i].mX), double(mItems[i].mY));
     // We ignore OOM, since it's not useful for us to return an error.
-    aValue.Append(buf);
+    aValue.AppendPrintf("%g,%g",
+                        double(mItems[i].mX), double(mItems[i].mY));
     if (i != last) {
       aValue.Append(' ');
     }
   }
 }
 
 nsresult
 SVGPointList::SetValueFromString(const nsAString& aValue)
--- a/dom/svg/nsSVGAngle.cpp
+++ b/dom/svg/nsSVGAngle.cpp
@@ -7,17 +7,16 @@
 #include "nsSVGAngle.h"
 
 #include "mozilla/ArrayUtils.h"
 #include "mozilla/dom/SVGMarkerElement.h"
 #include "mozilla/Move.h"
 #include "nsContentUtils.h" // NS_ENSURE_FINITE
 #include "nsSMILValue.h"
 #include "nsSVGAttrTearoffTable.h"
-#include "nsTextFormatter.h"
 #include "SVGAngle.h"
 #include "SVGAnimatedAngle.h"
 #include "SVGOrientSMILType.h"
 
 using namespace mozilla;
 using namespace mozilla::dom;
 
 static nsStaticAtom** const unitMap[] =
@@ -78,17 +77,18 @@ GetUnitTypeForString(const nsAString& un
   }
 
   return SVG_ANGLETYPE_UNKNOWN;
 }
 
 static void
 GetValueString(nsAString &aValueAsString, float aValue, uint16_t aUnitType)
 {
-  nsTextFormatter::ssprintf(aValueAsString, u"%g", (double)aValue);
+  aValueAsString.Truncate();
+  aValueAsString.AppendPrintf("%g", (double)aValue);
 
   nsAutoString unitString;
   GetUnitString(unitString, aUnitType);
   aValueAsString.Append(unitString);
 }
 
 /* static */ bool
 nsSVGAngle::GetValueFromString(const nsAString& aString,
--- a/dom/svg/nsSVGLength2.cpp
+++ b/dom/svg/nsSVGLength2.cpp
@@ -10,17 +10,16 @@
 #include "mozilla/dom/SVGAnimatedLength.h"
 #include "mozilla/dom/SVGViewportElement.h"
 #include "nsContentUtils.h" // NS_ENSURE_FINITE
 #include "nsIFrame.h"
 #include "nsSMILFloatType.h"
 #include "nsSMILValue.h"
 #include "nsSVGAttrTearoffTable.h"
 #include "nsSVGIntegrationUtils.h"
-#include "nsTextFormatter.h"
 #include "DOMSVGLength.h"
 #include "LayoutLogging.h"
 
 using namespace mozilla;
 using namespace mozilla::dom;
 
 static nsStaticAtom** const unitMap[] =
 {
@@ -81,17 +80,18 @@ GetUnitTypeForString(const nsAString& un
   }
 
   return nsIDOMSVGLength::SVG_LENGTHTYPE_UNKNOWN;
 }
 
 static void
 GetValueString(nsAString &aValueAsString, float aValue, uint16_t aUnitType)
 {
-  nsTextFormatter::ssprintf(aValueAsString, u"%g", (double)aValue);
+  aValueAsString.Truncate();
+  aValueAsString.AppendPrintf("%g", (double)aValue);
 
   nsAutoString unitString;
   GetUnitString(unitString, aUnitType);
   aValueAsString.Append(unitString);
 }
 
 static bool
 GetValueFromString(const nsAString& aString,
--- a/dom/svg/nsSVGTransform.cpp
+++ b/dom/svg/nsSVGTransform.cpp
@@ -2,73 +2,70 @@
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsError.h"
 #include "nsSVGTransform.h"
 #include "nsContentUtils.h" // for NS_ENSURE_FINITE
-#include "nsTextFormatter.h"
 
 namespace {
   const double kRadPerDegree = 2.0 * M_PI / 360.0;
 } // namespace
 
 namespace mozilla {
 
 void
 nsSVGTransform::GetValueAsString(nsAString& aValue) const
 {
+  aValue.Truncate();
   switch (mType) {
     case SVG_TRANSFORM_TRANSLATE:
       // The spec say that if Y is not provided, it is assumed to be zero.
       if (mMatrix._32 != 0)
-        nsTextFormatter::ssprintf(aValue,
-            u"translate(%g, %g)",
+        aValue.AppendPrintf(
+            "translate(%g, %g)",
             mMatrix._31, mMatrix._32);
       else
-        nsTextFormatter::ssprintf(aValue,
-            u"translate(%g)",
+        aValue.AppendPrintf(
+            "translate(%g)",
             mMatrix._31);
       break;
     case SVG_TRANSFORM_ROTATE:
       if (mOriginX != 0.0f || mOriginY != 0.0f)
-        nsTextFormatter::ssprintf(aValue,
-            u"rotate(%g, %g, %g)",
+        aValue.AppendPrintf(
+            "rotate(%g, %g, %g)",
             mAngle, mOriginX, mOriginY);
       else
-        nsTextFormatter::ssprintf(aValue,
-            u"rotate(%g)", mAngle);
+        aValue.AppendPrintf(
+            "rotate(%g)", mAngle);
       break;
     case SVG_TRANSFORM_SCALE:
       if (mMatrix._11 != mMatrix._22)
-        nsTextFormatter::ssprintf(aValue,
-            u"scale(%g, %g)", mMatrix._11, mMatrix._22);
+        aValue.AppendPrintf(
+            "scale(%g, %g)", mMatrix._11, mMatrix._22);
       else
-        nsTextFormatter::ssprintf(aValue,
-            u"scale(%g)", mMatrix._11);
+        aValue.AppendPrintf(
+            "scale(%g)", mMatrix._11);
       break;
     case SVG_TRANSFORM_SKEWX:
-      nsTextFormatter::ssprintf(aValue,
-                                u"skewX(%g)", mAngle);
+      aValue.AppendPrintf("skewX(%g)", mAngle);
       break;
     case SVG_TRANSFORM_SKEWY:
-      nsTextFormatter::ssprintf(aValue,
-                                u"skewY(%g)", mAngle);
+      aValue.AppendPrintf("skewY(%g)", mAngle);
       break;
     case SVG_TRANSFORM_MATRIX:
-      nsTextFormatter::ssprintf(aValue,
-          u"matrix(%g, %g, %g, %g, %g, %g)",
+      aValue.AppendPrintf(
+          "matrix(%g, %g, %g, %g, %g, %g)",
                             mMatrix._11, mMatrix._12,
                             mMatrix._21, mMatrix._22,
                             mMatrix._31, mMatrix._32);
       break;
     default:
-      aValue.Truncate();
       NS_ERROR("unknown transformation type");
       break;
   }
 }
 
 void
 nsSVGTransform::SetMatrix(const gfxMatrix& aMatrix)
 {
--- a/dom/svg/nsSVGViewBox.cpp
+++ b/dom/svg/nsSVGViewBox.cpp
@@ -4,17 +4,16 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsSVGViewBox.h"
 
 #include "mozilla/Move.h"
 #include "nsCharSeparatedTokenizer.h"
 #include "nsSMILValue.h"
-#include "nsTextFormatter.h"
 #include "SVGContentUtils.h"
 #include "SVGViewBoxSMILType.h"
 
 #define NUM_VIEWBOX_COMPONENTS 4
 using namespace mozilla;
 
 /* Implementation of nsSVGViewBoxRect methods */
 
@@ -201,20 +200,20 @@ nsSVGViewBox::SetBaseValueString(const n
 
 void
 nsSVGViewBox::GetBaseValueString(nsAString& aValue) const
 {
   if (mBaseVal.none) {
     aValue.AssignLiteral("none");
     return;
   }
-  nsTextFormatter::ssprintf(aValue,
-                            u"%g %g %g %g",
-                            (double)mBaseVal.x, (double)mBaseVal.y,
-                            (double)mBaseVal.width, (double)mBaseVal.height);
+  aValue.Truncate();
+  aValue.AppendPrintf("%g %g %g %g",
+                      (double)mBaseVal.x, (double)mBaseVal.y,
+                      (double)mBaseVal.width, (double)mBaseVal.height);
 }
 
 
 already_AddRefed<dom::SVGAnimatedRect>
 nsSVGViewBox::ToSVGAnimatedRect(nsSVGElement* aSVGElement)
 {
   RefPtr<dom::SVGAnimatedRect> domAnimatedRect =
     sSVGAnimatedRectTearoffTable.GetTearoff(this);