Title: [201777] trunk
Revision
201777
Author
[email protected]
Date
2016-06-07 17:06:28 -0700 (Tue, 07 Jun 2016)

Log Message

Text-decoration-style: dashed / dotted rendered as solid
https://bugs.webkit.org/show_bug.cgi?id=134336

Reviewed by Dean Jackson.

Source/WebCore:

We already had most of the infrastructure for dotted / dashed underlines.
Previously, we were setting the stroke style for the underlines, but then
filling the underlines (which means the stroke styles is irrelevant).
Instead, we should just compute the individual dots / dashes to fill.

The implementation of this is done inside GraphicsContext because
GraphicsContext is already responsible for handling the single / double
underline distinction. Extending it to be responsible for dotted / dashed
is the natural thing to do.

Tests: fast/css3-text/css3-text-decoration/text-decoration-dashed.html
       fast/css3-text/css3-text-decoration/text-decoration-dotted-dashed.html
       fast/css3-text/css3-text-decoration/text-decoration-dotted.html

* platform/graphics/GraphicsContext.h:
* platform/graphics/cairo/GraphicsContextCairo.cpp:
(WebCore::GraphicsContext::drawLineForText):
(WebCore::GraphicsContext::drawLinesForText):
* platform/graphics/cg/GraphicsContextCG.cpp:
(WebCore::GraphicsContext::drawLineForText):
(WebCore::GraphicsContext::drawLinesForText):
* rendering/TextDecorationPainter.cpp:
(WebCore::drawSkipInkUnderline):
(WebCore::TextDecorationPainter::paintTextDecoration):

LayoutTests:

Make sure that the dotted / dashed / solid renderings are all distinct.

* fast/css3-text/css3-text-decoration/text-decoration-dashed-expected-mismatch.html: Added.
* fast/css3-text/css3-text-decoration/text-decoration-dashed.html: Added.
* fast/css3-text/css3-text-decoration/text-decoration-dotted-dashed-expected-mismatch.html: Added.
* fast/css3-text/css3-text-decoration/text-decoration-dotted-dashed.html: Added.
* fast/css3-text/css3-text-decoration/text-decoration-dotted-expected-mismatch.html: Added.
* fast/css3-text/css3-text-decoration/text-decoration-dotted.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (201776 => 201777)


--- trunk/LayoutTests/ChangeLog	2016-06-07 23:45:53 UTC (rev 201776)
+++ trunk/LayoutTests/ChangeLog	2016-06-08 00:06:28 UTC (rev 201777)
@@ -1,3 +1,19 @@
+2016-06-07  Myles C. Maxfield  <[email protected]>
+
+        Text-decoration-style: dashed / dotted rendered as solid
+        https://bugs.webkit.org/show_bug.cgi?id=134336
+
+        Reviewed by Dean Jackson.
+
+        Make sure that the dotted / dashed / solid renderings are all distinct.
+
+        * fast/css3-text/css3-text-decoration/text-decoration-dashed-expected-mismatch.html: Added.
+        * fast/css3-text/css3-text-decoration/text-decoration-dashed.html: Added.
+        * fast/css3-text/css3-text-decoration/text-decoration-dotted-dashed-expected-mismatch.html: Added.
+        * fast/css3-text/css3-text-decoration/text-decoration-dotted-dashed.html: Added.
+        * fast/css3-text/css3-text-decoration/text-decoration-dotted-expected-mismatch.html: Added.
+        * fast/css3-text/css3-text-decoration/text-decoration-dotted.html: Added.
+
 2016-06-07  Ryan Haddad  <[email protected]>
 
         Skipping http/tests/websocket/tests/hybi/upgrade-simple-ws.html

Added: trunk/LayoutTests/fast/css3-text/css3-text-decoration/text-decoration-dashed-expected-mismatch.html (0 => 201777)


--- trunk/LayoutTests/fast/css3-text/css3-text-decoration/text-decoration-dashed-expected-mismatch.html	                        (rev 0)
+++ trunk/LayoutTests/fast/css3-text/css3-text-decoration/text-decoration-dashed-expected-mismatch.html	2016-06-08 00:06:28 UTC (rev 201777)
@@ -0,0 +1,8 @@
+<!DOCTYPE html>
+<html>
+<head>
+</head>
+<body>
+<div style="font-size: 40px; -webkit-text-decoration-style: solid; text-decoration: underline;">dotyedgdesc</div>
+</body>
+</html>
\ No newline at end of file

Added: trunk/LayoutTests/fast/css3-text/css3-text-decoration/text-decoration-dashed.html (0 => 201777)


--- trunk/LayoutTests/fast/css3-text/css3-text-decoration/text-decoration-dashed.html	                        (rev 0)
+++ trunk/LayoutTests/fast/css3-text/css3-text-decoration/text-decoration-dashed.html	2016-06-08 00:06:28 UTC (rev 201777)
@@ -0,0 +1,8 @@
+<!DOCTYPE html>
+<html>
+<head>
+</head>
+<body>
+<div style="font-size: 40px; -webkit-text-decoration-style: dashed; text-decoration: underline;">dotyedgdesc</div>
+</body>
+</html>
\ No newline at end of file

Added: trunk/LayoutTests/fast/css3-text/css3-text-decoration/text-decoration-dotted-dashed-expected-mismatch.html (0 => 201777)


--- trunk/LayoutTests/fast/css3-text/css3-text-decoration/text-decoration-dotted-dashed-expected-mismatch.html	                        (rev 0)
+++ trunk/LayoutTests/fast/css3-text/css3-text-decoration/text-decoration-dotted-dashed-expected-mismatch.html	2016-06-08 00:06:28 UTC (rev 201777)
@@ -0,0 +1,8 @@
+<!DOCTYPE html>
+<html>
+<head>
+</head>
+<body>
+<div style="font-size: 40px; -webkit-text-decoration-style: dashed; text-decoration: underline;">dotyedgdesc</div>
+</body>
+</html>
\ No newline at end of file

Added: trunk/LayoutTests/fast/css3-text/css3-text-decoration/text-decoration-dotted-dashed.html (0 => 201777)


--- trunk/LayoutTests/fast/css3-text/css3-text-decoration/text-decoration-dotted-dashed.html	                        (rev 0)
+++ trunk/LayoutTests/fast/css3-text/css3-text-decoration/text-decoration-dotted-dashed.html	2016-06-08 00:06:28 UTC (rev 201777)
@@ -0,0 +1,8 @@
+<!DOCTYPE html>
+<html>
+<head>
+</head>
+<body>
+<div style="font-size: 40px; -webkit-text-decoration-style: dotted; text-decoration: underline;">dotyedgdesc</div>
+</body>
+</html>
\ No newline at end of file

Added: trunk/LayoutTests/fast/css3-text/css3-text-decoration/text-decoration-dotted-expected-mismatch.html (0 => 201777)


--- trunk/LayoutTests/fast/css3-text/css3-text-decoration/text-decoration-dotted-expected-mismatch.html	                        (rev 0)
+++ trunk/LayoutTests/fast/css3-text/css3-text-decoration/text-decoration-dotted-expected-mismatch.html	2016-06-08 00:06:28 UTC (rev 201777)
@@ -0,0 +1,8 @@
+<!DOCTYPE html>
+<html>
+<head>
+</head>
+<body>
+<div style="font-size: 40px; -webkit-text-decoration-style: solid; text-decoration: underline;">dotyedgdesc</div>
+</body>
+</html>
\ No newline at end of file

Added: trunk/LayoutTests/fast/css3-text/css3-text-decoration/text-decoration-dotted.html (0 => 201777)


--- trunk/LayoutTests/fast/css3-text/css3-text-decoration/text-decoration-dotted.html	                        (rev 0)
+++ trunk/LayoutTests/fast/css3-text/css3-text-decoration/text-decoration-dotted.html	2016-06-08 00:06:28 UTC (rev 201777)
@@ -0,0 +1,8 @@
+<!DOCTYPE html>
+<html>
+<head>
+</head>
+<body>
+<div style="font-size: 40px; -webkit-text-decoration-style: dotted; text-decoration: underline;">dotyedgdesc</div>
+</body>
+</html>
\ No newline at end of file

Modified: trunk/Source/WebCore/ChangeLog (201776 => 201777)


--- trunk/Source/WebCore/ChangeLog	2016-06-07 23:45:53 UTC (rev 201776)
+++ trunk/Source/WebCore/ChangeLog	2016-06-08 00:06:28 UTC (rev 201777)
@@ -1,3 +1,35 @@
+2016-06-07  Myles C. Maxfield  <[email protected]>
+
+        Text-decoration-style: dashed / dotted rendered as solid
+        https://bugs.webkit.org/show_bug.cgi?id=134336
+
+        Reviewed by Dean Jackson.
+
+        We already had most of the infrastructure for dotted / dashed underlines.
+        Previously, we were setting the stroke style for the underlines, but then
+        filling the underlines (which means the stroke styles is irrelevant).
+        Instead, we should just compute the individual dots / dashes to fill.
+
+        The implementation of this is done inside GraphicsContext because
+        GraphicsContext is already responsible for handling the single / double
+        underline distinction. Extending it to be responsible for dotted / dashed
+        is the natural thing to do.
+
+        Tests: fast/css3-text/css3-text-decoration/text-decoration-dashed.html
+               fast/css3-text/css3-text-decoration/text-decoration-dotted-dashed.html
+               fast/css3-text/css3-text-decoration/text-decoration-dotted.html
+
+        * platform/graphics/GraphicsContext.h:
+        * platform/graphics/cairo/GraphicsContextCairo.cpp:
+        (WebCore::GraphicsContext::drawLineForText):
+        (WebCore::GraphicsContext::drawLinesForText):
+        * platform/graphics/cg/GraphicsContextCG.cpp:
+        (WebCore::GraphicsContext::drawLineForText):
+        (WebCore::GraphicsContext::drawLinesForText):
+        * rendering/TextDecorationPainter.cpp:
+        (WebCore::drawSkipInkUnderline):
+        (WebCore::TextDecorationPainter::paintTextDecoration):
+
 2016-06-07  Chris Fleizach  <[email protected]>
 
         AX: iOS: Need to expose whether object is a dialog element

Modified: trunk/Source/WebCore/platform/graphics/GraphicsContext.h (201776 => 201777)


--- trunk/Source/WebCore/platform/graphics/GraphicsContext.h	2016-06-07 23:45:53 UTC (rev 201776)
+++ trunk/Source/WebCore/platform/graphics/GraphicsContext.h	2016-06-08 00:06:28 UTC (rev 201777)
@@ -395,8 +395,8 @@
     FloatRect roundToDevicePixels(const FloatRect&, RoundingMode = RoundAllSides);
 
     FloatRect computeUnderlineBoundsForText(const FloatPoint&, float width, bool printing);
-    WEBCORE_EXPORT void drawLineForText(const FloatPoint&, float width, bool printing, bool doubleLines = false);
-    void drawLinesForText(const FloatPoint&, const DashArray& widths, bool printing, bool doubleLines = false);
+    WEBCORE_EXPORT void drawLineForText(const FloatPoint&, float width, bool printing, bool doubleLines = false, StrokeStyle = SolidStroke);
+    void drawLinesForText(const FloatPoint&, const DashArray& widths, bool printing, bool doubleLines = false, StrokeStyle = SolidStroke);
     enum DocumentMarkerLineStyle {
 #if PLATFORM(IOS)
         TextCheckingDictationPhraseWithAlternativesLineStyle,

Modified: trunk/Source/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp (201776 => 201777)


--- trunk/Source/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp	2016-06-07 23:45:53 UTC (rev 201776)
+++ trunk/Source/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp	2016-06-08 00:06:28 UTC (rev 201777)
@@ -643,7 +643,7 @@
     drawFocusRing(path, width, 0, color);
 }
 
-void GraphicsContext::drawLineForText(const FloatPoint& origin, float width, bool printing, bool doubleUnderlines)
+void GraphicsContext::drawLineForText(const FloatPoint& origin, float width, bool printing, bool doubleUnderlines, StrokeStyle)
 {
     DashArray widths;
     widths.append(width);
@@ -651,7 +651,7 @@
     drawLinesForText(origin, widths, printing, doubleUnderlines);
 }
 
-void GraphicsContext::drawLinesForText(const FloatPoint& point, const DashArray& widths, bool printing, bool doubleUnderlines)
+void GraphicsContext::drawLinesForText(const FloatPoint& point, const DashArray& widths, bool printing, bool doubleUnderlines, StrokeStyle)
 {
     if (paintingDisabled())
         return;

Modified: trunk/Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp (201776 => 201777)


--- trunk/Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp	2016-06-07 23:45:53 UTC (rev 201776)
+++ trunk/Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp	2016-06-08 00:06:28 UTC (rev 201777)
@@ -1479,15 +1479,15 @@
     return FloatRect(roundedOrigin, roundedLowerRight - roundedOrigin);
 }
 
-void GraphicsContext::drawLineForText(const FloatPoint& point, float width, bool printing, bool doubleLines)
+void GraphicsContext::drawLineForText(const FloatPoint& point, float width, bool printing, bool doubleLines, StrokeStyle strokeStyle)
 {
     DashArray widths;
     widths.append(width);
     widths.append(0);
-    drawLinesForText(point, widths, printing, doubleLines);
+    drawLinesForText(point, widths, printing, doubleLines, strokeStyle);
 }
 
-void GraphicsContext::drawLinesForText(const FloatPoint& point, const DashArray& widths, bool printing, bool doubleLines)
+void GraphicsContext::drawLinesForText(const FloatPoint& point, const DashArray& widths, bool printing, bool doubleLines, StrokeStyle strokeStyle)
 {
     if (paintingDisabled())
         return;
@@ -1508,9 +1508,33 @@
     Vector<CGRect, 4> dashBounds;
     ASSERT(!(widths.size() % 2));
     dashBounds.reserveInitialCapacity(dashBounds.size() / 2);
-    for (size_t i = 0; i < widths.size(); i += 2)
-        dashBounds.append(CGRectMake(bounds.x() + widths[i], bounds.y(), widths[i+1] - widths[i], bounds.height()));
 
+    float dashWidth = 0;
+    switch (strokeStyle) {
+    case DottedStroke:
+        dashWidth = bounds.height();
+        break;
+    case DashedStroke:
+        dashWidth = 2 * bounds.height();
+        break;
+    case SolidStroke:
+    default:
+        break;
+    }
+
+    for (size_t i = 0; i < widths.size(); i += 2) {
+        auto left = widths[i];
+        auto width = widths[i+1] - widths[i];
+        if (!dashWidth)
+            dashBounds.append(CGRectMake(bounds.x() + left, bounds.y(), width, bounds.height()));
+        else {
+            auto startParticle = static_cast<unsigned>(std::ceil(left / (2 * dashWidth)));
+            auto endParticle = static_cast<unsigned>((left + width) / (2 * dashWidth));
+            for (unsigned j = startParticle; j < endParticle; ++j)
+                dashBounds.append(CGRectMake(bounds.x() + j * 2 * dashWidth, bounds.y(), dashWidth, bounds.height()));
+        }
+    }
+
     if (doubleLines) {
         // The space between double underlines is equal to the height of the underline
         for (size_t i = 0; i < widths.size(); i += 2)

Modified: trunk/Source/WebCore/rendering/TextDecorationPainter.cpp (201776 => 201777)


--- trunk/Source/WebCore/rendering/TextDecorationPainter.cpp	2016-06-07 23:45:53 UTC (rev 201776)
+++ trunk/Source/WebCore/rendering/TextDecorationPainter.cpp	2016-06-08 00:06:28 UTC (rev 201777)
@@ -202,7 +202,7 @@
 }
 
 static void drawSkipInkUnderline(GraphicsContext& context, const FontCascade& font, const TextRun& textRun, const FloatPoint& textOrigin, const FloatPoint& localOrigin,
-    float underlineOffset, float width, bool isPrinting, bool doubleLines)
+    float underlineOffset, float width, bool isPrinting, bool doubleLines, StrokeStyle strokeStyle)
 {
     FloatPoint adjustedLocalOrigin = localOrigin;
     adjustedLocalOrigin.move(0, underlineOffset);
@@ -210,7 +210,7 @@
     DashArray intersections = font.dashesForIntersectionsWithRect(textRun, textOrigin, underlineBoundingBox);
     DashArray a = translateIntersectionPointsToSkipInkBoundaries(intersections, underlineBoundingBox.height(), width);
     ASSERT(!(a.size() % 2));
-    context.drawLinesForText(adjustedLocalOrigin, a, isPrinting, doubleLines);
+    context.drawLinesForText(adjustedLocalOrigin, a, isPrinting, doubleLines, strokeStyle);
 }
 #endif
 
@@ -267,7 +267,6 @@
     auto paintDecoration = [&](TextDecoration decoration, TextDecorationStyle style, Color color, StrokeStyle strokeStyle,
         const FloatPoint& start, const FloatPoint& end, int offset) {
         m_context.setStrokeColor(color);
-        m_context.setStrokeStyle(strokeStyle);
 
         if (style == TextDecorationStyleWavy)
             strokeWavyTextDecoration(m_context, start, end, textDecorationThickness);
@@ -275,15 +274,15 @@
 #if ENABLE(CSS3_TEXT_DECORATION_SKIP_INK)
             if ((m_lineStyle.textDecorationSkip() == TextDecorationSkipInk || m_lineStyle.textDecorationSkip() == TextDecorationSkipAuto) && m_isHorizontal) {
                 if (!m_context.paintingDisabled())
-                    drawSkipInkUnderline(m_context, *m_font, textRun, textOrigin, localOrigin, offset, m_width, m_isPrinting, style == TextDecorationStyleDouble);
+                    drawSkipInkUnderline(m_context, *m_font, textRun, textOrigin, localOrigin, offset, m_width, m_isPrinting, style == TextDecorationStyleDouble, strokeStyle);
             } else
                 // FIXME: Need to support text-decoration-skip: none.
 #endif
-                m_context.drawLineForText(start, m_width, m_isPrinting, style == TextDecorationStyleDouble);
+                m_context.drawLineForText(start, m_width, m_isPrinting, style == TextDecorationStyleDouble, strokeStyle);
             
         } else {
             ASSERT(decoration == TextDecorationLineThrough);
-            m_context.drawLineForText(start, m_width, m_isPrinting, style == TextDecorationStyleDouble);
+            m_context.drawLineForText(start, m_width, m_isPrinting, style == TextDecorationStyleDouble, strokeStyle);
         }
     };
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to