| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "core/paint/SVGInlineTextBoxPainter.h" | 5 #include "core/paint/SVGInlineTextBoxPainter.h" |
| 6 | 6 |
| 7 #include "core/editing/Editor.h" | 7 #include "core/editing/Editor.h" |
| 8 #include "core/editing/markers/DocumentMarkerController.h" | 8 #include "core/editing/markers/DocumentMarkerController.h" |
| 9 #include "core/editing/markers/RenderedDocumentMarker.h" | 9 #include "core/editing/markers/RenderedDocumentMarker.h" |
| 10 #include "core/frame/LocalFrame.h" | 10 #include "core/frame/LocalFrame.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include "core/paint/SVGPaintContext.h" | 22 #include "core/paint/SVGPaintContext.h" |
| 23 #include "core/style/ShadowList.h" | 23 #include "core/style/ShadowList.h" |
| 24 #include "platform/graphics/GraphicsContextStateSaver.h" | 24 #include "platform/graphics/GraphicsContextStateSaver.h" |
| 25 | 25 |
| 26 namespace blink { | 26 namespace blink { |
| 27 | 27 |
| 28 static inline bool textShouldBePainted(const LayoutSVGInlineText& textLayoutObje
ct) | 28 static inline bool textShouldBePainted(const LayoutSVGInlineText& textLayoutObje
ct) |
| 29 { | 29 { |
| 30 // Font::pixelSize(), returns FontDescription::computedPixelSize(), which re
turns "int(x + 0.5)". | 30 // Font::pixelSize(), returns FontDescription::computedPixelSize(), which re
turns "int(x + 0.5)". |
| 31 // If the absolute font size on screen is below x=0.5, don't render anything
. | 31 // If the absolute font size on screen is below x=0.5, don't render anything
. |
| 32 return textLayoutObject.scaledFont().fontDescription().computedPixelSize(); | 32 return textLayoutObject.scaledFont().getFontDescription().computedPixelSize(
); |
| 33 } | 33 } |
| 34 | 34 |
| 35 bool SVGInlineTextBoxPainter::shouldPaintSelection(const PaintInfo& paintInfo) c
onst | 35 bool SVGInlineTextBoxPainter::shouldPaintSelection(const PaintInfo& paintInfo) c
onst |
| 36 { | 36 { |
| 37 return !paintInfo.isPrinting() && m_svgInlineTextBox.getSelectionState() !=
SelectionNone; | 37 return !paintInfo.isPrinting() && m_svgInlineTextBox.getSelectionState() !=
SelectionNone; |
| 38 } | 38 } |
| 39 | 39 |
| 40 void SVGInlineTextBoxPainter::paint(const PaintInfo& paintInfo, const LayoutPoin
t& paintOffset) | 40 void SVGInlineTextBoxPainter::paint(const PaintInfo& paintInfo, const LayoutPoin
t& paintOffset) |
| 41 { | 41 { |
| 42 ASSERT(paintInfo.phase == PaintPhaseForeground || paintInfo.phase == PaintPh
aseSelection); | 42 ASSERT(paintInfo.phase == PaintPhaseForeground || paintInfo.phase == PaintPh
aseSelection); |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 return fontMetrics.floatAscent() * 3 / 8.0f; | 211 return fontMetrics.floatAscent() * 3 / 8.0f; |
| 212 | 212 |
| 213 ASSERT_NOT_REACHED(); | 213 ASSERT_NOT_REACHED(); |
| 214 return 0.0f; | 214 return 0.0f; |
| 215 } | 215 } |
| 216 | 216 |
| 217 static inline float thicknessForDecoration(TextDecoration, const Font& font) | 217 static inline float thicknessForDecoration(TextDecoration, const Font& font) |
| 218 { | 218 { |
| 219 // FIXME: For SVG Fonts we need to use the attributes defined in the <font-f
ace> if specified. | 219 // FIXME: For SVG Fonts we need to use the attributes defined in the <font-f
ace> if specified. |
| 220 // Compatible with Batik/Presto | 220 // Compatible with Batik/Presto |
| 221 return font.fontDescription().computedSize() / 20.0f; | 221 return font.getFontDescription().computedSize() / 20.0f; |
| 222 } | 222 } |
| 223 | 223 |
| 224 void SVGInlineTextBoxPainter::paintDecoration(const PaintInfo& paintInfo, TextDe
coration decoration, const SVGTextFragment& fragment) | 224 void SVGInlineTextBoxPainter::paintDecoration(const PaintInfo& paintInfo, TextDe
coration decoration, const SVGTextFragment& fragment) |
| 225 { | 225 { |
| 226 if (m_svgInlineTextBox.getLineLayoutItem().style()->textDecorationsInEffect(
) == TextDecorationNone) | 226 if (m_svgInlineTextBox.getLineLayoutItem().style()->textDecorationsInEffect(
) == TextDecorationNone) |
| 227 return; | 227 return; |
| 228 | 228 |
| 229 if (fragment.width <= 0) | 229 if (fragment.width <= 0) |
| 230 return; | 230 return; |
| 231 | 231 |
| 232 // Find out which style defined the text-decoration, as its fill/stroke prop
erties have to be used for drawing instead of ours. | 232 // Find out which style defined the text-decoration, as its fill/stroke prop
erties have to be used for drawing instead of ours. |
| 233 LayoutObject* decorationLayoutObject = findLayoutObjectDefininingTextDecorat
ion(m_svgInlineTextBox.parent()); | 233 LayoutObject* decorationLayoutObject = findLayoutObjectDefininingTextDecorat
ion(m_svgInlineTextBox.parent()); |
| 234 const ComputedStyle& decorationStyle = decorationLayoutObject->styleRef(); | 234 const ComputedStyle& decorationStyle = decorationLayoutObject->styleRef(); |
| 235 | 235 |
| 236 if (decorationStyle.visibility() == HIDDEN) | 236 if (decorationStyle.visibility() == HIDDEN) |
| 237 return; | 237 return; |
| 238 | 238 |
| 239 float scalingFactor = 1; | 239 float scalingFactor = 1; |
| 240 Font scaledFont; | 240 Font scaledFont; |
| 241 LayoutSVGInlineText::computeNewScaledFontForStyle(decorationLayoutObject, sc
alingFactor, scaledFont); | 241 LayoutSVGInlineText::computeNewScaledFontForStyle(decorationLayoutObject, sc
alingFactor, scaledFont); |
| 242 ASSERT(scalingFactor); | 242 ASSERT(scalingFactor); |
| 243 | 243 |
| 244 float thickness = thicknessForDecoration(decoration, scaledFont); | 244 float thickness = thicknessForDecoration(decoration, scaledFont); |
| 245 if (thickness <= 0) | 245 if (thickness <= 0) |
| 246 return; | 246 return; |
| 247 | 247 |
| 248 float decorationOffset = baselineOffsetForDecoration(decoration, scaledFont.
fontMetrics(), thickness); | 248 float decorationOffset = baselineOffsetForDecoration(decoration, scaledFont.
getFontMetrics(), thickness); |
| 249 FloatPoint decorationOrigin(fragment.x, fragment.y - decorationOffset / scal
ingFactor); | 249 FloatPoint decorationOrigin(fragment.x, fragment.y - decorationOffset / scal
ingFactor); |
| 250 | 250 |
| 251 Path path; | 251 Path path; |
| 252 path.addRect(FloatRect(decorationOrigin, FloatSize(fragment.width, thickness
/ scalingFactor))); | 252 path.addRect(FloatRect(decorationOrigin, FloatSize(fragment.width, thickness
/ scalingFactor))); |
| 253 | 253 |
| 254 const SVGComputedStyle& svgDecorationStyle = decorationStyle.svgStyle(); | 254 const SVGComputedStyle& svgDecorationStyle = decorationStyle.svgStyle(); |
| 255 | 255 |
| 256 for (int i = 0; i < 3; i++) { | 256 for (int i = 0; i < 3; i++) { |
| 257 switch (svgDecorationStyle.paintOrderType(i)) { | 257 switch (svgDecorationStyle.paintOrderType(i)) { |
| 258 case PT_FILL: | 258 case PT_FILL: |
| 259 if (svgDecorationStyle.hasFill()) { | 259 if (svgDecorationStyle.hasFill()) { |
| 260 SkPaint fillPaint; | 260 SkPaint fillPaint; |
| 261 if (!SVGPaintContext::paintForLayoutObject(paintInfo, decoration
Style, *decorationLayoutObject, ApplyToFillMode, fillPaint)) | 261 if (!SVGPaintContext::paintForLayoutObject(paintInfo, decoration
Style, *decorationLayoutObject, ApplyToFillMode, fillPaint)) |
| 262 break; | 262 break; |
| 263 fillPaint.setAntiAlias(true); | 263 fillPaint.setAntiAlias(true); |
| 264 paintInfo.context.drawPath(path.skPath(), fillPaint); | 264 paintInfo.context.drawPath(path.getSkPath(), fillPaint); |
| 265 } | 265 } |
| 266 break; | 266 break; |
| 267 case PT_STROKE: | 267 case PT_STROKE: |
| 268 if (svgDecorationStyle.hasVisibleStroke()) { | 268 if (svgDecorationStyle.hasVisibleStroke()) { |
| 269 SkPaint strokePaint; | 269 SkPaint strokePaint; |
| 270 if (!SVGPaintContext::paintForLayoutObject(paintInfo, decoration
Style, *decorationLayoutObject, ApplyToStrokeMode, strokePaint)) | 270 if (!SVGPaintContext::paintForLayoutObject(paintInfo, decoration
Style, *decorationLayoutObject, ApplyToStrokeMode, strokePaint)) |
| 271 break; | 271 break; |
| 272 strokePaint.setAntiAlias(true); | 272 strokePaint.setAntiAlias(true); |
| 273 StrokeData strokeData; | 273 StrokeData strokeData; |
| 274 SVGLayoutSupport::applyStrokeStyleToStrokeData(strokeData, decor
ationStyle, *decorationLayoutObject, 1); | 274 SVGLayoutSupport::applyStrokeStyleToStrokeData(strokeData, decor
ationStyle, *decorationLayoutObject, 1); |
| 275 if (svgDecorationStyle.vectorEffect() == VE_NON_SCALING_STROKE) | 275 if (svgDecorationStyle.vectorEffect() == VE_NON_SCALING_STROKE) |
| 276 strokeData.setThickness(strokeData.thickness() / scalingFact
or); | 276 strokeData.setThickness(strokeData.thickness() / scalingFact
or); |
| 277 strokeData.setupPaint(&strokePaint); | 277 strokeData.setupPaint(&strokePaint); |
| 278 paintInfo.context.drawPath(path.skPath(), strokePaint); | 278 paintInfo.context.drawPath(path.getSkPath(), strokePaint); |
| 279 } | 279 } |
| 280 break; | 280 break; |
| 281 case PT_MARKERS: | 281 case PT_MARKERS: |
| 282 break; | 282 break; |
| 283 default: | 283 default: |
| 284 ASSERT_NOT_REACHED(); | 284 ASSERT_NOT_REACHED(); |
| 285 } | 285 } |
| 286 } | 286 } |
| 287 } | 287 } |
| 288 | 288 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 textOrigin.scale(scalingFactor, scalingFactor); | 345 textOrigin.scale(scalingFactor, scalingFactor); |
| 346 textSize.scale(scalingFactor); | 346 textSize.scale(scalingFactor); |
| 347 stateSaver.save(); | 347 stateSaver.save(); |
| 348 context.scale(1 / scalingFactor, 1 / scalingFactor); | 348 context.scale(1 / scalingFactor, 1 / scalingFactor); |
| 349 } | 349 } |
| 350 | 350 |
| 351 TextRunPaintInfo textRunPaintInfo(textRun); | 351 TextRunPaintInfo textRunPaintInfo(textRun); |
| 352 textRunPaintInfo.from = startPosition; | 352 textRunPaintInfo.from = startPosition; |
| 353 textRunPaintInfo.to = endPosition; | 353 textRunPaintInfo.to = endPosition; |
| 354 | 354 |
| 355 float baseline = scaledFont.fontMetrics().floatAscent(); | 355 float baseline = scaledFont.getFontMetrics().floatAscent(); |
| 356 textRunPaintInfo.bounds = FloatRect(textOrigin.x(), textOrigin.y() - baselin
e, | 356 textRunPaintInfo.bounds = FloatRect(textOrigin.x(), textOrigin.y() - baselin
e, |
| 357 textSize.width(), textSize.height()); | 357 textSize.width(), textSize.height()); |
| 358 | 358 |
| 359 context.drawText(scaledFont, textRunPaintInfo, textOrigin, paint); | 359 context.drawText(scaledFont, textRunPaintInfo, textOrigin, paint); |
| 360 } | 360 } |
| 361 | 361 |
| 362 void SVGInlineTextBoxPainter::paintText(const PaintInfo& paintInfo, const Comput
edStyle& style, | 362 void SVGInlineTextBoxPainter::paintText(const PaintInfo& paintInfo, const Comput
edStyle& style, |
| 363 const ComputedStyle& selectionStyle, const SVGTextFragment& fragment, | 363 const ComputedStyle& selectionStyle, const SVGTextFragment& fragment, |
| 364 LayoutSVGResourceMode resourceMode, bool shouldPaintSelection) | 364 LayoutSVGResourceMode resourceMode, bool shouldPaintSelection) |
| 365 { | 365 { |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 496 stateSaver.save(); | 496 stateSaver.save(); |
| 497 paintInfo.context.concatCTM(fragment.buildFragmentTransform()); | 497 paintInfo.context.concatCTM(fragment.buildFragmentTransform()); |
| 498 } | 498 } |
| 499 FloatRect fragmentRect = m_svgInlineTextBox.selectionRectForTextFragment
(fragment, textMatchInfo.startPosition, textMatchInfo.endPosition, style); | 499 FloatRect fragmentRect = m_svgInlineTextBox.selectionRectForTextFragment
(fragment, textMatchInfo.startPosition, textMatchInfo.endPosition, style); |
| 500 paintInfo.context.setFillColor(color); | 500 paintInfo.context.setFillColor(color); |
| 501 paintInfo.context.fillRect(fragmentRect); | 501 paintInfo.context.fillRect(fragmentRect); |
| 502 } | 502 } |
| 503 } | 503 } |
| 504 | 504 |
| 505 } // namespace blink | 505 } // namespace blink |
| OLD | NEW |