<!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>[183878] 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/183878">183878</a></dd>
<dt>Author</dt> <dd>mrobinson@webkit.org</dd>
<dt>Date</dt> <dd>2015-05-06 10:52:43 -0700 (Wed, 06 May 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>[FreeType] Vertical CJK glyphs should not be rendered with synthetic oblique
https://bugs.webkit.org/show_bug.cgi?id=144612

Reviewed by Darin Adler.

Source/WebCore:

No new tests. This causes fast/text/international/synthesized-italic-vertical.html to pass.

* platform/graphics/Font.cpp:
(WebCore::Font::nonSyntheticItalicFont): Compile this method for Cairo as well.
* platform/graphics/FontCascadeFonts.cpp:
(WebCore::FontCascadeFonts::glyphDataForSystemFallback): When searching for the system fallback,
ensure that we do not use synthetic oblique when rendering vertical CJK glyphs.
(WebCore::FontCascadeFonts::glyphDataForNormalVariant): Extend the CJK fix to Cairo ports.
* platform/graphics/FontPlatformData.h:
(WebCore::FontPlatformData::setSyntheticOblique): Added this helper method, because
Freetype/Cairo ports needs to be able to recreate the scaled font matrix when the
synthetic oblique settings changes.
* platform/graphics/freetype/FontPlatformData.h: Rename initializeWithFontFace to buildScaledFont.
Remove the now unused m_horizontalOrientationMatrix member.
(WebCore::FontPlatformData::setSyntheticOblique): Added the helper here as well.
* platform/graphics/freetype/FontPlatformDataFreeType.cpp:
(WebCore::FontPlatformData::FontPlatformData): Calculate whether or not to use synthetic oblique here,
before buildScaledFont is called. Call buildScaledFont instead of initializeWithFontFace.
(WebCore::FontPlatformData::operator=):
(WebCore::FontPlatformData::buildScaledFont): Renamed from initializeWithFontFace, does
the same thing, except calculate whether or not to use synthetic oblique. Instead just
reads the value.
(WebCore::FontPlatformData::setOrientation): Instead of adjusting the font matrix, recreate
the entire font.
(WebCore::FontPlatformData::setSyntheticOblique): Added.
(WebCore::rotateCairoMatrixForVerticalOrientation): Deleted.
(WebCore::FontPlatformData::initializeWithFontFace): Deleted.

LayoutTests:

* platform/gtk/TestExpectations: Remove expectation for failing test.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsplatformgtkTestExpectations">trunk/LayoutTests/platform/gtk/TestExpectations</a></li>
<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="#trunkSourceWebCoreplatformgraphicsFontCascadeFontscpp">trunk/Source/WebCore/platform/graphics/FontCascadeFonts.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsFontPlatformDatah">trunk/Source/WebCore/platform/graphics/FontPlatformData.h</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsfreetypeFontPlatformDatah">trunk/Source/WebCore/platform/graphics/freetype/FontPlatformData.h</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsfreetypeFontPlatformDataFreeTypecpp">trunk/Source/WebCore/platform/graphics/freetype/FontPlatformDataFreeType.cpp</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (183877 => 183878)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2015-05-06 17:51:07 UTC (rev 183877)
+++ trunk/LayoutTests/ChangeLog        2015-05-06 17:52:43 UTC (rev 183878)
</span><span class="lines">@@ -1,5 +1,14 @@
</span><span class="cx"> 2015-05-06  Martin Robinson  &lt;mrobinson@igalia.com&gt;
</span><span class="cx"> 
</span><ins>+        [FreeType] Vertical CJK glyphs should not be rendered with synthetic oblique
+        https://bugs.webkit.org/show_bug.cgi?id=144612
+
+        Reviewed by Darin Adler.
+
+        * platform/gtk/TestExpectations: Remove expectation for failing test.
+
+2015-05-06  Martin Robinson  &lt;mrobinson@igalia.com&gt;
+
</ins><span class="cx">         Unreviewed GTK+ gardening
</span><span class="cx"> 
</span><span class="cx">         * platform/gtk/TestExpectations: Remove a couple expectations tests.
</span></span></pre></div>
<a id="trunkLayoutTestsplatformgtkTestExpectations"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/platform/gtk/TestExpectations (183877 => 183878)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/platform/gtk/TestExpectations        2015-05-06 17:51:07 UTC (rev 183877)
+++ trunk/LayoutTests/platform/gtk/TestExpectations        2015-05-06 17:52:43 UTC (rev 183878)
</span><span class="lines">@@ -2363,8 +2363,6 @@
</span><span class="cx"> webkit.org/b/144494 printing/quirks-percentage-height.html [ ImageOnlyFailure ]
</span><span class="cx"> webkit.org/b/144494 printing/standards-percentage-heights.html [ ImageOnlyFailure ]
</span><span class="cx"> 
</span><del>-webkit.org/b/144573 fast/text/international/synthesized-italic-vertical.html [ ImageOnlyFailure ]
-
</del><span class="cx"> webkit.org/b/144574 imported/mozilla/svg/objectBoundingBox-and-mask.svg [ ImageOnlyFailure ]
</span><span class="cx"> webkit.org/b/144574 imported/mozilla/svg/text/mask-applied.svg [ ImageOnlyFailure ]
</span><span class="cx"> webkit.org/b/144574 svg/masking/mask-negative-scale.svg [ ImageOnlyFailure ]
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (183877 => 183878)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2015-05-06 17:51:07 UTC (rev 183877)
+++ trunk/Source/WebCore/ChangeLog        2015-05-06 17:52:43 UTC (rev 183878)
</span><span class="lines">@@ -1,3 +1,38 @@
</span><ins>+2015-05-06  Martin Robinson  &lt;mrobinson@igalia.com&gt;
+
+        [FreeType] Vertical CJK glyphs should not be rendered with synthetic oblique
+        https://bugs.webkit.org/show_bug.cgi?id=144612
+
+        Reviewed by Darin Adler.
+
+        No new tests. This causes fast/text/international/synthesized-italic-vertical.html to pass.
+
+        * platform/graphics/Font.cpp:
+        (WebCore::Font::nonSyntheticItalicFont): Compile this method for Cairo as well.
+        * platform/graphics/FontCascadeFonts.cpp:
+        (WebCore::FontCascadeFonts::glyphDataForSystemFallback): When searching for the system fallback,
+        ensure that we do not use synthetic oblique when rendering vertical CJK glyphs.
+        (WebCore::FontCascadeFonts::glyphDataForNormalVariant): Extend the CJK fix to Cairo ports.
+        * platform/graphics/FontPlatformData.h:
+        (WebCore::FontPlatformData::setSyntheticOblique): Added this helper method, because
+        Freetype/Cairo ports needs to be able to recreate the scaled font matrix when the
+        synthetic oblique settings changes.
+        * platform/graphics/freetype/FontPlatformData.h: Rename initializeWithFontFace to buildScaledFont.
+        Remove the now unused m_horizontalOrientationMatrix member.
+        (WebCore::FontPlatformData::setSyntheticOblique): Added the helper here as well.
+        * platform/graphics/freetype/FontPlatformDataFreeType.cpp:
+        (WebCore::FontPlatformData::FontPlatformData): Calculate whether or not to use synthetic oblique here,
+        before buildScaledFont is called. Call buildScaledFont instead of initializeWithFontFace.
+        (WebCore::FontPlatformData::operator=):
+        (WebCore::FontPlatformData::buildScaledFont): Renamed from initializeWithFontFace, does
+        the same thing, except calculate whether or not to use synthetic oblique. Instead just
+        reads the value.
+        (WebCore::FontPlatformData::setOrientation): Instead of adjusting the font matrix, recreate
+        the entire font.
+        (WebCore::FontPlatformData::setSyntheticOblique): Added.
+        (WebCore::rotateCairoMatrixForVerticalOrientation): Deleted.
+        (WebCore::FontPlatformData::initializeWithFontFace): Deleted.
+
</ins><span class="cx"> 2015-05-06  Alex Christensen  &lt;achristensen@webkit.org&gt;
</span><span class="cx"> 
</span><span class="cx">         [Content Extensions] Test splitting NFAs by max NFA size.
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsFontcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/Font.cpp (183877 => 183878)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/Font.cpp        2015-05-06 17:51:07 UTC (rev 183877)
+++ trunk/Source/WebCore/platform/graphics/Font.cpp        2015-05-06 17:52:43 UTC (rev 183878)
</span><span class="lines">@@ -335,8 +335,8 @@
</span><span class="cx">         m_derivedFontData = std::make_unique&lt;DerivedFontData&gt;(isCustomFont());
</span><span class="cx">     if (!m_derivedFontData-&gt;nonSyntheticItalic) {
</span><span class="cx">         FontPlatformData nonSyntheticItalicFontPlatformData(m_platformData);
</span><del>-#if PLATFORM(COCOA)
-        nonSyntheticItalicFontPlatformData.m_syntheticOblique = false;
</del><ins>+#if PLATFORM(COCOA) || USE(CAIRO)
+        nonSyntheticItalicFontPlatformData.setSyntheticOblique(false);
</ins><span class="cx"> #endif
</span><span class="cx">         m_derivedFontData-&gt;nonSyntheticItalic = create(nonSyntheticItalicFontPlatformData, isCustomFont());
</span><span class="cx">     }
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsFontCascadeFontscpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/FontCascadeFonts.cpp (183877 => 183878)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/FontCascadeFonts.cpp        2015-05-06 17:51:07 UTC (rev 183877)
+++ trunk/Source/WebCore/platform/graphics/FontCascadeFonts.cpp        2015-05-06 17:52:43 UTC (rev 183878)
</span><span class="lines">@@ -218,7 +218,7 @@
</span><span class="cx">     return false;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-#if PLATFORM(COCOA)
</del><ins>+#if PLATFORM(COCOA) || USE(CAIRO)
</ins><span class="cx"> static GlyphData glyphDataForCJKCharacterWithoutSyntheticItalic(UChar32 character, GlyphData&amp; data)
</span><span class="cx"> {
</span><span class="cx">     GlyphData nonItalicData = data.font-&gt;nonSyntheticItalicFont()-&gt;glyphDataForCharacter(character);
</span><span class="lines">@@ -273,9 +273,13 @@
</span><span class="cx">     else
</span><span class="cx">         fallbackGlyphData = systemFallbackFont-&gt;variantFont(description, variant)-&gt;glyphDataForCharacter(c);
</span><span class="cx"> 
</span><del>-    if (variant == NormalVariant &amp;&amp; fallbackGlyphData.font) {
-        if (!FontCascade::isCJKIdeographOrSymbol(c) &amp;&amp; fallbackGlyphData.font-&gt;platformData().orientation() == Vertical &amp;&amp; !fallbackGlyphData.font-&gt;isTextOrientationFallback())
</del><ins>+    if (fallbackGlyphData.font &amp;&amp; fallbackGlyphData.font-&gt;platformData().orientation() == Vertical &amp;&amp; !fallbackGlyphData.font-&gt;isTextOrientationFallback()) {
+        if (variant == NormalVariant &amp;&amp; !FontCascade::isCJKIdeographOrSymbol(c))
</ins><span class="cx">             fallbackGlyphData = glyphDataForNonCJKCharacterWithGlyphOrientation(c, description.nonCJKGlyphOrientation(), fallbackGlyphData);
</span><ins>+#if PLATFORM(COCOA) || USE(CAIRO)
+        if (fallbackGlyphData.font-&gt;platformData().syntheticOblique() &amp;&amp; FontCascade::isCJKIdeographOrSymbol(c))
+            fallbackGlyphData = glyphDataForCJKCharacterWithoutSyntheticItalic(c, fallbackGlyphData);
+#endif
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     // Keep the system fallback fonts we use alive.
</span><span class="lines">@@ -330,7 +334,7 @@
</span><span class="cx">                     // to make sure you get a square (even for broken glyphs like symbols used for punctuation).
</span><span class="cx">                     return glyphDataForVariant(c, description, BrokenIdeographVariant, fallbackIndex);
</span><span class="cx">                 }
</span><del>-#if PLATFORM(COCOA)
</del><ins>+#if PLATFORM(COCOA) || USE(CAIRO)
</ins><span class="cx">                 if (data.font-&gt;platformData().syntheticOblique())
</span><span class="cx">                     return glyphDataForCJKCharacterWithoutSyntheticItalic(c, data);
</span><span class="cx"> #endif
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsFontPlatformDatah"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/FontPlatformData.h (183877 => 183878)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/FontPlatformData.h        2015-05-06 17:51:07 UTC (rev 183877)
+++ trunk/Source/WebCore/platform/graphics/FontPlatformData.h        2015-05-06 17:52:43 UTC (rev 183878)
</span><span class="lines">@@ -139,6 +139,7 @@
</span><span class="cx">     FontWidthVariant widthVariant() const { return m_widthVariant; }
</span><span class="cx"> 
</span><span class="cx">     void setOrientation(FontOrientation orientation) { m_orientation = orientation; }
</span><ins>+    void setSyntheticOblique(bool syntheticOblique) { m_syntheticOblique = syntheticOblique; }
</ins><span class="cx"> 
</span><span class="cx"> #if USE(CAIRO)
</span><span class="cx">     cairo_scaled_font_t* scaledFont() const { return m_scaledFont; }
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsfreetypeFontPlatformDatah"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/freetype/FontPlatformData.h (183877 => 183878)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/freetype/FontPlatformData.h        2015-05-06 17:51:07 UTC (rev 183877)
+++ trunk/Source/WebCore/platform/graphics/freetype/FontPlatformData.h        2015-05-06 17:52:43 UTC (rev 183878)
</span><span class="lines">@@ -77,6 +77,7 @@
</span><span class="cx">     void setSize(float size) { m_size = size; }
</span><span class="cx">     bool syntheticBold() const { return m_syntheticBold; }
</span><span class="cx">     bool syntheticOblique() const { return m_syntheticOblique; }
</span><ins>+    void setSyntheticOblique(bool);
</ins><span class="cx">     bool hasCompatibleCharmap();
</span><span class="cx"> 
</span><span class="cx">     FontOrientation orientation() const { return m_orientation; }
</span><span class="lines">@@ -112,11 +113,10 @@
</span><span class="cx">     mutable RefPtr&lt;HarfBuzzFace&gt; m_harfBuzzFace;
</span><span class="cx"> 
</span><span class="cx"> private:
</span><del>-    void initializeWithFontFace(cairo_font_face_t*, const FontDescription&amp; = FontDescription());
</del><ins>+    void buildScaledFont(cairo_font_face_t*);
</ins><span class="cx">     static cairo_scaled_font_t* hashTableDeletedFontValue() { return reinterpret_cast&lt;cairo_scaled_font_t*&gt;(-1); }
</span><span class="cx"> 
</span><span class="cx">     FontOrientation m_orientation;
</span><del>-    cairo_matrix_t m_horizontalOrientationMatrix;
</del><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsfreetypeFontPlatformDataFreeTypecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/freetype/FontPlatformDataFreeType.cpp (183877 => 183878)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/freetype/FontPlatformDataFreeType.cpp        2015-05-06 17:51:07 UTC (rev 183877)
+++ trunk/Source/WebCore/platform/graphics/freetype/FontPlatformDataFreeType.cpp        2015-05-06 17:52:43 UTC (rev 183878)
</span><span class="lines">@@ -134,16 +134,6 @@
</span><span class="cx">     return pattern;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-static void rotateCairoMatrixForVerticalOrientation(cairo_matrix_t* matrix)
-{
-    // The resulting transformation matrix for vertical glyphs (V) is a
-    // combination of rotation (R) and translation (T) applied on the
-    // horizontal matrix (H). V = H . R . T, where R rotates by -90 degrees
-    // and T translates by font size towards y axis.
-    cairo_matrix_rotate(matrix, -piOverTwoDouble);
-    cairo_matrix_translate(matrix, 0.0, 1.0);
-}
-
</del><span class="cx"> FontPlatformData::FontPlatformData(FcPattern* pattern, const FontDescription&amp; fontDescription)
</span><span class="cx">     : m_pattern(pattern)
</span><span class="cx">     , m_fallbacks(nullptr)
</span><span class="lines">@@ -154,8 +144,8 @@
</span><span class="cx">     , m_scaledFont(nullptr)
</span><span class="cx">     , m_orientation(fontDescription.orientation())
</span><span class="cx"> {
</span><ins>+    ASSERT(m_pattern);
</ins><span class="cx">     RefPtr&lt;cairo_font_face_t&gt; fontFace = adoptRef(cairo_ft_font_face_create_for_pattern(m_pattern.get()));
</span><del>-    initializeWithFontFace(fontFace.get(), fontDescription);
</del><span class="cx"> 
</span><span class="cx">     int spacing;
</span><span class="cx">     if (FcPatternGetInteger(pattern, FC_SPACING, 0, &amp;spacing) == FcResultMatch &amp;&amp; spacing == FC_MONO)
</span><span class="lines">@@ -173,6 +163,16 @@
</span><span class="cx">         if (!m_syntheticBold &amp;&amp; FcPatternGetInteger(pattern, FC_WEIGHT, 0, &amp;weight) == FcResultMatch)
</span><span class="cx">             m_syntheticBold = m_syntheticBold || weight &lt; FC_WEIGHT_DEMIBOLD;
</span><span class="cx">     }
</span><ins>+
+    // We requested an italic font, but Fontconfig gave us one that was neither oblique nor italic.
+    int actualFontSlant;
+    bool descriptionAllowsSyntheticOblique = fontDescription.fontSynthesis() &amp; FontSynthesisStyle;
+    if (descriptionAllowsSyntheticOblique &amp;&amp; fontDescription.italic()
+        &amp;&amp; FcPatternGetInteger(pattern, FC_SLANT, 0, &amp;actualFontSlant) == FcResultMatch) {
+        m_syntheticOblique = actualFontSlant == FC_SLANT_ROMAN;
+    }
+
+    buildScaledFont(fontFace.get());
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> FontPlatformData::FontPlatformData(float size, bool bold, bool italic)
</span><span class="lines">@@ -196,7 +196,7 @@
</span><span class="cx">     , m_scaledFont(nullptr)
</span><span class="cx">     , m_orientation(orientation)
</span><span class="cx"> {
</span><del>-    initializeWithFontFace(fontFace);
</del><ins>+    buildScaledFont(fontFace);
</ins><span class="cx"> 
</span><span class="cx">     FT_Face fontConfigFace = cairo_ft_scaled_font_lock_face(m_scaledFont);
</span><span class="cx">     if (fontConfigFace) {
</span><span class="lines">@@ -217,7 +217,6 @@
</span><span class="cx">     m_fixedWidth = other.m_fixedWidth;
</span><span class="cx">     m_pattern = other.m_pattern;
</span><span class="cx">     m_orientation = other.m_orientation;
</span><del>-    m_horizontalOrientationMatrix = other.m_horizontalOrientationMatrix;
</del><span class="cx"> 
</span><span class="cx">     if (m_fallbacks) {
</span><span class="cx">         FcFontSetDestroy(m_fallbacks);
</span><span class="lines">@@ -252,7 +251,7 @@
</span><span class="cx">     // We need to reinitialize the instance, because the difference in size 
</span><span class="cx">     // necessitates a new scaled font instance.
</span><span class="cx">     m_size = size;
</span><del>-    initializeWithFontFace(cairo_scaled_font_get_font_face(m_scaledFont));
</del><ins>+    buildScaledFont(cairo_scaled_font_get_font_face(m_scaledFont));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> FontPlatformData::~FontPlatformData()
</span><span class="lines">@@ -301,7 +300,7 @@
</span><span class="cx"> }
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><del>-void FontPlatformData::initializeWithFontFace(cairo_font_face_t* fontFace, const FontDescription&amp; fontDescription)
</del><ins>+void FontPlatformData::buildScaledFont(cairo_font_face_t* fontFace)
</ins><span class="cx"> {
</span><span class="cx">     cairo_font_options_t* options = getDefaultCairoFontOptions();
</span><span class="cx">     FcPattern* optionsPattern = m_pattern ? m_pattern.get() : getDefaultFontconfigOptions();
</span><span class="lines">@@ -310,10 +309,6 @@
</span><span class="cx">     cairo_matrix_t ctm;
</span><span class="cx">     cairo_matrix_init_identity(&amp;ctm);
</span><span class="cx"> 
</span><del>-    // Scaling a font with width zero size leads to a failed cairo_scaled_font_t instantiations.
-    // Instead we scale we scale the font to a very tiny size and just abort rendering later on.
-    float realSize = m_size ? m_size : 1;
-
</del><span class="cx">     // FontConfig may return a list of transformation matrices with the pattern, for instance,
</span><span class="cx">     // for fonts that are oblique. We use that to initialize the cairo font matrix.
</span><span class="cx">     cairo_matrix_t fontMatrix;
</span><span class="lines">@@ -326,15 +321,10 @@
</span><span class="cx">     cairo_matrix_init(&amp;fontMatrix, fontConfigMatrix.xx, -fontConfigMatrix.yx,
</span><span class="cx">         -fontConfigMatrix.xy, fontConfigMatrix.yy, 0, 0);
</span><span class="cx"> 
</span><del>-    // We requested an italic font, but Fontconfig gave us one that was neither oblique nor italic.
-    int actualFontSlant;
-    bool descriptionAllowsSyntheticOblique = fontDescription.fontSynthesis() &amp; FontSynthesisStyle;
-    if (descriptionAllowsSyntheticOblique &amp;&amp; fontDescription.italic()
-        &amp;&amp; FcPatternGetInteger(optionsPattern, FC_SLANT, 0, &amp;actualFontSlant) == FcResultMatch) {
-        m_syntheticOblique = actualFontSlant == FC_SLANT_ROMAN;
-    }
-
-    // The matrix from FontConfig does not include the scale. 
</del><ins>+    // The matrix from FontConfig does not include the scale. Scaling a font with width zero size leads
+    // to a failed cairo_scaled_font_t instantiations. Instead we scale we scale the font to a very tiny
+    // size and just abort rendering later on.
+    float realSize = m_size ? m_size : 1;
</ins><span class="cx">     cairo_matrix_scale(&amp;fontMatrix, realSize, realSize);
</span><span class="cx"> 
</span><span class="cx">     if (syntheticOblique()) {
</span><span class="lines">@@ -344,10 +334,18 @@
</span><span class="cx">         cairo_matrix_multiply(&amp;fontMatrix, m_orientation == Vertical ? &amp;verticalSkew : &amp;skew, &amp;fontMatrix);
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    m_horizontalOrientationMatrix = fontMatrix;
-    if (m_orientation == Vertical)
-        rotateCairoMatrixForVerticalOrientation(&amp;fontMatrix);
</del><ins>+    if (m_orientation == Vertical) {
+        // The resulting transformation matrix for vertical glyphs (V) is a
+        // combination of rotation (R) and translation (T) applied on the
+        // horizontal matrix (H). V = H . R . T, where R rotates by -90 degrees
+        // and T translates by font size towards y axis.
+        cairo_matrix_rotate(&amp;fontMatrix, -piOverTwoDouble);
+        cairo_matrix_translate(&amp;fontMatrix, 0.0, 1.0);
+    }
</ins><span class="cx"> 
</span><ins>+    if (m_scaledFont &amp;&amp; m_scaledFont != hashTableDeletedFontValue())
+        cairo_scaled_font_destroy(m_scaledFont);
+
</ins><span class="cx">     m_scaledFont = cairo_scaled_font_create(fontFace, &amp;fontMatrix, &amp;ctm, options);
</span><span class="cx">     cairo_font_options_destroy(options);
</span><span class="cx"> }
</span><span class="lines">@@ -397,31 +395,22 @@
</span><span class="cx"> 
</span><span class="cx"> void FontPlatformData::setOrientation(FontOrientation orientation)
</span><span class="cx"> {
</span><del>-    ASSERT(m_scaledFont);
-
</del><span class="cx">     if (!m_scaledFont || (m_orientation == orientation))
</span><span class="cx">         return;
</span><span class="cx"> 
</span><del>-    cairo_matrix_t transformationMatrix;
-    cairo_matrix_init_identity(&amp;transformationMatrix);
</del><ins>+    ASSERT(m_scaledFont);
+    m_orientation = orientation;
+    buildScaledFont(cairo_scaled_font_get_font_face(m_scaledFont));
+}
</ins><span class="cx"> 
</span><del>-    cairo_matrix_t fontMatrix;
-    cairo_scaled_font_get_font_matrix(m_scaledFont, &amp;fontMatrix);
</del><ins>+void FontPlatformData::setSyntheticOblique(bool newSyntheticObliqueValue)
+{
+    if (newSyntheticObliqueValue == syntheticOblique())
+        return;
</ins><span class="cx"> 
</span><del>-    cairo_font_options_t* options = getDefaultCairoFontOptions();
-
-    // In case of vertical orientation, rotate the transformation matrix.
-    // Otherwise restore the horizontal orientation matrix.
-    if (orientation == Vertical)
-        rotateCairoMatrixForVerticalOrientation(&amp;fontMatrix);
-    else
-        fontMatrix = m_horizontalOrientationMatrix;
-
-    cairo_font_face_t* fontFace = cairo_scaled_font_get_font_face(m_scaledFont);
-    cairo_scaled_font_destroy(m_scaledFont);
-    m_scaledFont = cairo_scaled_font_create(fontFace, &amp;fontMatrix, &amp;transformationMatrix, options);
-    cairo_font_options_destroy(options);
-    m_orientation = orientation;
</del><ins>+    ASSERT(m_scaledFont);
+    m_syntheticOblique = newSyntheticObliqueValue;
+    buildScaledFont(cairo_scaled_font_get_font_face(m_scaledFont));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> }
</span></span></pre>
</div>
</div>

</body>
</html>