fromRect static method

XmlElement fromRect(
  1. XmlElement rectTag
)

Converts a rect element into a path element.

Implementation

static XmlElement fromRect(XmlElement rectTag) {
  final filterAttributes = [
    AttributeName.x,
    AttributeName.y,
    AttributeName.width,
    AttributeName.height,
    AttributeName.rx,
    AttributeName.ry,
  ];

  final x = _getAttribute(rectTag, AttributeName.x);
  final y = _getAttribute(rectTag, AttributeName.y);
  final w = _getAttribute(rectTag, AttributeName.width);
  final h = _getAttribute(rectTag, AttributeName.height);
  var rx = _getAttribute(rectTag, AttributeName.rx);
  var ry = _getAttribute(rectTag, AttributeName.ry);
  final r = _c(x + w);
  final b = _c(y + h);

  if (ry == 0) {
    ry = rx;
  } else if (rx == 0) {
    rx = ry;
  }

  return rx == 0 && ry == 0
      ? _buildPath('M $x $y H $r V $b H $x V $y Z', rectTag, filterAttributes)
      : _buildPath(
          'M ${_c(x + rx)} $y '
          'L ${_c(r - rx)} $y '
          'Q $r $y $r ${_c(y + ry)} '
          'L $r ${_c(y + h - ry)} '
          'Q $r $b ${_c(r - rx)} $b '
          'L ${_c(x + rx)} $b '
          'Q $x $b $x ${_c(b - ry)} '
          'L $x ${_c(y + ry)} '
          'Q $x $y ${_c(x + rx)} $y '
          'Z',
          rectTag,
          filterAttributes,
        );
}