From 5fd3fef77bcb0a4232a656e72f6f79beb406a2d7 Mon Sep 17 00:00:00 2001 From: "masayuki%d-toybox.com" Date: Wed, 8 Mar 2006 03:30:57 +0000 Subject: [PATCH] Bug 164700 css word-spacing applies at   at paint time but not at layout (reflow) time r+sr=rbs git-svn-id: svn://10.0.0.236/trunk@191955 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/layout/generic/nsTextFrame.cpp | 41 ++++++++++++++++++-- mozilla/layout/generic/nsTextTransformer.cpp | 1 + mozilla/layout/generic/nsTextTransformer.h | 13 ++++--- 3 files changed, 46 insertions(+), 9 deletions(-) diff --git a/mozilla/layout/generic/nsTextFrame.cpp b/mozilla/layout/generic/nsTextFrame.cpp index fab77162a19..ca8ff7c373f 100644 --- a/mozilla/layout/generic/nsTextFrame.cpp +++ b/mozilla/layout/generic/nsTextFrame.cpp @@ -3453,7 +3453,7 @@ nsTextFrame::GetTextDimensionsOrLength(nsIRenderingContext& aRenderingContext, if (ch == kSZLIG) glyphDimensions.width += glyphDimensions.width; } - else if (ch == ' ') { + else if (ch == ' ' || ch == CH_NBSP) { glyphDimensions.width = aStyle.mSpaceWidth + aStyle.mLetterSpacing + aStyle.mWordSpacing; } @@ -5432,6 +5432,12 @@ nsTextFrame::MeasureText(nsPresContext* aPresContext, // since we didn't add the trailing space width, set this flag so that // we will not trim this non-existing space aTextData.mTrailingSpaceTrimmed = PR_TRUE; + // Note: word-spacing or letter-spacing can make the "space" really + // wide. But since this space is left out from our width, linelayout + // may still try to fit something narrower at the end of the line. + // So on return (see below), we flag a break-after status to ensure + // that linelayout doesn't place something where the "space" should + // be. break; } } @@ -5504,6 +5510,20 @@ nsTextFrame::MeasureText(nsPresContext* aPresContext, if (aTs.mLetterSpacing) { dimensions.width += aTs.mLetterSpacing * wordLen; } + + if (aTs.mWordSpacing) { + if (aTx.TransformedTextIsAscii()) { + for (char* bp = bp1; bp < bp1 + wordLen; bp++) { + if (*bp == ' ') // || *bp == CH_CJKSP) + dimensions.width += aTs.mWordSpacing; + } + } else { + for (PRUnichar* bp = bp2; bp < bp2 + wordLen; bp++) { + if (*bp == ' ') // || *bp == CH_CJKSP) + dimensions.width += aTs.mWordSpacing; + } + } + } } lastWordDimensions = dimensions; @@ -5762,6 +5782,13 @@ nsTextFrame::MeasureText(nsPresContext* aPresContext, if (aTs.mLetterSpacing) { lastWordDimensions.width += aTs.mLetterSpacing * lastWordLen; } + if (aTs.mWordSpacing) { + for (PRUnichar* bp = pWordBuf; + bp < pWordBuf + lastWordLen; bp++) { + if (*bp == ' ') // || *bp == CH_CJKSP) + lastWordDimensions.width += aTs.mWordSpacing; + } + } } } nsTextDimensions wordDimensions = ComputeTotalWordDimensions(aPresContext, @@ -5845,9 +5872,11 @@ nsTextFrame::MeasureText(nsPresContext* aPresContext, #endif // IBMBIDI ? NS_FRAME_COMPLETE : NS_FRAME_NOT_COMPLETE; - if (endsInNewline) { + if (endsInNewline || aTextData.mTrailingSpaceTrimmed) { rs = NS_INLINE_LINE_BREAK_AFTER(rs); - lineLayout.SetLineEndsInBR(PR_TRUE); + if (endsInNewline) { + lineLayout.SetLineEndsInBR(PR_TRUE); + } } else if ((aTextData.mOffset != contentLength) && (aTextData.mOffset == startingOffset)) { // Break-before a long-word that doesn't fit here @@ -6487,6 +6516,12 @@ nsTextFrame::ComputeWordFragmentDimensions(nsPresContext* aPresContext, rc.GetTextDimensions(bp, wordLen, dimensions); // NOTE: Don't forget to add letter spacing for the word fragment! dimensions.width += wordLen*ts.mLetterSpacing; + if (ts.mWordSpacing) { + for (PRUnichar* bp2 = bp; bp2 < bp + wordLen; bp2++) { + if (*bp2 == CH_NBSP) // || *bp2 == CH_CJKSP) + dimensions.width += ts.mWordSpacing; + } + } } rc.SetFont(oldfm); diff --git a/mozilla/layout/generic/nsTextTransformer.cpp b/mozilla/layout/generic/nsTextTransformer.cpp index ab6db2e0253..1a297fb566d 100644 --- a/mozilla/layout/generic/nsTextTransformer.cpp +++ b/mozilla/layout/generic/nsTextTransformer.cpp @@ -594,6 +594,7 @@ nsTextTransformer::ScanNormalUnicodeText_F(PRBool aForLineBreak, PRUnichar ch = *cp++; if (CH_NBSP == ch) { ch = ' '; + *aWasTransformed = PR_TRUE; } else if (IS_DISCARDED(ch) || (ch == 0x0a) || (ch == 0x0d)) { // Strip discarded characters from the transformed output diff --git a/mozilla/layout/generic/nsTextTransformer.h b/mozilla/layout/generic/nsTextTransformer.h index 5d1ec03fa57..1b63b30e537 100644 --- a/mozilla/layout/generic/nsTextTransformer.h +++ b/mozilla/layout/generic/nsTextTransformer.h @@ -52,12 +52,13 @@ class nsILineBreaker; class nsIWordBreaker; // XXX I'm sure there are other special characters -#define CH_NBSP 160 -#define CH_ENSP 8194 // -#define CH_EMSP 8195 // -#define CH_THINSP 8291 // -#define CH_ZWNJ 8204 // +#define CH_EMSP 8195 // +#define CH_THINSP 8291 // +#define CH_ZWNJ 8204 //