Changeset 176146 in webkit


Ignore:
Timestamp:
Nov 14, 2014 4:02:57 PM (9 years ago)
Author:
mmaxfield@apple.com
Message:

Get rid of WebFontCache
https://bugs.webkit.org/show_bug.cgi?id=134752

Reviewed by Dave Hyatt.

Source/WebCore:

No new tests because there is no behavior change.

  • Configurations/WebCore.xcconfig:
  • PlatformMac.cmake:
  • WebCore.exp.in:
  • WebCore.order:
  • WebCore.xcodeproj/project.pbxproj:
  • platform/graphics/mac/FontCacheMac.mm:

(WebCore::acceptableChoice):
(WebCore::betterChoice):
(WebCore::toTraitsMask):
(WebCore::desiredFamilyToAvailableFamilyDictionary):
(WebCore::rememberDesiredFamilyToAvailableFamilyMapping):
(WebCore::fontWithFamily):
(WebCore::invalidateFontCache):
(WebCore::FontCache::getTraitsInFamily):
(WebCore::FontCache::createFontPlatformData):

  • platform/mac/WebFontCache.h: Removed.
  • platform/mac/WebFontCache.mm: Removed.

Source/WebKit/mac:

  • WebView/WebHTMLView.mm:
Location:
trunk/Source
Files:
2 deleted
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r176142 r176146  
     12014-11-14  Myles C. Maxfield  <mmaxfield@apple.com>
     2
     3        Get rid of WebFontCache
     4        https://bugs.webkit.org/show_bug.cgi?id=134752
     5
     6        Reviewed by Dave Hyatt.
     7
     8        No new tests because there is no behavior change.
     9
     10        * Configurations/WebCore.xcconfig:
     11        * PlatformMac.cmake:
     12        * WebCore.exp.in:
     13        * WebCore.order:
     14        * WebCore.xcodeproj/project.pbxproj:
     15        * platform/graphics/mac/FontCacheMac.mm:
     16        (WebCore::acceptableChoice):
     17        (WebCore::betterChoice):
     18        (WebCore::toTraitsMask):
     19        (WebCore::desiredFamilyToAvailableFamilyDictionary):
     20        (WebCore::rememberDesiredFamilyToAvailableFamilyMapping):
     21        (WebCore::fontWithFamily):
     22        (WebCore::invalidateFontCache):
     23        (WebCore::FontCache::getTraitsInFamily):
     24        (WebCore::FontCache::createFontPlatformData):
     25        * platform/mac/WebFontCache.h: Removed.
     26        * platform/mac/WebFontCache.mm: Removed.
     27
    1282014-11-14  Daniel Bates  <dabates@apple.com>
    229
  • trunk/Source/WebCore/Configurations/WebCore.xcconfig

    r173192 r176146  
    123123
    124124EXCLUDED_SOURCE_FILE_NAMES = $(EXCLUDED_SOURCE_FILE_NAMES_$(PLATFORM_NAME));
    125 EXCLUDED_SOURCE_FILE_NAMES_iphoneos = *.tiff *Cursor.png AccessibilityObjectMac.mm AXObjectCacheMac.mm ColorMac.mm Cursor.cpp CursorMac.mm DataTransferMac.mm EditorMac.mm EventHandlerMac.mm EventLoopMac.mm GeolocationServiceMac.mm GraphicsContext3DOpenGLES.cpp IconDatabase.cpp IconMac.mm KillRingMac.mm LocalCurrentGraphicsContext.mm MIMETypeRegistryMac.mm MediaPlayerPrivateQTKit.mm NSScrollerImpDetails.mm NetworkStateNotifierMac.cpp PasteboardMac.mm PlatformEventFactoryMac.mm PlatformMouseEventMac.mm PlatformPasteboardMac.mm PlatformScreenMac.mm PlatformSpeechSynthesizerMac.mm PluginMainThreadScheduler.cpp RunLoopMac.mm SSLKeyGeneratorMac.cpp ScrollViewMac.mm ScrollbarThemeMac.mm SharedTimerMac.mm SoundMac.mm SystemTimeMac.cpp ThemeMac.mm ThreadCheck.mm UserAgentMac.mm WebAccessibilityObjectWrapperMac.mm WebCoreSystemInterface.mm WebCoreView.m WebFontCache.mm WebVideoFullscreenController.mm WebVideoFullscreenHUDWindowController.mm WebWindowAnimation.mm WidgetMac.mm DisplayRefreshMonitorMac.cpp $(EXCLUDED_SOURCE_FILE_NAMES_FOR_TOUCH_EVENTS) $(EXCLUDED_SOURCE_FILE_NAMES_FOR_GESTURE_EVENTS);
     125EXCLUDED_SOURCE_FILE_NAMES_iphoneos = *.tiff *Cursor.png AccessibilityObjectMac.mm AXObjectCacheMac.mm ColorMac.mm Cursor.cpp CursorMac.mm DataTransferMac.mm EditorMac.mm EventHandlerMac.mm EventLoopMac.mm GeolocationServiceMac.mm GraphicsContext3DOpenGLES.cpp IconDatabase.cpp IconMac.mm KillRingMac.mm LocalCurrentGraphicsContext.mm MIMETypeRegistryMac.mm MediaPlayerPrivateQTKit.mm NSScrollerImpDetails.mm NetworkStateNotifierMac.cpp PasteboardMac.mm PlatformEventFactoryMac.mm PlatformMouseEventMac.mm PlatformPasteboardMac.mm PlatformScreenMac.mm PlatformSpeechSynthesizerMac.mm PluginMainThreadScheduler.cpp RunLoopMac.mm SSLKeyGeneratorMac.cpp ScrollViewMac.mm ScrollbarThemeMac.mm SharedTimerMac.mm SoundMac.mm SystemTimeMac.cpp ThemeMac.mm ThreadCheck.mm UserAgentMac.mm WebAccessibilityObjectWrapperMac.mm WebCoreSystemInterface.mm WebCoreView.m WebVideoFullscreenController.mm WebVideoFullscreenHUDWindowController.mm WebWindowAnimation.mm WidgetMac.mm DisplayRefreshMonitorMac.cpp $(EXCLUDED_SOURCE_FILE_NAMES_FOR_TOUCH_EVENTS) $(EXCLUDED_SOURCE_FILE_NAMES_FOR_GESTURE_EVENTS);
    126126EXCLUDED_SOURCE_FILE_NAMES_iphonesimulator = $(EXCLUDED_SOURCE_FILE_NAMES_iphoneos);
    127127EXCLUDED_SOURCE_FILE_NAMES_macosx = *IOS.h *IOS.cpp *IOS.mm KillRingNone.cpp WAKAppKitStubs.h WAKClipView.h WAKResponder.h WAKScrollView.h WAKView.h WAKViewPrivate.h WAKWindow.h WKContentObservation.h WKGraphics.h WKTypes.h WKUtilities.h WKView.h WKViewPrivate.h WebCoreThread.h WebCoreThreadMessage.h WebCoreThreadRun.h WebCoreThreadSystemInterface.h $(EXCLUDED_SOURCE_FILE_NAMES_FOR_TOUCH_EVENTS) $(EXCLUDED_SOURCE_FILE_NAMES_FOR_GESTURE_EVENTS);
  • trunk/Source/WebCore/PlatformMac.cmake

    r172616 r176146  
    148148    platform/mac/WebCoreSystemInterface.mm
    149149    platform/mac/WebCoreView.m
    150     platform/mac/WebFontCache.mm
    151150    platform/mac/WebNSAttributedStringExtras.mm
    152151    platform/mac/WebVideoFullscreenController.mm
  • trunk/Source/WebCore/WebCore.exp.in

    r176137 r176146  
    22822282.objc_class_name_WebCoreFullScreenWarningView
    22832283.objc_class_name_WebCoreFullScreenWindow
    2284 .objc_class_name_WebFontCache
    22852284.objc_class_name_WebWindowFadeAnimation
    22862285.objc_class_name_WebWindowScaleAnimation
  • trunk/Source/WebCore/WebCore.order

    r176112 r176146  
    47224722__ZN3WTF9HashTableIN7WebCore24FontPlatformDataCacheKeyENS_12KeyValuePairIS2_NS_6OwnPtrINS1_16FontPlatformDataEEEEENS_24KeyValuePairKeyExtractorIS7_EENS1_28FontPlatformDataCacheKeyHashENS_18HashMapValueTraitsINS1_30FontPlatformDataCacheKeyTraitsENS_10HashTraitsIS6_EEEESC_E6rehashEi
    47234723__ZN7WebCore9FontCache22createFontPlatformDataERKNS_15FontDescriptionERKN3WTF12AtomicStringE
    4724 +[WebFontCache fontWithFamily:traits:weight:size:]
    4725 +[WebFontCache internalFontWithFamily:traits:weight:size:]
    47264724__ZNK7WebCore14SimpleFontData9isLoadingEv
    47274725__ZNK7WebCore11FontMetrics35hasIdenticalAscentDescentAndLineGapERKS0_
     
    82368234__ZN3WTF17HashMapTranslatorINS_18HashMapValueTraitsINS_10HashTraitsINS_6StringEEENS2_INS_6OwnPtrINS_6VectorINS_6RefPtrIN7WebCore11CSSFontFaceEEELm0ENS_15CrashOnOverflowEEEEEEEEENS_15CaseFoldingHashEE9translateINS_12KeyValuePairIS3_SD_EES3_NS_10PassOwnPtrISC_EEEEvRT_RKT0_RKT1_
    82378235__ZN7WebCore9FontCache17getTraitsInFamilyERKN3WTF12AtomicStringERNS1_6VectorIjLm0ENS1_15CrashOnOverflowEEE
    8238 +[WebFontCache getTraits:inFamily:]
    82398236__ZNK7WebCore12RenderObject14nextInPreOrderEv
    82408237__ZNK7WebCore10RenderText16linesBoundingBoxEv
     
    2052320520_OBJC_CLASS_$_WebCoreFullScreenWindow
    2052420521_OBJC_METACLASS_$_WebCoreFullScreenWindow
    20525 _OBJC_METACLASS_$_WebFontCache
    20526 _OBJC_CLASS_$_WebFontCache
    2052720522_OBJC_CLASS_$_WebGLLayer
    2052820523_OBJC_METACLASS_$_WebGLLayer
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r176142 r176146  
    52025202                BC6D44ED0C07F2ED0072D2C9 /* JSHTMLEmbedElement.h in Headers */ = {isa = PBXBuildFile; fileRef = BC6D44EB0C07F2ED0072D2C9 /* JSHTMLEmbedElement.h */; };
    52035203                BC6D6E2609AF943500F59759 /* ScrollView.h in Headers */ = {isa = PBXBuildFile; fileRef = BC6D6E2509AF943500F59759 /* ScrollView.h */; settings = {ATTRIBUTES = (Private, ); }; };
    5204                 BC6DADEF0A195FDF00E5CD14 /* WebFontCache.h in Headers */ = {isa = PBXBuildFile; fileRef = BC6DADEE0A195FDF00E5CD14 /* WebFontCache.h */; settings = {ATTRIBUTES = (Private, ); }; };
    5205                 BC6DADFA0A19602B00E5CD14 /* WebFontCache.mm in Sources */ = {isa = PBXBuildFile; fileRef = BC6DADF90A19602B00E5CD14 /* WebFontCache.mm */; };
    52065204                BC74DA371013F3F7007987AD /* RGBColor.h in Headers */ = {isa = PBXBuildFile; fileRef = BC74DA351013F3F7007987AD /* RGBColor.h */; };
    52075205                BC74DA381013F3F7007987AD /* RGBColor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BC74DA361013F3F7007987AD /* RGBColor.cpp */; };
     
    1259712595                BC6D44EB0C07F2ED0072D2C9 /* JSHTMLEmbedElement.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = JSHTMLEmbedElement.h; sourceTree = "<group>"; };
    1259812596                BC6D6E2509AF943500F59759 /* ScrollView.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = ScrollView.h; sourceTree = "<group>"; };
    12599                 BC6DADEE0A195FDF00E5CD14 /* WebFontCache.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = WebFontCache.h; sourceTree = "<group>"; };
    12600                 BC6DADF90A19602B00E5CD14 /* WebFontCache.mm */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.objcpp; path = WebFontCache.mm; sourceTree = "<group>"; };
    1260112597                BC74DA351013F3F7007987AD /* RGBColor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RGBColor.h; sourceTree = "<group>"; };
    1260212598                BC74DA361013F3F7007987AD /* RGBColor.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RGBColor.cpp; sourceTree = "<group>"; };
     
    1648316479                                BE855F7F0701E83500239769 /* WebCoreView.h */,
    1648416480                                BE8560510701F91100239769 /* WebCoreView.m */,
    16485                                 BC6DADEE0A195FDF00E5CD14 /* WebFontCache.h */,
    16486                                 BC6DADF90A19602B00E5CD14 /* WebFontCache.mm */,
    1648716481                                E1A3162B134BC32D007C9A4F /* WebNSAttributedStringExtras.h */,
    1648816482                                E1A3162C134BC32D007C9A4F /* WebNSAttributedStringExtras.mm */,
     
    2660026594                                FE0D84E910484348001A179E /* WebEvent.h in Headers */,
    2660126595                                225A16B50D5C11E900090295 /* WebEventRegion.h in Headers */,
    26602                                 BC6DADEF0A195FDF00E5CD14 /* WebFontCache.h in Headers */,
    2660326596                                A7D20F6D107F438B00A80392 /* WebGLActiveInfo.h in Headers */,
    2660426597                                49C7B9C91042D32F0009D447 /* WebGLBuffer.h in Headers */,
     
    2987929872                                FE0D84EB1048436E001A179E /* WebEvent.mm in Sources */,
    2988029873                                225A16B60D5C11E900090295 /* WebEventRegion.mm in Sources */,
    29881                                 BC6DADFA0A19602B00E5CD14 /* WebFontCache.mm in Sources */,
    2988229874                                49C7B9C81042D32F0009D447 /* WebGLBuffer.cpp in Sources */,
    2988329875                                7E66E23316D6EB6C00F7E7FF /* WebGLCompressedTextureATC.cpp in Sources */,
  • trunk/Source/WebCore/platform/graphics/mac/FontCacheMac.mm

    r176112 r176146  
    3838#import "FontPlatformData.h"
    3939#import "NSFontSPI.h"
     40#import "WebCoreNSStringExtras.h"
    4041#import "WebCoreSystemInterface.h"
    41 #import "WebFontCache.h"
    4242#import <AppKit/AppKit.h>
    4343#import <wtf/MainThread.h>
     
    4949namespace WebCore {
    5050
     51#define SYNTHESIZED_FONT_TRAITS (NSBoldFontMask | NSItalicFontMask)
     52
     53#define IMPORTANT_FONT_TRAITS (0 \
     54    | NSCompressedFontMask \
     55    | NSCondensedFontMask \
     56    | NSExpandedFontMask \
     57    | NSItalicFontMask \
     58    | NSNarrowFontMask \
     59    | NSPosterFontMask \
     60    | NSSmallCapsFontMask \
     61)
     62
     63static bool acceptableChoice(NSFontTraitMask desiredTraits, NSFontTraitMask candidateTraits)
     64{
     65    desiredTraits &= ~SYNTHESIZED_FONT_TRAITS;
     66    return (candidateTraits & desiredTraits) == desiredTraits;
     67}
     68
     69static bool betterChoice(NSFontTraitMask desiredTraits, int desiredWeight, NSFontTraitMask chosenTraits, int chosenWeight, NSFontTraitMask candidateTraits, int candidateWeight)
     70{
     71    if (!acceptableChoice(desiredTraits, candidateTraits))
     72        return false;
     73
     74    // A list of the traits we care about.
     75    // The top item in the list is the worst trait to mismatch; if a font has this
     76    // and we didn't ask for it, we'd prefer any other font in the family.
     77    const NSFontTraitMask masks[] = {
     78        NSPosterFontMask,
     79        NSSmallCapsFontMask,
     80        NSItalicFontMask,
     81        NSCompressedFontMask,
     82        NSCondensedFontMask,
     83        NSExpandedFontMask,
     84        NSNarrowFontMask,
     85        0
     86    };
     87
     88    int i = 0;
     89    NSFontTraitMask mask;
     90    while ((mask = masks[i++])) {
     91        bool desired = desiredTraits & mask;
     92        bool chosenHasUnwantedTrait = desired != (chosenTraits & mask);
     93        bool candidateHasUnwantedTrait = desired != (candidateTraits & mask);
     94        if (!candidateHasUnwantedTrait && chosenHasUnwantedTrait)
     95            return true;
     96        if (!chosenHasUnwantedTrait && candidateHasUnwantedTrait)
     97            return false;
     98    }
     99
     100    int chosenWeightDeltaMagnitude = abs(chosenWeight - desiredWeight);
     101    int candidateWeightDeltaMagnitude = abs(candidateWeight - desiredWeight);
     102
     103    // If both are the same distance from the desired weight, prefer the candidate if it is further from medium.
     104    if (chosenWeightDeltaMagnitude == candidateWeightDeltaMagnitude)
     105        return abs(candidateWeight - 6) > abs(chosenWeight - 6);
     106
     107    // Otherwise, prefer the one closer to the desired weight.
     108    return candidateWeightDeltaMagnitude < chosenWeightDeltaMagnitude;
     109}
     110
     111static inline FontTraitsMask toTraitsMask(NSFontTraitMask appKitTraits, NSInteger appKitWeight)
     112{
     113    return static_cast<FontTraitsMask>(((appKitTraits & NSFontItalicTrait) ? FontStyleItalicMask : FontStyleNormalMask)
     114        | FontVariantNormalMask
     115        | (appKitWeight == 1 ? FontWeight100Mask :
     116            appKitWeight == 2 ? FontWeight200Mask :
     117            appKitWeight <= 4 ? FontWeight300Mask :
     118            appKitWeight == 5 ? FontWeight400Mask :
     119            appKitWeight == 6 ? FontWeight500Mask :
     120            appKitWeight <= 8 ? FontWeight600Mask :
     121            appKitWeight == 9 ? FontWeight700Mask :
     122            appKitWeight <= 11 ? FontWeight800Mask :
     123                FontWeight900Mask));
     124}
     125
     126// Keep a cache for mapping desired font families to font families actually
     127// available on the system for performance.
     128static NSMutableDictionary* desiredFamilyToAvailableFamilyDictionary()
     129{
     130    ASSERT(isMainThread());
     131    static NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init];
     132    return dictionary;
     133}
     134
     135static inline void rememberDesiredFamilyToAvailableFamilyMapping(NSString* desiredFamily, NSString* availableFamily)
     136{
     137    static const NSUInteger maxCacheSize = 128;
     138    NSMutableDictionary *familyMapping = desiredFamilyToAvailableFamilyDictionary();
     139    ASSERT([familyMapping count] <= maxCacheSize);
     140    if ([familyMapping count] == maxCacheSize) {
     141        for (NSString *key in familyMapping) {
     142            [familyMapping removeObjectForKey:key];
     143            break;
     144        }
     145    }
     146    id value = availableFamily ? availableFamily : [NSNull null];
     147    [familyMapping setObject:value forKey:desiredFamily];
     148}
     149
     150// Family name is somewhat of a misnomer here. We first attempt to find an exact match
     151// comparing the desiredFamily to the PostScript name of the installed fonts. If that fails
     152// we then do a search based on the family names of the installed fonts.
     153static NSFont *fontWithFamily(NSString *desiredFamily, NSFontTraitMask desiredTraits, int desiredWeight, float size)
     154{
     155    if (stringIsCaseInsensitiveEqualToString(desiredFamily, @"-webkit-system-font")
     156        || stringIsCaseInsensitiveEqualToString(desiredFamily, @"-apple-system-font")) {
     157        // We ignore italic for system font.
     158        return (desiredWeight >= 7) ? [NSFont boldSystemFontOfSize:size] : [NSFont systemFontOfSize:size];
     159    }
     160
     161    id cachedAvailableFamily = [desiredFamilyToAvailableFamilyDictionary() objectForKey:desiredFamily];
     162    if (cachedAvailableFamily == [NSNull null]) {
     163        // We already know this font is not available.
     164        return nil;
     165    }
     166
     167    NSFontManager *fontManager = [NSFontManager sharedFontManager];
     168    NSString *availableFamily = cachedAvailableFamily;
     169    if (!availableFamily) {
     170        // Do a simple case insensitive search for a matching font family.
     171        // NSFontManager requires exact name matches.
     172        // This addresses the problem of matching arial to Arial, etc., but perhaps not all the issues.
     173        for (availableFamily in [fontManager availableFontFamilies]) {
     174            if ([desiredFamily caseInsensitiveCompare:availableFamily] == NSOrderedSame)
     175                break;
     176        }
     177
     178        if (!availableFamily) {
     179            // Match by PostScript name.
     180            NSFont *nameMatchedFont = nil;
     181            NSFontTraitMask desiredTraitsForNameMatch = desiredTraits | (desiredWeight >= 7 ? NSBoldFontMask : 0);
     182            for (NSString *availableFont in [fontManager availableFonts]) {
     183                if ([desiredFamily caseInsensitiveCompare:availableFont] == NSOrderedSame) {
     184                    nameMatchedFont = [NSFont fontWithName:availableFont size:size];
     185
     186                    // Special case Osaka-Mono. According to <rdar://problem/3999467>, we need to
     187                    // treat Osaka-Mono as fixed pitch.
     188                    if ([desiredFamily caseInsensitiveCompare:@"Osaka-Mono"] == NSOrderedSame && !desiredTraitsForNameMatch)
     189                        return nameMatchedFont;
     190
     191                    NSFontTraitMask traits = [fontManager traitsOfFont:nameMatchedFont];
     192                    if ((traits & desiredTraitsForNameMatch) == desiredTraitsForNameMatch)
     193                        return [fontManager convertFont:nameMatchedFont toHaveTrait:desiredTraitsForNameMatch];
     194
     195                    availableFamily = [nameMatchedFont familyName];
     196                    break;
     197                }
     198            }
     199        }
     200
     201        rememberDesiredFamilyToAvailableFamilyMapping(desiredFamily, availableFamily);
     202        if (!availableFamily)
     203            return nil;
     204    }
     205
     206    // Found a family, now figure out what weight and traits to use.
     207    bool choseFont = false;
     208    int chosenWeight = 0;
     209    NSFontTraitMask chosenTraits = 0;
     210    NSString *chosenFullName = 0;
     211
     212    NSArray *fonts = [fontManager availableMembersOfFontFamily:availableFamily];
     213    for (NSArray *fontInfo in fonts) {
     214        // Array indices must be hard coded because of lame AppKit API.
     215        NSString *fontFullName = [fontInfo objectAtIndex:0];
     216        NSInteger fontWeight = [[fontInfo objectAtIndex:2] intValue];
     217        NSFontTraitMask fontTraits = [[fontInfo objectAtIndex:3] unsignedIntValue];
     218
     219        BOOL newWinner;
     220        if (!choseFont)
     221            newWinner = acceptableChoice(desiredTraits, fontTraits);
     222        else
     223            newWinner = betterChoice(desiredTraits, desiredWeight, chosenTraits, chosenWeight, fontTraits, fontWeight);
     224
     225        if (newWinner) {
     226            choseFont = YES;
     227            chosenWeight = fontWeight;
     228            chosenTraits = fontTraits;
     229            chosenFullName = fontFullName;
     230
     231            if (chosenWeight == desiredWeight && (chosenTraits & IMPORTANT_FONT_TRAITS) == (desiredTraits & IMPORTANT_FONT_TRAITS))
     232                break;
     233        }
     234    }
     235
     236    if (!choseFont)
     237        return nil;
     238
     239    NSFont *font = [NSFont fontWithName:chosenFullName size:size];
     240
     241    if (!font)
     242        return nil;
     243
     244    NSFontTraitMask actualTraits = 0;
     245    if (desiredTraits & NSFontItalicTrait)
     246        actualTraits = [fontManager traitsOfFont:font];
     247    int actualWeight = [fontManager weightOfFont:font];
     248
     249    bool syntheticBold = desiredWeight >= 7 && actualWeight < 7;
     250    bool syntheticOblique = (desiredTraits & NSFontItalicTrait) && !(actualTraits & NSFontItalicTrait);
     251
     252    // There are some malformed fonts that will be correctly returned by -fontWithFamily:traits:weight:size: as a match for a particular trait,
     253    // though -[NSFontManager traitsOfFont:] incorrectly claims the font does not have the specified trait. This could result in applying
     254    // synthetic bold on top of an already-bold font, as reported in <http://bugs.webkit.org/show_bug.cgi?id=6146>. To work around this
     255    // problem, if we got an apparent exact match, but the requested traits aren't present in the matched font, we'll try to get a font from
     256    // the same family without those traits (to apply the synthetic traits to later).
     257    NSFontTraitMask nonSyntheticTraits = desiredTraits;
     258
     259    if (syntheticBold)
     260        nonSyntheticTraits &= ~NSBoldFontMask;
     261
     262    if (syntheticOblique)
     263        nonSyntheticTraits &= ~NSItalicFontMask;
     264
     265    if (nonSyntheticTraits != desiredTraits) {
     266        NSFont *fontWithoutSyntheticTraits = [fontManager fontWithFamily:availableFamily traits:nonSyntheticTraits weight:chosenWeight size:size];
     267        if (fontWithoutSyntheticTraits)
     268            font = fontWithoutSyntheticTraits;
     269    }
     270
     271    return font;
     272}
     273
    51274// The "void*" parameter makes the function match the prototype for callbacks from callOnMainThread.
    52275static void invalidateFontCache(void*)
     
    57280    }
    58281    fontCache().invalidate();
    59     [WebFontCache invalidate];
     282    [desiredFamilyToAvailableFamilyDictionary() removeAllObjects];
    60283}
    61284
     
    222445void FontCache::getTraitsInFamily(const AtomicString& familyName, Vector<unsigned>& traitsMasks)
    223446{
    224     [WebFontCache getTraits:traitsMasks inFamily:familyName];
     447    NSFontManager *fontManager = [NSFontManager sharedFontManager];
     448
     449    NSString *availableFamily;
     450    for (availableFamily in [fontManager availableFontFamilies]) {
     451        if ([familyName caseInsensitiveCompare:availableFamily] == NSOrderedSame)
     452            break;
     453    }
     454
     455    if (!availableFamily) {
     456        // Match by PostScript name.
     457        for (NSString *availableFont in [fontManager availableFonts]) {
     458            if ([familyName caseInsensitiveCompare:availableFont] == NSOrderedSame) {
     459                NSFont *font = [NSFont fontWithName:availableFont size:10];
     460                NSInteger weight = [fontManager weightOfFont:font];
     461                traitsMasks.append(toTraitsMask([fontManager traitsOfFont:font], weight));
     462                break;
     463            }
     464        }
     465        return;
     466    }
     467
     468    NSArray *fonts = [fontManager availableMembersOfFontFamily:availableFamily];
     469    traitsMasks.reserveCapacity([fonts count]);
     470    for (NSArray *fontInfo in fonts) {
     471        // Array indices must be hard coded because of lame AppKit API.
     472        NSInteger fontWeight = [[fontInfo objectAtIndex:2] intValue];
     473        NSFontTraitMask fontTraits = [[fontInfo objectAtIndex:3] unsignedIntValue];
     474        traitsMasks.uncheckedAppend(toTraitsMask(fontTraits, fontWeight));
     475    }
    225476}
    226477
     
    231482    float size = fontDescription.computedPixelSize();
    232483
    233     NSFont *nsFont = [WebFontCache fontWithFamily:family traits:traits weight:weight size:size shouldAutoActivateIfNeeded:shouldAutoActivateFontIfNeeded(family)];
    234     if (!nsFont)
    235         return nullptr;
     484    NSFont *nsFont = fontWithFamily(family, traits, weight, size);
     485    if (!nsFont) {
     486        if (!shouldAutoActivateFontIfNeeded(family))
     487            return nullptr;
     488
     489        // Auto activate the font before looking for it a second time.
     490        // Ignore the result because we want to use our own algorithm to actually find the font.
     491        [NSFont fontWithName:family size:size];
     492
     493        nsFont = fontWithFamily(family, traits, weight, size);
     494        if (!nsFont)
     495            return nullptr;
     496    }
    236497
    237498    NSFontManager *fontManager = [NSFontManager sharedFontManager];
  • trunk/Source/WebKit/mac/ChangeLog

    r176145 r176146  
     12014-11-14  Myles C. Maxfield  <mmaxfield@apple.com>
     2
     3        Get rid of WebFontCache
     4        https://bugs.webkit.org/show_bug.cgi?id=134752
     5
     6        Reviewed by Dave Hyatt.
     7
     8        * WebView/WebHTMLView.mm:
     9
    1102014-11-14  Timothy Horton  <timothy_horton@apple.com>
    211
  • trunk/Source/WebKit/mac/WebView/WebHTMLView.mm

    r175954 r176146  
    136136#import "WebNSEventExtras.h"
    137137#import "WebNSPasteboardExtras.h"
    138 #import <WebCore/WebFontCache.h>
    139138#import <WebCore/PlatformEventFactoryMac.h>
    140139#endif
Note: See TracChangeset for help on using the changeset viewer.