PDF417LogicImpl { public static Dimension determineDimensions(PDF417Bean pdf417Bean, int sourceCodeWords) { final int minCols = pdf417Bean.getMinCols(); final int maxCols = pdf417Bean.getMaxCols(); final int maxRows = pdf417Bean.getMaxRows(); final int minRows = pdf417Bean.getMinRows(); final double preferredRatio = pdf417Bean.getWidthToHeightRatio(); double ratio = 0; Dimension dimension = null; final int errorCorrectionCodeWords = PDF417ErrorCorrection.getErrorCorrectionCodewordCount( pdf417Bean.getErrorCorrectionLevel()); for (int cols = minCols; cols <= maxCols; cols++) { final int rows = calculateNumberOfRows(sourceCodeWords, errorCorrectionCodeWords, cols); if (rows < minRows) { break; } if (rows > maxRows) { continue; } final double newRatio = ((17 * cols + 69) * pdf417Bean.getModuleWidth()) / (rows * pdf417Bean.getBarHeight()); if (dimension != null && Math.abs(newRatio - preferredRatio) > Math.abs(ratio - preferredRatio)) { continue; } ratio = newRatio; dimension = new Dimension(cols, rows); } return dimension; }  static int getNumberOfRows(int m, int k, int c); static int calculateNumberOfRows(int m, int k, int c); static int getNumberOfPadCodewords(int m, int k, int c, int r); static int getNumberOfDataCodewords(int m, ErrorCorrectionLevel errorCorrectionLevel, int c); static void generateBarcodeLogic(TwoDimBarcodeLogicHandler logic,
            String msg, PDF417Bean pdf417Bean); static Dimension determineDimensions(PDF417Bean pdf417Bean,
            int sourceCodeWords);  }
@Test public void testDetermineDimensions() { System.out.println("determineDimensions"); PDF417Bean pdf417Bean = new PDF417Bean(); int sourceCodeWords = 9; Dimension expResult = new Dimension(2, 6); Dimension result = PDF417LogicImpl.determineDimensions(pdf417Bean, sourceCodeWords); assertEquals(expResult, result); pdf417Bean.setColumns(4); expResult = new Dimension(4, 3); result = PDF417LogicImpl.determineDimensions(pdf417Bean, sourceCodeWords); assertEquals(expResult, result); }