nsIFontMetrics* nextFont; nscoord nextY, glyphWidth;
nscoord glyphWidth;
TextFrame::GetWidth(nsIRenderingContext& aRenderingContext,                    TextStyle& aTextStyle,                    PRUnichar* aBuffer, PRInt32 aLength,                    nscoord& aWidthResult){  PRUnichar buf[TEXT_BUF_SIZE];  PRUnichar* bp0 = buf;  if (aLength > TEXT_BUF_SIZE) {    bp0 = new PRUnichar[aLength];  }  PRUnichar* bp = bp0;  nsIFontMetrics* lastFont = aTextStyle.mLastFont;  nscoord sum = 0;  PRInt32 pendingCount;  PRUnichar* runStart = bp;  nscoord charWidth;  for (; --aLength >= 0; aBuffer++) {    nsIFontMetrics* nextFont;    nscoord nextY, glyphWidth;    PRUnichar ch = *aBuffer;    if (aTextStyle.mSmallCaps && nsCRT::IsLower(ch)) {      nextFont = aTextStyle.mSmallFont;      ch = nsCRT::ToUpper(ch);      if (lastFont != aTextStyle.mSmallFont) {        aRenderingContext.SetFont(aTextStyle.mSmallFont);        aRenderingContext.GetWidth(ch, charWidth);        aRenderingContext.SetFont(aTextStyle.mNormalFont);      }      else {        aRenderingContext.GetWidth(ch, charWidth);      }      glyphWidth = charWidth + aTextStyle.mLetterSpacing;    }    else if (ch == ' ') {      nextFont = aTextStyle.mNormalFont;      glyphWidth = aTextStyle.mSpaceWidth + aTextStyle.mWordSpacing;      nscoord extra = aTextStyle.mExtraSpacePerSpace;      if (--aTextStyle.mNumSpaces == 0) {        extra += aTextStyle.mRemainingExtraSpace;      }      glyphWidth += extra;    }    else {      if (lastFont != aTextStyle.mNormalFont) {        aRenderingContext.SetFont(aTextStyle.mNormalFont);        aRenderingContext.GetWidth(ch, charWidth);        aRenderingContext.SetFont(aTextStyle.mSmallFont);      }      else {        aRenderingContext.GetWidth(ch, charWidth);      }      nextFont = aTextStyle.mNormalFont;      glyphWidth = charWidth + aTextStyle.mLetterSpacing;    }    if (nextFont != lastFont)      lastFont = nextFont;    sum += glyphWidth;    *bp++ = ch;  }  if (bp0 != buf) {    delete [] bp0;  }  aTextStyle.mLastFont = lastFont;  aWidthResult = sum;}