final int[] breakLines(int startPos){
  int[] lineEnds=(lineCache == null) ? null : lineCache.get();
  int[] oldLineEnds=lineEnds;
  int start=getStartOffset();
  int lineIndex=0;
  if (lineEnds != null) {
    lineIndex=findLine(startPos - start);
    if (lineIndex > 0) {
      lineIndex--;
    }
  }
  int p0=(lineIndex == 0) ? start : start + lineEnds[lineIndex - 1];
  int p1=getEndOffset();
  while (p0 < p1) {
    int p=calculateBreakPosition(p0,p1);
    p0=(p == p0) ? ++p : p;
    if (lineIndex == 0 && p0 >= p1) {
      lineCache=null;
      lineEnds=null;
      lineIndex=1;
      break;
    }
 else     if (lineEnds == null || lineIndex >= lineEnds.length) {
      double growFactor=((double)(p1 - start) / (p0 - start));
      int newSize=(int)Math.ceil((lineIndex + 1) * growFactor);
      newSize=Math.max(newSize,lineIndex + 2);
      int[] tmp=new int[newSize];
      if (lineEnds != null) {
        System.arraycopy(lineEnds,0,tmp,0,lineIndex);
      }
      lineEnds=tmp;
    }
    lineEnds[lineIndex++]=p0 - start;
  }
  lineCount=lineIndex;
  if (lineCount > 1) {
    int maxCapacity=lineCount + lineCount / 3;
    if (lineEnds.length > maxCapacity) {
      int[] tmp=new int[maxCapacity];
      System.arraycopy(lineEnds,0,tmp,0,lineCount);
      lineEnds=tmp;
    }
  }
  if (lineEnds != null && lineEnds != oldLineEnds) {
    lineCache=new SoftReference<int[]>(lineEnds);
  }
  return lineEnds;
}

final int [ ] breakLines ( int startPos ) { int [ ] lineEnds = ( lineCache == null ) ? null : lineCache . get ( ) ; int [ ] oldLineEnds = lineEnds ; int start = getStartOffset ( ) ; int lineIndex = 0 ; if ( lineEnds != null ) { lineIndex = findLine ( startPos - start ) ; if ( lineIndex > 0 ) { lineIndex -- ; } } int p0 = ( lineIndex == 0 ) ? start : start + lineEnds [ lineIndex - 1 ] ; int p1 = getEndOffset ( ) ; while ( p0 < p1 ) { int p = calculateBreakPosition ( p0 , p1 ) ; p0 = ( p == p0 ) ? ++ p : p ; if ( lineIndex == 0 && p0 >= p1 ) { lineCache = null ; lineEnds = null ; lineIndex = 1 ; break ; } else if ( lineEnds == null || lineIndex >= lineEnds . length ) { double growFactor = ( ( double ) ( p1 - start ) / ( p0 - start ) ) ; int newSize = ( int ) Math . ceil ( ( lineIndex + 1 ) * growFactor ) ; newSize = Math . max ( newSize , lineIndex + 2 ) ; int [ ] tmp = new int [ newSize ] ; if ( lineEnds != null ) { System . arraycopy ( lineEnds , 0 , tmp , 0 , lineIndex ) ; } lineEnds = tmp ; } lineEnds [ lineIndex ++ ] = p0 - start ; } lineCount = lineIndex ; if ( lineCount > 1 ) { int maxCapacity = lineCount + lineCount / 3 ; if ( lineEnds . length > maxCapacity ) { int [ ] tmp = new int [ maxCapacity ] ; System . arraycopy ( lineEnds , 0 , tmp , 0 , lineCount ) ; lineEnds = tmp ; } } if ( lineEnds != null && lineEnds != oldLineEnds ) { lineCache = new SoftReference < int [ ] > ( lineEnds ) ; } return lineEnds ; }
creates line cache if text breaks into more than one physical line .
