Title: [204858] trunk/Source/WebCore
Revision
204858
Author
[email protected]
Date
2016-08-23 14:11:20 -0700 (Tue, 23 Aug 2016)

Log Message

[Cocoa] Reduce uses of CGFonts
https://bugs.webkit.org/show_bug.cgi?id=160896

Reviewed by Darin Adler.

There are a few places where we unnecessarily use CGFonts instead of
CTFonts. We have had an ongoing effort throughout the past few years
of elliminating all of our uses of CGFonts, and this patch moves us
in that direction.

Most of the changes in this patch are straightforward (e.g.
CGFontGetUnitsPerEm() -> CTFontGetUnitsPerEm()). However, there is
one notable change: from CGContextShowGlyphsWithAdvances() to
CTFontDrawGlyphs(). This migration does not cause a performance
regression.

No new tests because there is no behavior change.

* WebCore.xcodeproj/project.pbxproj: Delete unnecessary
FontServicesIOS files.
* platform/graphics/FontMetrics.h:
(WebCore::FontMetrics::xHeight): Migrate to Optional<float>
(WebCore::FontMetrics::setXHeight):
(WebCore::FontMetrics::hasXHeight):
(WebCore::FontMetrics::hasCapHeight): Ditto.
(WebCore::FontMetrics::floatCapHeight):
(WebCore::FontMetrics::setCapHeight):
(WebCore::FontMetrics::capHeight):
(WebCore::FontMetrics::setZeroWidth): No one ever used the
m_hasZeroWidth variable, so this patch removes it.
(WebCore::FontMetrics::reset):
(WebCore::FontMetrics::FontMetrics): Deleted.
(WebCore::FontMetrics::setHasXHeight): Deleted. No one ever calls
this, so this patch removes it.
(WebCore::FontMetrics::hasZeroWidth): Deleted.
(WebCore::FontMetrics::setHasZeroWidth): Deleted.
* platform/graphics/cocoa/FontCascadeCocoa.mm:
(WebCore::TextMatrixRestorer::TextMatrixRestorer): Rather than leaving
the text matrix stale after using it, this class cleans it up after us.
This means that the text matrix doesn't have to be reset in other places
which draw text.
(WebCore::TextMatrixRestorer::~TextMatrixRestorer):
(WebCore::TextMatrixRestorer::savedMatrix):
(WebCore::showGlyphsWithAdvances): Migrate from
CGContextShowGlyphsWithAdvances() to CTFontDrawGlyphs()
(WebCore::FontCascade::drawGlyphs): See above comment about the text
matrix.
(WebCore::RenderingStyleSaver::RenderingStyleSaver): Deleted.
(WebCore::RenderingStyleSaver::~RenderingStyleSaver): Deleted.
* platform/graphics/cocoa/FontCocoa.mm:
(WebCore::shouldUseAdjustment): Taken from FontServicesIOS.
(WebCore::Font::platformInit): Migrate from CG to CT for some direct
replacement API calls.
(WebCore::Font::platformCharWidthInit): Ditto.
(WebCore::Font::determinePitch): Ditto.
* platform/graphics/cocoa/FontPlatformDataCocoa.mm:
(WebCore::FontPlatformData::openTypeTable): Ditto.
(WebCore::FontPlatformData::description): Ditto.
* platform/graphics/ios/FontServicesIOS.h: Removed. No longer needed
after migrating from CGContextShowGlyphsWithAdvances() to
CTFontDrawGlyphs().
(WebCore::FontServicesIOS::ascent): Deleted.
(WebCore::FontServicesIOS::descent): Deleted.
(WebCore::FontServicesIOS::lineGap): Deleted.
(WebCore::FontServicesIOS::lineSpacing): Deleted.
(WebCore::FontServicesIOS::xHeight): Deleted.
(WebCore::FontServicesIOS::capHeight): Deleted.
(WebCore::FontServicesIOS::unitsPerEm): Deleted.
* platform/graphics/ios/FontServicesIOS.mm: Removed. Moved into
Font::platformInit().
(WebCore::shouldUseAdjustment): Deleted.
(WebCore::isCourier): Deleted.
(WebCore::FontServicesIOS::FontServicesIOS): Deleted.
* platform/graphics/opentype/OpenTypeCG.cpp:
(WebCore::OpenType::tryGetTypoMetrics): Migrate from CG to CT for some
direct replacement API calls.
* platform/graphics/opentype/OpenTypeCG.h: Ditto.
* platform/graphics/win/FontCGWin.cpp:
(WebCore::FontCascade::drawGlyphs): Restore the text matrix.
* platform/graphics/win/SimpleFontDataCGWin.cpp:
(WebCore::Font::platformWidthForGlyph): Deleted.
* platform/spi/cg/CoreGraphicsSPI.h:
* platform/spi/cocoa/CoreTextSPI.h:
* rendering/RenderThemeIOS.mm:
(WebCore::paintAttachmentText): Deleted.
* rendering/RenderThemeMac.mm:
(WebCore::paintAttachmentTitle): Deleted.
(WebCore::paintAttachmentSubtitle): Deleted.

Modified Paths

Removed Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (204857 => 204858)


--- trunk/Source/WebCore/ChangeLog	2016-08-23 20:43:56 UTC (rev 204857)
+++ trunk/Source/WebCore/ChangeLog	2016-08-23 21:11:20 UTC (rev 204858)
@@ -1,3 +1,94 @@
+2016-08-23  Myles C. Maxfield  <[email protected]>
+
+        [Cocoa] Reduce uses of CGFonts
+        https://bugs.webkit.org/show_bug.cgi?id=160896
+
+        Reviewed by Darin Adler.
+
+        There are a few places where we unnecessarily use CGFonts instead of
+        CTFonts. We have had an ongoing effort throughout the past few years
+        of elliminating all of our uses of CGFonts, and this patch moves us
+        in that direction.
+
+        Most of the changes in this patch are straightforward (e.g.
+        CGFontGetUnitsPerEm() -> CTFontGetUnitsPerEm()). However, there is
+        one notable change: from CGContextShowGlyphsWithAdvances() to
+        CTFontDrawGlyphs(). This migration does not cause a performance
+        regression.
+
+        No new tests because there is no behavior change.
+
+        * WebCore.xcodeproj/project.pbxproj: Delete unnecessary
+        FontServicesIOS files.
+        * platform/graphics/FontMetrics.h:
+        (WebCore::FontMetrics::xHeight): Migrate to Optional<float>
+        (WebCore::FontMetrics::setXHeight):
+        (WebCore::FontMetrics::hasXHeight):
+        (WebCore::FontMetrics::hasCapHeight): Ditto.
+        (WebCore::FontMetrics::floatCapHeight):
+        (WebCore::FontMetrics::setCapHeight):
+        (WebCore::FontMetrics::capHeight):
+        (WebCore::FontMetrics::setZeroWidth): No one ever used the
+        m_hasZeroWidth variable, so this patch removes it.
+        (WebCore::FontMetrics::reset):
+        (WebCore::FontMetrics::FontMetrics): Deleted.
+        (WebCore::FontMetrics::setHasXHeight): Deleted. No one ever calls
+        this, so this patch removes it.
+        (WebCore::FontMetrics::hasZeroWidth): Deleted.
+        (WebCore::FontMetrics::setHasZeroWidth): Deleted.
+        * platform/graphics/cocoa/FontCascadeCocoa.mm:
+        (WebCore::TextMatrixRestorer::TextMatrixRestorer): Rather than leaving
+        the text matrix stale after using it, this class cleans it up after us.
+        This means that the text matrix doesn't have to be reset in other places
+        which draw text.
+        (WebCore::TextMatrixRestorer::~TextMatrixRestorer):
+        (WebCore::TextMatrixRestorer::savedMatrix):
+        (WebCore::showGlyphsWithAdvances): Migrate from
+        CGContextShowGlyphsWithAdvances() to CTFontDrawGlyphs()
+        (WebCore::FontCascade::drawGlyphs): See above comment about the text
+        matrix.
+        (WebCore::RenderingStyleSaver::RenderingStyleSaver): Deleted.
+        (WebCore::RenderingStyleSaver::~RenderingStyleSaver): Deleted.
+        * platform/graphics/cocoa/FontCocoa.mm:
+        (WebCore::shouldUseAdjustment): Taken from FontServicesIOS.
+        (WebCore::Font::platformInit): Migrate from CG to CT for some direct
+        replacement API calls.
+        (WebCore::Font::platformCharWidthInit): Ditto.
+        (WebCore::Font::determinePitch): Ditto.
+        * platform/graphics/cocoa/FontPlatformDataCocoa.mm:
+        (WebCore::FontPlatformData::openTypeTable): Ditto.
+        (WebCore::FontPlatformData::description): Ditto.
+        * platform/graphics/ios/FontServicesIOS.h: Removed. No longer needed
+        after migrating from CGContextShowGlyphsWithAdvances() to
+        CTFontDrawGlyphs().
+        (WebCore::FontServicesIOS::ascent): Deleted.
+        (WebCore::FontServicesIOS::descent): Deleted.
+        (WebCore::FontServicesIOS::lineGap): Deleted.
+        (WebCore::FontServicesIOS::lineSpacing): Deleted.
+        (WebCore::FontServicesIOS::xHeight): Deleted.
+        (WebCore::FontServicesIOS::capHeight): Deleted.
+        (WebCore::FontServicesIOS::unitsPerEm): Deleted.
+        * platform/graphics/ios/FontServicesIOS.mm: Removed. Moved into
+        Font::platformInit().
+        (WebCore::shouldUseAdjustment): Deleted.
+        (WebCore::isCourier): Deleted.
+        (WebCore::FontServicesIOS::FontServicesIOS): Deleted.
+        * platform/graphics/opentype/OpenTypeCG.cpp:
+        (WebCore::OpenType::tryGetTypoMetrics): Migrate from CG to CT for some
+        direct replacement API calls.
+        * platform/graphics/opentype/OpenTypeCG.h: Ditto.
+        * platform/graphics/win/FontCGWin.cpp:
+        (WebCore::FontCascade::drawGlyphs): Restore the text matrix.
+        * platform/graphics/win/SimpleFontDataCGWin.cpp:
+        (WebCore::Font::platformWidthForGlyph): Deleted.
+        * platform/spi/cg/CoreGraphicsSPI.h:
+        * platform/spi/cocoa/CoreTextSPI.h:
+        * rendering/RenderThemeIOS.mm:
+        (WebCore::paintAttachmentText): Deleted.
+        * rendering/RenderThemeMac.mm:
+        (WebCore::paintAttachmentTitle): Deleted.
+        (WebCore::paintAttachmentSubtitle): Deleted.
+
 2016-08-23  Alex Christensen  <[email protected]>
 
         Fix CMake build after r204852.

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (204857 => 204858)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2016-08-23 20:43:56 UTC (rev 204857)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2016-08-23 21:11:20 UTC (rev 204858)
@@ -5440,8 +5440,6 @@
 		C55C7BA11718AFBA001327E4 /* RenderThemeIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = C55C7BA01718AFBA001327E4 /* RenderThemeIOS.mm */; };
 		C572EE1F1201C9BC007D8F82 /* JSIDBIndex.h in Headers */ = {isa = PBXBuildFile; fileRef = C572EE1D1201C9BC007D8F82 /* JSIDBIndex.h */; };
 		C57FEDE11212EE9C0097BE65 /* FileSystem.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C57FEDE01212EE9C0097BE65 /* FileSystem.cpp */; };
-		C58361A91744523F00173511 /* FontServicesIOS.h in Headers */ = {isa = PBXBuildFile; fileRef = C58361A71744523F00173511 /* FontServicesIOS.h */; };
-		C58361AA1744523F00173511 /* FontServicesIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = C58361A81744523F00173511 /* FontServicesIOS.mm */; };
 		C585A66211D4FAC5004C3E4B /* IDBBindingUtilities.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C585A66011D4FAC5004C3E4B /* IDBBindingUtilities.cpp */; };
 		C585A66311D4FAC5004C3E4B /* IDBBindingUtilities.h in Headers */ = {isa = PBXBuildFile; fileRef = C585A66111D4FAC5004C3E4B /* IDBBindingUtilities.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		C585A68311D4FB08004C3E4B /* JSIDBDatabase.h in Headers */ = {isa = PBXBuildFile; fileRef = C585A66B11D4FB07004C3E4B /* JSIDBDatabase.h */; };
@@ -12885,8 +12883,6 @@
 		C55C7BA01718AFBA001327E4 /* RenderThemeIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = RenderThemeIOS.mm; sourceTree = "<group>"; };
 		C572EE1D1201C9BC007D8F82 /* JSIDBIndex.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSIDBIndex.h; sourceTree = "<group>"; };
 		C57FEDE01212EE9C0097BE65 /* FileSystem.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FileSystem.cpp; sourceTree = "<group>"; };
-		C58361A71744523F00173511 /* FontServicesIOS.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FontServicesIOS.h; sourceTree = "<group>"; };
-		C58361A81744523F00173511 /* FontServicesIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FontServicesIOS.mm; sourceTree = "<group>"; };
 		C585A66011D4FAC5004C3E4B /* IDBBindingUtilities.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = IDBBindingUtilities.cpp; sourceTree = "<group>"; };
 		C585A66111D4FAC5004C3E4B /* IDBBindingUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IDBBindingUtilities.h; sourceTree = "<group>"; };
 		C585A66B11D4FB07004C3E4B /* JSIDBDatabase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSIDBDatabase.h; sourceTree = "<group>"; };
@@ -16019,8 +16015,6 @@
 				0F97A657155DA81E00FADD4C /* DisplayRefreshMonitorIOS.mm */,
 				1AC2D89C1B1E291F00D52E87 /* FontAntialiasingStateSaver.h */,
 				3727DFD4142AAE4500D449CB /* FontCacheIOS.mm */,
-				C58361A71744523F00173511 /* FontServicesIOS.h */,
-				C58361A81744523F00173511 /* FontServicesIOS.mm */,
 				31AB4FFF122878A2001A7DB0 /* GraphicsContext3DIOS.h */,
 				FED13D3F0CEA939400D89466 /* IconIOS.mm */,
 			);
@@ -24332,7 +24326,6 @@
 				371F4FFC0D25E7F300ECE0D5 /* FontRanges.h in Headers */,
 				B2C3DA6B0D006CD600EF6F26 /* FontSelector.h in Headers */,
 				E419041F1CC6486B00C35F5D /* FontSelectorClient.h in Headers */,
-				C58361A91744523F00173511 /* FontServicesIOS.h in Headers */,
 				C2015C0A1BE6FEB200822389 /* FontVariantBuilder.h in Headers */,
 				4A0DA2FF129B241900AB61E1 /* FormAssociatedElement.h in Headers */,
 				D05CED2A0A40BB2C00C5AF38 /* FormatBlockCommand.h in Headers */,
@@ -27949,7 +27942,6 @@
 				84B62685133138F90095A489 /* FontPlatformData.cpp in Sources */,
 				B5320D6C122A24E9002D1440 /* FontPlatformDataCocoa.mm in Sources */,
 				371F4FFD0D25E7F300ECE0D5 /* FontRanges.cpp in Sources */,
-				C58361AA1744523F00173511 /* FontServicesIOS.mm in Sources */,
 				1C3249111C6D6A3B007EDB32 /* FontVariantBuilder.cpp in Sources */,
 				4A0DA2FE129B241900AB61E1 /* FormAssociatedElement.cpp in Sources */,
 				D05CED290A40BB2C00C5AF38 /* FormatBlockCommand.cpp in Sources */,

Modified: trunk/Source/WebCore/platform/graphics/FontMetrics.h (204857 => 204858)


--- trunk/Source/WebCore/platform/graphics/FontMetrics.h	2016-08-23 20:43:56 UTC (rev 204857)
+++ trunk/Source/WebCore/platform/graphics/FontMetrics.h	2016-08-23 21:11:20 UTC (rev 204858)
@@ -22,25 +22,13 @@
 
 #include "FontBaseline.h"
 #include <wtf/MathExtras.h>
+#include <wtf/Optional.h>
 
 namespace WebCore {
 
-const unsigned gDefaultUnitsPerEm = 1000;
-
 class FontMetrics {
 public:
-    FontMetrics()
-        : m_unitsPerEm(gDefaultUnitsPerEm)
-        , m_ascent(0)
-        , m_descent(0)
-        , m_lineGap(0)
-        , m_lineSpacing(0)
-        , m_xHeight(0)
-        , m_zeroWidth(0)
-        , m_hasXHeight(false)
-        , m_hasZeroWidth(false)
-    {
-    }
+    static const unsigned defaultUnitsPerEm = 1000;
 
     unsigned unitsPerEm() const { return m_unitsPerEm; }
     void setUnitsPerEm(unsigned unitsPerEm) { m_unitsPerEm = unitsPerEm; }
@@ -75,22 +63,12 @@
     void setLineSpacing(float lineSpacing) { m_lineSpacing = lineSpacing; }
 
     float xHeight() const { return m_xHeight; }
-    void setXHeight(float xHeight) 
-    { 
-        m_xHeight = xHeight;
-        m_hasXHeight = true;
-    }
-
-    bool hasXHeight() const { return m_hasXHeight && m_xHeight > 0; }
-    void setHasXHeight(bool hasXHeight) { m_hasXHeight = hasXHeight; }
+    void setXHeight(float xHeight) { m_xHeight = xHeight; }
+    bool hasXHeight() const { return m_xHeight > 0; }
     
-    bool hasCapHeight() const { return m_hasCapHeight && m_capHeight > 0; }
+    bool hasCapHeight() const { return m_capHeight > 0; }
     float floatCapHeight() const { return m_capHeight; }
-    void setCapHeight(float capHeight)
-    { 
-        m_capHeight = capHeight;
-        m_hasCapHeight = true;
-    }
+    void setCapHeight(float capHeight) { m_capHeight = capHeight; }
     
     // Integer variants of certain metrics, used for HTML rendering.
     int ascent(FontBaseline baselineType = AlphabeticBaseline) const
@@ -123,40 +101,31 @@
     }
 
     float zeroWidth() const { return m_zeroWidth; }
-    void setZeroWidth(float zeroWidth)
-    {
-        m_zeroWidth = zeroWidth;
-        m_hasZeroWidth = true;
-    }
+    void setZeroWidth(float zeroWidth) { m_zeroWidth = zeroWidth; }
 
-    bool hasZeroWidth() const { return m_hasZeroWidth; }
-    void setHasZeroWidth(bool hasZeroWidth) { m_hasZeroWidth = hasZeroWidth; }
-
 private:
     friend class Font;
 
     void reset()
     {
-        m_unitsPerEm = gDefaultUnitsPerEm;
+        m_unitsPerEm = defaultUnitsPerEm;
         m_ascent = 0;
         m_descent = 0;
         m_lineGap = 0;
         m_lineSpacing = 0;
         m_xHeight = 0;
-        m_hasXHeight = false;
+        m_capHeight = 0;
+        m_zeroWidth = 0;
     }
 
-    unsigned m_unitsPerEm;
-    float m_ascent;
-    float m_descent;
-    float m_lineGap;
-    float m_lineSpacing;
-    float m_xHeight;
-    float m_capHeight;
-    float m_zeroWidth;
-    bool m_hasXHeight;
-    bool m_hasCapHeight;
-    bool m_hasZeroWidth;
+    unsigned m_unitsPerEm { defaultUnitsPerEm };
+    float m_ascent { 0 };
+    float m_descent { 0 };
+    float m_lineGap { 0 };
+    float m_lineSpacing { 0 };
+    float m_zeroWidth { 0 };
+    float m_xHeight { 0 };
+    float m_capHeight { 0 };
 };
 
 static inline float scaleEmToUnits(float x, unsigned unitsPerEm)

Modified: trunk/Source/WebCore/platform/graphics/FontPlatformData.h (204857 => 204858)


--- trunk/Source/WebCore/platform/graphics/FontPlatformData.h	2016-08-23 20:43:56 UTC (rev 204857)
+++ trunk/Source/WebCore/platform/graphics/FontPlatformData.h	2016-08-23 21:11:20 UTC (rev 204858)
@@ -44,9 +44,6 @@
 #endif
 
 #if PLATFORM(COCOA)
-#if PLATFORM(IOS)
-#import <CoreGraphics/CoreGraphics.h>
-#endif
 #if USE(APPKIT)
 OBJC_CLASS NSFont;
 #endif
@@ -56,7 +53,7 @@
 #endif
 
 #if USE(CG)
-typedef struct CGFont* CGFontRef;
+#include <CoreGraphics/CoreGraphics.h>
 #endif
 
 #include <wtf/Forward.h>
@@ -292,6 +289,32 @@
 }
 #endif
 
+#if USE(CG)
+class ScopedTextMatrix {
+public:
+    ScopedTextMatrix(CGAffineTransform newMatrix, CGContextRef context)
+        : m_context(context)
+        , m_textMatrix(CGContextGetTextMatrix(context))
+    {
+        CGContextSetTextMatrix(m_context, newMatrix);
+    }
+
+    ~ScopedTextMatrix()
+    {
+        CGContextSetTextMatrix(m_context, m_textMatrix);
+    }
+
+    CGAffineTransform savedMatrix() const
+    {
+        return m_textMatrix;
+    }
+
+private:
+    CGContextRef m_context;
+    CGAffineTransform m_textMatrix;
+};
+#endif
+
 } // namespace WebCore
 
 #endif // FontPlatformData_h

Modified: trunk/Source/WebCore/platform/graphics/cocoa/FontCascadeCocoa.mm (204857 => 204858)


--- trunk/Source/WebCore/platform/graphics/cocoa/FontCascadeCocoa.mm	2016-08-23 20:43:56 UTC (rev 204857)
+++ trunk/Source/WebCore/platform/graphics/cocoa/FontCascadeCocoa.mm	2016-08-23 21:11:20 UTC (rev 204858)
@@ -131,33 +131,6 @@
 #endif
 }
 
-class RenderingStyleSaver {
-public:
-#if !PLATFORM(MAC) || __MAC_OS_X_VERSION_MIN_REQUIRED <= 101000
-    RenderingStyleSaver(CTFontRef, CGContextRef) { }
-#else
-    RenderingStyleSaver(CTFontRef font, CGContextRef context)
-        : m_context(context)
-    {
-        m_changed = CTFontSetRenderingStyle(font, context, &m_originalStyle, &m_originalDilation);
-    }
-
-    ~RenderingStyleSaver()
-    {
-        if (!m_changed)
-            return;
-        CGContextSetFontRenderingStyle(m_context, m_originalStyle);
-        CGContextSetFontDilation(m_context, m_originalDilation);
-    }
-
-private:
-    bool m_changed;
-    CGContextRef m_context;
-    CGFontRenderingStyle m_originalStyle;
-    CGSize m_originalDilation;
-#endif
-};
-
 static void showGlyphsWithAdvances(const FloatPoint& point, const Font& font, CGContextRef context, const CGGlyph* glyphs, const CGSize* advances, unsigned count)
 {
     if (!count)
@@ -167,13 +140,10 @@
 
     const FontPlatformData& platformData = font.platformData();
     Vector<CGPoint, 256> positions(count);
-    if (platformData.isColorBitmapFont())
-        fillVectorWithHorizontalGlyphPositions(positions, context, advances, count);
     if (platformData.orientation() == Vertical) {
-        CGAffineTransform savedMatrix;
         CGAffineTransform rotateLeftTransform = CGAffineTransformMake(0, -1, 1, 0, 0, 0);
-        savedMatrix = CGContextGetTextMatrix(context);
-        CGAffineTransform runMatrix = CGAffineTransformConcat(savedMatrix, rotateLeftTransform);
+        CGAffineTransform textMatrix = CGContextGetTextMatrix(context);
+        CGAffineTransform runMatrix = CGAffineTransformConcat(textMatrix, rotateLeftTransform);
         CGContextSetTextMatrix(context, runMatrix);
 
         Vector<CGSize, 256> translations(count);
@@ -188,21 +158,10 @@
             position.x += advances[i].width;
             position.y += advances[i].height;
         }
-        if (!platformData.isColorBitmapFont()) {
-            RenderingStyleSaver saver(platformData.ctFont(), context);
-            CGContextShowGlyphsAtPositions(context, glyphs, positions.data(), count);
-        } else
-            CTFontDrawGlyphs(platformData.ctFont(), glyphs, positions.data(), count, context);
-        CGContextSetTextMatrix(context, savedMatrix);
+        CTFontDrawGlyphs(platformData.ctFont(), glyphs, positions.data(), count, context);
     } else {
-        if (!platformData.isColorBitmapFont()) {
-            RenderingStyleSaver saver(platformData.ctFont(), context);
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wdeprecated-declarations"
-            CGContextShowGlyphsWithAdvances(context, glyphs, advances, count);
-#pragma clang diagnostic pop
-        } else
-            CTFontDrawGlyphs(platformData.ctFont(), glyphs, positions.data(), count, context);
+        fillVectorWithHorizontalGlyphPositions(positions, context, advances, count);
+        CTFontDrawGlyphs(platformData.ctFont(), glyphs, positions.data(), count, context);
     }
 }
 
@@ -270,8 +229,6 @@
     }
 #endif
 
-    CGContextSetFont(cgContext, platformData.cgFont());
-
     bool useLetterpressEffect = shouldUseLetterpressEffect(context);
     FloatPoint point = anchorPoint;
 
@@ -287,7 +244,7 @@
         else
             matrix = CGAffineTransformConcat(matrix, CGAffineTransformMake(1, 0, -obliqueSkew, 1, 0, 0));
     }
-    CGContextSetTextMatrix(cgContext, matrix);
+    ScopedTextMatrix restorer(matrix, cgContext);
 
     setCGFontRenderingMode(context);
     CGContextSetFontSize(cgContext, platformData.size());

Modified: trunk/Source/WebCore/platform/graphics/cocoa/FontCocoa.mm (204857 => 204858)


--- trunk/Source/WebCore/platform/graphics/cocoa/FontCocoa.mm	2016-08-23 20:43:56 UTC (rev 204857)
+++ trunk/Source/WebCore/platform/graphics/cocoa/FontCocoa.mm	2016-08-23 21:11:20 UTC (rev 204858)
@@ -34,6 +34,7 @@
 #import "FontCache.h"
 #import "FontCascade.h"
 #import "FontDescription.h"
+#import "OpenTypeCG.h"
 #import "SharedBuffer.h"
 #import "WebCoreSystemInterface.h"
 #import <float.h>
@@ -46,7 +47,6 @@
 #import <AppKit/AppKit.h>
 #import <ApplicationServices/ApplicationServices.h>
 #else
-#import "FontServicesIOS.h"
 #import <CoreText/CoreText.h>
 #endif
 
@@ -56,12 +56,13 @@
 @end
 #endif
 
-#if USE(APPKIT)
-#import "OpenTypeCG.h"
-#endif
-
 namespace WebCore {
 
+static inline bool caseInsensitiveCompare(CFStringRef a, CFStringRef b)
+{
+    return a && CFStringCompare(a, b, kCFCompareCaseInsensitive) == kCFCompareEqualTo;
+}
+
 static bool fontHasVerticalGlyphs(CTFontRef ctFont)
 {
     // The check doesn't look neat but this is what AppKit does for vertical writing...
@@ -77,7 +78,7 @@
     return false;
 }
 
-#if !USE(APPKIT)
+#if PLATFORM(IOS)
 bool fontFamilyShouldNotBeUsedForArabic(CFStringRef fontFamilyName)
 {
     if (!fontFamilyName)
@@ -88,13 +89,39 @@
     return (CFStringCompare(CFSTR("Times New Roman"), fontFamilyName, 0) == kCFCompareEqualTo)
         || (CFStringCompare(CFSTR("Arial"), fontFamilyName, 0) == kCFCompareEqualTo);
 }
+
+static const float kLineHeightAdjustment = 0.15f;
+
+static bool shouldUseAdjustment(CTFontRef font)
+{
+    RetainPtr<CFStringRef> familyName = adoptCF(CTFontCopyFamilyName(font));
+
+    if (!familyName || !CFStringGetLength(familyName.get()))
+        return false;
+
+    return caseInsensitiveCompare(familyName.get(), CFSTR("Times"))
+        || caseInsensitiveCompare(familyName.get(), CFSTR("Helvetica"))
+        || caseInsensitiveCompare(familyName.get(), CFSTR(".Helvetica NeueUI"));
+}
+
+#else
+
+static bool needsAscentAdjustment(CFStringRef familyName)
+{
+    return familyName && (caseInsensitiveCompare(familyName, CFSTR("Times"))
+        || caseInsensitiveCompare(familyName, CFSTR("Helvetica"))
+        || caseInsensitiveCompare(familyName, CFSTR("Courier")));
+}
+
 #endif
 
 void Font::platformInit()
 {
-    // FIXME: Unify these two codepaths
-#if USE(APPKIT)
+#if PLATFORM(IOS)
+    m_syntheticBoldOffset = m_platformData.syntheticBold() ? ceilf(m_platformData.size() / 24.0f) : 0.f;
+#else
     m_syntheticBoldOffset = m_platformData.syntheticBold() ? 1.0f : 0.f;
+#endif
 
 #if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED < 101100
     // Work around <rdar://problem/19433490>
@@ -103,16 +130,17 @@
     CTFontTransformGlyphs(m_platformData.ctFont(), dummyGlyphs, dummySize, 2, kCTFontTransformApplyPositioning | kCTFontTransformApplyShaping);
 #endif
 
-    unsigned unitsPerEm = CGFontGetUnitsPerEm(m_platformData.cgFont());
-
-    // Some fonts erroneously specify a positive descender value. We follow Core Text in assuming that
-    // such fonts meant the same distance, but in the reverse direction.
+    unsigned unitsPerEm = CTFontGetUnitsPerEm(m_platformData.font());
     float pointSize = m_platformData.size();
+    float capHeight = CTFontGetCapHeight(m_platformData.font());
+    float lineGap = CTFontGetLeading(m_platformData.font());
+#if PLATFORM(IOS)
+    CGFloat ascent = CTFontGetAscent(m_platformData.font());
+    CGFloat descent = CTFontGetDescent(m_platformData.font());
+#else
     float ascent = scaleEmToUnits(CGFontGetAscent(m_platformData.cgFont()), unitsPerEm) * pointSize;
     float descent = -scaleEmToUnits(-abs(CGFontGetDescent(m_platformData.cgFont())), unitsPerEm) * pointSize;
-    float capHeight = scaleEmToUnits(CGFontGetCapHeight(m_platformData.cgFont()), unitsPerEm) * pointSize;
-    
-    float lineGap = scaleEmToUnits(CGFontGetLeading(m_platformData.cgFont()), unitsPerEm) * pointSize;
+#endif
 
     // The Open Font Format describes the OS/2 USE_TYPO_METRICS flag as follows:
     // "If set, it is strongly recommended to use OS/2.sTypoAscender - OS/2.sTypoDescender+ OS/2.sTypoLineGap as a value for default line spacing for this font."
@@ -119,7 +147,7 @@
     // On OS X, we only apply this rule in the important case of fonts with a MATH table.
     if (OpenType::fontHasMathTable(m_platformData.ctFont())) {
         short typoAscent, typoDescent, typoLineGap;
-        if (OpenType::tryGetTypoMetrics(m_platformData.cgFont(), typoAscent, typoDescent, typoLineGap)) {
+        if (OpenType::tryGetTypoMetrics(m_platformData.font(), typoAscent, typoDescent, typoLineGap)) {
             ascent = scaleEmToUnits(typoAscent, unitsPerEm) * pointSize;
             descent = -scaleEmToUnits(typoDescent, unitsPerEm) * pointSize;
             lineGap = scaleEmToUnits(typoLineGap, unitsPerEm) * pointSize;
@@ -126,20 +154,21 @@
         }
     }
 
+    auto familyName = adoptCF(CTFontCopyFamilyName(m_platformData.font()));
+#if PLATFORM(MAC)
     // We need to adjust Times, Helvetica, and Courier to closely match the
     // vertical metrics of their Microsoft counterparts that are the de facto
     // web standard. The AppKit adjustment of 20% is too big and is
     // incorrectly added to line spacing, so we use a 15% adjustment instead
     // and add it to the ascent.
-    RetainPtr<CFStringRef> familyName = adoptCF(CTFontCopyFamilyName(m_platformData.font()));
-    if (!m_isCustomFont && familyName && (CFStringCompare(familyName.get(), CFSTR("Times"), kCFCompareCaseInsensitive) == kCFCompareEqualTo
-        || CFStringCompare(familyName.get(), CFSTR("Helvetica"), kCFCompareCaseInsensitive) == kCFCompareEqualTo
-        || CFStringCompare(familyName.get(), CFSTR("Courier"), kCFCompareCaseInsensitive) == kCFCompareEqualTo))
-        ascent += floorf(((ascent + descent) * 0.15f) + 0.5f);
+    if (!m_isCustomFont && needsAscentAdjustment(familyName.get()))
+        ascent += std::round((ascent + descent) * 0.15f);
+#endif
 
-    // Compute and store line spacing, before the line metrics hacks are applied.
-    m_fontMetrics.setLineSpacing(lroundf(ascent) + lroundf(descent) + lroundf(lineGap));
+    // Compute line spacing before the line metrics hacks are applied.
+    float lineSpacing = lroundf(ascent) + lroundf(descent) + lroundf(lineGap);
 
+#if !PLATFORM(IOS)
     // Hack Hiragino line metrics to allow room for marked text underlines.
     // <rdar://problem/5386183>
     if (descent < 3 && lineGap >= 3 && familyName && CFStringHasPrefix(familyName.get(), CFSTR("Hiragino"))) {
@@ -146,12 +175,24 @@
         lineGap -= 3 - descent;
         descent = 3;
     }
+#endif
     
     if (platformData().orientation() == Vertical && !isTextOrientationFallback())
         m_hasVerticalGlyphs = fontHasVerticalGlyphs(m_platformData.ctFont());
 
+#if PLATFORM(IOS)
+    CGFloat adjustment = shouldUseAdjustment(m_platformData.font()) ? ceil((ascent + descent) * kLineHeightAdjustment) : 0;
+
+    CGFontDescriptor descriptor;
+    float xHeight = CGFontGetDescriptor(m_platformData.cgFont(), &descriptor) ? (descriptor.xHeight / 1000) * CTFontGetSize(m_platformData.font()) : 0;
+    lineGap = ceilf(lineGap);
+    lineSpacing = ceil(ascent) + adjustment + ceil(descent) + lineGap;
+    ascent = ceilf(ascent + adjustment);
+    descent = ceilf(descent);
+
+    m_shouldNotBeUsedForArabic = fontFamilyShouldNotBeUsedForArabic(adoptCF(CTFontCopyFamilyName(m_platformData.font())).get());
+#else
     float xHeight;
-
     if (platformData().orientation() == Horizontal) {
         // Measure the actual character "x", since it's possible for it to extend below the baseline, and we need the
         // reported x-height to only include the portion of the glyph that is above the baseline.
@@ -159,9 +200,10 @@
         if (xGlyph)
             xHeight = -CGRectGetMinY(platformBoundsForGlyph(xGlyph));
         else
-            xHeight = scaleEmToUnits(CGFontGetXHeight(m_platformData.cgFont()), unitsPerEm) * pointSize;
+            xHeight = CTFontGetXHeight(m_platformData.font());
     } else
         xHeight = verticalRightOrientationFont().fontMetrics().xHeight();
+#endif
 
     m_fontMetrics.setUnitsPerEm(unitsPerEm);
     m_fontMetrics.setAscent(ascent);
@@ -169,25 +211,7 @@
     m_fontMetrics.setCapHeight(capHeight);
     m_fontMetrics.setLineGap(lineGap);
     m_fontMetrics.setXHeight(xHeight);
-
-#else
-
-    m_syntheticBoldOffset = m_platformData.syntheticBold() ? ceilf(m_platformData.size()  / 24.0f) : 0.f;
-
-    CTFontRef ctFont = m_platformData.font();
-    FontServicesIOS fontService(ctFont);
-    m_fontMetrics.setUnitsPerEm(fontService.unitsPerEm());
-    m_fontMetrics.setAscent(ceilf(fontService.ascent()));
-    m_fontMetrics.setDescent(ceilf(fontService.descent()));
-    m_fontMetrics.setLineGap(fontService.lineGap());
-    m_fontMetrics.setLineSpacing(fontService.lineSpacing());
-    m_fontMetrics.setXHeight(fontService.xHeight());
-    m_fontMetrics.setCapHeight(fontService.capHeight());
-    m_shouldNotBeUsedForArabic = fontFamilyShouldNotBeUsedForArabic(adoptCF(CTFontCopyFamilyName(ctFont)).get());
-
-    if (platformData().orientation() == Vertical && !isTextOrientationFallback())
-        m_hasVerticalGlyphs = fontHasVerticalGlyphs(m_platformData.ctFont());
-#endif
+    m_fontMetrics.setLineSpacing(lineSpacing);
 }
 
 void Font::platformCharWidthInit()
@@ -196,7 +220,7 @@
     m_maxCharWidth = 0;
     
 #if PLATFORM(MAC)
-    RetainPtr<CFDataRef> os2Table = adoptCF(CGFontCopyTableForTag(m_platformData.cgFont(), 'OS/2'));
+    auto os2Table = adoptCF(CTFontCopyTable(m_platformData.font(), kCTFontTableOS2, kCTFontTableOptionNoOptions));
     if (os2Table && CFDataGetLength(os2Table.get()) >= 4) {
         const UInt8* os2 = CFDataGetBytePtr(os2Table.get());
         SInt16 os2AvgCharWidth = os2[2] * 256 + os2[3];
@@ -203,7 +227,7 @@
         m_avgCharWidth = scaleEmToUnits(os2AvgCharWidth, m_fontMetrics.unitsPerEm()) * m_platformData.size();
     }
 
-    RetainPtr<CFDataRef> headTable = adoptCF(CGFontCopyTableForTag(m_platformData.cgFont(), 'head'));
+    auto headTable = adoptCF(CTFontCopyTable(m_platformData.font(), kCTFontTableHead, kCTFontTableOptionNoOptions));
     if (headTable && CFDataGetLength(headTable.get()) >= 42) {
         const UInt8* head = CFDataGetBytePtr(headTable.get());
         ushort uxMin = head[36] * 256 + head[37];
@@ -523,9 +547,12 @@
     return createDerivativeFont(scaledFont.get(), size, m_platformData.orientation(), fontTraits, m_platformData.syntheticBold(), m_platformData.syntheticOblique());
 }
 
-static inline bool caseInsensitiveCompare(CFStringRef a, CFStringRef b)
+static int extractNumber(CFNumberRef number)
 {
-    return a && CFStringCompare(a, b, kCFCompareCaseInsensitive) == kCFCompareEqualTo;
+    int result = 0;
+    if (number)
+        CFNumberGetValue(number, kCFNumberIntType, &result);
+    return result;
 }
 
 void Font::determinePitch()
@@ -545,12 +572,13 @@
     // According to <rdar://problem/5454704>, we should not treat MonotypeCorsiva as fixed pitch.
     // Note that AppKit does report MonotypeCorsiva as fixed pitch.
 
-    RetainPtr<CFStringRef> fullName = adoptCF(CTFontCopyFullName(ctFont));
-    RetainPtr<CFStringRef> familyName = adoptCF(CTFontCopyFamilyName(ctFont));
+    auto fullName = adoptCF(CTFontCopyFullName(ctFont));
+    auto familyName = adoptCF(CTFontCopyFamilyName(ctFont));
 
-    m_treatAsFixedPitch = (CTFontGetSymbolicTraits(ctFont) & kCTFontMonoSpaceTrait) || CGFontIsFixedPitch(m_platformData.cgFont()) || (caseInsensitiveCompare(fullName.get(), CFSTR("Osaka-Mono")) || caseInsensitiveCompare(fullName.get(), CFSTR("MS-PGothic")) || caseInsensitiveCompare(fullName.get(), CFSTR("MonotypeCorsiva")));
+    int fixedPitch = extractNumber(adoptCF(static_cast<CFNumberRef>(CTFontCopyAttribute(m_platformData.font(), kCTFontFixedAdvanceAttribute))).get());
+    m_treatAsFixedPitch = (CTFontGetSymbolicTraits(ctFont) & kCTFontMonoSpaceTrait) || fixedPitch || (caseInsensitiveCompare(fullName.get(), CFSTR("Osaka-Mono")) || caseInsensitiveCompare(fullName.get(), CFSTR("MS-PGothic")) || caseInsensitiveCompare(fullName.get(), CFSTR("MonotypeCorsiva")));
 #if PLATFORM(IOS)
-    if (familyName && CFStringCompare(familyName.get(), CFSTR("Courier New"), kCFCompareCaseInsensitive) == kCFCompareEqualTo) {
+    if (familyName && caseInsensitiveCompare(familyName.get(), CFSTR("Courier New"))) {
         // Special case Courier New to not be treated as fixed pitch, as this will make use of a hacked space width which is undesireable for iPhone (see rdar://6269783).
         m_treatAsFixedPitch = false;
     }

Modified: trunk/Source/WebCore/platform/graphics/cocoa/FontPlatformDataCocoa.mm (204857 => 204858)


--- trunk/Source/WebCore/platform/graphics/cocoa/FontPlatformDataCocoa.mm	2016-08-23 20:43:56 UTC (rev 204857)
+++ trunk/Source/WebCore/platform/graphics/cocoa/FontPlatformDataCocoa.mm	2016-08-23 21:11:20 UTC (rev 204858)
@@ -157,7 +157,7 @@
 
 RefPtr<SharedBuffer> FontPlatformData::openTypeTable(uint32_t table) const
 {
-    if (RetainPtr<CFDataRef> data = "" table)))
+    if (RetainPtr<CFDataRef> data = "" table, kCTFontTableOptionNoOptions)))
         return SharedBuffer::wrapCFData(data.get());
     
     return nullptr;
@@ -166,8 +166,8 @@
 #ifndef NDEBUG
 String FontPlatformData::description() const
 {
-    RetainPtr<CFStringRef> cgFontDescription = adoptCF(CFCopyDescription(cgFont()));
-    return String(cgFontDescription.get()) + " " + String::number(m_size)
+    auto fontDescription = adoptCF(CFCopyDescription(font()));
+    return String(fontDescription.get()) + " " + String::number(m_size)
             + (m_syntheticBold ? " synthetic bold" : "") + (m_syntheticOblique ? " synthetic oblique" : "") + (m_orientation ? " vertical orientation" : "");
 }
 #endif

Deleted: trunk/Source/WebCore/platform/graphics/ios/FontServicesIOS.h (204857 => 204858)


--- trunk/Source/WebCore/platform/graphics/ios/FontServicesIOS.h	2016-08-23 20:43:56 UTC (rev 204857)
+++ trunk/Source/WebCore/platform/graphics/ios/FontServicesIOS.h	2016-08-23 21:11:20 UTC (rev 204858)
@@ -1,53 +0,0 @@
-/*
- * Copyright (C) 2013 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.
- */
-#ifndef FontServicesIOS_h
-#define FontServicesIOS_h
-
-#import <CoreText/CoreText.h>
-
-namespace WebCore {
-
-class FontServicesIOS {
-public:
-    FontServicesIOS(CTFontRef);
-    CGFloat ascent() { return m_ascent; }
-    CGFloat descent() { return m_descent; }
-    CGFloat lineGap() { return m_lineGap; }
-    CGFloat lineSpacing() { return m_lineSpacing; }
-    CGFloat xHeight() { return m_xHeight; }
-    CGFloat capHeight() { return m_capHeight; }
-    unsigned unitsPerEm() { return m_unitsPerEm; }
-
-private:
-    CGFloat m_ascent;
-    CGFloat m_descent;
-    CGFloat m_lineGap;
-    CGFloat m_lineSpacing;
-    CGFloat m_xHeight;
-    CGFloat m_capHeight;
-    unsigned m_unitsPerEm;
-};
-
-}
-#endif

Deleted: trunk/Source/WebCore/platform/graphics/ios/FontServicesIOS.mm (204857 => 204858)


--- trunk/Source/WebCore/platform/graphics/ios/FontServicesIOS.mm	2016-08-23 20:43:56 UTC (rev 204857)
+++ trunk/Source/WebCore/platform/graphics/ios/FontServicesIOS.mm	2016-08-23 21:11:20 UTC (rev 204858)
@@ -1,122 +0,0 @@
-/*
- * Copyright (C) 2013 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.
- */
-
-#import "config.h"
-#import "FontServicesIOS.h"
-
-#import "CoreGraphicsSPI.h"
-#import "FontMetrics.h"
-#import "OpenTypeCG.h"
-#import <wtf/RetainPtr.h>
-#import <wtf/spi/darwin/dyldSPI.h>
-
-namespace WebCore {
-
-static const float kLineHeightAdjustment = 0.15f;
-
-static bool shouldUseAdjustment(CTFontRef font, bool isiOS7OrLater)
-{
-    RetainPtr<NSString> familyName = adoptNS((NSString *)CTFontCopyFamilyName(font));
-    if (![familyName length])
-        return false;
-
-    if ([familyName.get() compare:@"Times" options:NSCaseInsensitiveSearch] == NSOrderedSame
-        || [familyName.get() compare:@"Helvetica" options:NSCaseInsensitiveSearch] == NSOrderedSame
-        || [familyName.get() compare:@".Helvetica NeueUI" options:NSCaseInsensitiveSearch] == NSOrderedSame)
-        return true;
-    if (!isiOS7OrLater && [familyName.get() compare:@".Helvetica NeueUILegacy" options:NSCaseInsensitiveSearch] == NSOrderedSame)
-        return true;
-
-    return false;
-}
-
-static bool isCourier(CTFontRef font)
-{
-    RetainPtr<NSString> familyName = adoptNS((NSString *)CTFontCopyFamilyName(font));
-    if (![familyName length])
-        return false;
-    return [familyName.get() compare:@"Courier" options:NSCaseInsensitiveSearch] == NSOrderedSame;
-}
-
-FontServicesIOS::FontServicesIOS(CTFontRef font)
-{
-    CGFontDescriptor descriptor;
-    RetainPtr<CGFontRef> cgFont = adoptCF(CTFontCopyGraphicsFont(font, NULL));
-    m_xHeight = CGFontGetDescriptor(cgFont.get(), &descriptor) ? (descriptor.xHeight / 1000) * CTFontGetSize(font) : 0;
-    m_unitsPerEm = CTFontGetUnitsPerEm(font);
-    CGFloat lineGap;
-    CGFloat ascent;
-    CGFloat descent;
-    CGFloat capHeight;
-    static bool isiOS7OrLater = dyld_get_program_sdk_version() >= DYLD_IOS_VERSION_7_0;
-    if (isiOS7OrLater) {
-        // Use CoreText API in iOS 7.
-        ascent = CTFontGetAscent(font);
-        descent = CTFontGetDescent(font);
-        lineGap = CTFontGetLeading(font);
-        capHeight = CTFontGetCapHeight(font);
-    } else {
-        float pointSize = CTFontGetSize(font);
-        const CGFontHMetrics *metrics = CGFontGetHMetrics(cgFont.get());
-        unsigned unitsPerEm = CGFontGetUnitsPerEm(cgFont.get());
-        unsigned capHeightInGlyphSpace = CGFontGetCapHeight(cgFont.get());
-
-        lineGap = (dyld_get_program_sdk_version() >= DYLD_IOS_VERSION_3_0) ? scaleEmToUnits(metrics->lineGap, unitsPerEm) * pointSize : 0.0;
-        capHeight = scaleEmToUnits(capHeightInGlyphSpace, unitsPerEm) * pointSize;
-
-        bool isiOS6OrLater = dyld_get_program_sdk_version() >= DYLD_IOS_VERSION_6_0;
-        if (!isiOS6OrLater || !isCourier(font)) {
-            ascent = (scaleEmToUnits(metrics->ascent, unitsPerEm) * pointSize);
-            descent = (-scaleEmToUnits(metrics->descent, unitsPerEm) * pointSize);
-        } else {
-            // For Courier, we use Courier New's exact values, because in iOS 5.1 and earlier,
-            // Courier New was substituted for Courier by WebKit.
-            ascent = (scaleEmToUnits(1705, 2048) * pointSize);
-            descent = (scaleEmToUnits(615, 2048) * pointSize);
-        }
-    }
-    // The Open Font Format describes the OS/2 USE_TYPO_METRICS flag as follows:
-    // "If set, it is strongly recommended to use OS/2.sTypoAscender - OS/2.sTypoDescender+ OS/2.sTypoLineGap as a value for default line spacing for this font."
-    // On iOS, we only apply this rule in the important case of fonts with a MATH table.
-    if (OpenType::fontHasMathTable(font)) {
-        short typoAscent, typoDescent, typoLineGap;
-        if (OpenType::tryGetTypoMetrics(cgFont.get(), typoAscent, typoDescent, typoLineGap)) {
-            unsigned unitsPerEm = CGFontGetUnitsPerEm(cgFont.get());
-            float pointSize = CTFontGetSize(font);
-            ascent = scaleEmToUnits(typoAscent, unitsPerEm) * pointSize;
-            descent = -scaleEmToUnits(typoDescent, unitsPerEm) * pointSize;
-            lineGap = scaleEmToUnits(typoLineGap, unitsPerEm) * pointSize;
-        }
-    }
-    CGFloat adjustment = (shouldUseAdjustment(font, isiOS7OrLater)) ? ceil((ascent + descent) * kLineHeightAdjustment) : 0;
-
-    m_ascent = ascent + adjustment;
-    m_descent = descent;
-    m_lineGap = ceilf(lineGap);
-    m_lineSpacing = ceil(ascent) + adjustment + ceil(descent) + m_lineGap;
-    m_capHeight = capHeight;
-}
-
-
-} // namespace WebCore

Modified: trunk/Source/WebCore/platform/graphics/opentype/OpenTypeCG.cpp (204857 => 204858)


--- trunk/Source/WebCore/platform/graphics/opentype/OpenTypeCG.cpp	2016-08-23 20:43:56 UTC (rev 204857)
+++ trunk/Source/WebCore/platform/graphics/opentype/OpenTypeCG.cpp	2016-08-23 21:11:20 UTC (rev 204858)
@@ -35,7 +35,6 @@
 static const unsigned long kCTFontTableOS2 = 'OS/2';
 #endif
 
-#if PLATFORM(COCOA)
 bool fontHasMathTable(CTFontRef ctFont)
 {
     RetainPtr<CFArrayRef> tableTags = adoptCF(CTFontCopyAvailableTables(ctFont, kCTFontTableOptionNoOptions));
@@ -49,7 +48,6 @@
     }
     return false;
 }
-#endif
 
 static inline short readShortFromTable(const UInt8* os2Data, CFIndex offset)
 {
@@ -56,10 +54,10 @@
     return *(reinterpret_cast<const OpenType::Int16*>(os2Data + offset));
 }
 
-bool tryGetTypoMetrics(CGFontRef cgFont, short& ascent, short& descent, short& lineGap)
+bool tryGetTypoMetrics(CTFontRef font, short& ascent, short& descent, short& lineGap)
 {
     bool result = false;
-    if (CFDataRef os2Table = CGFontCopyTableForTag(cgFont, kCTFontTableOS2)) {
+    if (auto os2Table = adoptCF(CTFontCopyTable(font, kCTFontTableOS2, kCTFontTableOptionNoOptions))) {
         // For the structure of the OS/2 table, see
         // https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6OS2.html
         const CFIndex fsSelectionOffset = 16 * 2 + 10 + 4 * 4 + 4 * 1;
@@ -66,8 +64,8 @@
         const CFIndex sTypoAscenderOffset = fsSelectionOffset + 3 * 2;
         const CFIndex sTypoDescenderOffset = sTypoAscenderOffset + 2;
         const CFIndex sTypoLineGapOffset = sTypoDescenderOffset + 2;
-        if (CFDataGetLength(os2Table) >= sTypoLineGapOffset + 2) {
-            const UInt8* os2Data = CFDataGetBytePtr(os2Table);
+        if (CFDataGetLength(os2Table.get()) >= sTypoLineGapOffset + 2) {
+            const UInt8* os2Data = CFDataGetBytePtr(os2Table.get());
             // We test the use typo bit on the least significant byte of fsSelection.
             const UInt8 useTypoMetricsMask = 1 << 7;
             if (*(os2Data + fsSelectionOffset + 1) & useTypoMetricsMask) {
@@ -77,7 +75,6 @@
                 result = true;
             }
         }
-        CFRelease(os2Table);
     }
     return result;
 }

Modified: trunk/Source/WebCore/platform/graphics/opentype/OpenTypeCG.h (204857 => 204858)


--- trunk/Source/WebCore/platform/graphics/opentype/OpenTypeCG.h	2016-08-23 20:43:56 UTC (rev 204857)
+++ trunk/Source/WebCore/platform/graphics/opentype/OpenTypeCG.h	2016-08-23 21:11:20 UTC (rev 204858)
@@ -27,17 +27,17 @@
 #define OpenTypeCG_h
 
 #include <CoreGraphics/CoreGraphics.h>
-#if PLATFORM(COCOA)
 #include <CoreText/CoreText.h>
+
+#if PLATFORM(WIN)
+#include "CoreTextSPIWin.h"
 #endif
 
 namespace WebCore {
 namespace OpenType {
 
-#if PLATFORM(COCOA)
 bool fontHasMathTable(CTFontRef);
-#endif
-bool tryGetTypoMetrics(CGFontRef, short& ascent, short& descent, short& lineGap);
+bool tryGetTypoMetrics(CTFontRef, short& ascent, short& descent, short& lineGap);
 
 } // namespace OpenType
 } // namespace WebCore

Modified: trunk/Source/WebCore/platform/graphics/win/FontCGWin.cpp (204857 => 204858)


--- trunk/Source/WebCore/platform/graphics/win/FontCGWin.cpp	2016-08-23 20:43:56 UTC (rev 204857)
+++ trunk/Source/WebCore/platform/graphics/win/FontCGWin.cpp	2016-08-23 21:11:20 UTC (rev 204858)
@@ -172,6 +172,7 @@
         matrix = CGAffineTransformConcat(matrix, CGAffineTransformMake(1, 0, skew, 1, 0, 0));
     }
 
+    CGAffineTransform savedMatrix = CGContextGetTextMatrix(cgContext);
     CGContextSetTextMatrix(cgContext, matrix);
 
     // Uniscribe gives us offsets to help refine the positioning of combining glyphs.
@@ -215,6 +216,7 @@
         graphicsContext.setShadow(shadowOffset, shadowBlur, shadowColor);
 
     wkRestoreFontSmoothingStyle(cgContext, oldFontSmoothingStyle);
+    CGContextSetTextMatrix(cgContext, savedMatrix);
 }
 
 }

Modified: trunk/Source/WebCore/platform/graphics/win/SimpleFontDataCGWin.cpp (204857 => 204858)


--- trunk/Source/WebCore/platform/graphics/win/SimpleFontDataCGWin.cpp	2016-08-23 20:43:56 UTC (rev 204857)
+++ trunk/Source/WebCore/platform/graphics/win/SimpleFontDataCGWin.cpp	2016-08-23 21:11:20 UTC (rev 204858)
@@ -29,6 +29,7 @@
 #include "config.h"
 #include "Font.h"
 
+#include "CoreTextSPIWin.h"
 #include "FloatRect.h"
 #include "FontCache.h"
 #include "FontDescription.h"
@@ -67,7 +68,7 @@
     // The Open Font Format describes the OS/2 USE_TYPO_METRICS flag as follows:
     // "If set, it is strongly recommended to use OS/2.sTypoAscender - OS/2.sTypoDescender+ OS/2.sTypoLineGap as a value for default line spacing for this font."
     short typoAscent, typoDescent, typoLineGap;
-    if (OpenType::tryGetTypoMetrics(m_platformData.cgFont(), typoAscent, typoDescent, typoLineGap)) {
+    if (OpenType::tryGetTypoMetrics(adoptCF(CTFontCreateWithGraphicsFont(m_platformData.cgFont(), m_platformData.size(), nullptr, nullptr)).get(), typoAscent, typoDescent, typoLineGap)) {
         iAscent = typoAscent;
         iDescent = typoDescent;
         iLineGap = typoLineGap;
@@ -144,7 +145,6 @@
     CGSize advance;
     CGAffineTransform m = CGAffineTransformMakeScale(pointSize, pointSize);
  
-    // FIXME: Need to add real support for printer fonts.
     bool isPrinterFont = false;
     wkGetGlyphAdvances(font, m, m_platformData.isSystemFont(), isPrinterFont, glyph, advance);
 

Modified: trunk/Source/WebCore/platform/spi/cg/CoreGraphicsSPI.h (204857 => 204858)


--- trunk/Source/WebCore/platform/spi/cg/CoreGraphicsSPI.h	2016-08-23 20:43:56 UTC (rev 204857)
+++ trunk/Source/WebCore/platform/spi/cg/CoreGraphicsSPI.h	2016-08-23 21:11:20 UTC (rev 204858)
@@ -170,10 +170,6 @@
 void CGContextSetShouldAntialiasFonts(CGContextRef, bool shouldAntialiasFonts);
 void CGContextResetClip(CGContextRef);
 CGContextType CGContextGetType(CGContextRef);
-#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101100
-void CGContextSetFontDilation(CGContextRef, CGSize);
-void CGContextSetFontRenderingStyle(CGContextRef, CGFontRenderingStyle);
-#endif
 
 CFStringRef CGFontCopyFamilyName(CGFontRef);
 bool CGFontGetDescriptor(CGFontRef, CGFontDescriptor*);

Modified: trunk/Source/WebCore/platform/spi/cocoa/CoreTextSPI.h (204857 => 204858)


--- trunk/Source/WebCore/platform/spi/cocoa/CoreTextSPI.h	2016-08-23 20:43:56 UTC (rev 204857)
+++ trunk/Source/WebCore/platform/spi/cocoa/CoreTextSPI.h	2016-08-23 21:11:20 UTC (rev 204858)
@@ -67,9 +67,6 @@
 CTLineRef CTLineCreateWithUniCharProvider(CTUniCharProviderCallback provide, CTUniCharDisposeCallback dispose, void* refCon);
 CTTypesetterRef CTTypesetterCreateWithUniCharProviderAndOptions(CTUniCharProviderCallback provide, CTUniCharDisposeCallback dispose, void* refCon, CFDictionaryRef options);
 bool CTFontGetVerticalGlyphsForCharacters(CTFontRef, const UniChar characters[], CGGlyph glyphs[], CFIndex count);
-#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED > 101000
-bool CTFontSetRenderingStyle(CTFontRef, CGContextRef, CGFontRenderingStyle* originalStyle, CGSize* originalDilation);
-#endif
 
 CTFontDescriptorRef CTFontDescriptorCreateForUIType(CTFontUIFontType, CGFloat size, CFStringRef language);
 CTFontDescriptorRef CTFontDescriptorCreateWithTextStyle(CFStringRef style, CFStringRef size, CFStringRef language);

Modified: trunk/Source/WebCore/platform/spi/win/CoreTextSPIWin.h (204857 => 204858)


--- trunk/Source/WebCore/platform/spi/win/CoreTextSPIWin.h	2016-08-23 20:43:56 UTC (rev 204857)
+++ trunk/Source/WebCore/platform/spi/win/CoreTextSPIWin.h	2016-08-23 21:11:20 UTC (rev 204858)
@@ -33,13 +33,24 @@
 
 typedef const struct __CTFont* CTFontRef;
 typedef const struct __CTLine* CTLineRef;
+typedef UInt32 FourCharCode;
+typedef FourCharCode CTFontTableTag;
 
 extern const CFStringRef kCTFontAttributeName;
 extern const CFStringRef kCTForegroundColorFromContextAttributeName;
 
-CTFontRef CTFontCreateWithName(CFStringRef name, CGFloat size, const CGAffineTransform* matrix);
+typedef CF_OPTIONS(uint32_t, CTFontTableOptions)
+{
+    kCTFontTableOptionNoOptions = 0,
+    kCTFontTableOptionExcludeSynthetic = (1 << 0)
+};
+
+CTFontRef CTFontCreateWithName(CFStringRef, CGFloat size, const CGAffineTransform*);
+CTFontRef CTFontCreateWithGraphicsFont(CGFontRef, CGFloat size, const CGAffineTransform*, CTFontDescriptorRef attributes);
 CTLineRef CTLineCreateWithAttributedString(CFAttributedStringRef);
 void CTLineDraw(CTLineRef, CGContextRef);
+CFDataRef CTFontCopyTable(CTFontRef, CTFontTableTag, CTFontTableOptions);
+CFArrayRef CTFontCopyAvailableTables(CTFontRef, CTFontTableOptions);
 
 }
 

Modified: trunk/Source/WebCore/rendering/RenderThemeIOS.mm (204857 => 204858)


--- trunk/Source/WebCore/rendering/RenderThemeIOS.mm	2016-08-23 20:43:56 UTC (rev 204857)
+++ trunk/Source/WebCore/rendering/RenderThemeIOS.mm	2016-08-23 21:11:20 UTC (rev 204858)
@@ -1652,7 +1652,7 @@
         context.translate(toFloatSize(line.rect.minXMaxYCorner()));
         context.scale(FloatSize(1, -1));
 
-        CGContextSetTextMatrix(context.platformContext(), CGAffineTransformIdentity);
+        CGContextSetTextPosition(context.platformContext(), 0, 0);
         CTLineDraw(line.line.get(), context.platformContext());
     }
 }

Modified: trunk/Source/WebCore/rendering/RenderThemeMac.mm (204857 => 204858)


--- trunk/Source/WebCore/rendering/RenderThemeMac.mm	2016-08-23 20:43:56 UTC (rev 204857)
+++ trunk/Source/WebCore/rendering/RenderThemeMac.mm	2016-08-23 21:11:20 UTC (rev 204858)
@@ -2510,7 +2510,7 @@
         context.translate(toFloatSize(line.origin));
         context.scale(FloatSize(1, -1));
 
-        CGContextSetTextMatrix(context.platformContext(), CGAffineTransformIdentity);
+        CGContextSetTextPosition(context.platformContext(), 0, 0);
         CTLineDraw(line.line.get(), context.platformContext());
     }
 }
@@ -2522,7 +2522,7 @@
     context.translate(toFloatSize(layout.subtitleTextRect.minXMaxYCorner()));
     context.scale(FloatSize(1, -1));
 
-    CGContextSetTextMatrix(context.platformContext(), CGAffineTransformIdentity);
+    CGContextSetTextPosition(context.platformContext(), 0, 0);
     CTLineDraw(layout.subtitleLine.get(), context.platformContext());
 }
 

Modified: trunk/Source/WebCore/svg/SVGFontFaceElement.cpp (204857 => 204858)


--- trunk/Source/WebCore/svg/SVGFontFaceElement.cpp	2016-08-23 20:43:56 UTC (rev 204857)
+++ trunk/Source/WebCore/svg/SVGFontFaceElement.cpp	2016-08-23 21:11:20 UTC (rev 204858)
@@ -76,7 +76,7 @@
 {
     const AtomicString& value = attributeWithoutSynchronization(units_per_emAttr);
     if (value.isEmpty())
-        return gDefaultUnitsPerEm;
+        return FontMetrics::defaultUnitsPerEm;
 
     return static_cast<unsigned>(ceilf(value.toFloat()));
 }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to