Changeset 192017 in webkit


Ignore:
Timestamp:
Nov 4, 2015 12:50:31 AM (9 years ago)
Author:
fred.wang@free.fr
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.

Location:
trunk/Source/WebCore
Files:
2 added
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r192016 r192017  
     12015-11-04  Frederic Wang  <fred.wang@free.fr>
     2
     3        Add support for the USE_TYPO_METRICS flag on iOS
     4        https://bugs.webkit.org/show_bug.cgi?id=131839
     5
     6        Reviewed by Darin Adler.
     7
     8        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.
     9        The code shared by iOS, OS X and AppleWin is moved into a separate OpenTypeCG module.
     10
     11        No new tests because this is already tested by fonts/use-typo-metrics-1.html
     12
     13        * PlatformAppleWin.cmake: Add OpenTypeCG files.
     14        * PlatformMac.cmake: ditto.
     15        * WebCore.vcxproj/WebCore.vcxproj: ditto.
     16        * WebCore.vcxproj/WebCore.vcxproj.filters: ditto.
     17        * WebCore.xcodeproj/project.pbxproj: ditto.
     18        * platform/graphics/cocoa/FontCocoa.mm:
     19        (WebCore::Font::platformInit): Use functions from OpenTypeCG.
     20        (WebCore::fontHasMathTable): Deleted.
     21        * platform/graphics/ios/FontServicesIOS.mm:
     22        (WebCore::FontServicesIOS::FontServicesIOS): Use the typo metrics for fonts with a MATH table when the OS/2 USE_TYPO_METRICS flag is set.
     23        * platform/graphics/opentype/OpenTypeCG.h: Added.
     24        * platform/graphics/opentype/OpenTypeCG.cpp: Added.
     25        (WebCore::OpenType::fontHasMathTable): Move this code from FontCocoa.mm.
     26        (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.
     27        (WebCore::OpenType::tryGetTypoMetrics): Move this code from FontCocoa.mm.
     28        * platform/graphics/opentype/OpenTypeTypes.h: Add missing Glyph.h header needed by TableWithCoverage::getCoverageIndex.
     29        * platform/graphics/win/SimpleFontDataCGWin.cpp:
     30        (WebCore::Font::platformInit): Use functions from OpenTypeCG.
     31
    1322015-11-04  Chris Dumez  <cdumez@apple.com>
    233
  • trunk/Source/WebCore/PlatformAppleWin.cmake

    r190421 r192017  
    8383    platform/graphics/cg/TransformationMatrixCG.cpp
    8484
     85    platform/graphics/opentype/OpenTypeCG.cpp
     86
    8587    platform/graphics/win/FontCGWin.cpp
    8688    platform/graphics/win/FontCustomPlatformData.cpp
  • trunk/Source/WebCore/PlatformMac.cmake

    r191912 r192017  
    443443    platform/graphics/opengl/TemporaryOpenGLSetting.cpp
    444444
     445    platform/graphics/opentype/OpenTypeCG.cpp
    445446    platform/graphics/opentype/OpenTypeMathData.cpp
    446447
  • trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj

    r191719 r192017  
    84638463    <ClCompile Include="..\platform\graphics\win\IntSizeWin.cpp" />
    84648464    <ClCompile Include="..\platform\graphics\win\MediaPlayerPrivateFullscreenWindow.cpp" />
     8465    <ClCompile Include="..\platform\graphics\opentype\OpenTypeCG.cpp">
     8466      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug_WinCairo|Win32'">true</ExcludedFromBuild>
     8467      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug_WinCairo|x64'">true</ExcludedFromBuild>
     8468      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release_WinCairo|Win32'">true</ExcludedFromBuild>
     8469      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release_WinCairo|x64'">true</ExcludedFromBuild>
     8470    </ClCompile>
    84658471    <ClCompile Include="..\platform\graphics\opentype\OpenTypeMathData.cpp" />
    84668472    <ClCompile Include="..\platform\graphics\opentype\OpenTypeUtilities.cpp" />
  • trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj.filters

    r191719 r192017  
    71297129      <Filter>DerivedSources</Filter>
    71307130    </ClCompile>
     7131    <ClCompile Include="..\platform\graphics\opentype\OpenTypeCG.cpp">
     7132      <Filter>platform\graphics\opentype</Filter>
     7133    </ClCompile>
    71317134    <ClCompile Include="..\platform\graphics\opentype\OpenTypeMathData.cpp">
    71327135      <Filter>platform\graphics\opentype</Filter>
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r192014 r192017  
    49964996                B2C3DA6C0D006CD600EF6F26 /* GlyphBuffer.h in Headers */ = {isa = PBXBuildFile; fileRef = B2C3DA5B0D006CD600EF6F26 /* GlyphBuffer.h */; settings = {ATTRIBUTES = (Private, ); }; };
    49974997                B2C96D8D0B3AF2B7005E80EC /* JSSVGPathSegCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B2C96D8C0B3AF2B7005E80EC /* JSSVGPathSegCustom.cpp */; };
     4998                B2D3DA640D006CD600EF6F3A /* OpenTypeCG.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B2D3DA530D006CD600EF6F3A /* OpenTypeCG.cpp */; };
     4999                B2D3DA650D006CD600EF6F3A /* OpenTypeCG.h in Headers */ = {isa = PBXBuildFile; fileRef = B2D3DA540D006CD600EF6F3A /* OpenTypeCG.h */; settings = {ATTRIBUTES = (Private, ); }; };
    49985000                B2D3DA640D006CD600EF6F27 /* OpenTypeMathData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B2D3DA530D006CD600EF6F27 /* OpenTypeMathData.cpp */; };
    49995001                B2D3DA650D006CD600EF6F27 /* OpenTypeMathData.h in Headers */ = {isa = PBXBuildFile; fileRef = B2D3DA540D006CD600EF6F27 /* OpenTypeMathData.h */; settings = {ATTRIBUTES = (Private, ); }; };
     
    1273012732                B2C3DA5B0D006CD600EF6F26 /* GlyphBuffer.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = GlyphBuffer.h; sourceTree = "<group>"; };
    1273112733                B2C96D8C0B3AF2B7005E80EC /* JSSVGPathSegCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = JSSVGPathSegCustom.cpp; sourceTree = "<group>"; };
     12734                B2D3DA530D006CD600EF6F3A /* OpenTypeCG.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = OpenTypeCG.cpp; sourceTree = "<group>"; };
     12735                B2D3DA540D006CD600EF6F3A /* OpenTypeCG.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = OpenTypeCG.h; sourceTree = "<group>"; };
    1273212736                B2D3DA530D006CD600EF6F27 /* OpenTypeMathData.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = OpenTypeMathData.cpp; sourceTree = "<group>"; };
    1273312737                B2D3DA540D006CD600EF6F27 /* OpenTypeMathData.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = OpenTypeMathData.h; sourceTree = "<group>"; };
     
    1628716291                        isa = PBXGroup;
    1628816292                        children = (
     16293                                B2D3DA530D006CD600EF6F3A /* OpenTypeCG.cpp */,
     16294                                B2D3DA540D006CD600EF6F3A /* OpenTypeCG.h */,
    1628916295                                B2D3DA530D006CD600EF6F27 /* OpenTypeMathData.cpp */,
    1629016296                                B2D3DA540D006CD600EF6F27 /* OpenTypeMathData.h */,
     
    2676226768                                FDA9325E16703B2A008982DC /* OfflineAudioContext.h in Headers */,
    2676326769                                FDA3E95C134A49EF008D4B5A /* OfflineAudioDestinationNode.h in Headers */,
     26770                                B2D3DA650D006CD600EF6F3A /* OpenTypeCG.h in Headers */,
    2676426771                                B2D3DA650D006CD600EF6F27 /* OpenTypeMathData.h in Headers */,
    2676526772                                B2D3EA650D006CD600EF6F28 /* OpenTypeTypes.h in Headers */,
     
    3040230409                                FDA9325D16703B2A008982DC /* OfflineAudioContext.cpp in Sources */,
    3040330410                                FDA3E95B134A49EF008D4B5A /* OfflineAudioDestinationNode.cpp in Sources */,
     30411                                B2D3DA640D006CD600EF6F3A /* OpenTypeCG.cpp in Sources */,
    3040430412                                B2D3DA640D006CD600EF6F27 /* OpenTypeMathData.cpp in Sources */,
    3040530413                                CDE7FC44181904B1002BBB77 /* OrderIterator.cpp in Sources */,
  • trunk/Source/WebCore/platform/graphics/cocoa/FontCocoa.mm

    r191871 r192017  
    5959
    6060#if USE(APPKIT)
    61 #include "OpenTypeTypes.h"
     61#import "OpenTypeCG.h"
    6262#endif
    6363
     
    7878
    7979#if USE(APPKIT)
    80 static bool fontHasMathTable(CTFontRef ctFont)
    81 {
    82     RetainPtr<CFArrayRef> tableTags = adoptCF(CTFontCopyAvailableTables(ctFont, kCTFontTableOptionNoOptions));
    83     CFIndex numTables = CFArrayGetCount(tableTags.get());
    84     for (CFIndex index = 0; index < numTables; ++index) {
    85         CTFontTableTag tag = (CTFontTableTag)(uintptr_t)CFArrayGetValueAtIndex(tableTags.get(), index);
    86         if (tag == 'MATH')
    87             return true;
    88     }
    89     return false;
    90 }
    91 
    9280static NSString *webFallbackFontFamily(void)
    9381{
     
    189177    // The Open Font Format describes the OS/2 USE_TYPO_METRICS flag as follows:
    190178    // "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."
    191     // We only apply this rule in the important case of fonts with a MATH table.
    192     if (fontHasMathTable(m_platformData.ctFont())) {
    193         if (CFDataRef os2Table = CGFontCopyTableForTag(m_platformData.cgFont(), kCTFontTableOS2)) {
    194             // For the structure of the OS/2 table, see
    195             // https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6OS2.html
    196             const CFIndex fsSelectionOffset = 16 * 2 + 10 + 4 * 4 + 4 * 1;
    197             const CFIndex sTypoAscenderOffset = fsSelectionOffset + 3 * 2;
    198             const CFIndex sTypoDescenderOffset = sTypoAscenderOffset + 2;
    199             const CFIndex sTypoLineGapOffset = sTypoDescenderOffset + 2;
    200             if (CFDataGetLength(os2Table) >= sTypoLineGapOffset + 2) {
    201                 const UInt8* os2Data = CFDataGetBytePtr(os2Table);
    202                 const unsigned short useTypoMetricsMask = 1 << 7;
    203                 if (*(reinterpret_cast<const OpenType::UInt16*>(os2Data + fsSelectionOffset)) & useTypoMetricsMask) {
    204                     ascent = scaleEmToUnits(*(reinterpret_cast<const OpenType::Int16*>(os2Data + sTypoAscenderOffset)), unitsPerEm) * pointSize;
    205                     descent = -scaleEmToUnits(*(reinterpret_cast<const OpenType::Int16*>(os2Data + sTypoDescenderOffset)), unitsPerEm) * pointSize;
    206                     lineGap = scaleEmToUnits(*(reinterpret_cast<const OpenType::Int16*>(os2Data + sTypoLineGapOffset)), unitsPerEm) * pointSize;
    207                 }
    208             }
    209             CFRelease(os2Table);
     179    // On OS X, we only apply this rule in the important case of fonts with a MATH table.
     180    if (OpenType::fontHasMathTable(m_platformData.ctFont())) {
     181        short typoAscent, typoDescent, typoLineGap;
     182        if (OpenType::tryGetTypoMetrics(m_platformData.cgFont(), typoAscent, typoDescent, typoLineGap)) {
     183            ascent = scaleEmToUnits(typoAscent, unitsPerEm) * pointSize;
     184            descent = -scaleEmToUnits(typoDescent, unitsPerEm) * pointSize;
     185            lineGap = scaleEmToUnits(typoLineGap, unitsPerEm) * pointSize;
    210186        }
    211187    }
  • trunk/Source/WebCore/platform/graphics/ios/FontServicesIOS.mm

    r176265 r192017  
    2929#import "DynamicLinkerSPI.h"
    3030#import "FontMetrics.h"
     31#import "OpenTypeCG.h"
    3132#import <wtf/RetainPtr.h>
    3233
     
    9697        }
    9798    }
     99    // The Open Font Format describes the OS/2 USE_TYPO_METRICS flag as follows:
     100    // "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."
     101    // On iOS, we only apply this rule in the important case of fonts with a MATH table.
     102    if (OpenType::fontHasMathTable(font)) {
     103        short typoAscent, typoDescent, typoLineGap;
     104        if (OpenType::tryGetTypoMetrics(cgFont.get(), typoAscent, typoDescent, typoLineGap)) {
     105            unsigned unitsPerEm = CGFontGetUnitsPerEm(cgFont.get());
     106            float pointSize = CTFontGetSize(font);
     107            ascent = scaleEmToUnits(typoAscent, unitsPerEm) * pointSize;
     108            descent = -scaleEmToUnits(typoDescent, unitsPerEm) * pointSize;
     109            lineGap = scaleEmToUnits(typoLineGap, unitsPerEm) * pointSize;
     110        }
     111    }
    98112    CGFloat adjustment = (shouldUseAdjustment(font, isiOS7OrLater)) ? ceil((ascent + descent) * kLineHeightAdjustment) : 0;
    99113
  • trunk/Source/WebCore/platform/graphics/opentype/OpenTypeTypes.h

    r166640 r192017  
    2525#ifndef OpenTypeTypes_h
    2626#define OpenTypeTypes_h
     27
     28#if ENABLE(OPENTYPE_MATH)
     29#include "Glyph.h"
     30#endif
    2731
    2832#include "SharedBuffer.h"
  • trunk/Source/WebCore/platform/graphics/win/SimpleFontDataCGWin.cpp

    r191893 r192017  
    3535#include "GlyphPage.h"
    3636#include "HWndDC.h"
    37 #include "OpenTypeTypes.h"
     37#include "OpenTypeCG.h"
    3838#include <ApplicationServices/ApplicationServices.h>
    3939#include <WebKitSystemInterface/WebKitSystemInterface.h>
     
    6868    // The Open Font Format describes the OS/2 USE_TYPO_METRICS flag as follows:
    6969    // "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."
    70     if (CFDataRef os2Table = CGFontCopyTableForTag(m_platformData.cgFont(), 'OS/2')) {
    71         // For the structure of the OS/2 table, see
    72         // https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6OS2.html
    73         const CFIndex fsSelectionOffset = 16 * 2 + 10 + 4 * 4 + 4 * 1;
    74         const CFIndex sTypoAscenderOffset = fsSelectionOffset + 3 * 2;
    75         const CFIndex sTypoDescenderOffset = sTypoAscenderOffset + 2;
    76         const CFIndex sTypoLineGapOffset = sTypoDescenderOffset + 2;
    77         if (CFDataGetLength(os2Table) >= sTypoLineGapOffset + 2) {
    78             const UInt8* os2Data = CFDataGetBytePtr(os2Table);
    79             const unsigned short useTypoMetricsMask = 1 << 7;
    80             if (*(reinterpret_cast<const OpenType::UInt16*>(os2Data + fsSelectionOffset)) & useTypoMetricsMask) {
    81                 iAscent = *(reinterpret_cast<const OpenType::Int16*>(os2Data + sTypoAscenderOffset));
    82                 iDescent = *(reinterpret_cast<const OpenType::Int16*>(os2Data + sTypoDescenderOffset));
    83                 iLineGap = *(reinterpret_cast<const OpenType::Int16*>(os2Data + sTypoLineGapOffset));
    84             }
    85         }
    86         CFRelease(os2Table);
     70    short typoAscent, typoDescent, typoLineGap;
     71    if (OpenType::tryGetTypoMetrics(m_platformData.cgFont(), typoAscent, typoDescent, typoLineGap)) {
     72        iAscent = typoAscent;
     73        iDescent = typoDescent;
     74        iLineGap = typoLineGap;
    8775    }
    8876
Note: See TracChangeset for help on using the changeset viewer.