⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 281792 in webkit


Ignore:
Timestamp:
Aug 31, 2021, 12:18:14 AM (5 years ago)
Author:
mmaxfield@apple.com
Message:

[Cocoa] Drawing system fallback fonts to canvas causes a crash
​https://bugs.webkit.org/show_bug.cgi?id=229633
<rdar://problem/81889036>

Reviewed by Wenson Hsieh.

Source/WebCore/PAL:

  • pal/spi/cf/CoreTextSPI.h:

Source/WebKit:

Dot-prefixed font names don't survive the round-trip through
CTFontDescriptorCopyAttributes(CTFontCopyFontDescriptor(font)) unless you also
pass in the kCTFontOptionsSystemUIFont option.

Tests: fast/text/system-fallback-canvas.html

fast/text/draw-synthetic-system-bold-font-into-canvas.html

  • Shared/Cocoa/WebCoreArgumentCodersCocoa.mm:

(IPC::createCTFont):
(IPC::ArgumentCoder<Ref<WebCore::Font>>::decodePlatformData):

LayoutTests:

  • fast/text/system-fallback-canvas-expected.txt: Added.
  • fast/text/system-fallback-canvas.html: Added.
Location:
trunk
Files:
4 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r281784 r281792  
     12021-08-31  Myles C. Maxfield  <mmaxfield@apple.com>
     2
     3        [Cocoa] Drawing system fallback fonts to canvas causes a crash
     4        https://bugs.webkit.org/show_bug.cgi?id=229633
     5        <rdar://problem/81889036>
     6
     7        Reviewed by Wenson Hsieh.
     8
     9        * fast/text/system-fallback-canvas-expected.txt: Added.
     10        * fast/text/system-fallback-canvas.html: Added.
     11
    1122021-08-30  Megan Gardner  <megan_gardner@apple.com>
    213
  • trunk/Source/WebCore/PAL/ChangeLog

    r281791 r281792  
     12021-08-31  Myles C. Maxfield  <mmaxfield@apple.com>
     2
     3        [Cocoa] Drawing system fallback fonts to canvas causes a crash
     4        https://bugs.webkit.org/show_bug.cgi?id=229633
     5        <rdar://problem/81889036>
     6
     7        Reviewed by Wenson Hsieh.
     8
     9        * pal/spi/cf/CoreTextSPI.h:
     10
    1112021-08-26  Darin Adler  <darin@apple.com>
    212
  • trunk/Source/WebCore/PAL/pal/spi/cf/CoreTextSPI.h

    r278151 r281792  
    6060
    6161enum {
     62    kCTFontOptionsSystemUIFont = 1 << 1,
     63};
     64
     65enum {
    6266    kCTRunStatusHasOrigins = (1 << 4),
    6367};
    … …  
    149153bool CTFontDescriptorIsSystemUIFont(CTFontDescriptorRef);
    150154bool CTFontIsSystemUIFont(CTFontRef);
     155CTFontRef CTFontCreateWithFontDescriptorAndOptions(CTFontDescriptorRef, CGFloat size, const CGAffineTransform*, CTFontOptions);
    151156CTFontRef CTFontCreateForCSS(CFStringRef name, uint16_t weight, CTFontSymbolicTraits, CGFloat size);
    152157CTFontRef CTFontCreateForCharactersWithLanguage(CTFontRef currentFont, const UTF16Char *characters, CFIndex length, CFStringRef language, CFIndex *coveredLength);
  • trunk/Source/WebKit/ChangeLog

    r281791 r281792  
     12021-08-31  Myles C. Maxfield  <mmaxfield@apple.com>
     2
     3        [Cocoa] Drawing system fallback fonts to canvas causes a crash
     4        https://bugs.webkit.org/show_bug.cgi?id=229633
     5        <rdar://problem/81889036>
     6
     7        Reviewed by Wenson Hsieh.
     8
     9        Dot-prefixed font names don't survive the round-trip through
     10        CTFontDescriptorCopyAttributes(CTFontCopyFontDescriptor(font)) unless you also
     11        pass in the kCTFontOptionsSystemUIFont option.
     12
     13        Tests: fast/text/system-fallback-canvas.html
     14               fast/text/draw-synthetic-system-bold-font-into-canvas.html
     15
     16        * Shared/Cocoa/WebCoreArgumentCodersCocoa.mm:
     17        (IPC::createCTFont):
     18        (IPC::ArgumentCoder<Ref<WebCore::Font>>::decodePlatformData):
     19
    1202021-08-26  Darin Adler  <darin@apple.com>
    221
  • trunk/Source/WebKit/Shared/Cocoa/WebCoreArgumentCodersCocoa.mm

    r279750 r281792  
    502502}
    503503
     504static RetainPtr<CTFontRef> createCTFont(CFDictionaryRef attributes, float size, const String& referenceURL, const String& postScriptName)
     505{
     506    if (auto name = static_cast<CFStringRef>(CFDictionaryGetValue(attributes, kCTFontNameAttribute))) {
     507        if (CFStringHasPrefix(name, CFSTR("."))) {
     508            auto fontDescriptor = adoptCF(CTFontDescriptorCreateWithAttributes(attributes));
     509            if (!fontDescriptor)
     510                return nullptr;
     511            return adoptCF(CTFontCreateWithFontDescriptorAndOptions(fontDescriptor.get(), size, nullptr, kCTFontOptionsSystemUIFont));
     512        }
     513    }
     514
     515    auto fontDescriptor = findFontDescriptor(referenceURL, postScriptName);
     516    if (!fontDescriptor)
     517        return nullptr;
     518    fontDescriptor = adoptCF(CTFontDescriptorCreateCopyWithAttributes(fontDescriptor.get(), attributes));
     519    return adoptCF(CTFontCreateWithFontDescriptor(fontDescriptor.get(), size, nullptr));
     520}
     521
    504522std::optional<WebCore::FontPlatformData> ArgumentCoder<Ref<WebCore::Font>>::decodePlatformData(Decoder& decoder)
    505523{
    … …  
    581599        return std::nullopt;
    582600
    583     auto fontDescriptor = findFontDescriptor(*referenceURL, *postScriptName);
    584     if (!fontDescriptor)
    585         return std::nullopt;
    586     fontDescriptor = adoptCF(CTFontDescriptorCreateCopyWithAttributes(fontDescriptor.get(), attributes->get()));
    587     auto ctFont = adoptCF(CTFontCreateWithFontDescriptor(fontDescriptor.get(), *size, nullptr));
     601    auto ctFont = createCTFont(attributes->get(), *size, *referenceURL, *postScriptName);
     602    if (!ctFont)
     603        return std::nullopt;
    588604
    589605    return WebCore::FontPlatformData(ctFont.get(), *size, *syntheticBold, *syntheticOblique, *orientation, *widthVariant, *textRenderingMode);
Note: See TracChangeset for help on using the changeset viewer.