nsCOMPtr<nsILineBreaker> lb; doc->GetLineBreaker(getter_AddRefs(lb)); nsTextTransformer tx(lb, nsnull, aPresContext);
nsTextTransformer tx(doc->GetLineBreaker(), nsnull, aPresContext);
nsTextFrame::GetPointFromOffset(nsIPresContext* aPresContext,                                nsIRenderingContext* inRendContext,                                PRInt32 inOffset,                                nsPoint* outPoint){  if (!aPresContext || !inRendContext || !outPoint)    return NS_ERROR_NULL_POINTER;  if (mContentLength <= 0) {    outPoint->x = 0;    outPoint->y = 0;    return NS_OK;  }  inOffset-=mContentOffset;  if (inOffset < 0){    NS_ASSERTION(0,"offset less than this frame has in GetPointFromOffset");    inOffset = 0;  }  if (inOffset >= mContentLength)    inOffset = mContentLength;  TextStyle ts(aPresContext, *inRendContext, mStyleContext);  // Make enough space to transform  nsAutoTextBuffer paintBuffer;  nsAutoIndexBuffer indexBuffer;  nsresult rv = indexBuffer.GrowTo(mContentLength + 1);  if (NS_FAILED(rv)) {    return rv;  }  // Transform text from content into renderable form  nsCOMPtr<nsIDocument> doc(GetDocument(aPresContext));  nsCOMPtr<nsILineBreaker> lb;  doc->GetLineBreaker(getter_AddRefs(lb));  nsTextTransformer tx(lb, nsnull, aPresContext);  PRInt32 textLength;  PRInt32 numSpaces;  numSpaces = PrepareUnicodeText(tx, &indexBuffer, &paintBuffer, &textLength);  ComputeExtraJustificationSpacing(*inRendContext, ts, paintBuffer.mBuffer, textLength, numSpaces);  PRInt32* ip = indexBuffer.mBuffer;  if (inOffset > mContentLength){    NS_ASSERTION(0, "invalid offset passed to GetPointFromOffset");    inOffset = mContentLength;  }  while (inOffset >=0 && ip[inOffset] < mContentOffset) //buffer has shrunk    inOffset --;  nscoord width = mRect.width;  if (inOffset <0)  {    NS_ASSERTION(0, "invalid offset passed to GetPointFromOffset");    inOffset=0;    width = 0;  }  else  {    PRInt32 hitLength = ip[inOffset] - mContentOffset;    if (ts.mSmallCaps || (0 != ts.mWordSpacing) || (0 != ts.mLetterSpacing) || ts.mJustifying)    {      nsTextDimensions dimensions;      GetTextDimensions(*inRendContext, ts, paintBuffer.mBuffer, hitLength, &dimensions);      width = dimensions.width;    }    else    {      PRInt32 totalLength = 0; // length up to the last-in-flow frame      nsCOMPtr<nsITextContent> tc(do_QueryInterface(mContent));      if (tc) {        const nsTextFragment* frag;        tc->GetText(&frag);        totalLength = frag->GetLength(); // raw value which includes whitespace      }      if ((hitLength == textLength) && (inOffset = mContentLength) &&          (mContentOffset + mContentLength == totalLength)) {        // no need to re-measure when at the end of the last-in-flow      }      else        inRendContext->GetWidth(paintBuffer.mBuffer, hitLength, width);    }    if ((hitLength == textLength) && (TEXT_TRIMMED_WS & mState)) {      //      // Offset must be after a space that has      // been trimmed off the end of the frame.      // Add the width of the trimmed space back      // to the total width, so the caret appears      // in the proper place!      //      // NOTE: the trailing whitespace includes the word and letter spacing!!      width += ts.mSpaceWidth + ts.mWordSpacing + ts.mLetterSpacing;    }  }#ifdef IBMBIDI  PRUint8 level;  GetBidiProperty(aPresContext, nsLayoutAtoms::embeddingLevel, (void**)&level,sizeof(level));  if (level & 1) {    outPoint->x = mRect.width - width;  }  else#endif // IBMBIDI  //XXX callers need to safeguard themselves against empty frames, I noted that  //the caret can be locked when leftarrow'ing in: <span>...</span>\n<br>line  if (width > mRect.width)    outPoint->x = mRect.width;  else    outPoint->x = width;  outPoint->y = 0;  return NS_OK;}