$applyPaint method

  1. @override
void $applyPaint(
  1. Canvas? canvas
)
override

(Internal usage) Applies the current paint to the canvas, drawing the glyph using a ui.Paint object, updating it if necessary.

This method overrides the base implementation to avoid using a shape renderer to draw the glyph. Instead, it directly draws the glyph using a ui.Canvas object and a ui.Paint object.

The paint object used to draw the glyph is updated only if necessary. The method checks if any of the style properties have changed (such as color, size, font family, font variations, etc.). If any change is detected, _updateStyle() is called to update the style.

Once the style is updated, the method draws the glyph using a ui.ParagraphBuilder object and a ui.Paragraph object, which are created by _updateStyle(). Finally, it draws the paragraph to the canvas using the ui.Canvas.drawParagraph() method.

Note that the paragraph is always drawn at the origin, so its position must be transformed by the transformation matrix to get the final position of the glyph.

Implementation

@override
void $applyPaint(ui.Canvas? canvas) {
  if (data == null) return;
  if (_invalidStyle) {
    _invalidStyle = false;
    _updateStyle();
  }
  if (_paragraph != null) {
    canvas!.drawParagraph(_paragraph!, ui.Offset.zero);
  }
}