⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 176263 in webkit


Ignore:
Timestamp:
Nov 18, 2014, 10:04:13 AM (12 years ago)
Author:
mmaxfield@apple.com
Message:

Use underlining metrics from the font file
https://bugs.webkit.org/show_bug.cgi?id=138762

Patch by Myles C. Maxfield <litherum@gmail.com> on 2014-11-18
Reviewed by Dave Hyatt.

Source/WebCore:

Test: platform/mac/fast/css3-text/css3-text-decoration/text-decoration-thickness.html

  • platform/graphics/FontMetrics.h: Adding variables for text decoration thickness and

underline position.
(WebCore::FontMetrics::FontMetrics):
(WebCore::FontMetrics::decorationThickness):
(WebCore::FontMetrics::setDecorationThickness):
(WebCore::FontMetrics::underlinePosition):
(WebCore::FontMetrics::setUnderlinePosition):

  • platform/graphics/freetype/SimpleFontDataFreeType.cpp:

(WebCore::SimpleFontData::platformInit): Initialize new FontMetrics members.

  • platform/graphics/ios/SimpleFontDataIOS.mm:

(WebCore::SimpleFontData::platformInit): Ditto.

  • platform/graphics/mac/SimpleFontDataMac.mm:

(WebCore::SimpleFontData::platformInit): Ditto.

  • platform/graphics/win/SimpleFontDataCGWin.cpp:

(WebCore::SimpleFontData::platformInit): Ditto.

  • platform/graphics/win/SimpleFontDataCairoWin.cpp:

(WebCore::SimpleFontData::platformInit): Ditto.

  • platform/graphics/win/SimpleFontDataWin.cpp:

(WebCore::SimpleFontData::initGDIFont): Ditto.

  • rendering/InlineTextBox.cpp:

(WebCore::InlineTextBox::paintDecoration): Use FontMetrics data.

  • style/InlineTextBoxStyle.cpp:

(WebCore::computeUnderlineOffset): Ditto.
(WebCore::visualOverflowForDecorations): Ditto.

  • style/InlineTextBoxStyle.h:

(WebCore::textDecorationStrokeThickness): Deleted.

  • svg/SVGFontData.cpp:

(WebCore::SVGFontData::initializeFontData): Initialize new FontMetrics members.

LayoutTests:

This patch makes underline placement platform-dependent.

  • platform/mac/fast/css3-text/css3-text-decoration/text-decoration-thickness-expected.html: Renamed from LayoutTests/fast/css3-text/css3-text-decoration/text-decoration-thickness-expected.html.
  • platform/mac/fast/css3-text/css3-text-decoration/text-decoration-thickness.html: Renamed from LayoutTests/fast/css3-text/css3-text-decoration/text-decoration-thickness.html.
Location:
trunk
Files:
14 edited
2 moved

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r176262 r176263  
     12014-11-18  Myles C. Maxfield  <litherum@gmail.com>
     2
     3        Use underlining metrics from the font file
     4        https://bugs.webkit.org/show_bug.cgi?id=138762
     5
     6        Reviewed by Dave Hyatt.
     7
     8        This patch makes underline placement platform-dependent.
     9
     10        * platform/mac/fast/css3-text/css3-text-decoration/text-decoration-thickness-expected.html: Renamed from LayoutTests/fast/css3-text/css3-text-decoration/text-decoration-thickness-expected.html.
     11        * platform/mac/fast/css3-text/css3-text-decoration/text-decoration-thickness.html: Renamed from LayoutTests/fast/css3-text/css3-text-decoration/text-decoration-thickness.html.
     12
    1132014-11-17  David Hyatt  <hyatt@apple.com>
    214
  • trunk/LayoutTests/platform/mac/fast/css3-text/css3-text-decoration/text-decoration-thickness.html

    r176262 r176263  
    88to text size. The comparison is to a box that has its background color set.
    99<div style="position: relative; width: 600px; height: 600px; overflow: hidden;">
    10 <div style="font-family: Ahem; text-decoration: underline; font-size: 10000px; position: absolute; left: 0px; top: -8350px;">&nbsp;</div>
     10<div style="font-family: Ahem; text-decoration: underline; font-size: 31000px; position: absolute; left: 0px; top: -28925px;">&nbsp;</div>
    1111</div>
    1212</body>
  • trunk/Source/WebCore/ChangeLog

    r176262 r176263  
     12014-11-18  Myles C. Maxfield  <litherum@gmail.com>
     2
     3        Use underlining metrics from the font file
     4        https://bugs.webkit.org/show_bug.cgi?id=138762
     5
     6        Reviewed by Dave Hyatt.
     7
     8        Test: platform/mac/fast/css3-text/css3-text-decoration/text-decoration-thickness.html
     9
     10        * platform/graphics/FontMetrics.h: Adding variables for text decoration thickness and
     11        underline position.
     12        (WebCore::FontMetrics::FontMetrics):
     13        (WebCore::FontMetrics::decorationThickness):
     14        (WebCore::FontMetrics::setDecorationThickness):
     15        (WebCore::FontMetrics::underlinePosition):
     16        (WebCore::FontMetrics::setUnderlinePosition):
     17        * platform/graphics/freetype/SimpleFontDataFreeType.cpp:
     18        (WebCore::SimpleFontData::platformInit): Initialize new FontMetrics members.
     19        * platform/graphics/ios/SimpleFontDataIOS.mm:
     20        (WebCore::SimpleFontData::platformInit): Ditto.
     21        * platform/graphics/mac/SimpleFontDataMac.mm:
     22        (WebCore::SimpleFontData::platformInit): Ditto.
     23        * platform/graphics/win/SimpleFontDataCGWin.cpp:
     24        (WebCore::SimpleFontData::platformInit): Ditto.
     25        * platform/graphics/win/SimpleFontDataCairoWin.cpp:
     26        (WebCore::SimpleFontData::platformInit): Ditto.
     27        * platform/graphics/win/SimpleFontDataWin.cpp:
     28        (WebCore::SimpleFontData::initGDIFont): Ditto.
     29        * rendering/InlineTextBox.cpp:
     30        (WebCore::InlineTextBox::paintDecoration): Use FontMetrics data.
     31        * style/InlineTextBoxStyle.cpp:
     32        (WebCore::computeUnderlineOffset): Ditto.
     33        (WebCore::visualOverflowForDecorations): Ditto.
     34        * style/InlineTextBoxStyle.h:
     35        (WebCore::textDecorationStrokeThickness): Deleted.
     36        * svg/SVGFontData.cpp:
     37        (WebCore::SVGFontData::initializeFontData): Initialize new FontMetrics members.
     38
    1392014-11-17  David Hyatt  <hyatt@apple.com>
    240
  • trunk/Source/WebCore/platform/graphics/FontMetrics.h

    r173217 r176263  
    3838        , m_xHeight(0)
    3939        , m_zeroWidth(0)
     40        , m_decorationThickness(1)
     41        , m_underlinePosition(1)
    4042        , m_hasXHeight(false)
    4143        , m_hasZeroWidth(false)
     
    133135    void setHasZeroWidth(bool hasZeroWidth) { m_hasZeroWidth = hasZeroWidth; }
    134136
     137    float decorationThickness() const { return m_decorationThickness; }
     138    void setDecorationThickness(float decorationThickness) { m_decorationThickness = decorationThickness; }
     139
     140    float underlinePosition() const { return m_underlinePosition; }
     141    void setUnderlinePosition(float underlinePosition) { m_underlinePosition = underlinePosition; }
     142
    135143private:
    136144    friend class SimpleFontData;
     
    155163    float m_capHeight;
    156164    float m_zeroWidth;
     165    float m_decorationThickness;
     166    float m_underlinePosition;
    157167    bool m_hasXHeight;
    158168    bool m_hasCapHeight;
  • trunk/Source/WebCore/platform/graphics/SimpleFontData.h

    r176140 r176263  
    363363}
    364364
     365static inline void populateDecorationMetrics(float fontSize, float& decorationThickness, float& underlinePosition)
     366{
     367    // Decoration underlines should be proportional to the font size
     368    decorationThickness = fontSize / 16.0f;
     369    // An amount to lower the underline below the baseline
     370    underlinePosition = std::max(1.0f, ceilf(decorationThickness / 2.0));
     371}
     372
    365373} // namespace WebCore
    366374
  • trunk/Source/WebCore/platform/graphics/freetype/SimpleFontDataFreeType.cpp

    r174002 r176263  
    6666    float capHeight = narrowPrecisionToFloat(fontExtents.height);
    6767    float lineGap = narrowPrecisionToFloat(fontExtents.height - fontExtents.ascent - fontExtents.descent);
     68    float decorationThickness;
     69    float underlinePosition;
     70    populateDecorationMetrics(m_platformData.m_size, decorationThickness, underlinePosition);
    6871
    6972    m_fontMetrics.setAscent(ascent);
    7073    m_fontMetrics.setDescent(descent);
    7174    m_fontMetrics.setCapHeight(capHeight);
     75    m_fontMetrics.setDecorationThickness(decorationThickness);
     76    m_fontMetrics.setUnderlinePosition(underlinePosition);
    7277
    7378#if PLATFORM(EFL)
  • trunk/Source/WebCore/platform/graphics/ios/SimpleFontDataIOS.mm

    r176140 r176263  
    8080    float lineSpacing;
    8181    float xHeight;
     82    float decorationThickness;
     83    float underlinePosition;
    8284    RetainPtr<CFStringRef> familyName;
    8385    if (CTFontRef ctFont = m_platformData.font()) {
     
    8890        lineGap = fontService.lineGap();
    8991        xHeight = fontService.xHeight();
     92        decorationThickness = CTFontGetUnderlineThickness(ctFont);
     93        underlinePosition = -CTFontGetUnderlinePosition(ctFont);
    9094        capHeight = fontService.capHeight();
    9195        unitsPerEm = fontService.unitsPerEm();
     
    102106        xHeight = scaleEmToUnits(CGFontGetXHeight(cgFont), unitsPerEm) * pointSize;
    103107        capHeight = scaleEmToUnits(CGFontGetCapHeight(cgFont), unitsPerEm) * pointSize;
     108        float decorationThickness;
     109        float underlinePosition;
     110        populateDecorationMetrics(m_platformData.size(), decorationThickness, underlinePosition);
    104111
    105112        lineSpacing = ascent + descent + lineGap;
     
    114121    m_fontMetrics.setXHeight(xHeight);
    115122    m_fontMetrics.setCapHeight(capHeight);
     123    m_fontMetrics.setDecorationThickness(decorationThickness);
     124    m_fontMetrics.setUnderlinePosition(underlinePosition);
    116125    m_shouldNotBeUsedForArabic = fontFamilyShouldNotBeUsedForArabic(familyName.get());
    117126
  • trunk/Source/WebCore/platform/graphics/mac/SimpleFontDataMac.mm

    r176229 r176263  
    194194   
    195195    float lineGap = scaleEmToUnits(iLineGap, unitsPerEm) * pointSize;
     196    float decorationThickness = CTFontGetUnderlineThickness(m_platformData.ctFont());
     197    float underlinePosition = -CTFontGetUnderlinePosition(m_platformData.ctFont());
    196198
    197199    // We need to adjust Times, Helvetica, and Courier to closely match the
     
    237239    m_fontMetrics.setLineGap(lineGap);
    238240    m_fontMetrics.setXHeight(xHeight);
     241    m_fontMetrics.setDecorationThickness(decorationThickness);
     242    m_fontMetrics.setUnderlinePosition(underlinePosition);
    239243}
    240244
  • trunk/Source/WebCore/platform/graphics/win/SimpleFontDataCGWin.cpp

    r173840 r176263  
    7070    float fCapHeight = scaleEmToUnits(iCapHeight, unitsPerEm) * pointSize;
    7171    float fLineGap = scaleEmToUnits(iLineGap, unitsPerEm) * pointSize;
     72    float decorationThickness;
     73    float underlinePosition;
     74    populateDecorationMetrics(m_platformData.size(), decorationThickness, underlinePosition);
    7275
    7376    if (!isCustomFont()) {
     
    8891    m_fontMetrics.setLineGap(fLineGap);
    8992    m_fontMetrics.setLineSpacing(lroundf(fAscent) + lroundf(fDescent) + lroundf(fLineGap));
     93    m_fontMetrics.setDecorationThickness(decorationThickness);
     94    m_fontMetrics.setUnderlinePosition(underlinePosition);
    9095
    9196    GlyphPage* glyphPageZero = GlyphPageTreeNode::getRootChild(this, 0)->page();
  • trunk/Source/WebCore/platform/graphics/win/SimpleFontDataCairoWin.cpp

    r165676 r176263  
    7777    float xHeight = ascent * 0.56f; // Best guess for xHeight for non-Truetype fonts.
    7878    float lineGap = textMetrics.tmExternalLeading * metricsMultiplier;
     79    float decorationThickness;
     80    float underlinePosition;
     81    populateDecorationMetrics(m_platformData.size(), decorationThickness, underlinePosition);
    7982
    8083    int faceLength = ::GetTextFace(dc, 0, 0);
     
    8992    m_fontMetrics.setLineGap(lineGap);
    9093    m_fontMetrics.setLineSpacing(lroundf(ascent) + lroundf(descent) + lroundf(lineGap));
     94    m_fontMetrics.setDecorationThickness(decorationThickness);
     95    m_fontMetrics.setUnderlinePosition(underlinePosition);
    9196    m_avgCharWidth = textMetrics.tmAveCharWidth * metricsMultiplier;
    9297    m_maxCharWidth = textMetrics.tmMaxCharWidth * metricsMultiplier;
  • trunk/Source/WebCore/platform/graphics/win/SimpleFontDataWin.cpp

    r174465 r176263  
    9090    float descent = textMetrics.tmDescent;
    9191    float lineGap = textMetrics.tmExternalLeading;
     92    float decorationThickness;
     93    float underlinePosition;
     94    populateDecorationMetrics(m_platformData.size(), decorationThickness, underlinePosition);
    9295    m_fontMetrics.setAscent(ascent);
    9396    m_fontMetrics.setDescent(descent);
    9497    m_fontMetrics.setLineGap(lineGap);
    9598    m_fontMetrics.setLineSpacing(lroundf(ascent) + lroundf(descent) + lroundf(lineGap));
     99    m_fontMetrics.setDecorationThickness(decorationThickness);
     100    m_fontMetrics.setUnderlinePosition(underlinePosition);
    96101    m_avgCharWidth = textMetrics.tmAveCharWidth;
    97102    m_maxCharWidth = textMetrics.tmMaxCharWidth;
  • trunk/Source/WebCore/rendering/InlineTextBox.cpp

    r176147 r176263  
    926926    bool isPrinting = renderer().document().printing();
    927927
    928     float textDecorationThickness = textDecorationStrokeThickness(renderer().style().fontSize());
     928    float textDecorationThickness = renderer().style().fontMetrics().decorationThickness();
    929929    context.setStrokeThickness(textDecorationThickness);
    930930
     
    978978        if (decoration & TextDecorationUnderline) {
    979979            context.setStrokeColor(underline, colorSpace);
    980             const int underlineOffset = computeUnderlineOffset(lineStyle.textUnderlinePosition(), lineStyle.fontMetrics(), this, textDecorationThickness);
     980            const int underlineOffset = computeUnderlineOffset(lineStyle.textUnderlinePosition(), lineStyle.fontMetrics(), this);
    981981
    982982            switch (decorationStyle) {
  • trunk/Source/WebCore/style/InlineTextBoxStyle.cpp

    r169089 r176263  
    3333namespace WebCore {
    3434   
    35 int computeUnderlineOffset(TextUnderlinePosition underlinePosition, const FontMetrics& fontMetrics, InlineTextBox* inlineTextBox, int textDecorationThickness)
     35int computeUnderlineOffset(TextUnderlinePosition underlinePosition, const FontMetrics& fontMetrics, InlineTextBox* inlineTextBox)
    3636{
    3737    // This represents the gap between the baseline and the closest edge of the underline.
    38     int gap = std::max<int>(1, ceilf(textDecorationThickness / 2.0));
     38    float gap = fontMetrics.underlinePosition();
    3939
    4040    // According to the specification TextUnderlinePositionAuto should default to 'alphabetic' for horizontal text
     
    8484        return GlyphOverflow();
    8585   
    86     float strokeThickness = textDecorationStrokeThickness(lineStyle.fontSize());
     86    float strokeThickness = lineStyle.fontMetrics().decorationThickness();
    8787    float controlPointDistance;
    8888    float step;
     
    102102    // These metrics must match where underlines get drawn.
    103103    if (decoration & TextDecorationUnderline) {
    104         float underlineOffset = computeUnderlineOffset(lineStyle.textUnderlinePosition(), lineStyle.fontMetrics(), inlineTextBox, strokeThickness);
     104        float underlineOffset = computeUnderlineOffset(lineStyle.textUnderlinePosition(), lineStyle.fontMetrics(), inlineTextBox);
    105105        if (decorationStyle == TextDecorationStyleWavy) {
    106106            extendIntToFloat(overflowResult.bottom, underlineOffset + wavyOffset + controlPointDistance + strokeThickness - height);
  • trunk/Source/WebCore/style/InlineTextBoxStyle.h

    r169089 r176263  
    3434class InlineTextBox;
    3535
    36 inline float textDecorationStrokeThickness(float fontSize)
    37 {
    38     const float textDecorationBaseFontSize = 16;
    39     return fontSize / textDecorationBaseFontSize;
    40 }
    41 
    4236inline float wavyOffsetFromDecoration()
    4337{
     
    4741GlyphOverflow visualOverflowForDecorations(const RenderStyle& lineStyle, InlineTextBox*);
    4842void getWavyStrokeParameters(float strokeThickness, float& controlPointDistance, float& step);
    49 int computeUnderlineOffset(TextUnderlinePosition, const FontMetrics&, InlineTextBox*, int textDecorationThickness);
     43int computeUnderlineOffset(TextUnderlinePosition, const FontMetrics&, InlineTextBox*);
    5044   
    5145}
  • trunk/Source/WebCore/svg/SVGFontData.cpp

    r174619 r176263  
    8080    float descent = svgFontFaceElement->descent() * scale;
    8181    float lineGap = 0.1f * fontSize;
     82    float decorationThickness;
     83    float underlinePosition;
     84    populateDecorationMetrics(fontSize, decorationThickness, underlinePosition);
    8285
    8386    GlyphPage* glyphPageZero = GlyphPageTreeNode::getRootChild(fontData, 0)->page();
     
    9699    fontMetrics.setLineSpacing(roundf(ascent) + roundf(descent) + roundf(lineGap));
    97100    fontMetrics.setXHeight(xHeight);
     101    fontMetrics.setDecorationThickness(decorationThickness);
     102    fontMetrics.setUnderlinePosition(underlinePosition);
    98103
    99104    if (!glyphPageZero) {
Note: See TracChangeset for help on using the changeset viewer.