Title: [108843] trunk/Source/WebCore
Revision
108843
Author
[email protected]
Date
2012-02-24 13:38:54 -0800 (Fri, 24 Feb 2012)

Log Message

[WinCairo] Compute more acurate font heights.
https://bugs.webkit.org/show_bug.cgi?id=79524

Reviewed by Adam Roben.

Adjust font handling as suggested by Lynn Neir to use the proper
xHeight value for the font, rather than the fall-back guess
used in the current code.

css1/text_properties/line_height.html

* platform/graphics/win/SimpleFontDataCairoWin.cpp:
(WebCore::SimpleFontData::platformInit): Properly initialize a
  few elements.
(WebCore::SimpleFontData::platformWidthForGlyph): Use the Cairo
  cairo_scaled_font_text_extents call, rather than attempting
  to compute the value from ::GetGlyphOutline.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (108842 => 108843)


--- trunk/Source/WebCore/ChangeLog	2012-02-24 21:31:37 UTC (rev 108842)
+++ trunk/Source/WebCore/ChangeLog	2012-02-24 21:38:54 UTC (rev 108843)
@@ -1,3 +1,23 @@
+2012-02-24  Brent Fulgham  <[email protected]>
+
+        [WinCairo] Compute more acurate font heights.
+        https://bugs.webkit.org/show_bug.cgi?id=79524
+
+        Reviewed by Adam Roben.
+
+        Adjust font handling as suggested by Lynn Neir to use the proper
+        xHeight value for the font, rather than the fall-back guess
+        used in the current code.
+
+        css1/text_properties/line_height.html
+
+        * platform/graphics/win/SimpleFontDataCairoWin.cpp:
+        (WebCore::SimpleFontData::platformInit): Properly initialize a
+          few elements.
+        (WebCore::SimpleFontData::platformWidthForGlyph): Use the Cairo
+          cairo_scaled_font_text_extents call, rather than attempting
+          to compute the value from ::GetGlyphOutline.
+
 2012-02-24  Tim Horton  <[email protected]>
 
         Infinite repaint loop with SVGImageCache and deferred repaint timers

Modified: trunk/Source/WebCore/platform/graphics/win/SimpleFontDataCairoWin.cpp (108842 => 108843)


--- trunk/Source/WebCore/platform/graphics/win/SimpleFontDataCairoWin.cpp	2012-02-24 21:31:37 UTC (rev 108842)
+++ trunk/Source/WebCore/platform/graphics/win/SimpleFontDataCairoWin.cpp	2012-02-24 21:38:54 UTC (rev 108843)
@@ -34,6 +34,7 @@
 #include "Font.h"
 #include "FontCache.h"
 #include "FontDescription.h"
+#include "HWndDC.h"
 #include <cairo.h>
 #include <cairo-win32.h>
 #include <mlang.h>
@@ -55,27 +56,30 @@
         m_fontMetrics.reset();
         m_avgCharWidth = 0;
         m_maxCharWidth = 0;
+        m_isSystemFont = false;
+        m_scriptCache = 0;
+        m_scriptFontProperties = 0;
         return;
     }
 
-    HDC hdc = GetDC(0);
-    SaveDC(hdc);
+    HWndDC dc(0);
+    SaveDC(dc);
 
     cairo_scaled_font_t* scaledFont = m_platformData.scaledFont();
     const double metricsMultiplier = cairo_win32_scaled_font_get_metrics_factor(scaledFont) * m_platformData.size();
 
-    cairo_win32_scaled_font_select_font(scaledFont, hdc);
+    cairo_win32_scaled_font_select_font(scaledFont, dc);
 
     TEXTMETRIC textMetrics;
-    GetTextMetrics(hdc, &textMetrics);
+    GetTextMetrics(dc, &textMetrics);
     float ascent = textMetrics.tmAscent * metricsMultiplier;
     float descent = textMetrics.tmDescent * metricsMultiplier;
     float xHeight = ascent * 0.56f; // Best guess for xHeight for non-Truetype fonts.
     float lineGap = textMetrics.tmExternalLeading * metricsMultiplier;
 
-    int faceLength = ::GetTextFace(hdc, 0, 0);
+    int faceLength = ::GetTextFace(dc, 0, 0);
     Vector<WCHAR> faceName(faceLength);
-    ::GetTextFace(hdc, faceLength, faceName.data());
+    ::GetTextFace(dc, faceLength, faceName.data());
     m_isSystemFont = !wcscmp(faceName.data(), L"Lucida Grande");
  
     ascent = ascentConsideringMacAscentHack(faceName.data(), ascent, descent);
@@ -87,21 +91,17 @@
     m_avgCharWidth = textMetrics.tmAveCharWidth * metricsMultiplier;
     m_maxCharWidth = textMetrics.tmMaxCharWidth * metricsMultiplier;
 
-    OUTLINETEXTMETRIC metrics;
-    if (GetOutlineTextMetrics(hdc, sizeof(metrics), &metrics) > 0) {
-        // This is a TrueType font.  We might be able to get an accurate xHeight
-        GLYPHMETRICS gm;
-        MAT2 mat = { 1, 0, 0, 1 };
-        DWORD len = GetGlyphOutline(hdc, 'x', GGO_METRICS, &gm, 0, 0, &mat);
-        if (len != GDI_ERROR && gm.gmptGlyphOrigin.y > 0)
-            xHeight = gm.gmptGlyphOrigin.y * metricsMultiplier;
-    }
+    cairo_text_extents_t extents;
+    cairo_scaled_font_text_extents(scaledFont, "x", &extents);
+    xHeight = -extents.y_bearing;
 
     m_fontMetrics.setXHeight(xHeight);
     cairo_win32_scaled_font_done_font(scaledFont);
 
-    RestoreDC(hdc, -1);
-    ReleaseDC(0, hdc);
+    m_scriptCache = 0;
+    m_scriptFontProperties = 0;
+
+    RestoreDC(dc, -1);
 }
 
 FloatRect SimpleFontData::platformBoundsForGlyph(Glyph glyph) const
@@ -120,19 +120,18 @@
     if (!m_platformData.size())
         return 0;
 
-    HDC hdc = GetDC(0);
-    SaveDC(hdc);
+    HWndDC dc(0);
+    SaveDC(dc);
 
     cairo_scaled_font_t* scaledFont = m_platformData.scaledFont();
-    cairo_win32_scaled_font_select_font(scaledFont, hdc);
+    cairo_win32_scaled_font_select_font(scaledFont, dc);
 
     int width;
-    GetCharWidthI(hdc, glyph, 1, 0, &width);
+    GetCharWidthI(dc, glyph, 1, 0, &width);
 
     cairo_win32_scaled_font_done_font(scaledFont);
 
-    RestoreDC(hdc, -1);
-    ReleaseDC(0, hdc);
+    RestoreDC(dc, -1);
 
     const double metricsMultiplier = cairo_win32_scaled_font_get_metrics_factor(scaledFont) * m_platformData.size();
     return width * metricsMultiplier;
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to