<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[191893] trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/191893">191893</a></dd>
<dt>Author</dt> <dd>fred.wang@free.fr</dd>
<dt>Date</dt> <dd>2015-11-02 10:12:21 -0800 (Mon, 02 Nov 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>[Win] Add support for the USE_TYPO_METRICS flag
https://bugs.webkit.org/show_bug.cgi?id=150451

Reviewed by Darin Adler.

Source/WebCore:

Make the Windows backend use the typo metrics when the OS/2 USE_TYPO_METRICS flag is set.

No new tests because this is already tested by fonts/use-typo-metrics-1.html

* platform/graphics/win/SimpleFontDataCGWin.cpp:
(WebCore::Font::platformInit):
* platform/graphics/win/SimpleFontDataCairoWin.cpp:
(WebCore::Font::platformInit):
* platform/graphics/win/SimpleFontDataWin.cpp:
(WebCore::Font::initGDIFont):

LayoutTests:

Remove failure expectation for fonts/use-typo-metrics-1.html on Windows.

* platform/win/TestExpectations:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsplatformwinTestExpectations">trunk/LayoutTests/platform/win/TestExpectations</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicswinSimpleFontDataCGWincpp">trunk/Source/WebCore/platform/graphics/win/SimpleFontDataCGWin.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicswinSimpleFontDataCairoWincpp">trunk/Source/WebCore/platform/graphics/win/SimpleFontDataCairoWin.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicswinSimpleFontDataWincpp">trunk/Source/WebCore/platform/graphics/win/SimpleFontDataWin.cpp</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (191892 => 191893)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2015-11-02 17:55:24 UTC (rev 191892)
+++ trunk/LayoutTests/ChangeLog        2015-11-02 18:12:21 UTC (rev 191893)
</span><span class="lines">@@ -1,3 +1,14 @@
</span><ins>+2015-11-02  Frederic Wang  &lt;fred.wang@free.fr&gt;
+
+        [Win] Add support for the USE_TYPO_METRICS flag
+        https://bugs.webkit.org/show_bug.cgi?id=150451
+
+        Reviewed by Darin Adler.
+
+        Remove failure expectation for fonts/use-typo-metrics-1.html on Windows.
+
+        * platform/win/TestExpectations:
+
</ins><span class="cx"> 2015-11-02  Ryan Haddad  &lt;ryanhaddad@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Marking the following tests as flaky on win
</span></span></pre></div>
<a id="trunkLayoutTestsplatformwinTestExpectations"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/platform/win/TestExpectations (191892 => 191893)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/platform/win/TestExpectations        2015-11-02 17:55:24 UTC (rev 191892)
+++ trunk/LayoutTests/platform/win/TestExpectations        2015-11-02 18:12:21 UTC (rev 191893)
</span><span class="lines">@@ -3268,9 +3268,6 @@
</span><span class="cx"> # The following tests are not relevant on the Windows platform:
</span><span class="cx"> fast/forms/hidpi-textfield-background-bleeding.html [ Skip ]
</span><span class="cx"> 
</span><del>-# USE_TYPO_METRICS is not implemented on the Windows platform
-webkit.org/b/131839 fonts/use-typo-metrics-1.html [ ImageOnlyFailure ]
-
</del><span class="cx"> # [Win] Newly imported W3C XMLHttpRequest tests failing
</span><span class="cx"> webkit.org/b/150594 imported/w3c/web-platform-tests/XMLHttpRequest/send-conditional.htm [ Pass Failure ]
</span><span class="cx"> webkit.org/b/150594 imported/w3c/web-platform-tests/XMLHttpRequest/send-data-unexpected-tostring.htm [ Pass Failure ]
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (191892 => 191893)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2015-11-02 17:55:24 UTC (rev 191892)
+++ trunk/Source/WebCore/ChangeLog        2015-11-02 18:12:21 UTC (rev 191893)
</span><span class="lines">@@ -1,3 +1,21 @@
</span><ins>+2015-11-02  Frederic Wang  &lt;fred.wang@free.fr&gt;
+
+        [Win] Add support for the USE_TYPO_METRICS flag
+        https://bugs.webkit.org/show_bug.cgi?id=150451
+
+        Reviewed by Darin Adler.
+
+        Make the Windows backend use the typo metrics when the OS/2 USE_TYPO_METRICS flag is set.
+
+        No new tests because this is already tested by fonts/use-typo-metrics-1.html
+
+        * platform/graphics/win/SimpleFontDataCGWin.cpp:
+        (WebCore::Font::platformInit):
+        * platform/graphics/win/SimpleFontDataCairoWin.cpp:
+        (WebCore::Font::platformInit):
+        * platform/graphics/win/SimpleFontDataWin.cpp:
+        (WebCore::Font::initGDIFont):
+
</ins><span class="cx"> 2015-11-02  Hyunduk Kim  &lt;hyunduk.kim@samsung.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Enable MediaSource::isTypeSupported() to handle the upper-cased MIME type &amp; Codec
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicswinSimpleFontDataCGWincpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/win/SimpleFontDataCGWin.cpp (191892 => 191893)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/win/SimpleFontDataCGWin.cpp        2015-11-02 17:55:24 UTC (rev 191892)
+++ trunk/Source/WebCore/platform/graphics/win/SimpleFontDataCGWin.cpp        2015-11-02 18:12:21 UTC (rev 191893)
</span><span class="lines">@@ -34,6 +34,7 @@
</span><span class="cx"> #include &quot;FontDescription.h&quot;
</span><span class="cx"> #include &quot;GlyphPage.h&quot;
</span><span class="cx"> #include &quot;HWndDC.h&quot;
</span><ins>+#include &quot;OpenTypeTypes.h&quot;
</ins><span class="cx"> #include &lt;ApplicationServices/ApplicationServices.h&gt;
</span><span class="cx"> #include &lt;WebKitSystemInterface/WebKitSystemInterface.h&gt;
</span><span class="cx"> #include &lt;mlang.h&gt;
</span><span class="lines">@@ -63,6 +64,28 @@
</span><span class="cx">     int iDescent = CGFontGetDescent(font);
</span><span class="cx">     int iLineGap = CGFontGetLeading(font);
</span><span class="cx">     int iCapHeight = CGFontGetCapHeight(font);
</span><ins>+
+    // The Open Font Format describes the OS/2 USE_TYPO_METRICS flag as follows:
+    // &quot;If set, it is strongly recommended to use OS/2.sTypoAscender - OS/2.sTypoDescender+ OS/2.sTypoLineGap as a value for default line spacing for this font.&quot;
+    if (CFDataRef os2Table = CGFontCopyTableForTag(m_platformData.cgFont(), 'OS/2')) {
+        // For the structure of the OS/2 table, see
+        // https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6OS2.html
+        const CFIndex fsSelectionOffset = 16 * 2 + 10 + 4 * 4 + 4 * 1;
+        const CFIndex sTypoAscenderOffset = fsSelectionOffset + 3 * 2;
+        const CFIndex sTypoDescenderOffset = sTypoAscenderOffset + 2;
+        const CFIndex sTypoLineGapOffset = sTypoDescenderOffset + 2;
+        if (CFDataGetLength(os2Table) &gt;= sTypoLineGapOffset + 2) {
+            const UInt8* os2Data = CFDataGetBytePtr(os2Table);
+            const unsigned short useTypoMetricsMask = 1 &lt;&lt; 7;
+            if (*(reinterpret_cast&lt;const OpenType::UInt16*&gt;(os2Data + fsSelectionOffset)) &amp; useTypoMetricsMask) {
+                iAscent = *(reinterpret_cast&lt;const OpenType::Int16*&gt;(os2Data + sTypoAscenderOffset));
+                iDescent = *(reinterpret_cast&lt;const OpenType::Int16*&gt;(os2Data + sTypoDescenderOffset));
+                iLineGap = *(reinterpret_cast&lt;const OpenType::Int16*&gt;(os2Data + sTypoLineGapOffset));
+            }
+        }
+        CFRelease(os2Table);
+    }
+
</ins><span class="cx">     unsigned unitsPerEm = CGFontGetUnitsPerEm(font);
</span><span class="cx">     float pointSize = m_platformData.size();
</span><span class="cx">     float fAscent = scaleEmToUnits(iAscent, unitsPerEm) * pointSize;
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicswinSimpleFontDataCairoWincpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/win/SimpleFontDataCairoWin.cpp (191892 => 191893)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/win/SimpleFontDataCairoWin.cpp        2015-11-02 17:55:24 UTC (rev 191892)
+++ trunk/Source/WebCore/platform/graphics/win/SimpleFontDataCairoWin.cpp        2015-11-02 18:12:21 UTC (rev 191893)
</span><span class="lines">@@ -69,12 +69,23 @@
</span><span class="cx"> 
</span><span class="cx">     cairo_win32_scaled_font_select_font(scaledFont, dc);
</span><span class="cx"> 
</span><del>-    TEXTMETRIC textMetrics;
-    GetTextMetrics(dc, &amp;textMetrics);
-    float ascent = textMetrics.tmAscent * metricsMultiplier;
-    float descent = textMetrics.tmDescent * metricsMultiplier;
</del><ins>+    OUTLINETEXTMETRIC metrics;
+    GetOutlineTextMetrics(dc, sizeof(metrics), &amp;metrics);
+    TEXTMETRIC&amp; textMetrics = metrics.otmTextMetrics;
+    float ascent, descent, lineGap;
+    // The Open Font Format describes the OS/2 USE_TYPO_METRICS flag as follows:
+    // &quot;If set, it is strongly recommended to use OS/2.sTypoAscender - OS/2.sTypoDescender+ OS/2.sTypoLineGap as a value for default line spacing for this font.&quot;
+    const UINT useTypoMetricsMask = 1 &lt;&lt; 7;
+    if (metrics.otmfsSelection &amp; useTypoMetricsMask) {
+        ascent = metrics.otmAscent * metricsMultiplier;
+        descent = metrics.otmDescent * metricsMultiplier;
+        lineGap = metrics.otmLineGap * metricsMultiplier;
+    } else {
+        ascent = textMetrics.tmAscent * metricsMultiplier;
+        descent = textMetrics.tmDescent * metricsMultiplier;
+        lineGap = textMetrics.tmExternalLeading * metricsMultiplier;
+    }
</ins><span class="cx">     float xHeight = ascent * 0.56f; // Best guess for xHeight for non-Truetype fonts.
</span><del>-    float lineGap = textMetrics.tmExternalLeading * metricsMultiplier;
</del><span class="cx"> 
</span><span class="cx">     int faceLength = ::GetTextFace(dc, 0, 0);
</span><span class="cx">     Vector&lt;WCHAR&gt; faceName(faceLength);
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicswinSimpleFontDataWincpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/win/SimpleFontDataWin.cpp (191892 => 191893)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/win/SimpleFontDataWin.cpp        2015-11-02 17:55:24 UTC (rev 191892)
+++ trunk/Source/WebCore/platform/graphics/win/SimpleFontDataWin.cpp        2015-11-02 18:12:21 UTC (rev 191893)
</span><span class="lines">@@ -85,9 +85,19 @@
</span><span class="cx">     OUTLINETEXTMETRIC metrics;
</span><span class="cx">     GetOutlineTextMetrics(hdc, sizeof(metrics), &amp;metrics);
</span><span class="cx">     TEXTMETRIC&amp; textMetrics = metrics.otmTextMetrics;
</span><del>-    float ascent = textMetrics.tmAscent;
-    float descent = textMetrics.tmDescent;
-    float lineGap = textMetrics.tmExternalLeading;
</del><ins>+    float ascent, descent, lineGap;
+    // The Open Font Format describes the OS/2 USE_TYPO_METRICS flag as follows:
+    // &quot;If set, it is strongly recommended to use OS/2.sTypoAscender - OS/2.sTypoDescender+ OS/2.sTypoLineGap as a value for default line spacing for this font.&quot;
+    const UINT useTypoMetricsMask = 1 &lt;&lt; 7;
+    if (metrics.otmfsSelection &amp; useTypoMetricsMask) {
+        ascent = metrics.otmAscent;
+        descent = metrics.otmDescent;
+        lineGap = metrics.otmLineGap;
+    } else {
+        ascent = textMetrics.tmAscent;
+        descent = textMetrics.tmDescent;
+        lineGap = textMetrics.tmExternalLeading;
+    }
</ins><span class="cx">     m_fontMetrics.setAscent(ascent);
</span><span class="cx">     m_fontMetrics.setDescent(descent);
</span><span class="cx">     m_fontMetrics.setLineGap(lineGap);
</span></span></pre>
</div>
</div>

</body>
</html>