Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
shirne committed Jun 9, 2022
1 parent dd24f2a commit 964d6dd
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 31 deletions.
12 changes: 5 additions & 7 deletions lib/src/common/eci_string_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ import 'character_set_eci.dart';
import 'string_builder.dart';

class ECIStringBuilder {
late StringBuffer _currentBytes;
late StringBuffer? _result;
StringBuffer _currentBytes;
StringBuffer? _result;
Encoding _currentCharset = latin1;

ECIStringBuilder() {
_currentBytes = StringBuffer();
}
ECIStringBuilder() : _currentBytes = StringBuffer();

void write(dynamic value) {
if (value is StringBuffer || value is StringBuilder) {
Expand Down Expand Up @@ -52,9 +50,9 @@ class ECIStringBuilder {
List<int> bytes = latin1.encode(_currentBytes.toString());
_currentBytes = StringBuffer();
if (_result == null) {
_result = StringBuffer(latin1.decode(bytes));
_result = StringBuffer(_currentCharset.decode(bytes));
} else {
_result!.write(latin1.decode(bytes));
_result!.write(_currentCharset.decode(bytes));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/pdf417/decoder/decoded_bit_stream_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ class DecodedBitStreamParser {
codeIndex < codewords[0] &&
codewords[codeIndex] < _TEXT_COMPACTION_MODE_LATCH)) {
for (int i = 0; i < 6; i++) {
result.writeCharCode((value >> (8 * (5 - i))));
result.writeCharCode((value >> (8 * (5 - i))) & 0xff);
}
} else {
codeIndex -= count;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/pdf417/encoder/pdf417_high_level_encoder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ class PDF417HighLevelEncoder {
input = NoECIInput(msg);
if (encoding == null) {
encoding = _defaultEncoding;
} else if (_defaultEncoding != encoding) {
} else if (_defaultEncoding.name != encoding.name) {
CharacterSetECI? eci = CharacterSetECI.getCharacterSetECI(encoding);
if (eci != null) {
_encodingECI(eci.value, sb);
Expand Down
33 changes: 11 additions & 22 deletions test/core/pdf417/decoder/pdf417_decoder_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,6 @@ void main() {
}
}

void testUppercaseLowercaseNumericMix() {
performPermutationTest('Aa1'.codeUnits, 7, 15491);
}

String generateText(
math.Random random, int maxWidth, List<int> chars, List<double> weights) {
StringBuffer result = StringBuffer();
Expand Down Expand Up @@ -383,6 +379,10 @@ void main() {
['a', '\u00c4'].map((e) => e.codeUnitAt(0)).toList(), 10, 11233);
});

test('testUppercaseLowercaseNumericMix', () {
performPermutationTest('Aa1'.codeUnits, 7, 15491);
});

test('testUppercaseLowercasePunctuationMix', () {
performPermutationTest(
['A', 'a', ';'].map((e) => e.codeUnitAt(0)).toList(), 7, 15491);
Expand Down Expand Up @@ -483,23 +483,12 @@ void main() {
performDecodeTest(
[14, 927, 4, 901, 200, 927, 7, 207, 927, 4, 200, 927, 7, 207],
"\u010c\u042f\u010c\u042f");
performDecodeTest([
16,
927,
4,
924,
336,
432,
197,
51,
300,
927,
7,
348,
231,
311,
858,
567
], "\u010c\u010c\u010c\u010c\u010c\u010c\u042f\u042f\u042f\u042f\u042f\u042f");
performDecodeTest(
[
16, 927, 4, 924, 336, 432, 197, 51, 300, 927, 7, 348, 231, 311, 858,
567 //
],
"\u010c\u010c\u010c\u010c\u010c\u010c\u042f\u042f\u042f\u042f\u042f\u042f",
);
});
}

0 comments on commit 964d6dd

Please sign in to comment.