Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8ca12281 authored by Eric Fischer's avatar Eric Fischer Committed by Android (Google) Code Review
Browse files

Merge "Fix rounding of extra spacing when it is negative."

parents c1ba7431 1065758a
Loading
Loading
Loading
Loading
+6 −6
Original line number Original line Diff line number Diff line
@@ -1012,12 +1012,12 @@ extends Layout
        int extra;
        int extra;


        if (needMultiply) {
        if (needMultiply) {
            // XXX: this looks like it is using the +0.5 and the cast to int
            double ex = (below - above) * (spacingmult - 1) + spacingadd;
            // to do rounding, but this I expect this isn't doing the intended
            if (ex >= 0) {
            // thing when spacingmult < 1.  An intended extra of, say, -1.2
                extra = (int)(ex + 0.5);
            // will get 'rounded' to -.7 and then truncated to 0.
            } else {
            extra = (int) ((below - above) * (spacingmult - 1)
                extra = -(int)(-ex + 0.5);
                           + spacingadd + 0.5);
            }
        } else {
        } else {
            extra = 0;
            extra = 0;
        }
        }
+2 −2
Original line number Original line Diff line number Diff line
@@ -213,13 +213,13 @@ public class StaticLayoutTest extends TestCase {
        }
        }


        public int scale(float height) {
        public int scale(float height) {
            int altVal = (int)(height * sMult + sAdd + 0.5); // existing impl
            int altVal = (int)(height * sMult + sAdd + 0.5);
            int rndVal = Math.round(height * sMult + sAdd);
            int rndVal = Math.round(height * sMult + sAdd);
            if (altVal != rndVal) {
            if (altVal != rndVal) {
                Log.i("Scale", "expected scale: " + rndVal +
                Log.i("Scale", "expected scale: " + rndVal +
                        " != returned scale: " + altVal);
                        " != returned scale: " + altVal);
            }
            }
            return altVal; // existing implementation
            return rndVal;
        }
        }
    }
    }