Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2007, 2008 Rob Buis <buis@kde.org> | 2 * Copyright (C) 2007, 2008 Rob Buis <buis@kde.org> |
| 3 * Copyright (C) 2007 Nikolas Zimmermann <zimmermann@kde.org> | 3 * Copyright (C) 2007 Nikolas Zimmermann <zimmermann@kde.org> |
| 4 * Copyright (C) 2007 Eric Seidel <eric@webkit.org> | 4 * Copyright (C) 2007 Eric Seidel <eric@webkit.org> |
| 5 * Copyright (C) 2009 Google, Inc. All rights reserved. | 5 * Copyright (C) 2009 Google, Inc. All rights reserved. |
| 6 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org> | 6 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org> |
| 7 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved. | 7 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved. |
| 8 * | 8 * |
| 9 * This library is free software; you can redistribute it and/or | 9 * This library is free software; you can redistribute it and/or |
| 10 * modify it under the terms of the GNU Library General Public | 10 * modify it under the terms of the GNU Library General Public |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 32 #include "core/rendering/RenderLayer.h" | 32 #include "core/rendering/RenderLayer.h" |
| 33 #include "core/rendering/SubtreeLayoutScope.h" | 33 #include "core/rendering/SubtreeLayoutScope.h" |
| 34 #include "core/rendering/svg/RenderSVGInlineText.h" | 34 #include "core/rendering/svg/RenderSVGInlineText.h" |
| 35 #include "core/rendering/svg/RenderSVGResourceClipper.h" | 35 #include "core/rendering/svg/RenderSVGResourceClipper.h" |
| 36 #include "core/rendering/svg/RenderSVGResourceFilter.h" | 36 #include "core/rendering/svg/RenderSVGResourceFilter.h" |
| 37 #include "core/rendering/svg/RenderSVGResourceMasker.h" | 37 #include "core/rendering/svg/RenderSVGResourceMasker.h" |
| 38 #include "core/rendering/svg/RenderSVGRoot.h" | 38 #include "core/rendering/svg/RenderSVGRoot.h" |
| 39 #include "core/rendering/svg/RenderSVGShape.h" | 39 #include "core/rendering/svg/RenderSVGShape.h" |
| 40 #include "core/rendering/svg/RenderSVGText.h" | 40 #include "core/rendering/svg/RenderSVGText.h" |
| 41 #include "core/rendering/svg/RenderSVGViewportContainer.h" | 41 #include "core/rendering/svg/RenderSVGViewportContainer.h" |
| 42 #include "core/rendering/svg/SVGRenderingContext.h" | |
| 42 #include "core/rendering/svg/SVGResources.h" | 43 #include "core/rendering/svg/SVGResources.h" |
| 43 #include "core/rendering/svg/SVGResourcesCache.h" | 44 #include "core/rendering/svg/SVGResourcesCache.h" |
| 44 #include "core/svg/SVGElement.h" | 45 #include "core/svg/SVGElement.h" |
| 45 #include "platform/geometry/TransformState.h" | 46 #include "platform/geometry/TransformState.h" |
| 46 #include "platform/graphics/Path.h" | 47 #include "platform/graphics/Path.h" |
| 47 | 48 |
| 48 namespace blink { | 49 namespace blink { |
| 49 | 50 |
| 50 LayoutRect SVGRenderSupport::clippedOverflowRectForPaintInvalidation(const Rende rObject* object, const RenderLayerModelObject* paintInvalidationContainer, const PaintInvalidationState* paintInvalidationState) | 51 LayoutRect SVGRenderSupport::clippedOverflowRectForPaintInvalidation(const Rende rObject* object, const RenderLayerModelObject* paintInvalidationContainer, const PaintInvalidationState* paintInvalidationState) |
| 51 { | 52 { |
| (...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 387 return; | 388 return; |
| 388 | 389 |
| 389 DashArray dashArray; | 390 DashArray dashArray; |
| 390 size_t length = dashes->length(); | 391 size_t length = dashes->length(); |
| 391 for (size_t i = 0; i < length; ++i) | 392 for (size_t i = 0; i < length; ++i) |
| 392 dashArray.append(dashes->at(i)->value(lengthContext)); | 393 dashArray.append(dashes->at(i)->value(lengthContext)); |
| 393 | 394 |
| 394 strokeData->setLineDash(dashArray, svgStyle.strokeDashOffset()->value(length Context)); | 395 strokeData->setLineDash(dashArray, svgStyle.strokeDashOffset()->value(length Context)); |
| 395 } | 396 } |
| 396 | 397 |
| 398 static bool shouldTransformOnTextPainting(RenderObject& renderer, AffineTransfor m& resourceTransform) | |
|
fs
2014/10/14 13:49:17
Will remove these three functions in the next CL.
pdr.
2014/10/14 23:38:48
SGTM.
Nit: The crazy comment below (... "Cmp. Ren
| |
| 399 { | |
| 400 // This method should only be called for RenderObjects that deal with text r endering. Cmp. RenderObject.h's is*() methods. | |
| 401 ASSERT(renderer.isSVGText() || renderer.isSVGTextPath() || renderer.isSVGInl ine()); | |
| 402 | |
| 403 // In text drawing, the scaling part of the graphics context CTM is removed, compare SVGInlineTextBox::paintTextWithShadows. | |
| 404 // So, we use that scaling factor here, too, and then push it down to patter n or gradient space | |
| 405 // in order to keep the pattern or gradient correctly scaled. | |
| 406 float scalingFactor = SVGRenderingContext::calculateScreenFontSizeScalingFac tor(&renderer); | |
| 407 if (scalingFactor == 1) | |
| 408 return false; | |
| 409 resourceTransform.scale(scalingFactor); | |
| 410 return true; | |
| 411 } | |
| 412 | |
| 413 static AffineTransform transformOnNonScalingStroke(RenderObject& renderer, const AffineTransform& resourceTransform) | |
| 414 { | |
| 415 ASSERT(renderer.isSVGShape()); | |
| 416 SVGGraphicsElement* element = toSVGGraphicsElement(renderer.node()); | |
| 417 AffineTransform transform = element->getScreenCTM(SVGGraphicsElement::Disall owStyleUpdate); | |
| 418 transform *= resourceTransform; | |
| 419 return transform; | |
| 420 } | |
| 421 | |
| 422 static AffineTransform computeResourceSpaceTransform(RenderObject& renderer, con st SVGRenderStyle& svgStyle, RenderSVGResourceModeFlags resourceModeFlags) | |
| 423 { | |
| 424 AffineTransform computedSpaceTransform; | |
| 425 if (resourceModeFlags & ApplyToTextMode) { | |
| 426 // Depending on the font scaling factor, we may need to apply an | |
| 427 // additional transform (scale-factor) to the paintserver, since text | |
| 428 // painting removes the scale factor from the context. (See | |
| 429 // SVGInlineTextBoxPainter::paintTextWithShadows.) | |
| 430 AffineTransform additionalTextTransformation; | |
| 431 if (shouldTransformOnTextPainting(renderer, additionalTextTransformation )) | |
| 432 computedSpaceTransform = additionalTextTransformation; | |
| 433 } | |
| 434 if (resourceModeFlags & ApplyToStrokeMode) { | |
| 435 // Non-scaling stroke needs to reset the transform back to the host tran sform. | |
| 436 if (renderer.isSVGShape() && svgStyle.vectorEffect() == VE_NON_SCALING_S TROKE) | |
| 437 computedSpaceTransform = transformOnNonScalingStroke(renderer, compu tedSpaceTransform); | |
| 438 } | |
| 439 return computedSpaceTransform; | |
| 440 } | |
| 441 | |
| 397 bool SVGRenderSupport::updateGraphicsContext(GraphicsContextStateSaver& stateSav er, RenderStyle* style, RenderObject& renderer, unsigned resourceModeFlags) | 442 bool SVGRenderSupport::updateGraphicsContext(GraphicsContextStateSaver& stateSav er, RenderStyle* style, RenderObject& renderer, unsigned resourceModeFlags) |
| 398 { | 443 { |
| 399 ASSERT(style); | 444 ASSERT(style); |
| 400 | 445 |
| 401 RenderSVGResourceMode resourceMode = static_cast<RenderSVGResourceMode>(reso urceModeFlags & (ApplyToFillMode | ApplyToStrokeMode)); | 446 RenderSVGResourceMode resourceMode = static_cast<RenderSVGResourceMode>(reso urceModeFlags & (ApplyToFillMode | ApplyToStrokeMode)); |
| 402 ASSERT(resourceMode == ApplyToFillMode || resourceMode == ApplyToStrokeMode) ; | 447 ASSERT(resourceMode == ApplyToFillMode || resourceMode == ApplyToStrokeMode) ; |
| 403 | 448 |
| 404 GraphicsContext* context = stateSaver.context(); | 449 GraphicsContext* context = stateSaver.context(); |
| 405 if (isRenderingClipPathAsMaskImage(renderer)) { | 450 if (isRenderingClipPathAsMaskImage(renderer)) { |
| 406 if (resourceMode == ApplyToStrokeMode) | 451 if (resourceMode == ApplyToStrokeMode) |
| 407 return false; | 452 return false; |
| 408 context->setAlphaAsFloat(1); | 453 context->setAlphaAsFloat(1); |
| 409 context->setFillColor(SVGRenderStyle::initialFillPaintColor()); | 454 context->setFillColor(SVGRenderStyle::initialFillPaintColor()); |
| 410 return true; | 455 return true; |
| 411 } | 456 } |
| 412 | 457 |
| 413 SVGPaintServer paintServer = SVGPaintServer::requestForRenderer(renderer, st yle, resourceModeFlags); | 458 SVGPaintServer paintServer = SVGPaintServer::requestForRenderer(renderer, st yle, resourceMode); |
| 414 if (!paintServer.isValid()) | 459 if (!paintServer.isValid()) |
| 415 return false; | 460 return false; |
| 416 paintServer.apply(*context, resourceMode, &stateSaver); | |
| 417 | 461 |
| 418 const SVGRenderStyle& svgStyle = style->svgStyle(); | 462 const SVGRenderStyle& svgStyle = style->svgStyle(); |
| 419 | 463 |
| 464 if (paintServer.isTransformDependent()) | |
| 465 paintServer.prependTransform(computeResourceSpaceTransform(renderer, svg Style, resourceModeFlags)); | |
| 466 | |
| 467 paintServer.apply(*context, resourceMode, &stateSaver); | |
| 468 | |
| 420 if (resourceMode == ApplyToFillMode) { | 469 if (resourceMode == ApplyToFillMode) { |
| 421 context->setAlphaAsFloat(svgStyle.fillOpacity()); | 470 context->setAlphaAsFloat(svgStyle.fillOpacity()); |
| 422 context->setFillRule(svgStyle.fillRule()); | 471 context->setFillRule(svgStyle.fillRule()); |
| 423 } else { | 472 } else { |
| 424 context->setAlphaAsFloat(svgStyle.strokeOpacity()); | 473 context->setAlphaAsFloat(svgStyle.strokeOpacity()); |
| 425 applyStrokeStyleToContext(context, style, &renderer); | 474 applyStrokeStyleToContext(context, style, &renderer); |
| 426 } | 475 } |
| 427 return true; | 476 return true; |
| 428 } | 477 } |
| 429 | 478 |
| 430 void SVGRenderSupport::fillOrStrokePath(GraphicsContext* context, unsigned short resourceMode, const Path& path) | 479 void SVGRenderSupport::fillOrStrokePath(GraphicsContext* context, unsigned short resourceMode, const Path& path) |
| 431 { | 480 { |
| 432 if (resourceMode & ApplyToFillMode) | 481 if (resourceMode & ApplyToFillMode) |
| 433 context->fillPath(path); | 482 context->fillPath(path); |
| 434 if (resourceMode & ApplyToStrokeMode) | 483 if (resourceMode & ApplyToStrokeMode) |
| 435 context->strokePath(path); | 484 context->strokePath(path); |
| 436 } | 485 } |
| 437 | 486 |
| 438 bool SVGRenderSupport::isRenderableTextNode(const RenderObject* object) | 487 bool SVGRenderSupport::isRenderableTextNode(const RenderObject* object) |
| 439 { | 488 { |
| 440 ASSERT(object->isText()); | 489 ASSERT(object->isText()); |
| 441 // <br> is marked as text, but is not handled by the SVG rendering code-path . | 490 // <br> is marked as text, but is not handled by the SVG rendering code-path . |
| 442 return object->isSVGInlineText() && !toRenderSVGInlineText(object)->hasEmpty Text(); | 491 return object->isSVGInlineText() && !toRenderSVGInlineText(object)->hasEmpty Text(); |
| 443 } | 492 } |
| 444 | 493 |
| 445 } | 494 } |
| OLD | NEW |