Title: [211294] trunk
Revision
211294
Author
mmaxfi...@apple.com
Date
2017-01-27 12:28:11 -0800 (Fri, 27 Jan 2017)

Log Message

[Cocoa] Prepare ComplexTextController for unit testing
https://bugs.webkit.org/show_bug.cgi?id=167493

Reviewed by Dean Jackson.

Source/WebCore:

ComplexTextController has three phases:
1. Interrogate Core Text about some text
2. Compute layout advances and paint advances from the information retrieved from
Core Text
3. Iterate through the layout advances or paint advances.

This patch tests phases 2 and 3 by chopping ComplexTextController between
phases 1 and 2, and injecting foreign metrics from a unit test. These metrics
have been gathered from real-world uses; however, a layout test is not appropriate
because the fonts which produced these metrics are not licensed appropriately.
The tests can enforce the correct behavior by using ComplexTextController's
public API.

This is in preparation for https://bugs.webkit.org/show_bug.cgi?id=166013.
However, the fix for that bug is quite large, so I've split out this smaller piece
to ease the reviewing burden. The tests I've added are disabled for now (because
they fail), but will be enabled by the fix to that bug.

No new tests because there is no behavior change.

* WebCore.xcodeproj/project.pbxproj:
* platform/graphics/FontCascade.h:
* platform/graphics/FontDescription.h:
* platform/graphics/mac/ComplexTextController.cpp:
(WebCore::ComplexTextController::ComplexTextController):
(WebCore::ComplexTextController::finishConstruction):
* platform/graphics/mac/ComplexTextController.h:
(WebCore::ComplexTextController::ComplexTextRun::createForTesting):
* platform/graphics/mac/ComplexTextControllerCoreText.mm:
(WebCore::ComplexTextController::ComplexTextRun::ComplexTextRun):

Tools:

Create four unit tests.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebCore/ComplexTextController.cpp: Added.
(TestWebKitAPI::ComplexTextControllerTest::SetUp):
(TestWebKitAPI::TEST_F):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (211293 => 211294)


--- trunk/Source/WebCore/ChangeLog	2017-01-27 19:37:05 UTC (rev 211293)
+++ trunk/Source/WebCore/ChangeLog	2017-01-27 20:28:11 UTC (rev 211294)
@@ -1,3 +1,41 @@
+2017-01-27  Myles C. Maxfield  <mmaxfi...@apple.com>
+
+        [Cocoa] Prepare ComplexTextController for unit testing
+        https://bugs.webkit.org/show_bug.cgi?id=167493
+
+        Reviewed by Dean Jackson.
+
+        ComplexTextController has three phases:
+        1. Interrogate Core Text about some text
+        2. Compute layout advances and paint advances from the information retrieved from
+        Core Text
+        3. Iterate through the layout advances or paint advances.
+
+        This patch tests phases 2 and 3 by chopping ComplexTextController between
+        phases 1 and 2, and injecting foreign metrics from a unit test. These metrics
+        have been gathered from real-world uses; however, a layout test is not appropriate
+        because the fonts which produced these metrics are not licensed appropriately.
+        The tests can enforce the correct behavior by using ComplexTextController's
+        public API.
+
+        This is in preparation for https://bugs.webkit.org/show_bug.cgi?id=166013.
+        However, the fix for that bug is quite large, so I've split out this smaller piece
+        to ease the reviewing burden. The tests I've added are disabled for now (because
+        they fail), but will be enabled by the fix to that bug.
+
+        No new tests because there is no behavior change.
+
+        * WebCore.xcodeproj/project.pbxproj:
+        * platform/graphics/FontCascade.h:
+        * platform/graphics/FontDescription.h:
+        * platform/graphics/mac/ComplexTextController.cpp:
+        (WebCore::ComplexTextController::ComplexTextController):
+        (WebCore::ComplexTextController::finishConstruction):
+        * platform/graphics/mac/ComplexTextController.h:
+        (WebCore::ComplexTextController::ComplexTextRun::createForTesting):
+        * platform/graphics/mac/ComplexTextControllerCoreText.mm:
+        (WebCore::ComplexTextController::ComplexTextRun::ComplexTextRun):
+
 2017-01-27  Zalan Bujtas  <za...@apple.com>
 
         Simple line layout: Do not bail out on -webkit-line-box-contain: block glyphs unless text overflows vertically.

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (211293 => 211294)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2017-01-27 19:37:05 UTC (rev 211293)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2017-01-27 20:28:11 UTC (rev 211294)
@@ -1452,7 +1452,7 @@
 		37B327D31D17096A005737FA /* PIPSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = 37B327D21D17096A005737FA /* PIPSPI.h */; };
 		37BAAE581980D1DD005DFE71 /* ProtectionSpace.h in Headers */ = {isa = PBXBuildFile; fileRef = 37BAAE571980D1DD005DFE71 /* ProtectionSpace.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		37C236101097EE7700EF9F72 /* ComplexTextController.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37C2360E1097EE7700EF9F72 /* ComplexTextController.cpp */; };
-		37C236111097EE7700EF9F72 /* ComplexTextController.h in Headers */ = {isa = PBXBuildFile; fileRef = 37C2360F1097EE7700EF9F72 /* ComplexTextController.h */; };
+		37C236111097EE7700EF9F72 /* ComplexTextController.h in Headers */ = {isa = PBXBuildFile; fileRef = 37C2360F1097EE7700EF9F72 /* ComplexTextController.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		37C238221098C84200EF9F72 /* ComplexTextControllerCoreText.mm in Sources */ = {isa = PBXBuildFile; fileRef = 37C238201098C84200EF9F72 /* ComplexTextControllerCoreText.mm */; };
 		37D456FD1A9A50D8003330A1 /* LocalizableStrings.pm in Copy Scripts */ = {isa = PBXBuildFile; fileRef = 37D456FB1A9A50B6003330A1 /* LocalizableStrings.pm */; };
 		37DDCD9413844FD50008B793 /* MIMEHeader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37DDCD9213844FD50008B793 /* MIMEHeader.cpp */; };

Modified: trunk/Source/WebCore/platform/graphics/FontCascade.h (211293 => 211294)


--- trunk/Source/WebCore/platform/graphics/FontCascade.h	2017-01-27 19:37:05 UTC (rev 211293)
+++ trunk/Source/WebCore/platform/graphics/FontCascade.h	2017-01-27 20:28:11 UTC (rev 211294)
@@ -114,7 +114,7 @@
 class FontCascade {
 public:
     WEBCORE_EXPORT FontCascade();
-    WEBCORE_EXPORT FontCascade(const FontCascadeDescription&, float letterSpacing, float wordSpacing);
+    WEBCORE_EXPORT FontCascade(const FontCascadeDescription&, float letterSpacing = 0, float wordSpacing = 0);
     // This constructor is only used if the platform wants to start with a native font.
     WEBCORE_EXPORT FontCascade(const FontPlatformData&, FontSmoothingMode = AutoSmoothing);
 
@@ -129,7 +129,7 @@
     int pixelSize() const { return fontDescription().computedPixelSize(); }
     float size() const { return fontDescription().computedSize(); }
 
-    void update(RefPtr<FontSelector>&&) const;
+    WEBCORE_EXPORT void update(RefPtr<FontSelector>&&) const;
 
     enum CustomFontNotReadyAction { DoNotPaintIfFontNotReady, UseFallbackIfFontNotReady };
     WEBCORE_EXPORT float drawText(GraphicsContext&, const TextRun&, const FloatPoint&, unsigned from = 0, std::optional<unsigned> to = std::nullopt, CustomFontNotReadyAction = DoNotPaintIfFontNotReady) const;

Modified: trunk/Source/WebCore/platform/graphics/FontDescription.h (211293 => 211294)


--- trunk/Source/WebCore/platform/graphics/FontDescription.h	2017-01-27 19:37:05 UTC (rev 211293)
+++ trunk/Source/WebCore/platform/graphics/FontDescription.h	2017-01-27 20:28:11 UTC (rev 211294)
@@ -197,7 +197,7 @@
 // FIXME: Move to a file of its own.
 class FontCascadeDescription : public FontDescription {
 public:
-    FontCascadeDescription();
+    WEBCORE_EXPORT FontCascadeDescription();
 
     bool operator==(const FontCascadeDescription&) const;
     bool operator!=(const FontCascadeDescription& other) const { return !(*this == other); }

Modified: trunk/Source/WebCore/platform/graphics/mac/ComplexTextController.cpp (211293 => 211294)


--- trunk/Source/WebCore/platform/graphics/mac/ComplexTextController.cpp	2017-01-27 19:37:05 UTC (rev 211293)
+++ trunk/Source/WebCore/platform/graphics/mac/ComplexTextController.cpp	2017-01-27 20:28:11 UTC (rev 211294)
@@ -128,6 +128,23 @@
     }
 
     collectComplexTextRuns();
+
+    finishConstruction();
+}
+
+ComplexTextController::ComplexTextController(const FontCascade& font, const TextRun& run, Vector<Ref<ComplexTextRun>>& runs)
+    : m_font(font)
+    , m_run(run)
+    , m_end(run.length())
+{
+    for (auto& run : runs)
+        m_complexTextRuns.append(run.ptr());
+
+    finishConstruction();
+}
+
+void ComplexTextController::finishConstruction()
+{
     adjustGlyphsAndAdvances();
 
     if (!m_isLTROnly) {

Modified: trunk/Source/WebCore/platform/graphics/mac/ComplexTextController.h (211293 => 211294)


--- trunk/Source/WebCore/platform/graphics/mac/ComplexTextController.h	2017-01-27 19:37:05 UTC (rev 211293)
+++ trunk/Source/WebCore/platform/graphics/mac/ComplexTextController.h	2017-01-27 20:28:11 UTC (rev 211294)
@@ -58,8 +58,11 @@
 public:
     ComplexTextController(const FontCascade&, const TextRun&, bool mayUseNaturalWritingDirection = false, HashSet<const Font*>* fallbackFonts = 0, bool forTextEmphasis = false);
 
+    class ComplexTextRun;
+    WEBCORE_EXPORT ComplexTextController(const FontCascade&, const TextRun&, Vector<Ref<ComplexTextRun>>&);
+
     // Advance and emit glyphs up to the specified character.
-    void advance(unsigned to, GlyphBuffer* = nullptr, GlyphIterationStyle = IncludePartialGlyphs, HashSet<const Font*>* fallbackFonts = nullptr);
+    WEBCORE_EXPORT void advance(unsigned to, GlyphBuffer* = nullptr, GlyphIterationStyle = IncludePartialGlyphs, HashSet<const Font*>* fallbackFonts = nullptr);
 
     // Compute the character offset for a given x coordinate.
     unsigned offsetForPosition(float x, bool includePartialGlyphs);
@@ -75,8 +78,7 @@
     float maxGlyphBoundingBoxY() const { return m_maxGlyphBoundingBoxY; }
 
     float leadingExpansion() const { return m_leadingExpansion; }
-    
-private:
+
     class ComplexTextRun : public RefCounted<ComplexTextRun> {
     public:
         static Ref<ComplexTextRun> create(CTRunRef ctRun, const Font& font, const UChar* characters, unsigned stringLocation, size_t stringLength, CFRange runRange)
@@ -89,6 +91,11 @@
             return adoptRef(*new ComplexTextRun(font, characters, stringLocation, stringLength, ltr));
         }
 
+        static Ref<ComplexTextRun> createForTesting(Vector<CGSize> advances, Vector<CGPoint> origins, Vector<CGGlyph> glyphs, Vector<CFIndex> stringIndices, CGSize initialAdvance, const Font& font, const UChar* characters, unsigned stringLocation, size_t stringLength, CFRange runRange, bool ltr)
+        {
+            return adoptRef(*new ComplexTextRun(advances, origins, glyphs, stringIndices, initialAdvance, font, characters, stringLocation, stringLength, runRange, ltr));
+        }
+
         unsigned glyphCount() const { return m_glyphCount; }
         const Font& font() const { return m_font; }
         const UChar* characters() const { return m_characters; }
@@ -120,6 +127,7 @@
     private:
         ComplexTextRun(CTRunRef, const Font&, const UChar* characters, unsigned stringLocation, size_t stringLength, CFRange runRange);
         ComplexTextRun(const Font&, const UChar* characters, unsigned stringLocation, size_t stringLength, bool ltr);
+        WEBCORE_EXPORT ComplexTextRun(Vector<CGSize> advances, Vector<CGPoint> origins, Vector<CGGlyph> glyphs, Vector<CFIndex> stringIndices, CGSize initialAdvance, const Font&, const UChar* characters, unsigned stringLocation, size_t stringLength, CFRange runRange, bool ltr);
 
         Vector<CGSize, 64> m_baseAdvancesVector;
         Vector<CGPoint, 64> m_glyphOrigins;
@@ -138,8 +146,10 @@
         unsigned m_glyphCount;
         unsigned m_stringLocation;
         bool m_isLTR;
-        bool m_isMonotonic;
+        bool m_isMonotonic { true };
     };
+private:
+    void finishConstruction();
     
     static unsigned stringBegin(const ComplexTextRun& run) { return run.stringLocation() + run.indexBegin(); }
     static unsigned stringEnd(const ComplexTextRun& run) { return run.stringLocation() + run.indexEnd(); }

Modified: trunk/Source/WebCore/platform/graphics/mac/ComplexTextControllerCoreText.mm (211293 => 211294)


--- trunk/Source/WebCore/platform/graphics/mac/ComplexTextControllerCoreText.mm	2017-01-27 19:37:05 UTC (rev 211293)
+++ trunk/Source/WebCore/platform/graphics/mac/ComplexTextControllerCoreText.mm	2017-01-27 20:28:11 UTC (rev 211294)
@@ -111,14 +111,14 @@
     , m_font(font)
     , m_characters(characters)
     , m_stringLength(stringLength)
+    , m_coreTextIndices(CTRunGetStringIndicesPtr(ctRun))
+    , m_glyphs(CTRunGetGlyphsPtr(ctRun))
     , m_indexBegin(runRange.location)
     , m_indexEnd(runRange.location + runRange.length)
+    , m_glyphCount(CTRunGetGlyphCount(ctRun))
     , m_stringLocation(stringLocation)
     , m_isLTR(!(CTRunGetStatus(ctRun) & kCTRunStatusRightToLeft))
-    , m_isMonotonic(true)
 {
-    m_glyphCount = CTRunGetGlyphCount(ctRun);
-    m_coreTextIndices = CTRunGetStringIndicesPtr(ctRun);
     if (!m_coreTextIndices) {
         m_coreTextIndicesVector.grow(m_glyphCount);
         CTRunGetStringIndices(ctRun, CFRangeMake(0, 0), m_coreTextIndicesVector.data());
@@ -125,7 +125,6 @@
         m_coreTextIndices = m_coreTextIndicesVector.data();
     }
 
-    m_glyphs = CTRunGetGlyphsPtr(ctRun);
     if (!m_glyphs) {
         m_glyphsVector.grow(m_glyphCount);
         CTRunGetGlyphs(ctRun, CFRangeMake(0, 0), m_glyphsVector.data());
@@ -161,7 +160,6 @@
     , m_indexEnd(stringLength)
     , m_stringLocation(stringLocation)
     , m_isLTR(ltr)
-    , m_isMonotonic(true)
 {
     m_coreTextIndicesVector.reserveInitialCapacity(m_stringLength);
     unsigned r = 0;
@@ -184,6 +182,27 @@
     m_baseAdvances = m_baseAdvancesVector.data();
 }
 
+
+ComplexTextController::ComplexTextRun::ComplexTextRun(Vector<CGSize> advances, Vector<CGPoint> origins, Vector<CGGlyph> glyphs, Vector<CFIndex> stringIndices, CGSize initialAdvance, const Font& font, const UChar* characters, unsigned stringLocation, size_t stringLength, CFRange runRange, bool ltr)
+    : m_baseAdvancesVector(advances)
+    , m_glyphOrigins(origins)
+    , m_glyphsVector(glyphs)
+    , m_coreTextIndicesVector(stringIndices)
+    , m_initialAdvance(initialAdvance)
+    , m_font(font)
+    , m_characters(characters)
+    , m_stringLength(stringLength)
+    , m_coreTextIndices(m_coreTextIndicesVector.data())
+    , m_glyphs(m_glyphsVector.data())
+    , m_baseAdvances(m_baseAdvancesVector.data())
+    , m_indexBegin(runRange.location)
+    , m_indexEnd(runRange.location + runRange.length)
+    , m_glyphCount(glyphs.size())
+    , m_stringLocation(stringLocation)
+    , m_isLTR(ltr)
+{
+}
+
 struct ProviderInfo {
     const UChar* cp;
     unsigned length;

Modified: trunk/Tools/ChangeLog (211293 => 211294)


--- trunk/Tools/ChangeLog	2017-01-27 19:37:05 UTC (rev 211293)
+++ trunk/Tools/ChangeLog	2017-01-27 20:28:11 UTC (rev 211294)
@@ -1,3 +1,17 @@
+2017-01-27  Myles C. Maxfield  <mmaxfi...@apple.com>
+
+        [Cocoa] Prepare ComplexTextController for unit testing
+        https://bugs.webkit.org/show_bug.cgi?id=167493
+
+        Reviewed by Dean Jackson.
+
+        Create four unit tests.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WebCore/ComplexTextController.cpp: Added.
+        (TestWebKitAPI::ComplexTextControllerTest::SetUp):
+        (TestWebKitAPI::TEST_F):
+
 2017-01-26  Chris Dumez  <cdu...@apple.com>
 
         Crash when navigating back to a page in PacheCache when one of its frames has been removed

Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (211293 => 211294)


--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2017-01-27 19:37:05 UTC (rev 211293)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2017-01-27 20:28:11 UTC (rev 211294)
@@ -45,6 +45,7 @@
 		1C2B81831C891F0900A5529F /* CancelFontSubresourcePlugIn.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1C2B81811C891EFA00A5529F /* CancelFontSubresourcePlugIn.mm */; };
 		1C2B81861C89259D00A5529F /* webfont.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 1C2B81841C8924A200A5529F /* webfont.html */; };
 		1C2B81871C8925A000A5529F /* Ahem.ttf in Copy Resources */ = {isa = PBXBuildFile; fileRef = 1C2B81851C89252300A5529F /* Ahem.ttf */; };
+		1C9EB8411E380DA1005C6442 /* ComplexTextController.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1C9EB8401E380DA1005C6442 /* ComplexTextController.cpp */; };
 		1F83571B1D3FFB2300E3967B /* WKBackForwardList.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1F83571A1D3FFB0E00E3967B /* WKBackForwardList.mm */; };
 		26DF5A6315A2A27E003689C2 /* CancelLoadFromResourceLoadDelegate.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 26DF5A6115A2A22B003689C2 /* CancelLoadFromResourceLoadDelegate.html */; };
 		26F52EAD1828827B0023D412 /* geolocationGetCurrentPosition.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 26F52EAC1828820E0023D412 /* geolocationGetCurrentPosition.html */; };
@@ -823,6 +824,7 @@
 		1C2B81811C891EFA00A5529F /* CancelFontSubresourcePlugIn.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = CancelFontSubresourcePlugIn.mm; sourceTree = "<group>"; };
 		1C2B81841C8924A200A5529F /* webfont.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = webfont.html; sourceTree = "<group>"; };
 		1C2B81851C89252300A5529F /* Ahem.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = Ahem.ttf; sourceTree = "<group>"; };
+		1C9EB8401E380DA1005C6442 /* ComplexTextController.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ComplexTextController.cpp; sourceTree = "<group>"; };
 		1CB9BC371A67482300FE5678 /* WeakPtr.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WeakPtr.cpp; sourceTree = "<group>"; };
 		1CF0D3781BBF2F3D00B4EF54 /* WKRetainPtr.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WKRetainPtr.cpp; sourceTree = "<group>"; };
 		1F83571A1D3FFB0E00E3967B /* WKBackForwardList.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = WKBackForwardList.mm; path = Tests/WebKit2/WKBackForwardList.mm; sourceTree = SOURCE_ROOT; };
@@ -1604,6 +1606,7 @@
 				440A1D3814A0103A008A66F2 /* URL.cpp */,
 				5C6E65411D5CEF8500F7862E /* URLParser.cpp */,
 				9C64DC311D76198A004B598E /* YouTubePluginReplacement.cpp */,
+				1C9EB8401E380DA1005C6442 /* ComplexTextController.cpp */,
 			);
 			path = WebCore;
 			sourceTree = "<group>";
@@ -2702,6 +2705,7 @@
 				2DFF7B6D1DA487AF00814614 /* SnapshotStore.mm in Sources */,
 				5C6E65441D5CEFD400F7862E /* URLParser.cpp in Sources */,
 				7CCE7F271A411AF600447C4C /* UserContentController.mm in Sources */,
+				1C9EB8411E380DA1005C6442 /* ComplexTextController.cpp in Sources */,
 				7CCE7F2D1A411B1000447C4C /* UserContentTest.mm in Sources */,
 				7C882E0A1C80C764006BF731 /* UserContentWorld.mm in Sources */,
 				7CCB99211D3B41F6003922F6 /* UserInitiatedActionInNavigationAction.mm in Sources */,

Added: trunk/Tools/TestWebKitAPI/Tests/WebCore/ComplexTextController.cpp (0 => 211294)


--- trunk/Tools/TestWebKitAPI/Tests/WebCore/ComplexTextController.cpp	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebCore/ComplexTextController.cpp	2017-01-27 20:28:11 UTC (rev 211294)
@@ -0,0 +1,234 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#include <_javascript_Core/InitializeThreading.h>
+#include <WebCore/ComplexTextController.h>
+#include <WebCore/FontCascade.h>
+#include <wtf/MainThread.h>
+#include <wtf/RunLoop.h>
+
+using namespace WebCore;
+
+namespace TestWebKitAPI {
+
+class ComplexTextControllerTest : public testing::Test {
+public:
+    virtual void SetUp()
+    {
+        WTF::initializeMainThread();
+        JSC::initializeThreading();
+        RunLoop::initializeMainRunLoop();
+    }
+};
+
+TEST_F(ComplexTextControllerTest, DISABLED_InitialAdvanceWithLeftRunInRTL)
+{
+    FontCascadeDescription description;
+    description.setOneFamily("Times");
+    description.setComputedSize(80);
+    FontCascade font(description);
+    font.update(nullptr);
+    auto spaceWidth = font.primaryFont().spaceWidth();
+
+#if USE_LAYOUT_SPECIFIC_ADVANCES
+    Vector<CGSize> advances = { CGSizeZero, CGSizeMake(21.640625, 0.0), CGSizeMake(42.3046875, 0.0), CGSizeMake(55.8984375, 0.0), CGSizeMake(22.34375, 0.0) };
+    Vector<CGPoint> origins = { CGPointMake(-15.15625, 18.046875), CGPointZero, CGPointZero, CGPointZero, CGPointZero };
+#else
+    Vector<CGSize> advances = { CGSizeMake(15.15625, -18.046875), CGSizeMake(21.640625, 0.0), CGSizeMake(42.3046875, 0.0), CGSizeMake(55.8984375, 0.0), CGSizeMake(22.34375, 0.0) };
+    Vector<CGPoint> origins = { };
+#endif
+
+    CGSize initialAdvance = CGSizeMake(-15.15625, 18.046875);
+
+    UChar characters[] = { 0x644, 0x637, 0x641, 0x627, 0x64b, 0x20 };
+    size_t charactersLength = WTF_ARRAY_LENGTH(characters);
+    TextRun textRun(StringView(characters, charactersLength));
+    Ref<ComplexTextController::ComplexTextRun> run1 = ComplexTextController::ComplexTextRun::createForTesting({ CGSizeMake(21.875, 0) }, { CGPointZero }, { 5 }, { 5 }, CGSizeZero, font.primaryFont(), characters, 0, charactersLength, CFRangeMake(5, 1), false);
+    Ref<ComplexTextController::ComplexTextRun> run2 = ComplexTextController::ComplexTextRun::createForTesting(advances, origins, { 193, 377, 447, 431, 458 }, { 4, 3, 2, 1, 0 }, initialAdvance, font.primaryFont(), characters, 0, charactersLength, CFRangeMake(0, 5), false);
+    Vector<Ref<ComplexTextController::ComplexTextRun>> runs;
+    runs.append(WTFMove(run1));
+    runs.append(WTFMove(run2));
+    ComplexTextController controller(font, textRun, runs);
+
+    CGFloat totalWidth = 0;
+    for (size_t i = 1; i < advances.size(); ++i)
+        totalWidth += advances[i].width;
+    EXPECT_NEAR(controller.totalWidth(), spaceWidth + totalWidth, 0.0001);
+    GlyphBuffer glyphBuffer;
+    controller.advance(0, &glyphBuffer);
+    EXPECT_NEAR(controller.runWidthSoFar(), 0, 0.0001);
+    controller.advance(1, &glyphBuffer);
+    EXPECT_NEAR(controller.runWidthSoFar(), advances[4].width, 0.0001);
+    controller.advance(6, &glyphBuffer);
+    EXPECT_NEAR(controller.runWidthSoFar(), spaceWidth + totalWidth, 0.0001);
+    EXPECT_NEAR(glyphBuffer.initialAdvance().width(), 0, 0.0001);
+    EXPECT_NEAR(glyphBuffer.initialAdvance().height(), 0, 0.0001);
+    EXPECT_EQ(glyphBuffer.size(), 6U);
+    EXPECT_NEAR(glyphBuffer.advanceAt(0).width(), advances[4].width, 0.0001);
+    EXPECT_NEAR(glyphBuffer.advanceAt(1).width(), advances[3].width, 0.0001);
+    EXPECT_NEAR(glyphBuffer.advanceAt(2).width(), advances[2].width, 0.0001);
+    EXPECT_NEAR(glyphBuffer.advanceAt(3).width(), advances[1].width, 0.0001);
+    EXPECT_NEAR(glyphBuffer.advanceAt(4).width(), -initialAdvance.width, 0.0001);
+    EXPECT_NEAR(glyphBuffer.advanceAt(5).width(), spaceWidth + initialAdvance.width, 0.0001);
+}
+
+TEST_F(ComplexTextControllerTest, DISABLED_InitialAdvanceInRTL)
+{
+    FontCascadeDescription description;
+    description.setOneFamily("Times");
+    description.setComputedSize(80);
+    FontCascade font(description);
+    font.update(nullptr);
+
+#if USE_LAYOUT_SPECIFIC_ADVANCES
+    Vector<CGSize> advances = { CGSizeZero, CGSizeMake(21.640625, 0.0), CGSizeMake(42.3046875, 0.0), CGSizeMake(55.8984375, 0.0), CGSizeMake(22.34375, 0.0) };
+    Vector<CGPoint> origins = { CGPointMake(-15.15625, 18.046875), CGPointZero, CGPointZero, CGPointZero, CGPointZero };
+#else
+    Vector<CGSize> advances = { CGSizeMake(15.15625, -18.046875), CGSizeMake(21.640625, 0.0), CGSizeMake(42.3046875, 0.0), CGSizeMake(55.8984375, 0.0), CGSizeMake(22.34375, 0.0) };
+    Vector<CGPoint> origins = { };
+#endif
+
+    CGSize initialAdvance = CGSizeMake(-15.15625, 18.046875);
+
+    UChar characters[] = { 0x644, 0x637, 0x641, 0x627, 0x64b };
+    size_t charactersLength = WTF_ARRAY_LENGTH(characters);
+    TextRun textRun(StringView(characters, charactersLength));
+    Ref<ComplexTextController::ComplexTextRun> run = ComplexTextController::ComplexTextRun::createForTesting(advances, origins, { 193, 377, 447, 431, 458 }, { 4, 3, 2, 1, 0 }, initialAdvance, font.primaryFont(), characters, 0, charactersLength, CFRangeMake(0, 5), false);
+    Vector<Ref<ComplexTextController::ComplexTextRun>> runs;
+    runs.append(WTFMove(run));
+    ComplexTextController controller(font, textRun, runs);
+
+    CGFloat totalWidth = 0;
+    for (size_t i = 1; i < advances.size(); ++i)
+        totalWidth += advances[i].width;
+    EXPECT_NEAR(controller.totalWidth(), totalWidth, 0.0001);
+    GlyphBuffer glyphBuffer;
+    controller.advance(0, &glyphBuffer);
+    EXPECT_NEAR(controller.runWidthSoFar(), 0, 0.0001);
+    controller.advance(1, &glyphBuffer);
+    EXPECT_NEAR(controller.runWidthSoFar(), advances[4].width, 0.0001);
+    controller.advance(5, &glyphBuffer);
+    EXPECT_NEAR(controller.runWidthSoFar(), totalWidth, 0.0001);
+    EXPECT_NEAR(glyphBuffer.initialAdvance().width(), initialAdvance.width, 0.0001);
+    EXPECT_NEAR(glyphBuffer.initialAdvance().height(), initialAdvance.height, 0.0001);
+    EXPECT_EQ(glyphBuffer.size(), 5U);
+    EXPECT_NEAR(glyphBuffer.advanceAt(0).width(), advances[4].width, 0.0001);
+    EXPECT_NEAR(glyphBuffer.advanceAt(1).width(), advances[3].width, 0.0001);
+    EXPECT_NEAR(glyphBuffer.advanceAt(2).width(), advances[2].width, 0.0001);
+    EXPECT_NEAR(glyphBuffer.advanceAt(3).width(), advances[1].width, 0.0001);
+    EXPECT_NEAR(glyphBuffer.advanceAt(4).width(), -initialAdvance.width, 0.0001);
+}
+
+TEST_F(ComplexTextControllerTest, DISABLED_InitialAdvanceWithLeftRunInLTR)
+{
+    FontCascadeDescription description;
+    description.setOneFamily("LucidaGrande");
+    description.setComputedSize(80);
+    FontCascade font(description);
+    font.update(nullptr);
+    auto spaceWidth = font.primaryFont().spaceWidth();
+
+#if USE_LAYOUT_SPECIFIC_ADVANCES
+    Vector<CGSize> advances = { CGSizeMake(76.347656, 0.000000), CGSizeMake(0.000000, 0.000000) };
+    Vector<CGPoint> origins = { CGPointZero, CGPointMake(-23.281250, -8.398438) };
+#else
+    Vector<CGSize> advances = { CGSizeMake(53.066406, -8.398438), CGSizeMake(23.281250, 8.398438) };
+    Vector<CGPoint> origins = { };
+#endif
+
+    CGSize initialAdvance = CGSizeMake(28.144531, 0);
+
+    UChar characters[] = { 0x20, 0x61, 0x20e3 };
+    size_t charactersLength = WTF_ARRAY_LENGTH(characters);
+    TextRun textRun(StringView(characters, charactersLength));
+    Ref<ComplexTextController::ComplexTextRun> run1 = ComplexTextController::ComplexTextRun::createForTesting({ CGSizeMake(spaceWidth, 0) }, { CGPointZero }, { 5 }, { 0 }, CGSizeZero, font.primaryFont(), characters, 0, charactersLength, CFRangeMake(0, 1), true);
+    Ref<ComplexTextController::ComplexTextRun> run2 = ComplexTextController::ComplexTextRun::createForTesting(advances, origins, { 68, 1471 }, { 1, 2 }, initialAdvance, font.primaryFont(), characters, 0, charactersLength, CFRangeMake(1, 2), true);
+    Vector<Ref<ComplexTextController::ComplexTextRun>> runs;
+    runs.append(WTFMove(run1));
+    runs.append(WTFMove(run2));
+    ComplexTextController controller(font, textRun, runs);
+
+    EXPECT_NEAR(controller.totalWidth(), spaceWidth + 76.347656 + initialAdvance.width, 0.0001);
+    GlyphBuffer glyphBuffer;
+    controller.advance(0, &glyphBuffer);
+    EXPECT_NEAR(controller.runWidthSoFar(), 0, 0.0001);
+    controller.advance(1, &glyphBuffer);
+    EXPECT_NEAR(controller.runWidthSoFar(), spaceWidth, 0.0001);
+    controller.advance(2, &glyphBuffer);
+    EXPECT_NEAR(controller.runWidthSoFar(), spaceWidth + advances[0].width + initialAdvance.width, 0.0001);
+    controller.advance(3, &glyphBuffer);
+    EXPECT_NEAR(controller.runWidthSoFar(), spaceWidth + 76.347656 + initialAdvance.width, 0.0001);
+    EXPECT_NEAR(glyphBuffer.initialAdvance().width(), 0, 0.0001);
+    EXPECT_NEAR(glyphBuffer.initialAdvance().height(), 0, 0.0001);
+    EXPECT_EQ(glyphBuffer.size(), 3U);
+    EXPECT_NEAR(glyphBuffer.advanceAt(0).width(), spaceWidth + initialAdvance.width, 0.0001);
+    EXPECT_NEAR(glyphBuffer.advanceAt(1).width(), 53.066406, 0.0001);
+    EXPECT_NEAR(glyphBuffer.advanceAt(2).width(), 23.281250, 0.0001);
+}
+
+TEST_F(ComplexTextControllerTest, DISABLED_InitialAdvanceInLTR)
+{
+    FontCascadeDescription description;
+    description.setOneFamily("LucidaGrande");
+    description.setComputedSize(80);
+    FontCascade font(description);
+    font.update(nullptr);
+
+#if USE_LAYOUT_SPECIFIC_ADVANCES
+    Vector<CGSize> advances = { CGSizeMake(76.347656, 0.000000), CGSizeMake(0.000000, 0.000000) };
+    Vector<CGPoint> origins = { CGPointZero, CGPointMake(-23.281250, -8.398438) };
+#else
+    Vector<CGSize> advances = { CGSizeMake(53.066406, -8.398438), CGSizeMake(23.281250, 8.398438) };
+    Vector<CGPoint> origins = { };
+#endif
+
+    CGSize initialAdvance = CGSizeMake(28.144531, 0);
+
+    UChar characters[] = { 0x61, 0x20e3 };
+    size_t charactersLength = WTF_ARRAY_LENGTH(characters);
+    TextRun textRun(StringView(characters, charactersLength));
+    Ref<ComplexTextController::ComplexTextRun> run = ComplexTextController::ComplexTextRun::createForTesting(advances, origins, { 68, 1471 }, { 0, 1 }, initialAdvance, font.primaryFont(), characters, 0, charactersLength, CFRangeMake(0, 2), true);
+    Vector<Ref<ComplexTextController::ComplexTextRun>> runs;
+    runs.append(WTFMove(run));
+    ComplexTextController controller(font, textRun, runs);
+
+    EXPECT_NEAR(controller.totalWidth(), 76.347656 + initialAdvance.width, 0.0001);
+    GlyphBuffer glyphBuffer;
+    controller.advance(0, &glyphBuffer);
+    EXPECT_NEAR(controller.runWidthSoFar(), 0, 0.0001);
+    controller.advance(1, &glyphBuffer);
+    EXPECT_NEAR(controller.runWidthSoFar(), advances[0].width + initialAdvance.width, 0.0001);
+    controller.advance(2, &glyphBuffer);
+    EXPECT_NEAR(controller.runWidthSoFar(), 76.347656 + initialAdvance.width, 0.0001);
+    EXPECT_NEAR(glyphBuffer.initialAdvance().width(), initialAdvance.width, 0.0001);
+    EXPECT_NEAR(glyphBuffer.initialAdvance().height(), initialAdvance.height, 0.0001);
+    EXPECT_EQ(glyphBuffer.size(), 2U);
+    EXPECT_NEAR(glyphBuffer.advanceAt(0).width(), 53.066406, 0.0001);
+    EXPECT_NEAR(glyphBuffer.advanceAt(1).width(), 23.281250, 0.0001);
+}
+
+}
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to