andrey-ushakov / esc_pos_utils

Basic Flutter/Dart classes for ESC/POS printing
BSD 3-Clause "New" or "Revised" License
151 stars 339 forks source link

Fix CJK(Chinese, Japanese, Korean) PosAlign.right bug. #63

Open ttyniwa opened 3 years ago

ttyniwa commented 3 years ago

Please merge #62 first.

Overview

The following code will be printed across two lines due to wrong alignment.

    bytes += ticket.row([
      PosColumn(
          text: 'R右R',
          width: 12,
          styles: PosStyles(align: PosAlign.right),
          containsCjk: true),

Test

The receipt on the right is before the bug was fixed. left is after the bug fixed. IMG_3421

Tested with below code.

  Future<List<int>> debugCjk(PaperSize paper, CapabilityProfile profile) async {
    final Generator ticket = Generator(paper, profile);
    List<int> bytes = [];

    bytes += ticket.text(
      '漢字ひらがなカタカナ',
      styles: PosStyles(
        align: PosAlign.center,
        height: PosTextSize.size2,
        width: PosTextSize.size2,
      ),
      containsCjk: true,
    );

    bytes += ticket.text(
      'L左L',
      styles: PosStyles(align: PosAlign.left),
      containsCjk: true,
    );
    bytes += ticket.text(
      'C中央C',
      styles: PosStyles(align: PosAlign.center),
      containsCjk: true,
    );
    bytes += ticket.text(
      'R右R',
      styles: PosStyles(align: PosAlign.right),
      containsCjk: true,
    );

    bytes += ticket.row([
      PosColumn(
          text: 'L左L',
          width: 4,
          styles: PosStyles(align: PosAlign.left),
          containsCjk: true),
      PosColumn(
          text: 'L左L',
          width: 4,
          styles: PosStyles(align: PosAlign.left),
          containsCjk: true),
      PosColumn(
          text: 'L左L',
          width: 4,
          styles: PosStyles(align: PosAlign.left),
          containsCjk: true),
    ]);
    bytes += ticket.row([
      PosColumn(
          text: 'C中央C',
          width: 4,
          styles: PosStyles(align: PosAlign.center),
          containsCjk: true),
      PosColumn(
          text: 'C中央C',
          width: 4,
          styles: PosStyles(align: PosAlign.center),
          containsCjk: true),
      PosColumn(
          text: 'C中央C',
          width: 4,
          styles: PosStyles(align: PosAlign.center),
          containsCjk: true),
    ]);
    bytes += ticket.row([
      PosColumn(
          text: 'R右R',
          width: 4,
          styles: PosStyles(align: PosAlign.right),
          containsCjk: true),
      PosColumn(
          text: 'R右R',
          width: 4,
          styles: PosStyles(align: PosAlign.right),
          containsCjk: true),
      PosColumn(
          text: 'R右R',
          width: 4,
          styles: PosStyles(align: PosAlign.right),
          containsCjk: true),
    ]);

    bytes += ticket.row([
      PosColumn(
          text: 'left', width: 4, styles: PosStyles(align: PosAlign.left)),
      PosColumn(
          text: 'left', width: 4, styles: PosStyles(align: PosAlign.left)),
      PosColumn(
          text: 'left', width: 4, styles: PosStyles(align: PosAlign.left)),
    ]);
    bytes += ticket.row([
      PosColumn(
          text: 'center', width: 4, styles: PosStyles(align: PosAlign.center)),
      PosColumn(
          text: 'center', width: 4, styles: PosStyles(align: PosAlign.center)),
      PosColumn(
          text: 'center', width: 4, styles: PosStyles(align: PosAlign.center)),
    ]);
    bytes += ticket.row([
      PosColumn(
          text: 'right', width: 4, styles: PosStyles(align: PosAlign.right)),
      PosColumn(
          text: 'right', width: 4, styles: PosStyles(align: PosAlign.right)),
      PosColumn(
          text: 'right', width: 4, styles: PosStyles(align: PosAlign.right)),
    ]);

    ticket.feed(1);
    ticket.cut();
    return bytes;
  }
ttyniwa commented 3 years ago

@andrey-ushakov Could you merge #62 & #63 and release?