/*
* Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org>
- * 2008 Eric Seidel <eric@webkit.org>
- * 2008 Dirk Schulze <krit@webkit.org>
+ * Copyright (C) 2008 Eric Seidel <eric@webkit.org>
+ * Copyright (C) 2008 Dirk Schulze <krit@webkit.org>
* Copyright (C) Research In Motion Limited 2010. All rights reserved.
*
* This library is free software; you can redistribute it and/or
#include "GradientAttributes.h"
#include "GraphicsContext.h"
+#include "RenderSVGText.h"
#include "SVGImageBufferTools.h"
#include "SVGRenderSupport.h"
#include <wtf/UnusedParam.h>
RenderSVGResourceGradient::RenderSVGResourceGradient(SVGGradientElement* node)
: RenderSVGResourceContainer(node)
+ , m_shouldCollectGradientAttributes(true)
#if PLATFORM(CG)
, m_savedContext(0)
#endif
m_gradient.clear();
}
+ m_shouldCollectGradientAttributes = true;
markAllClientsForInvalidation(markForInvalidation ? RepaintInvalidation : ParentOnlyInvalidation);
}
static inline bool createMaskAndSwapContextForTextGradient(GraphicsContext*& context,
GraphicsContext*& savedContext,
OwnPtr<ImageBuffer>& imageBuffer,
- const RenderObject* object)
+ RenderObject* object)
{
- const RenderObject* textRootBlock = SVGRenderSupport::findTextRootObject(object);
+ RenderObject* textRootBlock = RenderSVGText::locateRenderSVGTextAncestor(object);
ASSERT(textRootBlock);
- AffineTransform absoluteTransform(SVGImageBufferTools::absoluteTransformFromContext(context));
+ AffineTransform absoluteTransform;
+ SVGImageBufferTools::calculateTransformationToOutermostSVGCoordinateSystem(textRootBlock, absoluteTransform);
+
FloatRect absoluteTargetRect = absoluteTransform.mapRect(textRootBlock->repaintRectInLocalCoordinates());
+ FloatRect clampedAbsoluteTargetRect = SVGImageBufferTools::clampedAbsoluteTargetRectForRenderer(textRootBlock, absoluteTargetRect);
+ if (clampedAbsoluteTargetRect.isEmpty())
+ return false;
OwnPtr<ImageBuffer> maskImage;
- if (!SVGImageBufferTools::createImageBuffer(absoluteTransform, absoluteTargetRect, maskImage, DeviceRGB))
+ if (!SVGImageBufferTools::createImageBuffer(absoluteTargetRect, clampedAbsoluteTargetRect, maskImage, ColorSpaceDeviceRGB))
return false;
+ GraphicsContext* maskImageContext = maskImage->context();
+ ASSERT(maskImageContext);
+
+ maskImageContext->translate(-clampedAbsoluteTargetRect.x(), -clampedAbsoluteTargetRect.y());
+ maskImageContext->concatCTM(absoluteTransform);
+
ASSERT(maskImage);
savedContext = context;
- context = maskImage->context();
+ context = maskImageContext;
imageBuffer = maskImage.release();
return true;
}
static inline AffineTransform clipToTextMask(GraphicsContext* context,
OwnPtr<ImageBuffer>& imageBuffer,
- FloatRect& repaintRect,
- const RenderObject* object,
- GradientData* gradientData)
+ FloatRect& targetRect,
+ RenderObject* object,
+ bool boundingBoxMode,
+ const AffineTransform& gradientTransform)
{
- const RenderObject* textRootBlock = SVGRenderSupport::findTextRootObject(object);
+ RenderObject* textRootBlock = RenderSVGText::locateRenderSVGTextAncestor(object);
ASSERT(textRootBlock);
- repaintRect = textRootBlock->repaintRectInLocalCoordinates();
+ targetRect = textRootBlock->repaintRectInLocalCoordinates();
+
+ AffineTransform absoluteTransform;
+ SVGImageBufferTools::calculateTransformationToOutermostSVGCoordinateSystem(textRootBlock, absoluteTransform);
- AffineTransform absoluteTransform(SVGImageBufferTools::absoluteTransformFromContext(context));
- FloatRect absoluteTargetRect = absoluteTransform.mapRect(repaintRect);
+ FloatRect absoluteTargetRect = absoluteTransform.mapRect(targetRect);
+ FloatRect clampedAbsoluteTargetRect = SVGImageBufferTools::clampedAbsoluteTargetRectForRenderer(textRootBlock, absoluteTargetRect);
- SVGImageBufferTools::clipToImageBuffer(context, absoluteTransform, absoluteTargetRect, imageBuffer.get());
+ SVGImageBufferTools::clipToImageBuffer(context, absoluteTransform, clampedAbsoluteTargetRect, imageBuffer);
AffineTransform matrix;
- if (gradientData->boundingBoxMode) {
+ if (boundingBoxMode) {
FloatRect maskBoundingBox = textRootBlock->objectBoundingBox();
matrix.translate(maskBoundingBox.x(), maskBoundingBox.y());
matrix.scaleNonUniform(maskBoundingBox.width(), maskBoundingBox.height());
}
- matrix.multLeft(gradientData->transform);
+ matrix.multLeft(gradientTransform);
return matrix;
}
#endif
if (!gradientElement)
return false;
- gradientElement->updateAnimatedSVGAttribute(anyQName());
+ if (m_shouldCollectGradientAttributes) {
+ gradientElement->updateAnimatedSVGAttribute(anyQName());
+ collectGradientAttributes(gradientElement);
+ m_shouldCollectGradientAttributes = false;
+ }
+
+ // Spec: When the geometry of the applicable element has no width or height and objectBoundingBox is specified,
+ // then the given effect (e.g. a gradient or a filter) will be ignored.
+ FloatRect objectBoundingBox = object->objectBoundingBox();
+ if (boundingBoxMode() && objectBoundingBox.isEmpty())
+ return false;
if (!m_gradient.contains(object))
m_gradient.set(object, new GradientData);
GradientData* gradientData = m_gradient.get(object);
-
bool isPaintingText = resourceMode & ApplyToTextMode;
// Create gradient object
// resource, so don't apply it here. For non-CG platforms, we want the text bounding
// box applied to the gradient space transform now, so the gradient shader can use it.
#if PLATFORM(CG)
- if (gradientData->boundingBoxMode && !isPaintingText) {
+ if (boundingBoxMode() && !objectBoundingBox.isEmpty() && !isPaintingText) {
#else
- if (gradientData->boundingBoxMode) {
+ if (boundingBoxMode() && !objectBoundingBox.isEmpty()) {
#endif
- FloatRect objectBoundingBox = object->objectBoundingBox();
gradientData->userspaceTransform.translate(objectBoundingBox.x(), objectBoundingBox.y());
gradientData->userspaceTransform.scaleNonUniform(objectBoundingBox.width(), objectBoundingBox.height());
}
- gradientData->userspaceTransform.multLeft(gradientData->transform);
+ AffineTransform gradientTransform;
+ calculateGradientTransform(gradientTransform);
+
+ gradientData->userspaceTransform.multLeft(gradientTransform);
gradientData->gradient->setGradientSpaceTransform(gradientData->userspaceTransform);
}
return true;
}
-void RenderSVGResourceGradient::postApplyResource(RenderObject* object, GraphicsContext*& context, unsigned short resourceMode)
+void RenderSVGResourceGradient::postApplyResource(RenderObject* object, GraphicsContext*& context, unsigned short resourceMode, const Path* path)
{
ASSERT(context);
ASSERT(resourceMode != ApplyToDefaultMode);
context = m_savedContext;
m_savedContext = 0;
- FloatRect repaintRect;
- gradientData->gradient->setGradientSpaceTransform(clipToTextMask(context, m_imageBuffer, repaintRect, object, gradientData));
+ AffineTransform gradientTransform;
+ calculateGradientTransform(gradientTransform);
+
+ FloatRect targetRect;
+ gradientData->gradient->setGradientSpaceTransform(clipToTextMask(context, m_imageBuffer, targetRect, object, boundingBoxMode(), gradientTransform));
context->setFillGradient(gradientData->gradient);
- context->fillRect(repaintRect);
+ context->fillRect(targetRect);
m_imageBuffer.clear();
}
#else
UNUSED_PARAM(object);
#endif
- } else {
+ } else if (path) {
if (resourceMode & ApplyToFillMode)
- context->fillPath();
+ context->fillPath(*path);
else if (resourceMode & ApplyToStrokeMode)
- context->strokePath();
+ context->strokePath(*path);
}
context->restore();