paintText method

void paintText(
  1. PaintingContext context,
  2. Offset offset,
  3. BarcodeText element
)

Implementation

void paintText(PaintingContext context, Offset offset, BarcodeText element) {
  TextAlign? align;
  switch (element.align) {
    case BarcodeTextAlign.left:
      align = TextAlign.left;
      break;
    case BarcodeTextAlign.center:
      align = TextAlign.center;
      break;
    case BarcodeTextAlign.right:
      align = TextAlign.right;
      break;
  }

  final builder = ui.ParagraphBuilder(
    style!.getParagraphStyle(
        textAlign: align,
        fontSize: element.height,
        maxLines: 1,
        ellipsis: '...'),
  )
    ..pushStyle(style!.getTextStyle())
    ..addText(element.text);

  final paragraph = builder.build();
  paragraph.layout(ui.ParagraphConstraints(width: element.width));

  context.canvas.drawParagraph(
    paragraph,
    Offset(
        offset.dx + element.left,
        offset.dy +
            element.top +
            paragraph.alphabeticBaseline -
            paragraph.height),
  );
}