shithub: freetype+ttf2subf

Download patch

ref: d156cabcaed41beeed2fb92cff2a72302b726435
parent: bd7e1c3ce049aca25b34b8b50a162c6e2f297b82
author: Werner Lemberg <[email protected]>
date: Fri Dec 14 02:48:32 EST 2007

* src/cff/cffparse.c (cff_parse_real): Don't apply `power_ten'
division too early; otherwise the most significant digit(s) of the
final result are lost as the value is truncated to an integer.  This
fixes Savannah bug #21794 (where the patch has been posted too).

git/fs: mount .git/fs: mount/attach disallowed
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2007-12-14  Werner Lemberg  <[email protected]>
+
+	* src/cff/cffparse.c (cff_parse_real): Don't apply `power_ten'
+	division too early; otherwise the most significant digit(s) of the
+	final result are lost as the value is truncated to an integer.  This
+	fixes Savannah bug #21794 (where the patch has been posted too).
+
 2007-12-06  Fix  <[email protected]>
 
 	Pass options from one configure script to another as-is (not
--- a/src/cff/cffparse.c
+++ b/src/cff/cffparse.c
@@ -248,29 +248,30 @@
       power_ten += (FT_Int)exponent;
     }
 
-    /* raise to power of ten if needed */
-    while ( power_ten > 0 )
-    {
-      result = result * 10;
-      num    = num * 10;
-
-      power_ten--;
-    }
+    /* Move the integer part into the high 16 bits. */
+    result <<= 16;
 
-    while ( power_ten < 0 )
+    /* Place the decimal part into the low 16 bits. */
+    if ( num )
+      result |= FT_DivFix( num, divider );
+
+    /* apply power of 10 if needed */
+    if ( power_ten > 0 )
     {
-      result  = result / 10;
-      divider = divider * 10;
+      divider = 10; /* actually, this will be used as multiplier here */
+      while ( --power_ten > 0 )
+        divider = divider * 10;
 
-      power_ten++;
+      result = FT_MulFix( divider << 16, result );
     }
+    else if ( power_ten < 0 )
+    {
+      divider = 10;
+      while ( ++power_ten < 0 )
+        divider = divider * 10;
 
-    /* Move the integer part into the high 16 bits. */
-    result <<= 16;
-
-    /* Place the decimal part into the low 16 bits. */
-    if ( num )
-      result |= FT_DivFix( num, divider );
+      result = FT_DivFix( result, divider << 16 );
+    }
 
     if ( sign )
       result = -result;