<!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>[180752] trunk/Source/WebCore</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/180752">180752</a></dd>
<dt>Author</dt> <dd>antti@apple.com</dd>
<dt>Date</dt> <dd>2015-02-27 08:12:13 -0800 (Fri, 27 Feb 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>Cache glyph widths to GlyphPages
https://bugs.webkit.org/show_bug.cgi?id=142028

Reviewed by Andreas Kling.

Currently we have a separate cache in Font for glyph widths. In practice we always need
the widths so we can just cache them in GlyphPages. This simplifies the code and removes
a per-character hash lookup from WidthIterator.

* platform/graphics/Font.cpp:
(WebCore::Font::Font):
(WebCore::Font::initCharWidths):
(WebCore::Font::platformGlyphInit):
(WebCore::createAndFillGlyphPage):
(WebCore::Font::computeWidthForGlyph):

    Rename to make it clear this doesn't cache.

(WebCore::GlyphPage::setGlyphDataForIndex):

    Initialize the width.
    This could go to GlyphPage.cpp if we had one.

* platform/graphics/Font.h:
(WebCore::Font::glyphZeroWidth):
(WebCore::Font::isZeroWidthSpaceGlyph):
(WebCore::Font::zeroGlyph): Deleted.
(WebCore::Font::setZeroGlyph): Deleted.
(WebCore::Font::widthForGlyph): Deleted.
* platform/graphics/FontCascade.cpp:
(WebCore::offsetToMiddleOfGlyph):
* platform/graphics/FontCascadeFonts.cpp:
(WebCore::FontCascadeFonts::glyphDataForCharacter):
* platform/graphics/GlyphPage.h:
(WebCore::GlyphData::GlyphData):

    Return width too as part of GlyphData.

(WebCore::GlyphPage::glyphDataForIndex):
(WebCore::GlyphPage::setGlyphDataForCharacter):
(WebCore::GlyphPage::setGlyphDataForIndex):
(WebCore::GlyphPage::GlyphPage):
* platform/graphics/WidthIterator.cpp:
(WebCore::WidthIterator::advanceInternal):

    No need to lookup width separately now.

* platform/graphics/mac/ComplexTextController.cpp:
(WebCore::ComplexTextController::adjustGlyphsAndAdvances):
* platform/graphics/mac/ComplexTextControllerCoreText.mm:
(WebCore::ComplexTextController::ComplexTextRun::ComplexTextRun):
* rendering/mathml/RenderMathMLOperator.cpp:
(WebCore::RenderMathMLOperator::advanceForGlyph):
* rendering/svg/SVGTextRunRenderingContext.cpp:
(WebCore::missingGlyphForFont):
* svg/SVGFontData.cpp:
(WebCore::SVGFontData::initializeFont):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsFontcpp">trunk/Source/WebCore/platform/graphics/Font.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsFonth">trunk/Source/WebCore/platform/graphics/Font.h</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsFontCascadecpp">trunk/Source/WebCore/platform/graphics/FontCascade.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsFontCascadeFontscpp">trunk/Source/WebCore/platform/graphics/FontCascadeFonts.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsGlyphPageh">trunk/Source/WebCore/platform/graphics/GlyphPage.h</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsWidthIteratorcpp">trunk/Source/WebCore/platform/graphics/WidthIterator.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsmacComplexTextControllercpp">trunk/Source/WebCore/platform/graphics/mac/ComplexTextController.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsmacComplexTextControllerCoreTextmm">trunk/Source/WebCore/platform/graphics/mac/ComplexTextControllerCoreText.mm</a></li>
<li><a href="#trunkSourceWebCorerenderingmathmlRenderMathMLOperatorcpp">trunk/Source/WebCore/rendering/mathml/RenderMathMLOperator.cpp</a></li>
<li><a href="#trunkSourceWebCorerenderingsvgSVGTextRunRenderingContextcpp">trunk/Source/WebCore/rendering/svg/SVGTextRunRenderingContext.cpp</a></li>
<li><a href="#trunkSourceWebCoresvgSVGFontDatacpp">trunk/Source/WebCore/svg/SVGFontData.cpp</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (180751 => 180752)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2015-02-27 14:57:19 UTC (rev 180751)
+++ trunk/Source/WebCore/ChangeLog        2015-02-27 16:12:13 UTC (rev 180752)
</span><span class="lines">@@ -1,3 +1,63 @@
</span><ins>+2015-02-27  Antti Koivisto  &lt;antti@apple.com&gt;
+
+        Cache glyph widths to GlyphPages
+        https://bugs.webkit.org/show_bug.cgi?id=142028
+
+        Reviewed by Andreas Kling.
+
+        Currently we have a separate cache in Font for glyph widths. In practice we always need
+        the widths so we can just cache them in GlyphPages. This simplifies the code and removes
+        a per-character hash lookup from WidthIterator.
+
+        * platform/graphics/Font.cpp:
+        (WebCore::Font::Font):
+        (WebCore::Font::initCharWidths):
+        (WebCore::Font::platformGlyphInit):
+        (WebCore::createAndFillGlyphPage):
+        (WebCore::Font::computeWidthForGlyph):
+
+            Rename to make it clear this doesn't cache.
+
+        (WebCore::GlyphPage::setGlyphDataForIndex):
+
+            Initialize the width.
+            This could go to GlyphPage.cpp if we had one.
+
+        * platform/graphics/Font.h:
+        (WebCore::Font::glyphZeroWidth):
+        (WebCore::Font::isZeroWidthSpaceGlyph):
+        (WebCore::Font::zeroGlyph): Deleted.
+        (WebCore::Font::setZeroGlyph): Deleted.
+        (WebCore::Font::widthForGlyph): Deleted.
+        * platform/graphics/FontCascade.cpp:
+        (WebCore::offsetToMiddleOfGlyph):
+        * platform/graphics/FontCascadeFonts.cpp:
+        (WebCore::FontCascadeFonts::glyphDataForCharacter):
+        * platform/graphics/GlyphPage.h:
+        (WebCore::GlyphData::GlyphData):
+
+            Return width too as part of GlyphData.
+
+        (WebCore::GlyphPage::glyphDataForIndex):
+        (WebCore::GlyphPage::setGlyphDataForCharacter):
+        (WebCore::GlyphPage::setGlyphDataForIndex):
+        (WebCore::GlyphPage::GlyphPage):
+        * platform/graphics/WidthIterator.cpp:
+        (WebCore::WidthIterator::advanceInternal):
+
+            No need to lookup width separately now.
+
+        * platform/graphics/mac/ComplexTextController.cpp:
+        (WebCore::ComplexTextController::adjustGlyphsAndAdvances):
+        * platform/graphics/mac/ComplexTextControllerCoreText.mm:
+        (WebCore::ComplexTextController::ComplexTextRun::ComplexTextRun):
+        * rendering/mathml/RenderMathMLOperator.cpp:
+        (WebCore::RenderMathMLOperator::advanceForGlyph):
+        * rendering/svg/SVGTextRunRenderingContext.cpp:
+        (WebCore::missingGlyphForFont):
+        * svg/SVGFontData.cpp:
+        (WebCore::SVGFontData::initializeFont):
+
</ins><span class="cx"> 2015-02-26  Alexey Proskuryakov  &lt;ap@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         iOS build fix after r180717.
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsFontcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/Font.cpp (180751 => 180752)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/Font.cpp        2015-02-27 14:57:19 UTC (rev 180751)
+++ trunk/Source/WebCore/platform/graphics/Font.cpp        2015-02-27 16:12:13 UTC (rev 180752)
</span><span class="lines">@@ -54,16 +54,9 @@
</span><span class="cx">     : m_maxCharWidth(-1)
</span><span class="cx">     , m_avgCharWidth(-1)
</span><span class="cx">     , m_platformData(platformData)
</span><del>-    , m_treatAsFixedPitch(false)
</del><span class="cx">     , m_isCustomFont(isCustomFont)
</span><span class="cx">     , m_isLoading(isLoading)
</span><span class="cx">     , m_isTextOrientationFallback(isTextOrientationFallback)
</span><del>-    , m_isBrokenIdeographFallback(false)
-    , m_mathData(nullptr)
-#if ENABLE(OPENTYPE_VERTICAL)
-    , m_verticalData(0)
-#endif
-    , m_hasVerticalGlyphs(false)
</del><span class="cx"> {
</span><span class="cx">     platformInit();
</span><span class="cx">     platformGlyphInit();
</span><span class="lines">@@ -79,19 +72,7 @@
</span><span class="cx"> Font::Font(std::unique_ptr&lt;SVGData&gt; svgData, float fontSize, bool syntheticBold, bool syntheticItalic)
</span><span class="cx">     : m_platformData(FontPlatformData(fontSize, syntheticBold, syntheticItalic))
</span><span class="cx">     , m_svgData(WTF::move(svgData))
</span><del>-    , m_treatAsFixedPitch(false)
</del><span class="cx">     , m_isCustomFont(true)
</span><del>-    , m_isLoading(false)
-    , m_isTextOrientationFallback(false)
-    , m_isBrokenIdeographFallback(false)
-    , m_mathData(nullptr)
-#if ENABLE(OPENTYPE_VERTICAL)
-    , m_verticalData(0)
-#endif
-    , m_hasVerticalGlyphs(false)
-#if PLATFORM(IOS)
-    , m_shouldNotBeUsedForArabic(false)
-#endif
</del><span class="cx"> {
</span><span class="cx">     m_svgData-&gt;initializeFont(this, fontSize);
</span><span class="cx"> }
</span><span class="lines">@@ -106,7 +87,7 @@
</span><span class="cx">         static const UChar32 digitZeroChar = '0';
</span><span class="cx">         Glyph digitZeroGlyph = glyphPageZero-&gt;glyphDataForCharacter(digitZeroChar).glyph;
</span><span class="cx">         if (digitZeroGlyph)
</span><del>-            m_avgCharWidth = widthForGlyph(digitZeroGlyph);
</del><ins>+            m_avgCharWidth = computeWidthForGlyph(digitZeroGlyph);
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     // If we can't retrieve the width of a '0', fall back to the x height.
</span><span class="lines">@@ -121,35 +102,37 @@
</span><span class="cx"> {
</span><span class="cx">     auto* glyphPageZero = glyphPage(0);
</span><span class="cx">     if (!glyphPageZero) {
</span><del>-        m_spaceGlyph = 0;
-        m_spaceWidth = 0;
-        m_zeroGlyph = 0;
-        m_adjustedSpaceWidth = 0;
</del><span class="cx">         determinePitch();
</span><del>-        m_zeroWidthSpaceGlyph = 0;
</del><span class="cx">         return;
</span><span class="cx">     }
</span><del>-
</del><span class="cx">     // Ask for the glyph for 0 to avoid paging in ZERO WIDTH SPACE. Control characters, including 0,
</span><span class="cx">     // are mapped to the ZERO WIDTH SPACE glyph.
</span><span class="cx">     m_zeroWidthSpaceGlyph = glyphPageZero-&gt;glyphDataForCharacter(0).glyph;
</span><del>-
</del><span class="cx">     // Nasty hack to determine if we should round or ceil space widths.
</span><span class="cx">     // If the font is monospace or fake monospace we ceil to ensure that 
</span><span class="cx">     // every character and the space are the same width. Otherwise we round.
</span><del>-    m_spaceGlyph = glyphPageZero-&gt;glyphDataForCharacter(' ').glyph;
-    float width = widthForGlyph(m_spaceGlyph);
-    m_spaceWidth = width;
-    m_zeroGlyph = glyphPageZero-&gt;glyphDataForCharacter('0').glyph;
-    m_fontMetrics.setZeroWidth(widthForGlyph(m_zeroGlyph));
</del><ins>+    auto spaceGlyphData = glyphPageZero-&gt;glyphDataForCharacter(' ');
+    m_spaceGlyph = spaceGlyphData.glyph;
+    m_spaceWidth = spaceGlyphData.width;
+    m_fontMetrics.setZeroWidth(glyphPageZero-&gt;glyphDataForCharacter('0').width);
</ins><span class="cx">     determinePitch();
</span><del>-    m_adjustedSpaceWidth = m_treatAsFixedPitch ? ceilf(width) : roundf(width);
</del><ins>+    m_adjustedSpaceWidth = m_treatAsFixedPitch ? ceilf(m_spaceWidth) : roundf(m_spaceWidth);
+    m_glyphZeroWidth = computeWidthForGlyph(0);
</ins><span class="cx"> 
</span><span class="cx">     // Force the glyph for ZERO WIDTH SPACE to have zero width, unless it is shared with SPACE.
</span><span class="cx">     // Helvetica is an example of a non-zero width ZERO WIDTH SPACE glyph.
</span><span class="cx">     // See &lt;http://bugs.webkit.org/show_bug.cgi?id=13178&gt; and Font::isZeroWidthSpaceGlyph()
</span><span class="cx">     if (m_zeroWidthSpaceGlyph == m_spaceGlyph)
</span><span class="cx">         m_zeroWidthSpaceGlyph = 0;
</span><ins>+    else {
+        // Fixup the page zero now that we know the zero width glyph.
+        for (unsigned i = 0; i &lt; GlyphPage::size; ++i) {
+            auto glyphData = m_glyphPageZero-&gt;glyphDataForIndex(i);
+            if (glyphData.glyph == m_zeroWidthSpaceGlyph)
+                m_glyphPageZero-&gt;setGlyphDataForIndex(i, { glyphData.glyph, 0, glyphData.font });
+        }
+    }
+    m_glyphPageZero-&gt;setImmutable();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> Font::~Font()
</span><span class="lines">@@ -171,7 +154,7 @@
</span><span class="cx">     return hasGlyphs;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-static RefPtr&lt;GlyphPage&gt; createAndFillGlyphPage(unsigned pageNumber, const Font* font)
</del><ins>+RefPtr&lt;GlyphPage&gt; createAndFillGlyphPage(unsigned pageNumber, const Font* font)
</ins><span class="cx"> {
</span><span class="cx"> #if PLATFORM(IOS)
</span><span class="cx">     // FIXME: Times New Roman contains Arabic glyphs, but Core Text doesn't know how to shape them. See &lt;rdar://problem/9823975&gt;.
</span><span class="lines">@@ -244,22 +227,45 @@
</span><span class="cx">     if (!haveGlyphs)
</span><span class="cx">         return nullptr;
</span><span class="cx"> 
</span><del>-    glyphPage-&gt;setImmutable();
</del><span class="cx">     return glyphPage;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+float Font::computeWidthForGlyph(Glyph glyph) const
+{
+    if (isZeroWidthSpaceGlyph(glyph))
+        return 0;
+    float width;
+    if (isSVGFont())
+        width = m_svgData-&gt;widthForSVGGlyph(glyph, m_platformData.size());
+#if ENABLE(OPENTYPE_VERTICAL)
+    else if (m_verticalData)
+#if USE(CG) || USE(CAIRO)
+        width = m_verticalData-&gt;advanceHeight(this, glyph) + m_syntheticBoldOffset;
+#else
+        width = m_verticalData-&gt;advanceHeight(this, glyph);
+#endif
+#endif
+    else
+        width = platformWidthForGlyph(glyph);
+    return width;
+}
+
</ins><span class="cx"> const GlyphPage* Font::glyphPage(unsigned pageNumber) const
</span><span class="cx"> {
</span><span class="cx">     if (!pageNumber) {
</span><span class="cx">         if (!m_glyphPageZero)
</span><span class="cx">             m_glyphPageZero = createAndFillGlyphPage(0, this);
</span><ins>+        // Zero page is marked immutable in platformGlyphInit.
</ins><span class="cx">         return m_glyphPageZero.get();
</span><span class="cx">     }
</span><span class="cx">     auto addResult = m_glyphPages.add(pageNumber, nullptr);
</span><del>-    if (addResult.isNewEntry)
-        addResult.iterator-&gt;value = createAndFillGlyphPage(pageNumber, this);
-
-    return addResult.iterator-&gt;value.get();
</del><ins>+    auto&amp; page = addResult.iterator-&gt;value;
+    if (addResult.isNewEntry) {
+        page = createAndFillGlyphPage(pageNumber, this);
+        if (page)
+            page-&gt;setImmutable();
+    }
+    return page.get();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> Glyph Font::glyphForCharacter(UChar32 character) const
</span><span class="lines">@@ -458,4 +464,10 @@
</span><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void GlyphPage::setGlyphDataForIndex(unsigned index, Glyph glyph, const Font* font)
+{
+    setGlyphDataForIndex(index, { glyph, font ? font-&gt;computeWidthForGlyph(glyph) : 0, font });
+}
+
+
</ins><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsFonth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/Font.h (180751 => 180752)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/Font.h        2015-02-27 14:57:19 UTC (rev 180751)
+++ trunk/Source/WebCore/platform/graphics/Font.h        2015-02-27 16:12:13 UTC (rev 180752)
</span><span class="lines">@@ -140,10 +140,9 @@
</span><span class="cx">     void setAvgCharWidth(float avgCharWidth) { m_avgCharWidth = avgCharWidth; }
</span><span class="cx"> 
</span><span class="cx">     FloatRect boundsForGlyph(Glyph) const;
</span><del>-    float widthForGlyph(Glyph) const;
-    FloatRect platformBoundsForGlyph(Glyph) const;
-    float platformWidthForGlyph(Glyph) const;
</del><span class="cx"> 
</span><ins>+    float computeWidthForGlyph(Glyph) const;
+
</ins><span class="cx">     float spaceWidth() const { return m_spaceWidth; }
</span><span class="cx">     float adjustedSpaceWidth() const { return m_adjustedSpaceWidth; }
</span><span class="cx">     void setSpaceWidths(float spaceWidth)
</span><span class="lines">@@ -151,6 +150,7 @@
</span><span class="cx">         m_spaceWidth = spaceWidth;
</span><span class="cx">         m_adjustedSpaceWidth = spaceWidth;
</span><span class="cx">     }
</span><ins>+    float glyphZeroWidth() const { return m_glyphZeroWidth; }
</ins><span class="cx"> 
</span><span class="cx"> #if USE(CG) || USE(CAIRO)
</span><span class="cx">     float syntheticBoldOffset() const { return m_syntheticBoldOffset; }
</span><span class="lines">@@ -161,8 +161,6 @@
</span><span class="cx">     Glyph zeroWidthSpaceGlyph() const { return m_zeroWidthSpaceGlyph; }
</span><span class="cx">     void setZeroWidthSpaceGlyph(Glyph spaceGlyph) { m_zeroWidthSpaceGlyph = spaceGlyph; }
</span><span class="cx">     bool isZeroWidthSpaceGlyph(Glyph glyph) const { return glyph == m_zeroWidthSpaceGlyph &amp;&amp; glyph; }
</span><del>-    Glyph zeroGlyph() const { return m_zeroGlyph; }
-    void setZeroGlyph(Glyph zeroGlyph) { m_zeroGlyph = zeroGlyph; }
</del><span class="cx"> 
</span><span class="cx">     GlyphData glyphDataForCharacter(UChar32) const;
</span><span class="cx">     Glyph glyphForCharacter(UChar32) const;
</span><span class="lines">@@ -227,8 +225,13 @@
</span><span class="cx">     PassRefPtr&lt;Font&gt; createScaledFont(const FontDescription&amp;, float scaleFactor) const;
</span><span class="cx">     PassRefPtr&lt;Font&gt; platformCreateScaledFont(const FontDescription&amp;, float scaleFactor) const;
</span><span class="cx"> 
</span><ins>+    float platformWidthForGlyph(Glyph) const;
+    FloatRect platformBoundsForGlyph(Glyph) const;
+
</ins><span class="cx">     void removeFromSystemFallbackCache();
</span><span class="cx"> 
</span><ins>+    friend RefPtr&lt;GlyphPage&gt; createAndFillGlyphPage(unsigned pageNumber, const Font*);
+
</ins><span class="cx"> #if PLATFORM(WIN)
</span><span class="cx">     void initGDIFont();
</span><span class="cx">     void platformCommonDestroy();
</span><span class="lines">@@ -246,14 +249,13 @@
</span><span class="cx">     mutable RefPtr&lt;GlyphPage&gt; m_glyphPageZero;
</span><span class="cx">     mutable HashMap&lt;unsigned, RefPtr&lt;GlyphPage&gt;&gt; m_glyphPages;
</span><span class="cx">     mutable std::unique_ptr&lt;GlyphMetricsMap&lt;FloatRect&gt;&gt; m_glyphToBoundsMap;
</span><del>-    mutable GlyphMetricsMap&lt;float&gt; m_glyphToWidthMap;
</del><span class="cx"> 
</span><del>-    bool m_treatAsFixedPitch;
-    bool m_isCustomFont; // Whether or not we are custom font loaded via @font-face
-    bool m_isLoading; // Whether or not this custom font is still in the act of loading.
</del><ins>+    bool m_treatAsFixedPitch { false };
+    bool m_isCustomFont { false }; // Whether or not we are custom font loaded via @font-face
+    bool m_isLoading { false }; // Whether or not this custom font is still in the act of loading.
</ins><span class="cx"> 
</span><del>-    bool m_isTextOrientationFallback;
-    bool m_isBrokenIdeographFallback;
</del><ins>+    bool m_isTextOrientationFallback { false };
+    bool m_isBrokenIdeographFallback { false };
</ins><span class="cx"> 
</span><span class="cx">     bool m_isUsedInSystemFallbackCache { false };
</span><span class="cx"> 
</span><span class="lines">@@ -261,15 +263,16 @@
</span><span class="cx"> #if ENABLE(OPENTYPE_VERTICAL)
</span><span class="cx">     RefPtr&lt;OpenTypeVerticalData&gt; m_verticalData;
</span><span class="cx"> #endif
</span><del>-    bool m_hasVerticalGlyphs;
</del><ins>+    bool m_hasVerticalGlyphs { false };
</ins><span class="cx"> 
</span><del>-    Glyph m_spaceGlyph;
-    float m_spaceWidth;
-    Glyph m_zeroGlyph;
-    float m_adjustedSpaceWidth;
</del><ins>+    Glyph m_spaceGlyph { 0 };
+    float m_spaceWidth { 0 };
+    float m_adjustedSpaceWidth { 0 };
</ins><span class="cx"> 
</span><del>-    Glyph m_zeroWidthSpaceGlyph;
</del><ins>+    Glyph m_zeroWidthSpaceGlyph { 0 };
</ins><span class="cx"> 
</span><ins>+    float m_glyphZeroWidth { 0 };
+
</ins><span class="cx">     struct DerivedFontData {
</span><span class="cx">         explicit DerivedFontData(bool custom)
</span><span class="cx">             : forCustomFont(custom)
</span><span class="lines">@@ -309,7 +312,7 @@
</span><span class="cx">     mutable SCRIPT_FONTPROPERTIES* m_scriptFontProperties;
</span><span class="cx"> #endif
</span><span class="cx"> #if PLATFORM(IOS)
</span><del>-    bool m_shouldNotBeUsedForArabic;
</del><ins>+    bool m_shouldNotBeUsedForArabic { false };
</ins><span class="cx"> #endif
</span><span class="cx"> };
</span><span class="cx"> 
</span><span class="lines">@@ -332,32 +335,6 @@
</span><span class="cx">     return bounds;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-ALWAYS_INLINE float Font::widthForGlyph(Glyph glyph) const
-{
-    if (isZeroWidthSpaceGlyph(glyph))
-        return 0;
-
-    float width = m_glyphToWidthMap.metricsForGlyph(glyph);
-    if (width != cGlyphSizeUnknown)
-        return width;
-
-    if (isSVGFont())
-        width = m_svgData-&gt;widthForSVGGlyph(glyph, m_platformData.size());
-#if ENABLE(OPENTYPE_VERTICAL)
-    else if (m_verticalData)
-#if USE(CG) || USE(CAIRO)
-        width = m_verticalData-&gt;advanceHeight(this, glyph) + m_syntheticBoldOffset;
-#else
-        width = m_verticalData-&gt;advanceHeight(this, glyph);
-#endif
-#endif
-    else
-        width = platformWidthForGlyph(glyph);
-
-    m_glyphToWidthMap.setMetricsForGlyph(glyph, width);
-    return width;
-}
-
</del><span class="cx"> } // namespace WebCore
</span><span class="cx"> 
</span><span class="cx"> #endif // Font_h
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsFontCascadecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/FontCascade.cpp (180751 => 180752)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/FontCascade.cpp        2015-02-27 14:57:19 UTC (rev 180751)
+++ trunk/Source/WebCore/platform/graphics/FontCascade.cpp        2015-02-27 16:12:13 UTC (rev 180752)
</span><span class="lines">@@ -1334,7 +1334,7 @@
</span><span class="cx">         return bounds.x() + bounds.width() / 2;
</span><span class="cx">     }
</span><span class="cx">     // FIXME: Use glyph bounds once they make sense for vertical fonts.
</span><del>-    return fontData-&gt;widthForGlyph(glyph) / 2;
</del><ins>+    return fontData-&gt;computeWidthForGlyph(glyph) / 2;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> inline static float offsetToMiddleOfGlyphAtIndex(const GlyphBuffer&amp; glyphBuffer, size_t i)
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsFontCascadeFontscpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/FontCascadeFonts.cpp (180751 => 180752)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/FontCascadeFonts.cpp        2015-02-27 14:57:19 UTC (rev 180751)
+++ trunk/Source/WebCore/platform/graphics/FontCascadeFonts.cpp        2015-02-27 16:12:13 UTC (rev 180752)
</span><span class="lines">@@ -387,7 +387,7 @@
</span><span class="cx">             cachedPage = GlyphPage::createCopyForMixedFonts(*cachedPage);
</span><span class="cx"> 
</span><span class="cx">         glyphData = glyphDataForNormalVariant(c, description);
</span><del>-        cachedPage-&gt;setGlyphDataForCharacter(c, glyphData.glyph, glyphData.font);
</del><ins>+        cachedPage-&gt;setGlyphDataForCharacter(c, glyphData);
</ins><span class="cx">     }
</span><span class="cx">     return glyphData;
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsGlyphPageh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/GlyphPage.h (180751 => 180752)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/GlyphPage.h        2015-02-27 14:57:19 UTC (rev 180751)
+++ trunk/Source/WebCore/platform/graphics/GlyphPage.h        2015-02-27 16:12:13 UTC (rev 180752)
</span><span class="lines">@@ -44,13 +44,16 @@
</span><span class="cx"> // Holds the glyph index and the corresponding Font information for a given
</span><span class="cx"> // character.
</span><span class="cx"> struct GlyphData {
</span><del>-    GlyphData(Glyph g = 0, const Font* f = 0)
-        : glyph(g)
-        , font(f)
-    {
-    }
-    Glyph glyph;
-    const Font* font;
</del><ins>+    GlyphData() { }
+    GlyphData(Glyph glyph, float width, const Font* font)
+        : glyph(glyph)
+        , width(width)
+        , font(font)
+    { }
+
+    Glyph glyph { 0 };
+    float width { 0 };
+    const Font* font { nullptr };
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> #if COMPILER(MSVC)
</span><span class="lines">@@ -109,9 +112,10 @@
</span><span class="cx">     {
</span><span class="cx">         ASSERT_WITH_SECURITY_IMPLICATION(index &lt; size);
</span><span class="cx">         Glyph glyph = m_glyphs[index];
</span><ins>+        float width = m_widths[index];
</ins><span class="cx">         if (hasPerGlyphFontData())
</span><del>-            return GlyphData(glyph, m_perGlyphFontData[index]);
-        return GlyphData(glyph, glyph ? m_fontForAllGlyphs : 0);
</del><ins>+            return { glyph, width, m_perGlyphFontData[index] };
+        return { glyph, width, glyph ? m_fontForAllGlyphs : nullptr };
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     ALWAYS_INLINE Glyph glyphAt(unsigned index) const
</span><span class="lines">@@ -128,33 +132,31 @@
</span><span class="cx">         return m_glyphs[index] ? m_fontForAllGlyphs : 0;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    void setGlyphDataForCharacter(UChar32 c, Glyph g, const Font* f)
</del><ins>+    void setGlyphDataForCharacter(UChar32 c, const GlyphData&amp; glyphData)
</ins><span class="cx">     {
</span><del>-        setGlyphDataForIndex(indexForCharacter(c), g, f);
</del><ins>+        setGlyphDataForIndex(indexForCharacter(c), glyphData);
</ins><span class="cx">     }
</span><span class="cx"> 
</span><del>-    void setGlyphDataForIndex(unsigned index, Glyph glyph, const Font* font)
</del><ins>+    void setGlyphDataForIndex(unsigned index, Glyph, const Font*);
+
+    void setGlyphDataForIndex(unsigned index, const GlyphData&amp; glyphData)
</ins><span class="cx">     {
</span><span class="cx">         ASSERT_WITH_SECURITY_IMPLICATION(index &lt; size);
</span><span class="cx">         ASSERT(!m_isImmutable);
</span><del>-        
-        m_glyphs[index] = glyph;
</del><span class="cx"> 
</span><ins>+        m_glyphs[index] = glyphData.glyph;
+        m_widths[index] = glyphData.width;
+
</ins><span class="cx">         // GlyphPage getters will always return a null Font* for glyph #0 if there's no per-glyph font array.
</span><span class="cx">         if (hasPerGlyphFontData()) {
</span><del>-            m_perGlyphFontData[index] = glyph ? font : 0;
</del><ins>+            m_perGlyphFontData[index] =  glyphData.glyph ?  glyphData.font : 0;
</ins><span class="cx">             return;
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         // A single-font GlyphPage already assigned m_fontForAllGlyphs in the constructor.
</span><del>-        ASSERT(!glyph || font == m_fontForAllGlyphs);
</del><ins>+        ASSERT(!glyphData.glyph || glyphData.font == m_fontForAllGlyphs);
</ins><span class="cx">     }
</span><span class="cx"> 
</span><del>-    void setGlyphDataForIndex(unsigned index, const GlyphData&amp; glyphData)
-    {
-        setGlyphDataForIndex(index, glyphData.glyph, glyphData.font);
-    }
-
</del><span class="cx">     // Implemented by the platform.
</span><span class="cx">     bool fill(unsigned offset, unsigned length, UChar* characterBuffer, unsigned bufferLength, const Font*);
</span><span class="cx"> #if PLATFORM(COCOA)
</span><span class="lines">@@ -168,6 +170,7 @@
</span><span class="cx">         : m_fontForAllGlyphs(fontForAllGlyphs)
</span><span class="cx">     {
</span><span class="cx">         memset(m_glyphs, 0, sizeof(m_glyphs));
</span><ins>+        memset(m_widths, 0, sizeof(m_widths));
</ins><span class="cx">         if (hasPerGlyphFontData())
</span><span class="cx">             memset(m_perGlyphFontData, 0, sizeof(Font*) * GlyphPage::size);
</span><span class="cx">         ++s_count;
</span><span class="lines">@@ -175,8 +178,9 @@
</span><span class="cx"> 
</span><span class="cx">     bool hasPerGlyphFontData() const { return !m_fontForAllGlyphs; }
</span><span class="cx"> 
</span><del>-    const Font* m_fontForAllGlyphs;
</del><ins>+    const Font* m_fontForAllGlyphs { nullptr };
</ins><span class="cx">     Glyph m_glyphs[size];
</span><ins>+    float m_widths[size];
</ins><span class="cx"> 
</span><span class="cx">     bool m_isImmutable { false };
</span><span class="cx">     // NOTE: This array has (GlyphPage::size) elements if m_fontForAllGlyphs is null.
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsWidthIteratorcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/WidthIterator.cpp (180751 => 180752)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/WidthIterator.cpp        2015-02-27 14:57:19 UTC (rev 180751)
+++ trunk/Source/WebCore/platform/graphics/WidthIterator.cpp        2015-02-27 16:12:13 UTC (rev 180752)
</span><span class="lines">@@ -191,7 +191,7 @@
</span><span class="cx">         if (character == '\t' &amp;&amp; m_run.allowTabs())
</span><span class="cx">             width = m_font-&gt;tabWidth(*font, m_run.tabSize(), m_run.xPos() + m_runWidthSoFar + widthSinceLastRounding);
</span><span class="cx">         else {
</span><del>-            width = font-&gt;widthForGlyph(glyph);
</del><ins>+            width = glyphData.width;
</ins><span class="cx"> 
</span><span class="cx">             // SVG uses horizontalGlyphStretch(), when textLength is used to stretch/squeeze text.
</span><span class="cx">             width *= m_run.horizontalGlyphStretch();
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsmacComplexTextControllercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/mac/ComplexTextController.cpp (180751 => 180752)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/mac/ComplexTextController.cpp        2015-02-27 14:57:19 UTC (rev 180751)
+++ trunk/Source/WebCore/platform/graphics/mac/ComplexTextController.cpp        2015-02-27 16:12:13 UTC (rev 180752)
</span><span class="lines">@@ -638,7 +638,7 @@
</span><span class="cx">             CGSize advance = treatAsSpace ? CGSizeMake(spaceWidth, advances[i].height) : advances[i];
</span><span class="cx"> #if PLATFORM(IOS)
</span><span class="cx">             if (isEmoji &amp;&amp; advance.width)
</span><del>-                advance.width = font.widthForGlyph(glyph);
</del><ins>+                advance.width = font.computeWidthForGlyph(glyph);
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx">             if (ch == '\t' &amp;&amp; m_run.allowTabs())
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsmacComplexTextControllerCoreTextmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/mac/ComplexTextControllerCoreText.mm (180751 => 180752)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/mac/ComplexTextControllerCoreText.mm        2015-02-27 14:57:19 UTC (rev 180751)
+++ trunk/Source/WebCore/platform/graphics/mac/ComplexTextControllerCoreText.mm        2015-02-27 16:12:13 UTC (rev 180752)
</span><span class="lines">@@ -163,7 +163,7 @@
</span><span class="cx">     // Synthesize a run of missing glyphs.
</span><span class="cx">     m_glyphsVector.fill(0, m_glyphCount);
</span><span class="cx">     m_glyphs = m_glyphsVector.data();
</span><del>-    m_advancesVector.fill(CGSizeMake(m_font.widthForGlyph(0), 0), m_glyphCount);
</del><ins>+    m_advancesVector.fill(CGSizeMake(m_font.glyphZeroWidth(), 0), m_glyphCount);
</ins><span class="cx">     m_advances = m_advancesVector.data();
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingmathmlRenderMathMLOperatorcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/mathml/RenderMathMLOperator.cpp (180751 => 180752)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/mathml/RenderMathMLOperator.cpp        2015-02-27 14:57:19 UTC (rev 180751)
+++ trunk/Source/WebCore/rendering/mathml/RenderMathMLOperator.cpp        2015-02-27 16:12:13 UTC (rev 180752)
</span><span class="lines">@@ -1343,7 +1343,8 @@
</span><span class="cx"> 
</span><span class="cx"> float RenderMathMLOperator::advanceForGlyph(const GlyphData&amp; data) const
</span><span class="cx"> {
</span><del>-    return data.font-&gt;widthForGlyph(data.glyph);
</del><ins>+    // FIXME: MathML code synthesizes bad GlyphDatas.
+    return data.width ? data.width : data.font-&gt;computeWidthForGlyph(data.glyph);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void RenderMathMLOperator::computePreferredLogicalWidths()
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingsvgSVGTextRunRenderingContextcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/svg/SVGTextRunRenderingContext.cpp (180751 => 180752)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/svg/SVGTextRunRenderingContext.cpp        2015-02-27 14:57:19 UTC (rev 180751)
+++ trunk/Source/WebCore/rendering/svg/SVGTextRunRenderingContext.cpp        2015-02-27 16:12:13 UTC (rev 180752)
</span><span class="lines">@@ -298,7 +298,8 @@
</span><span class="cx">     SVGFontElement* fontElement;
</span><span class="cx">     SVGFontFaceElement* fontFaceElement;
</span><span class="cx">     svgFontAndFontFaceElementForFontData(&amp;primaryFont, fontFaceElement, fontElement);
</span><del>-    return GlyphData(fontElement-&gt;missingGlyph(), &amp;primaryFont);
</del><ins>+    auto missingGlyph = fontElement-&gt;missingGlyph();
+    return { missingGlyph, primaryFont.computeWidthForGlyph(missingGlyph), &amp;primaryFont };
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> GlyphData SVGTextRunRenderingContext::glyphDataForCharacter(const FontCascade&amp; font, WidthIterator&amp; iterator, UChar32 character, bool mirror, int currentCharacter, unsigned&amp; advanceLength, String&amp; normalizedSpacesStringCache)
</span></span></pre></div>
<a id="trunkSourceWebCoresvgSVGFontDatacpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/svg/SVGFontData.cpp (180751 => 180752)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/svg/SVGFontData.cpp        2015-02-27 14:57:19 UTC (rev 180751)
+++ trunk/Source/WebCore/svg/SVGFontData.cpp        2015-02-27 16:12:13 UTC (rev 180752)
</span><span class="lines">@@ -79,7 +79,7 @@
</span><span class="cx">     if (!xHeight &amp;&amp; glyphPageZero) {
</span><span class="cx">         // Fallback if x_heightAttr is not specified for the font element.
</span><span class="cx">         Glyph letterXGlyph = glyphPageZero-&gt;glyphDataForCharacter('x').glyph;
</span><del>-        xHeight = letterXGlyph ? font-&gt;widthForGlyph(letterXGlyph) : 2 * ascent / 3;
</del><ins>+        xHeight = letterXGlyph ? font-&gt;computeWidthForGlyph(letterXGlyph) : 2 * ascent / 3;
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     FontMetrics&amp; fontMetrics = font-&gt;fontMetrics();
</span><span class="lines">@@ -99,17 +99,17 @@
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     // Calculate space width.
</span><del>-    Glyph spaceGlyph = glyphPageZero-&gt;glyphDataForCharacter(' ').glyph;
-    font-&gt;setSpaceGlyph(spaceGlyph);
-    font-&gt;setSpaceWidths(font-&gt;widthForGlyph(spaceGlyph));
</del><ins>+    auto spaceGlyphData = glyphPageZero-&gt;glyphDataForCharacter(' ');
+    font-&gt;setSpaceGlyph(spaceGlyphData.glyph);
+    font-&gt;setSpaceWidths(spaceGlyphData.width);
</ins><span class="cx"> 
</span><span class="cx">     // Estimate average character width.
</span><del>-    Glyph numeralZeroGlyph = glyphPageZero-&gt;glyphDataForCharacter('0').glyph;
-    font-&gt;setAvgCharWidth(numeralZeroGlyph ? font-&gt;widthForGlyph(numeralZeroGlyph) : font-&gt;spaceWidth());
</del><ins>+    auto numeralZeroGlyphData = glyphPageZero-&gt;glyphDataForCharacter('0');
+    font-&gt;setAvgCharWidth(numeralZeroGlyphData.glyph ? numeralZeroGlyphData.width : font-&gt;spaceWidth());
</ins><span class="cx"> 
</span><span class="cx">     // Estimate maximum character width.
</span><del>-    Glyph letterWGlyph = glyphPageZero-&gt;glyphDataForCharacter('W').glyph;
-    font-&gt;setMaxCharWidth(letterWGlyph ? font-&gt;widthForGlyph(letterWGlyph) : ascent);
</del><ins>+    auto letterWGlyphData = glyphPageZero-&gt;glyphDataForCharacter('W');
+    font-&gt;setMaxCharWidth(letterWGlyphData.glyph ? letterWGlyphData.width : ascent);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> float SVGFontData::widthForSVGGlyph(Glyph glyph, float fontSize) const
</span></span></pre>
</div>
</div>

</body>
</html>