freetype-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[freetype2] master b72858c: [truetype] Clamp variation requests to valid


From: Werner LEMBERG
Subject: [freetype2] master b72858c: [truetype] Clamp variation requests to valid range.
Date: Thu, 3 Nov 2016 05:42:03 +0000 (UTC)

branch: master
commit b72858c992d4c9b06899f35f8e11c71801229c53
Author: Behdad Esfahbod <address@hidden>
Commit: Werner Lemberg <address@hidden>

    [truetype] Clamp variation requests to valid range.
    
    This is required by OpenType 1.8; it also avoids rounding surprises.
    
    * src/truetype/ttgxvar.c (TT_Set_Var_Design): Clamp design coordinates
    outside of the allowed range to always stay within the range instead
    of producing an error.
---
 ChangeLog              |   10 ++++++++++
 src/truetype/ttgxvar.c |   33 ++++++++++++++++++++-------------
 2 files changed, 30 insertions(+), 13 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index ffb6fa4..0dc5880 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2016-11-03  Behdad Esfahbod  <address@hidden>
+
+       [truetype] Clamp variation requests to valid range.
+
+       This is required by OpenType 1.8; it also avoids rounding surprises.
+
+       * src/truetype/ttgxvar.c (TT_Set_Var_Design): Clamp design coordinates
+       outside of the allowed range to always stay within the range instead
+       of producing an error.
+
 2016-10-29  Werner Lemberg  <address@hidden>
 
        [truetype] Remove clang warnings.
diff --git a/src/truetype/ttgxvar.c b/src/truetype/ttgxvar.c
index fd00ca4..0b48c2c 100644
--- a/src/truetype/ttgxvar.c
+++ b/src/truetype/ttgxvar.c
@@ -1310,26 +1310,33 @@
     a = mmvar->axis;
     for ( i = 0; i < num_coords; i++, a++ )
     {
-      FT_TRACE5(( "  %.4f\n", coords[i] / 65536.0 ));
-      if ( coords[i] > a->maximum || coords[i] < a->minimum )
+      FT_Fixed  coord = coords[i];
+
+
+      FT_TRACE5(( "  %.4f\n", coord / 65536.0 ));
+      if ( coord > a->maximum || coord < a->minimum )
       {
-        FT_TRACE1(( "TT_Set_Var_Design: normalized design coordinate %.4f\n"
-                    "                   is out of range [%.4f;%.4f]\n",
-                    coords[i] / 65536.0,
-                    a->minimum / 65536.0,
-                    a->maximum / 65536.0 ));
-        error = FT_THROW( Invalid_Argument );
-        goto Exit;
+        FT_TRACE1((
+          "TT_Set_Var_Design: normalized design coordinate %.4f\n"
+          "                   is out of range [%.4f;%.4f]; clamping\n",
+          coord / 65536.0,
+          a->minimum / 65536.0,
+          a->maximum / 65536.0 ));
+
+        if ( coord > a->maximum)
+          coord = a->maximum;
+        else
+          coord = a->minimum;
       }
 
-      if ( coords[i] < a->def )
+      if ( coord < a->def )
         normalized[i] = -FT_DivFix( coords[i] - a->def,
                                     a->minimum - a->def );
-      else if ( a->maximum == a->def )
-        normalized[i] = 0;
-      else
+      else if ( coord > a->def )
         normalized[i] = FT_DivFix( coords[i] - a->def,
                                    a->maximum - a->def );
+      else
+        normalized[i] = 0;
     }
 
     FT_TRACE5(( "\n" ));



reply via email to

[Prev in Thread] Current Thread [Next in Thread]