Changeset 191456 in webkit


Ignore:
Timestamp:
Oct 22, 2015 10:17:56 AM (8 years ago)
Author:
fred.wang@free.fr
Message:

[Mac] Add support for the USE_TYPO_METRICS flag
https://bugs.webkit.org/show_bug.cgi?id=150394

Reviewed by Myles C. Maxfield.

Source/WebCore:

Make the Cocoa backend use the typo metrics for fonts with a MATH table when the OS/2 USE_TYPO_METRICS flag is set.

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

  • platform/graphics/cocoa/FontCocoa.mm:

(WebCore::fontHasMathTable): Add a function to verify whether a font has a MATH table.
(WebCore::Font::platformInit): Verify whether the OS/2 USE_TYPO_METRICS flag is set and use the typo metrics if that is the case.

LayoutTests:

Update font, reference and Mac expectation for fonts/use-typo-metrics-1.html

  • fonts/lineheight5000-typolineheight2300.woff: Add a MATH table.
  • platform/mac-mavericks/mathml/opentype/opentype-stretchy-horizontal-expected.txt: Updated.
  • platform/mac/TestExpectations: Remove Mac failure expectation.
  • platform/mac/mathml/opentype/opentype-stretchy-expected.txt: Updated.
  • platform/mac/mathml/opentype/opentype-stretchy-horizontal-expected.txt: Updated.
Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r191455 r191456  
     12015-10-22  Frederic Wang  <fred.wang@free.fr>
     2
     3        [Mac] Add support for the USE_TYPO_METRICS flag
     4        https://bugs.webkit.org/show_bug.cgi?id=150394
     5
     6        Reviewed by Myles C. Maxfield.
     7
     8        Update font, reference and Mac expectation for fonts/use-typo-metrics-1.html
     9
     10        * fonts/lineheight5000-typolineheight2300.woff: Add a MATH table.
     11        * platform/mac-mavericks/mathml/opentype/opentype-stretchy-horizontal-expected.txt: Updated.
     12        * platform/mac/TestExpectations: Remove Mac failure expectation.
     13        * platform/mac/mathml/opentype/opentype-stretchy-expected.txt: Updated.
     14        * platform/mac/mathml/opentype/opentype-stretchy-horizontal-expected.txt: Updated.
     15
    1162015-10-22  Michael Saboff  <msaboff@apple.com>
    217
  • trunk/LayoutTests/platform/mac-mavericks/mathml/opentype/opentype-stretchy-horizontal-expected.txt

    r191444 r191456  
    1111                RenderMathMLBlock (anonymous, flex) at (2,0) size 11x4
    1212                  RenderBlock (anonymous) at (0,0) size 2x4
    13                     RenderText at (0,-3) size 2x10
     13                    RenderText at (0,-3) size 2x0
    1414                      text run at (0,-3) width 2: "\x{219C}"
    1515              RenderMathMLSpace {mspace} at (4,0) size 8x1
     
    2222                RenderMathMLBlock (anonymous, flex) at (2,0) size 22x4
    2323                  RenderBlock (anonymous) at (0,0) size 2x4
    24                     RenderText at (0,-3) size 2x10
     24                    RenderText at (0,-3) size 2x0
    2525                      text run at (0,-3) width 2: "\x{219C}"
    2626              RenderMathMLSpace {mspace} at (5,0) size 16x1
     
    3333                RenderMathMLBlock (anonymous, flex) at (2,0) size 151x4
    3434                  RenderBlock (anonymous) at (0,0) size 2x4
    35                     RenderText at (0,-3) size 2x10
     35                    RenderText at (0,-3) size 2x0
    3636                      text run at (0,-3) width 2: "\x{219C}"
    3737              RenderMathMLSpace {mspace} at (2,0) size 151x1
  • trunk/LayoutTests/platform/mac/TestExpectations

    r191444 r191456  
    13491349# Imported Blink tests which have not been investigated.
    13501350imported/blink/compositing/video/video-controls-layer-creation-squashing.html [ Pass ImageOnlyFailure ]
    1351 
    1352 # USE_TYPO_METRICS is not implemented on mac.
    1353 webkit.org/b/131839 fonts/use-typo-metrics-1.html [ ImageOnlyFailure ]
  • trunk/LayoutTests/platform/mac/mathml/opentype/opentype-stretchy-expected.txt

    r191444 r191456  
    1010              RenderMathMLBlock (anonymous, flex) at (2,0) size 42x3
    1111                RenderBlock (anonymous) at (0,0) size 3x3
    12                   RenderText at (0,-3) size 3x10
     12                  RenderText at (0,-3) size 3x0
    1313                    text run at (0,-3) width 3: "\x{219F}"
    1414        RenderText {#text} at (48,16) size 5x18
     
    1919              RenderMathMLBlock (anonymous, flex) at (2,0) size 42x3
    2020                RenderBlock (anonymous) at (0,0) size 3x3
    21                   RenderText at (0,-3) size 3x10
     21                  RenderText at (0,-3) size 3x0
    2222                    text run at (0,-3) width 3: "\x{219F}"
    2323        RenderText {#text} at (100,16) size 5x18
     
    2828              RenderMathMLBlock (anonymous, flex) at (2,0) size 42x3
    2929                RenderBlock (anonymous) at (0,0) size 3x3
    30                   RenderText at (0,-3) size 3x10
     30                  RenderText at (0,-3) size 3x0
    3131                    text run at (0,-3) width 3: "\x{219F}"
    3232        RenderText {#text} at (0,0) size 0x0
     
    3737              RenderMathMLBlock (anonymous, flex) at (2,0) size 42x3
    3838                RenderBlock (anonymous) at (0,0) size 3x3
    39                   RenderText at (0,-3) size 3x10
     39                  RenderText at (0,-3) size 3x0
    4040                    text run at (0,-3) width 3: "\x{219F}"
    4141        RenderText {#text} at (0,0) size 0x0
     
    4646              RenderMathMLBlock (anonymous, flex) at (0,0) size 83x12
    4747                RenderBlock (anonymous) at (0,0) size 11x12
    48                   RenderText at (0,6) size 11x10
     48                  RenderText at (0,6) size 11x0
    4949                    text run at (0,6) width 11: "\x{2A1B}"
    5050        RenderText {#text} at (0,0) size 0x0
  • trunk/LayoutTests/platform/mac/mathml/opentype/opentype-stretchy-horizontal-expected.txt

    r191444 r191456  
    1111                RenderMathMLBlock (anonymous, flex) at (2,0) size 11x4
    1212                  RenderBlock (anonymous) at (0,0) size 2x4
    13                     RenderText at (0,-3) size 2x10
     13                    RenderText at (0,-3) size 2x0
    1414                      text run at (0,-3) width 2: "\x{219C}"
    1515              RenderMathMLSpace {mspace} at (4,0) size 8x1
     
    2222                RenderMathMLBlock (anonymous, flex) at (2,0) size 22x4
    2323                  RenderBlock (anonymous) at (0,0) size 2x4
    24                     RenderText at (0,-3) size 2x10
     24                    RenderText at (0,-3) size 2x0
    2525                      text run at (0,-3) width 2: "\x{219C}"
    2626              RenderMathMLSpace {mspace} at (5,0) size 16x1
     
    3333                RenderMathMLBlock (anonymous, flex) at (2,0) size 151x4
    3434                  RenderBlock (anonymous) at (0,0) size 2x4
    35                     RenderText at (0,-3) size 2x10
     35                    RenderText at (0,-3) size 2x0
    3636                      text run at (0,-3) width 2: "\x{219C}"
    3737              RenderMathMLSpace {mspace} at (2,0) size 151x1
  • trunk/Source/WebCore/ChangeLog

    r191452 r191456  
     12015-10-22  Frederic Wang  <fred.wang@free.fr>
     2
     3        [Mac] Add support for the USE_TYPO_METRICS flag
     4        https://bugs.webkit.org/show_bug.cgi?id=150394
     5
     6        Reviewed by Myles C. Maxfield.
     7
     8        Make the Cocoa backend use the typo metrics for fonts with a MATH table when the OS/2 USE_TYPO_METRICS flag is set.
     9
     10        No new tests because this is already tested by fonts/use-typo-metrics-1.html
     11
     12        * platform/graphics/cocoa/FontCocoa.mm:
     13        (WebCore::fontHasMathTable): Add a function to verify whether a font has a MATH table.
     14        (WebCore::Font::platformInit): Verify whether the OS/2 USE_TYPO_METRICS flag is set and use the typo metrics if that is the case.
     15
    1162015-10-22  Wenson Hsieh  <wenson_hsieh@apple.com>
    217
  • trunk/Source/WebCore/platform/graphics/cocoa/FontCocoa.mm

    r191444 r191456  
    5858#endif
    5959
     60#if USE(APPKIT)
     61#include "OpenTypeTypes.h"
     62#endif
     63
    6064namespace WebCore {
    6165
     
    7478
    7579#if USE(APPKIT)
     80static 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
    7692static NSString *webFallbackFontFamily(void)
    7793{
     
    171187    float lineGap = scaleEmToUnits(CGFontGetLeading(m_platformData.cgFont()), unitsPerEm) * pointSize;
    172188
     189    // The Open Font Format describes the OS/2 USE_TYPO_METRICS flag as follows:
     190    // "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);
     210        }
     211    }
     212
    173213    // We need to adjust Times, Helvetica, and Courier to closely match the
    174214    // vertical metrics of their Microsoft counterparts that are the de facto
Note: See TracChangeset for help on using the changeset viewer.