public void paintCode(){
  int maxErr, lenErr, tot, pad;
  if ((options & PDF417_USE_RAW_CODEWORDS) != 0) {
    if (lenCodewords > MAX_DATA_CODEWORDS || lenCodewords < 1 || lenCodewords != codewords[0]) {
      throw new PdfException(PdfException.InvalidCodewordSize);
    }
  }
 else {
    if (code == null)     throw new PdfException(PdfException.TextCannotBeNull);
    if (code.length > ABSOLUTE_MAX_TEXT_SIZE) {
      throw new PdfException(PdfException.TextIsTooBig);
    }
    segmentList=new SegmentList();
    breakString();
    assemble();
    segmentList=null;
    codewords[0]=lenCodewords=cwPtr;
  }
  maxErr=maxPossibleErrorLevel(MAX_DATA_CODEWORDS + 2 - lenCodewords);
  if ((options & PDF417_USE_ERROR_LEVEL) == 0) {
    if (lenCodewords < 41)     errorLevel=2;
 else     if (lenCodewords < 161)     errorLevel=3;
 else     if (lenCodewords < 321)     errorLevel=4;
 else     errorLevel=5;
  }
  if (errorLevel < 0)   errorLevel=0;
 else   if (errorLevel > maxErr)   errorLevel=maxErr;
  if (codeColumns < 1)   codeColumns=1;
 else   if (codeColumns > 30)   codeColumns=30;
  if (codeRows < 3)   codeRows=3;
 else   if (codeRows > 90)   codeRows=90;
  lenErr=2 << errorLevel;
  boolean fixedColumn=(options & PDF417_FIXED_ROWS) == 0;
  boolean skipRowColAdjust=false;
  tot=lenCodewords + lenErr;
  if ((options & PDF417_FIXED_RECTANGLE) != 0) {
    tot=codeColumns * codeRows;
    if (tot > MAX_DATA_CODEWORDS + 2) {
      tot=getMaxSquare();
    }
    if (tot < lenCodewords + lenErr)     tot=lenCodewords + lenErr;
 else     skipRowColAdjust=true;
  }
 else   if ((options & (PDF417_FIXED_COLUMNS | PDF417_FIXED_ROWS)) == 0) {
    double c, b;
    fixedColumn=true;
    if (aspectRatio < 0.001)     aspectRatio=0.001f;
 else     if (aspectRatio > 1000)     aspectRatio=1000;
    b=73 * aspectRatio - 4;
    c=(-b + Math.sqrt(b * b + 4 * 17 * aspectRatio* (lenCodewords + lenErr)* yHeight)) / (2 * 17 * aspectRatio);
    codeColumns=(int)(c + 0.5);
    if (codeColumns < 1)     codeColumns=1;
 else     if (codeColumns > 30)     codeColumns=30;
  }
  if (!skipRowColAdjust) {
    if (fixedColumn) {
      codeRows=(tot - 1) / codeColumns + 1;
      if (codeRows < 3)       codeRows=3;
 else       if (codeRows > 90) {
        codeRows=90;
        codeColumns=(tot - 1) / 90 + 1;
      }
    }
 else {
      codeColumns=(tot - 1) / codeRows + 1;
      if (codeColumns > 30) {
        codeColumns=30;
        codeRows=(tot - 1) / 30 + 1;
      }
    }
    tot=codeRows * codeColumns;
  }
  if (tot > MAX_DATA_CODEWORDS + 2) {
    tot=getMaxSquare();
  }
  errorLevel=maxPossibleErrorLevel(tot - lenCodewords);
  lenErr=2 << errorLevel;
  pad=tot - lenErr - lenCodewords;
  if ((options & PDF417_USE_MACRO) != 0) {
    System.arraycopy(codewords,macroIndex,codewords,macroIndex + pad,pad);
    cwPtr=lenCodewords + pad;
    while (pad-- != 0)     codewords[macroIndex++]=TEXT_MODE;
  }
 else {
    cwPtr=lenCodewords;
    while (pad-- != 0)     codewords[cwPtr++]=TEXT_MODE;
  }
  codewords[0]=lenCodewords=cwPtr;
  calculateErrorCorrection(lenCodewords);
  lenCodewords=tot;
  outPaintCode();
}

public void paintCode ( ) { int maxErr , lenErr , tot , pad ; if ( ( options & PDF417_USE_RAW_CODEWORDS ) != 0 ) { if ( lenCodewords > MAX_DATA_CODEWORDS || lenCodewords < 1 || lenCodewords != codewords [ 0 ] ) { throw new PdfException ( PdfException . InvalidCodewordSize ) ; } } else { if ( code == null ) throw new PdfException ( PdfException . TextCannotBeNull ) ; if ( code . length > ABSOLUTE_MAX_TEXT_SIZE ) { throw new PdfException ( PdfException . TextIsTooBig ) ; } segmentList = new SegmentList ( ) ; breakString ( ) ; assemble ( ) ; segmentList = null ; codewords [ 0 ] = lenCodewords = cwPtr ; } maxErr = maxPossibleErrorLevel ( MAX_DATA_CODEWORDS + 2 - lenCodewords ) ; if ( ( options & PDF417_USE_ERROR_LEVEL ) == 0 ) { if ( lenCodewords < 41 ) errorLevel = 2 ; else if ( lenCodewords < 161 ) errorLevel = 3 ; else if ( lenCodewords < 321 ) errorLevel = 4 ; else errorLevel = 5 ; } if ( errorLevel < 0 ) errorLevel = 0 ; else if ( errorLevel > maxErr ) errorLevel = maxErr ; if ( codeColumns < 1 ) codeColumns = 1 ; else if ( codeColumns > 30 ) codeColumns = 30 ; if ( codeRows < 3 ) codeRows = 3 ; else if ( codeRows > 90 ) codeRows = 90 ; lenErr = 2 << errorLevel ; boolean fixedColumn = ( options & PDF417_FIXED_ROWS ) == 0 ; boolean skipRowColAdjust = false ; tot = lenCodewords + lenErr ; if ( ( options & PDF417_FIXED_RECTANGLE ) != 0 ) { tot = codeColumns * codeRows ; if ( tot > MAX_DATA_CODEWORDS + 2 ) { tot = getMaxSquare ( ) ; } if ( tot < lenCodewords + lenErr ) tot = lenCodewords + lenErr ; else skipRowColAdjust = true ; } else if ( ( options & ( PDF417_FIXED_COLUMNS | PDF417_FIXED_ROWS ) ) == 0 ) { double c , b ; fixedColumn = true ; if ( aspectRatio < 0.001 ) aspectRatio = 0.001f ; else if ( aspectRatio > 1000 ) aspectRatio = 1000 ; b = 73 * aspectRatio - 4 ; c = ( - b + Math . sqrt ( b * b + 4 * 17 * aspectRatio * ( lenCodewords + lenErr ) * yHeight ) ) / ( 2 * 17 * aspectRatio ) ; codeColumns = ( int ) ( c + 0.5 ) ; if ( codeColumns < 1 ) codeColumns = 1 ; else if ( codeColumns > 30 ) codeColumns = 30 ; } if ( ! skipRowColAdjust ) { if ( fixedColumn ) { codeRows = ( tot - 1 ) / codeColumns + 1 ; if ( codeRows < 3 ) codeRows = 3 ; else if ( codeRows > 90 ) { codeRows = 90 ; codeColumns = ( tot - 1 ) / 90 + 1 ; } } else { codeColumns = ( tot - 1 ) / codeRows + 1 ; if ( codeColumns > 30 ) { codeColumns = 30 ; codeRows = ( tot - 1 ) / 30 + 1 ; } } tot = codeRows * codeColumns ; } if ( tot > MAX_DATA_CODEWORDS + 2 ) { tot = getMaxSquare ( ) ; } errorLevel = maxPossibleErrorLevel ( tot - lenCodewords ) ; lenErr = 2 << errorLevel ; pad = tot - lenErr - lenCodewords ; if ( ( options & PDF417_USE_MACRO ) != 0 ) { System . arraycopy ( codewords , macroIndex , codewords , macroIndex + pad , pad ) ; cwPtr = lenCodewords + pad ; while ( pad -- != 0 ) codewords [ macroIndex ++ ] = TEXT_MODE ; } else { cwPtr = lenCodewords ; while ( pad -- != 0 ) codewords [ cwPtr ++ ] = TEXT_MODE ; } codewords [ 0 ] = lenCodewords = cwPtr ; calculateErrorCorrection ( lenCodewords ) ; lenCodewords = tot ; outPaintCode ( ) ; }
paints the barcode . if no exception was thrown a valid barcode is available .
