本文整理汇总了C++中LinearGradientAttributes类的典型用法代码示例。如果您正苦于以下问题:C++ LinearGradientAttributes类的具体用法?C++ LinearGradientAttributes怎么用?C++ LinearGradientAttributes使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了LinearGradientAttributes类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: calculateStartEndPoints
void SVGLinearGradientElement::calculateStartEndPoints(const LinearGradientAttributes& attributes, FloatPoint& startPoint, FloatPoint& endPoint)
{
// Determine gradient start/end points
if (attributes.boundingBoxMode()) {
startPoint = FloatPoint(attributes.x1().valueAsPercentage(), attributes.y1().valueAsPercentage());
endPoint = FloatPoint(attributes.x2().valueAsPercentage(), attributes.y2().valueAsPercentage());
} else {
startPoint = FloatPoint(attributes.x1().value(this), attributes.y1().value(this));
endPoint = FloatPoint(attributes.x2().value(this), attributes.y2().value(this));
}
}
示例2: collectGradientProperties
void SVGLinearGradientElement::buildGradient() const
{
LinearGradientAttributes attributes = collectGradientProperties();
// If we didn't find any gradient containing stop elements, ignore the request.
if (attributes.stops().isEmpty())
return;
RefPtr<SVGPaintServerLinearGradient> linearGradient = WTF::static_pointer_cast<SVGPaintServerLinearGradient>(m_resource);
linearGradient->setGradientStops(attributes.stops());
linearGradient->setBoundingBoxMode(attributes.boundingBoxMode());
linearGradient->setGradientSpreadMethod(attributes.spreadMethod());
linearGradient->setGradientTransform(attributes.gradientTransform());
linearGradient->setGradientStart(FloatPoint::narrowPrecision(attributes.x1(), attributes.y1()));
linearGradient->setGradientEnd(FloatPoint::narrowPrecision(attributes.x2(), attributes.y2()));
}
示例3: writeSVGResourceContainer
void writeSVGResourceContainer(TextStream& ts, const RenderObject& object, int indent)
{
writeStandardPrefix(ts, object, indent);
Element* element = toElement(object.node());
const AtomicString& id = element->getIdAttribute();
writeNameAndQuotedValue(ts, "id", id);
RenderSVGResourceContainer* resource = const_cast<RenderObject&>(object).toRenderSVGResourceContainer();
ASSERT(resource);
if (resource->resourceType() == MaskerResourceType) {
RenderSVGResourceMasker* masker = toRenderSVGResourceMasker(resource);
writeNameValuePair(ts, "maskUnits", masker->maskUnits());
writeNameValuePair(ts, "maskContentUnits", masker->maskContentUnits());
ts << "\n";
} else if (resource->resourceType() == FilterResourceType) {
RenderSVGResourceFilter* filter = toRenderSVGResourceFilter(resource);
writeNameValuePair(ts, "filterUnits", filter->filterUnits());
writeNameValuePair(ts, "primitiveUnits", filter->primitiveUnits());
ts << "\n";
// Creating a placeholder filter which is passed to the builder.
FloatRect dummyRect;
RefPtr<SVGFilter> dummyFilter = SVGFilter::create(AffineTransform(), dummyRect, dummyRect, dummyRect, true);
if (RefPtr<SVGFilterBuilder> builder = filter->buildPrimitives(dummyFilter.get())) {
if (FilterEffect* lastEffect = builder->lastEffect())
lastEffect->externalRepresentation(ts, indent + 1);
}
} else if (resource->resourceType() == ClipperResourceType) {
writeNameValuePair(ts, "clipPathUnits", toRenderSVGResourceClipper(resource)->clipPathUnits());
ts << "\n";
} else if (resource->resourceType() == MarkerResourceType) {
RenderSVGResourceMarker* marker = toRenderSVGResourceMarker(resource);
writeNameValuePair(ts, "markerUnits", marker->markerUnits());
ts << " [ref at " << marker->referencePoint() << "]";
ts << " [angle=";
if (marker->angle() == -1)
ts << "auto" << "]\n";
else
ts << marker->angle() << "]\n";
} else if (resource->resourceType() == PatternResourceType) {
RenderSVGResourcePattern* pattern = static_cast<RenderSVGResourcePattern*>(resource);
// Dump final results that are used for rendering. No use in asking SVGPatternElement for its patternUnits(), as it may
// link to other patterns using xlink:href, we need to build the full inheritance chain, aka. collectPatternProperties()
PatternAttributes attributes;
toSVGPatternElement(pattern->element())->collectPatternAttributes(attributes);
writeNameValuePair(ts, "patternUnits", attributes.patternUnits());
writeNameValuePair(ts, "patternContentUnits", attributes.patternContentUnits());
AffineTransform transform = attributes.patternTransform();
if (!transform.isIdentity())
ts << " [patternTransform=" << transform << "]";
ts << "\n";
} else if (resource->resourceType() == LinearGradientResourceType) {
RenderSVGResourceLinearGradient* gradient = static_cast<RenderSVGResourceLinearGradient*>(resource);
// Dump final results that are used for rendering. No use in asking SVGGradientElement for its gradientUnits(), as it may
// link to other gradients using xlink:href, we need to build the full inheritance chain, aka. collectGradientProperties()
LinearGradientAttributes attributes;
toSVGLinearGradientElement(gradient->element())->collectGradientAttributes(attributes);
writeCommonGradientProperties(ts, attributes.spreadMethod(), attributes.gradientTransform(), attributes.gradientUnits());
ts << " [start=" << gradient->startPoint(attributes) << "] [end=" << gradient->endPoint(attributes) << "]\n";
} else if (resource->resourceType() == RadialGradientResourceType) {
RenderSVGResourceRadialGradient* gradient = toRenderSVGResourceRadialGradient(resource);
// Dump final results that are used for rendering. No use in asking SVGGradientElement for its gradientUnits(), as it may
// link to other gradients using xlink:href, we need to build the full inheritance chain, aka. collectGradientProperties()
RadialGradientAttributes attributes;
toSVGRadialGradientElement(gradient->element())->collectGradientAttributes(attributes);
writeCommonGradientProperties(ts, attributes.spreadMethod(), attributes.gradientTransform(), attributes.gradientUnits());
FloatPoint focalPoint = gradient->focalPoint(attributes);
FloatPoint centerPoint = gradient->centerPoint(attributes);
float radius = gradient->radius(attributes);
float focalRadius = gradient->focalRadius(attributes);
ts << " [center=" << centerPoint << "] [focal=" << focalPoint << "] [radius=" << radius << "] [focalRadius=" << focalRadius << "]\n";
} else
ts << "\n";
writeChildren(ts, object, indent);
}
示例4: while
LinearGradientAttributes SVGLinearGradientElement::collectGradientProperties() const
{
LinearGradientAttributes attributes;
HashSet<const SVGGradientElement*> processedGradients;
bool isLinear = true;
const 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<SVGGradientStop>& stops(current->buildStops());
if (!stops.isEmpty())
attributes.setStops(stops);
}
if (isLinear) {
const SVGLinearGradientElement* linear = static_cast<const 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<const SVGGradientElement*>(const_cast<const Node*>(refNode));
// Cycle detection
if (processedGradients.contains(current))
return LinearGradientAttributes();
isLinear = current->gradientType() == LinearGradientPaintServer;
} else
current = 0;
}
return attributes;
}
示例5: collectGradientProperties
void SVGLinearGradientElement::buildGradient() const
{
LinearGradientAttributes attributes = collectGradientProperties();
RefPtr<SVGPaintServerLinearGradient> linearGradient = WTF::static_pointer_cast<SVGPaintServerLinearGradient>(m_resource);
FloatPoint startPoint;
FloatPoint endPoint;
if (attributes.boundingBoxMode()) {
startPoint = FloatPoint(attributes.x1().valueAsPercentage(), attributes.y1().valueAsPercentage());
endPoint = FloatPoint(attributes.x2().valueAsPercentage(), attributes.y2().valueAsPercentage());
} else {
startPoint = FloatPoint(attributes.x1().value(this), attributes.y1().value(this));
endPoint = FloatPoint(attributes.x2().value(this), attributes.y2().value(this));
}
RefPtr<Gradient> gradient = Gradient::create(startPoint, endPoint);
gradient->setSpreadMethod(attributes.spreadMethod());
Vector<SVGGradientStop> m_stops = attributes.stops();
float previousOffset = 0.0f;
for (unsigned i = 0; i < m_stops.size(); ++i) {
float offset = std::min(std::max(previousOffset, m_stops[i].first), 1.0f);
previousOffset = offset;
gradient->addColorStop(offset, m_stops[i].second);
}
linearGradient->setGradient(gradient);
if (attributes.stops().isEmpty())
return;
// This code should go away. PaintServers should go away too.
// Only this code should care about bounding boxes
linearGradient->setBoundingBoxMode(attributes.boundingBoxMode());
linearGradient->setGradientStops(attributes.stops());
// These should possibly be supported on Gradient
linearGradient->setGradientTransform(attributes.gradientTransform());
linearGradient->setGradientStart(startPoint);
linearGradient->setGradientEnd(endPoint);
}
示例6: setGradientAttributes
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());
}
}
示例7: writeSVGResourceContainer
void writeSVGResourceContainer(TextStream& ts, const RenderObject& object, int indent)
{
writeStandardPrefix(ts, object, indent);
Element* element = static_cast<Element*>(object.node());
const AtomicString& id = element->getIdAttribute();
writeNameAndQuotedValue(ts, "id", id);
RenderSVGResourceContainer* resource = const_cast<RenderObject&>(object).toRenderSVGResourceContainer();
ASSERT(resource);
if (resource->resourceType() == MaskerResourceType) {
RenderSVGResourceMasker* masker = static_cast<RenderSVGResourceMasker*>(resource);
writeNameValuePair(ts, "maskUnits", masker->maskUnits());
writeNameValuePair(ts, "maskContentUnits", masker->maskContentUnits());
ts << "\n";
#if ENABLE(FILTERS)
} else if (resource->resourceType() == FilterResourceType) {
RenderSVGResourceFilter* filter = static_cast<RenderSVGResourceFilter*>(resource);
writeNameValuePair(ts, "filterUnits", filter->filterUnits());
writeNameValuePair(ts, "primitiveUnits", filter->primitiveUnits());
ts << "\n";
if (RefPtr<SVGFilterBuilder> builder = filter->buildPrimitives()) {
if (FilterEffect* lastEffect = builder->lastEffect())
lastEffect->externalRepresentation(ts, indent + 1);
}
#endif
} else if (resource->resourceType() == ClipperResourceType) {
RenderSVGResourceClipper* clipper = static_cast<RenderSVGResourceClipper*>(resource);
writeNameValuePair(ts, "clipPathUnits", clipper->clipPathUnits());
ts << "\n";
} else if (resource->resourceType() == MarkerResourceType) {
RenderSVGResourceMarker* marker = static_cast<RenderSVGResourceMarker*>(resource);
writeNameValuePair(ts, "markerUnits", marker->markerUnits());
ts << " [ref at " << marker->referencePoint() << "]";
ts << " [angle=";
if (marker->angle() == -1)
ts << "auto" << "]\n";
else
ts << marker->angle() << "]\n";
} else if (resource->resourceType() == PatternResourceType) {
RenderSVGResourcePattern* pattern = static_cast<RenderSVGResourcePattern*>(resource);
// Dump final results that are used for rendering. No use in asking SVGPatternElement for its patternUnits(), as it may
// link to other patterns using xlink:href, we need to build the full inheritance chain, aka. collectPatternProperties()
PatternAttributes attributes = static_cast<SVGPatternElement*>(pattern->node())->collectPatternProperties();
writeNameValuePair(ts, "patternUnits", boundingBoxModeString(attributes.boundingBoxMode()));
writeNameValuePair(ts, "patternContentUnits", boundingBoxModeString(attributes.boundingBoxModeContent()));
AffineTransform transform = attributes.patternTransform();
if (!transform.isIdentity())
ts << " [patternTransform=" << transform << "]";
ts << "\n";
} else if (resource->resourceType() == LinearGradientResourceType) {
RenderSVGResourceLinearGradient* gradient = static_cast<RenderSVGResourceLinearGradient*>(resource);
// Dump final results that are used for rendering. No use in asking SVGGradientElement for its gradientUnits(), as it may
// link to other gradients using xlink:href, we need to build the full inheritance chain, aka. collectGradientProperties()
SVGLinearGradientElement* linearGradientElement = static_cast<SVGLinearGradientElement*>(gradient->node());
LinearGradientAttributes attributes = linearGradientElement->collectGradientProperties();
writeCommonGradientProperties(ts, attributes.spreadMethod(), attributes.gradientTransform(), attributes.boundingBoxMode());
FloatPoint startPoint;
FloatPoint endPoint;
linearGradientElement->calculateStartEndPoints(attributes, startPoint, endPoint);
ts << " [start=" << startPoint << "] [end=" << endPoint << "]\n";
} else if (resource->resourceType() == RadialGradientResourceType) {
RenderSVGResourceRadialGradient* gradient = static_cast<RenderSVGResourceRadialGradient*>(resource);
// Dump final results that are used for rendering. No use in asking SVGGradientElement for its gradientUnits(), as it may
// link to other gradients using xlink:href, we need to build the full inheritance chain, aka. collectGradientProperties()
SVGRadialGradientElement* radialGradientElement = static_cast<SVGRadialGradientElement*>(gradient->node());
RadialGradientAttributes attributes = radialGradientElement->collectGradientProperties();
writeCommonGradientProperties(ts, attributes.spreadMethod(), attributes.gradientTransform(), attributes.boundingBoxMode());
FloatPoint focalPoint;
FloatPoint centerPoint;
float radius;
radialGradientElement->calculateFocalCenterPointsAndRadius(attributes, focalPoint, centerPoint, radius);
ts << " [center=" << centerPoint << "] [focal=" << focalPoint << "] [radius=" << radius << "]\n";
} else
ts << "\n";
writeChildren(ts, object, indent);
}
示例8: setGradientAttributes
static void setGradientAttributes(SVGGradientElement* element, LinearGradientAttributes& attributes, bool isLinear = true)
{
if (!attributes.hasSpreadMethod() && element->spreadMethod()->isSpecified())
attributes.setSpreadMethod(element->spreadMethod()->currentValue()->enumValue());
if (!attributes.hasGradientUnits() && element->gradientUnits()->isSpecified())
attributes.setGradientUnits(element->gradientUnits()->currentValue()->enumValue());
if (!attributes.hasGradientTransform() && element->gradientTransform()->isSpecified()) {
AffineTransform transform;
element->gradientTransform()->currentValue()->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 = toSVGLinearGradientElement(element);
if (!attributes.hasX1() && linear->x1()->isSpecified())
attributes.setX1(linear->x1()->currentValue());
if (!attributes.hasY1() && linear->y1()->isSpecified())
attributes.setY1(linear->y1()->currentValue());
if (!attributes.hasX2() && linear->x2()->isSpecified())
attributes.setX2(linear->x2()->currentValue());
if (!attributes.hasY2() && linear->y2()->isSpecified())
attributes.setY2(linear->y2()->currentValue());
}
}