From 2bde8e466a4451c7319e3a072d118917957d6554 Mon Sep 17 00:00:00 2001 From: Steve Block Date: Wed, 25 May 2011 19:08:45 +0100 Subject: Merge WebKit at r82507: Initial merge by git Change-Id: I60ce9d780725b58b45e54165733a8ffee23b683e --- .../platform/graphics/mac/SimpleFontDataMac.mm | 56 ++++++---------------- 1 file changed, 15 insertions(+), 41 deletions(-) (limited to 'Source/WebCore/platform/graphics/mac/SimpleFontDataMac.mm') diff --git a/Source/WebCore/platform/graphics/mac/SimpleFontDataMac.mm b/Source/WebCore/platform/graphics/mac/SimpleFontDataMac.mm index 3094498..cd34000 100644 --- a/Source/WebCore/platform/graphics/mac/SimpleFontDataMac.mm +++ b/Source/WebCore/platform/graphics/mac/SimpleFontDataMac.mm @@ -259,49 +259,32 @@ void SimpleFontData::platformInit() descent = 3; } - if (m_orientation == Vertical) { - // Ignore vertical orientation when the font doesn't support vertical metrics. + if (platformData().orientation() == Vertical && !isTextOrientationFallback()) { // The check doesn't look neat but this is what AppKit does for vertical writing... RetainPtr tableTags(AdoptCF, CTFontCopyAvailableTables(m_platformData.ctFont(), kCTFontTableOptionExcludeSynthetic)); CFIndex numTables = CFArrayGetCount(tableTags.get()); - bool found = false; for (CFIndex index = 0; index < numTables; ++index) { CTFontTableTag tag = (CTFontTableTag)(uintptr_t)CFArrayGetValueAtIndex(tableTags.get(), index); if (tag == kCTFontTableVhea || tag == kCTFontTableVORG) { - found = true; + m_hasVerticalGlyphs = true; break; } } - - if (found == false) - m_orientation = Horizontal; } float xHeight; - // Measure the actual character "x", because AppKit synthesizes X height rather than getting it from the font. - // Unfortunately, NSFont will round this for us so we don't quite get the right value. - GlyphPage* glyphPageZero = GlyphPageTreeNode::getRootChild(this, 0)->page(); - NSGlyph xGlyph = glyphPageZero ? glyphPageZero->glyphDataForCharacter('x').glyph : 0; - if (xGlyph) { - CGRect xBox = platformBoundsForGlyph(xGlyph); - // Use the maximum of either width or height because "x" is nearly square - // and web pages that foolishly use this metric for width will be laid out - // poorly if we return an accurate height. Classic case is Times 13 point, - // which has an "x" that is 7x6 pixels. - xHeight = static_cast(max(CGRectGetMaxX(xBox), -CGRectGetMinY(xBox))); - } else { -#ifndef BUILDING_ON_TIGER - xHeight = static_cast(CGFontGetXHeight(m_platformData.cgFont())) / unitsPerEm; -#else - xHeight = m_platformData.font() ? [m_platformData.font() xHeight] : 0; -#endif - // CGFontGetXHeight() returns a wrong value for "Apple Symbols" font (a float close to 0, but not strictly 0). - // The following code makes a guess for xHeight in that case. - // The int cast is a workaround for the "almost" zero value returned by CGFontGetXHeight(). - if (!static_cast(xHeight) && ascent) - xHeight = 2 * ascent / 3; - } + if (platformData().orientation() == Horizontal) { + // Measure the actual character "x", since it's possible for it to extend below the baseline, and we need the + // reported x-height to only include the portion of the glyph that is above the baseline. + GlyphPage* glyphPageZero = GlyphPageTreeNode::getRootChild(this, 0)->page(); + NSGlyph xGlyph = glyphPageZero ? glyphPageZero->glyphDataForCharacter('x').glyph : 0; + if (xGlyph) + xHeight = -CGRectGetMinY(platformBoundsForGlyph(xGlyph)); + else + xHeight = scaleEmToUnits(CGFontGetXHeight(m_platformData.cgFont()), unitsPerEm) * pointSize; + } else + xHeight = verticalRightOrientationFontData()->fontMetrics().xHeight(); m_fontMetrics.setUnitsPerEm(unitsPerEm); m_fontMetrics.setAscent(ascent); @@ -474,17 +457,8 @@ void SimpleFontData::determinePitch() FloatRect SimpleFontData::platformBoundsForGlyph(Glyph glyph) const { FloatRect boundingBox; -#ifndef BUILDING_ON_TIGER - boundingBox = CTFontGetBoundingRectsForGlyphs(m_platformData.ctFont(), - orientation() == Vertical ? kCTFontVerticalOrientation : kCTFontHorizontalOrientation, &glyph, 0, 1); + boundingBox = CTFontGetBoundingRectsForGlyphs(m_platformData.ctFont(), platformData().orientation() == Vertical ? kCTFontVerticalOrientation : kCTFontHorizontalOrientation, &glyph, 0, 1); boundingBox.setY(-boundingBox.maxY()); -#else - // FIXME: Custom fonts don't have NSFonts, so this function doesn't compute correct bounds for these on Tiger. - if (!m_platformData.font()) - return boundingBox; - boundingBox = [m_platformData.font() boundingRectForGlyph:glyph]; - boundingBox.setY(-boundingBox.maxY()); -#endif if (m_syntheticBoldOffset) boundingBox.setWidth(boundingBox.width() + m_syntheticBoldOffset); @@ -494,7 +468,7 @@ FloatRect SimpleFontData::platformBoundsForGlyph(Glyph glyph) const float SimpleFontData::platformWidthForGlyph(Glyph glyph) const { CGSize advance; - if (orientation() == Horizontal || m_isBrokenIdeographFont) { + if (platformData().orientation() == Horizontal || m_isBrokenIdeographFallback) { NSFont* font = platformData().font(); float pointSize = platformData().m_size; CGAffineTransform m = CGAffineTransformMakeScale(pointSize, pointSize); -- cgit v1.1