Changeset 76442 in webkit


Ignore:
Timestamp:
Jan 22, 2011 3:46:23 AM (13 years ago)
Author:
Nikolas Zimmermann
Message:

2011-01-21 Nikolas Zimmermann <nzimmermann@rim.com>

Reviewed by Dirk Schulze.

Introduce FontMetrics abstraction
https://bugs.webkit.org/show_bug.cgi?id=51456

  • src/ExternalPopupMenu.cpp: Use FontMetrics instead of Font to access the metrics. (WebKit::ExternalPopupMenu::getPopupMenuInfo):
  • src/WebFontImpl.cpp: Ditto. (WebKit::WebFontImpl::ascent): (WebKit::WebFontImpl::descent): (WebKit::WebFontImpl::height): (WebKit::WebFontImpl::lineSpacing): (WebKit::WebFontImpl::xHeight):

2011-01-21 Nikolas Zimmermann <nzimmermann@rim.com>

Reviewed by Dirk Schulze.

Introduce FontMetrics abstraction
https://bugs.webkit.org/show_bug.cgi?id=51456

  • FullscreenVideoController.cpp: Use FontMetrics instead of Font to access the metrics. (FullscreenVideoController::draw):
  • WebCoreSupport/WebDragClient.cpp: Ditto. (WebDragClient::createDragImageForLink):
  • WebKitGraphics.cpp: Ditto. (FontMetrics):

2011-01-21 Nikolas Zimmermann <nzimmermann@rim.com>

Reviewed by Dirk Schulze.

Introduce FontMetrics abstraction
https://bugs.webkit.org/show_bug.cgi?id=51456

Encapsulate ascent/descent/lineHeight/lineGap methods in a single FontMetrics class, instead of
having to define them in both Font & SimpleFontData. Changed to store floating point values
as default, in order to get accurate information for small sized fonts. All these methods
now have floating-point and integer versions. Whenever an integer variant of these functions
is called, lroundf() is used to round the value.

This makes it possible to support small font-sizes for SVG in a follow-up patch, as well
as fixing rounding issues when using SVG Fonts.


Shouldn't affect existing tests.

  • GNUmakefile.am: Add FontMetrics.h to build.
  • WebCore.gypi: Ditto.
  • WebCore.pro: Ditto.
  • WebCore.vcproj/WebCore.vcproj: Ditto.
  • WebCore.xcodeproj/project.pbxproj: Ditto.
  • accessibility/gtk/AccessibilityObjectWrapperAtk.cpp: Use style->fontMetrics() instead of style->font() to access the metrics. (baselinePositionForAccessibilityRenderObject):
  • css/CSSPrimitiveValue.cpp: (WebCore::CSSPrimitiveValue::computeLengthDouble):
  • html/canvas/CanvasRenderingContext2D.cpp: Ditto. (WebCore::CanvasRenderingContext2D::drawTextInternal):
  • inspector/InspectorController.cpp: Ditto. (WebCore::InspectorController::drawElementTitle):
  • platform/chromium/PopupMenuChromium.cpp: Ditto. (WebCore::PopupListBox::paintRow): (WebCore::PopupListBox::getRowHeight):
  • platform/graphics/Font.h: Remove ascent/descent/height/lineGap/lineSpacing/xHeight/unitsPerEm accessor... (WebCore::Font::fontMetrics): ... and only expose a single FontMetrics object here.
  • platform/graphics/FontFastPath.cpp: Use fontMetrics() to query metrics information. (WebCore::Font::emphasisMarkAscent): (WebCore::Font::emphasisMarkDescent): (WebCore::Font::emphasisMarkHeight): (WebCore::Font::floatWidthForSimpleText):
  • platform/graphics/FontMetrics.h: Added. (WebCore::FontMetrics::FontMetrics): Creates a FontMetrics object, stored in SimpleFontData. (WebCore::FontMetrics::unitsPerEm): Returns an unsigned describing the unitsPerEm. (WebCore::FontMetrics::setUnitsPerEm): Sets the unitsPerEm value. (WebCore::FontMetrics::floatAscent): Returns the stored m_ascent float. (WebCore::FontMetrics::setAscent): Sets the stored m_ascent float. (WebCore::FontMetrics::floatDescent): Returns the stored m_descent float. (WebCore::FontMetrics::setDescent): Sets the stored m_descent float. (WebCore::FontMetrics::floatHeight): Returns floatAscent() + floatDescent(). (WebCore::FontMetrics::floatLineGap): Returns the stored m_lineGap float. (WebCore::FontMetrics::setLineGap): Sets the stored m_lineGap float. (WebCore::FontMetrics::floatLineSpacing): Returns the stored m_lineSpacing float. (WebCore::FontMetrics::setLineSpacing): Sets the stored m_lineSpacing float. (WebCore::FontMetrics::xHeight): Returns the stored m_xHeight float (no integer version available, hence no 'float' prefix). (WebCore::FontMetrics::setXHeight): Sets the stored m_xHeight float. (WebCore::FontMetrics::ascent): Returns a rounded version of ascent(). (WebCore::FontMetrics::descent): Ditto (for descent). (WebCore::FontMetrics::height): Returns ascent() + descent(). (WebCore::FontMetrics::lineGap): Returns a rounded version of lineGap(). (WebCore::FontMetrics::lineSpacing): Ditto (for lineSpacing). (WebCore::FontMetrics::reset): Nulls all members, used only by the platform variants of SimpleFontData.
  • platform/graphics/SimpleFontData.cpp: Adapt SVG Fonts code, to initialize the FontMetrics object, as the m_ascent/etc.. members are gone. (WebCore::SimpleFontData::SimpleFontData): (WebCore::SimpleFontData::initCharWidths):
  • platform/graphics/SimpleFontData.h: Remove ascent/descent/height/lineSpacing/lineGap/xHeight/unitsPerEm accessors, and members, just store a FontMetrics object and expose it. (WebCore::SimpleFontData::fontMetrics): (WebCore::SimpleFontData::avgCharWidth):
  • platform/graphics/chromium/FontChromiumWin.cpp: Use fontMetrics() to query font metrics. (WebCore::TransparencyAwareFontPainter::TransparencyAwareGlyphPainter::estimateTextBounds): (WebCore::TransparencyAwareFontPainter::TransparencyAwareGlyphPainter::drawGlyphs): (WebCore::TransparencyAwareFontPainter::TransparencyAwareUniscribePainter::estimateTextBounds): (WebCore::Font::drawComplexText):
  • platform/graphics/chromium/SimpleFontDataChromiumWin.cpp: Adapt platform code, to initialize the FontMetrics object. (WebCore::SimpleFontData::platformInit):
  • platform/graphics/chromium/SimpleFontDataLinux.cpp: Ditto. (WebCore::SimpleFontData::platformInit):
  • platform/graphics/chromium/UniscribeHelperTextRun.cpp: Use fontMetrics() to query font metrics. (WebCore::UniscribeHelperTextRun::UniscribeHelperTextRun): (WebCore::UniscribeHelperTextRun::nextWinFontData):
  • platform/graphics/freetype/SimpleFontDataFreeType.cpp: Adapt platform code, to initialize the FontMetrics object. (WebCore::SimpleFontData::platformInit):
  • platform/graphics/haiku/SimpleFontDataHaiku.cpp: Ditto. (WebCore::SimpleFontData::platformInit):
  • platform/graphics/mac/FontComplexTextMac.cpp: Use fontMetrics() to query font metrics. (WebCore::Font::floatWidthForComplexText):
  • platform/graphics/mac/FontMac.mm: Ditto. (WebCore::showGlyphsWithAdvances):
  • platform/graphics/mac/SimpleFontDataMac.mm: Adapt platform code, to initialize the FontMetrics object. (WebCore::SimpleFontData::platformInit): (WebCore::SimpleFontData::platformCharWidthInit):
  • platform/graphics/pango/SimpleFontDataPango.cpp: Ditto. (WebCore::SimpleFontData::platformInit):
  • platform/graphics/qt/SimpleFontDataQt.cpp: Ditto. (+ Switch to QFontMetricsF to get floating-point accurancy.) (WebCore::SimpleFontData::platformInit):
  • platform/graphics/win/FontCGWin.cpp: Use fontMetrics() to query font metrics. (WebCore::drawGDIGlyphs):
  • platform/graphics/win/FontWin.cpp: Ditto. (WebCore::Font::floatWidthForComplexText):
  • platform/graphics/win/SimpleFontDataCGWin.cpp: Adapt platform code, to initialize the FontMetrics object. (WebCore::SimpleFontData::platformInit): (WebCore::SimpleFontData::platformBoundsForGlyph):
  • platform/graphics/win/SimpleFontDataCairoWin.cpp: Ditto. (WebCore::SimpleFontData::platformInit):
  • platform/graphics/win/SimpleFontDataWin.cpp: Ditto. (WebCore::SimpleFontData::initGDIFont):
  • platform/graphics/wince/GraphicsContextWinCE.cpp: Use fontMetrics() to query font metrics. (WebCore::GraphicsContext::drawText):
  • platform/graphics/wince/SimpleFontDataWinCE.cpp: Adapt platform code, to initialize the FontMetrics object. (WebCore::SimpleFontData::platformInit):
  • platform/graphics/wx/SimpleFontDataWx.cpp: Ditto. (WebCore::SimpleFontData::platformInit):
  • platform/win/PopupMenuWin.cpp: Use style->fontMetrics() instead of style->font() to access the metrics. (WebCore::PopupMenuWin::calculatePositionAndSize): (WebCore::PopupMenuWin::paint):
  • rendering/EllipsisBox.cpp: Ditto. (WebCore::EllipsisBox::paint): (WebCore::EllipsisBox::nodeAtPoint):
  • rendering/InlineBox.cpp: Ditto. (WebCore::InlineBox::logicalHeight):
  • rendering/InlineFlowBox.cpp: Ditto. (WebCore::verticalPositionForBox): (WebCore::InlineFlowBox::computeLogicalBoxHeights): (WebCore::InlineFlowBox::placeBoxesInBlockDirection):
  • rendering/InlineTextBox.cpp: Ditto. (WebCore::InlineTextBox::paint): (WebCore::InlineTextBox::paintDecoration): (WebCore::InlineTextBox::paintSpellingOrGrammarMarker): (WebCore::InlineTextBox::paintCompositionUnderline):
  • rendering/RenderBlock.cpp: Ditto. (WebCore::RenderBlock::baselinePosition): (WebCore::RenderBlock::firstLineBoxBaseline): (WebCore::RenderBlock::lastLineBoxBaseline):
  • rendering/RenderBox.cpp: Ditto. (WebCore::RenderBox::localCaretRect):
  • rendering/RenderEmbeddedObject.cpp: Ditto. (WebCore::RenderEmbeddedObject::paintReplaced):
  • rendering/RenderImage.cpp: Ditto. (WebCore::RenderImage::setImageSizeForAltText): (WebCore::RenderImage::paintReplaced):
  • rendering/RenderInline.cpp: Ditto. (WebCore::RenderInline::baselinePosition):
  • rendering/RenderListBox.cpp: Ditto. (WebCore::RenderListBox::paintItemForeground): (WebCore::RenderListBox::itemHeight):
  • rendering/RenderListMarker.cpp: Ditto. (WebCore::RenderListMarker::paint): (WebCore::RenderListMarker::layout): (WebCore::RenderListMarker::computePreferredLogicalWidths): (WebCore::RenderListMarker::updateMargins): (WebCore::RenderListMarker::getRelativeMarkerRect):
  • rendering/RenderTextControl.cpp: Ditto. (WebCore::RenderTextControl::paintPlaceholder):
  • rendering/RenderTextControlSingleLine.cpp: Ditto. (WebCore::RenderTextControlSingleLine::createInnerTextStyle):
  • rendering/RenderThemeWin.cpp: Ditto. (WebCore::RenderThemeWin::adjustMenuListButtonStyle):
  • rendering/mathml/RenderMathMLFraction.cpp: Ditto. (WebCore::RenderMathMLFraction::baselinePosition):
  • rendering/style/RenderStyle.h: Add "const FontMetrics& fontMetrics() const" accessor. (WebCore::InheritedFlags::fontMetrics): (WebCore::InheritedFlags::computedLineHeight):
  • rendering/svg/RenderSVGInlineText.cpp: Use style->fontMetrics() instead of style->font() to access the metrics. (WebCore::RenderSVGInlineText::positionForPoint):
  • rendering/svg/SVGInlineTextBox.cpp: Ditto. (WebCore::SVGInlineTextBox::selectionRectForTextFragment): (WebCore::positionOffsetForDecoration): (WebCore::SVGInlineTextBox::paintDecorationWithStyle): (WebCore::SVGInlineTextBox::paintTextWithShadows): (WebCore::SVGInlineTextBox::calculateBoundaries):
  • rendering/svg/SVGTextLayoutEngineBaseline.cpp: Ditto. (WebCore::SVGTextLayoutEngineBaseline::calculateBaselineShift): (WebCore::SVGTextLayoutEngineBaseline::calculateAlignmentBaselineShift): (WebCore::SVGTextLayoutEngineBaseline::calculateGlyphAdvanceAndOrientation):
  • rendering/svg/SVGTextLayoutEngineSpacing.cpp: Ditto. (WebCore::SVGTextLayoutEngineSpacing::calculateSVGKerning):
  • rendering/svg/SVGTextMetrics.cpp: Ditto. (WebCore::SVGTextMetrics::SVGTextMetrics):
  • rendering/svg/SVGTextQuery.cpp: Ditto. (WebCore::calculateGlyphBoundaries):
  • svg/SVGFontFaceElement.cpp: (WebCore::SVGFontFaceElement::unitsPerEm): Rename defaultUnitsPerEm global to gDefaultUnitsPerEm.
  • svg/SVGLength.cpp: Use style->fontMetrics() instead of style->font() to access the metrics. (WebCore::SVGLength::convertValueFromUserUnitsToEXS): (WebCore::SVGLength::convertValueFromEXSToUserUnits):

2011-01-21 Nikolas Zimmermann <nzimmermann@rim.com>

Reviewed by Dirk Schulze.

Introduce FontMetrics abstraction
https://bugs.webkit.org/show_bug.cgi?id=51456

  • WebProcess/WebCoreSupport/win/WebPopupMenuWin.cpp: Use FontMetrics instead of Font to access the metrics. (WebKit::WebPopupMenu::setUpPlatformData):
Location:
trunk/Source
Files:
1 added
68 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r76438 r76442  
     12011-01-21  Nikolas Zimmermann  <nzimmermann@rim.com>
     2
     3        Reviewed by Dirk Schulze.
     4
     5        Introduce FontMetrics abstraction
     6        https://bugs.webkit.org/show_bug.cgi?id=51456
     7
     8        Encapsulate ascent/descent/lineHeight/lineGap methods in a single FontMetrics class, instead of
     9        having to define them in both Font & SimpleFontData. Changed to store floating point values
     10        as default, in order to get accurate information for small sized fonts. All these methods
     11        now have floating-point and integer versions. Whenever an integer variant of these functions
     12        is called, lroundf() is used to round the value.
     13
     14        This makes it possible to support small font-sizes for SVG in a follow-up patch, as well
     15        as fixing rounding issues when using SVG Fonts.
     16       
     17        Shouldn't affect existing tests.
     18
     19        * GNUmakefile.am: Add FontMetrics.h to build.
     20        * WebCore.gypi: Ditto.
     21        * WebCore.pro: Ditto.
     22        * WebCore.vcproj/WebCore.vcproj: Ditto.
     23        * WebCore.xcodeproj/project.pbxproj: Ditto.
     24        * accessibility/gtk/AccessibilityObjectWrapperAtk.cpp: Use style->fontMetrics() instead of style->font() to access the metrics.
     25        (baselinePositionForAccessibilityRenderObject):
     26        * css/CSSPrimitiveValue.cpp:         
     27        (WebCore::CSSPrimitiveValue::computeLengthDouble):
     28        * html/canvas/CanvasRenderingContext2D.cpp: Ditto.
     29        (WebCore::CanvasRenderingContext2D::drawTextInternal):
     30        * inspector/InspectorController.cpp: Ditto.
     31        (WebCore::InspectorController::drawElementTitle):
     32        * platform/chromium/PopupMenuChromium.cpp: Ditto.
     33        (WebCore::PopupListBox::paintRow):
     34        (WebCore::PopupListBox::getRowHeight):
     35        * platform/graphics/Font.h: Remove ascent/descent/height/lineGap/lineSpacing/xHeight/unitsPerEm accessor...
     36        (WebCore::Font::fontMetrics): ... and only expose a single FontMetrics object here.
     37        * platform/graphics/FontFastPath.cpp: Use fontMetrics() to query metrics information.
     38        (WebCore::Font::emphasisMarkAscent):
     39        (WebCore::Font::emphasisMarkDescent):
     40        (WebCore::Font::emphasisMarkHeight):
     41        (WebCore::Font::floatWidthForSimpleText):
     42        * platform/graphics/FontMetrics.h: Added.
     43        (WebCore::FontMetrics::FontMetrics): Creates a FontMetrics object, stored in SimpleFontData.
     44        (WebCore::FontMetrics::unitsPerEm): Returns an unsigned describing the unitsPerEm.
     45        (WebCore::FontMetrics::setUnitsPerEm): Sets the unitsPerEm value.
     46        (WebCore::FontMetrics::floatAscent): Returns the stored m_ascent float.
     47        (WebCore::FontMetrics::setAscent): Sets the stored m_ascent float.
     48        (WebCore::FontMetrics::floatDescent): Returns the stored m_descent float.
     49        (WebCore::FontMetrics::setDescent): Sets the stored m_descent float.
     50        (WebCore::FontMetrics::floatHeight): Returns floatAscent() + floatDescent().
     51        (WebCore::FontMetrics::floatLineGap): Returns the stored m_lineGap float.
     52        (WebCore::FontMetrics::setLineGap): Sets the stored m_lineGap float.
     53        (WebCore::FontMetrics::floatLineSpacing): Returns the stored m_lineSpacing float.
     54        (WebCore::FontMetrics::setLineSpacing): Sets the stored m_lineSpacing float.
     55        (WebCore::FontMetrics::xHeight): Returns the stored m_xHeight float (no integer version available, hence no 'float' prefix).
     56        (WebCore::FontMetrics::setXHeight): Sets the stored m_xHeight float.
     57        (WebCore::FontMetrics::ascent): Returns a rounded version of ascent().
     58        (WebCore::FontMetrics::descent): Ditto (for descent).
     59        (WebCore::FontMetrics::height): Returns ascent() + descent().
     60        (WebCore::FontMetrics::lineGap): Returns a rounded version of lineGap().
     61        (WebCore::FontMetrics::lineSpacing): Ditto (for lineSpacing).
     62        (WebCore::FontMetrics::reset): Nulls all members, used only by the platform variants of SimpleFontData.
     63        * platform/graphics/SimpleFontData.cpp: Adapt SVG Fonts code, to initialize the FontMetrics object, as the m_ascent/etc.. members are gone.
     64        (WebCore::SimpleFontData::SimpleFontData):
     65        (WebCore::SimpleFontData::initCharWidths):
     66        * platform/graphics/SimpleFontData.h: Remove ascent/descent/height/lineSpacing/lineGap/xHeight/unitsPerEm accessors, and members, just store a FontMetrics object and expose it.
     67        (WebCore::SimpleFontData::fontMetrics):
     68        (WebCore::SimpleFontData::avgCharWidth):
     69        * platform/graphics/chromium/FontChromiumWin.cpp: Use fontMetrics() to query font metrics.
     70        (WebCore::TransparencyAwareFontPainter::TransparencyAwareGlyphPainter::estimateTextBounds):
     71        (WebCore::TransparencyAwareFontPainter::TransparencyAwareGlyphPainter::drawGlyphs):
     72        (WebCore::TransparencyAwareFontPainter::TransparencyAwareUniscribePainter::estimateTextBounds):
     73        (WebCore::Font::drawComplexText):
     74        * platform/graphics/chromium/SimpleFontDataChromiumWin.cpp: Adapt platform code, to initialize the FontMetrics object.
     75        (WebCore::SimpleFontData::platformInit):
     76        * platform/graphics/chromium/SimpleFontDataLinux.cpp: Ditto.
     77        (WebCore::SimpleFontData::platformInit):
     78        * platform/graphics/chromium/UniscribeHelperTextRun.cpp: Use fontMetrics() to query font metrics.
     79        (WebCore::UniscribeHelperTextRun::UniscribeHelperTextRun):
     80        (WebCore::UniscribeHelperTextRun::nextWinFontData):
     81        * platform/graphics/freetype/SimpleFontDataFreeType.cpp: Adapt platform code, to initialize the FontMetrics object.
     82        (WebCore::SimpleFontData::platformInit):
     83        * platform/graphics/haiku/SimpleFontDataHaiku.cpp: Ditto.
     84        (WebCore::SimpleFontData::platformInit):
     85        * platform/graphics/mac/FontComplexTextMac.cpp: Use fontMetrics() to query font metrics.
     86        (WebCore::Font::floatWidthForComplexText):
     87        * platform/graphics/mac/FontMac.mm: Ditto.
     88        (WebCore::showGlyphsWithAdvances):
     89        * platform/graphics/mac/SimpleFontDataMac.mm: Adapt platform code, to initialize the FontMetrics object.
     90        (WebCore::SimpleFontData::platformInit):
     91        (WebCore::SimpleFontData::platformCharWidthInit):
     92        * platform/graphics/pango/SimpleFontDataPango.cpp: Ditto.
     93        (WebCore::SimpleFontData::platformInit):
     94        * platform/graphics/qt/SimpleFontDataQt.cpp: Ditto. (+ Switch to QFontMetricsF to get floating-point accurancy.)
     95        (WebCore::SimpleFontData::platformInit):
     96        * platform/graphics/win/FontCGWin.cpp: Use fontMetrics() to query font metrics.
     97        (WebCore::drawGDIGlyphs):
     98        * platform/graphics/win/FontWin.cpp: Ditto.
     99        (WebCore::Font::floatWidthForComplexText):
     100        * platform/graphics/win/SimpleFontDataCGWin.cpp: Adapt platform code, to initialize the FontMetrics object.
     101        (WebCore::SimpleFontData::platformInit):
     102        (WebCore::SimpleFontData::platformBoundsForGlyph):
     103        * platform/graphics/win/SimpleFontDataCairoWin.cpp: Ditto.
     104        (WebCore::SimpleFontData::platformInit):
     105        * platform/graphics/win/SimpleFontDataWin.cpp: Ditto.
     106        (WebCore::SimpleFontData::initGDIFont):
     107        * platform/graphics/wince/GraphicsContextWinCE.cpp: Use fontMetrics() to query font metrics.
     108        (WebCore::GraphicsContext::drawText):
     109        * platform/graphics/wince/SimpleFontDataWinCE.cpp: Adapt platform code, to initialize the FontMetrics object.
     110        (WebCore::SimpleFontData::platformInit):
     111        * platform/graphics/wx/SimpleFontDataWx.cpp: Ditto.
     112        (WebCore::SimpleFontData::platformInit):
     113        * platform/win/PopupMenuWin.cpp: Use style->fontMetrics() instead of style->font() to access the metrics.
     114        (WebCore::PopupMenuWin::calculatePositionAndSize):
     115        (WebCore::PopupMenuWin::paint):
     116        * rendering/EllipsisBox.cpp: Ditto.
     117        (WebCore::EllipsisBox::paint):
     118        (WebCore::EllipsisBox::nodeAtPoint):
     119        * rendering/InlineBox.cpp: Ditto.
     120        (WebCore::InlineBox::logicalHeight):
     121        * rendering/InlineFlowBox.cpp: Ditto.
     122        (WebCore::verticalPositionForBox):
     123        (WebCore::InlineFlowBox::computeLogicalBoxHeights):
     124        (WebCore::InlineFlowBox::placeBoxesInBlockDirection):
     125        * rendering/InlineTextBox.cpp: Ditto.
     126        (WebCore::InlineTextBox::paint):
     127        (WebCore::InlineTextBox::paintDecoration):
     128        (WebCore::InlineTextBox::paintSpellingOrGrammarMarker):
     129        (WebCore::InlineTextBox::paintCompositionUnderline):
     130        * rendering/RenderBlock.cpp: Ditto.
     131        (WebCore::RenderBlock::baselinePosition):
     132        (WebCore::RenderBlock::firstLineBoxBaseline):
     133        (WebCore::RenderBlock::lastLineBoxBaseline):
     134        * rendering/RenderBox.cpp: Ditto.
     135        (WebCore::RenderBox::localCaretRect):
     136        * rendering/RenderEmbeddedObject.cpp: Ditto.
     137        (WebCore::RenderEmbeddedObject::paintReplaced):
     138        * rendering/RenderImage.cpp: Ditto.
     139        (WebCore::RenderImage::setImageSizeForAltText):
     140        (WebCore::RenderImage::paintReplaced):
     141        * rendering/RenderInline.cpp: Ditto.
     142        (WebCore::RenderInline::baselinePosition):
     143        * rendering/RenderListBox.cpp: Ditto.
     144        (WebCore::RenderListBox::paintItemForeground):
     145        (WebCore::RenderListBox::itemHeight):
     146        * rendering/RenderListMarker.cpp: Ditto.
     147        (WebCore::RenderListMarker::paint):
     148        (WebCore::RenderListMarker::layout):
     149        (WebCore::RenderListMarker::computePreferredLogicalWidths):
     150        (WebCore::RenderListMarker::updateMargins):
     151        (WebCore::RenderListMarker::getRelativeMarkerRect):
     152        * rendering/RenderTextControl.cpp: Ditto.
     153        (WebCore::RenderTextControl::paintPlaceholder):
     154        * rendering/RenderTextControlSingleLine.cpp: Ditto.
     155        (WebCore::RenderTextControlSingleLine::createInnerTextStyle):
     156        * rendering/RenderThemeWin.cpp: Ditto.
     157        (WebCore::RenderThemeWin::adjustMenuListButtonStyle):
     158        * rendering/mathml/RenderMathMLFraction.cpp: Ditto.
     159        (WebCore::RenderMathMLFraction::baselinePosition):
     160        * rendering/style/RenderStyle.h: Add "const FontMetrics& fontMetrics() const" accessor.
     161        (WebCore::InheritedFlags::fontMetrics):
     162        (WebCore::InheritedFlags::computedLineHeight):
     163        * rendering/svg/RenderSVGInlineText.cpp: Use style->fontMetrics() instead of style->font() to access the metrics.
     164        (WebCore::RenderSVGInlineText::positionForPoint):
     165        * rendering/svg/SVGInlineTextBox.cpp: Ditto.
     166        (WebCore::SVGInlineTextBox::selectionRectForTextFragment):
     167        (WebCore::positionOffsetForDecoration):
     168        (WebCore::SVGInlineTextBox::paintDecorationWithStyle):
     169        (WebCore::SVGInlineTextBox::paintTextWithShadows):
     170        (WebCore::SVGInlineTextBox::calculateBoundaries):
     171        * rendering/svg/SVGTextLayoutEngineBaseline.cpp: Ditto.
     172        (WebCore::SVGTextLayoutEngineBaseline::calculateBaselineShift):
     173        (WebCore::SVGTextLayoutEngineBaseline::calculateAlignmentBaselineShift):
     174        (WebCore::SVGTextLayoutEngineBaseline::calculateGlyphAdvanceAndOrientation):
     175        * rendering/svg/SVGTextLayoutEngineSpacing.cpp: Ditto.
     176        (WebCore::SVGTextLayoutEngineSpacing::calculateSVGKerning):
     177        * rendering/svg/SVGTextMetrics.cpp: Ditto.
     178        (WebCore::SVGTextMetrics::SVGTextMetrics):
     179        * rendering/svg/SVGTextQuery.cpp: Ditto.
     180        (WebCore::calculateGlyphBoundaries):
     181        * svg/SVGFontFaceElement.cpp:
     182        (WebCore::SVGFontFaceElement::unitsPerEm): Rename defaultUnitsPerEm global to gDefaultUnitsPerEm.
     183        * svg/SVGLength.cpp: Use style->fontMetrics() instead of style->font() to access the metrics.
     184        (WebCore::SVGLength::convertValueFromUserUnitsToEXS):
     185        (WebCore::SVGLength::convertValueFromEXSToUserUnits):
     186
    11872011-01-22  Ryosuke Niwa  <rniwa@webkit.org>
    2188
  • trunk/Source/WebCore/GNUmakefile.am

    r76378 r76442  
    24032403        Source/WebCore/platform/graphics/FontFastPath.cpp \
    24042404        Source/WebCore/platform/graphics/Font.h \
     2405        Source/WebCore/platform/graphics/FontMetrics.h \
    24052406        Source/WebCore/platform/graphics/FontOrientation.h \
    24062407        Source/WebCore/platform/graphics/FontRenderingMode.h \
  • trunk/Source/WebCore/WebCore.gypi

    r76397 r76442  
    29082908            'platform/graphics/FontFamily.h',
    29092909            'platform/graphics/FontFastPath.cpp',
     2910            'platform/graphics/FontMetrics.h',
    29102911            'platform/graphics/FontRenderingMode.h',
    29112912            'platform/graphics/FontSelector.h',
  • trunk/Source/WebCore/WebCore.pro

    r76378 r76442  
    21182118    platform/graphics/FontDescription.h \
    21192119    platform/graphics/FontFamily.h \
     2120    platform/graphics/FontMetrics.h \
    21202121    platform/graphics/Font.h \
    21212122    platform/graphics/GeneratedImage.h \
  • trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj

    r76378 r76442  
    2655026550                                </File>
    2655126551                                <File
     26552                                        RelativePath="..\platform\graphics\FontMetrics.h"
     26553                                        >
     26554                                </File>
     26555                                <File
    2655226556                                        RelativePath="..\platform\graphics\FontRenderingMode.h"
    2655326557                                        >
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r76378 r76442  
    103103                083DAEA80F01A7FB00342754 /* RenderTextControlSingleLine.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 083DAEA40F01A7FB00342754 /* RenderTextControlSingleLine.cpp */; };
    104104                083DAEA90F01A7FB00342754 /* RenderTextControlSingleLine.h in Headers */ = {isa = PBXBuildFile; fileRef = 083DAEA50F01A7FB00342754 /* RenderTextControlSingleLine.h */; };
     105                0845680812B90DA600960A9F /* FontMetrics.h in Headers */ = {isa = PBXBuildFile; fileRef = 0845680712B90DA600960A9F /* FontMetrics.h */; settings = {ATTRIBUTES = (Private, ); }; };
    105106                084A0829128D7867002DB1F1 /* SVGPathSegListPropertyTearOff.h in Headers */ = {isa = PBXBuildFile; fileRef = 084A0828128D7867002DB1F1 /* SVGPathSegListPropertyTearOff.h */; };
    106107                084AEBE40FB505FA0038483E /* SelectElement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 084AEBE20FB505FA0038483E /* SelectElement.cpp */; };
     
    64176418                083DAEA40F01A7FB00342754 /* RenderTextControlSingleLine.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RenderTextControlSingleLine.cpp; sourceTree = "<group>"; };
    64186419                083DAEA50F01A7FB00342754 /* RenderTextControlSingleLine.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RenderTextControlSingleLine.h; sourceTree = "<group>"; };
     6420                0845680712B90DA600960A9F /* FontMetrics.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FontMetrics.h; sourceTree = "<group>"; };
    64196421                084A0828128D7867002DB1F1 /* SVGPathSegListPropertyTearOff.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SVGPathSegListPropertyTearOff.h; sourceTree = "<group>"; };
    64206422                084AEBE20FB505FA0038483E /* SelectElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SelectElement.cpp; sourceTree = "<group>"; };
     
    1746017462                                B2C3DA590D006CD600EF6F26 /* FontFamily.h */,
    1746117463                                72626E010EF022FE00A07E20 /* FontFastPath.cpp */,
     17464                                0845680712B90DA600960A9F /* FontMetrics.h */,
    1746217465                                F7A034C3126BF6BE007DC19E /* FontOrientation.h */,
    1746317466                                37ACCE410DA2980F0089E602 /* FontRenderingMode.h */,
     
    2063120634                                B2C3DA6A0D006CD600EF6F26 /* FontFamily.h in Headers */,
    2063220635                                A80E6CF30A1989CA007FB8C5 /* FontFamilyValue.h in Headers */,
     20636                                0845680812B90DA600960A9F /* FontMetrics.h in Headers */,
    2063320637                                F7A034C4126BF6BE007DC19E /* FontOrientation.h in Headers */,
    2063420638                                B5320D6B122A24E9002D1440 /* FontPlatformData.h in Headers */,
  • trunk/Source/WebCore/accessibility/gtk/AccessibilityObjectWrapperAtk.cpp

    r75250 r76442  
    12311231    // removed in r70072. The implementation looks incorrect though, because this is not the
    12321232    // baseline of the underlying RenderObject, but of the AccessibilityRenderObject.
    1233     const Font& f = renderObject->firstLineStyle()->font();
    1234     return f.ascent() + (renderObject->firstLineStyle()->computedLineHeight() - f.height()) / 2;
     1233    const FontMetrics& fontMetrics = renderObject->firstLineStyle()->fontMetrics();
     1234    return fontMetrics.ascent() + (renderObject->firstLineStyle()->computedLineHeight() - fontMetrics.height()) / 2;
    12351235}
    12361236
  • trunk/Source/WebCore/css/CSSPrimitiveValue.cpp

    r72205 r76442  
    401401            // our actual constructed rendering font.
    402402            applyZoomMultiplier = false;
    403             factor = style->font().xHeight();
     403            factor = style->fontMetrics().xHeight();
    404404            break;
    405405        case CSS_REMS:
  • trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp

    r76235 r76442  
    17611761
    17621762    const Font& font = accessFont();
    1763    
     1763    const FontMetrics& fontMetrics = font.fontMetrics();
     1764
    17641765    // FIXME: Handle maxWidth.
    17651766    // FIXME: Need to turn off font smoothing.
     
    17781779    case TopTextBaseline:
    17791780    case HangingTextBaseline:
    1780         location.setY(y + font.ascent());
     1781        location.setY(y + fontMetrics.ascent());
    17811782        break;
    17821783    case BottomTextBaseline:
    17831784    case IdeographicTextBaseline:
    1784         location.setY(y - font.descent());
     1785        location.setY(y - fontMetrics.descent());
    17851786        break;
    17861787    case MiddleTextBaseline:
    1787         location.setY(y - font.descent() + font.height() / 2);
     1788        location.setY(y - fontMetrics.descent() + fontMetrics.height() / 2);
    17881789        break;
    17891790    case AlphabeticTextBaseline:
     
    18131814
    18141815    // The slop built in to this mask rect matches the heuristic used in FontCGWin.cpp for GDI text.
    1815     FloatRect textRect = FloatRect(location.x() - font.height() / 2, location.y() - font.ascent() - font.lineGap(),
    1816                                    width + font.height(), font.lineSpacing());
     1816    FloatRect textRect = FloatRect(location.x() - fontMetrics.height() / 2, location.y() - fontMetrics.ascent() - fontMetrics.lineGap(),
     1817                                   width + fontMetrics.height(), fontMetrics.lineSpacing());
    18171818    if (!fill)
    18181819        textRect.inflate(c->strokeThickness() / 2);
  • trunk/Source/WebCore/inspector/InspectorController.cpp

    r76392 r76442  
    13461346    context.drawRect(titleRect);
    13471347    context.setFillColor(tooltipFontColor, ColorSpaceDeviceRGB);
    1348     context.drawText(font, nodeTitleRun, IntPoint(titleRect.x() + rectInflatePx, titleRect.y() + font.height()));
     1348    context.drawText(font, nodeTitleRun, IntPoint(titleRect.x() + rectInflatePx, titleRect.y() + font.fontMetrics().height()));
    13491349}
    13501350
  • trunk/Source/WebCore/platform/chromium/PopupMenuChromium.cpp

    r76170 r76442  
    981981
    982982    // Draw the item text.
    983     int textY = rowRect.y() + itemFont.ascent() + (rowRect.height() - itemFont.height()) / 2;
     983    int textY = rowRect.y() + itemFont.fontMetrics().ascent() + (rowRect.height() - itemFont.fontMetrics().height()) / 2;
    984984    gc->drawBidiText(itemFont, textRun, IntPoint(textX, textY));
    985985
     
    11211121    RefPtr<Image> image(Image::loadPlatformResource(icon.utf8().data()));
    11221122
    1123     int fontHeight = getRowFont(index).height();
     1123    int fontHeight = getRowFont(index).fontMetrics().height();
    11241124    int iconHeight = (image && !image->isNull()) ? image->rect().height() : 0;
    11251125
  • trunk/Source/WebCore/platform/graphics/Font.h

    r76170 r76442  
    4444class FloatRect;
    4545class FontData;
    46 class FontFallbackList;
     46class FontMetrics;
    4747class FontPlatformData;
    4848class FontSelector;
     
    5454
    5555struct GlyphData;
    56 
    57 const unsigned defaultUnitsPerEm = 1000;
    5856
    5957struct GlyphOverflow {
     
    129127
    130128    // Metrics that we query the FontFallbackList for.
    131     int ascent(FontBaseline baselineType = AlphabeticBaseline) const { return primaryFont()->ascent(baselineType); }
    132     int descent(FontBaseline baselineType = AlphabeticBaseline) const { return primaryFont()->descent(baselineType); }
    133     int height() const { return ascent() + descent(); }
    134     int lineSpacing() const { return primaryFont()->lineSpacing(); }
    135     int lineGap() const { return primaryFont()->lineGap(); }
    136     float xHeight() const { return primaryFont()->xHeight(); }
    137     unsigned unitsPerEm() const { return primaryFont()->unitsPerEm(); }
     129    const FontMetrics& fontMetrics() const { return primaryFont()->fontMetrics(); }
    138130    int spaceWidth() const { return (int)ceilf(primaryFont()->adjustedSpaceWidth() + m_letterSpacing); }
    139131    float tabWidth(const SimpleFontData& fontData) const { return 8 * ceilf(fontData.adjustedSpaceWidth() + letterSpacing()); }
  • trunk/Source/WebCore/platform/graphics/FontFastPath.cpp

    r76170 r76442  
    253253        return 0;
    254254
    255     return markFontData->ascent();
     255    return markFontData->fontMetrics().ascent();
    256256}
    257257
     
    267267        return 0;
    268268
    269     return markFontData->descent();
     269    return markFontData->fontMetrics().descent();
    270270}
    271271
     
    281281        return 0;
    282282
    283     return markFontData->height();
     283    return markFontData->fontMetrics().height();
    284284}
    285285
     
    415415
    416416    if (glyphOverflow) {
    417         glyphOverflow->top = max<int>(glyphOverflow->top, ceilf(-it.minGlyphBoundingBoxY()) - ascent());
    418         glyphOverflow->bottom = max<int>(glyphOverflow->bottom, ceilf(it.maxGlyphBoundingBoxY()) - descent());
     417        glyphOverflow->top = max<int>(glyphOverflow->top, ceilf(-it.minGlyphBoundingBoxY()) - fontMetrics().ascent());
     418        glyphOverflow->bottom = max<int>(glyphOverflow->bottom, ceilf(it.maxGlyphBoundingBoxY()) - fontMetrics().descent());
    419419        glyphOverflow->left = ceilf(it.firstGlyphOverflow());
    420420        glyphOverflow->right = ceilf(it.lastGlyphOverflow());
  • trunk/Source/WebCore/platform/graphics/SimpleFontData.cpp

    r74169 r76442  
    5151    : m_maxCharWidth(-1)
    5252    , m_avgCharWidth(-1)
    53     , m_unitsPerEm(defaultUnitsPerEm)
    5453    , m_orientation(platformData.orientation())
    5554    , m_platformData(platformData)
     
    7574{
    7675    SVGFontFaceElement* svgFontFaceElement = m_svgFontData->svgFontFaceElement();
    77     m_unitsPerEm = svgFontFaceElement->unitsPerEm();
    78 
    79     double scale = size;
    80     if (m_unitsPerEm)
    81         scale /= m_unitsPerEm;
    82 
    83     m_ascent = static_cast<int>(svgFontFaceElement->ascent() * scale);
    84     m_descent = static_cast<int>(svgFontFaceElement->descent() * scale);
    85     m_xHeight = static_cast<int>(svgFontFaceElement->xHeight() * scale);
    86     m_lineGap = 0.1f * size;
    87     m_lineSpacing = m_ascent + m_descent + m_lineGap;
     76    unsigned unitsPerEm = svgFontFaceElement->unitsPerEm();
     77
     78    float scale = size;
     79    if (unitsPerEm)
     80        scale /= unitsPerEm;
     81
     82    // FIXME: Use floating-point metrics, now that they're exposed!
     83    int xHeight = static_cast<int>(svgFontFaceElement->xHeight() * scale);
     84    int ascent = static_cast<int>(svgFontFaceElement->ascent() * scale);
     85    int descent = static_cast<int>(svgFontFaceElement->descent() * scale);
     86    int lineGap = static_cast<int>(0.1f * size);
     87    m_fontMetrics.setUnitsPerEm(unitsPerEm);
     88    m_fontMetrics.setAscent(ascent);
     89    m_fontMetrics.setDescent(descent);
     90    m_fontMetrics.setLineGap(lineGap);
     91    m_fontMetrics.setXHeight(xHeight);
    8892
    8993    SVGFontElement* associatedFontElement = svgFontFaceElement->associatedFontElement();
     
    9195    Vector<SVGGlyphIdentifier> spaceGlyphs;
    9296    associatedFontElement->getGlyphIdentifiersForString(String(" ", 1), spaceGlyphs);
    93     m_spaceWidth = spaceGlyphs.isEmpty() ? m_xHeight : static_cast<float>(spaceGlyphs.first().horizontalAdvanceX * scale);
     97    m_spaceWidth = spaceGlyphs.isEmpty() ? xHeight : static_cast<float>(spaceGlyphs.first().horizontalAdvanceX * scale);
    9498
    9599    Vector<SVGGlyphIdentifier> numeralZeroGlyphs;
     
    99103    Vector<SVGGlyphIdentifier> letterWGlyphs;
    100104    associatedFontElement->getGlyphIdentifiersForString(String("W", 1), letterWGlyphs);
    101     m_maxCharWidth = letterWGlyphs.isEmpty() ? m_ascent : static_cast<float>(letterWGlyphs.first().horizontalAdvanceX * scale);
     105    m_maxCharWidth = letterWGlyphs.isEmpty() ? ascent : static_cast<float>(letterWGlyphs.first().horizontalAdvanceX * scale);
    102106
    103107    // FIXME: is there a way we can get the space glyph from the SVGGlyphIdentifier above?
     
    127131    // If we can't retrieve the width of a '0', fall back to the x height.
    128132    if (m_avgCharWidth <= 0.f)
    129         m_avgCharWidth = m_xHeight;
    130 
     133        m_avgCharWidth = m_fontMetrics.xHeight();
     134
     135    // FIXME: Use floating-point metrics, now that they're exposed!
    131136    if (m_maxCharWidth <= 0.f)
    132         m_maxCharWidth = max<float>(m_avgCharWidth, m_ascent);
     137        m_maxCharWidth = max<float>(m_avgCharWidth, m_fontMetrics.ascent());
    133138}
    134139
  • trunk/Source/WebCore/platform/graphics/SimpleFontData.h

    r74169 r76442  
    2727#include "FontBaseline.h"
    2828#include "FontData.h"
     29#include "FontMetrics.h"
    2930#include "FontPlatformData.h"
    3031#include "FloatRect.h"
     
    102103    // a broken ideographic font, then just hard-code to split ascent/descent down the middle.  Otherwise we should actually use the metrics
    103104    // from the font itself.
    104     int ascent(FontBaseline baselineType = AlphabeticBaseline) const { return baselineType == AlphabeticBaseline ? m_ascent : height() - height() / 2; }
    105     int descent(FontBaseline baselineType = AlphabeticBaseline) const { return baselineType == AlphabeticBaseline ? m_descent : height() / 2; }
    106     int height() const { return m_ascent + m_descent; }
    107     int lineSpacing() const { return m_lineSpacing; }
    108     int lineGap() const { return m_lineGap; }
     105    const FontMetrics& fontMetrics() const { return m_fontMetrics; }
    109106    float maxCharWidth() const { return m_maxCharWidth; }
    110107    float avgCharWidth() const { return m_avgCharWidth; }
    111     float xHeight() const { return m_xHeight; }
    112     unsigned unitsPerEm() const { return m_unitsPerEm; }
    113108
    114109    FloatRect boundsForGlyph(Glyph) const;
     
    212207#endif
    213208
    214     int m_ascent;
    215     int m_descent;
    216     int m_lineSpacing;
    217     int m_lineGap;
     209    FontMetrics m_fontMetrics;
    218210    float m_maxCharWidth;
    219211    float m_avgCharWidth;
    220     float m_xHeight;
    221     unsigned m_unitsPerEm;
    222212   
    223213    FontOrientation m_orientation; // This is our supported orientation according to the tables in the font.  FontPlatformData will just always have the desired orientation.
  • trunk/Source/WebCore/platform/graphics/chromium/FontChromiumWin.cpp

    r76340 r76442  
    247247        totalWidth += lroundf(m_glyphBuffer.advanceAt(m_from + i));
    248248
    249     return IntRect(m_point.x() - (m_font->ascent() + m_font->descent()) / 2,
    250                    m_point.y() - m_font->ascent() - m_font->lineGap(),
    251                    totalWidth + m_font->ascent() + m_font->descent(),
    252                    m_font->lineSpacing());
     249    const FontMetrics& fontMetrics = m_font->fontMetrics();
     250    return IntRect(m_point.x() - (fontMetrics.ascent() + fontMetrics.descent()) / 2,
     251                   m_point.y() - fontMetrics.ascent() - fontMetrics.lineGap(),
     252                   totalWidth + fontMetrics.ascent() + fontMetrics.descent(),
     253                   fontMetrics.lineSpacing());
    253254}
    254255
     
    271272    // to subtract off the font ascent to get it.
    272273    int x = lroundf(m_point.x() + startAdvance);
    273     int y = lroundf(m_point.y() - m_font->ascent());
     274    int y = lroundf(m_point.y() - m_font->fontMetrics().ascent());
    274275
    275276    // If there is a non-blur shadow and both the fill color and shadow color
     
    355356    // go outside the selection rect) is based roughly on
    356357    // TransparencyAwareGlyphPainter::estimateTextBounds above.
    357     return IntRect(left - (m_font->ascent() + m_font->descent()) / 2,
    358                    m_point.y() - m_font->ascent() - m_font->lineGap(),
    359                    (right - left) + m_font->ascent() + m_font->descent(),
    360                    m_font->lineSpacing());
     358    const FontMetrics& fontMetrics = m_font->fontMetrics();
     359    return IntRect(left - (fontMetrics.ascent() + fontMetrics.descent()) / 2,
     360                   m_point.y() - fontMetrics.ascent() - fontMetrics.lineGap(),
     361                   (right - left) + fontMetrics.ascent() + fontMetrics.descent(),
     362                   fontMetrics.lineSpacing());
    361363}
    362364
     
    497499        SetTextColor(hdc, textColor);
    498500        state.draw(graphicsContext, hdc, static_cast<int>(point.x()) + shadowOffset.width(),
    499                    static_cast<int>(point.y() - ascent()) + shadowOffset.height(), from, to);
     501                   static_cast<int>(point.y() - fontMetrics().ascent()) + shadowOffset.height(), from, to);
    500502        SetTextColor(hdc, savedTextColor);
    501503    }
     
    504506    // the baseline, so we have to subtract off the ascent.
    505507    state.draw(graphicsContext, hdc, static_cast<int>(point.x()),
    506                static_cast<int>(point.y() - ascent()), from, to);
     508               static_cast<int>(point.y() - fontMetrics().ascent()), from, to);
    507509
    508510    context->canvas()->endPlatformPaint();
  • trunk/Source/WebCore/platform/graphics/chromium/SimpleFontDataChromiumWin.cpp

    r76340 r76442  
    5555{
    5656    if (!m_platformData.size()) {
    57         m_ascent = 0;
    58         m_descent = 0;
    59         m_lineGap = 0;
    60         m_lineSpacing = 0;
     57        m_fontMetrics.reset();
    6158        m_avgCharWidth = 0;
    6259        m_maxCharWidth = 0;
    63         m_xHeight = 0;
    64         m_unitsPerEm = 0;
    6560        return;
    6661    }
     
    8378    m_maxCharWidth = textMetric.tmMaxCharWidth;
    8479
    85     m_ascent = textMetric.tmAscent;
    86     m_descent = textMetric.tmDescent;
    87     m_lineGap = textMetric.tmExternalLeading;
    88     m_xHeight = m_ascent * 0.56f;  // Best guess for xHeight for non-Truetype fonts.
     80    // FIXME: Access ascent/descent/lineGap with floating point precision.
     81    float ascent = textMetric.tmAscent;
     82    float descent = textMetric.tmDescent;
     83    float lineGap = textMetric.tmExternalLeading;
     84    float xHeight = ascent * 0.56f; // Best guess for xHeight for non-Truetype fonts.
    8985
    9086    OUTLINETEXTMETRIC outlineTextMetric;
     
    9591        DWORD len = GetGlyphOutlineW(dc, 'x', GGO_METRICS, &glyphMetrics, 0, 0, &identityMatrix);
    9692        if (len != GDI_ERROR && glyphMetrics.gmBlackBoxY > 0)
    97             m_xHeight = static_cast<float>(glyphMetrics.gmBlackBoxY);
    98     }
    99 
    100     m_lineSpacing = m_ascent + m_descent + m_lineGap;
     93            xHeight = static_cast<float>(glyphMetrics.gmBlackBoxY);
     94    }
     95
     96    m_fontMetrics.setAscent(ascent);
     97    m_fontMetrics.setDescent(descent);
     98    m_fontMetrics.setLineGap(lineGap);
     99    m_fontMetrics.setXHeight(xHeight);
    101100
    102101    SelectObject(dc, oldFont);
  • trunk/Source/WebCore/platform/graphics/chromium/SimpleFontDataLinux.cpp

    r74232 r76442  
    5656{
    5757    if (!m_platformData.size()) {
    58         m_ascent = 0;
    59         m_descent = 0;
    60         m_lineGap = 0;
    61         m_lineSpacing = 0;
     58        m_fontMetrics.reset();
    6259        m_avgCharWidth = 0;
    6360        m_maxCharWidth = 0;
    64         m_xHeight = 0;
    65         m_unitsPerEm = 0;
    6661        return;
    6762    }
     
    8984    }
    9085
     86    float ascent;
     87    float descent;
     88
    9189    // Beware those who step here: This code is designed to match Win32 font
    9290    // metrics *exactly*.
    9391    if (isVDMXValid) {
    94         m_ascent = vdmxAscent;
    95         m_descent = -vdmxDescent;
     92        // FIXME: Access ascent/descent with floating point precision.
     93        ascent = vdmxAscent;
     94        descent = -vdmxDescent;
    9695    } else {
    9796        SkScalar height = -metrics.fAscent + metrics.fDescent + metrics.fLeading;
    98         m_ascent = SkScalarRound(-metrics.fAscent);
    99         m_descent = SkScalarRound(height) - m_ascent;
    100     }
    101 
     97        ascent = SkScalarToFloat(-metrics.fAscent);
     98        descent = SkScalarToFloat(height) - ascent;
     99    }
     100
     101    m_fontMetrics.setAscent(ascent);
     102    m_fontMetrics.setDescent(descent);
     103
     104    float xHeight;
    102105    if (metrics.fXHeight)
    103         m_xHeight = metrics.fXHeight;
     106        xHeight = metrics.fXHeight;
    104107    else {
    105108        // hack taken from the Windows port
    106         m_xHeight = static_cast<float>(m_ascent) * 0.56;
    107     }
    108 
    109     m_lineGap = SkScalarRound(metrics.fLeading);
    110     m_lineSpacing = m_ascent + m_descent + m_lineGap;
     109        xHeight = ascent * 0.56f;
     110    }
     111
     112    m_fontMetrics.setLineGap(SkScalarToFloat(metrics.fLeading));
     113    m_fontMetrics.setXHeight(xHeight);
    111114
    112115    if (m_orientation == Vertical) {
     
    129132        m_avgCharWidth = SkScalarRound(metrics.fAvgCharWidth);
    130133    else {
    131         m_avgCharWidth = m_xHeight;
     134        m_avgCharWidth = xHeight;
    132135
    133136        GlyphPage* glyphPageZero = GlyphPageTreeNode::getRootChild(this, 0)->page();
  • trunk/Source/WebCore/platform/graphics/chromium/UniscribeHelperTextRun.cpp

    r76340 r76442  
    5252    setSpaceWidth(font.spaceWidth());
    5353    setWordSpacing(font.wordSpacing());
    54     setAscent(font.primaryFont()->ascent());
     54    setAscent(font.fontMetrics()->ascent());
    5555
    5656    init();
     
    122122        m_scriptCaches.append(simpleFontData->platformData().scriptCache());
    123123        m_fontProperties.append(simpleFontData->platformData().scriptFontProperties());
    124         m_ascents.append(simpleFontData->ascent());
     124        m_ascents.append(simpleFontData->fontMetrics().ascent());
    125125    }
    126126
  • trunk/Source/WebCore/platform/graphics/freetype/SimpleFontDataFreeType.cpp

    r74169 r76442  
    5151    cairo_text_extents_t text_extents;
    5252    cairo_scaled_font_extents(m_platformData.scaledFont(), &font_extents);
    53     m_ascent = static_cast<int>(lroundf(font_extents.ascent));
    54     m_descent = static_cast<int>(lroundf(font_extents.descent));
    55     m_lineSpacing = static_cast<int>(lroundf(font_extents.height));
     53
     54    m_fontMetrics.setAscent(font_extents.ascent);
     55    m_fontMetrics.setDescent(font_extents.descent);
     56
    5657    // There seems to be some rounding error in cairo (or in how we
    5758    // use cairo) with some fonts, like DejaVu Sans Mono, which makes
     
    5960    // wrong and confuses WebCore's layout system. Workaround this
    6061    // while we figure out what's going on.
    61     if (m_lineSpacing < m_ascent + m_descent)
    62         m_lineSpacing = m_ascent + m_descent;
     62    float lineSpacing = font_extents.height;
     63    if (lineSpacing < font_extents.ascent + font_extents.descent)
     64        lineSpacing = font_extents.ascent + font_extents.descent;
     65    m_fontMetrics.setLineGap(lineSpacing - font_extents.ascent - font_extents.descent);
     66
    6367    cairo_scaled_font_text_extents(m_platformData.scaledFont(), "x", &text_extents);
    64     m_xHeight = text_extents.height;
     68    m_fontMetrics.setXHeight(text_extents.height);
     69
    6570    cairo_scaled_font_text_extents(m_platformData.scaledFont(), " ", &text_extents);
    6671    m_spaceWidth = static_cast<float>(text_extents.x_advance);
    67     m_lineGap = m_lineSpacing - m_ascent - m_descent;
     72   
    6873    m_syntheticBoldOffset = m_platformData.syntheticBold() ? 1.0f : 0.f;
    6974}
  • trunk/Source/WebCore/platform/graphics/haiku/SimpleFontDataHaiku.cpp

    r74169 r76442  
    4949    font_height height;
    5050    font->GetHeight(&height);
    51     m_ascent = static_cast<int>(height.ascent);
    52     m_descent = static_cast<int>(height.descent);
    53     m_lineSpacing = m_ascent + m_descent;
    54     m_xHeight = height.ascent * 0.56f; // Hack taken from the win port.
    55     m_lineGap = height.leading;
     51    m_fontMetrics.setAscent(height.ascent);
     52    m_fontMetrics.setDescent(height.descent);
     53    m_fontMetrics.setXHeight(height.ascent * 0.56f); // Hack taken from the win port.
     54    m_fontMetrics.setLineGap(height.leading);
    5655}
    5756
  • trunk/Source/WebCore/platform/graphics/mac/FontComplexTextMac.cpp

    r76170 r76442  
    112112    ComplexTextController controller(this, run, true, fallbackFonts);
    113113    if (glyphOverflow) {
    114         glyphOverflow->top = max<int>(glyphOverflow->top, ceilf(-controller.minGlyphBoundingBoxY()) - ascent());
    115         glyphOverflow->bottom = max<int>(glyphOverflow->bottom, ceilf(controller.maxGlyphBoundingBoxY()) - descent());
     114        glyphOverflow->top = max<int>(glyphOverflow->top, ceilf(-controller.minGlyphBoundingBoxY()) - fontMetrics().ascent());
     115        glyphOverflow->bottom = max<int>(glyphOverflow->bottom, ceilf(controller.maxGlyphBoundingBoxY()) - fontMetrics().descent());
    116116        glyphOverflow->left = max<int>(0, ceilf(-controller.minGlyphBoundingBoxX()));
    117117        glyphOverflow->right = max<int>(0, ceilf(controller.maxGlyphBoundingBoxX() - controller.totalWidth()));
  • trunk/Source/WebCore/platform/graphics/mac/FontMac.mm

    r74532 r76442  
    6161            CGAffineTransform runMatrix = CGAffineTransformConcat(savedMatrix, rotateLeftTransform);
    6262            // Move start point to put glyphs into original region.
    63             runMatrix.tx = savedMatrix.tx + font->ascent();
    64             runMatrix.ty = savedMatrix.ty + font->descent();
     63            runMatrix.tx = savedMatrix.tx + font->fontMetrics().ascent();
     64            runMatrix.ty = savedMatrix.ty + font->fontMetrics().descent();
    6565            CGContextSetTextMatrix(context, runMatrix);
    6666        }
  • trunk/Source/WebCore/platform/graphics/mac/SimpleFontDataMac.mm

    r74178 r76442  
    219219    int iDescent;
    220220    int iLineGap;
     221    unsigned unitsPerEm;
    221222#ifdef BUILDING_ON_TIGER
    222     wkGetFontMetrics(m_platformData.cgFont(), &iAscent, &iDescent, &iLineGap, &m_unitsPerEm);
     223    wkGetFontMetrics(m_platformData.cgFont(), &iAscent, &iDescent, &iLineGap, &unitsPerEm);
    223224#else
    224225    iAscent = CGFontGetAscent(m_platformData.cgFont());
    225226    iDescent = CGFontGetDescent(m_platformData.cgFont());
    226227    iLineGap = CGFontGetLeading(m_platformData.cgFont());
    227     m_unitsPerEm = CGFontGetUnitsPerEm(m_platformData.cgFont());
     228    unitsPerEm = CGFontGetUnitsPerEm(m_platformData.cgFont());
    228229#endif
    229230
    230231    float pointSize = m_platformData.m_size;
    231     float fAscent = scaleEmToUnits(iAscent, m_unitsPerEm) * pointSize;
    232     float fDescent = -scaleEmToUnits(iDescent, m_unitsPerEm) * pointSize;
    233     float fLineGap = scaleEmToUnits(iLineGap, m_unitsPerEm) * pointSize;
     232    float ascent = scaleEmToUnits(iAscent, unitsPerEm) * pointSize;
     233    float descent = -scaleEmToUnits(iDescent, unitsPerEm) * pointSize;
     234    float lineGap = scaleEmToUnits(iLineGap, unitsPerEm) * pointSize;
    234235
    235236    // We need to adjust Times, Helvetica, and Courier to closely match the
     
    240241    NSString *familyName = [m_platformData.font() familyName];
    241242    if ([familyName isEqualToString:@"Times"] || [familyName isEqualToString:@"Helvetica"] || [familyName isEqualToString:@"Courier"])
    242         fAscent += floorf(((fAscent + fDescent) * 0.15f) + 0.5f);
     243        ascent += floorf(((ascent + descent) * 0.15f) + 0.5f);
    243244    else if ([familyName isEqualToString:@"Geeza Pro"]) {
    244245        // Geeza Pro has glyphs that draw slightly above the ascent or far below the descent. Adjust
    245246        // those vertical metrics to better match reality, so that diacritics at the bottom of one line
    246247        // do not overlap diacritics at the top of the next line.
    247         fAscent *= 1.08f;
    248         fDescent *= 2.f;
    249     }
    250 
    251     m_ascent = lroundf(fAscent);
    252     m_descent = lroundf(fDescent);
    253     m_lineGap = lroundf(fLineGap);
    254     m_lineSpacing = m_ascent + m_descent + m_lineGap;
    255    
     248        ascent *= 1.08f;
     249        descent *= 2.f;
     250    }
     251
    256252    // Hack Hiragino line metrics to allow room for marked text underlines.
    257253    // <rdar://problem/5386183>
    258     if (m_descent < 3 && m_lineGap >= 3 && [familyName hasPrefix:@"Hiragino"]) {
    259         m_lineGap -= 3 - m_descent;
    260         m_descent = 3;
     254    if (descent < 3 && lineGap >= 3 && [familyName hasPrefix:@"Hiragino"]) {
     255        lineGap -= 3 - descent;
     256        descent = 3;
    261257    }
    262258   
     
    279275    }
    280276
     277    float xHeight;
     278
    281279    // Measure the actual character "x", because AppKit synthesizes X height rather than getting it from the font.
    282280    // Unfortunately, NSFont will round this for us so we don't quite get the right value.
     
    289287        // poorly if we return an accurate height. Classic case is Times 13 point,
    290288        // which has an "x" that is 7x6 pixels.
    291         m_xHeight = static_cast<float>(max(CGRectGetMaxX(xBox), -CGRectGetMinY(xBox)));
     289        xHeight = static_cast<float>(max(CGRectGetMaxX(xBox), -CGRectGetMinY(xBox)));
    292290    } else {
    293291#ifndef BUILDING_ON_TIGER
    294         m_xHeight = static_cast<float>(CGFontGetXHeight(m_platformData.cgFont())) / m_unitsPerEm;
    295 #else
    296         m_xHeight = m_platformData.font() ? [m_platformData.font() xHeight] : 0;
     292        xHeight = static_cast<float>(CGFontGetXHeight(m_platformData.cgFont())) / unitsPerEm;
     293#else
     294        xHeight = m_platformData.font() ? [m_platformData.font() xHeight] : 0;
    297295#endif
    298296        // CGFontGetXHeight() returns a wrong value for "Apple Symbols" font (a float close to 0, but not strictly 0).
    299         // The following code makes a guess for m_xHeight in that case.
     297        // The following code makes a guess for xHeight in that case.
    300298        // The int cast is a workaround for the "almost" zero value returned by CGFontGetXHeight().
    301         if (!static_cast<int>(m_xHeight) && fAscent)
    302             m_xHeight = 2 * fAscent / 3;
    303     }
    304 }
    305    
     299        if (!static_cast<int>(xHeight) && ascent)
     300            xHeight = 2 * ascent / 3;
     301    }
     302
     303    m_fontMetrics.setUnitsPerEm(unitsPerEm);
     304    m_fontMetrics.setAscent(ascent);
     305    m_fontMetrics.setDescent(descent);
     306    m_fontMetrics.setLineGap(lineGap);
     307    m_fontMetrics.setXHeight(xHeight);
     308}
     309
    306310static CFDataRef copyFontTableForTag(FontPlatformData& platformData, FourCharCode tableName)
    307311{
     
    338342        const UInt8* os2 = CFDataGetBytePtr(os2Table.get());
    339343        SInt16 os2AvgCharWidth = os2[2] * 256 + os2[3];
    340         m_avgCharWidth = scaleEmToUnits(os2AvgCharWidth, m_unitsPerEm) * m_platformData.m_size;
     344        m_avgCharWidth = scaleEmToUnits(os2AvgCharWidth, m_fontMetrics.unitsPerEm()) * m_platformData.m_size;
    341345    }
    342346
     
    349353        SInt16 xMax = static_cast<SInt16>(uxMax);
    350354        float diff = static_cast<float>(xMax - xMin);
    351         m_maxCharWidth = scaleEmToUnits(diff, m_unitsPerEm) * m_platformData.m_size;
     355        m_maxCharWidth = scaleEmToUnits(diff, m_fontMetrics.unitsPerEm()) * m_platformData.m_size;
    352356    }
    353357
  • trunk/Source/WebCore/platform/graphics/pango/SimpleFontDataPango.cpp

    r74169 r76442  
    5050    cairo_text_extents_t text_extents;
    5151    cairo_scaled_font_extents(m_platformData.m_scaledFont, &font_extents);
    52     m_ascent = static_cast<int>(lroundf(font_extents.ascent));
    53     m_descent = static_cast<int>(lroundf(font_extents.descent));
    54     m_lineSpacing = static_cast<int>(lroundf(font_extents.height));
     52
     53    m_fontMetrics.setAscent(font_extents.ascent);
     54    m_fontMetrics.setDescent(font_extents.descent);
     55
    5556    // There seems to be some rounding error in cairo (or in how we
    5657    // use cairo) with some fonts, like DejaVu Sans Mono, which makes
     
    5859    // wrong and confuses WebCore's layout system. Workaround this
    5960    // while we figure out what's going on.
    60     if (m_lineSpacing < m_ascent + m_descent)
    61         m_lineSpacing = m_ascent + m_descent;
     61    float lineSpacing = font_extents.height;
     62    if (lineSpacing < font_extents.ascent + font_extents.descent)
     63        lineSpacing = font_extents.ascent + font_extents.descent;
     64    m_fontMetrics.setLineGap(lineSpacing - font_extents.ascent - font_extents.descent);
     65
    6266    cairo_scaled_font_text_extents(m_platformData.m_scaledFont, "x", &text_extents);
    63     m_xHeight = text_extents.height;
     67    m_fontMetrics.setXHeight(text_extents.height);
     68
    6469    cairo_scaled_font_text_extents(m_platformData.m_scaledFont, " ", &text_extents);
    65     m_spaceWidth =  static_cast<float>(text_extents.x_advance);
    66     m_lineGap = m_lineSpacing - m_ascent - m_descent;
     70    m_spaceWidth = static_cast<float>(text_extents.x_advance);
     71   
    6772    m_syntheticBoldOffset = m_platformData.syntheticBold() ? 1.0f : 0.f;
    6873}
  • trunk/Source/WebCore/platform/graphics/qt/SimpleFontDataQt.cpp

    r73341 r76442  
    2525#include "SimpleFontData.h"
    2626
    27 #include <QFontMetrics>
     27#include <QFontMetricsF>
    2828
    2929namespace WebCore {
     
    4242{
    4343    if (!m_platformData.size()) {
    44          m_ascent = 0;
    45          m_descent = 0;
    46          m_lineGap = 0;
    47          m_lineSpacing = 0;
     44         m_fontMetrics.reset();
    4845         m_avgCharWidth = 0;
    4946         m_maxCharWidth = 0;
    50          m_xHeight = 0;
    51          m_unitsPerEm = 0;
    5247         return;
    5348    }
    5449
    55     QFontMetrics fm(m_platformData.font());
    56 
    57     m_ascent = fm.ascent();
    58     m_descent = fm.descent();
    59     m_lineSpacing = fm.lineSpacing();
    60     m_xHeight = fm.xHeight();
     50    QFontMetricsF fm(m_platformData.font());
     51    m_fontMetrics.setAscent(fm.ascent());
     52    m_fontMetrics.setDescent(fm.descent());
     53    m_fontMetrics.setXHeight(fm.xHeight());
     54    m_fontMetrics.setLineGap(fm.leading());
    6155    m_spaceWidth = fm.width(QLatin1Char(' '));
    62     m_lineGap = fm.leading();
    6356}
    6457
  • trunk/Source/WebCore/platform/graphics/win/FontCGWin.cpp

    r74532 r76442  
    168168        // We put slop into this rect, since glyphs can overflow the ascent/descent bounds and the left/right edges.
    169169        // FIXME: Can get glyphs' optical bounds (even from CG) to get this right.
    170         int lineGap = font->lineGap();
    171         textRect = IntRect(point.x() - (font->ascent() + font->descent()) / 2, point.y() - font->ascent() - lineGap, totalWidth + font->ascent() + font->descent(), font->lineSpacing());
     170        const FontMetrics& fontMetrics = font->fontMetrics();
     171        int lineGap = fontMetrics.lineGap();
     172        textRect = IntRect(point.x() - (fontMetrics.ascent() + fontMetrics.descent()) / 2,
     173                           point.y() - fontMetrics.ascent() - lineGap,
     174                           totalWidth + fontMetrics.ascent() + fontMetrics.descent(),
     175                           fontMetrics.lineSpacing());
    172176        bitmap.set(graphicsContext->createWindowsBitmap(textRect.size()));
    173177        memset(bitmap->buffer(), 255, bitmap->bufferLength());
  • trunk/Source/WebCore/platform/graphics/win/FontWin.cpp

    r76170 r76442  
    123123    controller.advance(run.length());
    124124    if (glyphOverflow) {
    125         glyphOverflow->top = max<int>(glyphOverflow->top, ceilf(-controller.minGlyphBoundingBoxY()) - ascent());
    126         glyphOverflow->bottom = max<int>(glyphOverflow->bottom, ceilf(controller.maxGlyphBoundingBoxY()) - descent());
     125        glyphOverflow->top = max<int>(glyphOverflow->top, ceilf(-controller.minGlyphBoundingBoxY()) - fontMetrics().ascent());
     126        glyphOverflow->bottom = max<int>(glyphOverflow->bottom, ceilf(controller.maxGlyphBoundingBoxY()) - fontMetrics().descent());
    127127        glyphOverflow->left = max<int>(0, ceilf(-controller.minGlyphBoundingBoxX()));
    128128        glyphOverflow->right = max<int>(0, ceilf(controller.maxGlyphBoundingBoxX() - controller.runWidthSoFar()));
  • trunk/Source/WebCore/platform/graphics/win/SimpleFontDataCGWin.cpp

    r58192 r76442  
    6565    int iDescent = CGFontGetDescent(font);
    6666    int iLineGap = CGFontGetLeading(font);
    67     m_unitsPerEm = CGFontGetUnitsPerEm(font);
     67    unsigned unitsPerEm = CGFontGetUnitsPerEm(font);
    6868    float pointSize = m_platformData.size();
    69     float fAscent = scaleEmToUnits(iAscent, m_unitsPerEm) * pointSize;
    70     float fDescent = -scaleEmToUnits(iDescent, m_unitsPerEm) * pointSize;
    71     float fLineGap = scaleEmToUnits(iLineGap, m_unitsPerEm) * pointSize;
     69    float fAscent = scaleEmToUnits(iAscent, unitsPerEm) * pointSize;
     70    float fDescent = -scaleEmToUnits(iDescent, unitsPerEm) * pointSize;
     71    float fLineGap = scaleEmToUnits(iLineGap, unitsPerEm) * pointSize;
    7272
    7373    if (!isCustomFont()) {
     
    9494    }
    9595
    96     m_ascent = lroundf(fAscent);
    97     m_descent = lroundf(fDescent);
    98     m_lineGap = lroundf(fLineGap);
    99     m_lineSpacing = m_ascent + m_descent + m_lineGap;
     96    m_fontMetrics.setAscent(fAscent);
     97    m_fontMetrics.setDescent(fDescent);
     98    m_fontMetrics.setLineGap(fLineGap);
    10099
    101100    // Measure the actual character "x", because AppKit synthesizes X height rather than getting it from the font.
     
    110109        // poorly if we return an accurate height. Classic case is Times 13 point,
    111110        // which has an "x" that is 7x6 pixels.
    112         m_xHeight = scaleEmToUnits(max(CGRectGetMaxX(xBox), CGRectGetMaxY(xBox)), m_unitsPerEm) * pointSize;
     111        m_fontMetrics.setXHeight(scaleEmToUnits(max(CGRectGetMaxX(xBox), CGRectGetMaxY(xBox)), unitsPerEm) * pointSize);
    113112    } else {
    114113        int iXHeight = CGFontGetXHeight(font);
    115         m_xHeight = scaleEmToUnits(iXHeight, m_unitsPerEm) * pointSize;
     114        m_fontMetrics.setXHeight(scaleEmToUnits(iXHeight, unitsPerEm) * pointSize);
    116115    }
     116
     117    m_fontMetrics.setUnitsPerEm(unitsPerEm);
    117118}
    118119
     
    134135    CGFontGetGlyphBBoxes(m_platformData.cgFont(), &glyph, 1, &box);
    135136    float pointSize = m_platformData.size();
    136     CGFloat scale = pointSize / unitsPerEm();
     137    CGFloat scale = pointSize / fontMetrics().unitsPerEm();
    137138    FloatRect boundingBox = CGRectApplyAffineTransform(box, CGAffineTransformMakeScale(scale, -scale));
    138139    if (m_syntheticBoldOffset)
  • trunk/Source/WebCore/platform/graphics/win/SimpleFontDataCairoWin.cpp

    r58192 r76442  
    6464    TEXTMETRIC textMetrics;
    6565    GetTextMetrics(hdc, &textMetrics);
    66     m_ascent = lroundf(textMetrics.tmAscent * metricsMultiplier);
    67     m_descent = lroundf(textMetrics.tmDescent * metricsMultiplier);
    68     m_xHeight = m_ascent * 0.56f; // Best guess for xHeight for non-Truetype fonts.
    69     m_lineGap = lroundf(textMetrics.tmExternalLeading * metricsMultiplier);
    70     m_lineSpacing = m_ascent + m_descent + m_lineGap;
    71     m_avgCharWidth = lroundf(textMetrics.tmAveCharWidth * metricsMultiplier);
    72     m_maxCharWidth = lroundf(textMetrics.tmMaxCharWidth * metricsMultiplier);
     66    float ascent = textMetrics.tmAscent * metricsMultiplier;
     67    float descent = textMetrics.tmDescent * metricsMultiplier;
     68    float xHeight = ascent * 0.56f; // Best guess for xHeight for non-Truetype fonts.
     69    float lineGap = textMetrics.tmExternalLeading * metricsMultiplier;
     70    m_fontMetrics.setAscent(ascent);
     71    m_fontMetrics.setDescent(descent);
     72    m_fontMetrics.setLineGap(lineGap);
     73    m_avgCharWidth = textMetrics.tmAveCharWidth * metricsMultiplier;
     74    m_maxCharWidth = textMetrics.tmMaxCharWidth * metricsMultiplier;
    7375
    7476    OUTLINETEXTMETRIC metrics;
     
    7981        DWORD len = GetGlyphOutline(hdc, 'x', GGO_METRICS, &gm, 0, 0, &mat);
    8082        if (len != GDI_ERROR && gm.gmptGlyphOrigin.y > 0)
    81             m_xHeight = gm.gmptGlyphOrigin.y * metricsMultiplier;
     83            xHeight = gm.gmptGlyphOrigin.y * metricsMultiplier;
    8284    }
    8385
     86    m_fontMetrics.setXHeight(xHeight);
    8487    cairo_win32_scaled_font_done_font(scaledFont);
    8588
  • trunk/Source/WebCore/platform/graphics/win/SimpleFontDataWin.cpp

    r74169 r76442  
    6767{
    6868    if (!m_platformData.size()) {
    69         m_ascent = 0;
    70         m_descent = 0;
    71         m_lineGap = 0;
    72         m_lineSpacing = 0;
     69        m_fontMetrics.reset();
    7370        m_avgCharWidth = 0;
    7471        m_maxCharWidth = 0;
    75         m_xHeight = 0;
    76         m_unitsPerEm = 0;
    7772        return;
    7873    }
     
    8378     GetOutlineTextMetrics(hdc, sizeof(metrics), &metrics);
    8479     TEXTMETRIC& textMetrics = metrics.otmTextMetrics;
    85      m_ascent = textMetrics.tmAscent;
    86      m_descent = textMetrics.tmDescent;
    87      m_lineGap = textMetrics.tmExternalLeading;
    88      m_lineSpacing = m_ascent + m_descent + m_lineGap;
     80     float ascent = textMetrics.tmAscent;
     81     float descent = textMetrics.tmDescent;
     82     float lineGap = textMetrics.tmExternalLeading;
     83     m_fontMetrics.setAscent(ascent);
     84     m_fontMetrics.setDescent(descent);
     85     m_fontMetrics.setLineGap(lineGap);
    8986     m_avgCharWidth = textMetrics.tmAveCharWidth;
    9087     m_maxCharWidth = textMetrics.tmMaxCharWidth;
    91      m_xHeight = m_ascent * 0.56f; // Best guess for xHeight if no x glyph is present.
     88     float xHeight = ascent * 0.56f; // Best guess for xHeight if no x glyph is present.
    9289
    9390     GLYPHMETRICS gm;
     
    9592     DWORD len = GetGlyphOutline(hdc, 'x', GGO_METRICS, &gm, 0, 0, &mat);
    9693     if (len != GDI_ERROR && gm.gmptGlyphOrigin.y > 0)
    97          m_xHeight = gm.gmptGlyphOrigin.y;
    98 
    99      m_unitsPerEm = metrics.otmEMSquare;
     94         xHeight = gm.gmptGlyphOrigin.y;
     95
     96     m_fontMetrics.setXHeight(xHeight);
     97     m_fontMetrics.setUnitsPerEm(metrics.otmEMSquare);
    10098
    10199     SelectObject(hdc, oldFont);
  • trunk/Source/WebCore/platform/graphics/wince/GraphicsContextWinCE.cpp

    r76248 r76442  
    15381538
    15391539    FloatRect textRect = font.selectionRectForText(run, point, font.height(), from, to);
    1540     textRect.setY(textRect.y() - font.ascent());
     1540    textRect.setY(textRect.y() - font.fontMetrics().ascent());
    15411541    IntRect trRect = enclosingIntRect(m_data->mapRect(textRect));
    15421542    RECT bmpRect;
     
    15471547            gc.setBitmap(bmp);
    15481548            gc.scale(FloatSize(m_data->m_transform.a(), m_data->m_transform.d()));
    1549             font.drawText(&gc, run, IntPoint(0, font.ascent()), from, to);
     1549            font.drawText(&gc, run, IntPoint(0, font.fontMetrics().ascent()), from, to);
    15501550        }
    15511551        unsigned key1;
     
    15921592        : 0;
    15931593
    1594     FloatPoint startPoint(point.x(), point.y() - fontData->ascent());
     1594    FloatPoint startPoint(point.x(), point.y() - fontData->fontMetrics().ascent());
    15951595    FloatPoint trPoint = m_data->mapPoint(startPoint);
    15961596    int y = stableRound(trPoint.y());
  • trunk/Source/WebCore/platform/graphics/wince/SimpleFontDataWinCE.cpp

    r74169 r76442  
    5252    m_isSystemFont = m_platformData.isSystemFont();
    5353
    54     m_ascent = (tm.tmAscent * m_platformData.size() + 36) / 72;
    55     m_descent = (tm.tmDescent * m_platformData.size() + 36) / 72;
    56     m_lineGap = (tm.tmExternalLeading * m_platformData.size() + 36) / 72;
    57     m_lineSpacing = m_ascent + m_descent + m_lineGap;
    58     m_xHeight = m_ascent * 0.56f;
     54    float ascent = (tm.tmAscent * m_platformData.size() + 36) / 72.0f;
     55    float descent = (tm.tmDescent * m_platformData.size() + 36) / 72.0f;
     56    float lineGap = (tm.tmExternalLeading * m_platformData.size() + 36) / 72.0f;
     57    m_fontMetrics.setAscent(ascent);
     58    m_fontMetrics.setDescent(descent);
     59    m_fontMetrics.setLineGap(lineGap);
     60    m_fontMetrics.setXHeight(ascent * 0.56f);
    5961}
    6062
  • trunk/Source/WebCore/platform/graphics/wx/SimpleFontDataWx.cpp

    r74169 r76442  
    5454    if (font && font->IsOk()) {
    5555        wxFontProperties props = wxFontProperties(font);
    56         m_ascent = props.GetAscent();
    57         m_descent = props.GetDescent();
    58         m_lineSpacing = props.GetLineSpacing();
    59         m_xHeight = props.GetXHeight();
    60         m_unitsPerEm = 1; // FIXME!
    61         m_lineGap = props.GetLineGap();
     56        m_fontMetrics.setAscent(props.GetAscent());
     57        m_fontMetrics.setDescent(props.GetDescent());
     58        m_fontMetrics.setXHeight(props.GetXHeight());
     59        m_fontMetrics.setUnitsPerEm(1); // FIXME!
     60        m_fontMetrics.setLineGap(props.GetLineGap());
    6261    }
    6362
  • trunk/Source/WebCore/platform/win/PopupMenuWin.cpp

    r76378 r76442  
    307307    // First, determine the popup's height
    308308    int itemCount = client()->listSize();
    309     m_itemHeight = client()->menuStyle().font().height() + optionSpacingMiddle;
     309    m_itemHeight = client()->menuStyle().font().fontMetrics().height() + optionSpacingMiddle;
    310310    int naturalHeight = m_itemHeight * itemCount;
    311311    int popupHeight = min(maxPopupHeight, naturalHeight);
     
    650650            if (RenderTheme::defaultTheme()->popupOptionSupportsTextIndent() && itemStyle.textDirection() == LTR)
    651651                textX += itemStyle.textIndent().calcMinValue(itemRect.width());
    652             int textY = itemRect.y() + itemFont.ascent() + (itemRect.height() - itemFont.height()) / 2;
     652            int textY = itemRect.y() + itemFont.fontMetrics().ascent() + (itemRect.height() - itemFont.fontMetrics().height()) / 2;
    653653            context.drawBidiText(itemFont, textRun, IntPoint(textX, textY));
    654654        }
  • trunk/Source/WebCore/rendering/EllipsisBox.cpp

    r76170 r76442  
    5454
    5555    const String& str = m_str;
    56     context->drawText(style->font(), TextRun(str.characters(), str.length(), false, 0, 0, false, style->visuallyOrdered()), IntPoint(m_x + tx, m_y + ty + style->font().ascent()));
     56    context->drawText(style->font(), TextRun(str.characters(), str.length(), false, 0, 0, false, style->visuallyOrdered()), IntPoint(m_x + tx, m_y + ty + style->fontMetrics().ascent()));
    5757
    5858    // Restore the regular fill color.
     
    6666        // Paint the markup box
    6767        tx += m_x + m_logicalWidth - m_markupBox->x();
    68         ty += m_y + style->font().ascent() - (m_markupBox->y() + m_markupBox->renderer()->style(m_firstLine)->font().ascent());
     68        ty += m_y + style->fontMetrics().ascent() - (m_markupBox->y() + m_markupBox->renderer()->style(m_firstLine)->fontMetrics().ascent());
    6969        m_markupBox->paint(paintInfo, tx, ty);
    7070    }
     
    109109        RenderStyle* style = m_renderer->style(m_firstLine);
    110110        int mtx = tx + m_logicalWidth - m_markupBox->x();
    111         int mty = ty + style->font().ascent() - (m_markupBox->y() + m_markupBox->renderer()->style(m_firstLine)->font().ascent());
     111        int mty = ty + style->fontMetrics().ascent() - (m_markupBox->y() + m_markupBox->renderer()->style(m_firstLine)->fontMetrics().ascent());
    112112        if (m_markupBox->nodeAtPoint(request, result, x, y, mtx, mty)) {
    113113            renderer()->updateHitTestResult(result, IntPoint(x - mtx, y - mty));
  • trunk/Source/WebCore/rendering/InlineBox.cpp

    r75837 r76442  
    9595   
    9696    if (renderer()->isText())
    97         return m_isText ? renderer()->style(m_firstLine)->font().height() : 0;
     97        return m_isText ? renderer()->style(m_firstLine)->fontMetrics().height() : 0;
    9898    if (renderer()->isBox() && parent())
    9999        return isHorizontal() ? toRenderBox(m_renderer)->height() : toRenderBox(m_renderer)->width();
     
    101101    ASSERT(isInlineFlowBox());
    102102    RenderBoxModelObject* flowObject = boxModelObject();
    103     const Font& font = renderer()->style(m_firstLine)->font();
    104     int result = font.height();
     103    const FontMetrics& fontMetrics = renderer()->style(m_firstLine)->fontMetrics();
     104    int result = fontMetrics.height();
    105105    if (parent())
    106106        result += flowObject->borderAndPaddingLogicalHeight();
  • trunk/Source/WebCore/rendering/InlineFlowBox.cpp

    r75257 r76442  
    409409        if (verticalAlign != BASELINE) {
    410410            const Font& font = parent->style(firstLine)->font();
     411            const FontMetrics& fontMetrics = font.fontMetrics();
    411412            int fontSize = font.pixelSize();
    412413
     
    418419                verticalPosition -= fontSize / 3 + 1;
    419420            else if (verticalAlign == TEXT_TOP)
    420                 verticalPosition += renderer->baselinePosition(baselineType, firstLine, lineDirection) - font.ascent(baselineType);
     421                verticalPosition += renderer->baselinePosition(baselineType, firstLine, lineDirection) - fontMetrics.ascent(baselineType);
    421422            else if (verticalAlign == MIDDLE)
    422                 verticalPosition += -static_cast<int>(font.xHeight() / 2) - renderer->lineHeight(firstLine, lineDirection) / 2 + renderer->baselinePosition(baselineType, firstLine, lineDirection);
     423                verticalPosition += -static_cast<int>(fontMetrics.xHeight() / 2) - renderer->lineHeight(firstLine, lineDirection) / 2 + renderer->baselinePosition(baselineType, firstLine, lineDirection);
    423424            else if (verticalAlign == TEXT_BOTTOM) {
    424                 verticalPosition += font.descent(baselineType);
     425                verticalPosition += fontMetrics.descent(baselineType);
    425426                // lineHeight - baselinePosition is always 0 for replaced elements (except inline blocks), so don't bother wasting time in that case.
    426427                if (!renderer->isReplaced() || renderer->isInlineBlockOrInlineTable())
     
    504505            int baselineToBottom = 0;
    505506            for (size_t i = 0; i < usedFonts->size(); ++i) {
    506                 int halfLeading = (usedFonts->at(i)->lineSpacing() - usedFonts->at(i)->height()) / 2;
    507                 int usedFontBaseline = halfLeading + usedFonts->at(i)->ascent(baselineType);
    508                 int usedFontBaselineToBottom = usedFonts->at(i)->lineSpacing() - usedFontBaseline;
     507                const FontMetrics& fontMetrics = usedFonts->at(i)->fontMetrics();
     508                int halfLeading = (fontMetrics.lineSpacing() - fontMetrics.height()) / 2;
     509                int usedFontBaseline = halfLeading + fontMetrics.ascent(baselineType);
     510                int usedFontBaselineToBottom = fontMetrics.lineSpacing() - usedFontBaseline;
    509511                if (!baselineSet) {
    510512                    baselineSet = true;
     
    516518                }
    517519                if (!affectsAscent)
    518                     affectsAscent = usedFonts->at(i)->ascent() - curr->logicalTop() > 0;
     520                    affectsAscent = fontMetrics.ascent() - curr->logicalTop() > 0;
    519521                if (!affectsDescent)
    520                     affectsDescent = usedFonts->at(i)->descent() + curr->logicalTop() > 0;
     522                    affectsDescent = fontMetrics.descent() + curr->logicalTop() > 0;
    521523            }
    522524            lineHeight = baseline + baselineToBottom;
     
    528530                // If the top of our font box relative to the root box baseline is above the root box baseline, then
    529531                // we are contributing to the maxAscent value.
    530                 affectsAscent = curr->renderer()->style(m_firstLine)->font().ascent(baselineType) - curr->logicalTop() > 0;
     532                const FontMetrics& fontMetrics = curr->renderer()->style(m_firstLine)->fontMetrics();
     533                affectsAscent = fontMetrics.ascent(baselineType) - curr->logicalTop() > 0;
    531534               
    532535                // Descent is similar.  If any part of our font box is below the root box's baseline, then
    533536                // we contribute to the maxDescent value.
    534                 affectsDescent = curr->renderer()->style(m_firstLine)->font().descent(baselineType) + curr->logicalTop() > 0;
     537                affectsDescent = fontMetrics.descent(baselineType) + curr->logicalTop() > 0;
    535538            } else {
    536539                // Replaced elements always affect both the ascent and descent.
     
    607610           
    608611        if (curr->isText() || curr->isInlineFlowBox()) {
    609             const Font& font = curr->renderer()->style(m_firstLine)->font();
    610             newLogicalTop += curr->baselinePosition(baselineType) - font.ascent(baselineType);
     612            const FontMetrics& fontMetrics = curr->renderer()->style(m_firstLine)->fontMetrics();
     613            newLogicalTop += curr->baselinePosition(baselineType) - fontMetrics.ascent(baselineType);
    611614            if (curr->isInlineFlowBox()) {
    612615                RenderBoxModelObject* boxObject = toRenderBoxModelObject(curr->renderer());
     
    669672
    670673    if (isRootInlineBox()) {
    671         const Font& font = renderer()->style(m_firstLine)->font();
    672         setLogicalTop(logicalTop() + baselinePosition(baselineType) - font.ascent(baselineType));
     674        const FontMetrics& fontMetrics = renderer()->style(m_firstLine)->fontMetrics();
     675        setLogicalTop(logicalTop() + baselinePosition(baselineType) - fontMetrics.ascent(baselineType));
    673676       
    674677        if (hasTextChildren() || strictMode) {
  • trunk/Source/WebCore/rendering/InlineTextBox.cpp

    r76170 r76442  
    486486    boxOrigin.move(tx, ty);   
    487487    IntRect boxRect(boxOrigin, IntSize(logicalWidth(), logicalHeight()));
    488     IntPoint textOrigin = IntPoint(boxOrigin.x(), boxOrigin.y() + styleToUse->font().ascent());
     488    IntPoint textOrigin = IntPoint(boxOrigin.x(), boxOrigin.y() + styleToUse->fontMetrics().ascent());
    489489
    490490    if (!isHorizontal()) {
     
    627627    const AtomicString& emphasisMark = hasTextEmphasis ? styleToUse->textEmphasisMarkString() : nullAtom;
    628628    if (!emphasisMark.isEmpty())
    629         emphasisMarkOffset = emphasisMarkPosition == TextEmphasisPositionOver ? -font.ascent() - font.emphasisMarkDescent(emphasisMark) : font.descent() + font.emphasisMarkAscent(emphasisMark);
     629        emphasisMarkOffset = emphasisMarkPosition == TextEmphasisPositionOver ? -font.fontMetrics().ascent() - font.emphasisMarkDescent(emphasisMark) : font.fontMetrics().descent() + font.emphasisMarkAscent(emphasisMark);
    630630
    631631    if (!paintSelectedTextOnly) {
     
    838838
    839839    RenderStyle* styleToUse = renderer()->style(m_firstLine);
    840     int baseline = styleToUse->font().ascent();
     840    int baseline = styleToUse->fontMetrics().ascent();
    841841
    842842    bool setClip = false;
     
    971971    // we pin to two pixels under the baseline.
    972972    int lineThickness = cMisspellingLineThickness;
    973     int baseline = renderer()->style(m_firstLine)->font().ascent();
     973    int baseline = renderer()->style(m_firstLine)->fontMetrics().ascent();
    974974    int descent = logicalHeight() - baseline;
    975975    int underlineOffset;
     
    11281128    // If there's not enough space the underline will touch or overlap characters.
    11291129    int lineThickness = 1;
    1130     int baseline = renderer()->style(m_firstLine)->font().ascent();
     1130    int baseline = renderer()->style(m_firstLine)->fontMetrics().ascent();
    11311131    if (underline.thick && logicalHeight() - baseline >= 2)
    11321132        lineThickness = 2;
  • trunk/Source/WebCore/rendering/RenderBlock.cpp

    r76438 r76442  
    49594959    }
    49604960
    4961     const Font& f = style(firstLine)->font();
    4962     return f.ascent(baselineType) + (lineHeight(firstLine, direction, linePositionMode) - f.height()) / 2;
     4961    const FontMetrics& fontMetrics = style(firstLine)->fontMetrics();
     4962    return fontMetrics.ascent(baselineType) + (lineHeight(firstLine, direction, linePositionMode) - fontMetrics.height()) / 2;
    49634963}
    49644964
     
    49704970    if (childrenInline()) {
    49714971        if (firstLineBox())
    4972             return firstLineBox()->logicalTop() + style(true)->font().ascent(firstRootBox()->baselineType());
     4972            return firstLineBox()->logicalTop() + style(true)->fontMetrics().ascent(firstRootBox()->baselineType());
    49734973        else
    49744974            return -1;
     
    49964996    if (childrenInline()) {
    49974997        if (!firstLineBox() && hasLineIfEmpty()) {
    4998             const Font& f = firstLineStyle()->font();
    4999             return f.ascent() + (lineHeight(true, lineDirection, PositionOfInteriorLineBoxes) - f.height()) / 2 + (lineDirection == HorizontalLine ? borderTop() + paddingTop() : borderRight() + paddingRight());
     4998            const FontMetrics& fontMetrics = firstLineStyle()->fontMetrics();
     4999            return fontMetrics.ascent()
     5000                 + (lineHeight(true, lineDirection, PositionOfInteriorLineBoxes) - fontMetrics.height()) / 2
     5001                 + (lineDirection == HorizontalLine ? borderTop() + paddingTop() : borderRight() + paddingRight());
    50005002        }
    50015003        if (lastLineBox())
    5002             return lastLineBox()->logicalTop() + style(lastLineBox() == firstLineBox())->font().ascent(lastRootBox()->baselineType());
     5004            return lastLineBox()->logicalTop() + style(lastLineBox() == firstLineBox())->fontMetrics().ascent(lastRootBox()->baselineType());
    50035005        return -1;
    50045006    } else {
     
    50135015        }
    50145016        if (!haveNormalFlowChild && hasLineIfEmpty()) {
    5015             const Font& f = firstLineStyle()->font();
    5016             return f.ascent() + (lineHeight(true, lineDirection, PositionOfInteriorLineBoxes) - f.height()) / 2 + (lineDirection == HorizontalLine ? borderTop() + paddingTop() : borderRight() + paddingRight());
     5017            const FontMetrics& fontMetrics = firstLineStyle()->fontMetrics();
     5018            return fontMetrics.ascent()
     5019                 + (lineHeight(true, lineDirection, PositionOfInteriorLineBoxes) - fontMetrics.height()) / 2
     5020                 + (lineDirection == HorizontalLine ? borderTop() + paddingTop() : borderRight() + paddingRight());
    50175021        }
    50185022    }
  • trunk/Source/WebCore/rendering/RenderBox.cpp

    r76141 r76442  
    29772977    //
    29782978    // FIXME: ignoring :first-line, missing good reason to take care of
    2979     int fontHeight = style()->font().height();
     2979    int fontHeight = style()->fontMetrics().height();
    29802980    if (fontHeight > rect.height() || (!isReplaced() && !isTable()))
    29812981        rect.setHeight(fontHeight);
  • trunk/Source/WebCore/rendering/RenderEmbeddedObject.cpp

    r76170 r76442  
    173173    context->fillPath(path);
    174174
     175    const FontMetrics& fontMetrics = font.fontMetrics();
    175176    float labelX = roundf(replacementTextRect.location().x() + (replacementTextRect.size().width() - textWidth) / 2);
    176     float labelY = roundf(replacementTextRect.location().y() + (replacementTextRect.size().height() - font.height()) / 2 + font.ascent());
     177    float labelY = roundf(replacementTextRect.location().y() + (replacementTextRect.size().height() - fontMetrics.height()) / 2 + fontMetrics.ascent());
    177178    context->setAlpha(m_missingPluginIndicatorIsPressed ? replacementTextPressedTextOpacity : replacementTextTextOpacity);
    178179    context->setFillColor(Color::black, style()->colorSpace());
  • trunk/Source/WebCore/rendering/RenderImage.cpp

    r76170 r76442  
    113113    if (!m_altText.isEmpty()) {
    114114        const Font& font = style()->font();
    115         IntSize textSize(min(font.width(TextRun(m_altText.characters(), m_altText.length())), maxAltTextWidth), min(font.height(), maxAltTextHeight));
     115        IntSize textSize(min(font.width(TextRun(m_altText.characters(), m_altText.length())), maxAltTextWidth), min(font.fontMetrics().height(), maxAltTextHeight));
    116116        imageSize = imageSize.expandedTo(textSize);
    117117    }
     
    290290                int ay = ty + topBorder + topPad;
    291291                const Font& font = style()->font();
    292                 int ascent = font.ascent();
     292                const FontMetrics& fontMetrics = font.fontMetrics();
     293                int ascent = fontMetrics.ascent();
    293294
    294295                // Only draw the alt text if it'll fit within the content box,
     
    297298                int textWidth = font.width(textRun);
    298299                if (errorPictureDrawn) {
    299                     if (usableWidth >= textWidth && font.height() <= imageY)
    300                         context->drawText(style()->font(), textRun, IntPoint(ax, ay + ascent));
    301                 } else if (usableWidth >= textWidth && cHeight >= font.height())
    302                     context->drawText(style()->font(), textRun, IntPoint(ax, ay + ascent));
     300                    if (usableWidth >= textWidth && fontMetrics.height() <= imageY)
     301                        context->drawText(font, textRun, IntPoint(ax, ay + ascent));
     302                } else if (usableWidth >= textWidth && cHeight >= fontMetrics.height())
     303                    context->drawText(font, textRun, IntPoint(ax, ay + ascent));
    303304            }
    304305        }
  • trunk/Source/WebCore/rendering/RenderInline.cpp

    r74775 r76442  
    906906int RenderInline::baselinePosition(FontBaseline baselineType, bool firstLine, LineDirectionMode direction, LinePositionMode linePositionMode) const
    907907{
    908     const Font& f = style(firstLine)->font();
    909     return f.ascent(baselineType) + (lineHeight(firstLine, direction, linePositionMode) - f.height()) / 2;
     908    const FontMetrics& fontMetrics = style(firstLine)->fontMetrics();
     909    return fontMetrics.ascent(baselineType) + (lineHeight(firstLine, direction, linePositionMode) - fontMetrics.height()) / 2;
    910910}
    911911
  • trunk/Source/WebCore/rendering/RenderListBox.cpp

    r76378 r76442  
    304304    // Determine where the item text should be placed
    305305    IntRect r = itemBoundingBoxRect(tx, ty, listIndex);
    306     r.move(optionsSpacingHorizontal, style()->font().ascent());
     306    r.move(optionsSpacingHorizontal, style()->fontMetrics().ascent());
    307307
    308308    RenderStyle* itemStyle = element->renderStyle();
     
    551551int RenderListBox::itemHeight() const
    552552{
    553     return style()->font().height() + rowSpacing;
     553    return style()->fontMetrics().height() + rowSpacing;
    554554}
    555555
  • trunk/Source/WebCore/rendering/RenderListMarker.cpp

    r76170 r76442  
    12661266    }
    12671267
    1268     IntPoint textOrigin = IntPoint(marker.x(), marker.y() + style()->font().ascent());
     1268    IntPoint textOrigin = IntPoint(marker.x(), marker.y() + style()->fontMetrics().ascent());
    12691269
    12701270    if (type == Asterisks || type == Footnotes)
     
    13121312    } else {
    13131313        setLogicalWidth(minPreferredLogicalWidth());
    1314         setLogicalHeight(style()->font().height());
     1314        setLogicalHeight(style()->fontMetrics().height());
    13151315    }
    13161316
     
    13471347
    13481348    const Font& font = style()->font();
     1349    const FontMetrics& fontMetrics = font.fontMetrics();
    13491350
    13501351    if (isImage()) {
    13511352        // FIXME: This is a somewhat arbitrary width.  Generated images for markers really won't become particularly useful
    13521353        // until we support the CSS3 marker pseudoclass to allow control over the width and height of the marker box.
    1353         int bulletWidth = font.ascent() / 2;
     1354        int bulletWidth = fontMetrics.ascent() / 2;
    13541355        m_image->setImageContainerSize(IntSize(bulletWidth, bulletWidth));
    13551356        IntSize imageSize = m_image->imageSize(this, style()->effectiveZoom());
     
    13741375        case Square:
    13751376            m_text = listMarkerText(type, 0); // value is ignored for these types
    1376             logicalWidth = (font.ascent() * 2 / 3 + 1) / 2 + 2;
     1377            logicalWidth = (fontMetrics.ascent() * 2 / 3 + 1) / 2 + 2;
    13771378            break;
    13781379        case Afar:
     
    14731474void RenderListMarker::updateMargins()
    14741475{
    1475     const Font& font = style()->font();
     1476    const FontMetrics& fontMetrics = style()->fontMetrics();
    14761477
    14771478    int marginStart = 0;
     
    14861487            case Square:
    14871488                marginStart = -1;
    1488                 marginEnd = font.ascent() - minPreferredLogicalWidth() + 1;
     1489                marginEnd = fontMetrics.ascent() - minPreferredLogicalWidth() + 1;
    14891490                break;
    14901491            default:
     
    14961497                marginStart = -minPreferredLogicalWidth() - cMarkerPadding;
    14971498            else {
    1498                 int offset = font.ascent() * 2 / 3;
     1499                int offset = fontMetrics.ascent() * 2 / 3;
    14991500                switch (style()->listStyleType()) {
    15001501                    case Disc:
     
    15141515                marginEnd = cMarkerPadding;
    15151516            else {
    1516                 int offset = font.ascent() * 2 / 3;
     1517                int offset = fontMetrics.ascent() * 2 / 3;
    15171518                switch (style()->listStyleType()) {
    15181519                    case Disc:
     
    15851586        case Footnotes: {
    15861587            const Font& font = style()->font();
    1587             relativeRect = IntRect(0, 0, font.width(m_text), font.height());
     1588            relativeRect = IntRect(0, 0, font.width(m_text), font.fontMetrics().height());
    15881589            break;
    15891590        }
     
    15921593        case Square: {
    15931594            // FIXME: Are these particular rounding rules necessary?
    1594             const Font& font = style()->font();
    1595             int ascent = font.ascent();
     1595            const FontMetrics& fontMetrics = style()->fontMetrics();
     1596            int ascent = fontMetrics.ascent();
    15961597            int bulletWidth = (ascent * 2 / 3 + 1) / 2;
    15971598            relativeRect = IntRect(1, 3 * (ascent - ascent * 2 / 3) / 2, bulletWidth, bulletWidth);
     
    16811682            UChar suffixSpace[2] = { listMarkerSuffix(type, m_listItem->value()), ' ' };
    16821683            int suffixSpaceWidth = font.width(TextRun(suffixSpace, 2));
    1683             relativeRect = IntRect(0, 0, itemWidth + suffixSpaceWidth, font.height());
     1684            relativeRect = IntRect(0, 0, itemWidth + suffixSpaceWidth, font.fontMetrics().height());
    16841685    }
    16851686
  • trunk/Source/WebCore/rendering/RenderTextControl.cpp

    r76170 r76442  
    645645    if (textRenderer) {
    646646        IntPoint textPoint;
    647         textPoint.setY(ty + textBlockInsetTop() + placeholderStyle->font().ascent());
     647        textPoint.setY(ty + textBlockInsetTop() + placeholderStyle->fontMetrics().ascent());
    648648        if (placeholderStyle->isLeftToRightDirection())
    649649            textPoint.setX(tx + textBlockInsetLeft());
  • trunk/Source/WebCore/rendering/RenderTextControlSingleLine.cpp

    r76378 r76442  
    709709
    710710    // Do not allow line-height to be smaller than our default.
    711     if (textBlockStyle->font().lineSpacing() > lineHeight(true, HorizontalLine, PositionOfInteriorLineBoxes))
     711    if (textBlockStyle->fontMetrics().lineSpacing() > lineHeight(true, HorizontalLine, PositionOfInteriorLineBoxes))
    712712        textBlockStyle->setLineHeight(Length(-100.0f, Percent));
    713713
  • trunk/Source/WebCore/rendering/RenderThemeWin.cpp

    r68864 r76442  
    770770
    771771    // Calculate our min-height
    772     int minHeight = style->font().height();
     772    int minHeight = style->fontMetrics().height();
    773773    minHeight = max(minHeight, dropDownBoxMinHeight);
    774774
  • trunk/Source/WebCore/rendering/mathml/RenderMathMLFraction.cpp

    r76375 r76442  
    177177        else if (nextSibling())
    178178            refStyle = nextSibling()->style();
    179         int shift = int(ceil((refStyle->font().xHeight() + 1) / 2));
     179        int shift = int(ceil((refStyle->fontMetrics().xHeight() + 1) / 2));
    180180        return numerator->offsetHeight() + shift;
    181181    }
  • trunk/Source/WebCore/rendering/style/RenderStyle.h

    r76083 r76442  
    464464
    465465    const Font& font() const { return inherited->font; }
     466    const FontMetrics& fontMetrics() const { return inherited->font.fontMetrics(); }
    466467    const FontDescription& fontDescription() const { return inherited->font.fontDescription(); }
    467468    int fontSize() const { return inherited->font.pixelSize(); }
     
    488489        // Negative value means the line height is not set.  Use the font's built-in spacing.
    489490        if (lh.isNegative())
    490             return font().lineSpacing();
     491            return fontMetrics().lineSpacing();
    491492
    492493        if (lh.isPercent())
  • trunk/Source/WebCore/rendering/svg/RenderSVGInlineText.cpp

    r75325 r76442  
    162162    RenderStyle* style = this->style();
    163163    ASSERT(style);
    164     int baseline = style->font().ascent();
     164    int baseline = style->fontMetrics().ascent();
    165165
    166166    RenderBlock* containingBlock = this->containingBlock();
  • trunk/Source/WebCore/rendering/svg/SVGInlineTextBox.cpp

    r76170 r76442  
    8585
    8686    const Font& font = style->font();
    87     FloatPoint textOrigin(fragment.x, fragment.y - font.ascent());
     87    FloatPoint textOrigin(fragment.x, fragment.y - font.fontMetrics().ascent());
    8888    return font.selectionRectForText(constructTextRun(style, fragment), textOrigin, fragment.height, startPosition, endPosition);
    8989}
     
    410410}
    411411
    412 static inline float positionOffsetForDecoration(ETextDecoration decoration, const Font& font, float thickness)
     412static inline float positionOffsetForDecoration(ETextDecoration decoration, const FontMetrics& fontMetrics, float thickness)
    413413{
    414414    // FIXME: For SVG Fonts we need to use the attributes defined in the <font-face> if specified.
    415415    // Compatible with Batik/Opera.
    416416    if (decoration == UNDERLINE)
    417         return font.ascent() + thickness * 1.5f;
     417        return fontMetrics.ascent() + thickness * 1.5f;
    418418    if (decoration == OVERLINE)
    419419        return thickness;
    420420    if (decoration == LINE_THROUGH)
    421         return font.ascent() * 5.0f / 8.0f;
     421        return fontMetrics.ascent() * 5.0f / 8.0f;
    422422
    423423    ASSERT_NOT_REACHED();
     
    488488
    489489    const Font& font = decorationStyle->font();
     490    const FontMetrics& fontMetrics = font.fontMetrics();
    490491
    491492    // The initial y value refers to overline position.
     
    495496        return;
    496497
    497     float y = fragment.y - font.ascent() + positionOffsetForDecoration(decoration, font, thickness);
     498    float y = fragment.y - fontMetrics.ascent() + positionOffsetForDecoration(decoration, fontMetrics, thickness);
    498499
    499500    Path path;
     
    514515
    515516    FloatPoint textOrigin(fragment.x, fragment.y);
    516     FloatRect shadowRect(FloatPoint(textOrigin.x(), textOrigin.y() - font.ascent()), FloatSize(fragment.width, fragment.height));
     517    FloatRect shadowRect(FloatPoint(textOrigin.x(), textOrigin.y() - font.fontMetrics().ascent()), FloatSize(fragment.width, fragment.height));
    517518
    518519    do {
     
    588589
    589590    int baseline = baselinePosition(AlphabeticBaseline);
    590     int heightDifference = baseline - style->font().ascent();
     591    int heightDifference = baseline - style->fontMetrics().ascent();
    591592
    592593    unsigned textFragmentsSize = m_textFragments.size();
  • trunk/Source/WebCore/rendering/svg/SVGTextLayoutEngineBaseline.cpp

    r75325 r76442  
    5050        return 0;
    5151    case BS_SUB:
    52         return -m_font.height() / 2;
     52        return -m_font.fontMetrics().height() / 2;
    5353    case BS_SUPER:
    54         return m_font.height() / 2;
     54        return m_font.fontMetrics().height() / 2;
    5555    default:
    5656        ASSERT_NOT_REACHED();
     
    123123    }
    124124
     125    const FontMetrics& fontMetrics = m_font.fontMetrics();
     126
    125127    // Note: http://wiki.apache.org/xmlgraphics-fop/LineLayout/AlignmentHandling
    126128    switch (baseline) {
     
    129131    case AB_BEFORE_EDGE:
    130132    case AB_TEXT_BEFORE_EDGE:
    131         return m_font.ascent();
     133        return fontMetrics.ascent();
    132134    case AB_MIDDLE:
    133         return m_font.xHeight() / 2;
     135        return fontMetrics.xHeight() / 2;
    134136    case AB_CENTRAL:
    135         return (m_font.ascent() - m_font.descent()) / 2;
     137        return (fontMetrics.ascent() - fontMetrics.descent()) / 2;
    136138    case AB_AFTER_EDGE:
    137139    case AB_TEXT_AFTER_EDGE:
    138140    case AB_IDEOGRAPHIC:
    139         return m_font.descent();
     141        return fontMetrics.descent();
    140142    case AB_ALPHABETIC:
    141143        return 0;
    142144    case AB_HANGING:
    143         return m_font.ascent() * 8 / 10.f;
     145        return fontMetrics.ascent() * 8 / 10.f;
    144146    case AB_MATHEMATICAL:
    145         return m_font.ascent() / 2;
     147        return fontMetrics.ascent() / 2;
    146148    default:
    147149        ASSERT_NOT_REACHED();
     
    193195    // 180 degrees, then the current text position is incremented according to the horizontal metrics of the glyph.
    194196
     197    const FontMetrics& fontMetrics = m_font.fontMetrics();
     198
    195199    // Vertical orientation handling.
    196200    if (isVerticalText) {
    197         float ascentMinusDescent = m_font.ascent() - m_font.descent();
     201        float ascentMinusDescent = fontMetrics.ascent() - fontMetrics.descent();
    198202        if (!angle) {
    199203            xOrientationShift = (ascentMinusDescent - metrics.width()) / 2;
    200             yOrientationShift = m_font.ascent();
     204            yOrientationShift = fontMetrics.ascent();
    201205        } else if (angle == 180)
    202206            xOrientationShift = (ascentMinusDescent + metrics.width()) / 2;
     
    218222    else if (angle == 180) {
    219223        xOrientationShift = metrics.width();
    220         yOrientationShift = -m_font.ascent();
     224        yOrientationShift = -fontMetrics.ascent();
    221225    } else if (angle == 270)
    222226        xOrientationShift = metrics.width();
  • trunk/Source/WebCore/rendering/svg/SVGTextLayoutEngineSpacing.cpp

    r68878 r76442  
    5959    m_lastGlyph = currentGlyph;
    6060    m_lastGlyph.isValid = true;
    61     kerning *= m_font.size() / m_font.primaryFont()->unitsPerEm();
     61    kerning *= m_font.size() / m_font.fontMetrics().unitsPerEm();
    6262    return kerning;
    6363#else
  • trunk/Source/WebCore/rendering/svg/SVGTextMetrics.cpp

    r76170 r76442  
    4444
    4545    m_width = font.floatWidth(run, extraCharsAvailable, length, m_glyph.name);
    46     m_height = font.height();
     46    m_height = font.fontMetrics().height();
    4747    m_glyph.unicodeString = String(run.characters(), length);
    4848    m_glyph.isValid = true;
  • trunk/Source/WebCore/rendering/svg/SVGTextQuery.cpp

    r75325 r76442  
    473473static inline void calculateGlyphBoundaries(SVGTextQuery::Data* queryData, const SVGTextFragment& fragment, int startPosition, FloatRect& extent)
    474474{
    475     extent.setLocation(FloatPoint(fragment.x, fragment.y - queryData->textRenderer->style()->font().ascent()));
     475    extent.setLocation(FloatPoint(fragment.x, fragment.y - queryData->textRenderer->style()->fontMetrics().ascent()));
    476476
    477477    if (startPosition) {
  • trunk/Source/WebCore/svg/SVGFontFaceElement.cpp

    r74622 r76442  
    126126    const AtomicString& value = getAttribute(units_per_emAttr);
    127127    if (value.isEmpty())
    128         return defaultUnitsPerEm;
     128        return gDefaultUnitsPerEm;
    129129
    130130    return static_cast<unsigned>(ceilf(value.toFloat()));
  • trunk/Source/WebCore/svg/SVGLength.cpp

    r74788 r76442  
    439439    // Use of ceil allows a pixel match to the W3Cs expected output of coords-units-03-b.svg
    440440    // if this causes problems in real world cases maybe it would be best to remove this
    441     float xHeight = ceilf(style->font().xHeight());
     441    float xHeight = ceilf(style->fontMetrics().xHeight());
    442442    if (!xHeight) {
    443443        ec = NOT_SUPPORTED_ERR;
     
    458458    // Use of ceil allows a pixel match to the W3Cs expected output of coords-units-03-b.svg
    459459    // if this causes problems in real world cases maybe it would be best to remove this
    460     return value * ceilf(style->font().xHeight());
     460    return value * ceilf(style->fontMetrics().xHeight());
    461461}
    462462
  • trunk/Source/WebKit/chromium/ChangeLog

    r76412 r76442  
     12011-01-21  Nikolas Zimmermann  <nzimmermann@rim.com>
     2
     3        Reviewed by Dirk Schulze.
     4
     5        Introduce FontMetrics abstraction
     6        https://bugs.webkit.org/show_bug.cgi?id=51456
     7
     8        * src/ExternalPopupMenu.cpp: Use FontMetrics instead of Font to access the metrics.
     9        (WebKit::ExternalPopupMenu::getPopupMenuInfo):
     10        * src/WebFontImpl.cpp: Ditto.
     11        (WebKit::WebFontImpl::ascent):
     12        (WebKit::WebFontImpl::descent):
     13        (WebKit::WebFontImpl::height):
     14        (WebKit::WebFontImpl::lineSpacing):
     15        (WebKit::WebFontImpl::xHeight):
     16
    1172011-01-21  Chris Rogers  <crogers@google.com>
    218
  • trunk/Source/WebKit/chromium/src/ExternalPopupMenu.cpp

    r72586 r76442  
    143143    }
    144144
    145     info->itemHeight = m_popupMenuClient->menuStyle().font().height();
     145    info->itemHeight = m_popupMenuClient->menuStyle().font().fontMetrics().height();
    146146    info->itemFontSize =
    147147        static_cast<int>(m_popupMenuClient->menuStyle().font().size());
  • trunk/Source/WebKit/chromium/src/WebFontImpl.cpp

    r76170 r76442  
    6565int WebFontImpl::ascent() const
    6666{
    67     return m_font.ascent();
     67    return m_font.fontMetrics().ascent();
    6868}
    6969
    7070int WebFontImpl::descent() const
    7171{
    72     return m_font.descent();
     72    return m_font.fontMetrics().descent();
    7373}
    7474
    7575int WebFontImpl::height() const
    7676{
    77     return m_font.height();
     77    return m_font.fontMetrics().height();
    7878}
    7979
    8080int WebFontImpl::lineSpacing() const
    8181{
    82     return m_font.lineSpacing();
     82    return m_font.fontMetrics().lineSpacing();
    8383}
    8484
    8585float WebFontImpl::xHeight() const
    8686{
    87     return m_font.xHeight();
     87    return m_font.fontMetrics().xHeight();
    8888}
    8989
  • trunk/Source/WebKit/win/ChangeLog

    r76390 r76442  
     12011-01-21  Nikolas Zimmermann  <nzimmermann@rim.com>
     2
     3        Reviewed by Dirk Schulze.
     4
     5        Introduce FontMetrics abstraction
     6        https://bugs.webkit.org/show_bug.cgi?id=51456
     7
     8        * FullscreenVideoController.cpp: Use FontMetrics instead of Font to access the metrics.
     9        (FullscreenVideoController::draw):
     10        * WebCoreSupport/WebDragClient.cpp: Ditto.
     11        (WebDragClient::createDragImageForLink):
     12        * WebKitGraphics.cpp: Ditto.
     13        (FontMetrics):
     14
    1152011-01-21  Chris Rogers  <crogers@google.com>
    216
  • trunk/Source/WebKit/win/FullscreenVideoController.cpp

    r75262 r76442  
    533533    // Left string
    534534    s = timeToString(currentTime());
     535    int fontHeight = font.fontMetrics().height();
    535536    TextRun leftText(s);
    536537    context.setFillColor(Color(textColor), ColorSpaceDeviceRGB);
    537     context.drawText(font, leftText, IntPoint(windowWidth / 2 - timeSliderWidth / 2 - margin - font.width(leftText), windowHeight - margin - sliderHeight / 2 + font.height() / 4));
     538    context.drawText(font, leftText, IntPoint(windowWidth / 2 - timeSliderWidth / 2 - margin - font.width(leftText), windowHeight - margin - sliderHeight / 2 + fontHeight / 4));
    538539
    539540    // Right string
     
    541542    TextRun rightText(s);
    542543    context.setFillColor(Color(textColor), ColorSpaceDeviceRGB);
    543     context.drawText(font, rightText, IntPoint(windowWidth / 2 + timeSliderWidth / 2 + margin, windowHeight - margin - sliderHeight / 2 + font.height() / 4));
     544    context.drawText(font, rightText, IntPoint(windowWidth / 2 + timeSliderWidth / 2 + margin, windowHeight - margin - sliderHeight / 2 + fontHeight / 4));
    544545
    545546    // Copy to the window
  • trunk/Source/WebKit/win/WebCoreSupport/WebDragClient.cpp

    r76170 r76442  
    249249    TextRun labelRun(label.impl());
    250250    TextRun urlRun(urlString.impl());
    251     IntSize labelSize(labelFont->width(labelRun), labelFont->ascent() + labelFont->descent());
     251    IntSize labelSize(labelFont->width(labelRun), labelFont->fontMetrics().ascent() + labelFont->fontMetrics().descent());
    252252
    253253    if (labelSize.width() > MAX_DRAG_LABEL_STRING_WIDTH){
     
    262262    if (drawURLString) {
    263263        urlStringSize.setWidth(urlFont->width(urlRun));
    264         urlStringSize.setHeight(urlFont->ascent() + urlFont->descent());
     264        urlStringSize.setHeight(urlFont->fontMetrics().ascent() + urlFont->fontMetrics().descent());
    265265        imageSize.setHeight(imageSize.height() + urlStringSize.height());
    266266        if (urlStringSize.width() > MAX_DRAG_LABEL_STRING_WIDTH) {
     
    305305        if (clipURLString)
    306306            urlString = StringTruncator::rightTruncate(urlString, imageSize.width() - (DRAG_LABEL_BORDER_X * 2.0f), *urlFont, false);
    307         IntPoint textPos(DRAG_LABEL_BORDER_X, imageSize.height() - (DRAG_LABEL_BORDER_Y_OFFSET + urlFont->descent()));
     307        IntPoint textPos(DRAG_LABEL_BORDER_X, imageSize.height() - (DRAG_LABEL_BORDER_Y_OFFSET + urlFont->fontMetrics().descent()));
    308308        WebCoreDrawDoubledTextAtPoint(context, urlString, textPos, *urlFont, topColor, bottomColor);
    309309    }
  • trunk/Source/WebKit/win/WebKitGraphics.cpp

    r70143 r76442  
    134134
    135135    Font font(makeFont(description));
     136    const WebCore::FontMetrics& fontMetrics(font.fontMetrics());
    136137
    137138    if (ascent)
    138         *ascent = font.ascent();
     139        *ascent = fontMetrics.ascent();
    139140
    140141    if (descent)
    141         *descent = font.descent();
     142        *descent = fontMetrics.descent();
    142143
    143144    if (lineSpacing)
    144         *lineSpacing = font.lineSpacing();
     145        *lineSpacing = fontMetrics.lineSpacing();
    145146}
    146147
  • trunk/Source/WebKit2/ChangeLog

    r76434 r76442  
     12011-01-21  Nikolas Zimmermann  <nzimmermann@rim.com>
     2
     3        Reviewed by Dirk Schulze.
     4
     5        Introduce FontMetrics abstraction
     6        https://bugs.webkit.org/show_bug.cgi?id=51456
     7
     8        * WebProcess/WebCoreSupport/win/WebPopupMenuWin.cpp: Use FontMetrics instead of Font to access the metrics.
     9        (WebKit::WebPopupMenu::setUpPlatformData):
     10
    1112011-01-22  Alexey Proskuryakov  <ap@apple.com>
    212
  • trunk/Source/WebKit2/WebProcess/WebCoreSupport/win/WebPopupMenuWin.cpp

    r75532 r76442  
    5050    data.m_clientInsetLeft = m_popupClient->clientInsetLeft();
    5151    data.m_clientInsetRight = m_popupClient->clientInsetRight();
    52     data.m_itemHeight = m_popupClient->menuStyle().font().height() + 1;
     52    data.m_itemHeight = m_popupClient->menuStyle().font().fontMetrics().height() + 1;
    5353
    5454    int popupWidth = 0;
     
    134134            if (RenderTheme::defaultTheme()->popupOptionSupportsTextIndent() && itemStyle.textDirection() == LTR)
    135135                textX += itemStyle.textIndent().calcMinValue(itemRect.width());
    136             int textY = itemRect.y() + itemFont.ascent() + (itemRect.height() - itemFont.height()) / 2;
     136            int textY = itemRect.y() + itemFont.fontMetrics().ascent() + (itemRect.height() - itemFont.fontMetrics().height()) / 2;
    137137
    138138            notSelectedBackingStoreContext->drawBidiText(itemFont, textRun, IntPoint(textX, textY));
Note: See TracChangeset for help on using the changeset viewer.