Changeset 200807 in webkit


Ignore:
Timestamp:
May 12, 2016 6:55:40 PM (8 years ago)
Author:
mmaxfield@apple.com
Message:

Source/WebCore:
[Cocoa] Text shadow sometimes clipped unexpectedly
https://bugs.webkit.org/show_bug.cgi?id=108929

Reviewed by Dean Jackson.

CoreGraphics can only draw one text shadow at a time. We work around that by drawing
the text multiple times, one for each shadow. However, we want to make sure that the
original text isn't also drawn multiple times, so we bump up the shadow offsets so
the text and the shadow don't intersect, and then we clip out the original text (so
only the shadow remains).

Unfortunately, this clipping requires knowing where the visual extent of the text is,
which WebKit currently has trouble with. In particular, we often use layout extents
in lieu of visual extents, which is a problem when the glyphs draw outside of their
layout boxes. In this case, it causes us to think the text shadow is much smaller
than it really is, so our clipping operation clips to an area which is too small.

A quick solution to this is to inflate the clip rect by an amount proportional to the
font size, and offset the text shadow accordingly. If this amount is large enough,
this bug will occur on few enough sites that it is reasonable to consider this bug
fixed without the real solution of educating WebKit properly about the difference
between text layout rects and text visual extent rects.

Test: fast/text/multiple-text-shadow-overflow-layout-rect.html

  • rendering/TextPainter.cpp:

(WebCore::ShadowApplier::ShadowApplier):

LayoutTests:
Text shadow sometimes clipped unexpectedly
https://bugs.webkit.org/show_bug.cgi?id=108929

Reviewed by Dean Jackson.

Add a font which draws dramatically far outside of its layout rect.

  • fast/text/multiple-text-shadow-overflow-layout-rect-expected.html: Added.
  • fast/text/multiple-text-shadow-overflow-layout-rect.html: Added.
  • fast/text/resources/font-overflow-layout-rect.svg: Added.
Location:
trunk
Files:
3 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r200804 r200807  
     12016-05-12  Myles C. Maxfield  <mmaxfield@apple.com>
     2
     3        Text shadow sometimes clipped unexpectedly
     4        https://bugs.webkit.org/show_bug.cgi?id=108929
     5
     6        Reviewed by Dean Jackson.
     7
     8        Add a font which draws dramatically far outside of its layout rect.
     9
     10        * fast/text/multiple-text-shadow-overflow-layout-rect-expected.html: Added.
     11        * fast/text/multiple-text-shadow-overflow-layout-rect.html: Added.
     12        * fast/text/resources/font-overflow-layout-rect.svg: Added.
     13
    1142016-05-12  Ryan Haddad  <ryanhaddad@apple.com>
    215
  • trunk/Source/WebCore/ChangeLog

    r200803 r200807  
     12016-05-12  Myles C. Maxfield  <mmaxfield@apple.com>
     2
     3        [Cocoa] Text shadow sometimes clipped unexpectedly
     4        https://bugs.webkit.org/show_bug.cgi?id=108929
     5
     6        Reviewed by Dean Jackson.
     7
     8        CoreGraphics can only draw one text shadow at a time. We work around that by drawing
     9        the text multiple times, one for each shadow. However, we want to make sure that the
     10        original text isn't also drawn multiple times, so we bump up the shadow offsets so
     11        the text and the shadow don't intersect, and then we clip out the original text (so
     12        only the shadow remains).
     13
     14        Unfortunately, this clipping requires knowing where the visual extent of the text is,
     15        which WebKit currently has trouble with. In particular, we often use layout extents
     16        in lieu of visual extents, which is a problem when the glyphs draw outside of their
     17        layout boxes. In this case, it causes us to think the text shadow is much smaller
     18        than it really is, so our clipping operation clips to an area which is too small.
     19
     20        A quick solution to this is to inflate the clip rect by an amount proportional to the
     21        font size, and offset the text shadow accordingly. If this amount is large enough,
     22        this bug will occur on few enough sites that it is reasonable to consider this bug
     23        fixed without the real solution of educating WebKit properly about the difference
     24        between text layout rects and text visual extent rects.
     25
     26        Test: fast/text/multiple-text-shadow-overflow-layout-rect.html
     27
     28        * rendering/TextPainter.cpp:
     29        (WebCore::ShadowApplier::ShadowApplier):
     30
    1312016-05-12  Myles C. Maxfield  <mmaxfield@apple.com>
    232
  • trunk/Source/WebCore/rendering/TextPainter.cpp

    r199304 r200807  
    5555    if (m_onlyDrawsShadow) {
    5656        FloatRect shadowRect(textRect);
    57         shadowRect.inflate(shadow->paintingExtent());
     57        shadowRect.inflate(shadow->paintingExtent() + 3 * textRect.height());
    5858        shadowRect.move(shadowOffset);
    5959        context.save();
     
    6161
    6262        m_didSaveContext = true;
    63         m_extraOffset = FloatSize(0, 2 * textRect.height() + std::max(0.0f, shadowOffset.height()) + shadowRadius);
     63        m_extraOffset = FloatSize(0, 2 * shadowRect.height() + std::max(0.0f, shadowOffset.height()) + shadowRadius);
    6464        shadowOffset -= m_extraOffset;
    6565    }
Note: See TracChangeset for help on using the changeset viewer.