Text-shadow with (0, 0) offset and radius = 0 is ugly
[WebKit-https.git] / Source / WebCore / rendering / TextPainter.cpp
index fe8549cc55fe83235943f10315fd58b76e622159..78e73e196ceae7ee679e3ac7ef39bdd3c52917d0 100644 (file)
@@ -60,6 +60,13 @@ static void drawTextOrEmphasisMarks(GraphicsContext& context, const Font& font,
         context.drawEmphasisMarks(font, textRun, emphasisMark, point + IntSize(0, emphasisMarkOffset), from, to);
 }
 
         context.drawEmphasisMarks(font, textRun, emphasisMark, point + IntSize(0, emphasisMarkOffset), from, to);
 }
 
+static bool isEmptyShadow(const ShadowData* shadowPtr)
+{
+    if (!shadowPtr)
+        return true;
+    return shadow->location() == IntPoint() && !shadow->radius();
+}
+
 static void paintTextWithShadows(GraphicsContext* context, const Font& font, const TextRun& textRun, const AtomicString& emphasisMark,
     int emphasisMarkOffset, int startOffset, int endOffset, int truncationPoint, const FloatPoint& textOrigin, const FloatRect& boxRect,
     const ShadowData* shadow, bool stroked, bool horizontal)
 static void paintTextWithShadows(GraphicsContext* context, const Font& font, const TextRun& textRun, const AtomicString& emphasisMark,
     int emphasisMarkOffset, int startOffset, int endOffset, int truncationPoint, const FloatPoint& textOrigin, const FloatRect& boxRect,
     const ShadowData* shadow, bool stroked, bool horizontal)
@@ -72,7 +79,8 @@ static void paintTextWithShadows(GraphicsContext* context, const Font& font, con
 
     do {
         IntSize extraOffset;
 
     do {
         IntSize extraOffset;
-        if (shadow)
+        bool shadowIsEmpty = isEmptyShadow(shadow);
+        if (!shadowIsEmpty)
             extraOffset = roundedIntSize(InlineTextBox::applyShadowToGraphicsContext(context, shadow, boxRect, stroked, opaque, horizontal));
         else if (!opaque)
             context->setFillColor(fillColor, fillColorSpace);
             extraOffset = roundedIntSize(InlineTextBox::applyShadowToGraphicsContext(context, shadow, boxRect, stroked, opaque, horizontal));
         else if (!opaque)
             context->setFillColor(fillColor, fillColorSpace);
@@ -91,7 +99,7 @@ static void paintTextWithShadows(GraphicsContext* context, const Font& font, con
 
         if (shadow->next() || stroked || !opaque)
             context->restore();
 
         if (shadow->next() || stroked || !opaque)
             context->restore();
-        else
+        else if (!shadowIsEmpty)
             context->clearShadow();
 
         shadow = shadow->next();
             context->clearShadow();
 
         shadow = shadow->next();
@@ -120,7 +128,7 @@ void TextPainter::paintText()
         if (!m_emphasisMark.isEmpty()) {
             updateGraphicsContext(*m_savedDrawingStateForMask.m_context, *m_savedDrawingStateForMask.m_textPaintStyle, UseEmphasisMarkColor);
 
         if (!m_emphasisMark.isEmpty()) {
             updateGraphicsContext(*m_savedDrawingStateForMask.m_context, *m_savedDrawingStateForMask.m_textPaintStyle, UseEmphasisMarkColor);
 
-            DEFINE_STATIC_LOCAL(TextRun, objectReplacementCharacterTextRun, (&objectReplacementCharacter, 1));
+            DEPRECATED_DEFINE_STATIC_LOCAL(TextRun, objectReplacementCharacterTextRun, (&objectReplacementCharacter, 1));
             TextRun& emphasisMarkTextRun = m_combinedText ? objectReplacementCharacterTextRun : m_textRun;
             FloatPoint emphasisMarkTextOrigin = m_combinedText ? FloatPoint(boxOrigin.x() + m_boxRect.width() / 2, boxOrigin.y() + m_font.fontMetrics().ascent()) : m_textOrigin;
             if (m_combinedText)
             TextRun& emphasisMarkTextRun = m_combinedText ? objectReplacementCharacterTextRun : m_textRun;
             FloatPoint emphasisMarkTextOrigin = m_combinedText ? FloatPoint(boxOrigin.x() + m_boxRect.width() / 2, boxOrigin.y() + m_font.fontMetrics().ascent()) : m_textOrigin;
             if (m_combinedText)
@@ -146,7 +154,7 @@ void TextPainter::paintText()
         if (!m_emphasisMark.isEmpty()) {
             updateGraphicsContext(*m_savedDrawingStateForMask.m_context, *m_savedDrawingStateForMask.m_selectionPaintStyle, UseEmphasisMarkColor);
 
         if (!m_emphasisMark.isEmpty()) {
             updateGraphicsContext(*m_savedDrawingStateForMask.m_context, *m_savedDrawingStateForMask.m_selectionPaintStyle, UseEmphasisMarkColor);
 
-            DEFINE_STATIC_LOCAL(TextRun, objectReplacementCharacterTextRun, (&objectReplacementCharacter, 1));
+            DEPRECATED_DEFINE_STATIC_LOCAL(TextRun, objectReplacementCharacterTextRun, (&objectReplacementCharacter, 1));
             TextRun& emphasisMarkTextRun = m_combinedText ? objectReplacementCharacterTextRun : m_textRun;
             FloatPoint emphasisMarkTextOrigin = m_combinedText ? FloatPoint(boxOrigin.x() + m_boxRect.width() / 2, boxOrigin.y() + m_font.fontMetrics().ascent()) : m_textOrigin;
             if (m_combinedText)
             TextRun& emphasisMarkTextRun = m_combinedText ? objectReplacementCharacterTextRun : m_textRun;
             FloatPoint emphasisMarkTextOrigin = m_combinedText ? FloatPoint(boxOrigin.x() + m_boxRect.width() / 2, boxOrigin.y() + m_font.fontMetrics().ascent()) : m_textOrigin;
             if (m_combinedText)
@@ -176,4 +184,11 @@ void TextPainter::paintTextInContext(GraphicsContext& context, float amountToInc
     m_savedDrawingStateForMask = savedDrawingStateForMask;
 }
 
     m_savedDrawingStateForMask = savedDrawingStateForMask;
 }
 
+#if ENABLE(CSS3_TEXT_DECORATION_SKIP_INK)
+DashArray TextPainter::dashesForIntersectionsWithRect(const FloatRect& lineExtents)
+{
+    return m_font.dashesForIntersectionsWithRect(m_textRun, m_textOrigin, lineExtents);
+}
+#endif
+
 } // namespace WebCore
 } // namespace WebCore