Check scalar to fixed conversions with axes.
authorbenjaminwagner <benjaminwagner@google.com>
Thu, 25 Feb 2016 20:20:40 +0000 (12:20 -0800)
committerCommit bot <commit-bot@chromium.org>
Thu, 25 Feb 2016 20:20:40 +0000 (12:20 -0800)
In SkTypeface_FreeType::Scanner::computeAxisValues, check for
out-of-range values before converting to SkFixed.

BUG=skia:4632
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1709403003

Review URL: https://codereview.chromium.org/1709403003

src/ports/SkFontHost_FreeType.cpp

index d61a94323aaf84e2d4b4e47fee56efd2daa658ee..181116a15e09d4b1853a17abeb0da73a261e6d16 100644 (file)
@@ -1750,13 +1750,14 @@ bool SkTypeface_FreeType::Scanner::scanFont(
 {
     for (int i = 0; i < axisDefinitions.count(); ++i) {
         const Scanner::AxisDefinition& axisDefinition = axisDefinitions[i];
+        const SkScalar axisMin = SkFixedToScalar(axisDefinition.fMinimum);
+        const SkScalar axisMax = SkFixedToScalar(axisDefinition.fMaximum);
         axisValues[i] = axisDefinition.fDefault;
         for (int j = 0; j < requestedAxisCount; ++j) {
             const SkFontMgr::FontParameters::Axis& axisSpecified = requestedAxes[j];
             if (axisDefinition.fTag == axisSpecified.fTag) {
-                SkFixed axisValue = SkScalarToFixed(axisSpecified.fStyleValue);
-                axisValues[i] = SkTPin(axisValue, axisDefinition.fMinimum, axisDefinition.fMaximum);
-                if (axisValues[i] != axisValue) {
+                const SkScalar axisValue = SkTPin(axisSpecified.fStyleValue, axisMin, axisMax);
+                if (axisSpecified.fStyleValue != axisValue) {
                     SkDEBUGF(("Requested font axis value out of range: "
                               "%s '%c%c%c%c' %f; pinned to %f.\n",
                               name.c_str(),
@@ -1765,8 +1766,9 @@ bool SkTypeface_FreeType::Scanner::scanFont(
                               (axisDefinition.fTag >>  8) & 0xFF,
                               (axisDefinition.fTag      ) & 0xFF,
                               SkScalarToDouble(axisSpecified.fStyleValue),
-                              SkFixedToDouble(axisValues[i])));
+                              SkScalarToDouble(axisValue)));
                 }
+                axisValues[i] = SkScalarToFixed(axisValue);
                 break;
             }
         }