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

Changeset 167773 in webkit


Ignore:
Timestamp:
Apr 24, 2014, 2:20:54 PM (12 years ago)
Author:
mmaxfield@apple.com
Message:

Unify platformWidthForGlyph across OS X and iOS
https://bugs.webkit.org/show_bug.cgi?id=132036

Reviewed by Darin Adler.

This patch creates on shared SimpleFontData::platformWidthForGlyph() function for both OS X and iOS.

No new tests are necessary because there should be no behavior changes.

  • platform/graphics/SimpleFontData.h: Signatures for two helper functions
  • platform/graphics/ios/SimpleFontDataIOS.mm: Replace iOS implementation of platformWidthForGlyph() with

implementations of only the two helper functions
(WebCore::SimpleFontData::getRenderingStyle): Compute style argument to CGFontGetGlyphAdvancesForStyle()
(WebCore::SimpleFontData::advanceForColorBitmapFont): iOS doesn't have color bitmap fonts
(WebCore::SimpleFontData::platformWidthForGlyph): Deleted.

  • platform/graphics/mac/SimpleFontDataMac.mm:

(WebCore::SimpleFontData::getRenderingStyle): Compute style argument to CGFontGetGlyphAdvancesForStyle()
(WebCore::SimpleFontData::advanceForColorBitmapFont): Use [NSFont advancementForGlyph] to compute the advance
(WebCore::hasCustomTracking): Removed #if
(WebCore::isEmoji): Only relevant on iOS
(WebCore::SimpleFontData::platformWidthForGlyph): Shared implementation. Calls helper functions.

Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r167771 r167773  
     12014-04-24  Myles C. Maxfield  <mmaxfield@apple.com>
     2
     3        Unify platformWidthForGlyph across OS X and iOS
     4        https://bugs.webkit.org/show_bug.cgi?id=132036
     5
     6        Reviewed by Darin Adler.
     7
     8        This patch creates on shared SimpleFontData::platformWidthForGlyph() function for both OS X and iOS.
     9
     10        No new tests are necessary because there should be no behavior changes.
     11
     12        * platform/graphics/SimpleFontData.h: Signatures for two helper functions
     13        * platform/graphics/ios/SimpleFontDataIOS.mm: Replace iOS implementation of platformWidthForGlyph() with
     14        implementations of only the two helper functions
     15        (WebCore::SimpleFontData::getRenderingStyle): Compute style argument to CGFontGetGlyphAdvancesForStyle()
     16        (WebCore::SimpleFontData::advanceForColorBitmapFont): iOS doesn't have color bitmap fonts
     17        (WebCore::SimpleFontData::platformWidthForGlyph): Deleted.
     18        * platform/graphics/mac/SimpleFontDataMac.mm:
     19        (WebCore::SimpleFontData::getRenderingStyle): Compute style argument to CGFontGetGlyphAdvancesForStyle()
     20        (WebCore::SimpleFontData::advanceForColorBitmapFont): Use [NSFont advancementForGlyph] to compute the advance
     21        (WebCore::hasCustomTracking): Removed #if
     22        (WebCore::isEmoji): Only relevant on iOS
     23        (WebCore::SimpleFontData::platformWidthForGlyph): Shared implementation. Calls helper functions.
     24
    1252014-04-24  Zalan Bujtas  <zalan@apple.com>
    226
  • trunk/Source/WebCore/platform/graphics/SimpleFontData.h

    r166633 r167773  
    5353#if USE(CAIRO)
    5454#include <cairo.h>
     55#endif
     56
     57#if USE(CG)
     58#if defined(__has_include) && __has_include(<CoreGraphics/CGFontRendering.h>)
     59#include <CoreGraphics/CGFontRendering.h>
     60#else
     61enum {
     62    kCGFontRenderingStyleAntialiasing = (1 << 0),
     63    kCGFontRenderingStyleSmoothing = (1 << 1),
     64    kCGFontRenderingStyleSubpixelPositioning = (1 << 2),
     65    kCGFontRenderingStyleSubpixelQuantization = (1 << 3),
     66    kCGFontRenderingStylePlatformNative = (1 << 9),
     67    kCGFontRenderingStyleMask = 0x20F
     68};
     69#endif
     70typedef uint32_t CGFontRenderingStyle;
    5571#endif
    5672
     
    246262#endif
    247263
     264#if USE(CG)
     265    bool canUseFastGlyphAdvanceGetter(Glyph glyph, CGSize& advance, bool& populatedAdvance) const;
     266    CGFontRenderingStyle renderingStyle() const;
     267    bool advanceForColorBitmapFont(Glyph, CGSize& result) const; // Returns true if the font is a color bitmap font
     268#endif
     269
    248270    FontMetrics m_fontMetrics;
    249271    float m_maxCharWidth;
  • trunk/Source/WebCore/platform/graphics/ios/SimpleFontDataIOS.mm

    r167768 r167773  
    3333#import "FontDescription.h"
    3434#import "FontServicesIOS.h"
    35 #import <CoreGraphics/CGFontGlyphSupport.h>
    3635#import <CoreGraphics/CGFontInfo.h>
    37 #import <CoreGraphics/CGFontRendering.h>
    3836#import <CoreText/CoreText.h>
    3937#import <float.h>
     
    188186}
    189187
    190 float SimpleFontData::platformWidthForGlyph(Glyph glyph) const
     188CGFontRenderingStyle SimpleFontData::renderingStyle() const
    191189{
    192     CGSize advance = CGSizeZero;
    193     if (platformData().orientation() == Horizontal || m_isBrokenIdeographFallback) {
    194         if (platformData().m_isEmoji)
    195             CTFontGetAdvancesForGlyphs(m_platformData.ctFont(), kCTFontHorizontalOrientation, &glyph, &advance, 1);
    196         else {
    197             float pointSize = platformData().m_size;
    198             CGAffineTransform transform = CGAffineTransformMakeScale(pointSize, pointSize);
    199             static const CGFontRenderingStyle renderingStyle = kCGFontRenderingStyleAntialiasing | kCGFontRenderingStyleSubpixelPositioning | kCGFontRenderingStyleSubpixelQuantization | kCGFontAntialiasingStyleUnfiltered;
    200             if (!CGFontGetGlyphAdvancesForStyle(platformData().cgFont(), &transform, renderingStyle, &glyph, 1, &advance)) {
    201                 RetainPtr<CFStringRef> fullName = adoptCF(CGFontCopyFullName(platformData().cgFont()));
    202                 LOG_ERROR("Unable to cache glyph widths for %@ %f", fullName.get(), pointSize);
    203                 advance.width = 0;
    204             }
    205         }
    206     } else
    207         CTFontGetAdvancesForGlyphs(m_platformData.ctFont(), kCTFontVerticalOrientation, &glyph, &advance, 1);
     190    return kCGFontRenderingStyleAntialiasing | kCGFontRenderingStyleSubpixelPositioning | kCGFontRenderingStyleSubpixelQuantization | kCGFontAntialiasingStyleUnfiltered;
     191}
    208192
    209     return advance.width + m_syntheticBoldOffset;
     193bool SimpleFontData::advanceForColorBitmapFont(Glyph, CGSize&) const
     194{
     195    return false;
    210196}
    211197
  • trunk/Source/WebCore/platform/graphics/mac/SimpleFontDataMac.mm

    r167768 r167773  
    5151#import <CoreText/CTFontDescriptorPriv.h>
    5252#endif
    53 
    5453extern "C" bool CTFontDescriptorIsSystemUIFont(CTFontDescriptorRef);
     54
     55#if defined(__has_include) && __has_include(<CoreGraphics/CGFontGlyphSupport.h>)
     56#import <CoreGraphics/CGFontGlyphSupport.h>
     57#endif
     58extern "C" bool CGFontGetGlyphAdvancesForStyle(CGFontRef font,
     59    const CGAffineTransform *t, CGFontRenderingStyle style,
     60    const CGGlyph glyphs[], size_t count, CGSize advances[]);
    5561
    5662#if !PLATFORM(IOS)
     
    366372}
    367373
    368 #if !PLATFORM(IOS)
     374#if PLATFORM(MAC)
     375inline CGFontRenderingStyle SimpleFontData::renderingStyle() const
     376{
     377    CGFontRenderingStyle style = kCGFontRenderingStyleAntialiasing | kCGFontRenderingStyleSubpixelPositioning | kCGFontRenderingStyleSubpixelQuantization;
     378    NSFont *font = platformData().font();
     379    if (font) {
     380        switch ([font renderingMode]) {
     381        case NSFontIntegerAdvancementsRenderingMode:
     382            style = 0;
     383            break;
     384        case NSFontAntialiasedIntegerAdvancementsRenderingMode:
     385            style = kCGFontRenderingStyleAntialiasing;
     386            break;
     387        default:
     388            break;
     389        }
     390    }
     391    return style;
     392}
     393
     394inline bool SimpleFontData::advanceForColorBitmapFont(Glyph glyph, CGSize& advance) const
     395{
     396    NSFont *font = platformData().font();
     397    if (!font || !platformData().isColorBitmapFont())
     398        return false;
     399    advance = NSSizeToCGSize([font advancementForGlyph:glyph]);
     400    return true;
     401}
     402#endif
     403
    369404static bool hasCustomTracking(CTFontRef font)
    370405{
    371 #if __MAC_OS_X_VERSION_MIN_REQUIRED < 1090
     406#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED < 1090
    372407    UNUSED_PARAM(font);
    373408    return false;
     
    377412}
    378413
     414static inline bool isEmoji(const FontPlatformData& platformData)
     415{
     416#if PLATFORM(IOS)
     417    return platformData.m_isEmoji;
     418#else
     419    UNUSED_PARAM(platformData);
     420    return false;
     421#endif
     422}
     423
     424inline bool SimpleFontData::canUseFastGlyphAdvanceGetter(Glyph glyph, CGSize& advance, bool& populatedAdvance) const
     425{
     426    // Fast getter doesn't take custom tracking into account
     427    if (hasCustomTracking(platformData().ctFont()))
     428        return false;
     429    // Fast getter doesn't work for emoji
     430    if (isEmoji(platformData()))
     431        return false;
     432    // ... or for any bitmap fonts in general
     433    if (advanceForColorBitmapFont(glyph, advance)) {
     434        populatedAdvance = true;
     435        return false;
     436    }
     437    return true;
     438}
     439
    379440float SimpleFontData::platformWidthForGlyph(Glyph glyph) const
    380441{
    381442    CGSize advance = CGSizeZero;
    382443    bool horizontal = platformData().orientation() == Horizontal;
    383     if ((horizontal || m_isBrokenIdeographFallback) && !hasCustomTracking(m_platformData.ctFont())) {
    384         NSFont *font = platformData().font();
    385         if (font && platformData().isColorBitmapFont())
    386             advance = NSSizeToCGSize([font advancementForGlyph:glyph]);
    387         else {
    388             float pointSize = platformData().m_size;
    389             CGAffineTransform m = CGAffineTransformMakeScale(pointSize, pointSize);
    390             if (!wkGetGlyphTransformedAdvances(platformData().cgFont(), font, &m, &glyph, &advance)) {
    391                 LOG_ERROR("Unable to cache glyph widths for %@ %f", [font displayName], pointSize);
    392                 advance.width = 0;
    393             }
     444    bool populatedAdvance = false;
     445    if ((horizontal || m_isBrokenIdeographFallback) && canUseFastGlyphAdvanceGetter(glyph, advance, populatedAdvance)) {
     446        float pointSize = platformData().m_size;
     447        CGAffineTransform m = CGAffineTransformMakeScale(pointSize, pointSize);
     448        if (!CGFontGetGlyphAdvancesForStyle(platformData().cgFont(), &m, renderingStyle(), &glyph, 1, &advance)) {
     449            RetainPtr<CFStringRef> fullName = adoptCF(CGFontCopyFullName(platformData().cgFont()));
     450            LOG_ERROR("Unable to cache glyph widths for %@ %f", fullName.get(), pointSize);
     451            advance.width = 0;
    394452        }
    395     } else
     453    } else if (!populatedAdvance)
    396454        CTFontGetAdvancesForGlyphs(m_platformData.ctFont(), horizontal ? kCTFontHorizontalOrientation : kCTFontVerticalOrientation, &glyph, &advance, 1);
    397455
    398456    return advance.width + m_syntheticBoldOffset;
    399457}
    400 #endif // !PLATFORM(IOS)
    401458
    402459struct ProviderInfo {
Note: See TracChangeset for help on using the changeset viewer.