bool SVGLinearGradientElement::collectGradientAttributes(LinearGradientAttributes& attributes) { if (!renderer()) return false; HashSet<SVGGradientElement*> processedGradients; SVGGradientElement* current = this; setGradientAttributes(current, attributes); processedGradients.add(current); while (true) { // Respect xlink:href, take attributes from referenced element Node* refNode = SVGURIReference::targetElementFromIRIString(current->href()->currentValue()->value(), treeScope()); if (refNode && isSVGGradientElement(*refNode)) { current = toSVGGradientElement(refNode); // Cycle detection if (processedGradients.contains(current)) return true; if (!current->renderer()) return false; setGradientAttributes(current, attributes, isSVGLinearGradientElement(*current)); processedGradients.add(current); } else { return true; } } ASSERT_NOT_REACHED(); return false; }
bool SVGLinearGradientElement::collectGradientAttributes(LinearGradientAttributes& attributes) { if (!renderer()) return false; HashSet<SVGGradientElement*> processedGradients; SVGGradientElement* current = this; setGradientAttributes(*current, attributes); processedGradients.add(current); while (true) { // Respect xlink:href, take attributes from referenced element Node* refNode = SVGURIReference::targetElementFromIRIString(current->href(), document()); if (is<SVGGradientElement>(refNode)) { current = downcast<SVGGradientElement>(refNode); // Cycle detection if (processedGradients.contains(current)) return true; if (!current->renderer()) return false; setGradientAttributes(*current, attributes, current->hasTagName(SVGNames::linearGradientTag)); processedGradients.add(current); } else return true; } ASSERT_NOT_REACHED(); return false; }
SVGPaintServer LayoutSVGResourceGradient::preparePaintServer( const LayoutObject& object) { clearInvalidationMask(); // Be sure to synchronize all SVG properties on the gradientElement _before_ // processing any further. Otherwhise the call to collectGradientAttributes() // in createTileImage(), may cause the SVG DOM property synchronization to // kick in, which causes removeAllClientsFromCache() to be called, which in // turn deletes our GradientData object! Leaving out the line below will cause // svg/dynamic-updates/SVG*GradientElement-svgdom* to crash. SVGGradientElement* gradientElement = toSVGGradientElement(element()); if (!gradientElement) return SVGPaintServer::invalid(); if (m_shouldCollectGradientAttributes) { gradientElement->synchronizeAnimatedSVGAttribute(anyQName()); if (!collectGradientAttributes(gradientElement)) return SVGPaintServer::invalid(); 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 (gradientUnits() == SVGUnitTypes::kSvgUnitTypeObjectboundingbox && objectBoundingBox.isEmpty()) return SVGPaintServer::invalid(); std::unique_ptr<GradientData>& gradientData = m_gradientMap.add(&object, nullptr).storedValue->value; if (!gradientData) gradientData = WTF::wrapUnique(new GradientData); // Create gradient object if (!gradientData->gradient) { gradientData->gradient = buildGradient(); // We want the text bounding box applied to the gradient space transform // now, so the gradient shader can use it. if (gradientUnits() == SVGUnitTypes::kSvgUnitTypeObjectboundingbox && !objectBoundingBox.isEmpty()) { gradientData->userspaceTransform.translate(objectBoundingBox.x(), objectBoundingBox.y()); gradientData->userspaceTransform.scaleNonUniform( objectBoundingBox.width(), objectBoundingBox.height()); } AffineTransform gradientTransform = calculateGradientTransform(); gradientData->userspaceTransform *= gradientTransform; } if (!gradientData->gradient) return SVGPaintServer::invalid(); return SVGPaintServer(gradientData->gradient, gradientData->userspaceTransform); }
JSValue jsSVGGradientElementStyle(ExecState* exec, JSValue slotBase, const Identifier&) { JSSVGGradientElement* castedThis = static_cast<JSSVGGradientElement*>(asObject(slotBase)); UNUSED_PARAM(exec); SVGGradientElement* imp = static_cast<SVGGradientElement*>(castedThis->impl()); JSValue result = toJS(exec, castedThis->globalObject(), WTF::getPtr(imp->style())); return result; }
JSValue jsSVGGradientElementSpreadMethod(ExecState* exec, JSValue slotBase, const Identifier&) { JSSVGGradientElement* castedThis = static_cast<JSSVGGradientElement*>(asObject(slotBase)); UNUSED_PARAM(exec); SVGGradientElement* imp = static_cast<SVGGradientElement*>(castedThis->impl()); RefPtr<SVGAnimatedEnumeration> obj = imp->spreadMethodAnimated(); JSValue result = toJS(exec, castedThis->globalObject(), obj.get()); return result; }
JSValue jsSVGGradientElementExternalResourcesRequired(ExecState* exec, JSValue slotBase, const Identifier&) { JSSVGGradientElement* castedThis = static_cast<JSSVGGradientElement*>(asObject(slotBase)); UNUSED_PARAM(exec); SVGGradientElement* imp = static_cast<SVGGradientElement*>(castedThis->impl()); RefPtr<SVGAnimatedBoolean> obj = imp->externalResourcesRequiredAnimated(); JSValue result = toJS(exec, castedThis->globalObject(), obj.get()); return result; }
JSValue jsSVGGradientElementClassName(ExecState* exec, JSValue slotBase, const Identifier&) { JSSVGGradientElement* castedThis = static_cast<JSSVGGradientElement*>(asObject(slotBase)); UNUSED_PARAM(exec); SVGGradientElement* imp = static_cast<SVGGradientElement*>(castedThis->impl()); RefPtr<SVGAnimatedString> obj = imp->classNameAnimated(); JSValue result = toJS(exec, castedThis->globalObject(), obj.get()); return result; }
JSValue* jsSVGGradientElementPrototypeFunctionGetPresentationAttribute(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) { if (!thisValue->isObject(&JSSVGGradientElement::s_info)) return throwError(exec, TypeError); JSSVGGradientElement* castedThisObj = static_cast<JSSVGGradientElement*>(thisValue); SVGGradientElement* imp = static_cast<SVGGradientElement*>(castedThisObj->impl()); const UString& name = args.at(exec, 0)->toString(exec); JSC::JSValue* result = toJS(exec, WTF::getPtr(imp->getPresentationAttribute(name))); return result; }
JSValue JSC_HOST_CALL jsSVGGradientElementPrototypeFunctionGetPresentationAttribute(ExecState* exec, JSObject*, JSValue thisValue, const ArgList& args) { UNUSED_PARAM(args); if (!thisValue.inherits(&JSSVGGradientElement::s_info)) return throwError(exec, TypeError); JSSVGGradientElement* castedThisObj = static_cast<JSSVGGradientElement*>(asObject(thisValue)); SVGGradientElement* imp = static_cast<SVGGradientElement*>(castedThisObj->impl()); const UString& name = args.at(0).toString(exec); JSC::JSValue result = toJS(exec, castedThisObj->globalObject(), WTF::getPtr(imp->getPresentationAttribute(name))); return result; }
EncodedJSValue JSC_HOST_CALL jsSVGGradientElementPrototypeFunctionGetPresentationAttribute(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); if (!thisValue.inherits(&JSSVGGradientElement::s_info)) return throwVMTypeError(exec); JSSVGGradientElement* castedThis = static_cast<JSSVGGradientElement*>(asObject(thisValue)); ASSERT_GC_OBJECT_INHERITS(castedThis, &JSSVGGradientElement::s_info); SVGGradientElement* imp = static_cast<SVGGradientElement*>(castedThis->impl()); const String& name(ustringToString(exec->argument(0).toString(exec))); if (exec->hadException()) return JSValue::encode(jsUndefined()); JSC::JSValue result = toJS(exec, castedThis->globalObject(), WTF::getPtr(imp->getPresentationAttribute(name))); return JSValue::encode(result); }
void RenderSVGGradientStop::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle) { RenderObject::styleDidChange(diff, oldStyle); if (!diff.hasDifference()) return; // <stop> elements should only be allowed to make renderers under gradient elements // but I can imagine a few cases we might not be catching, so let's not crash if our parent isn't a gradient. SVGGradientElement* gradient = gradientElement(); if (!gradient) return; RenderObject* renderer = gradient->renderer(); if (!renderer) return; RenderSVGResourceContainer* container = toRenderSVGResourceContainer(renderer); container->removeAllClientsFromCache(); }
bool SVGRadialGradientElement::collectGradientAttributes(RadialGradientAttributes& attributes) { if (!renderer()) return false; WillBeHeapHashSet<RawPtrWillBeMember<SVGGradientElement> > processedGradients; SVGGradientElement* current = this; setGradientAttributes(current, attributes); processedGradients.add(current); while (true) { // Respect xlink:href, take attributes from referenced element Node* refNode = SVGURIReference::targetElementFromIRIString(current->href()->currentValue()->value(), treeScope()); if (refNode && isSVGGradientElement(*refNode)) { current = toSVGGradientElement(refNode); // Cycle detection if (processedGradients.contains(current)) break; if (!current->renderer()) return false; setGradientAttributes(current, attributes, isSVGRadialGradientElement(*current)); processedGradients.add(current); } else { break; } } // Handle default values for fx/fy if (!attributes.hasFx()) attributes.setFx(attributes.cx()); if (!attributes.hasFy()) attributes.setFy(attributes.cy()); return true; }
bool SVGRadialGradientElement::collectGradientAttributes(RadialGradientAttributes& attributes) { if (!renderer()) return false; HashSet<SVGGradientElement*> processedGradients; SVGGradientElement* current = this; setGradientAttributes(*current, attributes); processedGradients.add(current); while (true) { // Respect xlink:href, take attributes from referenced element Node* refNode = SVGURIReference::targetElementFromIRIString(current->href(), document()); if (is<SVGGradientElement>(refNode)) { current = downcast<SVGGradientElement>(refNode); // Cycle detection if (processedGradients.contains(current)) break; if (!current->renderer()) return false; setGradientAttributes(*current, attributes, current->hasTagName(SVGNames::radialGradientTag)); processedGradients.add(current); } else break; } // Handle default values for fx/fy if (!attributes.hasFx()) attributes.setFx(attributes.cx()); if (!attributes.hasFy()) attributes.setFy(attributes.cy()); return true; }
JSValue* JSSVGGradientElement::getValueProperty(ExecState* exec, int token) const { switch (token) { case GradientUnitsAttrNum: { SVGGradientElement* imp = static_cast<SVGGradientElement*>(impl()); RefPtr<SVGAnimatedEnumeration> obj = imp->gradientUnitsAnimated(); return toJS(exec, obj.get(), imp); } case GradientTransformAttrNum: { SVGGradientElement* imp = static_cast<SVGGradientElement*>(impl()); RefPtr<SVGAnimatedTransformList> obj = imp->gradientTransformAnimated(); return toJS(exec, obj.get(), imp); } case SpreadMethodAttrNum: { SVGGradientElement* imp = static_cast<SVGGradientElement*>(impl()); RefPtr<SVGAnimatedEnumeration> obj = imp->spreadMethodAnimated(); return toJS(exec, obj.get(), imp); } case HrefAttrNum: { SVGGradientElement* imp = static_cast<SVGGradientElement*>(impl()); RefPtr<SVGAnimatedString> obj = imp->hrefAnimated(); return toJS(exec, obj.get(), imp); } case ExternalResourcesRequiredAttrNum: { SVGGradientElement* imp = static_cast<SVGGradientElement*>(impl()); RefPtr<SVGAnimatedBoolean> obj = imp->externalResourcesRequiredAnimated(); return toJS(exec, obj.get(), imp); } case ClassNameAttrNum: { SVGGradientElement* imp = static_cast<SVGGradientElement*>(impl()); RefPtr<SVGAnimatedString> obj = imp->classNameAnimated(); return toJS(exec, obj.get(), imp); } case StyleAttrNum: { SVGGradientElement* imp = static_cast<SVGGradientElement*>(impl()); return toJS(exec, WTF::getPtr(imp->style())); } case ConstructorAttrNum: return getConstructor(exec); } return 0; }
bool RenderSVGResourceGradient::applyResource(RenderObject* object, RenderStyle* style, GraphicsContext*& context, unsigned short resourceMode) { ASSERT(object); ASSERT(style); ASSERT(context); ASSERT(resourceMode != ApplyToDefaultMode); clearInvalidationMask(); // Be sure to synchronize all SVG properties on the gradientElement _before_ processing any further. // Otherwhise the call to collectGradientAttributes() in createTileImage(), may cause the SVG DOM property // synchronization to kick in, which causes removeAllClientsFromCache() to be called, which in turn deletes our // GradientData object! Leaving out the line below will cause svg/dynamic-updates/SVG*GradientElement-svgdom* to crash. SVGGradientElement* gradientElement = toSVGGradientElement(element()); if (!gradientElement) return false; if (m_shouldCollectGradientAttributes) { gradientElement->synchronizeAnimatedSVGAttribute(anyQName()); if (!collectGradientAttributes(gradientElement)) return false; 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 (gradientUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX && objectBoundingBox.isEmpty()) return false; OwnPtr<GradientData>& gradientData = m_gradientMap.add(object, nullptr).storedValue->value; if (!gradientData) gradientData = adoptPtr(new GradientData); // Create gradient object if (!gradientData->gradient) { buildGradient(gradientData.get()); // We want the text bounding box applied to the gradient space transform now, so the gradient shader can use it. if (gradientUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX && !objectBoundingBox.isEmpty()) { gradientData->userspaceTransform.translate(objectBoundingBox.x(), objectBoundingBox.y()); gradientData->userspaceTransform.scaleNonUniform(objectBoundingBox.width(), objectBoundingBox.height()); } AffineTransform gradientTransform; calculateGradientTransform(gradientTransform); gradientData->userspaceTransform *= gradientTransform; } if (!gradientData->gradient) return false; const SVGRenderStyle* svgStyle = style->svgStyle(); ASSERT(svgStyle); AffineTransform computedGradientSpaceTransform = computeResourceSpaceTransform(object, gradientData->userspaceTransform, svgStyle, resourceMode); gradientData->gradient->setGradientSpaceTransform(computedGradientSpaceTransform); // Draw gradient context->save(); if (resourceMode & ApplyToTextMode) context->setTextDrawingMode(resourceMode & ApplyToFillMode ? TextModeFill : TextModeStroke); if (resourceMode & ApplyToFillMode) { context->setAlphaAsFloat(svgStyle->fillOpacity()); context->setFillGradient(gradientData->gradient); context->setFillRule(svgStyle->fillRule()); } else if (resourceMode & ApplyToStrokeMode) { context->setAlphaAsFloat(svgStyle->strokeOpacity()); context->setStrokeGradient(gradientData->gradient); SVGRenderSupport::applyStrokeStyleToContext(context, style, object); } return true; }
bool RenderSVGResourceGradient::applyResource(RenderObject* object, RenderStyle* style, GraphicsContext*& context, unsigned short resourceMode) { ASSERT(object); ASSERT(style); ASSERT(context); ASSERT(resourceMode != ApplyToDefaultMode); // Be sure to synchronize all SVG properties on the gradientElement _before_ processing any further. // Otherwhise the call to collectGradientAttributes() in createTileImage(), may cause the SVG DOM property // synchronization to kick in, which causes invalidateClients() to be called, which in turn deletes our // GradientData object! Leaving out the line below will cause svg/dynamic-updates/SVG*GradientElement-svgdom* to crash. SVGGradientElement* gradientElement = static_cast<SVGGradientElement*>(node()); if (!gradientElement) return false; gradientElement->updateAnimatedSVGAttribute(anyQName()); if (!m_gradient.contains(object)) m_gradient.set(object, new GradientData); GradientData* gradientData = m_gradient.get(object); // Create gradient object if (!gradientData->gradient) buildGradient(gradientData, gradientElement); if (!gradientData->gradient) return false; // Draw gradient context->save(); bool isPaintingText = resourceMode & ApplyToTextMode; if (isPaintingText) { #if PLATFORM(CG) if (!createMaskAndSwapContextForTextGradient(context, m_savedContext, m_imageBuffer, object)) { context->restore(); return false; } #endif context->setTextDrawingMode(resourceMode & ApplyToFillMode ? cTextFill : cTextStroke); } AffineTransform transform; // CG platforms will handle the gradient space transform for text after applying the // 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) { #else if (gradientData->boundingBoxMode) { #endif FloatRect objectBoundingBox = object->objectBoundingBox(); transform.translate(objectBoundingBox.x(), objectBoundingBox.y()); transform.scaleNonUniform(objectBoundingBox.width(), objectBoundingBox.height()); } transform.multiply(gradientData->transform); gradientData->gradient->setGradientSpaceTransform(transform); const SVGRenderStyle* svgStyle = style->svgStyle(); ASSERT(svgStyle); if (resourceMode & ApplyToFillMode) { context->setAlpha(svgStyle->fillOpacity()); context->setFillGradient(gradientData->gradient); context->setFillRule(svgStyle->fillRule()); } else if (resourceMode & ApplyToStrokeMode) { context->setAlpha(svgStyle->strokeOpacity()); context->setStrokeGradient(gradientData->gradient); applyStrokeStyleToContext(context, style, object); } return true; } void RenderSVGResourceGradient::postApplyResource(RenderObject* object, GraphicsContext*& context, unsigned short resourceMode) { ASSERT(context); ASSERT(resourceMode != ApplyToDefaultMode); if (resourceMode & ApplyToTextMode) { #if PLATFORM(CG) // CG requires special handling for gradient on text if (m_savedContext && m_gradient.contains(object)) { GradientData* gradientData = m_gradient.get(object); // Restore on-screen drawing context context = m_savedContext; m_savedContext = 0; gradientData->gradient->setGradientSpaceTransform(clipToTextMask(context, m_imageBuffer, object, gradientData)); context->setFillGradient(gradientData->gradient); const RenderObject* textRootBlock = findTextRootObject(object); context->fillRect(textRootBlock->repaintRectInLocalCoordinates()); m_imageBuffer.clear(); } #else UNUSED_PARAM(object); #endif } else { if (resourceMode & ApplyToFillMode) context->fillPath(); else if (resourceMode & ApplyToStrokeMode) context->strokePath(); } context->restore(); }
static void setGradientAttributes(SVGGradientElement& element, RadialGradientAttributes& attributes, bool isRadial = true) { if (!attributes.hasSpreadMethod() && element.hasAttribute(SVGNames::spreadMethodAttr)) attributes.setSpreadMethod(element.spreadMethod()); if (!attributes.hasGradientUnits() && element.hasAttribute(SVGNames::gradientUnitsAttr)) attributes.setGradientUnits(element.gradientUnits()); if (!attributes.hasGradientTransform() && element.hasAttribute(SVGNames::gradientTransformAttr)) { AffineTransform transform; element.gradientTransform().concatenate(transform); attributes.setGradientTransform(transform); } if (!attributes.hasStops()) { const Vector<Gradient::ColorStop>& stops(element.buildStops()); if (!stops.isEmpty()) attributes.setStops(stops); } if (isRadial) { SVGRadialGradientElement& radial = downcast<SVGRadialGradientElement>(element); if (!attributes.hasCx() && element.hasAttribute(SVGNames::cxAttr)) attributes.setCx(radial.cx()); if (!attributes.hasCy() && element.hasAttribute(SVGNames::cyAttr)) attributes.setCy(radial.cy()); if (!attributes.hasR() && element.hasAttribute(SVGNames::rAttr)) attributes.setR(radial.r()); if (!attributes.hasFx() && element.hasAttribute(SVGNames::fxAttr)) attributes.setFx(radial.fx()); if (!attributes.hasFy() && element.hasAttribute(SVGNames::fyAttr)) attributes.setFy(radial.fy()); if (!attributes.hasFr() && element.hasAttribute(SVGNames::frAttr)) attributes.setFr(radial.fr()); } }
static void setGradientAttributes(SVGGradientElement& element, LinearGradientAttributes& attributes, bool isLinear = true) { if (!attributes.hasSpreadMethod() && element.hasAttribute(SVGNames::spreadMethodAttr)) attributes.setSpreadMethod(element.spreadMethod()); if (!attributes.hasGradientUnits() && element.hasAttribute(SVGNames::gradientUnitsAttr)) attributes.setGradientUnits(element.gradientUnits()); if (!attributes.hasGradientTransform() && element.hasAttribute(SVGNames::gradientTransformAttr)) { AffineTransform transform; element.gradientTransform().concatenate(transform); attributes.setGradientTransform(transform); } if (!attributes.hasStops()) { const Vector<Gradient::ColorStop>& stops(element.buildStops()); if (!stops.isEmpty()) attributes.setStops(stops); } if (isLinear) { SVGLinearGradientElement& linear = downcast<SVGLinearGradientElement>(element); if (!attributes.hasX1() && element.hasAttribute(SVGNames::x1Attr)) attributes.setX1(linear.x1()); if (!attributes.hasY1() && element.hasAttribute(SVGNames::y1Attr)) attributes.setY1(linear.y1()); if (!attributes.hasX2() && element.hasAttribute(SVGNames::x2Attr)) attributes.setX2(linear.x2()); if (!attributes.hasY2() && element.hasAttribute(SVGNames::y2Attr)) attributes.setY2(linear.y2()); } }
bool RenderSVGResourceGradient::applyResource(RenderObject* object, RenderStyle* style, GraphicsContext*& context, unsigned short resourceMode) { ASSERT(object); ASSERT(style); ASSERT(context); ASSERT(resourceMode != ApplyToDefaultMode); // Be sure to synchronize all SVG properties on the gradientElement _before_ processing any further. // Otherwhise the call to collectGradientAttributes() in createTileImage(), may cause the SVG DOM property // synchronization to kick in, which causes removeAllClientsFromCache() to be called, which in turn deletes our // GradientData object! Leaving out the line below will cause svg/dynamic-updates/SVG*GradientElement-svgdom* to crash. SVGGradientElement* gradientElement = static_cast<SVGGradientElement*>(node()); if (!gradientElement) return false; if (m_shouldCollectGradientAttributes) { gradientElement->synchronizeAnimatedSVGAttribute(anyQName()); if (!collectGradientAttributes(gradientElement)) return false; 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 (gradientUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX && objectBoundingBox.isEmpty()) return false; OwnPtr<GradientData>& gradientData = m_gradientMap.add(object, nullptr).iterator->value; if (!gradientData) gradientData = adoptPtr(new GradientData); bool isPaintingText = resourceMode & ApplyToTextMode; // Create gradient object if (!gradientData->gradient) { buildGradient(gradientData.get()); // CG platforms will handle the gradient space transform for text after applying the // 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 USE(CG) if (gradientUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX && !objectBoundingBox.isEmpty() && !isPaintingText) { #else if (gradientUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX && !objectBoundingBox.isEmpty()) { #endif gradientData->userspaceTransform.translate(objectBoundingBox.x(), objectBoundingBox.y()); gradientData->userspaceTransform.scaleNonUniform(objectBoundingBox.width(), objectBoundingBox.height()); } AffineTransform gradientTransform; calculateGradientTransform(gradientTransform); gradientData->userspaceTransform *= gradientTransform; if (isPaintingText) { // Depending on font scaling factor, we may need to rescale the gradient here since // text painting removes the scale factor from the context. AffineTransform additionalTextTransform; if (shouldTransformOnTextPainting(object, additionalTextTransform)) gradientData->userspaceTransform *= additionalTextTransform; } gradientData->gradient->setGradientSpaceTransform(gradientData->userspaceTransform); } if (!gradientData->gradient) return false; // Draw gradient context->save(); if (isPaintingText) { #if USE(CG) if (!createMaskAndSwapContextForTextGradient(context, m_savedContext, m_imageBuffer, object)) { context->restore(); return false; } #endif context->setTextDrawingMode(resourceMode & ApplyToFillMode ? TextModeFill : TextModeStroke); } const SVGRenderStyle* svgStyle = style->svgStyle(); ASSERT(svgStyle); if (resourceMode & ApplyToFillMode) { context->setAlpha(svgStyle->fillOpacity()); context->setFillGradient(gradientData->gradient); context->setFillRule(svgStyle->fillRule()); } else if (resourceMode & ApplyToStrokeMode) { if (svgStyle->vectorEffect() == VE_NON_SCALING_STROKE) gradientData->gradient->setGradientSpaceTransform(transformOnNonScalingStroke(object, gradientData->userspaceTransform)); context->setAlpha(svgStyle->strokeOpacity()); context->setStrokeGradient(gradientData->gradient); SVGRenderSupport::applyStrokeStyleToContext(context, style, object); } return true; } void RenderSVGResourceGradient::postApplyResource(RenderObject* object, GraphicsContext*& context, unsigned short resourceMode, const Path* path, const RenderSVGShape* shape) { ASSERT(context); ASSERT(resourceMode != ApplyToDefaultMode); if (resourceMode & ApplyToTextMode) { #if USE(CG) // CG requires special handling for gradient on text GradientData* gradientData; if (m_savedContext && (gradientData = m_gradientMap.get(object))) { // Restore on-screen drawing context context = m_savedContext; m_savedContext = 0; AffineTransform gradientTransform; calculateGradientTransform(gradientTransform); FloatRect targetRect; gradientData->gradient->setGradientSpaceTransform(clipToTextMask(context, m_imageBuffer, targetRect, object, gradientUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX, gradientTransform)); context->setFillGradient(gradientData->gradient); context->fillRect(targetRect); m_imageBuffer.clear(); } #else UNUSED_PARAM(object); #endif } else { if (resourceMode & ApplyToFillMode) { if (path) context->fillPath(*path); else if (shape) shape->fillShape(context); } if (resourceMode & ApplyToStrokeMode) { if (path) context->strokePath(*path); else if (shape) shape->strokeShape(context); } } context->restore(); }
LinearGradientAttributes SVGLinearGradientElement::collectGradientProperties() { LinearGradientAttributes attributes; HashSet<SVGGradientElement*> processedGradients; bool isLinear = true; SVGGradientElement* current = this; while (current) { if (!attributes.hasSpreadMethod() && current->hasAttribute(SVGNames::spreadMethodAttr)) attributes.setSpreadMethod((GradientSpreadMethod) current->spreadMethod()); if (!attributes.hasBoundingBoxMode() && current->hasAttribute(SVGNames::gradientUnitsAttr)) attributes.setBoundingBoxMode(current->gradientUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX); if (!attributes.hasGradientTransform() && current->hasAttribute(SVGNames::gradientTransformAttr)) attributes.setGradientTransform(current->gradientTransform()->consolidate().matrix()); if (!attributes.hasStops()) { const Vector<Gradient::ColorStop>& stops(current->buildStops()); if (!stops.isEmpty()) attributes.setStops(stops); } if (isLinear) { SVGLinearGradientElement* linear = static_cast<SVGLinearGradientElement*>(current); if (!attributes.hasX1() && current->hasAttribute(SVGNames::x1Attr)) attributes.setX1(linear->x1()); if (!attributes.hasY1() && current->hasAttribute(SVGNames::y1Attr)) attributes.setY1(linear->y1()); if (!attributes.hasX2() && current->hasAttribute(SVGNames::x2Attr)) attributes.setX2(linear->x2()); if (!attributes.hasY2() && current->hasAttribute(SVGNames::y2Attr)) attributes.setY2(linear->y2()); } processedGradients.add(current); // Respect xlink:href, take attributes from referenced element Node* refNode = ownerDocument()->getElementById(SVGURIReference::getTarget(current->href())); if (refNode && (refNode->hasTagName(SVGNames::linearGradientTag) || refNode->hasTagName(SVGNames::radialGradientTag))) { current = static_cast<SVGGradientElement*>(refNode); // Cycle detection if (processedGradients.contains(current)) return LinearGradientAttributes(); isLinear = current->hasTagName(SVGNames::linearGradientTag); } else current = 0; } return attributes; }