Changeset 101343 in webkit


Ignore:
Timestamp:
Nov 29, 2011 1:42:34 AM (12 years ago)
Author:
Philippe Normand
Message:

[GTK] Improve FontMetrics accuracy
https://bugs.webkit.org/show_bug.cgi?id=72614

Reviewed by Martin Robinson.
Patch by Nikolas Zimmermann.

  • platform/graphics/freetype/FontPlatformDataFreeType.cpp:

(WebCore::setCairoFontOptionsFromFontConfigPattern):

  • platform/graphics/freetype/SimpleFontDataFreeType.cpp:

(WebCore::SimpleFontData::platformInit):

Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r101342 r101343  
     12011-11-25  Philippe Normand  <pnormand@igalia.com>
     2
     3        [GTK] Improve FontMetrics accuracy
     4        https://bugs.webkit.org/show_bug.cgi?id=72614
     5
     6        Reviewed by Martin Robinson.
     7        Patch by Nikolas Zimmermann.
     8
     9        * platform/graphics/freetype/FontPlatformDataFreeType.cpp:
     10        (WebCore::setCairoFontOptionsFromFontConfigPattern):
     11        * platform/graphics/freetype/SimpleFontDataFreeType.cpp:
     12        (WebCore::SimpleFontData::platformInit):
     13
    1142011-11-29  Nikolas Zimmermann  <nzimmermann@rim.com>
    215
  • trunk/Source/WebCore/platform/graphics/freetype/FontPlatformDataFreeType.cpp

    r96941 r101343  
    9999    if (FcPatternGetBool(pattern, FC_HINTING, 0, &booleanResult) == FcResultMatch && !booleanResult)
    100100        cairo_font_options_set_hint_style(options, CAIRO_HINT_STYLE_NONE);
     101
     102    // Turn off text metrics hinting, which quantizes metrics to pixels in device space.
     103    cairo_font_options_set_hint_metrics(options, CAIRO_HINT_METRICS_OFF);
    101104}
    102105
  • trunk/Source/WebCore/platform/graphics/freetype/SimpleFontDataFreeType.cpp

    r90041 r101343  
    3434#include "SimpleFontData.h"
    3535
     36#include "FloatConversion.h"
    3637#include "FloatRect.h"
    3738#include "Font.h"
     
    5657    cairo_scaled_font_extents(m_platformData.scaledFont(), &font_extents);
    5758
    58     m_fontMetrics.setAscent(font_extents.ascent);
    59     m_fontMetrics.setDescent(font_extents.descent);
     59    float ascent = narrowPrecisionToFloat(font_extents.ascent);
     60    float descent = narrowPrecisionToFloat(font_extents.descent);
     61    float lineGap = narrowPrecisionToFloat(font_extents.height - font_extents.ascent - font_extents.descent);
    6062
    61     // There seems to be some rounding error in cairo (or in how we
    62     // use cairo) with some fonts, like DejaVu Sans Mono, which makes
    63     // cairo report a height smaller than ascent + descent, which is
    64     // wrong and confuses WebCore's layout system. Workaround this
    65     // while we figure out what's going on.
    66     float lineSpacing = font_extents.height;
    67     if (lineSpacing < font_extents.ascent + font_extents.descent)
    68         lineSpacing = font_extents.ascent + font_extents.descent;
     63    m_fontMetrics.setAscent(ascent);
     64    m_fontMetrics.setDescent(descent);
    6965
    70     m_fontMetrics.setLineSpacing(lroundf(lineSpacing));
    71     m_fontMetrics.setLineGap(lineSpacing - font_extents.ascent - font_extents.descent);
     66    // Match CoreGraphics metrics.
     67    m_fontMetrics.setLineSpacing(lroundf(ascent) + lroundf(descent) + lroundf(lineGap));
     68    m_fontMetrics.setLineGap(lineGap);
    7269
    7370    cairo_scaled_font_text_extents(m_platformData.scaledFont(), "x", &text_extents);
    74     m_fontMetrics.setXHeight(text_extents.height);
     71    m_fontMetrics.setXHeight(narrowPrecisionToFloat(text_extents.height));
    7572
    7673    cairo_scaled_font_text_extents(m_platformData.scaledFont(), " ", &text_extents);
    77     m_spaceWidth = static_cast<float>(text_extents.x_advance);
     74    m_spaceWidth = narrowPrecisionToFloat(text_extents.x_advance);
    7875   
    7976    m_syntheticBoldOffset = m_platformData.syntheticBold() ? 1.0f : 0.f;
Note: See TracChangeset for help on using the changeset viewer.