Changeset 211294 in webkit


Ignore:
Timestamp:
Jan 27, 2017 12:28:11 PM (7 years ago)
Author:
mmaxfield@apple.com
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

  1. 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):

Location:
trunk
Files:
1 added
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r211292 r211294  
     12017-01-27  Myles C. Maxfield  <mmaxfield@apple.com>
     2
     3        [Cocoa] Prepare ComplexTextController for unit testing
     4        https://bugs.webkit.org/show_bug.cgi?id=167493
     5
     6        Reviewed by Dean Jackson.
     7
     8        ComplexTextController has three phases:
     9        1. Interrogate Core Text about some text
     10        2. Compute layout advances and paint advances from the information retrieved from
     11        Core Text
     12        3. Iterate through the layout advances or paint advances.
     13
     14        This patch tests phases 2 and 3 by chopping ComplexTextController between
     15        phases 1 and 2, and injecting foreign metrics from a unit test. These metrics
     16        have been gathered from real-world uses; however, a layout test is not appropriate
     17        because the fonts which produced these metrics are not licensed appropriately.
     18        The tests can enforce the correct behavior by using ComplexTextController's
     19        public API.
     20
     21        This is in preparation for https://bugs.webkit.org/show_bug.cgi?id=166013.
     22        However, the fix for that bug is quite large, so I've split out this smaller piece
     23        to ease the reviewing burden. The tests I've added are disabled for now (because
     24        they fail), but will be enabled by the fix to that bug.
     25
     26        No new tests because there is no behavior change.
     27
     28        * WebCore.xcodeproj/project.pbxproj:
     29        * platform/graphics/FontCascade.h:
     30        * platform/graphics/FontDescription.h:
     31        * platform/graphics/mac/ComplexTextController.cpp:
     32        (WebCore::ComplexTextController::ComplexTextController):
     33        (WebCore::ComplexTextController::finishConstruction):
     34        * platform/graphics/mac/ComplexTextController.h:
     35        (WebCore::ComplexTextController::ComplexTextRun::createForTesting):
     36        * platform/graphics/mac/ComplexTextControllerCoreText.mm:
     37        (WebCore::ComplexTextController::ComplexTextRun::ComplexTextRun):
     38
    1392017-01-27  Zalan Bujtas  <zalan@apple.com>
    240
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r211283 r211294  
    14531453                37BAAE581980D1DD005DFE71 /* ProtectionSpace.h in Headers */ = {isa = PBXBuildFile; fileRef = 37BAAE571980D1DD005DFE71 /* ProtectionSpace.h */; settings = {ATTRIBUTES = (Private, ); }; };
    14541454                37C236101097EE7700EF9F72 /* ComplexTextController.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37C2360E1097EE7700EF9F72 /* ComplexTextController.cpp */; };
    1455                 37C236111097EE7700EF9F72 /* ComplexTextController.h in Headers */ = {isa = PBXBuildFile; fileRef = 37C2360F1097EE7700EF9F72 /* ComplexTextController.h */; };
     1455                37C236111097EE7700EF9F72 /* ComplexTextController.h in Headers */ = {isa = PBXBuildFile; fileRef = 37C2360F1097EE7700EF9F72 /* ComplexTextController.h */; settings = {ATTRIBUTES = (Private, ); }; };
    14561456                37C238221098C84200EF9F72 /* ComplexTextControllerCoreText.mm in Sources */ = {isa = PBXBuildFile; fileRef = 37C238201098C84200EF9F72 /* ComplexTextControllerCoreText.mm */; };
    14571457                37D456FD1A9A50D8003330A1 /* LocalizableStrings.pm in Copy Scripts */ = {isa = PBXBuildFile; fileRef = 37D456FB1A9A50B6003330A1 /* LocalizableStrings.pm */; };
  • trunk/Source/WebCore/platform/graphics/FontCascade.h

    r208985 r211294  
    115115public:
    116116    WEBCORE_EXPORT FontCascade();
    117     WEBCORE_EXPORT FontCascade(const FontCascadeDescription&, float letterSpacing, float wordSpacing);
     117    WEBCORE_EXPORT FontCascade(const FontCascadeDescription&, float letterSpacing = 0, float wordSpacing = 0);
    118118    // This constructor is only used if the platform wants to start with a native font.
    119119    WEBCORE_EXPORT FontCascade(const FontPlatformData&, FontSmoothingMode = AutoSmoothing);
     
    130130    float size() const { return fontDescription().computedSize(); }
    131131
    132     void update(RefPtr<FontSelector>&&) const;
     132    WEBCORE_EXPORT void update(RefPtr<FontSelector>&&) const;
    133133
    134134    enum CustomFontNotReadyAction { DoNotPaintIfFontNotReady, UseFallbackIfFontNotReady };
  • trunk/Source/WebCore/platform/graphics/FontDescription.h

    r209875 r211294  
    198198class FontCascadeDescription : public FontDescription {
    199199public:
    200     FontCascadeDescription();
     200    WEBCORE_EXPORT FontCascadeDescription();
    201201
    202202    bool operator==(const FontCascadeDescription&) const;
  • trunk/Source/WebCore/platform/graphics/mac/ComplexTextController.cpp

    r209907 r211294  
    129129
    130130    collectComplexTextRuns();
     131
     132    finishConstruction();
     133}
     134
     135ComplexTextController::ComplexTextController(const FontCascade& font, const TextRun& run, Vector<Ref<ComplexTextRun>>& runs)
     136    : m_font(font)
     137    , m_run(run)
     138    , m_end(run.length())
     139{
     140    for (auto& run : runs)
     141        m_complexTextRuns.append(run.ptr());
     142
     143    finishConstruction();
     144}
     145
     146void ComplexTextController::finishConstruction()
     147{
    131148    adjustGlyphsAndAdvances();
    132149
  • trunk/Source/WebCore/platform/graphics/mac/ComplexTextController.h

    r206466 r211294  
    5959    ComplexTextController(const FontCascade&, const TextRun&, bool mayUseNaturalWritingDirection = false, HashSet<const Font*>* fallbackFonts = 0, bool forTextEmphasis = false);
    6060
     61    class ComplexTextRun;
     62    WEBCORE_EXPORT ComplexTextController(const FontCascade&, const TextRun&, Vector<Ref<ComplexTextRun>>&);
     63
    6164    // Advance and emit glyphs up to the specified character.
    62     void advance(unsigned to, GlyphBuffer* = nullptr, GlyphIterationStyle = IncludePartialGlyphs, HashSet<const Font*>* fallbackFonts = nullptr);
     65    WEBCORE_EXPORT void advance(unsigned to, GlyphBuffer* = nullptr, GlyphIterationStyle = IncludePartialGlyphs, HashSet<const Font*>* fallbackFonts = nullptr);
    6366
    6467    // Compute the character offset for a given x coordinate.
     
    7679
    7780    float leadingExpansion() const { return m_leadingExpansion; }
    78    
    79 private:
     81
    8082    class ComplexTextRun : public RefCounted<ComplexTextRun> {
    8183    public:
     
    8890        {
    8991            return adoptRef(*new ComplexTextRun(font, characters, stringLocation, stringLength, ltr));
     92        }
     93
     94        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)
     95        {
     96            return adoptRef(*new ComplexTextRun(advances, origins, glyphs, stringIndices, initialAdvance, font, characters, stringLocation, stringLength, runRange, ltr));
    9097        }
    9198
     
    121128        ComplexTextRun(CTRunRef, const Font&, const UChar* characters, unsigned stringLocation, size_t stringLength, CFRange runRange);
    122129        ComplexTextRun(const Font&, const UChar* characters, unsigned stringLocation, size_t stringLength, bool ltr);
     130        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);
    123131
    124132        Vector<CGSize, 64> m_baseAdvancesVector;
     
    139147        unsigned m_stringLocation;
    140148        bool m_isLTR;
    141         bool m_isMonotonic;
     149        bool m_isMonotonic { true };
    142150    };
     151private:
     152    void finishConstruction();
    143153   
    144154    static unsigned stringBegin(const ComplexTextRun& run) { return run.stringLocation() + run.indexBegin(); }
  • trunk/Source/WebCore/platform/graphics/mac/ComplexTextControllerCoreText.mm

    r206466 r211294  
    112112    , m_characters(characters)
    113113    , m_stringLength(stringLength)
     114    , m_coreTextIndices(CTRunGetStringIndicesPtr(ctRun))
     115    , m_glyphs(CTRunGetGlyphsPtr(ctRun))
    114116    , m_indexBegin(runRange.location)
    115117    , m_indexEnd(runRange.location + runRange.length)
     118    , m_glyphCount(CTRunGetGlyphCount(ctRun))
    116119    , m_stringLocation(stringLocation)
    117120    , m_isLTR(!(CTRunGetStatus(ctRun) & kCTRunStatusRightToLeft))
    118     , m_isMonotonic(true)
    119 {
    120     m_glyphCount = CTRunGetGlyphCount(ctRun);
    121     m_coreTextIndices = CTRunGetStringIndicesPtr(ctRun);
     121{
    122122    if (!m_coreTextIndices) {
    123123        m_coreTextIndicesVector.grow(m_glyphCount);
     
    126126    }
    127127
    128     m_glyphs = CTRunGetGlyphsPtr(ctRun);
    129128    if (!m_glyphs) {
    130129        m_glyphsVector.grow(m_glyphCount);
     
    162161    , m_stringLocation(stringLocation)
    163162    , m_isLTR(ltr)
    164     , m_isMonotonic(true)
    165163{
    166164    m_coreTextIndicesVector.reserveInitialCapacity(m_stringLength);
     
    183181    m_baseAdvancesVector.fill(CGSizeMake(m_font.widthForGlyph(0), 0), m_glyphCount);
    184182    m_baseAdvances = m_baseAdvancesVector.data();
     183}
     184
     185
     186ComplexTextController::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)
     187    : m_baseAdvancesVector(advances)
     188    , m_glyphOrigins(origins)
     189    , m_glyphsVector(glyphs)
     190    , m_coreTextIndicesVector(stringIndices)
     191    , m_initialAdvance(initialAdvance)
     192    , m_font(font)
     193    , m_characters(characters)
     194    , m_stringLength(stringLength)
     195    , m_coreTextIndices(m_coreTextIndicesVector.data())
     196    , m_glyphs(m_glyphsVector.data())
     197    , m_baseAdvances(m_baseAdvancesVector.data())
     198    , m_indexBegin(runRange.location)
     199    , m_indexEnd(runRange.location + runRange.length)
     200    , m_glyphCount(glyphs.size())
     201    , m_stringLocation(stringLocation)
     202    , m_isLTR(ltr)
     203{
    185204}
    186205
  • trunk/Tools/ChangeLog

    r211254 r211294  
     12017-01-27  Myles C. Maxfield  <mmaxfield@apple.com>
     2
     3        [Cocoa] Prepare ComplexTextController for unit testing
     4        https://bugs.webkit.org/show_bug.cgi?id=167493
     5
     6        Reviewed by Dean Jackson.
     7
     8        Create four unit tests.
     9
     10        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
     11        * TestWebKitAPI/Tests/WebCore/ComplexTextController.cpp: Added.
     12        (TestWebKitAPI::ComplexTextControllerTest::SetUp):
     13        (TestWebKitAPI::TEST_F):
     14
    1152017-01-26  Chris Dumez  <cdumez@apple.com>
    216
  • trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj

    r211240 r211294  
    4646                1C2B81861C89259D00A5529F /* webfont.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 1C2B81841C8924A200A5529F /* webfont.html */; };
    4747                1C2B81871C8925A000A5529F /* Ahem.ttf in Copy Resources */ = {isa = PBXBuildFile; fileRef = 1C2B81851C89252300A5529F /* Ahem.ttf */; };
     48                1C9EB8411E380DA1005C6442 /* ComplexTextController.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1C9EB8401E380DA1005C6442 /* ComplexTextController.cpp */; };
    4849                1F83571B1D3FFB2300E3967B /* WKBackForwardList.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1F83571A1D3FFB0E00E3967B /* WKBackForwardList.mm */; };
    4950                26DF5A6315A2A27E003689C2 /* CancelLoadFromResourceLoadDelegate.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 26DF5A6115A2A22B003689C2 /* CancelLoadFromResourceLoadDelegate.html */; };
     
    824825                1C2B81841C8924A200A5529F /* webfont.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = webfont.html; sourceTree = "<group>"; };
    825826                1C2B81851C89252300A5529F /* Ahem.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = Ahem.ttf; sourceTree = "<group>"; };
     827                1C9EB8401E380DA1005C6442 /* ComplexTextController.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ComplexTextController.cpp; sourceTree = "<group>"; };
    826828                1CB9BC371A67482300FE5678 /* WeakPtr.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WeakPtr.cpp; sourceTree = "<group>"; };
    827829                1CF0D3781BBF2F3D00B4EF54 /* WKRetainPtr.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WKRetainPtr.cpp; sourceTree = "<group>"; };
     
    16051607                                5C6E65411D5CEF8500F7862E /* URLParser.cpp */,
    16061608                                9C64DC311D76198A004B598E /* YouTubePluginReplacement.cpp */,
     1609                                1C9EB8401E380DA1005C6442 /* ComplexTextController.cpp */,
    16071610                        );
    16081611                        path = WebCore;
     
    27032706                                5C6E65441D5CEFD400F7862E /* URLParser.cpp in Sources */,
    27042707                                7CCE7F271A411AF600447C4C /* UserContentController.mm in Sources */,
     2708                                1C9EB8411E380DA1005C6442 /* ComplexTextController.cpp in Sources */,
    27052709                                7CCE7F2D1A411B1000447C4C /* UserContentTest.mm in Sources */,
    27062710                                7C882E0A1C80C764006BF731 /* UserContentWorld.mm in Sources */,
Note: See TracChangeset for help on using the changeset viewer.