for (PRInt32 i = 0; i < textLength; i++) {
PRInt32 justifiableRange = textLength; if (IsEndOfLine(mState)) justifiableRange--; for (PRInt32 i = 0; i < justifiableRange; i++) {
nsTextFrame::PrepareUnicodeText(nsTextTransformer& aTX,                                nsAutoIndexBuffer* aIndexBuffer,                                nsAutoTextBuffer* aTextBuffer,                                PRInt32* aTextLen,                                PRBool aForceArabicShaping,                                PRIntn* aJustifiableCharCount){  // Setup transform to operate starting in the content at our content  // offset  aTX.Init(this, mContent, mContentOffset, aForceArabicShaping);  PRInt32 strInx = mContentOffset;  PRInt32* indexp = aIndexBuffer ? aIndexBuffer->mBuffer : nsnull;  // Skip over the leading whitespace  PRInt32 n = mContentLength;  if (0 != (mState & TEXT_SKIP_LEADING_WS)) {    PRBool isWhitespace, wasTransformed;    PRInt32 wordLen, contentLen;#ifdef IBMBIDI    wordLen = (mState & NS_FRAME_IS_BIDI) ? mContentOffset + mContentLength : -1;#endif // IBMBIDI    aTX.GetNextWord(PR_FALSE, &wordLen, &contentLen, &isWhitespace, &wasTransformed);    // we trip this assertion in bug 31053, but I think it's unnecessary    //NS_ASSERTION(isWhitespace, "mState and content are out of sync");#ifdef IBMBIDI    if (mState & NS_FRAME_IS_BIDI        && contentLen > mContentLength) {      contentLen = mContentLength;    }#endif // IBMBIDI    if (isWhitespace) {      if (nsnull != indexp) {        // Point mapping indicies at the same content index since        // all of the compressed whitespace maps down to the same        // renderable character.        PRInt32 i = contentLen;        while (--i >= 0) {          *indexp++ = strInx;        }      }      n -= contentLen;      if(n<0)        NS_WARNING("mContentLength is < FragmentLength");    }  }  // Rescan the content and transform it. Stop when we have consumed  // mContentLength characters.  PRBool inWord = (TEXT_IN_WORD & mState) ? PR_TRUE : PR_FALSE;  PRInt32 column = mColumn;  PRInt32 textLength = 0;  PRInt32 dstOffset = 0;  nsAutoTextBuffer tmpTextBuffer;  nsAutoTextBuffer* textBuffer = aTextBuffer;  if (!textBuffer && aJustifiableCharCount)    textBuffer = &tmpTextBuffer;  while (0 != n) {    PRUnichar* bp;    PRBool isWhitespace, wasTransformed;    PRInt32 wordLen, contentLen;#ifdef IBMBIDI    wordLen = (mState & NS_FRAME_IS_BIDI) ? mContentOffset + mContentLength : -1;#endif // IBMBIDI    // Get the next word    bp = aTX.GetNextWord(inWord, &wordLen, &contentLen, &isWhitespace, &wasTransformed);    if (nsnull == bp) {#ifdef IBMBIDI      if (indexp && (mState & NS_FRAME_IS_BIDI) ) {        while (--n >= 0) {          *indexp++ = strInx++;        }      }#endif // IBMBIDI      break;    }    if (contentLen > n) {      contentLen = n;    }    if (wordLen > n) {      wordLen = n;    }    inWord = PR_FALSE;    if (isWhitespace) {      if ('\t' == bp[0]) {        PRInt32 spaces = 8 - (7 & column);        PRUnichar* tp = bp;        wordLen = spaces;        while (--spaces >= 0) {          *tp++ = ' ';        }        // XXX This is a one to many mapping that I think isn't handled well        if (nsnull != indexp) {          *indexp++ = strInx;          strInx += wordLen;        }      }      else if ('\n' == bp[0]) {        if (nsnull != indexp) {          *indexp++ = strInx;        }        break;      }      else if (nsnull != indexp) {        if (1 == wordLen) {          // Point mapping indicies at the same content index since          // all of the compressed whitespace maps down to the same          // renderable character.          PRInt32 i = contentLen;          while (--i >= 0) {            *indexp++ = strInx;          }          strInx++;        } else {          // Point mapping indicies at each content index in the word          PRInt32 i = contentLen;          while (--i >= 0) {            *indexp++ = strInx++;          }        }      }    }    else {      PRInt32 i;      if (nsnull != indexp) {        // Point mapping indicies at each content index in the word        if (1 == wordLen && contentLen == 2 && IS_CJ_CHAR(*bp)) {          // if all these condition meets, we have a '\n' between CJK chars,           // and this '\n' should be removed.          i = contentLen;          while (--i >= 0) {            *indexp++ = strInx;          }          strInx++;        } else {          i = contentLen;          while (--i >= 0) {            *indexp++ = strInx++;          }        }      }    }    // Grow the buffer before we run out of room. The only time this    // happens is because of tab expansion.    if (textBuffer != nsnull && dstOffset + wordLen > textBuffer->mBufferLen) {      nsresult rv = textBuffer->GrowBy(wordLen);      if (NS_FAILED(rv)) {        break;      }    }    column += wordLen;    textLength += wordLen;    n -= contentLen;    if (textBuffer != nsnull) {      memcpy(textBuffer->mBuffer + dstOffset, bp,             sizeof(PRUnichar)*wordLen);    }    dstOffset += wordLen;  }#ifdef DEBUG  if (aIndexBuffer) {    NS_ASSERTION(indexp <= aIndexBuffer->mBuffer + aIndexBuffer->mBufferLen,                 "yikes - we just overwrote memory");  }  if (textBuffer) {    NS_ASSERTION(dstOffset <= textBuffer->mBufferLen,                 "yikes - we just overwrote memory");  }#endif  // Remove trailing whitespace if it was trimmed after reflow  // TEXT_TRIMMED_WS can be set in measureText during reflow, and   // nonexitent text buffer may occur in this situation.  if (TEXT_TRIMMED_WS & mState && textBuffer) {    if (--dstOffset >= 0) {      PRUnichar ch = textBuffer->mBuffer[dstOffset];      if (XP_IS_SPACE(ch))        textLength--;    }  }  if (aIndexBuffer) {    PRInt32* ip = aIndexBuffer->mBuffer;    ip[mContentLength] = ip[mContentLength-1];    if ((ip[mContentLength] - mContentOffset) < textLength) {      // Must set up last one for selection beyond edge if in boundary      ip[mContentLength] = textLength + mContentOffset;    }  }  *aTextLen = textLength;  if (aJustifiableCharCount && textBuffer) {    PRBool isCJ = IsChineseJapaneseLangGroup();    PRIntn numJustifiableCharacter = 0;    for (PRInt32 i = 0; i < textLength; i++) {      if (IsJustifiableCharacter(textBuffer->mBuffer[i], isCJ))        numJustifiableCharacter++;    }    *aJustifiableCharCount = numJustifiableCharacter;  }}