Bug 1415581 - get the correct positions of explicit hyphens while calling PropertyProvider::GetHyphenationBreaks. r=jfkthame a=gchang
authorJeremy Chen <jeremychen@mozilla.com>
Fri, 17 Nov 2017 12:00:58 +0800
changeset 704432 63888c62a7937154e9cbf8ebecdecadb734aa8ae
parent 704431 6a0f1693d6641bcb4bb0b00e3ae39ecd7bac3cce
child 704433 af82d0c3342786f2575a3bca847bd7e91d44b1d0
push id91167
push userbmo:csadilek@mozilla.com
push dateTue, 28 Nov 2017 16:21:38 +0000
reviewersjfkthame, gchang
bugs1415581
milestone58.0
Bug 1415581 - get the correct positions of explicit hyphens while calling PropertyProvider::GetHyphenationBreaks. r=jfkthame a=gchang In the current implementation, when hyphens property is set to auto, we do some math to determine the index of text fragment, so we can check whether a character is an explicit hyphen. However, the math calculation is not reliable, and it is not easy to calculate the fragment index when there are more than one fragments in a gfxTextRun, e.g., a paragraph which consists multiple inline elements. In this patch, we simply use GetOriginalOffset() to get the position relative to the current text fragment, and scan/detect explicit hyphens correctly. MozReview-Commit-ID: JIg3tdpViRH
layout/generic/nsTextFrame.cpp
--- a/layout/generic/nsTextFrame.cpp
+++ b/layout/generic/nsTextFrame.cpp
@@ -3673,20 +3673,19 @@ PropertyProvider::GetHyphenationBreaks(R
            run.GetSkippedOffset() > mStart.GetSkippedOffset())
           ? HyphenType::Soft
           : HyphenType::None;
       allowHyphenBreakBeforeNextChar = false;
     }
   }
 
   if (mTextStyle->mHyphens == StyleHyphens::Auto) {
+    uint32_t currentFragOffset = mStart.GetOriginalOffset();
     for (uint32_t i = 0; i < aRange.Length(); ++i) {
-      int32_t fragIndex = mFrag->GetLength() > aRange.end ?
-                          aRange.start + i : i;
-      if (IS_HYPHEN(mFrag->CharAt(fragIndex))) {
+      if (IS_HYPHEN(mFrag->CharAt(currentFragOffset + i))) {
         aBreakBefore[i] = HyphenType::Explicit;
         continue;
       }
 
       if (mTextRun->CanHyphenateBefore(aRange.start + i) &&
           aBreakBefore[i] == HyphenType::None) {
         aBreakBefore[i] = HyphenType::AutoWithoutManualInSameWord;
       }