Read passed any empty runs when iterating glyphs. Discussion here: https://2dimensions.slack.com/archives/CLLCU09T6/p1694476323513999 Fixes https://github.com/rive-app/rive/issues/5973 Diffs= 85b2b6ed1 Read passed any empty runs when iterating glyphs. (#5974) Co-authored-by: Luigi Rosso <luigi-rosso@users.noreply.github.com>
diff --git a/.rive_head b/.rive_head index 69fa08c..b5177a6 100644 --- a/.rive_head +++ b/.rive_head
@@ -1 +1 @@ -b9382846d3152fd87ee8ffc8e7a86ea2b5933a9b +85b2b6ed1965d66f5f268993e54f5f89f30a2e29
diff --git a/include/rive/text/text.hpp b/include/rive/text/text.hpp index 95f4278..91c6419 100644 --- a/include/rive/text/text.hpp +++ b/include/rive/text/text.hpp
@@ -72,6 +72,8 @@ m_line(line), m_run(run), m_glyphIndex(glyphIndex) {} + void tryAdvanceRun(); + bool operator!=(const GlyphItr& that) const { return m_run != that.m_run || m_glyphIndex != that.m_glyphIndex; @@ -116,7 +118,9 @@ GlyphItr begin() const { auto runItr = m_runs.data(); - return GlyphItr(this, runItr, startGlyphIndex(*runItr)); + auto itr = GlyphItr(this, runItr, startGlyphIndex(*runItr)); + itr.tryAdvanceRun(); + return itr; } GlyphItr end() const
diff --git a/src/text/text.cpp b/src/text/text.cpp index 089a865..14bb666 100644 --- a/src/text/text.cpp +++ b/src/text/text.cpp
@@ -11,17 +11,27 @@ #include "rive/artboard.hpp" #include "rive/factory.hpp" +void GlyphItr::tryAdvanceRun() +{ + while (true) + { + auto run = *m_run; + if (m_glyphIndex == m_line->endGlyphIndex(run) && run != m_line->lastRun()) + { + m_run++; + m_glyphIndex = m_line->startGlyphIndex(*m_run); + } + else + { + break; + } + } +} GlyphItr& GlyphItr::operator++() { auto run = *m_run; m_glyphIndex += run->dir == TextDirection::ltr ? 1 : -1; - - // Did we reach the end of the run? - if (m_glyphIndex == m_line->endGlyphIndex(run) && run != m_line->lastRun()) - { - m_run++; - m_glyphIndex = m_line->startGlyphIndex(*m_run); - } + tryAdvanceRun(); return *this; } @@ -380,6 +390,7 @@ isEllipsisLineLast, &m_ellipsisRun)); } + const OrderedLine& orderedLine = m_orderedLines[lineIndex]; float x = -m_bounds.width() * originX() + line.startX; float renderY = y + line.baseline;
diff --git a/test/assets/double_line.riv b/test/assets/double_line.riv new file mode 100644 index 0000000..ab6bc19 --- /dev/null +++ b/test/assets/double_line.riv Binary files differ
diff --git a/test/text_test.cpp b/test/text_test.cpp index 6e7298a..701fcb2 100644 --- a/test/text_test.cpp +++ b/test/text_test.cpp
@@ -247,3 +247,23 @@ } } } + +TEST_CASE("double new line type works", "[text]") +{ + auto file = ReadRiveFile("../../test/assets/double_line.riv"); + auto artboard = file->artboard(); + + auto textObjects = artboard->find<rive::Text>(); + REQUIRE(textObjects.size() == 1); + + auto styleObjects = artboard->find<rive::TextStyle>(); + REQUIRE(styleObjects.size() == 1); + + auto runObjects = artboard->find<rive::TextValueRun>(); + REQUIRE(runObjects.size() == 9); + + artboard->advance(0.0f); + auto text = textObjects[0]; + auto lines = text->orderedLines(); + REQUIRE(lines.size() == 3); +}