Prevent duplicate entries in the line-break array. Bug 404204, b+r+sr=roc
authorsmontagu@smontagu.org
Mon, 26 Nov 2007 00:27:06 -0800
changeset 8330 8229d0b8edc2b6e8ed41f8020d12b4e41722ba69
parent 8329 9ab4cf729815adca6b7d08b94c923c04a33f369e
child 8331 ceb55eca2888634de1a8136ddc089d4bfd8e469a
push idunknown
push userunknown
push dateunknown
bugs404204
milestone1.9b2pre
Prevent duplicate entries in the line-break array. Bug 404204, b+r+sr=roc
layout/generic/nsTextFrameThebes.cpp
layout/generic/nsTextFrameUtils.h
layout/generic/nsTextRunTransformations.cpp
--- a/layout/generic/nsTextFrameThebes.cpp
+++ b/layout/generic/nsTextFrameThebes.cpp
@@ -1317,24 +1317,16 @@ GetFontMetrics(gfxFontGroup* aFontGroup)
   if (!aFontGroup)
     return gfxFont::Metrics();
   gfxFont* font = aFontGroup->GetFontAt(0);
   if (!font)
     return gfxFont::Metrics();
   return font->GetMetrics();
 }
 
-static void
-AppendLineBreakOffset(nsTArray<PRUint32>* aArray, PRUint32 aOffset)
-{
-  if (aArray->Length() > 0 && (*aArray)[aArray->Length() - 1] == aOffset)
-    return;
-  aArray->AppendElement(aOffset);
-}
-
 void
 BuildTextRunsScanner::BuildTextRunForFrames(void* aTextBuffer)
 {
   gfxSkipCharsBuilder builder;
 
   const void* textPtr = aTextBuffer;
   PRBool anySmallcapsStyle = PR_FALSE;
   PRBool anyTextTransformStyle = PR_FALSE;
@@ -1527,21 +1519,22 @@ BuildTextRunsScanner::BuildTextRunForFra
   gfxSkipChars skipChars;
   skipChars.TakeFrom(&builder);
   // Convert linebreak coordinates to transformed string offsets
   NS_ASSERTION(nextBreakIndex == mLineBreakBeforeFrames.Length(),
                "Didn't find all the frames to break-before...");
   gfxSkipCharsIterator iter(skipChars);
   nsAutoTArray<PRUint32,50> textBreakPointsAfterTransform;
   for (i = 0; i < textBreakPoints.Length(); ++i) {
-    AppendLineBreakOffset(&textBreakPointsAfterTransform, 
+    nsTextFrameUtils::AppendLineBreakOffset(&textBreakPointsAfterTransform, 
             iter.ConvertOriginalToSkipped(textBreakPoints[i]));
   }
   if (mStartOfLine) {
-    AppendLineBreakOffset(&textBreakPointsAfterTransform, transformedLength);
+    nsTextFrameUtils::AppendLineBreakOffset(&textBreakPointsAfterTransform,
+                                            transformedLength);
   }
 
   // Setup factory chain
   nsAutoPtr<nsTransformingTextRunFactory> transformingFactory;
   if (anySmallcapsStyle) {
     transformingFactory = new nsFontVariantTextRunFactory();
   }
   if (anyTextTransformStyle) {
--- a/layout/generic/nsTextFrameUtils.h
+++ b/layout/generic/nsTextFrameUtils.h
@@ -108,16 +108,25 @@ public:
                                   PRUint32* aAnalysisFlags);
 
   static PRUint8* TransformText(const PRUint8* aText, PRUint32 aLength,
                                 PRUint8* aOutput,
                                 PRBool aCompressWhitespace,
                                 PRPackedBool* aIncomingWhitespace,
                                 gfxSkipCharsBuilder* aSkipChars,
                                 PRUint32* aAnalysisFlags);
+
+  static void
+  AppendLineBreakOffset(nsTArray<PRUint32>* aArray, PRUint32 aOffset)
+  {
+    if (aArray->Length() > 0 && (*aArray)[aArray->Length() - 1] == aOffset)
+      return;
+    aArray->AppendElement(aOffset);
+  }
+
 };
 
 class nsSkipCharsRunIterator {
 public:
   enum LengthMode {
     LENGTH_UNSKIPPED_ONLY   = PR_FALSE,
     LENGTH_INCLUDES_SKIPPED = PR_TRUE
   };
--- a/layout/generic/nsTextRunTransformations.cpp
+++ b/layout/generic/nsTextRunTransformations.cpp
@@ -101,24 +101,24 @@ nsTransformedTextRun::SetLineBreaks(PRUi
       break;
     newBreaks.AppendElement(pos);
   }
   if (aLineBreakBefore != (i < mLineBreaks.Length() &&
                            mLineBreaks[i] == aStart)) {
     changed = PR_TRUE;
   }
   if (aLineBreakBefore) {
-    newBreaks.AppendElement(aStart);
+    nsTextFrameUtils::AppendLineBreakOffset(&newBreaks, aStart);
   }
   if (aLineBreakAfter != (i + 1 < mLineBreaks.Length() &&
                           mLineBreaks[i + 1] == aStart + aLength)) {
     changed = PR_TRUE;
   }
   if (aLineBreakAfter) {
-    newBreaks.AppendElement(aStart + aLength);
+    nsTextFrameUtils::AppendLineBreakOffset(&newBreaks, aStart + aLength);
   }
   for (; i < mLineBreaks.Length(); ++i) {
     if (mLineBreaks[i] > aStart + aLength)
       break;
     changed = PR_TRUE;
   }
   if (!changed) {
     if (aAdvanceWidthDelta) {