Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX] Wrong left offset when spacers disabled #71

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading