Title: [192017] trunk/Source/WebCore
Revision
192017
Author
fred.w...@free.fr
Date
2015-11-04 00:50:31 -0800 (Wed, 04 Nov 2015)

Log Message

Add support for the USE_TYPO_METRICS flag on iOS
https://bugs.webkit.org/show_bug.cgi?id=131839

Reviewed by Darin Adler.

Make the iOS Font service use the typo metrics for fonts with a MATH table when the OS/2 USE_TYPO_METRICS flag is set.
The code shared by iOS, OS X and AppleWin is moved into a separate OpenTypeCG module.

No new tests because this is already tested by fonts/use-typo-metrics-1.html

* PlatformAppleWin.cmake: Add OpenTypeCG files.
* PlatformMac.cmake: ditto.
* WebCore.vcxproj/WebCore.vcxproj: ditto.
* WebCore.vcxproj/WebCore.vcxproj.filters: ditto.
* WebCore.xcodeproj/project.pbxproj: ditto.
* platform/graphics/cocoa/FontCocoa.mm:
(WebCore::Font::platformInit): Use functions from OpenTypeCG.
(WebCore::fontHasMathTable): Deleted.
* platform/graphics/ios/FontServicesIOS.mm:
(WebCore::FontServicesIOS::FontServicesIOS): Use the typo metrics for fonts with a MATH table when the OS/2 USE_TYPO_METRICS flag is set.
* platform/graphics/opentype/OpenTypeCG.h: Added.
* platform/graphics/opentype/OpenTypeCG.cpp: Added.
(WebCore::OpenType::fontHasMathTable): Move this code from FontCocoa.mm.
(WebCore::OpenType::readShortFromTable): Inline function to read a 16-bit big endian integer from the OS/2 table and to cast it into a short integer.
(WebCore::OpenType::tryGetTypoMetrics): Move this code from FontCocoa.mm.
* platform/graphics/opentype/OpenTypeTypes.h: Add missing Glyph.h header needed by TableWithCoverage::getCoverageIndex.
* platform/graphics/win/SimpleFontDataCGWin.cpp:
(WebCore::Font::platformInit): Use functions from OpenTypeCG.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (192016 => 192017)


--- trunk/Source/WebCore/ChangeLog	2015-11-04 08:10:09 UTC (rev 192016)
+++ trunk/Source/WebCore/ChangeLog	2015-11-04 08:50:31 UTC (rev 192017)
@@ -1,3 +1,34 @@
+2015-11-04  Frederic Wang  <fred.w...@free.fr>
+
+        Add support for the USE_TYPO_METRICS flag on iOS
+        https://bugs.webkit.org/show_bug.cgi?id=131839
+
+        Reviewed by Darin Adler.
+
+        Make the iOS Font service use the typo metrics for fonts with a MATH table when the OS/2 USE_TYPO_METRICS flag is set.
+        The code shared by iOS, OS X and AppleWin is moved into a separate OpenTypeCG module.
+
+        No new tests because this is already tested by fonts/use-typo-metrics-1.html
+
+        * PlatformAppleWin.cmake: Add OpenTypeCG files.
+        * PlatformMac.cmake: ditto.
+        * WebCore.vcxproj/WebCore.vcxproj: ditto.
+        * WebCore.vcxproj/WebCore.vcxproj.filters: ditto.
+        * WebCore.xcodeproj/project.pbxproj: ditto.
+        * platform/graphics/cocoa/FontCocoa.mm:
+        (WebCore::Font::platformInit): Use functions from OpenTypeCG.
+        (WebCore::fontHasMathTable): Deleted.
+        * platform/graphics/ios/FontServicesIOS.mm:
+        (WebCore::FontServicesIOS::FontServicesIOS): Use the typo metrics for fonts with a MATH table when the OS/2 USE_TYPO_METRICS flag is set.
+        * platform/graphics/opentype/OpenTypeCG.h: Added.
+        * platform/graphics/opentype/OpenTypeCG.cpp: Added.
+        (WebCore::OpenType::fontHasMathTable): Move this code from FontCocoa.mm.
+        (WebCore::OpenType::readShortFromTable): Inline function to read a 16-bit big endian integer from the OS/2 table and to cast it into a short integer.
+        (WebCore::OpenType::tryGetTypoMetrics): Move this code from FontCocoa.mm.
+        * platform/graphics/opentype/OpenTypeTypes.h: Add missing Glyph.h header needed by TableWithCoverage::getCoverageIndex.
+        * platform/graphics/win/SimpleFontDataCGWin.cpp:
+        (WebCore::Font::platformInit): Use functions from OpenTypeCG.
+
 2015-11-04  Chris Dumez  <cdu...@apple.com>
 
         Regression(r191652): Colloquy doesn’t render any chat content

Modified: trunk/Source/WebCore/PlatformAppleWin.cmake (192016 => 192017)


--- trunk/Source/WebCore/PlatformAppleWin.cmake	2015-11-04 08:10:09 UTC (rev 192016)
+++ trunk/Source/WebCore/PlatformAppleWin.cmake	2015-11-04 08:50:31 UTC (rev 192017)
@@ -82,6 +82,8 @@
     platform/graphics/cg/SubimageCacheWithTimer.cpp
     platform/graphics/cg/TransformationMatrixCG.cpp
 
+    platform/graphics/opentype/OpenTypeCG.cpp
+
     platform/graphics/win/FontCGWin.cpp
     platform/graphics/win/FontCustomPlatformData.cpp
     platform/graphics/win/FontPlatformDataCGWin.cpp

Modified: trunk/Source/WebCore/PlatformMac.cmake (192016 => 192017)


--- trunk/Source/WebCore/PlatformMac.cmake	2015-11-04 08:10:09 UTC (rev 192016)
+++ trunk/Source/WebCore/PlatformMac.cmake	2015-11-04 08:50:31 UTC (rev 192017)
@@ -442,6 +442,7 @@
     platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp
     platform/graphics/opengl/TemporaryOpenGLSetting.cpp
 
+    platform/graphics/opentype/OpenTypeCG.cpp
     platform/graphics/opentype/OpenTypeMathData.cpp
 
     platform/mac/BlockExceptions.mm

Modified: trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj (192016 => 192017)


--- trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj	2015-11-04 08:10:09 UTC (rev 192016)
+++ trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj	2015-11-04 08:50:31 UTC (rev 192017)
@@ -8462,6 +8462,12 @@
     <ClCompile Include="..\platform\graphics\win\IntRectWin.cpp" />
     <ClCompile Include="..\platform\graphics\win\IntSizeWin.cpp" />
     <ClCompile Include="..\platform\graphics\win\MediaPlayerPrivateFullscreenWindow.cpp" />
+    <ClCompile Include="..\platform\graphics\opentype\OpenTypeCG.cpp">
+      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug_WinCairo|Win32'">true</ExcludedFromBuild>
+      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug_WinCairo|x64'">true</ExcludedFromBuild>
+      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release_WinCairo|Win32'">true</ExcludedFromBuild>
+      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release_WinCairo|x64'">true</ExcludedFromBuild>
+    </ClCompile>
     <ClCompile Include="..\platform\graphics\opentype\OpenTypeMathData.cpp" />
     <ClCompile Include="..\platform\graphics\opentype\OpenTypeUtilities.cpp" />
     <ClCompile Include="..\platform\graphics\opentype\OpenTypeVerticalData.cpp" />

Modified: trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj.filters (192016 => 192017)


--- trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj.filters	2015-11-04 08:10:09 UTC (rev 192016)
+++ trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj.filters	2015-11-04 08:50:31 UTC (rev 192017)
@@ -7128,6 +7128,9 @@
     <ClCompile Include="$(ConfigurationBuildDir)\obj$(PlatformArchitecture)\WebCore\DerivedSources\JSWebGLRenderingContextBase.cpp">
       <Filter>DerivedSources</Filter>
     </ClCompile>
+    <ClCompile Include="..\platform\graphics\opentype\OpenTypeCG.cpp">
+      <Filter>platform\graphics\opentype</Filter>
+    </ClCompile>
     <ClCompile Include="..\platform\graphics\opentype\OpenTypeMathData.cpp">
       <Filter>platform\graphics\opentype</Filter>
     </ClCompile>

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (192016 => 192017)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2015-11-04 08:10:09 UTC (rev 192016)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2015-11-04 08:50:31 UTC (rev 192017)
@@ -4995,6 +4995,8 @@
 		B2C3DA6B0D006CD600EF6F26 /* FontSelector.h in Headers */ = {isa = PBXBuildFile; fileRef = B2C3DA5A0D006CD600EF6F26 /* FontSelector.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		B2C3DA6C0D006CD600EF6F26 /* GlyphBuffer.h in Headers */ = {isa = PBXBuildFile; fileRef = B2C3DA5B0D006CD600EF6F26 /* GlyphBuffer.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		B2C96D8D0B3AF2B7005E80EC /* JSSVGPathSegCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B2C96D8C0B3AF2B7005E80EC /* JSSVGPathSegCustom.cpp */; };
+		B2D3DA640D006CD600EF6F3A /* OpenTypeCG.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B2D3DA530D006CD600EF6F3A /* OpenTypeCG.cpp */; };
+		B2D3DA650D006CD600EF6F3A /* OpenTypeCG.h in Headers */ = {isa = PBXBuildFile; fileRef = B2D3DA540D006CD600EF6F3A /* OpenTypeCG.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		B2D3DA640D006CD600EF6F27 /* OpenTypeMathData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B2D3DA530D006CD600EF6F27 /* OpenTypeMathData.cpp */; };
 		B2D3DA650D006CD600EF6F27 /* OpenTypeMathData.h in Headers */ = {isa = PBXBuildFile; fileRef = B2D3DA540D006CD600EF6F27 /* OpenTypeMathData.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		B2D3EA650D006CD600EF6F28 /* OpenTypeTypes.h in Headers */ = {isa = PBXBuildFile; fileRef = B2D3EA540D006CD600EF6F28 /* OpenTypeTypes.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -12729,6 +12731,8 @@
 		B2C3DA5A0D006CD600EF6F26 /* FontSelector.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = FontSelector.h; sourceTree = "<group>"; };
 		B2C3DA5B0D006CD600EF6F26 /* GlyphBuffer.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = GlyphBuffer.h; sourceTree = "<group>"; };
 		B2C96D8C0B3AF2B7005E80EC /* JSSVGPathSegCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = JSSVGPathSegCustom.cpp; sourceTree = "<group>"; };
+		B2D3DA530D006CD600EF6F3A /* OpenTypeCG.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = OpenTypeCG.cpp; sourceTree = "<group>"; };
+		B2D3DA540D006CD600EF6F3A /* OpenTypeCG.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = OpenTypeCG.h; sourceTree = "<group>"; };
 		B2D3DA530D006CD600EF6F27 /* OpenTypeMathData.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = OpenTypeMathData.cpp; sourceTree = "<group>"; };
 		B2D3DA540D006CD600EF6F27 /* OpenTypeMathData.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = OpenTypeMathData.h; sourceTree = "<group>"; };
 		B2D3EA540D006CD600EF6F28 /* OpenTypeTypes.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = OpenTypeTypes.h; sourceTree = "<group>"; };
@@ -16286,6 +16290,8 @@
 		3721493318F0B6D600156EDC /* opentype */ = {
 			isa = PBXGroup;
 			children = (
+				B2D3DA530D006CD600EF6F3A /* OpenTypeCG.cpp */,
+				B2D3DA540D006CD600EF6F3A /* OpenTypeCG.h */,
 				B2D3DA530D006CD600EF6F27 /* OpenTypeMathData.cpp */,
 				B2D3DA540D006CD600EF6F27 /* OpenTypeMathData.h */,
 				B2D3EA540D006CD600EF6F28 /* OpenTypeTypes.h */,
@@ -26761,6 +26767,7 @@
 				FDA3E95A134A49EF008D4B5A /* OfflineAudioCompletionEvent.h in Headers */,
 				FDA9325E16703B2A008982DC /* OfflineAudioContext.h in Headers */,
 				FDA3E95C134A49EF008D4B5A /* OfflineAudioDestinationNode.h in Headers */,
+				B2D3DA650D006CD600EF6F3A /* OpenTypeCG.h in Headers */,
 				B2D3DA650D006CD600EF6F27 /* OpenTypeMathData.h in Headers */,
 				B2D3EA650D006CD600EF6F28 /* OpenTypeTypes.h in Headers */,
 				CDE7FC45181904B1002BBB77 /* OrderIterator.h in Headers */,
@@ -30401,6 +30408,7 @@
 				FDA3E959134A49EF008D4B5A /* OfflineAudioCompletionEvent.cpp in Sources */,
 				FDA9325D16703B2A008982DC /* OfflineAudioContext.cpp in Sources */,
 				FDA3E95B134A49EF008D4B5A /* OfflineAudioDestinationNode.cpp in Sources */,
+				B2D3DA640D006CD600EF6F3A /* OpenTypeCG.cpp in Sources */,
 				B2D3DA640D006CD600EF6F27 /* OpenTypeMathData.cpp in Sources */,
 				CDE7FC44181904B1002BBB77 /* OrderIterator.cpp in Sources */,
 				0014628A103CD1DE000B20DB /* OriginAccessEntry.cpp in Sources */,

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


--- trunk/Source/WebCore/platform/graphics/cocoa/FontCocoa.mm	2015-11-04 08:10:09 UTC (rev 192016)
+++ trunk/Source/WebCore/platform/graphics/cocoa/FontCocoa.mm	2015-11-04 08:50:31 UTC (rev 192017)
@@ -58,7 +58,7 @@
 #endif
 
 #if USE(APPKIT)
-#include "OpenTypeTypes.h"
+#import "OpenTypeCG.h"
 #endif
 
 namespace WebCore {
@@ -77,18 +77,6 @@
 }
 
 #if USE(APPKIT)
-static bool fontHasMathTable(CTFontRef ctFont)
-{
-    RetainPtr<CFArrayRef> tableTags = adoptCF(CTFontCopyAvailableTables(ctFont, kCTFontTableOptionNoOptions));
-    CFIndex numTables = CFArrayGetCount(tableTags.get());
-    for (CFIndex index = 0; index < numTables; ++index) {
-        CTFontTableTag tag = (CTFontTableTag)(uintptr_t)CFArrayGetValueAtIndex(tableTags.get(), index);
-        if (tag == 'MATH')
-            return true;
-    }
-    return false;
-}
-
 static NSString *webFallbackFontFamily(void)
 {
     static NSString *webFallbackFontFamily = [[[NSFont systemFontOfSize:16.0f] familyName] retain];
@@ -188,25 +176,13 @@
 
     // 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."
-    // We only apply this rule in the important case of fonts with a MATH table.
-    if (fontHasMathTable(m_platformData.ctFont())) {
-        if (CFDataRef os2Table = CGFontCopyTableForTag(m_platformData.cgFont(), kCTFontTableOS2)) {
-            // 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;
-            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);
-                const unsigned short useTypoMetricsMask = 1 << 7;
-                if (*(reinterpret_cast<const OpenType::UInt16*>(os2Data + fsSelectionOffset)) & useTypoMetricsMask) {
-                    ascent = scaleEmToUnits(*(reinterpret_cast<const OpenType::Int16*>(os2Data + sTypoAscenderOffset)), unitsPerEm) * pointSize;
-                    descent = -scaleEmToUnits(*(reinterpret_cast<const OpenType::Int16*>(os2Data + sTypoDescenderOffset)), unitsPerEm) * pointSize;
-                    lineGap = scaleEmToUnits(*(reinterpret_cast<const OpenType::Int16*>(os2Data + sTypoLineGapOffset)), unitsPerEm) * pointSize;
-                }
-            }
-            CFRelease(os2Table);
+    // 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)) {
+            ascent = scaleEmToUnits(typoAscent, unitsPerEm) * pointSize;
+            descent = -scaleEmToUnits(typoDescent, unitsPerEm) * pointSize;
+            lineGap = scaleEmToUnits(typoLineGap, unitsPerEm) * pointSize;
         }
     }
 

Modified: trunk/Source/WebCore/platform/graphics/ios/FontServicesIOS.mm (192016 => 192017)


--- trunk/Source/WebCore/platform/graphics/ios/FontServicesIOS.mm	2015-11-04 08:10:09 UTC (rev 192016)
+++ trunk/Source/WebCore/platform/graphics/ios/FontServicesIOS.mm	2015-11-04 08:50:31 UTC (rev 192017)
@@ -28,6 +28,7 @@
 #import "CoreGraphicsSPI.h"
 #import "DynamicLinkerSPI.h"
 #import "FontMetrics.h"
+#import "OpenTypeCG.h"
 #import <wtf/RetainPtr.h>
 
 namespace WebCore {
@@ -95,6 +96,19 @@
             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;

Added: trunk/Source/WebCore/platform/graphics/opentype/OpenTypeCG.cpp (0 => 192017)


--- trunk/Source/WebCore/platform/graphics/opentype/OpenTypeCG.cpp	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/opentype/OpenTypeCG.cpp	2015-11-04 08:50:31 UTC (rev 192017)
@@ -0,0 +1,84 @@
+/*
+ * Copyright (C) 2015 Frederic Wang (fred.w...@free.fr). 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 THE COPYRIGHT HOLDERS AND 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 THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "OpenTypeCG.h"
+
+#include "OpenTypeTypes.h"
+
+namespace WebCore {
+namespace OpenType {
+
+#if PLATFORM(WIN)
+static const unsigned long kCTFontTableOS2 = 'OS/2';
+#endif
+
+#if PLATFORM(COCOA)
+bool fontHasMathTable(CTFontRef ctFont)
+{
+    RetainPtr<CFArrayRef> tableTags = adoptCF(CTFontCopyAvailableTables(ctFont, kCTFontTableOptionNoOptions));
+    CFIndex numTables = CFArrayGetCount(tableTags.get());
+    for (CFIndex index = 0; index < numTables; ++index) {
+        CTFontTableTag tag = (CTFontTableTag)(uintptr_t)CFArrayGetValueAtIndex(tableTags.get(), index);
+        if (tag == 'MATH')
+            return true;
+    }
+    return false;
+}
+#endif
+
+static inline short readShortFromTable(const UInt8* os2Data, CFIndex offset)
+{
+    return *(reinterpret_cast<const OpenType::Int16*>(os2Data + offset));
+}
+
+bool tryGetTypoMetrics(CGFontRef cgFont, short& ascent, short& descent, short& lineGap)
+{
+    bool result = false;
+    if (CFDataRef os2Table = CGFontCopyTableForTag(cgFont, kCTFontTableOS2)) {
+        // 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;
+        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);
+            // We test the use typo bit on the least significant byte of fsSelection.
+            const UInt8 useTypoMetricsMask = 1 << 7;
+            if (*(os2Data + fsSelectionOffset + 1) & useTypoMetricsMask) {
+                ascent = readShortFromTable(os2Data, sTypoAscenderOffset);
+                descent = readShortFromTable(os2Data, sTypoDescenderOffset);
+                lineGap = readShortFromTable(os2Data, sTypoLineGapOffset);
+                result = true;
+            }
+        }
+        CFRelease(os2Table);
+    }
+    return result;
+}
+
+} // namespace OpenType
+} // namespace WebCore
Property changes on: trunk/Source/WebCore/platform/graphics/opentype/OpenTypeCG.cpp
___________________________________________________________________

Added: svn:eol-style

Added: trunk/Source/WebCore/platform/graphics/opentype/OpenTypeCG.h (0 => 192017)


--- trunk/Source/WebCore/platform/graphics/opentype/OpenTypeCG.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/opentype/OpenTypeCG.h	2015-11-04 08:50:31 UTC (rev 192017)
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2015 Frederic Wang (fred.w...@free.fr). 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 THE COPYRIGHT HOLDERS AND 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 THE COPYRIGHT
+ * OWNER OR 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 OpenTypeCG_h
+#define OpenTypeCG_h
+
+#include <CoreGraphics/CoreGraphics.h>
+#if PLATFORM(COCOA)
+#include <CoreText/CoreText.h>
+#endif
+
+namespace WebCore {
+namespace OpenType {
+
+#if PLATFORM(COCOA)
+bool fontHasMathTable(CTFontRef);
+#endif
+bool tryGetTypoMetrics(CGFontRef, short& ascent, short& descent, short& lineGap);
+
+} // namespace OpenType
+} // namespace WebCore
+#endif // OpenTypeCG_h
Property changes on: trunk/Source/WebCore/platform/graphics/opentype/OpenTypeCG.h
___________________________________________________________________

Added: svn:eol-style

Modified: trunk/Source/WebCore/platform/graphics/opentype/OpenTypeTypes.h (192016 => 192017)


--- trunk/Source/WebCore/platform/graphics/opentype/OpenTypeTypes.h	2015-11-04 08:10:09 UTC (rev 192016)
+++ trunk/Source/WebCore/platform/graphics/opentype/OpenTypeTypes.h	2015-11-04 08:50:31 UTC (rev 192017)
@@ -25,6 +25,10 @@
 #ifndef OpenTypeTypes_h
 #define OpenTypeTypes_h
 
+#if ENABLE(OPENTYPE_MATH)
+#include "Glyph.h"
+#endif
+
 #include "SharedBuffer.h"
 
 namespace WebCore {

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


--- trunk/Source/WebCore/platform/graphics/win/SimpleFontDataCGWin.cpp	2015-11-04 08:10:09 UTC (rev 192016)
+++ trunk/Source/WebCore/platform/graphics/win/SimpleFontDataCGWin.cpp	2015-11-04 08:50:31 UTC (rev 192017)
@@ -34,7 +34,7 @@
 #include "FontDescription.h"
 #include "GlyphPage.h"
 #include "HWndDC.h"
-#include "OpenTypeTypes.h"
+#include "OpenTypeCG.h"
 #include <ApplicationServices/ApplicationServices.h>
 #include <WebKitSystemInterface/WebKitSystemInterface.h>
 #include <mlang.h>
@@ -67,23 +67,11 @@
 
     // 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."
-    if (CFDataRef os2Table = CGFontCopyTableForTag(m_platformData.cgFont(), 'OS/2')) {
-        // 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;
-        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);
-            const unsigned short useTypoMetricsMask = 1 << 7;
-            if (*(reinterpret_cast<const OpenType::UInt16*>(os2Data + fsSelectionOffset)) & useTypoMetricsMask) {
-                iAscent = *(reinterpret_cast<const OpenType::Int16*>(os2Data + sTypoAscenderOffset));
-                iDescent = *(reinterpret_cast<const OpenType::Int16*>(os2Data + sTypoDescenderOffset));
-                iLineGap = *(reinterpret_cast<const OpenType::Int16*>(os2Data + sTypoLineGapOffset));
-            }
-        }
-        CFRelease(os2Table);
+    short typoAscent, typoDescent, typoLineGap;
+    if (OpenType::tryGetTypoMetrics(m_platformData.cgFont(), typoAscent, typoDescent, typoLineGap)) {
+        iAscent = typoAscent;
+        iDescent = typoDescent;
+        iLineGap = typoLineGap;
     }
 
     unsigned unitsPerEm = CGFontGetUnitsPerEm(font);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to