Changeset 182898 in webkit


Ignore:
Timestamp:
Apr 16, 2015, 11:47:53 AM (11 years ago)
Author:
Simon Fraser
Message:

Pull emoji-position adjustment code into its own function
https://bugs.webkit.org/show_bug.cgi?id=143592

Reviewed by Myles C. Maxfield.

First step to cleaning up FontCascade::drawGlyphs(). Pull iOS-only code related to
emoji positioning into its own function.

  • platform/graphics/cocoa/FontCascadeCocoa.mm:

(WebCore::pointAdjustedForEmoji):
(WebCore::FontCascade::drawGlyphs):

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r182894 r182898  
     12015-04-15  Simon Fraser  <simon.fraser@apple.com>
     2
     3        Pull emoji-position adjustment code into its own function
     4        https://bugs.webkit.org/show_bug.cgi?id=143592
     5
     6        Reviewed by Myles C. Maxfield.
     7
     8        First step to cleaning up FontCascade::drawGlyphs(). Pull iOS-only code related to
     9        emoji positioning into its own function.
     10
     11        * platform/graphics/cocoa/FontCascadeCocoa.mm:
     12        (WebCore::pointAdjustedForEmoji):
     13        (WebCore::FontCascade::drawGlyphs):
     14
    1152015-04-16  Myles C. Maxfield  <mmaxfield@apple.com>
    216
  • trunk/Source/WebCore/platform/graphics/cocoa/FontCascadeCocoa.mm

    r182824 r182898  
    224224#endif
    225225
     226static FloatPoint pointAdjustedForEmoji(const FontPlatformData& platformData, FloatPoint point)
     227{
     228#if PLATFORM(IOS)
     229    if (!platformData.m_isEmoji)
     230        return point;
     231
     232    // Mimic the positioining of non-bitmap glyphs, which are not subpixel-positioned.
     233    point.setY(ceilf(point.y()));
     234
     235    // Emoji glyphs snap to the CSS pixel grid.
     236    point.setX(floorf(point.x()));
     237
     238    // Emoji glyphs are offset one CSS pixel to the right.
     239    point.move(1, 0);
     240
     241    // Emoji glyphs are offset vertically based on font size.
     242    float fontSize = platformData.size();
     243    float y = point.y();
     244    if (fontSize <= 15) {
     245        // Undo Core Text's y adjustment.
     246        static float yAdjustmentFactor = iosExecutableWasLinkedOnOrAfterVersion(wkIOSSystemVersion_6_0) ? .19 : .1;
     247        point.setY(floorf(y - yAdjustmentFactor * (fontSize + 2) + 2));
     248    } else {
     249        if (fontSize < 26)
     250            y -= .35f * fontSize - 10;
     251
     252        // Undo Core Text's y adjustment.
     253        static float yAdjustment = iosExecutableWasLinkedOnOrAfterVersion(wkIOSSystemVersion_6_0) ? 3.8 : 2;
     254        point.setY(floorf(y - yAdjustment));
     255    }
     256#else
     257    UNUSED_PARAM(platformData);
     258#endif
     259    return point;
     260}
     261
    226262void FontCascade::drawGlyphs(GraphicsContext* context, const Font* font, const GlyphBuffer& glyphBuffer, int from, int numGlyphs, const FloatPoint& anchorPoint) const
    227263{
     
    298334
    299335    bool useLetterpressEffect = shouldUseLetterpressEffect(*context);
    300     FloatPoint point = anchorPoint;
     336    FloatPoint point = pointAdjustedForEmoji(platformData, anchorPoint);
     337
    301338#if PLATFORM(IOS)
    302339    float fontSize = platformData.size();
    303340    CGAffineTransform matrix = useLetterpressEffect || platformData.isColorBitmapFont() ? CGAffineTransformIdentity : CGAffineTransformMakeScale(fontSize, fontSize);
    304     if (platformData.m_isEmoji) {
    305         // Mimic the positioining of non-bitmap glyphs, which are not subpixel-positioned.
    306         point.setY(ceilf(point.y()));
    307 
    308         // Emoji glyphs snap to the CSS pixel grid.
    309         point.setX(floorf(point.x()));
    310 
    311         // Emoji glyphs are offset one CSS pixel to the right.
    312         point.move(1, 0);
    313 
    314         // Emoji glyphs are offset vertically based on font size.
    315         float y = point.y();
    316         if (fontSize <= 15) {
    317             // Undo Core Text's y adjustment.
    318             static float yAdjustmentFactor = iosExecutableWasLinkedOnOrAfterVersion(wkIOSSystemVersion_6_0) ? .19 : .1;
    319             point.setY(floorf(y - yAdjustmentFactor * (fontSize + 2) + 2));
    320         } else {
    321             if (fontSize < 26)
    322                 y -= .35f * fontSize - 10;
    323 
    324             // Undo Core Text's y adjustment.
    325             static float yAdjustment = iosExecutableWasLinkedOnOrAfterVersion(wkIOSSystemVersion_6_0) ? 3.8 : 2;
    326             point.setY(floorf(y - yAdjustment));
    327         }
    328     }
    329341#else
    330342    CGAffineTransform matrix = CGAffineTransformIdentity;
Note: See TracChangeset for help on using the changeset viewer.