FontPlatformData::harfBuzzFace() should return a reference
authorzandobersek@gmail.com <zandobersek@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 15 Feb 2018 19:04:01 +0000 (19:04 +0000)
committerzandobersek@gmail.com <zandobersek@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 15 Feb 2018 19:04:01 +0000 (19:04 +0000)
https://bugs.webkit.org/show_bug.cgi?id=182825

Reviewed by Carlos Garcia Campos.

Have FontPlatformData::harfBuzzFace() return a reference instead of a
pointer, given that the returned HarfBuzzFace object cannot be null.

Call-sites of FontPlatformData::harfBuzzFace() are adjusted.
OpenTypeMathData constructors are also changed to not rely on
preprocessor to correctly position the closing brace.

* platform/graphics/FontPlatformData.h:
* platform/graphics/freetype/FontPlatformDataFreeType.cpp:
(WebCore::FontPlatformData::harfBuzzFace const):
* platform/graphics/harfbuzz/ComplexTextControllerHarfBuzz.cpp:
(WebCore::ComplexTextController::collectComplexTextRunsForCharacters):
* platform/graphics/opentype/OpenTypeMathData.cpp:
(WebCore::OpenTypeMathData::OpenTypeMathData):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@228524 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/FontPlatformData.h
Source/WebCore/platform/graphics/freetype/FontPlatformDataFreeType.cpp
Source/WebCore/platform/graphics/harfbuzz/ComplexTextControllerHarfBuzz.cpp
Source/WebCore/platform/graphics/opentype/OpenTypeMathData.cpp

index 8e2a08a..dedaf85 100644 (file)
@@ -1,3 +1,25 @@
+2018-02-15  Zan Dobersek  <zdobersek@igalia.com>
+
+        FontPlatformData::harfBuzzFace() should return a reference
+        https://bugs.webkit.org/show_bug.cgi?id=182825
+
+        Reviewed by Carlos Garcia Campos.
+
+        Have FontPlatformData::harfBuzzFace() return a reference instead of a
+        pointer, given that the returned HarfBuzzFace object cannot be null.
+
+        Call-sites of FontPlatformData::harfBuzzFace() are adjusted.
+        OpenTypeMathData constructors are also changed to not rely on
+        preprocessor to correctly position the closing brace.
+
+        * platform/graphics/FontPlatformData.h:
+        * platform/graphics/freetype/FontPlatformDataFreeType.cpp:
+        (WebCore::FontPlatformData::harfBuzzFace const):
+        * platform/graphics/harfbuzz/ComplexTextControllerHarfBuzz.cpp:
+        (WebCore::ComplexTextController::collectComplexTextRunsForCharacters):
+        * platform/graphics/opentype/OpenTypeMathData.cpp:
+        (WebCore::OpenTypeMathData::OpenTypeMathData):
+
 2018-02-15  Jiewen Tan  <jiewen_tan@apple.com>
 
         [WebAuthN] Revisit the whole async model of task dispatching, timeout and aborting
index 5a79d59..bd46fc5 100644 (file)
@@ -162,7 +162,7 @@ public:
 #endif
 
 #if USE(FREETYPE)
-    HarfBuzzFace* harfBuzzFace() const;
+    HarfBuzzFace& harfBuzzFace() const;
     bool hasCompatibleCharmap() const;
     FcFontSet* fallbacks() const;
 #endif
index 3c3ca81..6c4abfa 100644 (file)
@@ -238,11 +238,11 @@ FontPlatformData FontPlatformData::cloneWithSize(const FontPlatformData& source,
     return copy;
 }
 
-HarfBuzzFace* FontPlatformData::harfBuzzFace() const
+HarfBuzzFace& FontPlatformData::harfBuzzFace() const
 {
     if (!m_harfBuzzFace)
         m_harfBuzzFace = std::make_unique<HarfBuzzFace>(const_cast<FontPlatformData*>(this), hash());
-    return m_harfBuzzFace.get();
+    return *m_harfBuzzFace;
 }
 
 FcFontSet* FontPlatformData::fallbacks() const
index 4e6a53b..37f66b6 100644 (file)
@@ -207,12 +207,11 @@ void ComplexTextController::collectComplexTextRunsForCharacters(const UChar* cha
         }
         hb_buffer_add_utf16(buffer.get(), reinterpret_cast<const uint16_t*>(characters), length, run.startIndex, run.endIndex - run.startIndex);
 
-        HarfBuzzFace* face = fontPlatformData.harfBuzzFace();
-        ASSERT(face);
+        auto& face = fontPlatformData.harfBuzzFace();
         if (fontPlatformData.orientation() == Vertical)
-            face->setScriptForVerticalGlyphSubstitution(buffer.get());
+            face.setScriptForVerticalGlyphSubstitution(buffer.get());
 
-        HbUniquePtr<hb_font_t> harfBuzzFont(face->createFont());
+        HbUniquePtr<hb_font_t> harfBuzzFont(face.createFont());
         hb_shape(harfBuzzFont.get(), buffer.get(), features.isEmpty() ? nullptr : features.data(), features.size());
         m_complexTextRuns.append(ComplexTextRun::create(buffer.get(), *font, characters, stringLocation, length, run.startIndex, run.endIndex));
         hb_buffer_reset(buffer.get());
index f10e400..84181fa 100644 (file)
@@ -254,20 +254,17 @@ OpenTypeMathData::OpenTypeMathData(const FontPlatformData& font)
     const OpenType::MathVariants* mathVariants = math->mathVariants(*m_mathBuffer);
     if (!mathVariants)
         m_mathBuffer = nullptr;
+}
 #elif USE(HARFBUZZ)
 OpenTypeMathData::OpenTypeMathData(const FontPlatformData& font)
+    : m_mathFont(font.harfBuzzFace().createFont())
 {
-    HarfBuzzFace* face = font.harfBuzzFace();
-    if (face) {
-        m_mathFont.reset(face->createFont());
-        if (!hb_ot_math_has_data(hb_font_get_face(m_mathFont.get())))
-            m_mathFont.release();
-    }
+    if (!hb_ot_math_has_data(hb_font_get_face(m_mathFont.get())))
+        m_mathFont = nullptr;
+}
 #else
-OpenTypeMathData::OpenTypeMathData(const FontPlatformData&)
-{
+OpenTypeMathData::OpenTypeMathData(const FontPlatformData&) = default;
 #endif
-}
 
 OpenTypeMathData::~OpenTypeMathData() = default;