[Cocoa] Reduce uses of CGFonts in favor of CTFonts
authormmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 12 Sep 2016 21:44:29 +0000 (21:44 +0000)
committermmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 12 Sep 2016 21:44:29 +0000 (21:44 +0000)
https://bugs.webkit.org/show_bug.cgi?id=161809

Reviewed by Daniel Bates.

Source/WebCore:

Eventually, we want to remove the cgFont() member of PlatformFontData for both memory
savings and conceptual clarity. Because there is no performance loss from moving from
CGFontGetGlyphsForUnichars() to CTFontGetGlyphsForCharacters(), making this switch
gets us closer to reducing the uses of cgFont().

No new tests because there is no behavior change.

* platform/graphics/Font.cpp:
(WebCore::createAndFillGlyphPage):
* platform/graphics/GlyphPage.h:
(WebCore::GlyphData::GlyphData):
* platform/graphics/mac/GlyphPageMac.cpp:
(WebCore::shouldFillWithVerticalGlyphs):
(WebCore::GlyphPage::fill):
(WebCore::shouldUseCoreText): Deleted.

Source/WTF:

* wtf/unicode/CharacterNames.h:

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

Source/WTF/ChangeLog
Source/WTF/wtf/unicode/CharacterNames.h
Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/Font.cpp
Source/WebCore/platform/graphics/GlyphPage.h
Source/WebCore/platform/graphics/mac/GlyphPageMac.cpp

index a4e9e17..c6ac49c 100644 (file)
@@ -1,3 +1,12 @@
+2016-09-12  Myles C. Maxfield  <mmaxfield@apple.com>
+
+        [Cocoa] Reduce uses of CGFonts in favor of CTFonts
+        https://bugs.webkit.org/show_bug.cgi?id=161809
+
+        Reviewed by Daniel Bates.
+
+        * wtf/unicode/CharacterNames.h:
+
 2016-09-12  Saam Barati  <sbarati@apple.com>
 
         MapHash should do constant folding when it has a constant argument and its legal to hash that value
index 1dc2794..1c415be 100644 (file)
@@ -37,8 +37,9 @@ namespace Unicode {
 // more convenient for WebCore code that mostly uses UTF-16.
 
 const UChar AppleLogo = 0xF8FF;
-const UChar32 aegeanWordSeparatorLine = 0x10100;
+const UChar HiraganaLetterSmallA = 0x3041;
 const UChar32 aegeanWordSeparatorDot = 0x10101;
+const UChar32 aegeanWordSeparatorLine = 0x10100;
 const UChar apostrophe = 0x0027;
 const UChar blackCircle = 0x25CF;
 const UChar blackSquare = 0x25A0;
@@ -50,10 +51,8 @@ const UChar ethiopicPrefaceColon = 0x1366;
 const UChar ethiopicWordspace = 0x1361;
 const UChar firstStrongIsolate = 0x2068;
 const UChar fisheye = 0x25C9;
-const UChar quotationMark = 0x0022;
 const UChar hebrewPunctuationGeresh = 0x05F3;
 const UChar hebrewPunctuationGershayim = 0x05F4;
-const UChar HiraganaLetterSmallA = 0x3041;
 const UChar horizontalEllipsis = 0x2026;
 const UChar hyphen = 0x2010;
 const UChar hyphenMinus = 0x002D;
@@ -67,12 +66,14 @@ const UChar leftToRightIsolate = 0x2066;
 const UChar leftToRightMark = 0x200E;
 const UChar leftToRightOverride = 0x202D;
 const UChar minusSign = 0x2212;
+const UChar narrowNoBreakSpace = 0x202F;
 const UChar narrowNonBreakingSpace = 0x202F;
 const UChar newlineCharacter = 0x000A;
 const UChar noBreakSpace = 0x00A0;
 const UChar objectReplacementCharacter = 0xFFFC;
 const UChar popDirectionalFormatting = 0x202C;
 const UChar popDirectionalIsolate = 0x2069;
+const UChar quotationMark = 0x0022;
 const UChar replacementCharacter = 0xFFFD;
 const UChar rightDoubleQuotationMark = 0x201D;
 const UChar rightSingleQuotationMark = 0x2019;
@@ -84,8 +85,8 @@ const UChar sesameDot = 0xFE45;
 const UChar smallLetterSharpS = 0x00DF;
 const UChar softHyphen = 0x00AD;
 const UChar space = 0x0020;
-const UChar tibetanMarkIntersyllabicTsheg = 0x0F0B;
 const UChar tibetanMarkDelimiterTshegBstar = 0x0F0C;
+const UChar tibetanMarkIntersyllabicTsheg = 0x0F0B;
 const UChar32 ugariticWordDivider = 0x1039F;
 const UChar whiteBullet = 0x25E6;
 const UChar whiteCircle = 0x25CB;
@@ -93,16 +94,17 @@ const UChar whiteSesameDot = 0xFE46;
 const UChar whiteUpPointingTriangle = 0x25B3;
 const UChar yenSign = 0x00A5;
 const UChar zeroWidthJoiner = 0x200D;
+const UChar zeroWidthNoBreakSpace = 0xFEFF;
 const UChar zeroWidthNonJoiner = 0x200C;
 const UChar zeroWidthSpace = 0x200B;
-const UChar zeroWidthNoBreakSpace = 0xFEFF;
 
 } // namespace Unicode
 } // namespace WTF
 
 using WTF::Unicode::AppleLogo;
-using WTF::Unicode::aegeanWordSeparatorLine;
+using WTF::Unicode::HiraganaLetterSmallA;
 using WTF::Unicode::aegeanWordSeparatorDot;
+using WTF::Unicode::aegeanWordSeparatorLine;
 using WTF::Unicode::blackCircle;
 using WTF::Unicode::blackSquare;
 using WTF::Unicode::blackUpPointingTriangle;
@@ -115,7 +117,6 @@ using WTF::Unicode::firstStrongIsolate;
 using WTF::Unicode::fisheye;
 using WTF::Unicode::hebrewPunctuationGeresh;
 using WTF::Unicode::hebrewPunctuationGershayim;
-using WTF::Unicode::HiraganaLetterSmallA;
 using WTF::Unicode::horizontalEllipsis;
 using WTF::Unicode::hyphen;
 using WTF::Unicode::hyphenMinus;
@@ -129,6 +130,7 @@ using WTF::Unicode::leftToRightIsolate;
 using WTF::Unicode::leftToRightMark;
 using WTF::Unicode::leftToRightOverride;
 using WTF::Unicode::minusSign;
+using WTF::Unicode::narrowNoBreakSpace;
 using WTF::Unicode::narrowNonBreakingSpace;
 using WTF::Unicode::newlineCharacter;
 using WTF::Unicode::noBreakSpace;
@@ -145,8 +147,8 @@ using WTF::Unicode::rightToLeftOverride;
 using WTF::Unicode::sesameDot;
 using WTF::Unicode::softHyphen;
 using WTF::Unicode::space;
-using WTF::Unicode::tibetanMarkIntersyllabicTsheg;
 using WTF::Unicode::tibetanMarkDelimiterTshegBstar;
+using WTF::Unicode::tibetanMarkIntersyllabicTsheg;
 using WTF::Unicode::ugariticWordDivider;
 using WTF::Unicode::whiteBullet;
 using WTF::Unicode::whiteCircle;
@@ -154,8 +156,8 @@ using WTF::Unicode::whiteSesameDot;
 using WTF::Unicode::whiteUpPointingTriangle;
 using WTF::Unicode::yenSign;
 using WTF::Unicode::zeroWidthJoiner;
+using WTF::Unicode::zeroWidthNoBreakSpace;
 using WTF::Unicode::zeroWidthNonJoiner;
 using WTF::Unicode::zeroWidthSpace;
-using WTF::Unicode::zeroWidthNoBreakSpace;
 
 #endif // CharacterNames_h
index 83ad487..bd81b75 100644 (file)
@@ -1,3 +1,26 @@
+2016-09-12  Myles C. Maxfield  <mmaxfield@apple.com>
+
+        [Cocoa] Reduce uses of CGFonts in favor of CTFonts
+        https://bugs.webkit.org/show_bug.cgi?id=161809
+
+        Reviewed by Daniel Bates.
+
+        Eventually, we want to remove the cgFont() member of PlatformFontData for both memory
+        savings and conceptual clarity. Because there is no performance loss from moving from
+        CGFontGetGlyphsForUnichars() to CTFontGetGlyphsForCharacters(), making this switch
+        gets us closer to reducing the uses of cgFont().
+
+        No new tests because there is no behavior change.
+
+        * platform/graphics/Font.cpp:
+        (WebCore::createAndFillGlyphPage):
+        * platform/graphics/GlyphPage.h:
+        (WebCore::GlyphData::GlyphData):
+        * platform/graphics/mac/GlyphPageMac.cpp:
+        (WebCore::shouldFillWithVerticalGlyphs):
+        (WebCore::GlyphPage::fill):
+        (WebCore::shouldUseCoreText): Deleted.
+
 2016-09-12  Alex Christensen  <achristensen@webkit.org>
 
         Remove trailing control characters and spaces before parsing a URL
index 4834095..6d24d20 100644 (file)
@@ -187,6 +187,7 @@ static RefPtr<GlyphPage> createAndFillGlyphPage(unsigned pageNumber, const Font&
         overwriteCodePoint('\n', space);
         overwriteCodePoint('\t', space);
         overwriteCodePoint(noBreakSpace, space);
+        overwriteCodePoint(narrowNoBreakSpace, zeroWidthSpace);
         overwriteCodePoint(leftToRightMark, zeroWidthSpace);
         overwriteCodePoint(rightToLeftMark, zeroWidthSpace);
         overwriteCodePoint(leftToRightEmbed, zeroWidthSpace);
index a1a5944..cd0dcd4 100644 (file)
@@ -31,7 +31,6 @@
 #define GlyphPage_h
 
 #include "Glyph.h"
-#include <string.h>
 #include <unicode/utypes.h>
 #include <wtf/RefCounted.h>
 #include <wtf/Ref.h>
@@ -43,9 +42,9 @@ class Font;
 // Holds the glyph index and the corresponding Font information for a given
 // character.
 struct GlyphData {
-    GlyphData(Glyph g = 0, const Font* f = 0)
-        : glyph(g)
-        , font(f)
+    GlyphData(Glyph glyph = 0, const Font* font = nullptr)
+        : glyph(glyph)
+        , font(font)
     {
     }
 
index f39c8dc..bbff11b 100644 (file)
 
 namespace WebCore {
 
-static bool shouldUseCoreText(const UChar* buffer, unsigned bufferLength, const Font& fontData)
+static bool shouldFillWithVerticalGlyphs(const UChar* buffer, unsigned bufferLength, const Font& font)
 {
-    // This needs to be kept in sync with GlyphPage::fill(). Currently, the CoreText paths are not able to handle
-    // every situtation. Returning true from this function in a new situation will require you to explicitly add
-    // handling for that situation in the CoreText paths of GlyphPage::fill().
-    if (fontData.platformData().isSystemFont())
-        return true;
-    if (fontData.platformData().isForTextCombine() || fontData.hasVerticalGlyphs()) {
-        // Ideographs don't have a vertical variant or width variants.
-        for (unsigned i = 0; i < bufferLength; ++i) {
-            if (!FontCascade::isCJKIdeograph(buffer[i]))
-                return true;
-        }
+    if (!font.hasVerticalGlyphs())
+        return false;
+    for (unsigned i = 0; i < bufferLength; ++i) {
+        if (!FontCascade::isCJKIdeograph(buffer[i]))
+            return true;
     }
-
     return false;
 }
 
@@ -64,26 +57,12 @@ bool GlyphPage::fill(UChar* buffer, unsigned bufferLength)
 
     const Font& font = this->font();
     Vector<CGGlyph, 512> glyphs(bufferLength);
-    unsigned glyphStep;
-    if (!shouldUseCoreText(buffer, bufferLength, font)) {
-        // We pass in either 256 or 512 UTF-16 characters: 256 for U+FFFF and less, 512 (double character surrogates)
-        // for U+10000 and above. It is indeed possible to get back 512 glyphs back from the API, so the glyph buffer
-        // we pass in must be 512. If we get back more than 256 glyphs though we'll ignore all the ones after 256,
-        // this should not happen as the only time we pass in 512 characters is when they are surrogates.
-        CGFontGetGlyphsForUnichars(font.platformData().cgFont(), buffer, glyphs.data(), bufferLength);
-        glyphStep = 1;
-    } else {
-        // Because we know the implementation of shouldUseCoreText(), if the font isn't for text combine and it isn't a system font,
-        // we know it must have vertical glyphs.
-        if (font.platformData().isForTextCombine() || font.platformData().isSystemFont())
-            CTFontGetGlyphsForCharacters(font.platformData().ctFont(), buffer, glyphs.data(), bufferLength);
-        else
-            CTFontGetVerticalGlyphsForCharacters(font.platformData().ctFont(), buffer, glyphs.data(), bufferLength);
+    unsigned glyphStep = bufferLength / GlyphPage::size;
 
-        // When buffer consists of surrogate pairs, CTFontGetVerticalGlyphsForCharacters and CTFontGetGlyphsForCharacters
-        // place the glyphs at indices corresponding to the first character of each pair.
-        glyphStep = bufferLength / GlyphPage::size;
-    }
+    if (shouldFillWithVerticalGlyphs(buffer, bufferLength, font))
+        CTFontGetVerticalGlyphsForCharacters(font.platformData().ctFont(), buffer, glyphs.data(), bufferLength);
+    else
+        CTFontGetGlyphsForCharacters(font.platformData().ctFont(), buffer, glyphs.data(), bufferLength);
 
     bool haveGlyphs = false;
     for (unsigned i = 0; i < GlyphPage::size; ++i) {