Changeset 68148 in webkit


Ignore:
Timestamp:
Sep 23, 2010 9:18:01 AM (14 years ago)
Author:
mitz@apple.com
Message:

Address a remaining discrepancy in piecewise text measurement
https://bugs.webkit.org/show_bug.cgi?id=45796

Patch by Brad Moore <bradm@apple.com> on 2010-09-23
Reviewed by Dan Bernstein.

Don't include always-integral space widths in the floating point accumulator designed
to minimize precision loss. This brings whole-string measurement in line with piecewise
text measurement when dealing with fonts with fractional advances.

  • platform/graphics/WidthIterator.cpp:

(WebCore::WidthIterator::advance): Change the associativity of width addition to minimize precision loss.

Location:
trunk/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r68147 r68148  
     12010-09-23  Brad Moore  <bradm@apple.com>
     2
     3        Reviewed by Dan Bernstein.
     4
     5        Address a remaining discrepancy in piecewise text measurement
     6        https://bugs.webkit.org/show_bug.cgi?id=45796
     7
     8        Don't include always-integral space widths in the floating point accumulator designed
     9        to minimize precision loss.  This brings whole-string measurement in line with piecewise
     10        text measurement when dealing with fonts with fractional advances.
     11
     12        * platform/graphics/WidthIterator.cpp:
     13        (WebCore::WidthIterator::advance): Change the associativity of width addition to minimize precision loss.
     14
    1152010-09-23  Patrick Gansterer  <paroga@webkit.org>
    216
  • trunk/WebCore/platform/graphics/WidthIterator.cpp

    r63570 r68148  
    213213        // Force characters that are used to determine word boundaries for the rounding hack
    214214        // to be integer width, so following words will start on an integer boundary.
    215         if (m_run.applyWordRounding() && Font::isRoundingHackCharacter(c))
     215        if (m_run.applyWordRounding() && Font::isRoundingHackCharacter(c)) {
    216216            width = ceilf(width);
    217217
    218         // Check to see if the next character is a "rounding hack character", if so, adjust
    219         // width so that the total run width will be on an integer boundary.
    220         if ((m_run.applyWordRounding() && currentCharacter < m_run.length() && Font::isRoundingHackCharacter(*cp))
    221                 || (m_run.applyRunRounding() && currentCharacter >= m_end)) {
    222             float totalWidth = widthSinceLastRounding + width;
    223             widthSinceLastRounding = ceilf(totalWidth);
    224             width += widthSinceLastRounding - totalWidth;
    225             m_runWidthSoFar += widthSinceLastRounding;
    226             widthSinceLastRounding = 0;
    227         } else
    228             widthSinceLastRounding += width;
     218            // Since widthSinceLastRounding can lose precision if we include measurements for
     219            // preceding whitespace, we bypass it here.
     220            m_runWidthSoFar += width;
     221
     222            // Since this is a rounding hack character, we should have reset this sum on the previous
     223            // iteration.
     224            ASSERT(!widthSinceLastRounding);
     225        } else {
     226            // Check to see if the next character is a "rounding hack character", if so, adjust
     227            // width so that the total run width will be on an integer boundary.
     228            if ((m_run.applyWordRounding() && currentCharacter < m_run.length() && Font::isRoundingHackCharacter(*cp))
     229                    || (m_run.applyRunRounding() && currentCharacter >= m_end)) {
     230                float totalWidth = widthSinceLastRounding + width;
     231                widthSinceLastRounding = ceilf(totalWidth);
     232                width += widthSinceLastRounding - totalWidth;
     233                m_runWidthSoFar += widthSinceLastRounding;
     234                widthSinceLastRounding = 0;
     235            } else
     236                widthSinceLastRounding += width;
     237        }
    229238
    230239        if (glyphBuffer)
Note: See TracChangeset for help on using the changeset viewer.