Skip to content

Commit

Permalink
CodablockF: include check digit count in total count from start
Browse files Browse the repository at this point in the history
  • Loading branch information
gredler committed Nov 23, 2024
1 parent e13ff59 commit 6ee39b5
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/main/java/uk/org/okapibarcode/backend/CodablockF.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,10 @@ protected void encode() {
throw OkapiInputException.inputTooLong();
}

/* Make a guess at how many characters will be needed to encode the data */
estimate_codelength = 0.0;
last_mode = Mode.AORB; /* Codablock always starts with Code A */
// guess how many characters will be needed to encode the data,
// we need two characters right off the bat for the check digits
estimate_codelength = 2.0;
last_mode = Mode.AORB; // Codablock always starts with Code A
for (i = 0; i < input_length; i++) {
this_mode = findSubset(inputData[i]);
if (this_mode != last_mode) {
Expand All @@ -123,14 +124,14 @@ protected void encode() {
}

/* Decide symbol size based on the above guess */
rows = (int) (0.5 + Math.sqrt((estimate_codelength + 2) / 1.45));
rows = (int) (0.5 + Math.sqrt(estimate_codelength / 1.45));
if (rows < 2) {
rows = 2;
}
if (rows > 44) {
rows = 44;
}
columns = (int) (estimate_codelength + 2) / rows;
columns = (int) estimate_codelength / rows;
if (columns < 4) {
columns = 4;
}
Expand Down

0 comments on commit 6ee39b5

Please sign in to comment.