SvgClipPath.fromXml constructor

SvgClipPath.fromXml(
  1. XmlElement element,
  2. SvgPainter painter,
  3. SvgBrush brush
)

Implementation

factory SvgClipPath.fromXml(
    XmlElement element, SvgPainter painter, SvgBrush brush) {
  final clipPathAttr = element.getAttribute('clip-path');
  if (clipPathAttr == null) {
    return const SvgClipPath(null, true, null);
  }

  Iterable<SvgOperation?> children;

  if (clipPathAttr.startsWith('url(#')) {
    final id = clipPathAttr.substring(5, clipPathAttr.lastIndexOf(')'));
    final clipPath = painter.parser.findById(id);
    if (clipPath != null) {
      children = clipPath.children
          .whereType<XmlElement>()
          .map<SvgOperation?>((c) => SvgOperation.fromXml(c, painter, brush));
      return SvgClipPath(children, false, painter);
    }
  }

  return const SvgClipPath(null, true, null);
}