toOperators method

String toOperators()

Convert path to PDF content stream operators.

Implementation

String toOperators() {
  final buffer = StringBuffer();
  for (final seg in _segments) {
    switch (seg.op) {
      case _PathOp.moveTo:
        buffer.writeln(
            '${_fmt(seg.points[0])} ${_fmt(seg.points[1])} m');
        break;
      case _PathOp.lineTo:
        buffer.writeln(
            '${_fmt(seg.points[0])} ${_fmt(seg.points[1])} l');
        break;
      case _PathOp.curveTo:
        buffer.writeln(
            '${_fmt(seg.points[0])} ${_fmt(seg.points[1])} '
            '${_fmt(seg.points[2])} ${_fmt(seg.points[3])} '
            '${_fmt(seg.points[4])} ${_fmt(seg.points[5])} c');
        break;
      case _PathOp.close:
        buffer.writeln('h');
        break;
      case _PathOp.rectangle:
        buffer.writeln(
            '${_fmt(seg.points[0])} ${_fmt(seg.points[1])} '
            '${_fmt(seg.points[2])} ${_fmt(seg.points[3])} re');
        break;
    }
  }
  return buffer.toString();
}