Changeset 80662 in webkit


Ignore:
Timestamp:
Mar 9, 2011 2:20:34 PM (13 years ago)
Author:
hyatt@apple.com
Message:

<rdar://problem/9110316> REGRESSION: 'ex' unit broken for vertical text

Reviewed by Dan Bernstein.

Fall back to the verticalRightOrientation data when obtaining the x-height for vertically oriented
text. That way we use the same metrics as for horizontal.

This fixes regressions in fast/lists and fast/overflow vertical text tests.

  • platform/graphics/mac/SimpleFontDataMac.mm:

(WebCore::SimpleFontData::platformInit):
(WebCore::SimpleFontData::platformBoundsForGlyph):

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r80658 r80662  
     12011-03-09  David Hyatt  <hyatt@apple.com>
     2
     3        Reviewed by Dan Bernstein.
     4
     5        <rdar://problem/9110316> REGRESSION: 'ex' unit broken for vertical text
     6
     7        Fall back to the verticalRightOrientation data when obtaining the x-height for vertically oriented
     8        text. That way we use the same metrics as for horizontal.
     9
     10        This fixes regressions in fast/lists and fast/overflow vertical text tests.
     11
     12        * platform/graphics/mac/SimpleFontDataMac.mm:
     13        (WebCore::SimpleFontData::platformInit):
     14        (WebCore::SimpleFontData::platformBoundsForGlyph):
     15
    1162011-03-09  Ryosuke Niwa  <rniwa@webkit.org>
    217
  • trunk/Source/WebCore/platform/graphics/mac/SimpleFontDataMac.mm

    r80582 r80662  
    275275    float xHeight;
    276276
    277     // Measure the actual character "x", because AppKit synthesizes X height rather than getting it from the font.
    278     // Unfortunately, NSFont will round this for us so we don't quite get the right value.
    279     GlyphPage* glyphPageZero = GlyphPageTreeNode::getRootChild(this, 0)->page();
    280     NSGlyph xGlyph = glyphPageZero ? glyphPageZero->glyphDataForCharacter('x').glyph : 0;
    281     if (xGlyph) {
    282         CGRect xBox = platformBoundsForGlyph(xGlyph);
    283         // Use the maximum of either width or height because "x" is nearly square
    284         // and web pages that foolishly use this metric for width will be laid out
    285         // poorly if we return an accurate height. Classic case is Times 13 point,
    286         // which has an "x" that is 7x6 pixels.
    287         xHeight = static_cast<float>(max(CGRectGetMaxX(xBox), -CGRectGetMinY(xBox)));
    288     } else {
    289 #ifndef BUILDING_ON_TIGER
    290         xHeight = static_cast<float>(CGFontGetXHeight(m_platformData.cgFont())) / unitsPerEm;
    291 #else
    292         xHeight = m_platformData.font() ? [m_platformData.font() xHeight] : 0;
    293 #endif
    294         // CGFontGetXHeight() returns a wrong value for "Apple Symbols" font (a float close to 0, but not strictly 0).
    295         // The following code makes a guess for xHeight in that case.
    296         // The int cast is a workaround for the "almost" zero value returned by CGFontGetXHeight().
    297         if (!static_cast<int>(xHeight) && ascent)
    298             xHeight = 2 * ascent / 3;
    299     }
     277    // Measure the actual character "x", since it's possible for it to extend below the baseline, and we need the
     278    // reported x-height to only include the portion of the glyph that is above the baseline.
     279    if (platformData().orientation() == Horizontal) {
     280        GlyphPage* glyphPageZero = GlyphPageTreeNode::getRootChild(this, 0)->page();
     281        NSGlyph xGlyph = glyphPageZero ? glyphPageZero->glyphDataForCharacter('x').glyph : 0;
     282        if (xGlyph) {
     283            CGRect xBox = platformBoundsForGlyph(xGlyph);
     284            // Use the maximum of either width or height because "x" is nearly square
     285            // and web pages that foolishly use this metric for width will be laid out
     286            // poorly if we return an accurate height. Classic case is Times 13 point,
     287            // which has an "x" that is 7x6 pixels.
     288            xHeight = max(CGRectGetMaxX(xBox), -CGRectGetMinY(xBox));
     289        } else {
     290            xHeight = static_cast<float>(CGFontGetXHeight(m_platformData.cgFont())) / unitsPerEm;
     291            // CGFontGetXHeight() returns a wrong value for "Apple Symbols" font (a float close to 0, but not strictly 0).
     292            // The following code makes a guess for xHeight in that case.
     293            // The int cast is a workaround for the "almost" zero value returned by CGFontGetXHeight().
     294            if (!static_cast<int>(xHeight) && ascent)
     295                xHeight = 2 * ascent / 3;
     296        }
     297    } else
     298        xHeight = verticalRightOrientationFontData()->fontMetrics().xHeight();
    300299
    301300    m_fontMetrics.setUnitsPerEm(unitsPerEm);
     
    470469{
    471470    FloatRect boundingBox;
    472 #ifndef BUILDING_ON_TIGER
    473471    boundingBox = CTFontGetBoundingRectsForGlyphs(m_platformData.ctFont(), platformData().orientation() == Vertical ? kCTFontVerticalOrientation : kCTFontHorizontalOrientation, &glyph, 0, 1);
    474472    boundingBox.setY(-boundingBox.maxY());
    475 #else
    476     // FIXME: Custom fonts don't have NSFonts, so this function doesn't compute correct bounds for these on Tiger.
    477     if (!m_platformData.font())
    478         return boundingBox;
    479     boundingBox = [m_platformData.font() boundingRectForGlyph:glyph];
    480     boundingBox.setY(-boundingBox.maxY());
    481 #endif
    482473    if (m_syntheticBoldOffset)
    483474        boundingBox.setWidth(boundingBox.width() + m_syntheticBoldOffset);
Note: See TracChangeset for help on using the changeset viewer.