GetTextDimensions(aRenderingContext,aTextStyle,currenttext, (PRInt32)currentlength,&newDimensions);
PRBool     isEndOfFrame = iter.IsLast(); GetTextDimensions(aRenderingContext, aTextStyle, currenttext, (PRInt32)currentlength, isEndOfFrame, &newDimensions);
nsTextFrame::PaintTextSlowly(nsPresContext* aPresContext,                             nsIRenderingContext& aRenderingContext,                             nsStyleContext* aStyleContext,                             TextPaintStyle& aTextStyle,                             nscoord dx, nscoord dy){  nsCOMPtr<nsISelectionController> selCon;  nsCOMPtr<nsIPresShell> shell;  PRBool  displaySelection;  PRBool  isPaginated,canDarkenColor=PR_FALSE;  PRBool  isSelected;  PRInt16 selectionValue;  nsCOMPtr<nsILineBreaker> lb;  if (NS_FAILED(GetTextInfoForPainting(aPresContext,                                        aRenderingContext,                                       getter_AddRefs(shell),                                       getter_AddRefs(selCon),                                       displaySelection,                                       isPaginated,                                       isSelected,                                       selectionValue,                                       getter_AddRefs(lb)))) {     return;  }  if(isPaginated){    canDarkenColor = CanDarken(aPresContext);  }  // Make enough space to transform  nsAutoTextBuffer paintBuffer;  nsAutoIndexBuffer indexBuffer;  if (NS_FAILED(indexBuffer.GrowTo(mContentLength + 1))) {    return;  }  nscoord width = mRect.width;  PRInt32 textLength;  nsTextTransformer tx(lb, nsnull, aPresContext);  PRIntn numJustifiableCharacter;    PrepareUnicodeText(tx, (displaySelection ? &indexBuffer : nsnull),                     &paintBuffer, &textLength, PR_TRUE, &numJustifiableCharacter);  PRInt32* ip = indexBuffer.mBuffer;  PRUnichar* text = paintBuffer.mBuffer;  if (0 != textLength) {#ifdef IBMBIDI    PRBool isOddLevel = PR_FALSE;    nsCharType charType = eCharType_LeftToRight;    if (aPresContext->BidiEnabled()) {      nsBidiPresUtils* bidiUtils = aPresContext->GetBidiUtils();      if (bidiUtils) {        isOddLevel = NS_GET_EMBEDDING_LEVEL(this) & 1;        charType = (nsCharType)NS_PTR_TO_INT32(aPresContext->PropertyTable()->GetProperty(this, nsLayoutAtoms::charType));#ifdef DEBUG        PRInt32 rememberTextLength = textLength;#endif        // Since we paint char by char, handle the text like on non-bidi platform        bidiUtils->ReorderUnicodeText(text, textLength, charType,                                      isOddLevel, PR_FALSE);        NS_ASSERTION(rememberTextLength == textLength, "Bidi formatting changed text length");      }    }#endif // IBMBIDI    ComputeExtraJustificationSpacing(aRenderingContext, aTextStyle, text, textLength, numJustifiableCharacter);    if (!displaySelection || !isSelected) {       // When there is no selection showing, use the fastest and      // simplest rendering approach      aRenderingContext.SetColor(nsCSSRendering::TransformColor(aTextStyle.mColor->mColor,canDarkenColor));      RenderString(aRenderingContext, aStyleContext, aPresContext, aTextStyle,                   text, textLength, dx, dy, width);    }    else     {      SelectionDetails *details = nsnull;      nsCOMPtr<nsIFrameSelection> frameSelection;//get the frame selection      nsresult rv = NS_OK;      frameSelection = do_QueryInterface(selCon); //this MAY implement      if (!frameSelection)//if that failed get it from the presshell        frameSelection = shell->FrameSelection();      nsCOMPtr<nsIContent> content;      PRInt32 offset;      PRInt32 length;      rv = GetContentAndOffsetsForSelection(aPresContext,                                            getter_AddRefs(content),                                            &offset, &length);      if (NS_SUCCEEDED(rv)) {        rv = frameSelection->LookUpSelection(content, mContentOffset,                                              mContentLength, &details,                                             PR_FALSE);      }      //where are the selection points "really"      SelectionDetails *sdptr = details;      while (sdptr){        sdptr->mStart = ip[sdptr->mStart] - mContentOffset;        sdptr->mEnd = ip[sdptr->mEnd]  - mContentOffset;#ifdef IBMBIDI        AdjustSelectionPointsForBidi(sdptr, textLength, CHARTYPE_IS_RTL(charType), isOddLevel, PR_FALSE);#endif        sdptr = sdptr->mNext;      }      DrawSelectionIterator iter(content, details,text,(PRUint32)textLength,aTextStyle, selectionValue, aPresContext, mStyleContext);      if (!iter.IsDone() && iter.First())      {        nscoord currentX = dx;        nsTextDimensions newDimensions;//temp        while (!iter.IsDone())        {          PRUnichar *currenttext  = iter.CurrentTextUnicharPtr();          PRUint32   currentlength= iter.CurrentLength();          //TextStyle &currentStyle = iter.CurrentStyle();          nscolor    currentFGColor = iter.CurrentForeGroundColor();          nscolor    currentBKColor;          PRBool     isCurrentBKColorTransparent;          GetTextDimensions(aRenderingContext,aTextStyle,currenttext, (PRInt32)currentlength,&newDimensions);          if (newDimensions.width)          {            if (iter.CurrentBackGroundColor(currentBKColor, &isCurrentBKColorTransparent))            {//DRAW RECT HERE!!!              if (!isCurrentBKColorTransparent) {                aRenderingContext.SetColor(currentBKColor);                aRenderingContext.FillRect(currentX, dy, newDimensions.width, mRect.height);              }              currentFGColor = EnsureDifferentColors(currentFGColor, currentBKColor);            }          }          if (isPaginated && !iter.IsBeforeOrAfter()) {            aRenderingContext.SetColor(nsCSSRendering::TransformColor(aTextStyle.mColor->mColor, canDarkenColor));            RenderString(aRenderingContext, aStyleContext, aPresContext,                         aTextStyle, currenttext, currentlength,                         currentX, dy, width, details);          } else if (!isPaginated) {            aRenderingContext.SetColor(nsCSSRendering::TransformColor(currentFGColor, canDarkenColor));            RenderString(aRenderingContext,aStyleContext, aPresContext,                         aTextStyle, currenttext, currentlength, currentX,                         dy, width, details);          }          // increment twips X start but remember to get ready for          // next draw by reducing current x by letter spacing amount          currentX += newDimensions.width; // + aTextStyle.mLetterSpacing;          iter.Next();        }      }      else if (!isPaginated)       {        aRenderingContext.SetColor(nsCSSRendering::TransformColor(aTextStyle.mColor->mColor,canDarkenColor));        RenderString(aRenderingContext, aStyleContext, aPresContext,                     aTextStyle, text, PRUint32(textLength),                     dx, dy, width, details);      }      sdptr = details;      if (details){        while ((sdptr = details->mNext) != nsnull) {          delete details;          details = sdptr;        }        delete details;      }    }  }}