aRenderingContext.SetColor(aTextStyle.mColor->mColor);
nsTextFrame::PaintUnicodeText(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  PRUnichar wordBufMem[WORD_BUF_SIZE];  PRUnichar paintBufMem[TEXT_BUF_SIZE];  PRInt32 indicies[TEXT_BUF_SIZE];  PRInt32* ip = indicies;  PRUnichar* paintBuf = paintBufMem;  if (mContentLength > TEXT_BUF_SIZE) {    ip = new PRInt32[mContentLength+1];    paintBuf = new PRUnichar[mContentLength];  }  nscoord width = mRect.width;  PRInt32 textLength;  // Transform text from content into renderable form  nsCOMPtr<nsILineBreaker> lb;  doc->GetLineBreaker(getter_AddRefs(lb));  nsCOMPtr<nsIWordBreaker> wb;  doc->GetWordBreaker(getter_AddRefs(wb));  nsTextTransformer tx(wordBufMem, WORD_BUF_SIZE,lb,wb);  PrepareUnicodeText(tx, (displaySelection ? ip : nsnull),                     paintBuf, &textLength);  PRUnichar* text = paintBuf;  nsFrameState  frameState;  PRBool        isSelected;  GetFrameState(&frameState);  isSelected = (frameState & NS_FRAME_SELECTED_CONTENT) == NS_FRAME_SELECTED_CONTENT;  if (0 != textLength) {    if (!displaySelection || !isSelected ) {       // When there is no selection showing, use the fastest and      // simplest rendering approach      aRenderingContext.DrawString(text, PRUint32(textLength), dx, dy);      PaintTextDecorations(aRenderingContext, aStyleContext, aTextStyle,                           dx, dy, width);    }    else {      ip[mContentLength] = ip[mContentLength-1];      if ((ip[mContentLength]-mContentOffset) < textLength) {        //must set up last one for selection beyond edge if in boundary        ip[mContentLength]++;      }      PRInt32 textWidth;      PRInt32 selectionStartOffset = 0;//frame coordinates      PRInt32 selectionEndOffset = 0;//frame coordinates      nsCOMPtr<nsIPresShell> shell;      nsCOMPtr<nsIDOMSelection> selection;      nsCOMPtr<nsIFrameSelection> frameSelection;      PRBool drawSelected = PR_FALSE;      nsresult rv = aPresContext->GetShell(getter_AddRefs(shell));      if (NS_SUCCEEDED(rv) && shell){        rv = shell->GetSelection(getter_AddRefs(selection));        if (NS_SUCCEEDED(rv) && selection){          frameSelection = do_QueryInterface(selection);          nsCOMPtr<nsIContent> content;          rv = GetContent(getter_AddRefs(content));          if (NS_SUCCEEDED(rv)){            rv = frameSelection->LookUpSelection(content, mContentOffset,                                   mContentLength , &selectionStartOffset, &selectionEndOffset,                                  &drawSelected,0);// last param notused          }        }      }              if (frameSelection ){        //where are the selection points "really"        if (drawSelected){          selectionStartOffset = ip[selectionStartOffset] - mContentOffset;          selectionEndOffset = ip[selectionEndOffset]  - mContentOffset;        }        if (!drawSelected || (selectionStartOffset == selectionEndOffset)) {          aRenderingContext.DrawString(text, PRUint32(textLength), dx, dy);          PaintTextDecorations(aRenderingContext, aStyleContext,                               aTextStyle, dx, dy, width);  #ifdef SHOW_SELECTION_CURSOR          aRenderingContext.GetWidth(text, PRUint32(selectionStartOffset), textWidth);          RenderSelectionCursor(aRenderingContext,                              dx + textWidth, dy, mRect.height,                              CURSOR_COLOR);  #endif        }        else {          nscoord x = dx;          if (selectionStartOffset) {            // Render first (unselected) section            aRenderingContext.GetWidth(text, PRUint32(selectionStartOffset),//si.mStartOffset),                                       textWidth);            aRenderingContext.DrawString(text, PRUint32(selectionStartOffset),                                         x, dy);            PaintTextDecorations(aRenderingContext, aStyleContext, aTextStyle,                                 x, dy, textWidth);            x += textWidth;          }          PRInt32 secondLen = selectionEndOffset - selectionStartOffset;           if (0 != secondLen) {            // Get the width of the second (selected) section            aRenderingContext.GetWidth(text + selectionStartOffset,                                       PRUint32(secondLen), textWidth);            // Render second (selected) section            aRenderingContext.SetColor(aTextStyle.mSelectionBGColor);            aRenderingContext.FillRect(x, dy, textWidth, mRect.height);            aRenderingContext.SetColor(aTextStyle.mSelectionTextColor);            aRenderingContext.DrawString(text + selectionStartOffset,                                          PRUint32(secondLen), x, dy);            PaintTextDecorations(aRenderingContext, aStyleContext, aTextStyle,                                 x, dy, textWidth);            aRenderingContext.SetColor(aTextStyle.mColor->mColor);            x += textWidth;          }          if (textLength != selectionEndOffset) {            PRInt32 thirdLen = textLength - selectionEndOffset;            if (thirdLen > 0) //Text length is not negative or zero            {                        // Render third (unselected) section              aRenderingContext.GetWidth(text + selectionEndOffset, PRUint32(thirdLen),                                         textWidth);              aRenderingContext.DrawString(text + selectionEndOffset,                                           PRUint32(thirdLen), x, dy);              PaintTextDecorations(aRenderingContext, aStyleContext, aTextStyle,                                   x, dy, textWidth);            }          }        }      }    }  }  // Cleanup  if (paintBuf != paintBufMem) {    delete [] paintBuf;  }  if (ip != indicies) {    delete [] ip;  }}