} if (strstr(buf, "font5")) {
}*/ if (strstr(buf, "paragraph")) {
TextFrame::PaintRegularText(nsIPresContext& aPresContext,                            nsIRenderingContext& aRenderingContext,                            const nsRect& aDirtyRect,                            nscoord dx, nscoord dy){  // Get Selection Object  nsIPresShell * shell = aPresContext.GetShell();  nsIDocument  * doc   = shell->GetDocument();    if (doc->GetDisplaySelection() == PR_FALSE)  {    // Skip leading space if necessary    Text* txt = (Text*) mContent;    const PRUnichar* cp = txt->mText + mContentOffset;    const PRUnichar* end = cp + mContentLength;    if ((mFlags & TEXT_SKIP_LEADING_WS) != 0) {      while (cp < end) {        PRUnichar ch = *cp++;        if (!XP_IS_SPACE(ch)) {          cp--;          break;        }      }    }    if ((mFlags & TEXT_IS_PRE) != 0) {      if ((mFlags & TEXT_HAS_MULTIBYTE) != 0) {        // XXX to be written      } else {        PRIntn tabs = TEXT_GET_TAB_COUNT(mFlags);        // Make a copy of the text we are to render, translating tabs        // into whitespace.        char buf[100];        char* s = buf;        char* s0 = s;        PRInt32 maxLen = (end - cp) + 8*tabs;        if (maxLen > sizeof(buf)) {          s0 = s = new char[maxLen];        }        // Translate tabs into whitespace; translate other whitespace into        // spaces.        PRIntn col = (PRIntn) mColumn;        while (cp < end) {          PRUint8 ch = (PRUint8) *cp++;          if (XP_IS_SPACE(ch)) {            if (ch == '\t') {              PRIntn spaces = 8 - (col & 7);              col += spaces;              while (--spaces >= 0) {                *s++ = ' ';              }              continue;            } else {              *s++ = ' ';            }          } else if (ch == CH_NBSP) {            *s++ = ' ';          } else {            *s++ = ch;          }          col++;        }        // Render the text        const nsStyleColor* color = (const nsStyleColor*)mStyleContext->GetStyleData(eStyleStruct_Color);        aRenderingContext.SetColor(color->mColor);        aRenderingContext.DrawString(s0, s - s0, dx, dy, mRect.width);/*        // ROD -- WARNING!!!!!        // 1.The fixed size buffers causes the application to CRASH.        // 2 These statements do not appear to do anything.        char cmpBuf[256];        char sBuf[256];        int len = s - s0;        strncpy(cmpBuf, compressedStr, compressedStrLen);        cmpBuf[compressedStrLen] = 0;        strncpy(sBuf, s0, len);        cmpBuf[compressedStrLen] = 0;        if (compressedStrLen != (PRUint32)len ||            strcmp(cmpBuf, sBuf)) {          int x = 0;        }*/        if (s0 != buf) {          delete[] s0;        }      }    } else {      if ((mFlags & TEXT_HAS_MULTIBYTE) != 0) {        // XXX to be written      } else {        // Make a copy of the text we are to render, compressing out        // whitespace; translating whitespace to literal spaces;        // eliminating trailing whitespace.        char buf[100];        char* s = buf;        char* s0 = s;        PRInt32 maxLen = end - cp;        if (maxLen > sizeof(buf)) {          s0 = s = new char[maxLen];        }        // Compress down the whitespace        while (cp < end) {          PRUint8 ch = (PRUint8) *cp++;          if (XP_IS_SPACE(ch)) {            while (cp < end) {              ch = (PRUint8) *cp++;              if (!XP_IS_SPACE(ch)) {                cp--;                break;              }            }            *s++ = ' ';          } else {            *s++ = ch;          }        }        // Render the text        const nsStyleColor* color = (const nsStyleColor*)mStyleContext->GetStyleData(eStyleStruct_Color);        aRenderingContext.SetColor(color->mColor);        aRenderingContext.DrawString(s0, s - s0, dx, dy, mRect.width);/*        // ROD -- WARNING!!!!!        // 1.The fixed size buffers causes the application to CRASH.        // 2 These statements do not appear to do anything.        // gpk        char cmpBuf[256];        char sBuf[256];        int len = s - s0;        strncpy(cmpBuf, compressedStr, compressedStrLen);        cmpBuf[compressedStrLen] = 0;        strncpy(sBuf, s0, len);        sBuf[len] = 0;        if (compressedStrLen != (PRUint32)len ||            strcmp(cmpBuf, sBuf)) {          int x = 0;        }*/        if (s0 != buf) {          delete[] s0;        }      }    }    NS_RELEASE(doc);    NS_RELEASE(shell);    return;  }  PRBool   delCompressedStr;  PRUint16 indexes[1024];  PRUint32 compressedStrLen = 0;  char     buf[128];  char *   compressedStr  = CompressWhiteSpace(buf, sizeof(buf), indexes, compressedStrLen, delCompressedStr);    nsIDeviceContext * deviceContext = aRenderingContext.GetDeviceContext();    nsISelection     * selection = doc->GetSelection();  nsSelectionRange * range     = selection->GetRange();  nsSelectionPoint * startPnt  = range->GetStartPoint();  nsSelectionPoint * endPnt    = range->GetEndPoint();  nsIContent       * startContent = startPnt->GetContent();  nsIContent       * endContent   = endPnt->GetContent();  PRBool startEndInSameContent;  // This is a little more optimized,   // Check to see if the start and end points are in the same content   if (mContent == startContent && mContent == endContent) {    startEndInSameContent = PR_TRUE;  // If this gets set to TRUE then we get to skip the IsInRange check    // The Start & End contents are the same     // Now check to see if it is an "insert" cursor     if (startPnt->GetOffset() == endPnt->GetOffset()) {      /*nsString target;      startContent->GetAttribute(nsString("target"), target);      if (target.Length() == 0) {        int x = 0;        startContent->GetAttribute(nsString(NS_HTML_BASE_TARGET), target);        printf("Target length %d\n", target.Length());      }      printf("Target length %d\n", target.Length());*/		  // Render the text Normal		  const nsStyleColor* color = (const nsStyleColor*)mStyleContext->GetStyleData(eStyleStruct_Color);		  aRenderingContext.SetColor(color->mColor);		  aRenderingContext.DrawString(compressedStr, compressedStrLen, dx, dy, mRect.width);      // If cursor is in this frame the draw it      if (startPnt->GetOffset() >= mContentOffset &&          startPnt->GetOffset() < mContentOffset+mContentLength) { // Draw Cursor Only        nsIFontMetrics * fm = aRenderingContext.GetFontMetrics();		    nsString textStr;		    textStr.Append(compressedStr, endPnt->GetOffset()- mContentOffset);		    nscoord textLen = fm->GetWidth(deviceContext, textStr);        // Draw little blue triangle		    aRenderingContext.SetColor(NS_RGB(0,0,255));        nsPoint pnts[4];        nscoord ox = mRect.height / 4;        nscoord oy = ox;        nscoord yy = mRect.height;        pnts[0].x = textLen-ox;        pnts[0].y = yy;        pnts[1].x = textLen;        pnts[1].y = yy-oy;        pnts[2].x = textLen+ox;        pnts[2].y = yy;        pnts[3].x = textLen-ox;        pnts[3].y = yy;        //aRenderingContext.DrawPolygon(pnts, 4);        aRenderingContext.FillPolygon(pnts, 4);		    //aRenderingContext.DrawLine(textLen, mRect.height-(mRect.height/3), textLen, mRect.height);        NS_RELEASE(fm);      }      NS_IF_RELEASE(startContent);      NS_IF_RELEASE(endContent);      NS_IF_RELEASE(selection);      NS_RELEASE(doc);      NS_RELEASE(shell);      return;    }   } else {    startEndInSameContent = PR_FALSE;  }  if (startEndInSameContent || doc->IsInRange(startContent, endContent, mContent)) {    nsIFontMetrics * fm = aRenderingContext.GetFontMetrics();    PRInt32 startOffset = startPnt->GetOffset() - mContentOffset;    PRInt32 endOffset   = endPnt->GetOffset()   - mContentOffset;    nsRect rect;    GetRect(rect);    rect.x = 0;     // HACK!!!: Not sure why x and y value are sometime garbage -- gpk    rect.y = 0;    rect.width--;    rect.height--;#ifdef DO_SELECTION    {      char buf[255];      strncpy(buf, compressedStr, compressedStrLen);      buf[compressedStrLen] = 0;      printf("2 - Drawing [%s] at [%d,%d,%d,%d]\n", buf, rect.x, rect.y, rect.width, rect.height);      /*if (strstr(buf, "Example")) {        int xx = 0;        xx++;      }      if (strstr(buf, "basic4")) {        int xx = 0;        xx++;      }      if (strstr(buf, "font5")) {        int xx = 0;        xx++;      }      if (strstr(buf, "green")) {        int xx = 0;        xx++;      }*/    }#endif    if (startEndInSameContent) {      // Assume here the offsets are different       // because we have already taken care of case where they are      // Render the text Normal      const nsStyleColor* color = (const nsStyleColor*)mStyleContext->GetStyleData(eStyleStruct_Color);      aRenderingContext.SetColor(color->mColor);      //---------------------------------------------------      // Calc the starting point of the Selection and      // and draw from the beginning to where the selection starts      //---------------------------------------------------      nsString textStr;      nscoord  startTwipLen = 0;      nscoord  endCoord;       nscoord  startCoord;      PRBool skip = PR_FALSE;      startCoord = 0;      if (startPnt->GetOffset() > mContentOffset+mContentLength) {        skip = PR_TRUE;      } else if (startPnt->GetOffset() <= mContentOffset) {        //startCoord = 0;      } else {        startCoord = indexes[startPnt->GetOffset()-mContentOffset]-mContentOffset;        /*PRUint32 i;        for (i=0;i<mContentLength;i++) {          if (indexes[i] == startPnt->GetOffset()) {            startCoord = i;            break;          }        }*/      }      endCoord = mContentLength;      if (endPnt->GetOffset() > mContentOffset+mContentLength) {        //endCoord = mContentLength;      } else if (endPnt->GetOffset() <= mContentOffset) {        //endCoord = mContentLength;        skip = PR_TRUE;      } else {        if (endPnt->GetOffset() == (PRInt32)compressedStrLen) {          endCoord = compressedStrLen;        } else {          endCoord = indexes[endPnt->GetOffset()-mContentOffset]-mContentOffset;        }      }       PRUint32 selTextCharLen = endCoord - startCoord;      if (startCoord > 0) {        textStr.Append(compressedStr, startCoord);        startTwipLen = fm->GetWidth(deviceContext, textStr);        aRenderingContext.DrawString(compressedStr, startCoord, dx, dy, startTwipLen);      }      //---------------------------------------------------      // Calc the starting point of the Selection and      // and draw the selected text       //---------------------------------------------------      textStr.SetLength(0);      textStr.Append(compressedStr+startCoord, selTextCharLen);      nscoord selTextTwipLen = fm->GetWidth(deviceContext, textStr);      rect.x     = startTwipLen;      rect.width = selTextTwipLen;      if (!skip) {        // Render Selected Text        aRenderingContext.SetColor(NS_RGB(0,0,0));        aRenderingContext.FillRect(rect);        // Render the text in White        aRenderingContext.SetColor(NS_RGB(255,255,255));      }      aRenderingContext.DrawString(compressedStr+startCoord, selTextCharLen,                                   dx+startTwipLen, dy, selTextTwipLen);      //---------------------------------------------------      // Calc the end point of the Selection and      // and draw the remaining text       //---------------------------------------------------      if (endCoord < (PRInt32)compressedStrLen && !skip) {        textStr.SetLength(0);        textStr.Append(compressedStr+endCoord, compressedStrLen-selTextCharLen);        PRUint32 endTextTwipLen = fm->GetWidth(deviceContext, textStr);        aRenderingContext.SetColor(color->mColor);        aRenderingContext.DrawString(compressedStr+endCoord, compressedStrLen-endCoord,                                      dx+startTwipLen+selTextTwipLen, dy, mRect.width-endTextTwipLen);      }    } else if (mContent == startContent) {      if (startPnt->GetOffset() >= mContentOffset &&           startPnt->GetOffset() < mContentOffset+mContentLength) {        // Render the text Normal        const nsStyleColor* color = (const nsStyleColor*)mStyleContext->GetStyleData(eStyleStruct_Color);        aRenderingContext.SetColor(color->mColor);        PRInt32 startOffset = 0;        startOffset = indexes[startPnt->GetOffset()-mContentOffset]-mContentOffset;        //---------------------------------------------------        // Calc the starting point of the Selection and        // and draw from the beginning to where the selection starts        //---------------------------------------------------        nsString textStr;        nscoord  startTwipLen   = 0;        PRUint32 selTextCharLen = compressedStrLen-startOffset;        if (startOffset > 0) {          textStr.Append(compressedStr, startOffset);          startTwipLen = fm->GetWidth(deviceContext, textStr);          aRenderingContext.DrawString(compressedStr, startOffset, dx, dy, startTwipLen);        }        //---------------------------------------------------        // Calc the starting point of the Selection and        // and draw the selected text         //---------------------------------------------------        textStr.SetLength(0);        textStr.Append(compressedStr+startOffset, selTextCharLen);        nscoord selTextTwipLen = fm->GetWidth(deviceContext, textStr);        rect.x     = startTwipLen;        rect.width = selTextTwipLen;        // Render Selected Text        aRenderingContext.SetColor(NS_RGB(0,0,0));        aRenderingContext.FillRect(rect);        aRenderingContext.SetColor(NS_RGB(255,255,255));        // Render the text in White        aRenderingContext.DrawString(compressedStr+startOffset, selTextCharLen,                                     dx+startTwipLen, dy, selTextTwipLen);      } else {        if (startPnt->GetOffset() < mContentOffset) {          aRenderingContext.SetColor(NS_RGB(0,0,0));          aRenderingContext.FillRect(rect);          aRenderingContext.SetColor(NS_RGB(255,255,255));        } else {          const nsStyleColor* color = (const nsStyleColor*)mStyleContext->GetStyleData(eStyleStruct_Color);          aRenderingContext.SetColor(color->mColor);        }        // Render the text in White        aRenderingContext.DrawString(compressedStr, compressedStrLen, dx, dy, mRect.width);      }    } else if (mContent == endContent) {      if (endPnt->GetOffset() > mContentOffset &&           endPnt->GetOffset() <= mContentOffset+mContentLength) {        if (endPnt->GetOffset() == mContentOffset+mContentLength) {          endOffset = compressedStrLen;        } else {          if (endPnt->GetOffset() == (PRInt32)compressedStrLen) {            endOffset = compressedStrLen;          } else {            endOffset = indexes[endPnt->GetOffset()-mContentOffset]-mContentOffset;          }        }        //---------------------------------------------------        // Calc the starting point of the Selection and        // and draw from the beginning to where the selection starts        //---------------------------------------------------        nsString textStr;        PRUint32 selTextCharLen = endOffset;        //---------------------------------------------------        // Calc the starting point of the Selection and        // and draw the selected text         //---------------------------------------------------        textStr.SetLength(0);        textStr.Append(compressedStr, selTextCharLen);        nscoord selTextTwipLen = fm->GetWidth(deviceContext, textStr);        rect.width = selTextTwipLen;        // Render Selected Text        aRenderingContext.SetColor(NS_RGB(0,0,0));        aRenderingContext.FillRect(rect);        aRenderingContext.SetColor(NS_RGB(255,255,255));        // Render the text in White        aRenderingContext.DrawString(compressedStr, selTextCharLen,  dx, dy, selTextTwipLen);        //---------------------------------------------------        // Calc the end point of the Selection and        // and draw the remaining text         //---------------------------------------------------        textStr.SetLength(0);        textStr.Append(compressedStr+endOffset, compressedStrLen-selTextCharLen);        PRUint32 endTextTwipLen = fm->GetWidth(deviceContext, textStr);        const nsStyleColor* color = (const nsStyleColor*)mStyleContext->GetStyleData(eStyleStruct_Color);        aRenderingContext.SetColor(color->mColor);        aRenderingContext.DrawString(compressedStr+endOffset, compressedStrLen-endOffset,                                      dx+selTextTwipLen, dy, mRect.width-endTextTwipLen);      } else {        if (endPnt->GetOffset() > mContentOffset+mContentLength) {          aRenderingContext.SetColor(NS_RGB(0,0,0));          aRenderingContext.FillRect(rect);          aRenderingContext.SetColor(NS_RGB(255,255,255));        } else {          const nsStyleColor* color = (const nsStyleColor*)mStyleContext->GetStyleData(eStyleStruct_Color);          aRenderingContext.SetColor(color->mColor);        }        aRenderingContext.DrawString(compressedStr, compressedStrLen, dx, dy, mRect.width);      }        } else {      aRenderingContext.SetColor(NS_RGB(0,0,0));      aRenderingContext.FillRect(rect);      aRenderingContext.SetColor(NS_RGB(255,255,255));      // Render the text      aRenderingContext.DrawString(compressedStr, compressedStrLen, dx, dy, mRect.width);      //const nsStyleColor* color = (const nsStyleColor*)mStyleContext->GetStyleData(eStyleStruct_Color);      //aRenderingContext.SetColor(color->mColor);    }    NS_RELEASE(fm);  } else {    // Render the text    const nsStyleColor* color = (const nsStyleColor*)mStyleContext->GetStyleData(eStyleStruct_Color);    aRenderingContext.SetColor(color->mColor);    aRenderingContext.DrawString(compressedStr, compressedStrLen, dx, dy, mRect.width);  }  if (delCompressedStr) {    delete compressedStr;  }  //printf("startContent %d\n", startContent?startContent->Release():-1);  //printf("endContent %d\n", endContent?endContent->Release():-1);  NS_IF_RELEASE(deviceContext);  NS_IF_RELEASE(startContent);  NS_IF_RELEASE(endContent);  NS_RELEASE(shell);  NS_RELEASE(doc);  NS_RELEASE(selection);}