SvgPath.fromRectXml constructor

SvgPath.fromRectXml(
  1. XmlElement element,
  2. SvgPainter painter,
  3. SvgBrush brush
)

Implementation

factory SvgPath.fromRectXml(
  XmlElement element,
  SvgPainter painter,
  SvgBrush brush,
) {
  final _brush = SvgBrush.fromXml(element, brush, painter);

  final x =
      SvgParser.getNumeric(element, 'x', _brush, defaultValue: 0)!.sizeValue;
  final y =
      SvgParser.getNumeric(element, 'y', _brush, defaultValue: 0)!.sizeValue;
  final width =
      SvgParser.getNumeric(element, 'width', _brush, defaultValue: 0)!
          .sizeValue;
  final height =
      SvgParser.getNumeric(element, 'height', _brush, defaultValue: 0)!
          .sizeValue;
  var rx = SvgParser.getNumeric(element, 'rx', _brush)?.sizeValue;
  var ry = SvgParser.getNumeric(element, 'ry', _brush)?.sizeValue;

  ry ??= rx ?? 0;
  rx ??= ry;
  final topRight = rx != 0 || ry != 0 ? 'a $rx $ry 0 0 1 $rx $ry' : '';
  final bottomRight = rx != 0 || ry != 0 ? 'a $rx $ry 0 0 1 ${-rx} $ry' : '';
  final bottomLeft =
      rx != 0 || ry != 0 ? 'a $rx $ry 0 0 1 ${-rx} ${-ry}' : '';
  final topLeft = rx != 0 || ry != 0 ? 'a $rx $ry 0 0 1 $rx ${-ry}' : '';
  final d =
      'M${x + rx} ${y}h${width - rx * 2}${topRight}v${height - ry * 2}${bottomRight}h${-(width - rx * 2)}${bottomLeft}v${-(height - ry * 2)}${topLeft}z';

  return SvgPath(
    d,
    _brush,
    SvgClipPath.fromXml(element, painter, _brush),
    SvgTransform.fromXml(element),
    painter,
  );
}