本文整理汇总了C++中SVGGraphicsElement::toClipPath方法的典型用法代码示例。如果您正苦于以下问题:C++ SVGGraphicsElement::toClipPath方法的具体用法?C++ SVGGraphicsElement::toClipPath怎么用?C++ SVGGraphicsElement::toClipPath使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SVGGraphicsElement
的用法示例。
在下文中一共展示了SVGGraphicsElement::toClipPath方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: pathOnlyClipping
bool RenderSVGResourceClipper::pathOnlyClipping(GraphicsContext* context, const AffineTransform& animatedLocalTransform, const FloatRect& objectBoundingBox)
{
// If the current clip-path gets clipped itself, we have to fallback to masking.
if (!style()->svgStyle()->clipperResource().isEmpty())
return false;
WindRule clipRule = RULE_NONZERO;
Path clipPath = Path();
// If clip-path only contains one visible shape or path, we can use path-based clipping. Invisible
// shapes don't affect the clipping and can be ignored. If clip-path contains more than one
// visible shape, the additive clipping may not work, caused by the clipRule. EvenOdd
// as well as NonZero can cause self-clipping of the elements.
// See also http://www.w3.org/TR/SVG/painting.html#FillRuleProperty
for (Node* childNode = clipPathElement().firstChild(); childNode; childNode = childNode->nextSibling()) {
RenderObject* renderer = childNode->renderer();
if (!renderer)
continue;
// Only shapes or paths are supported for direct clipping. We need to fallback to masking for texts.
if (renderer->isSVGText())
return false;
if (!childNode->isSVGElement() || !toSVGElement(childNode)->isSVGGraphicsElement())
continue;
SVGGraphicsElement* styled = toSVGGraphicsElement(childNode);
RenderStyle* style = renderer->style();
if (!style || style->display() == NONE || style->visibility() != VISIBLE)
continue;
const SVGRenderStyle* svgStyle = style->svgStyle();
// Current shape in clip-path gets clipped too. Fallback to masking.
if (!svgStyle->clipperResource().isEmpty())
return false;
// Fallback to masking, if there is more than one clipping path.
if (clipPath.isEmpty()) {
styled->toClipPath(clipPath);
clipRule = svgStyle->clipRule();
} else
return false;
}
// Only one visible shape/path was found. Directly continue clipping and transform the content to userspace if necessary.
if (clipPathElement().clipPathUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX) {
AffineTransform transform;
transform.translate(objectBoundingBox.x(), objectBoundingBox.y());
transform.scaleNonUniform(objectBoundingBox.width(), objectBoundingBox.height());
clipPath.transform(transform);
}
// Transform path by animatedLocalTransform.
clipPath.transform(animatedLocalTransform);
// The SVG specification wants us to clip everything, if clip-path doesn't have a child.
if (clipPath.isEmpty())
clipPath.addRect(FloatRect());
context->clipPath(clipPath, clipRule);
return true;
}
示例2: tryPathOnlyClipping
bool RenderSVGResourceClipper::tryPathOnlyClipping(GraphicsContext* context,
const AffineTransform& animatedLocalTransform, const FloatRect& objectBoundingBox) {
// If the current clip-path gets clipped itself, we have to fallback to masking.
if (!style()->svgStyle().clipperResource().isEmpty())
return false;
WindRule clipRule = RULE_NONZERO;
Path clipPath = Path();
for (SVGElement* childElement = Traversal<SVGElement>::firstChild(*element()); childElement; childElement = Traversal<SVGElement>::nextSibling(*childElement)) {
RenderObject* renderer = childElement->renderer();
if (!renderer)
continue;
// Only shapes or paths are supported for direct clipping. We need to fallback to masking for texts.
if (renderer->isSVGText())
return false;
if (!childElement->isSVGGraphicsElement())
continue;
SVGGraphicsElement* styled = toSVGGraphicsElement(childElement);
RenderStyle* style = renderer->style();
if (!style || style->display() == NONE || style->visibility() != VISIBLE)
continue;
const SVGRenderStyle& svgStyle = style->svgStyle();
// Current shape in clip-path gets clipped too. Fallback to masking.
if (!svgStyle.clipperResource().isEmpty())
return false;
if (clipPath.isEmpty()) {
// First clip shape.
styled->toClipPath(clipPath);
clipRule = svgStyle.clipRule();
clipPath.setWindRule(clipRule);
continue;
}
if (RuntimeEnabledFeatures::pathOpsSVGClippingEnabled()) {
// Attempt to generate a combined clip path, fall back to masking if not possible.
Path subPath;
styled->toClipPath(subPath);
subPath.setWindRule(svgStyle.clipRule());
if (!clipPath.unionPath(subPath))
return false;
} else {
return false;
}
}
// Only one visible shape/path was found. Directly continue clipping and transform the content to userspace if necessary.
if (clipPathUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX) {
AffineTransform transform;
transform.translate(objectBoundingBox.x(), objectBoundingBox.y());
transform.scaleNonUniform(objectBoundingBox.width(), objectBoundingBox.height());
clipPath.transform(transform);
}
// Transform path by animatedLocalTransform.
clipPath.transform(animatedLocalTransform);
// The SVG specification wants us to clip everything, if clip-path doesn't have a child.
if (clipPath.isEmpty())
clipPath.addRect(FloatRect());
context->clipPath(clipPath, clipRule);
return true;
}