Skip to content

Commit

Permalink
Merge pull request #13 from iandis/fix/remove-receipt-vertical-padding
Browse files Browse the repository at this point in the history
fix(receipt): remove receipt vertical padding
  • Loading branch information
iandis committed Sep 30, 2022
2 parents 738db9e + f947827 commit cb2bda8
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
27 changes: 25 additions & 2 deletions lib/blue_print_pos.dart
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,36 @@ class BluePrintPos {
batchOptions.getStartEnd(contentLength);

for (final List<int> startEnd in startEndIter) {
final ReceiptSectionText section = receiptSectionText.getSection(
startEnd[0],
startEnd[1],
);
// This is to prevent cropped section at the bottom
if (Platform.isIOS) {
section.addSpacerPx(15);
}
final Uint8List bytes = await contentToImage(
content: receiptSectionText.getContent(startEnd[0], startEnd[1]),
content: section.getContent(),
duration: duration,
textScaleFactor: textScaleFactor,
);
List<int>? croppedExcessTop;
// This is to remove the excess top
if (Platform.isIOS) {
final img.Image? image = img.decodeImage(bytes);
if (image != null) {
final img.Image cropped = img.copyCrop(
image,
0,
45,
image.width,
image.height - 45,
);
croppedExcessTop = img.encodeJpg(cropped);
}
}
final List<int> byteBuffer = await _getBytes(
bytes,
croppedExcessTop ?? bytes,
paperSize: paperSize,
feedCount: feedCount,
useCut: useCut,
Expand Down
2 changes: 1 addition & 1 deletion lib/receipt/collection_style.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class CollectionStyle {
}
.container {
padding: 5px 15px;
padding: 0px 15px;
}
hr {
Expand Down
10 changes: 8 additions & 2 deletions lib/receipt/receipt_section_text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ import 'receipt_text_style.dart';
import 'receipt_text_style_type.dart';

class ReceiptSectionText {
ReceiptSectionText();
ReceiptSectionText() : _data = <String>[];

final List<String> _data = <String>[];
ReceiptSectionText._(this._data);

final List<String> _data;

int get contentLength => _data.length;

Expand Down Expand Up @@ -47,6 +49,10 @@ ${CollectionStyle.all}
''';
}

ReceiptSectionText getSection([int start = 0, int? end]) {
return ReceiptSectionText._(_data.sublist(start, end));
}

/// Handler tag of text (p or b) and put inside body html
/// This will generate single line text left, center or right
/// [text] value of text will print
Expand Down

0 comments on commit cb2bda8

Please sign in to comment.