int[] determineDimensions(int sourceCodeWords,int errorCorrectionCodeWords) throws WriterException {
  float ratio=0.0f;
  int[] dimension=null;
  for (int cols=minCols; cols <= maxCols; cols++) {
    int rows=calculateNumberOfRows(sourceCodeWords,errorCorrectionCodeWords,cols);
    if (rows < minRows) {
      break;
    }
    if (rows > maxRows) {
      continue;
    }
    float newRatio=((17 * cols + 69) * DEFAULT_MODULE_WIDTH) / (rows * HEIGHT);
    if (dimension != null && Math.abs(newRatio - PREFERRED_RATIO) > Math.abs(ratio - PREFERRED_RATIO)) {
      continue;
    }
    ratio=newRatio;
    dimension=new int[]{cols,rows};
  }
  if (dimension == null) {
    int rows=calculateNumberOfRows(sourceCodeWords,errorCorrectionCodeWords,minCols);
    if (rows < minRows) {
      dimension=new int[]{minCols,minRows};
    }
  }
  if (dimension == null) {
    throw new WriterException("Unable to fit message in columns");
  }
  return dimension;
}

int [ ] determineDimensions ( int sourceCodeWords , int errorCorrectionCodeWords ) throws WriterException { float ratio = 0.0f ; int [ ] dimension = null ; for ( int cols = minCols ; cols <= maxCols ; cols ++ ) { int rows = calculateNumberOfRows ( sourceCodeWords , errorCorrectionCodeWords , cols ) ; if ( rows < minRows ) { break ; } if ( rows > maxRows ) { continue ; } float newRatio = ( ( 17 * cols + 69 ) * DEFAULT_MODULE_WIDTH ) / ( rows * HEIGHT ) ; if ( dimension != null && Math . abs ( newRatio - PREFERRED_RATIO ) > Math . abs ( ratio - PREFERRED_RATIO ) ) { continue ; } ratio = newRatio ; dimension = new int [ ] { cols , rows } ; } if ( dimension == null ) { int rows = calculateNumberOfRows ( sourceCodeWords , errorCorrectionCodeWords , minCols ) ; if ( rows < minRows ) { dimension = new int [ ] { minCols , minRows } ; } } if ( dimension == null ) { throw new WriterException ( "Unable to fit message in columns" ) ; } return dimension ; }
determine optimal nr of columns and rows for the specified number of codewords .
