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 "config.h" | 5 #include "config.h" |
6 #include "core/paint/SVGInlineTextBoxPainter.h" | 6 #include "core/paint/SVGInlineTextBoxPainter.h" |
7 | 7 |
8 #include "core/dom/DocumentMarkerController.h" | 8 #include "core/dom/DocumentMarkerController.h" |
9 #include "core/dom/RenderedDocumentMarker.h" | 9 #include "core/dom/RenderedDocumentMarker.h" |
10 #include "core/editing/Editor.h" | 10 #include "core/editing/Editor.h" |
11 #include "core/frame/LocalFrame.h" | 11 #include "core/frame/LocalFrame.h" |
12 #include "core/layout/LayoutInline.h" | 12 #include "core/layout/LayoutInline.h" |
13 #include "core/layout/LayoutTheme.h" | 13 #include "core/layout/LayoutTheme.h" |
14 #include "core/layout/PaintInfo.h" | 14 #include "core/layout/PaintInfo.h" |
15 #include "core/style/ShadowList.h" | 15 #include "core/style/ShadowList.h" |
16 #include "core/layout/svg/LayoutSVGInlineText.h" | 16 #include "core/layout/svg/LayoutSVGInlineText.h" |
17 #include "core/layout/svg/SVGLayoutSupport.h" | 17 #include "core/layout/svg/SVGLayoutSupport.h" |
18 #include "core/layout/svg/SVGResourcesCache.h" | 18 #include "core/layout/svg/SVGResourcesCache.h" |
19 #include "core/layout/svg/line/SVGInlineTextBox.h" | 19 #include "core/layout/svg/line/SVGInlineTextBox.h" |
20 #include "core/paint/InlinePainter.h" | 20 #include "core/paint/InlinePainter.h" |
21 #include "core/paint/InlineTextBoxPainter.h" | 21 #include "core/paint/InlineTextBoxPainter.h" |
22 #include "core/paint/LayoutObjectDrawingRecorder.h" | 22 #include "core/paint/LayoutObjectDrawingRecorder.h" |
| 23 #include "core/paint/SVGPaintContext.h" |
23 | 24 |
24 namespace blink { | 25 namespace blink { |
25 | 26 |
26 static inline bool textShouldBePainted(LayoutSVGInlineText& textRenderer) | 27 static inline bool textShouldBePainted(LayoutSVGInlineText& textRenderer) |
27 { | 28 { |
28 // Font::pixelSize(), returns FontDescription::computedPixelSize(), which re
turns "int(x + 0.5)". | 29 // Font::pixelSize(), returns FontDescription::computedPixelSize(), which re
turns "int(x + 0.5)". |
29 // If the absolute font size on screen is below x=0.5, don't render anything
. | 30 // If the absolute font size on screen is below x=0.5, don't render anything
. |
30 return textRenderer.scaledFont().fontDescription().computedPixelSize(); | 31 return textRenderer.scaledFont().fontDescription().computedPixelSize(); |
31 } | 32 } |
32 | 33 |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 | 262 |
262 Path path; | 263 Path path; |
263 path.addRect(FloatRect(decorationOrigin, FloatSize(fragment.width, thickness
/ scalingFactor))); | 264 path.addRect(FloatRect(decorationOrigin, FloatSize(fragment.width, thickness
/ scalingFactor))); |
264 | 265 |
265 const SVGComputedStyle& svgDecorationStyle = decorationStyle.svgStyle(); | 266 const SVGComputedStyle& svgDecorationStyle = decorationStyle.svgStyle(); |
266 | 267 |
267 for (int i = 0; i < 3; i++) { | 268 for (int i = 0; i < 3; i++) { |
268 switch (svgDecorationStyle.paintOrderType(i)) { | 269 switch (svgDecorationStyle.paintOrderType(i)) { |
269 case PT_FILL: | 270 case PT_FILL: |
270 if (svgDecorationStyle.hasFill()) { | 271 if (svgDecorationStyle.hasFill()) { |
271 GraphicsContextStateSaver stateSaver(*paintInfo.context, false); | 272 SkPaint fillPaint; |
272 if (!SVGLayoutSupport::updateGraphicsContext(paintInfo, stateSav
er, decorationStyle, *decorationRenderer, ApplyToFillMode)) | 273 if (!SVGPaintContext::paintForLayoutObject(paintInfo, decoration
Style, *decorationRenderer, ApplyToFillMode, fillPaint)) |
273 break; | 274 break; |
274 paintInfo.context->fillPath(path); | 275 fillPaint.setAntiAlias(true); |
| 276 paintInfo.context->drawPath(path.skPath(), fillPaint); |
275 } | 277 } |
276 break; | 278 break; |
277 case PT_STROKE: | 279 case PT_STROKE: |
278 if (svgDecorationStyle.hasVisibleStroke()) { | 280 if (svgDecorationStyle.hasVisibleStroke()) { |
279 // FIXME: Non-scaling stroke is not applied here. | 281 // FIXME: Non-scaling stroke is not applied here. |
280 GraphicsContextStateSaver stateSaver(*paintInfo.context, false); | 282 SkPaint strokePaint; |
281 if (!SVGLayoutSupport::updateGraphicsContext(paintInfo, stateSav
er, decorationStyle, *decorationRenderer, ApplyToStrokeMode)) | 283 if (!SVGPaintContext::paintForLayoutObject(paintInfo, decoration
Style, *decorationRenderer, ApplyToStrokeMode, strokePaint)) |
282 break; | 284 break; |
283 paintInfo.context->strokePath(path); | 285 strokePaint.setAntiAlias(true); |
| 286 StrokeData strokeData; |
| 287 SVGLayoutSupport::applyStrokeStyleToStrokeData(strokeData, decor
ationStyle, *decorationRenderer); |
| 288 strokeData.setupPaint(&strokePaint); |
| 289 paintInfo.context->drawPath(path.skPath(), strokePaint); |
284 } | 290 } |
285 break; | 291 break; |
286 case PT_MARKERS: | 292 case PT_MARKERS: |
287 break; | 293 break; |
288 default: | 294 default: |
289 ASSERT_NOT_REACHED(); | 295 ASSERT_NOT_REACHED(); |
290 } | 296 } |
291 } | 297 } |
292 } | 298 } |
293 | 299 |
(...skipping 23 matching lines...) Expand all Loading... |
317 textOrigin.scale(scalingFactor, scalingFactor); | 323 textOrigin.scale(scalingFactor, scalingFactor); |
318 textSize.scale(scalingFactor); | 324 textSize.scale(scalingFactor); |
319 stateSaver.save(); | 325 stateSaver.save(); |
320 context->scale(1 / scalingFactor, 1 / scalingFactor); | 326 context->scale(1 / scalingFactor, 1 / scalingFactor); |
321 // Adjust the paint-server coordinate space. | 327 // Adjust the paint-server coordinate space. |
322 paintServerTransform.scale(scalingFactor); | 328 paintServerTransform.scale(scalingFactor); |
323 additionalPaintServerTransform = &paintServerTransform; | 329 additionalPaintServerTransform = &paintServerTransform; |
324 } | 330 } |
325 | 331 |
326 // FIXME: Non-scaling stroke is not applied here. | 332 // FIXME: Non-scaling stroke is not applied here. |
327 | 333 SkPaint paint; |
328 if (!SVGLayoutSupport::updateGraphicsContext(paintInfo, stateSaver, style, m
_svgInlineTextBox.parent()->layoutObject(), resourceMode, additionalPaintServerT
ransform)) | 334 if (!SVGPaintContext::paintForLayoutObject(paintInfo, style, m_svgInlineText
Box.parent()->layoutObject(), resourceMode, paint, additionalPaintServerTransfor
m)) |
329 return; | 335 return; |
| 336 paint.setAntiAlias(true); |
330 | 337 |
331 if (hasShadow) { | 338 if (hasShadow) { |
332 stateSaver.saveIfNeeded(); | 339 OwnPtr<DrawLooperBuilder> drawLooperBuilder = shadowList->createDrawLoop
er(DrawLooperBuilder::ShadowRespectsAlpha); |
333 context->setDrawLooper(shadowList->createDrawLooper(DrawLooperBuilder::S
hadowRespectsAlpha)); | 340 RefPtr<SkDrawLooper> drawLooper = drawLooperBuilder->detachDrawLooper(); |
| 341 paint.setLooper(drawLooper.get()); |
334 } | 342 } |
335 | 343 |
336 context->setTextDrawingMode(resourceMode == ApplyToFillMode ? TextModeFill :
TextModeStroke); | 344 if (resourceMode == ApplyToStrokeMode) { |
337 | 345 StrokeData strokeData; |
338 if (scalingFactor != 1 && resourceMode == ApplyToStrokeMode) | 346 SVGLayoutSupport::applyStrokeStyleToStrokeData(strokeData, style, m_svgI
nlineTextBox.parent()->layoutObject()); |
339 context->setStrokeThickness(context->strokeThickness() * scalingFactor); | 347 strokeData.setThickness(strokeData.thickness() * scalingFactor); |
| 348 strokeData.setupPaint(&paint); |
| 349 } |
340 | 350 |
341 TextRunPaintInfo textRunPaintInfo(textRun); | 351 TextRunPaintInfo textRunPaintInfo(textRun); |
342 textRunPaintInfo.from = startPosition; | 352 textRunPaintInfo.from = startPosition; |
343 textRunPaintInfo.to = endPosition; | 353 textRunPaintInfo.to = endPosition; |
344 | 354 |
345 float baseline = scaledFont.fontMetrics().floatAscent(); | 355 float baseline = scaledFont.fontMetrics().floatAscent(); |
346 textRunPaintInfo.bounds = FloatRect(textOrigin.x(), textOrigin.y() - baselin
e, | 356 textRunPaintInfo.bounds = FloatRect(textOrigin.x(), textOrigin.y() - baselin
e, |
347 textSize.width(), textSize.height()); | 357 textSize.width(), textSize.height()); |
348 | 358 |
349 context->drawText(scaledFont, textRunPaintInfo, textOrigin); | 359 context->drawText(scaledFont, textRunPaintInfo, textOrigin, paint); |
350 } | 360 } |
351 | 361 |
352 void SVGInlineTextBoxPainter::paintText(const PaintInfo& paintInfo, const Comput
edStyle& style, | 362 void SVGInlineTextBoxPainter::paintText(const PaintInfo& paintInfo, const Comput
edStyle& style, |
353 const ComputedStyle& selectionStyle, const SVGTextFragment& fragment, | 363 const ComputedStyle& selectionStyle, const SVGTextFragment& fragment, |
354 LayoutSVGResourceMode resourceMode, bool shouldPaintSelection) | 364 LayoutSVGResourceMode resourceMode, bool shouldPaintSelection) |
355 { | 365 { |
356 int startPosition = 0; | 366 int startPosition = 0; |
357 int endPosition = 0; | 367 int endPosition = 0; |
358 if (shouldPaintSelection) { | 368 if (shouldPaintSelection) { |
359 m_svgInlineTextBox.selectionStartEnd(startPosition, endPosition); | 369 m_svgInlineTextBox.selectionStartEnd(startPosition, endPosition); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 | 451 |
442 fragmentRect = fragmentTransform.mapRect(fragmentRect); | 452 fragmentRect = fragmentTransform.mapRect(fragmentRect); |
443 markerRect.unite(fragmentRect); | 453 markerRect.unite(fragmentRect); |
444 } | 454 } |
445 } | 455 } |
446 | 456 |
447 toRenderedDocumentMarker(marker)->setRenderedRect(LayoutRect(textRenderer.lo
calToAbsoluteQuad(markerRect).enclosingBoundingBox())); | 457 toRenderedDocumentMarker(marker)->setRenderedRect(LayoutRect(textRenderer.lo
calToAbsoluteQuad(markerRect).enclosingBoundingBox())); |
448 } | 458 } |
449 | 459 |
450 } // namespace blink | 460 } // namespace blink |
OLD | NEW |