mirror of
https://github.com/zxing/zxing.git
synced 2024-09-19 21:17:33 -07:00
Minor code tweaks
This commit is contained in:
parent
2e22d09479
commit
6c034f9775
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,3 +1,4 @@
|
||||||
|
dependency-reduced-pom.xml
|
||||||
target
|
target
|
||||||
.idea
|
.idea
|
||||||
*.iml
|
*.iml
|
||||||
|
|
|
@ -169,8 +169,7 @@ final class MinimalEncoder {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (neededEncoders.size() == 1 && !needUnicodeEncoder) {
|
if (neededEncoders.size() == 1 && !needUnicodeEncoder) {
|
||||||
encoders = new CharsetEncoder[1];
|
encoders = new CharsetEncoder[] { neededEncoders.get(0) };
|
||||||
encoders[0] = neededEncoders.get(0);
|
|
||||||
} else {
|
} else {
|
||||||
encoders = new CharsetEncoder[neededEncoders.size() + 2];
|
encoders = new CharsetEncoder[neededEncoders.size() + 2];
|
||||||
int index = 0;
|
int index = 0;
|
||||||
|
@ -185,7 +184,7 @@ final class MinimalEncoder {
|
||||||
int priorityEncoderIndexValue = -1;
|
int priorityEncoderIndexValue = -1;
|
||||||
if (priorityCharset != null) {
|
if (priorityCharset != null) {
|
||||||
for (int i = 0; i < encoders.length; i++) {
|
for (int i = 0; i < encoders.length; i++) {
|
||||||
if (priorityCharset.name().equals(encoders[i].charset().name())) {
|
if (encoders[i] != null && priorityCharset.name().equals(encoders[i].charset().name())) {
|
||||||
priorityEncoderIndexValue = i;
|
priorityEncoderIndexValue = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -275,15 +274,6 @@ final class MinimalEncoder {
|
||||||
return Encoder.getAlphanumericCode(c) != -1;
|
return Encoder.getAlphanumericCode(c) != -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the maximum number of encodeable characters in the given mode for the given version. Example: in
|
|
||||||
* Version 1, 2^10 digits or 2^8 bytes can be encoded. In Version 3 it is 2^14 digits and 2^16 bytes
|
|
||||||
*/
|
|
||||||
static int getMaximumNumberOfEncodeableCharacters(Version version, Mode mode) {
|
|
||||||
int count = mode.getCharacterCountBits(version);
|
|
||||||
return count == 0 ? 0 : 1 << count;
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean canEncode(Mode mode, char c) {
|
boolean canEncode(Mode mode, char c) {
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case KANJI: return isDoubleByteKanji(c);
|
case KANJI: return isDoubleByteKanji(c);
|
||||||
|
@ -533,8 +523,9 @@ final class MinimalEncoder {
|
||||||
private final int characterLength;
|
private final int characterLength;
|
||||||
private final Edge previous;
|
private final Edge previous;
|
||||||
private final int cachedTotalSize;
|
private final int cachedTotalSize;
|
||||||
|
|
||||||
private Edge(Mode mode, int fromPosition, int charsetEncoderIndex, int characterLength, Edge previous,
|
private Edge(Mode mode, int fromPosition, int charsetEncoderIndex, int characterLength, Edge previous,
|
||||||
Version version) {
|
Version version) {
|
||||||
this.mode = mode;
|
this.mode = mode;
|
||||||
this.fromPosition = fromPosition;
|
this.fromPosition = fromPosition;
|
||||||
this.charsetEncoderIndex = mode == Mode.BYTE || previous == null ? charsetEncoderIndex :
|
this.charsetEncoderIndex = mode == Mode.BYTE || previous == null ? charsetEncoderIndex :
|
||||||
|
@ -573,9 +564,10 @@ final class MinimalEncoder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final class ResultList extends ArrayList<ResultList.ResultNode> {
|
final class ResultList {
|
||||||
|
|
||||||
final Version version;
|
private final List<ResultList.ResultNode> list = new ArrayList<>();
|
||||||
|
private final Version version;
|
||||||
|
|
||||||
ResultList(Version version, Edge solution) {
|
ResultList(Version version, Edge solution) {
|
||||||
int length = 0;
|
int length = 0;
|
||||||
|
@ -595,12 +587,12 @@ final class MinimalEncoder {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (previous == null || previous.mode != current.mode || needECI) {
|
if (previous == null || previous.mode != current.mode || needECI) {
|
||||||
add(0, new ResultNode(current.mode, current.fromPosition, current.charsetEncoderIndex, length));
|
list.add(0, new ResultNode(current.mode, current.fromPosition, current.charsetEncoderIndex, length));
|
||||||
length = 0;
|
length = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (needECI) {
|
if (needECI) {
|
||||||
add(0, new ResultNode(Mode.ECI, current.fromPosition, current.charsetEncoderIndex, 0));
|
list.add(0, new ResultNode(Mode.ECI, current.fromPosition, current.charsetEncoderIndex, 0));
|
||||||
}
|
}
|
||||||
current = previous;
|
current = previous;
|
||||||
}
|
}
|
||||||
|
@ -608,14 +600,14 @@ final class MinimalEncoder {
|
||||||
// prepend FNC1 if needed. If the bits contain an ECI then the FNC1 must be preceeded by an ECI.
|
// prepend FNC1 if needed. If the bits contain an ECI then the FNC1 must be preceeded by an ECI.
|
||||||
// If there is no ECI at the beginning then we put an ECI to the default charset (ISO-8859-1)
|
// If there is no ECI at the beginning then we put an ECI to the default charset (ISO-8859-1)
|
||||||
if (isGS1) {
|
if (isGS1) {
|
||||||
ResultNode first = get(0);
|
ResultNode first = list.get(0);
|
||||||
if (first != null && first.mode != Mode.ECI && containsECI) {
|
if (first != null && first.mode != Mode.ECI && containsECI) {
|
||||||
// prepend a default character set ECI
|
// prepend a default character set ECI
|
||||||
add(0, new ResultNode(Mode.ECI, 0, 0, 0));
|
list.add(0, new ResultNode(Mode.ECI, 0, 0, 0));
|
||||||
}
|
}
|
||||||
first = get(0);
|
first = list.get(0);
|
||||||
// prepend or insert a FNC1_FIRST_POSITION after the ECI (if any)
|
// prepend or insert a FNC1_FIRST_POSITION after the ECI (if any)
|
||||||
add(first.mode != Mode.ECI ? 0 : 1, new ResultNode(Mode.FNC1_FIRST_POSITION, 0, 0, 0));
|
list.add(first.mode != Mode.ECI ? 0 : 1, new ResultNode(Mode.FNC1_FIRST_POSITION, 0, 0, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
// set version to smallest version into which the bits fit.
|
// set version to smallest version into which the bits fit.
|
||||||
|
@ -660,7 +652,7 @@ final class MinimalEncoder {
|
||||||
|
|
||||||
private int getSize(Version version) {
|
private int getSize(Version version) {
|
||||||
int result = 0;
|
int result = 0;
|
||||||
for (ResultNode resultNode : this) {
|
for (ResultNode resultNode : list) {
|
||||||
result += resultNode.getSize(version);
|
result += resultNode.getSize(version);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
@ -670,7 +662,7 @@ final class MinimalEncoder {
|
||||||
* appends the bits
|
* appends the bits
|
||||||
*/
|
*/
|
||||||
void getBits(BitArray bits) throws WriterException {
|
void getBits(BitArray bits) throws WriterException {
|
||||||
for (ResultNode resultNode : this) {
|
for (ResultNode resultNode : list) {
|
||||||
resultNode.getBits(bits);
|
resultNode.getBits(bits);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -682,7 +674,7 @@ final class MinimalEncoder {
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuilder result = new StringBuilder();
|
StringBuilder result = new StringBuilder();
|
||||||
ResultNode previous = null;
|
ResultNode previous = null;
|
||||||
for (ResultNode current : this) {
|
for (ResultNode current : list) {
|
||||||
if (previous != null) {
|
if (previous != null) {
|
||||||
result.append(",");
|
result.append(",");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue