createDiagramParagraph function

TextPainter createDiagramParagraph(
  1. List<TextRun> runs,
  2. TextRole role,
  3. DiagramColor foreground,
  4. ParagraphAlignment alignment, {
  5. required double fontSize,
  6. ParagraphDirection direction = ParagraphDirection.ltr,
  7. double defaultFontSize = diagramDefaultFontSize,
  8. int? maxLines,
  9. double? lineHeight,
})

Implementation

TextPainter createDiagramParagraph(
  List<TextRun> runs,
  TextRole role,
  DiagramColor foreground,
  ParagraphAlignment alignment, {
  required double fontSize,
  ParagraphDirection direction = ParagraphDirection.ltr,
  double defaultFontSize = diagramDefaultFontSize,
  int? maxLines,
  double? lineHeight,
}) => TextPainter(
  text: TextSpan(
    style: diagramTextRunStyle(
      TextRun('', fontSize: fontSize),
      role,
      foreground,
    ),
    children: [
      for (final run in runs)
        TextSpan(
          text: run.text,
          style: diagramTextRunStyle(
            run,
            role,
            foreground,
            defaultFontSize: defaultFontSize,
          ),
        ),
    ],
  ),
  textDirection: direction == ParagraphDirection.rtl
      ? TextDirection.rtl
      : TextDirection.ltr,
  textAlign: switch (alignment) {
    ParagraphAlignment.start => TextAlign.start,
    ParagraphAlignment.center => TextAlign.center,
    ParagraphAlignment.end => TextAlign.end,
    ParagraphAlignment.justify => TextAlign.justify,
  },
  maxLines: maxLines,
  strutStyle: StrutStyle(
    fontSize: fontSize,
    height: lineHeight == null
        ? diagramDefaultTextHeight
        : lineHeight / fontSize,
    forceStrutHeight: lineHeight != null,
  ),
);