From ca9cb53ed1119a3fd98fafa0972ffeb56dee1c24 Mon Sep 17 00:00:00 2001 From: Steve Block Date: Thu, 8 Jul 2010 12:51:48 +0100 Subject: Merge WebKit at r62496: Initial merge by git Change-Id: Ie3da0770eca22a70a632e3571f31cfabc80facb2 --- WebCore/rendering/SVGInlineTextBox.cpp | 67 ++++++++++++++++++++-------------- 1 file changed, 40 insertions(+), 27 deletions(-) (limited to 'WebCore/rendering/SVGInlineTextBox.cpp') diff --git a/WebCore/rendering/SVGInlineTextBox.cpp b/WebCore/rendering/SVGInlineTextBox.cpp index 68b4fd0..8e498ad 100644 --- a/WebCore/rendering/SVGInlineTextBox.cpp +++ b/WebCore/rendering/SVGInlineTextBox.cpp @@ -124,8 +124,9 @@ int SVGInlineTextBox::offsetForPosition(int xCoordinate, bool includePartialGlyp m_currentChunkPart = SVGTextChunkPart(); // Eventually handle lengthAdjust="spacingAndGlyphs". + // FIXME: Need to revisit the whole offsetForPosition concept for vertical text selection. if (!m_chunkTransformation.isIdentity()) - textRun.setGlyphScale(narrowPrecisionToFloat(isVerticalWritingMode(style->svgStyle()) ? m_chunkTransformation.d() : m_chunkTransformation.a())); + textRun.setHorizontalGlyphStretch(narrowPrecisionToFloat(m_chunkTransformation.a())); return hitPart.offset + style->font().offsetForPosition(textRun, x, includePartialGlyphs); } @@ -189,9 +190,9 @@ IntRect SVGInlineTextBox::selectionRect(int, int, int startPos, int endPos) return enclosingIntRect(m_chunkTransformation.mapRect(selectionRect)); } -void SVGInlineTextBox::paint(RenderObject::PaintInfo& paintInfo, int, int) +void SVGInlineTextBox::paint(PaintInfo& paintInfo, int, int) { - ASSERT(renderer()->shouldPaintWithinRoot(paintInfo)); + ASSERT(paintInfo.shouldPaintWithinRoot(renderer())); ASSERT(paintInfo.phase == PaintPhaseForeground || paintInfo.phase == PaintPhaseSelection); ASSERT(truncation() == cNoTruncation); @@ -562,6 +563,35 @@ void SVGInlineTextBox::paintSelection(GraphicsContext* context, const FloatPoint context->restore(); } +void SVGInlineTextBox::paintTextWithShadows(GraphicsContext* context, const FloatPoint& textOrigin, RenderStyle* style, TextRun& textRun, int startPos, int endPos) +{ + const Font& font = style->font(); + const ShadowData* shadow = style->textShadow(); + + FloatRect shadowRect(FloatPoint(textOrigin.x(), textOrigin.y() - font.ascent()), FloatSize(m_currentChunkPart.width, m_currentChunkPart.height)); + do { + if (!prepareGraphicsContextForTextPainting(context, textRun, style)) + break; + + FloatSize extraOffset; + if (shadow) + extraOffset = applyShadowToGraphicsContext(context, shadow, shadowRect, false /* stroked */, true /* opaque */); + + font.drawText(context, textRun, textOrigin + extraOffset, startPos, endPos); + restoreGraphicsContextAfterTextPainting(context, textRun); + + if (!shadow) + break; + + if (shadow->next()) + context->restore(); + else + context->clearShadow(); + + shadow = shadow->next(); + } while (shadow); +} + void SVGInlineTextBox::paintText(GraphicsContext* context, const FloatPoint& textOrigin, RenderStyle* style, RenderStyle* selectionStyle, bool hasSelection, bool paintSelectedTextOnly) { ASSERT(style); @@ -572,41 +602,24 @@ void SVGInlineTextBox::paintText(GraphicsContext* context, const FloatPoint& tex int endPos = 0; selectionStartEnd(startPos, endPos); - const Font& font = style->font(); - TextRun textRun(constructTextRun(style)); - // Fast path if there is no selection, just draw the whole chunk part using the regular style + TextRun textRun(constructTextRun(style)); if (!hasSelection || startPos >= endPos) { - if (prepareGraphicsContextForTextPainting(context, textRun, style)) { - font.drawText(context, textRun, textOrigin, 0, m_currentChunkPart.length); - restoreGraphicsContextAfterTextPainting(context, textRun); - } - + paintTextWithShadows(context, textOrigin, style, textRun, 0, m_currentChunkPart.length); return; } // Eventually draw text using regular style until the start position of the selection - if (startPos > 0 && !paintSelectedTextOnly) { - if (prepareGraphicsContextForTextPainting(context, textRun, style)) { - font.drawText(context, textRun, textOrigin, 0, startPos); - restoreGraphicsContextAfterTextPainting(context, textRun); - } - } + if (startPos > 0 && !paintSelectedTextOnly) + paintTextWithShadows(context, textOrigin, style, textRun, 0, startPos); // Draw text using selection style from the start to the end position of the selection TextRun selectionTextRun(constructTextRun(selectionStyle)); - if (prepareGraphicsContextForTextPainting(context, selectionTextRun, selectionStyle)) { - selectionStyle->font().drawText(context, selectionTextRun, textOrigin, startPos, endPos); - restoreGraphicsContextAfterTextPainting(context, selectionTextRun); - } + paintTextWithShadows(context, textOrigin, selectionStyle, textRun, startPos, endPos); // Eventually draw text using regular style from the end position of the selection to the end of the current chunk part - if (endPos < m_currentChunkPart.length && !paintSelectedTextOnly) { - if (prepareGraphicsContextForTextPainting(context, textRun, style)) { - font.drawText(context, textRun, textOrigin, endPos, m_currentChunkPart.length); - restoreGraphicsContextAfterTextPainting(context, textRun); - } - } + if (endPos < m_currentChunkPart.length && !paintSelectedTextOnly) + paintTextWithShadows(context, textOrigin, style, textRun, endPos, m_currentChunkPart.length); } void SVGInlineTextBox::buildLayoutInformation(SVGCharacterLayoutInfo& info, SVGLastGlyphInfo& lastGlyph) -- cgit v1.1