PRBool  isPaginated,canDarkenColor;
PRBool  isPaginated,canDarkenColor=PR_FALSE;
nsTextFrame::PaintTextSlowly(nsIPresContext* aPresContext,                             nsIRenderingContext& aRenderingContext,                             nsIStyleContext* aStyleContext,                             TextStyle& aTextStyle,                             nscoord dx, nscoord dy){  nsCOMPtr<nsISelectionController> selCon;  nsCOMPtr<nsIPresShell> shell;  PRBool  displaySelection;  PRBool  isPaginated,canDarkenColor;  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);  PRInt32 numSpaces;    numSpaces = PrepareUnicodeText(tx, (displaySelection ? &indexBuffer : nsnull),                                 &paintBuffer, &textLength);  PRInt32* ip = indexBuffer.mBuffer;  PRUnichar* text = paintBuffer.mBuffer;  if (0 != textLength) {#ifdef IBMBIDI    PRBool bidiEnabled;    PRUint8 level = 0;    nsCharType charType = eCharType_LeftToRight;    aPresContext->GetBidiEnabled(&bidiEnabled);    if (bidiEnabled) {      nsBidiPresUtils* bidiUtils;      aPresContext->GetBidiUtils(&bidiUtils);      if (bidiUtils) {        GetBidiProperty(aPresContext, nsLayoutAtoms::embeddingLevel,                        (void**) &level,sizeof(level));        GetBidiProperty(aPresContext, nsLayoutAtoms::charType,                         (void**) &charType,sizeof(charType));        // Since we paint char by char, handle the text like on non-bidi platform        bidiUtils->FormatUnicodeText(aPresContext, text, textLength, charType,                                     level & 1, PR_FALSE);      }    }    if (0 != textLength) { // textLength might change due to the bidi formattimg#endif // IBMBIDI    ComputeExtraJustificationSpacing(aRenderingContext, aTextStyle, text, textLength, numSpaces);    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, 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        rv = shell->GetFrameSelection(getter_AddRefs(frameSelection));      if (NS_SUCCEEDED(rv) && 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), level & 1, PR_FALSE);#endif        sdptr = sdptr->mNext;      }      DrawSelectionIterator iter(details,text,(PRUint32)textLength,aTextStyle, selectionValue);      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;	      GetTextDimensions(aRenderingContext,aTextStyle,currenttext, (PRInt32)currentlength,&newDimensions);	      if (newDimensions.width)	      {		      if (iter.CurrentBackGroundColor(currentBKColor))		      {//DRAW RECT HERE!!!		      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, aTextStyle, currenttext, 					        currentlength, currentX, dy, width, details);        } else if (!isPaginated) {          aRenderingContext.SetColor(nsCSSRendering::TransformColor(currentFGColor,canDarkenColor));	        RenderString(aRenderingContext,aStyleContext, 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, aTextStyle, text,                     PRUint32(textLength), dx, dy, width, details);      }      sdptr = details;      if (details){        while ((sdptr = details->mNext) != nsnull) {          delete details;          details = sdptr;        }        delete details;      }    }#ifdef IBMBIDI   }#endif // IBMBIDI  }}