drawText method

  1. @override
void drawText(
  1. String text,
  2. num x,
  3. num y,
  4. PFont font,
  5. PStyle style,
)
override

Draw a text at position (x,y).

Implementation

@override
void drawText(String text, num x, num y, PFont font, PStyle style) {
  var xd = transform.xD(x);
  var yd = transform.yD(y);

  xd = canvasXD(xd);
  yd = canvasYD(yd);

  final textStyle =
      font.toTextStyle(color: style.color, pixelRatio: pixelRatio);
  final textSpan = TextSpan(text: text, style: textStyle);

  final textPainter =
      TextPainter(text: textSpan, textDirection: TextDirection.ltr)
        ..layout(minWidth: 0, maxWidth: double.infinity);

  _widgetPainter.addOp((canvas, size) {
    textPainter.paint(canvas, Offset(xd, yd));
  });
}