diff options
| author | François Tiercelin <francois.tiercelin@hpe.com> | 2024-11-17 19:25:04 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-11-17 19:25:04 +0300 |
| commit | 2dfb2054af1e1872ac5354e6d8218931fb88e021 (patch) | |
| tree | ddc39ce5511c75881eb3a39c5464ded533d1014b /core/src/main/java | |
| parent | 3b189fc700c9c7c210f4b78fc66b01f4c13ae5d2 (diff) | |
| download | zxing-2dfb2054af1e1872ac5354e6d8218931fb88e021.tar.xz | |
Fixing issue #1831 (#1879)
* throw a more explicit exception when trying to PDF417/TEXT encode something outside of 0...255
* refactor PDF417HighLevelEncoder to avoid code duplication
extend UT to new method PDF417HighLevelEncoder#checkCharset
* fix javadoc typo
make UT more stringent on PDF417HighLevelEncoder#checkCharset
* restrict TEXT to 0...127
test with CP437 and Greek chars
* reinstate testEncodeAuto UT
* refactor testEncodeAuto UT
* address codacy findings
* formatting
* fix issue #1831
make PDF417#determineDimensions to enable finer UT
add UT coverage to validate fix for #1831
* fix javadoc for PDF417#determineDimensions
remove stacktrace when UT fails
* make UT Java 8 compliant
Diffstat (limited to 'core/src/main/java')
| -rw-r--r-- | core/src/main/java/com/google/zxing/pdf417/encoder/PDF417.java | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/core/src/main/java/com/google/zxing/pdf417/encoder/PDF417.java b/core/src/main/java/com/google/zxing/pdf417/encoder/PDF417.java index a9d63dc23..3402bb3d1 100644 --- a/core/src/main/java/com/google/zxing/pdf417/encoder/PDF417.java +++ b/core/src/main/java/com/google/zxing/pdf417/encoder/PDF417.java @@ -659,7 +659,8 @@ public final class PDF417 { String highLevel = PDF417HighLevelEncoder.encodeHighLevel(msg, compaction, encoding, autoECI); int sourceCodeWords = highLevel.length(); - int[] dimension = determineDimensions(sourceCodeWords, errorCorrectionCodeWords); + int[] dimension = determineDimensions(minCols, maxCols, minRows, maxRows, + sourceCodeWords, errorCorrectionCodeWords); int cols = dimension[0]; int rows = dimension[1]; @@ -692,16 +693,25 @@ public final class PDF417 { * Determine optimal nr of columns and rows for the specified number of * codewords. * + * @param minCols minimum number of columns + * @param maxCols maximum number of columns + * @param minRows minimum number of rows + * @param maxRows maximum number of rows * @param sourceCodeWords number of code words * @param errorCorrectionCodeWords number of error correction code words * @return dimension object containing cols as width and rows as height + * @throws WriterException when dimensions can't be determined */ - private int[] determineDimensions(int sourceCodeWords, int errorCorrectionCodeWords) throws WriterException { + protected static int[] determineDimensions(int minCols, int maxCols, + int minRows, int maxRows, + int sourceCodeWords, int errorCorrectionCodeWords) throws WriterException { float ratio = 0.0f; int[] dimension = null; + int currentCol = minCols; for (int cols = minCols; cols <= maxCols; cols++) { - + currentCol = cols; + int rows = calculateNumberOfRows(sourceCodeWords, errorCorrectionCodeWords, cols); if (rows < minRows) { @@ -725,7 +735,7 @@ public final class PDF417 { // Handle case when min values were larger than necessary if (dimension == null) { - int rows = calculateNumberOfRows(sourceCodeWords, errorCorrectionCodeWords, minCols); + int rows = calculateNumberOfRows(sourceCodeWords, errorCorrectionCodeWords, currentCol); if (rows < minRows) { dimension = new int[]{minCols, minRows}; } |
