Changeset 188146 in webkit


Ignore:
Timestamp:
Aug 7, 2015 12:09:59 PM (9 years ago)
Author:
mmaxfield@apple.com
Message:

Implement font-feature-settings
https://bugs.webkit.org/show_bug.cgi?id=147722

Reviewed by Simon Fraser.

Source/WebCore:

Fonts with features are simply modeled as new font objects. Font
feature information is contained within FontDescription, and our
caches are correctly sensitive to this information. Therefore,
we just need to make our font lookup code honor the request to
use certain features.

This patch creates a file, FontCacheCoreText.cpp, which will be the
new home of all shared OS X / iOS FontCache code. Over time, I will
be moving more and more source into this file, until there is
nothing left of FontCacheMac.mm and FontCacheIOS.mm. For now, the
only function in this file is the code which applies font features.

Test: css3/font-feature-settings-preinstalled-fonts.html

  • WebCore.xcodeproj/project.pbxproj: Add FontCacheCoreText.cpp.
  • platform/graphics/FontCache.h:
  • platform/graphics/cocoa/FontCacheCoreText.cpp: Added.

(WebCore::appendTrueTypeFeature): What the name says.
(WebCore::appendOpenTypeFeature): Ditto.
(WebCore::applyFontFeatureSettings): Ditto.

  • platform/graphics/ios/FontCacheIOS.mm:

(WebCore::FontCache::getSystemFontFallbackForCharacters): Call
applyFontFeatureSettings().
(WebCore::FontCache::createFontPlatformData): Ditto.

  • platform/graphics/mac/FontCacheMac.mm:

(WebCore::fontWithFamily): Ditto.
(WebCore::FontCache::systemFallbackForCharacters): Ditto.
(WebCore::FontCache::createFontPlatformData): Ditto.

  • platform/graphics/mac/FontCustomPlatformData.cpp:

(WebCore::FontCustomPlatformData::fontPlatformData): Ditto.

  • rendering/RenderThemeIOS.mm:

(WebCore::RenderThemeIOS::updateCachedSystemFontDescription):
Ditto.

LayoutTests:

Until I can make a custom font for reference tests, use a simple dump-render-tree test.

  • css3/font-feature-settings-preinstalled-fonts.html: Added.
  • platform/mac-yosemite/css3/font-feature-settings-preinstalled-fonts-expected.txt: Added.
Location:
trunk
Files:
4 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r188143 r188146  
     12015-08-07  Myles C. Maxfield  <mmaxfield@apple.com>
     2
     3        Implement font-feature-settings
     4        https://bugs.webkit.org/show_bug.cgi?id=147722
     5
     6        Reviewed by Simon Fraser.
     7
     8        Until I can make a custom font for reference tests, use a simple dump-render-tree test.
     9
     10        * css3/font-feature-settings-preinstalled-fonts.html: Added.
     11        * platform/mac-yosemite/css3/font-feature-settings-preinstalled-fonts-expected.txt: Added.
     12
    1132015-08-07  Simon Fraser  <simon.fraser@apple.com>
    214
  • trunk/Source/WebCore/ChangeLog

    r188145 r188146  
     12015-08-07  Myles C. Maxfield  <mmaxfield@apple.com>
     2
     3        Implement font-feature-settings
     4        https://bugs.webkit.org/show_bug.cgi?id=147722
     5
     6        Reviewed by Simon Fraser.
     7
     8        Fonts with features are simply modeled as new font objects. Font
     9        feature information is contained within FontDescription, and our
     10        caches are correctly sensitive to this information. Therefore,
     11        we just need to make our font lookup code honor the request to
     12        use certain features.
     13
     14        This patch creates a file, FontCacheCoreText.cpp, which will be the
     15        new home of all shared OS X / iOS FontCache code. Over time, I will
     16        be moving more and more source into this file, until there is
     17        nothing left of FontCacheMac.mm and FontCacheIOS.mm. For now, the
     18        only function in this file is the code which applies font features.
     19
     20        Test: css3/font-feature-settings-preinstalled-fonts.html
     21
     22        * WebCore.xcodeproj/project.pbxproj: Add FontCacheCoreText.cpp.
     23        * platform/graphics/FontCache.h:
     24        * platform/graphics/cocoa/FontCacheCoreText.cpp: Added.
     25        (WebCore::appendTrueTypeFeature): What the name says.
     26        (WebCore::appendOpenTypeFeature): Ditto.
     27        (WebCore::applyFontFeatureSettings): Ditto.
     28        * platform/graphics/ios/FontCacheIOS.mm:
     29        (WebCore::FontCache::getSystemFontFallbackForCharacters): Call
     30        applyFontFeatureSettings().
     31        (WebCore::FontCache::createFontPlatformData): Ditto.
     32        * platform/graphics/mac/FontCacheMac.mm:
     33        (WebCore::fontWithFamily): Ditto.
     34        (WebCore::FontCache::systemFallbackForCharacters): Ditto.
     35        (WebCore::FontCache::createFontPlatformData): Ditto.
     36        * platform/graphics/mac/FontCustomPlatformData.cpp:
     37        (WebCore::FontCustomPlatformData::fontPlatformData): Ditto.
     38        * rendering/RenderThemeIOS.mm:
     39        (WebCore::RenderThemeIOS::updateCachedSystemFontDescription):
     40        Ditto.
     41
    1422015-08-07  Commit Queue  <commit-queue@webkit.org>
    243
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r188127 r188146  
    952952                1C26497A0D7E248A00BD10F2 /* DocumentLoaderMac.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1C2649790D7E248A00BD10F2 /* DocumentLoaderMac.cpp */; };
    953953                1C26497C0D7E24EC00BD10F2 /* PageMac.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1C26497B0D7E24EC00BD10F2 /* PageMac.cpp */; };
     954                1C3969D01B74211E002BCFA7 /* FontCacheCoreText.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1C3969CF1B74211E002BCFA7 /* FontCacheCoreText.cpp */; };
    954955                1C6466251A12C38E0094603C /* CoreTextSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = 1C5E980F1A02CEFA002DB55F /* CoreTextSPI.h */; settings = {ATTRIBUTES = (Private, ); }; };
    955956                1C6466281A12C4200094603C /* NSFontSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = 1C6466271A12C3F90094603C /* NSFontSPI.h */; settings = {ATTRIBUTES = (Private, ); }; };
     
    81178118                1C2649790D7E248A00BD10F2 /* DocumentLoaderMac.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DocumentLoaderMac.cpp; sourceTree = "<group>"; };
    81188119                1C26497B0D7E24EC00BD10F2 /* PageMac.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PageMac.cpp; sourceTree = "<group>"; };
     8120                1C3969CF1B74211E002BCFA7 /* FontCacheCoreText.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FontCacheCoreText.cpp; sourceTree = "<group>"; };
    81198121                1C5E980F1A02CEFA002DB55F /* CoreTextSPI.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CoreTextSPI.h; sourceTree = "<group>"; };
    81208122                1C6466271A12C3F90094603C /* NSFontSPI.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NSFontSPI.h; sourceTree = "<group>"; };
     
    2125921261                        isa = PBXGroup;
    2126021262                        children = (
     21263                                1C3969CF1B74211E002BCFA7 /* FontCacheCoreText.cpp */,
    2126121264                                B2AFFC780D00A5C10030074D /* FontCascadeCocoa.mm */,
    2126221265                                7C4EDD731A7B607800198C4D /* FontCocoa.mm */,
     
    2999730000                                93F19AD508245E59001E9ABC /* RenderTreeAsText.cpp in Sources */,
    2999830001                                5824ABAA1AE849C8009074B7 /* RenderTreePosition.cpp in Sources */,
     30002                                1C3969D01B74211E002BCFA7 /* FontCacheCoreText.cpp in Sources */,
    2999930003                                E44614510CD68A3500FADA75 /* RenderVideo.cpp in Sources */,
    3000030004                                BCEA4867097D93020094C9E4 /* RenderView.cpp in Sources */,
  • trunk/Source/WebCore/platform/graphics/FontCache.h

    r188114 r188146  
    4141#include <wtf/text/WTFString.h>
    4242
    43 #if PLATFORM(IOS)
     43#if PLATFORM(COCOA)
    4444#include <CoreText/CTFont.h>
    4545#endif
     
    215215};
    216216
     217#if PLATFORM(COCOA)
     218RetainPtr<CTFontRef> applyFontFeatureSettings(CTFontRef, const FontFeatureSettings&);
     219#endif
     220
    217221#if !PLATFORM(MAC)
    218222inline void FontCache::platformPurgeInactiveFontData()
  • trunk/Source/WebCore/platform/graphics/ios/FontCacheIOS.mm

    r188104 r188146  
    8686        return nullptr;
    8787
     88    if (substituteFont && description.featureSettings() && description.featureSettings()->size())
     89        substituteFont = applyFontFeatureSettings(substituteFont.get(), *description.featureSettings());
     90
    8891    CTFontSymbolicTraits originalTraits = CTFontGetSymbolicTraits(ctFont);
    8992    CTFontSymbolicTraits actualTraits = 0;
     
    693696        return nullptr;
    694697
     698    if (ctFont && fontDescription.featureSettings() && fontDescription.featureSettings()->size())
     699        ctFont = applyFontFeatureSettings(ctFont.get(), *fontDescription.featureSettings());
     700
    695701    CTFontSymbolicTraits actualTraits = 0;
    696702    if (isFontWeightBold(fontDescription.weight()) || fontDescription.italic())
  • trunk/Source/WebCore/platform/graphics/mac/FontCacheMac.mm

    r187985 r188146  
    265265// comparing the desiredFamily to the PostScript name of the installed fonts. If that fails
    266266// we then do a search based on the family names of the installed fonts.
    267 static NSFont *fontWithFamily(const AtomicString& family, NSFontTraitMask desiredTraits, FontWeight weight, float size)
     267static NSFont *fontWithFamily(const AtomicString& family, NSFontTraitMask desiredTraits, FontWeight weight, const FontFeatureSettings* featureSettings, float size)
    268268{
    269269    if (const auto& specialCase = fontWithFamilySpecialCase(family, weight, desiredTraits, size))
     
    287287
    288288    NSString *desiredFamily = family;
    289     font = CFBridgingRelease(CTFontCreateForCSS((CFStringRef)desiredFamily, toCoreTextFontWeight(weight), requestedTraits, size));
     289    RetainPtr<CTFontRef> foundFont = adoptCF(CTFontCreateForCSS((CFStringRef)desiredFamily, toCoreTextFontWeight(weight), requestedTraits, size));
     290    if (!foundFont)
     291        return nil;
     292    if (featureSettings && featureSettings->size())
     293        foundFont = applyFontFeatureSettings(foundFont.get(), *featureSettings);
     294    font = CFBridgingRelease(CFRetain(foundFont.get()));
    290295    availableFamily = [font familyName];
    291296    chosenWeight = [fontManager weightOfFont:font];
    292297
    293298#else
     299
     300    UNUSED_PARAM(featureSettings);
    294301
    295302    NSFontTraitMask desiredTraitsForNameMatch = desiredTraits | (weight >= FontWeight600 ? NSBoldFontMask : 0);
     
    507514    NSFont *nsFont = platformData.nsFont();
    508515    RetainPtr<CTFontRef> result = lookupCTFont(platformData.font(), platformData.size(), characters, length);
     516    if (result && description.featureSettings() && description.featureSettings()->size())
     517        result = applyFontFeatureSettings(result.get(), *description.featureSettings());
    509518    if (!result)
    510519        return nullptr;
     
    665674    float size = fontDescription.computedPixelSize();
    666675
    667     NSFont *nsFont = fontWithFamily(family, traits, fontDescription.weight(), size);
     676    NSFont *nsFont = fontWithFamily(family, traits, fontDescription.weight(), fontDescription.featureSettings(), size);
    668677    if (!nsFont) {
    669678        if (!shouldAutoActivateFontIfNeeded(family))
     
    674683        [NSFont fontWithName:family size:size];
    675684
    676         nsFont = fontWithFamily(family, traits, fontDescription.weight(), size);
     685        nsFont = fontWithFamily(family, traits, fontDescription.weight(), fontDescription.featureSettings(), size);
    677686        if (!nsFont)
    678687            return nullptr;
  • trunk/Source/WebCore/platform/graphics/mac/FontCustomPlatformData.cpp

    r188130 r188146  
    2222#include "FontCustomPlatformData.h"
    2323
     24#include "FontCache.h"
    2425#include "FontDescription.h"
    2526#include "FontPlatformData.h"
     
    4041    FontWidthVariant widthVariant = fontDescription.widthVariant();
    4142#if CORETEXT_WEB_FONTS
    42     return FontPlatformData(adoptCF(CTFontCreateWithFontDescriptor(m_fontDescriptor.get(), size, nullptr)).get(), size, bold, italic, orientation, widthVariant);
     43    RetainPtr<CTFontRef> font = adoptCF(CTFontCreateWithFontDescriptor(m_fontDescriptor.get(), size, nullptr));
     44    if (font && fontDescription.featureSettings() && fontDescription.featureSettings()->size())
     45        font = applyFontFeatureSettings(font.get(), *fontDescription.featureSettings());
     46    return FontPlatformData(font.get(), size, bold, italic, orientation, widthVariant);
    4347#else
    4448    return FontPlatformData(m_cgFont.get(), size, bold, italic, orientation, widthVariant);
  • trunk/Source/WebCore/rendering/RenderThemeIOS.mm

    r187878 r188146  
    12621262    ASSERT(fontDescriptor);
    12631263    RetainPtr<CTFontRef> font = adoptCF(CTFontCreateWithFontDescriptor(fontDescriptor.get(), 0, nullptr));
     1264    if (font && fontDescription.featureSettings() && fontDescription.featureSettings()->size())
     1265        font = applyFontFeatureSettings(font.get(), *fontDescription.featureSettings());
    12641266    fontDescription.setIsAbsoluteSize(true);
    12651267    fontDescription.setOneFamily(textStyle);
Note: See TracChangeset for help on using the changeset viewer.