From ed06e3fa57fbc0202acc55f93723ad81af7d6335 Mon Sep 17 00:00:00 2001 From: Nicola Verbeeck Date: Mon, 29 Apr 2024 15:26:41 +0200 Subject: [PATCH] [BUGFIX] Wrong left offset when spacers disabled --- barcode/CHANGELOG.md | 4 ++++ barcode/lib/src/code39.dart | 3 ++- barcode/pubspec.yaml | 2 +- barcode/test/code39_test.dart | 4 ++++ 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/barcode/CHANGELOG.md b/barcode/CHANGELOG.md index 49d295d..b166ec5 100644 --- a/barcode/CHANGELOG.md +++ b/barcode/CHANGELOG.md @@ -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] diff --git a/barcode/lib/src/code39.dart b/barcode/lib/src/code39.dart index 844166a..39da0e6 100644 --- a/barcode/lib/src/code39.dart +++ b/barcode/lib/src/code39.dart @@ -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, diff --git a/barcode/pubspec.yaml b/barcode/pubspec.yaml index 24371a3..48a8a24 100644 --- a/barcode/pubspec.yaml +++ b/barcode/pubspec.yaml @@ -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" diff --git a/barcode/test/code39_test.dart b/barcode/test/code39_test.dart index e24c114..9ffd10a 100644 --- a/barcode/test/code39_test.dart +++ b/barcode/test/code39_test.dart @@ -74,6 +74,8 @@ void main() { final textElements = elements.whereType(); + // 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); }); @@ -84,6 +86,8 @@ void main() { final textElements = elements.whereType(); + // 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, '*'); });