} else if (!isPaginated) { aRenderingContext.SetColor(nsCSSRendering::TransformColor(aTextStyle.mColor->mColor,canDarkenColor)); aRenderingContext.DrawString(text, PRUint32(textLength), dx, dy + mAscent); }
else if (!isPaginated) { aRenderingContext.SetColor(nsCSSRendering::TransformColor(aTextStyle.mColor->mColor,canDarkenColor)); aRenderingContext.DrawString(text, PRUint32(textLength), dx, dy + mAscent); } }
nsTextFrame::PaintAsciiText(nsPresContext* aPresContext,                            nsIRenderingContext& aRenderingContext,                            nsStyleContext* aStyleContext,                            TextPaintStyle& aTextStyle,                            nscoord dx, nscoord dy){  NS_PRECONDITION(0 == (TEXT_HAS_MULTIBYTE & mState), "text is multi-byte");  nsCOMPtr<nsISelectionController> selCon;  nsCOMPtr<nsIPresShell> shell;  PRBool  displaySelection,canDarkenColor=PR_FALSE;  PRBool  isPaginated;  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);  }  // Get the text fragment  nsCOMPtr<nsITextContent> tc = do_QueryInterface(mContent);  const nsTextFragment* frag = nsnull;  if (tc) {    frag = tc->Text();    if (!frag) {      return;    }  }  // Make enough space to transform  nsAutoTextBuffer unicodePaintBuffer;  nsAutoIndexBuffer indexBuffer;  if (displaySelection) {    if (NS_FAILED(indexBuffer.GrowTo(mContentLength + 1))) {      return;    }  }  nsTextTransformer tx(lb, nsnull, aPresContext);  // See if we need to transform the text. If the text fragment is ascii and  // wasn't transformed, then we can skip this step. If we're displaying the  // selection and the text is selected, then we need to do this step so we  // can create the index buffer  PRInt32     textLength = 0;  const char* text;  char        paintBufMem[TEXT_BUF_SIZE];  char*       paintBuf = paintBufMem;  if (frag->Is2b() ||      (0 != (mState & TEXT_WAS_TRANSFORMED)) ||      (displaySelection && isSelected)) {        // Transform text from content into Unicode renderable form    // XXX If the text fragment is ascii, then we should ask the    // text transformer to leave the text in ascii. That way we can    // elimninate the conversion from Unicode back to ascii...    PrepareUnicodeText(tx, (displaySelection ? &indexBuffer : nsnull),                       &unicodePaintBuffer, &textLength);    // Translate unicode data into ascii for rendering    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++);    }    text = paintBuf;  }  else if (mContentOffset + mContentLength <= frag->GetLength()) {    text = frag->Get1b() + mContentOffset;    textLength = mContentLength;    // See if we should skip leading whitespace    if (0 != (mState & TEXT_SKIP_LEADING_WS)) {      while ((textLength > 0) && XP_IS_SPACE(*text)) {        text++;        textLength--;      }    }    // See if the text ends in a newline    if ((textLength > 0) && (text[textLength - 1] == '\n')) {      textLength--;    }    NS_ASSERTION(textLength >= 0, "bad text length");  }  else {    // This might happen if a paint event beats the reflow; e.g., as    // is the case in bug 73291. Not a big deal, because the reflow    // will schedule another invalidate.    NS_WARNING("content length exceeds fragment length");  }  nscoord width = mRect.width;  PRInt32* ip = indexBuffer.mBuffer;  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(nsCSSRendering::TransformColor(aTextStyle.mColor->mColor,canDarkenColor));      aRenderingContext.DrawString(text, PRUint32(textLength), dx, dy + mAscent);      PaintTextDecorations(aRenderingContext, aStyleContext,                           aPresContext, aTextStyle, dx, dy, width);    }    else {      SelectionDetails *details;      nsCOMPtr<nsIFrameSelection> frameSelection;//get the frame selection      frameSelection = do_QueryInterface(selCon); //this MAY implement      nsresult rv = NS_OK;      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;        sdptr = sdptr->mNext;      }      DrawSelectionIterator iter(content, details,(PRUnichar *)text,(PRUint32)textLength,aTextStyle, selectionValue, aPresContext, mStyleContext); //ITS OK TO CAST HERE THE RESULT WE USE WILLNOT DO BAD CONVERSION      if (!iter.IsDone() && 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;          PRBool     isCurrentBKColorTransparent;          if (NS_SUCCEEDED(aRenderingContext.GetWidth(currenttext, currentlength,newWidth)))//ADJUST FOR CHAR SPACING          {            if (iter.CurrentBackGroundColor(currentBKColor, &isCurrentBKColorTransparent) && !isPaginated)            {//DRAW RECT HERE!!!              if (!isCurrentBKColorTransparent) {                aRenderingContext.SetColor(currentBKColor);                aRenderingContext.FillRect(currentX, dy, newWidth, mRect.height);              }              currentFGColor = EnsureDifferentColors(currentFGColor, currentBKColor);            }          }          else            newWidth =0;          if (isPaginated && !iter.IsBeforeOrAfter()) {            aRenderingContext.DrawString(currenttext, currentlength, currentX, dy + mAscent);          } else if (!isPaginated) {            aRenderingContext.SetColor(nsCSSRendering::TransformColor(currentFGColor,isPaginated));            aRenderingContext.DrawString(currenttext, currentlength, currentX, dy + mAscent);          }          currentX+=newWidth;//increment twips X start          iter.Next();        }      }      else if (!isPaginated)       {        aRenderingContext.SetColor(nsCSSRendering::TransformColor(aTextStyle.mColor->mColor,canDarkenColor));        aRenderingContext.DrawString(text, PRUint32(textLength), dx, dy + mAscent);      }      PaintTextDecorations(aRenderingContext, aStyleContext, aPresContext,                           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;  }}