Skip to content

Commit

Permalink
[BUGFIX] Wrong left offset when spacers disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolaVerbeeck committed Apr 29, 2024
1 parent 067964d commit ed06e3f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
4 changes: 4 additions & 0 deletions barcode/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 2.2.9

- Fixed wrong left text position for CODE 39 with spacers disabled [NicolaVerbeeck]

## 2.2.8

- Add option to turn off spacers for CODE 39 [NicolaVerbeeck]
Expand Down
3 changes: 2 additions & 1 deletion barcode/lib/src/code39.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,10 @@ class BarcodeCode39 extends Barcode1D {
) sync* {
final text = drawSpacers ? '*$data*' : data;

final additionalOffset = drawSpacers ? 0 : 1;
for (var i = 0; i < text.length; i++) {
yield BarcodeText(
left: lineWidth * BarcodeMaps.code39Len * i,
left: lineWidth * BarcodeMaps.code39Len * (i + additionalOffset),
top: height - fontHeight,
width: lineWidth * BarcodeMaps.code39Len,
height: fontHeight,
Expand Down
2 changes: 1 addition & 1 deletion barcode/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description: >-
homepage: https://github.com/DavBfr/dart_barcode/tree/master/barcode
repository: https://github.com/DavBfr/dart_barcode
issue_tracker: https://github.com/DavBfr/dart_barcode/issues
version: 2.2.8
version: 2.2.9

environment:
sdk: ">=2.12.0 <4.0.0"
Expand Down
4 changes: 4 additions & 0 deletions barcode/test/code39_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ void main() {

final textElements = elements.whereType<BarcodeText>();

// If we don't draw spacers, the text starts after the imaginary first spacer
expect(textElements.first.left, isNonZero);
expect(textElements.any((element) => element.text.contains('*')), false);
});

Expand All @@ -84,6 +86,8 @@ void main() {

final textElements = elements.whereType<BarcodeText>();

// If we do draw spacers, the text starts at the start of the barcode
expect(textElements.first.left, isZero);
expect(textElements.first.text, '*');
expect(textElements.last.text, '*');
});
Expand Down

0 comments on commit ed06e3f

Please sign in to comment.