if (iter.CurrentBackGroundColor(currentBKColor))
if (iter.CurrentBackGroundColor(currentBKColor) && !isPaginated)
nsTextFrame::PaintUnicodeText(nsIPresContext* aPresContext,                              nsIRenderingContext& aRenderingContext,                              nsIStyleContext* aStyleContext,                              TextStyle& aTextStyle,                              nscoord dx, nscoord dy){  nsCOMPtr<nsIPresShell> shell;//get the presshell  nsresult rv = aPresContext->GetShell(getter_AddRefs(shell));  if (NS_FAILED(rv) || !shell)    return;//get the selection controller  nsCOMPtr<nsISelectionController> selCon;  rv = GetSelectionController(aPresContext, getter_AddRefs(selCon));  if (NS_FAILED(rv) || !selCon)    return;  PRInt16 selectionValue;  selCon->GetDisplaySelection(&selectionValue);//if greater than hidden then we display some kind of selection  PRBool displaySelection = selectionValue > nsISelectionController::SELECTION_HIDDEN;  // Make enough space to transform  nsAutoTextBuffer paintBuffer;  nsAutoIndexBuffer indexBuffer;  if (displaySelection) {    if (NS_FAILED(indexBuffer.GrowTo(mContentLength + 1))) {      return;    }  }  nscoord width = mRect.width;  // Transform text from content into renderable form  // XXX If the text fragment is already Unicode and text text wasn't  // transformed when we formatted it, then there's no need to do all  // this and we should just render the text fragment directly. See  // PaintAsciiText()...  nsCOMPtr<nsIDocument> doc;  shell->GetDocument(getter_AddRefs(doc));  if (!doc)    return;  nsCOMPtr<nsILineBreaker> lb;  doc->GetLineBreaker(getter_AddRefs(lb));  nsTextTransformer tx(lb, nsnull, aPresContext);  PRInt32 textLength;  // no need to worry about justification, that's always on the slow path  PrepareUnicodeText(tx, (displaySelection ? &indexBuffer : nsnull),                     &paintBuffer, &textLength);  PRInt32* ip = indexBuffer.mBuffer;  PRUnichar* text = paintBuffer.mBuffer;  nsFrameState  frameState;  PRBool        isSelected;  GetFrameState(&frameState);  isSelected = (frameState & NS_FRAME_SELECTED_CONTENT) == NS_FRAME_SELECTED_CONTENT;  if (0 != textLength)   {    if (!displaySelection || !isSelected ) //draw text normally    {       // When there is no selection showing, use the fastest and      // simplest rendering approach      aRenderingContext.SetColor(aTextStyle.mColor->mColor);      aRenderingContext.DrawString(text, PRUint32(textLength), dx, dy);      PaintTextDecorations(aRenderingContext, aStyleContext, aTextStyle,                           dx, dy, width);    }    else     { //we draw according to selection rules      SelectionDetails *details = nsnull;      nsCOMPtr<nsIFrameSelection> frameSelection;//get the frameSelection from the selection controller      if (NS_SUCCEEDED(rv) && selCon)      {        frameSelection = do_QueryInterface(selCon); //this MAY implement      }//if that failed get it from the pres shell      if (!frameSelection)        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) && content){          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;        sdptr = sdptr->mNext;      }      //while we have substrings...      //PRBool drawn = PR_FALSE;      DrawSelectionIterator iter(details,text,(PRUint32)textLength,aTextStyle, selectionValue);      if (!iter.IsDone() && iter.First())      {        nscoord currentX = dx;        nscoord newWidth;//temp        while (!iter.IsDone())        {          PRUnichar *currenttext  = iter.CurrentTextUnicharPtr();          PRUint32   currentlength= iter.CurrentLength();          //TextStyle &currentStyle = iter.CurrentStyle();          nscolor    currentFGColor = iter.CurrentForeGroundColor();          nscolor    currentBKColor;          if (NS_SUCCEEDED(aRenderingContext.GetWidth(currenttext, currentlength,newWidth)))//ADJUST FOR CHAR SPACING          {            if (iter.CurrentBackGroundColor(currentBKColor))            {//DRAW RECT HERE!!!              aRenderingContext.SetColor(currentBKColor);              aRenderingContext.FillRect(currentX, dy, newWidth, mRect.height);							currentFGColor = EnsureDifferentColors(currentFGColor, currentBKColor);            }          }          else            newWidth =0;                    aRenderingContext.SetColor(currentFGColor);          aRenderingContext.DrawString(currenttext, currentlength, currentX, dy);          currentX+=newWidth;//increment twips X start          iter.Next();        }      }      else      {        aRenderingContext.SetColor(aTextStyle.mColor->mColor);        aRenderingContext.DrawString(text, PRUint32(textLength), dx, dy);      }      PaintTextDecorations(aRenderingContext, aStyleContext,                           aTextStyle, dx, dy, width, text, details,0,(PRUint32)textLength);      sdptr = details;      if (details){        while ((sdptr = details->mNext) != nsnull) {          delete details;          details = sdptr;        }        delete details;      }    }  }}