nscoord currentX = dx; nscoord newWidth; while (!iter.IsDone())
char *currenttext  = iter.CurrentTextCStrPtr(); PRUint32   currentlength= iter.CurrentLength(); TextStyle &currentStyle = iter.CurrentStyle(); nscolor    currentFGColor = iter.CurrentForeGroundColor(); nscolor    currentBKColor;  if (NS_SUCCEEDED(aRenderingContext.GetWidth(currenttext, currentlength,newWidth)))
nsTextFrame::PaintAsciiText(nsIPresContext* aPresContext,                            nsIRenderingContext& aRenderingContext,                            nsIStyleContext* aStyleContext,                            TextStyle& aTextStyle,                            nscoord dx, nscoord dy){  nsCOMPtr<nsIDocument> doc(getter_AddRefs(GetDocument(aPresContext)));  PRBool displaySelection;  displaySelection = doc->GetDisplaySelection();  // Make enough space to transform  nsAutoTextBuffer unicodePaintBuffer;  nsAutoIndexBuffer indexBuffer;  if (displaySelection) {    if (NS_FAILED(indexBuffer.GrowTo(mContentLength + 1))) {      return;    }  }  // Transform text from content into renderable form  nsCOMPtr<nsILineBreaker> lb;  doc->GetLineBreaker(getter_AddRefs(lb));  nsTextTransformer tx(lb, nsnull);  PRInt32 textLength;  PrepareUnicodeText(tx, (displaySelection ? &indexBuffer : nsnull),                     &unicodePaintBuffer, &textLength);  // Translate unicode data into ascii for rendering  char paintBufMem[TEXT_BUF_SIZE];  char* paintBuf = paintBufMem;  if (textLength > TEXT_BUF_SIZE) {    paintBuf = new char[textLength];    if (!paintBuf) {      return;    }  }  char* dst = paintBuf;  char* end = dst + textLength;  PRUnichar* src = unicodePaintBuffer.mBuffer;  while (dst < end) {    *dst++ = (char) ((unsigned char) *src++);  }  nscoord width = mRect.width;  PRInt32* ip = indexBuffer.mBuffer;  char* text = paintBuf;  nsFrameState  frameState;  PRBool        isSelected;  GetFrameState(&frameState);  isSelected = (frameState & NS_FRAME_SELECTED_CONTENT) == NS_FRAME_SELECTED_CONTENT;  if (0 != textLength) {    if (!displaySelection || !isSelected) {       //if selection is > content length then selection has "slid off"      // 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 {      SelectionDetails *details;      nsCOMPtr<nsIPresShell> shell;      nsCOMPtr<nsIFrameSelection> frameSelection;      nsresult rv = aPresContext->GetShell(getter_AddRefs(shell));      if (NS_SUCCEEDED(rv) && shell){        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;        sdptr = sdptr->mNext;      }      if (details)      {        DrawSelectionIterator iter(details,(PRUnichar *)text,(PRUint32)textLength,aTextStyle);//ITS OK TO CAST HERE THE RESULT WE USE WILLNOT DO BAD CONVERSION        if (iter.First())        {          nscoord currentX = dx;          nscoord newWidth;//temp          while (!iter.IsDone())          {            char *currenttext  = iter.CurrentTextCStrPtr();            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);        }      }      else      {        aRenderingContext.SetColor(aTextStyle.mColor->mColor);        aRenderingContext.DrawString(text, PRUint32(textLength), dx, dy);      }      PaintTextDecorations(aRenderingContext, aStyleContext,                           aTextStyle, dx, dy, width,                           unicodePaintBuffer.mBuffer,                           details, 0, textLength);      sdptr = details;      if (details){        while ((sdptr = details->mNext) != nsnull) {          delete details;          details = sdptr;        }        delete details;      }    }  }  // Cleanup  if (paintBuf != paintBufMem) {    delete [] paintBuf;  }}