Bug 1678756 - Check we don't run off the end of the textPath while skipping characters r=emilio
authorlongsonr <longsonr@gmail.com>
Sat, 05 Dec 2020 21:05:41 +0000
changeset 559579 4410515e06c75b927687488f1707dc36b1c838ca
parent 559578 7f5fad730196dc402439111f3b553624f5b842fc
child 559580 5ead3aca145cc49854e5a1f2fcad21e6b629600f
push id38007
push userrmaries@mozilla.com
push dateSun, 06 Dec 2020 09:30:54 +0000
treeherdermozilla-central@5a17a9893fe0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersemilio
bugs1678756
milestone85.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1678756 - Check we don't run off the end of the textPath while skipping characters r=emilio The textcase and reference differ by a single space. We should check that we've not run off the end of the path while we're skipping characters Also removes a redundant check presumably left over from some earlier refactoring. Differential Revision: https://phabricator.services.mozilla.com/D97828
layout/reftests/svg/text/reftest.list
layout/reftests/svg/text/textpath-cluster-ref.svg
layout/reftests/svg/text/textpath-cluster.svg
layout/svg/SVGTextFrame.cpp
--- a/layout/reftests/svg/text/reftest.list
+++ b/layout/reftests/svg/text/reftest.list
@@ -109,16 +109,17 @@ fails-if(geckoview) == multiple-chunks-m
 == simple-multiline-number.svg simple-multiline-number-ref.svg
 == simple-multiline-pc.svg simple-multiline-pc-ref.svg
 == simple-multiline-anchor-end.svg simple-multiline-anchor-end-ref.svg
 
 random-if(/^Windows\x20NT\x206\.1/.test(http.oscpu)) fuzzy-if(skiaContent,0-1,0-15) == textpath.svg textpath-ref.svg # Bug 1392106
 random-if(/^Windows\x20NT\x206\.1/.test(http.oscpu)) == textpath-a.svg textpath-a-ref.svg # Bug 1392106
 random-if(/^Windows\x20NT\x206\.1/.test(http.oscpu)) == textpath-anchor-middle.svg textpath-anchor-middle-ref.svg # Bug 1392106
 random-if(/^Windows\x20NT\x206\.1/.test(http.oscpu)) == textpath-anchor-end.svg textpath-anchor-end-ref.svg # Bug 1392106
+random-if(/^Windows\x20NT\x206\.1/.test(http.oscpu)) == textpath-cluster.svg textpath-cluster-ref.svg # Bug 1392106
 random-if(/^Windows\x20NT\x206\.1/.test(http.oscpu)) == textpath-invalid-parent.svg textpath-invalid-parent-ref.svg # Bug 1392106
 random-if(/^Windows\x20NT\x206\.1/.test(http.oscpu)) == textpath-multiline.svg textpath-multiline-ref.svg # Bug 1392106
 random-if(/^Windows\x20NT\x206\.1/.test(http.oscpu)) == textpath-multiline-2.svg textpath-multiline-2-ref.svg # Bug 1392106
 random-if(/^Windows\x20NT\x206\.1/.test(http.oscpu)) == textpath-after.svg textpath-after-ref.svg # Bug 1392106
 random-if(/^Windows\x20NT\x206\.1/.test(http.oscpu)) == textpath-after-anchor-end.svg textpath-after-anchor-end-ref.svg # Bug 1392106
 random-if(/^Windows\x20NT\x206\.1/.test(http.oscpu)) == textpath-reset-position.svg textpath-reset-position-ref.svg # Bug 1392106
 random-if(/^Windows\x20NT\x206\.1/.test(http.oscpu)) == textpath-inherit-position.svg textpath-inherit-position-ref.svg # Bug 1392106
 
new file mode 100644
--- /dev/null
+++ b/layout/reftests/svg/text/textpath-cluster-ref.svg
@@ -0,0 +1,12 @@
+<svg width="500" height="500" xmlns="http://www.w3.org/2000/svg" >
+  <defs>
+    <path id="path" d="M 100 200 C 200 100 300 0 400 100" />
+    <style>
+      text {
+        font: 40px monospace;
+      }
+    </style>
+  </defs>
+
+  <text transform="translate(0, 40)">a <textPath href="#path">b </textPath>c</text>
+</svg>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/svg/text/textpath-cluster.svg
@@ -0,0 +1,12 @@
+<svg width="500" height="500" xmlns="http://www.w3.org/2000/svg" >
+  <defs>
+    <path id="path" d="M 100 200 C 200 100 300 0 400 100" />
+    <style>
+      text {
+        font: 40px monospace;
+      }
+    </style>
+  </defs>
+
+  <text transform="translate(0, 40)">a <textPath href="#path">b </textPath> c</text>
+</svg>
--- a/layout/svg/SVGTextFrame.cpp
+++ b/layout/svg/SVGTextFrame.cpp
@@ -4655,19 +4655,20 @@ void SVGTextFrame::DoTextPathLayout() {
         continue;
       }
       if (it.IsClusterAndLigatureGroupStart()) {
         break;
       }
       it.Next();
     }
 
+    bool skippedEndOfTextPath = false;
+
     // Loop for each character in the text path.
-    while (!it.AtEnd() && it.TextPathFrame() &&
-           it.TextPathFrame()->GetContent() == textPath) {
+    while (!it.AtEnd() && it.TextPathFrame()) {
       // The index of the cluster or ligature group's first character.
       uint32_t i = it.TextElementCharIndex();
 
       // The index of the next character of the cluster or ligature.
       // We track this as we loop over the characters below so that we
       // can detect undisplayed characters and append entries into
       // partialAdvances for them.
       uint32_t j = i + 1;
@@ -4690,24 +4691,31 @@ void SVGTextFrame::DoTextPathLayout() {
           partialAdvances.AppendElement(partialAdvance);
           ++j;
         }
         // This loop may end up outside of the current text path, but
         // that's OK; we'll consider any complete cluster or ligature
         // group that begins inside the text path as being affected
         // by it.
         if (it.IsOriginalCharSkipped()) {
+          if (!it.TextPathFrame()) {
+            skippedEndOfTextPath = true;
+            break;
+          }
           // Leave partialAdvance unchanged.
         } else if (it.IsClusterAndLigatureGroupStart()) {
           break;
         } else {
           partialAdvance += it.GetAdvance(context);
         }
         partialAdvances.AppendElement(partialAdvance);
       }
+      if (skippedEndOfTextPath) {
+        break;
+      }
 
       // Any final undisplayed characters the CharIterator skipped over.
       MOZ_ASSERT(j <= it.TextElementCharIndex());
       while (j < it.TextElementCharIndex()) {
         partialAdvances.AppendElement(partialAdvance);
         ++j;
       }