text method

PrintBuilder text(
  1. String text, {
  2. AlignPos align = AlignPos.left,
  3. FontSize fontSize = FontSize.normal,
  4. bool bold = false,
  5. bool underline = false,
})

Implementation

PrintBuilder text(
    String text, {
      AlignPos align = AlignPos.left,
      FontSize fontSize = FontSize.normal,
      bool bold = false,
      bool underline = false,
    }) {
  // Set alignment
  switch (align) {
    case AlignPos.left:
      _bytes.addAll(ESCPOSCommands.alignLeft);
      break;
    case AlignPos.center:
      _bytes.addAll(ESCPOSCommands.alignCenter);
      break;
    case AlignPos.right:
      _bytes.addAll(ESCPOSCommands.alignRight);
      break;
  }

  // Set font size
  switch (fontSize) {
    case FontSize.normal:
      _bytes.addAll(ESCPOSCommands.fontNormal);
      break;
    case FontSize.compressed:
      _bytes.addAll(ESCPOSCommands.fontCompressed);
      break;
    case FontSize.doubleWidth:
      _bytes.addAll(ESCPOSCommands.fontDoubleWidth);
      break;
    case FontSize.doubleHeight:
      _bytes.addAll(ESCPOSCommands.fontDoubleHeight);
      break;
    case FontSize.big:
      _bytes.addAll(ESCPOSCommands.fontBig);
      break;
  }

  // Set styling
  if (bold) _bytes.addAll(ESCPOSCommands.boldOn);
  if (underline) _bytes.addAll(ESCPOSCommands.underlineOn);

  // Add text
  _bytes.addAll(utf8.encode(text));
  _bytes.add(0x0A); // Line feed

  // Reset styling
  if (bold) _bytes.addAll(ESCPOSCommands.boldOff);
  if (underline) _bytes.addAll(ESCPOSCommands.underlineOff);

  return this;
}