buildParagraph method

Paragraph buildParagraph(
  1. ChantContext ctxt,
  2. Map<String, dynamic> extraProps,
  3. TextAlign textAlign, [
  4. double? resize,
])

Builds and caches the Paragraph for this span.

Implementation

Paragraph buildParagraph(
  ChantContext ctxt,
  Map<String, dynamic> extraProps,
  TextAlign textAlign, [
  double? resize,
]) {
  // The paragraph depends only on the text and its style inputs; cache it
  // so repeated draws (hover, pan/zoom) skip ParagraphBuilder entirely.
  final key = Object.hash(
    _text,
    textAlign,
    resize,
    extraProps['fill'],
    extraProps['font-size'],
    extraProps['base-font-size'],
    extraProps['font-family'],
    extraProps['base-font-family'],
    extraProps['font-style'],
    extraProps['font-weight'],
    extraProps['font-variant'],
    extraProps['line-height'],
  );
  final cached = _cachedParagraph;
  if (cached != null && _cachedParagraphKey == key) return cached;

  final builder =
      ParagraphBuilder(
          ParagraphStyle(
            textAlign: textAlign,
            textDirection: TextDirection.ltr,
          ),
        )
        ..pushStyle(getTextStyle(extraProps, ctxt, resize))
        ..addText(_text);

  final paragraph = builder.build();
  _cachedParagraph = paragraph;
  _cachedParagraphKey = key;
  // A freshly built paragraph has never been laid out; force the next
  // draw to run layout before drawParagraph (which asserts _needsLayout).
  _lastLayoutWidth = -1;
  return paragraph;
}