From c6c74d8fe2d1f3311631c394cb402f4f81777787 Mon Sep 17 00:00:00 2001 From: "kipp%netscape.com" Date: Mon, 1 Nov 1999 15:36:02 +0000 Subject: [PATCH] r=ftang (someday); fixed bug 17130 - the problem was that nbsp's were being mapped into spaces by the text-transformer which is normally good, but for the purposes of line-breaking look-ahead was bad. I added code to revert the post-transformed spaces into nbsp's before using the line-breaker git-svn-id: svn://10.0.0.236/trunk@52390 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/layout/generic/nsTextFrame.cpp | 26 +++++++++++++++++--- mozilla/layout/html/base/src/nsTextFrame.cpp | 26 +++++++++++++++++--- 2 files changed, 46 insertions(+), 6 deletions(-) diff --git a/mozilla/layout/generic/nsTextFrame.cpp b/mozilla/layout/generic/nsTextFrame.cpp index 3e641079b7b..6b2b0ec33d3 100644 --- a/mozilla/layout/generic/nsTextFrame.cpp +++ b/mozilla/layout/generic/nsTextFrame.cpp @@ -524,7 +524,7 @@ public: const nsHTMLReflowState& aReflowState, nsIFrame* aNextFrame, nscoord aBaseWidth, - const PRUnichar* aWordBuf, + PRUnichar* aWordBuf, PRUint32 aWordBufLen, PRUint32 aWordBufSize); @@ -3181,6 +3181,18 @@ nsTextFrame::TrimTrailingWhiteSpace(nsIPresContext* aPresContext, return NS_OK; } +static void +RevertSpacesToNBSP(PRUnichar* aBuffer, PRInt32 aWordLen) +{ + PRUnichar* end = aBuffer + aWordLen; + for (; aBuffer < end; aBuffer++) { + PRUnichar ch = *aBuffer; + if (ch == ' ') { + *aBuffer = CH_NBSP; + } + } +} + nscoord nsTextFrame::ComputeTotalWordWidth(nsIPresContext* aPresContext, nsILineBreaker* aLineBreaker, @@ -3188,10 +3200,14 @@ nsTextFrame::ComputeTotalWordWidth(nsIPresContext* aPresContext, const nsHTMLReflowState& aReflowState, nsIFrame* aNextFrame, nscoord aBaseWidth, - const PRUnichar* aWordBuf, + PRUnichar* aWordBuf, PRUint32 aWordLen, PRUint32 aWordBufSize) { + // Before we get going, convert any spaces in the current word back + // to nbsp's. This keeps the breaking logic happy. + RevertSpacesToNBSP(aWordBuf, (PRInt32) aWordLen); + nscoord addedWidth = 0; while (nsnull != aNextFrame) { nsIContent* content = nsnull; @@ -3203,7 +3219,7 @@ nsTextFrame::ComputeTotalWordWidth(nsIPresContext* aPresContext, #endif nsITextContent* tc; if (NS_OK == content->QueryInterface(kITextContentIID, (void**)&tc)) { - PRBool stop; + PRBool stop = PR_FALSE; nscoord moreWidth = ComputeWordFragmentWidth(aPresContext, aLineBreaker, aLineLayout, @@ -3270,6 +3286,10 @@ nsTextFrame::ComputeWordFragmentWidth(nsIPresContext* aPresContext, } *aStop = contentLen < tx.GetContentLength(); + // Convert any spaces in the current word back to nbsp's. This keeps + // the breaking logic happy. + RevertSpacesToNBSP(bp, wordLen); + // We need to adjust the length by look at the two pieces together // XXX this should grow aWordBuf if necessary PRUint32 copylen = sizeof(PRUnichar) * diff --git a/mozilla/layout/html/base/src/nsTextFrame.cpp b/mozilla/layout/html/base/src/nsTextFrame.cpp index 3e641079b7b..6b2b0ec33d3 100644 --- a/mozilla/layout/html/base/src/nsTextFrame.cpp +++ b/mozilla/layout/html/base/src/nsTextFrame.cpp @@ -524,7 +524,7 @@ public: const nsHTMLReflowState& aReflowState, nsIFrame* aNextFrame, nscoord aBaseWidth, - const PRUnichar* aWordBuf, + PRUnichar* aWordBuf, PRUint32 aWordBufLen, PRUint32 aWordBufSize); @@ -3181,6 +3181,18 @@ nsTextFrame::TrimTrailingWhiteSpace(nsIPresContext* aPresContext, return NS_OK; } +static void +RevertSpacesToNBSP(PRUnichar* aBuffer, PRInt32 aWordLen) +{ + PRUnichar* end = aBuffer + aWordLen; + for (; aBuffer < end; aBuffer++) { + PRUnichar ch = *aBuffer; + if (ch == ' ') { + *aBuffer = CH_NBSP; + } + } +} + nscoord nsTextFrame::ComputeTotalWordWidth(nsIPresContext* aPresContext, nsILineBreaker* aLineBreaker, @@ -3188,10 +3200,14 @@ nsTextFrame::ComputeTotalWordWidth(nsIPresContext* aPresContext, const nsHTMLReflowState& aReflowState, nsIFrame* aNextFrame, nscoord aBaseWidth, - const PRUnichar* aWordBuf, + PRUnichar* aWordBuf, PRUint32 aWordLen, PRUint32 aWordBufSize) { + // Before we get going, convert any spaces in the current word back + // to nbsp's. This keeps the breaking logic happy. + RevertSpacesToNBSP(aWordBuf, (PRInt32) aWordLen); + nscoord addedWidth = 0; while (nsnull != aNextFrame) { nsIContent* content = nsnull; @@ -3203,7 +3219,7 @@ nsTextFrame::ComputeTotalWordWidth(nsIPresContext* aPresContext, #endif nsITextContent* tc; if (NS_OK == content->QueryInterface(kITextContentIID, (void**)&tc)) { - PRBool stop; + PRBool stop = PR_FALSE; nscoord moreWidth = ComputeWordFragmentWidth(aPresContext, aLineBreaker, aLineLayout, @@ -3270,6 +3286,10 @@ nsTextFrame::ComputeWordFragmentWidth(nsIPresContext* aPresContext, } *aStop = contentLen < tx.GetContentLength(); + // Convert any spaces in the current word back to nbsp's. This keeps + // the breaking logic happy. + RevertSpacesToNBSP(bp, wordLen); + // We need to adjust the length by look at the two pieces together // XXX this should grow aWordBuf if necessary PRUint32 copylen = sizeof(PRUnichar) *