private static void decodeTextCompaction(int[] textCompactionData,int[] byteCompactionData,int length,StringBuilder result){
  Mode subMode=Mode.ALPHA;
  Mode priorToShiftMode=Mode.ALPHA;
  int i=0;
  while (i < length) {
    int subModeCh=textCompactionData[i];
    char ch=0;
switch (subMode) {
case ALPHA:
      if (subModeCh < 26) {
        ch=(char)('A' + subModeCh);
      }
 else {
        if (subModeCh == 26) {
          ch=' ';
        }
 else         if (subModeCh == LL) {
          subMode=Mode.LOWER;
        }
 else         if (subModeCh == ML) {
          subMode=Mode.MIXED;
        }
 else         if (subModeCh == PS) {
          priorToShiftMode=subMode;
          subMode=Mode.PUNCT_SHIFT;
        }
 else         if (subModeCh == MODE_SHIFT_TO_BYTE_COMPACTION_MODE) {
          result.append((char)byteCompactionData[i]);
        }
 else         if (subModeCh == TEXT_COMPACTION_MODE_LATCH) {
          subMode=Mode.ALPHA;
        }
      }
    break;
case LOWER:
  if (subModeCh < 26) {
    ch=(char)('a' + subModeCh);
  }
 else {
    if (subModeCh == 26) {
      ch=' ';
    }
 else     if (subModeCh == AS) {
      priorToShiftMode=subMode;
      subMode=Mode.ALPHA_SHIFT;
    }
 else     if (subModeCh == ML) {
      subMode=Mode.MIXED;
    }
 else     if (subModeCh == PS) {
      priorToShiftMode=subMode;
      subMode=Mode.PUNCT_SHIFT;
    }
 else     if (subModeCh == MODE_SHIFT_TO_BYTE_COMPACTION_MODE) {
      result.append((char)byteCompactionData[i]);
    }
 else     if (subModeCh == TEXT_COMPACTION_MODE_LATCH) {
      subMode=Mode.ALPHA;
    }
  }
break;
case MIXED:
if (subModeCh < PL) {
ch=MIXED_CHARS[subModeCh];
}
 else {
if (subModeCh == PL) {
  subMode=Mode.PUNCT;
}
 else if (subModeCh == 26) {
  ch=' ';
}
 else if (subModeCh == LL) {
  subMode=Mode.LOWER;
}
 else if (subModeCh == AL) {
  subMode=Mode.ALPHA;
}
 else if (subModeCh == PS) {
  priorToShiftMode=subMode;
  subMode=Mode.PUNCT_SHIFT;
}
 else if (subModeCh == MODE_SHIFT_TO_BYTE_COMPACTION_MODE) {
  result.append((char)byteCompactionData[i]);
}
 else if (subModeCh == TEXT_COMPACTION_MODE_LATCH) {
  subMode=Mode.ALPHA;
}
}
break;
case PUNCT:
if (subModeCh < PAL) {
ch=PUNCT_CHARS[subModeCh];
}
 else {
if (subModeCh == PAL) {
subMode=Mode.ALPHA;
}
 else if (subModeCh == MODE_SHIFT_TO_BYTE_COMPACTION_MODE) {
result.append((char)byteCompactionData[i]);
}
 else if (subModeCh == TEXT_COMPACTION_MODE_LATCH) {
subMode=Mode.ALPHA;
}
}
break;
case ALPHA_SHIFT:
subMode=priorToShiftMode;
if (subModeCh < 26) {
ch=(char)('A' + subModeCh);
}
 else {
if (subModeCh == 26) {
ch=' ';
}
 else if (subModeCh == TEXT_COMPACTION_MODE_LATCH) {
subMode=Mode.ALPHA;
}
}
break;
case PUNCT_SHIFT:
subMode=priorToShiftMode;
if (subModeCh < PAL) {
ch=PUNCT_CHARS[subModeCh];
}
 else {
if (subModeCh == PAL) {
subMode=Mode.ALPHA;
}
 else if (subModeCh == MODE_SHIFT_TO_BYTE_COMPACTION_MODE) {
result.append((char)byteCompactionData[i]);
}
 else if (subModeCh == TEXT_COMPACTION_MODE_LATCH) {
subMode=Mode.ALPHA;
}
}
break;
}
if (ch != 0) {
result.append(ch);
}
i++;
}
}

private static void decodeTextCompaction ( int [ ] textCompactionData , int [ ] byteCompactionData , int length , StringBuilder result ) { Mode subMode = Mode . ALPHA ; Mode priorToShiftMode = Mode . ALPHA ; int i = 0 ; while ( i < length ) { int subModeCh = textCompactionData [ i ] ; char ch = 0 ; switch ( subMode ) { case ALPHA : if ( subModeCh < 26 ) { ch = ( char ) ( 'A' + subModeCh ) ; } else { if ( subModeCh == 26 ) { ch = ' ' ; } else if ( subModeCh == LL ) { subMode = Mode . LOWER ; } else if ( subModeCh == ML ) { subMode = Mode . MIXED ; } else if ( subModeCh == PS ) { priorToShiftMode = subMode ; subMode = Mode . PUNCT_SHIFT ; } else if ( subModeCh == MODE_SHIFT_TO_BYTE_COMPACTION_MODE ) { result . append ( ( char ) byteCompactionData [ i ] ) ; } else if ( subModeCh == TEXT_COMPACTION_MODE_LATCH ) { subMode = Mode . ALPHA ; } } break ; case LOWER : if ( subModeCh < 26 ) { ch = ( char ) ( 'a' + subModeCh ) ; } else { if ( subModeCh == 26 ) { ch = ' ' ; } else if ( subModeCh == AS ) { priorToShiftMode = subMode ; subMode = Mode . ALPHA_SHIFT ; } else if ( subModeCh == ML ) { subMode = Mode . MIXED ; } else if ( subModeCh == PS ) { priorToShiftMode = subMode ; subMode = Mode . PUNCT_SHIFT ; } else if ( subModeCh == MODE_SHIFT_TO_BYTE_COMPACTION_MODE ) { result . append ( ( char ) byteCompactionData [ i ] ) ; } else if ( subModeCh == TEXT_COMPACTION_MODE_LATCH ) { subMode = Mode . ALPHA ; } } break ; case MIXED : if ( subModeCh < PL ) { ch = MIXED_CHARS [ subModeCh ] ; } else { if ( subModeCh == PL ) { subMode = Mode . PUNCT ; } else if ( subModeCh == 26 ) { ch = ' ' ; } else if ( subModeCh == LL ) { subMode = Mode . LOWER ; } else if ( subModeCh == AL ) { subMode = Mode . ALPHA ; } else if ( subModeCh == PS ) { priorToShiftMode = subMode ; subMode = Mode . PUNCT_SHIFT ; } else if ( subModeCh == MODE_SHIFT_TO_BYTE_COMPACTION_MODE ) { result . append ( ( char ) byteCompactionData [ i ] ) ; } else if ( subModeCh == TEXT_COMPACTION_MODE_LATCH ) { subMode = Mode . ALPHA ; } } break ; case PUNCT : if ( subModeCh < PAL ) { ch = PUNCT_CHARS [ subModeCh ] ; } else { if ( subModeCh == PAL ) { subMode = Mode . ALPHA ; } else if ( subModeCh == MODE_SHIFT_TO_BYTE_COMPACTION_MODE ) { result . append ( ( char ) byteCompactionData [ i ] ) ; } else if ( subModeCh == TEXT_COMPACTION_MODE_LATCH ) { subMode = Mode . ALPHA ; } } break ; case ALPHA_SHIFT : subMode = priorToShiftMode ; if ( subModeCh < 26 ) { ch = ( char ) ( 'A' + subModeCh ) ; } else { if ( subModeCh == 26 ) { ch = ' ' ; } else if ( subModeCh == TEXT_COMPACTION_MODE_LATCH ) { subMode = Mode . ALPHA ; } } break ; case PUNCT_SHIFT : subMode = priorToShiftMode ; if ( subModeCh < PAL ) { ch = PUNCT_CHARS [ subModeCh ] ; } else { if ( subModeCh == PAL ) { subMode = Mode . ALPHA ; } else if ( subModeCh == MODE_SHIFT_TO_BYTE_COMPACTION_MODE ) { result . append ( ( char ) byteCompactionData [ i ] ) ; } else if ( subModeCh == TEXT_COMPACTION_MODE_LATCH ) { subMode = Mode . ALPHA ; } } break ; } if ( ch != 0 ) { result . append ( ch ) ; } i ++ ; } }
the text compaction mode includes all the printable ascii characters ( i . e . values from 32 to 126 ) and three ascii control characters : ht or tab ( ascii value 9 ) , lf or line feed ( ascii value 10 ) , and cr or carriage return ( ascii value 13 ) . the text compaction mode also includes various latch and shift characters which are used exclusively within the mode . the text compaction mode encodes up to 2 characters per codeword . the compaction rules for converting data into pdf417 codewords are defined in 5 . 4 . 2 . 2 . the sub - mode switches are defined in 5 . 4 . 2 . 3 .
