Title: [205826] trunk/Source
Revision
205826
Author
mmaxfi...@apple.com
Date
2016-09-12 14:44:29 -0700 (Mon, 12 Sep 2016)

Log Message

[Cocoa] Reduce uses of CGFonts in favor of CTFonts
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:

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (205825 => 205826)


--- trunk/Source/WTF/ChangeLog	2016-09-12 21:42:31 UTC (rev 205825)
+++ trunk/Source/WTF/ChangeLog	2016-09-12 21:44:29 UTC (rev 205826)
@@ -1,3 +1,12 @@
+2016-09-12  Myles C. Maxfield  <mmaxfi...@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  <sbar...@apple.com>
 
         MapHash should do constant folding when it has a constant argument and its legal to hash that value

Modified: trunk/Source/WTF/wtf/unicode/CharacterNames.h (205825 => 205826)


--- trunk/Source/WTF/wtf/unicode/CharacterNames.h	2016-09-12 21:42:31 UTC (rev 205825)
+++ trunk/Source/WTF/wtf/unicode/CharacterNames.h	2016-09-12 21:44:29 UTC (rev 205826)
@@ -37,8 +37,9 @@
 // more convenient for WebCore code that mostly uses UTF-16.
 
 const UChar AppleLogo = 0xF8FF;
+const UChar HiraganaLetterSmallA = 0x3041;
+const UChar32 aegeanWordSeparatorDot = 0x10101;
 const UChar32 aegeanWordSeparatorLine = 0x10100;
-const UChar32 aegeanWordSeparatorDot = 0x10101;
 const UChar apostrophe = 0x0027;
 const UChar blackCircle = 0x25CF;
 const UChar blackSquare = 0x25A0;
@@ -50,10 +51,8 @@
 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,6 +66,7 @@
 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;
@@ -73,6 +73,7 @@
 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 smallLetterSharpS = 0x00DF;
 const UChar softHyphen = 0x00AD;
 const UChar space = 0x0020;
+const UChar tibetanMarkDelimiterTshegBstar = 0x0F0C;
 const UChar tibetanMarkIntersyllabicTsheg = 0x0F0B;
-const UChar tibetanMarkDelimiterTshegBstar = 0x0F0C;
 const UChar32 ugariticWordDivider = 0x1039F;
 const UChar whiteBullet = 0x25E6;
 const UChar whiteCircle = 0x25CB;
@@ -93,16 +94,17 @@
 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::HiraganaLetterSmallA;
+using WTF::Unicode::aegeanWordSeparatorDot;
 using WTF::Unicode::aegeanWordSeparatorLine;
-using WTF::Unicode::aegeanWordSeparatorDot;
 using WTF::Unicode::blackCircle;
 using WTF::Unicode::blackSquare;
 using WTF::Unicode::blackUpPointingTriangle;
@@ -115,7 +117,6 @@
 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::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::sesameDot;
 using WTF::Unicode::softHyphen;
 using WTF::Unicode::space;
+using WTF::Unicode::tibetanMarkDelimiterTshegBstar;
 using WTF::Unicode::tibetanMarkIntersyllabicTsheg;
-using WTF::Unicode::tibetanMarkDelimiterTshegBstar;
 using WTF::Unicode::ugariticWordDivider;
 using WTF::Unicode::whiteBullet;
 using WTF::Unicode::whiteCircle;
@@ -154,8 +156,8 @@
 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

Modified: trunk/Source/WebCore/ChangeLog (205825 => 205826)


--- trunk/Source/WebCore/ChangeLog	2016-09-12 21:42:31 UTC (rev 205825)
+++ trunk/Source/WebCore/ChangeLog	2016-09-12 21:44:29 UTC (rev 205826)
@@ -1,3 +1,26 @@
+2016-09-12  Myles C. Maxfield  <mmaxfi...@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  <achristen...@webkit.org>
 
         Remove trailing control characters and spaces before parsing a URL

Modified: trunk/Source/WebCore/platform/graphics/Font.cpp (205825 => 205826)


--- trunk/Source/WebCore/platform/graphics/Font.cpp	2016-09-12 21:42:31 UTC (rev 205825)
+++ trunk/Source/WebCore/platform/graphics/Font.cpp	2016-09-12 21:44:29 UTC (rev 205826)
@@ -187,6 +187,7 @@
         overwriteCodePoint('\n', space);
         overwriteCodePoint('\t', space);
         overwriteCodePoint(noBreakSpace, space);
+        overwriteCodePoint(narrowNoBreakSpace, zeroWidthSpace);
         overwriteCodePoint(leftToRightMark, zeroWidthSpace);
         overwriteCodePoint(rightToLeftMark, zeroWidthSpace);
         overwriteCodePoint(leftToRightEmbed, zeroWidthSpace);

Modified: trunk/Source/WebCore/platform/graphics/GlyphPage.h (205825 => 205826)


--- trunk/Source/WebCore/platform/graphics/GlyphPage.h	2016-09-12 21:42:31 UTC (rev 205825)
+++ trunk/Source/WebCore/platform/graphics/GlyphPage.h	2016-09-12 21:44:29 UTC (rev 205826)
@@ -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 @@
 // 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)
     {
     }
 

Modified: trunk/Source/WebCore/platform/graphics/mac/GlyphPageMac.cpp (205825 => 205826)


--- trunk/Source/WebCore/platform/graphics/mac/GlyphPageMac.cpp	2016-09-12 21:42:31 UTC (rev 205825)
+++ trunk/Source/WebCore/platform/graphics/mac/GlyphPageMac.cpp	2016-09-12 21:44:29 UTC (rev 205826)
@@ -40,21 +40,14 @@
 
 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 @@
 
     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) {
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to