diff --git a/.rive_head b/.rive_head index 69fa08ca..b5177a62 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 95f42783..91c64193 100644 --- a/include/rive/text/text.hpp +++ b/include/rive/text/text.hpp @@ -72,6 +72,8 @@ class GlyphItr 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 @@ class OrderedLine 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 089a8658..14bb666a 100644 --- a/src/text/text.cpp +++ b/src/text/text.cpp @@ -11,17 +11,27 @@ using namespace rive; #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 @@ void Text::buildRenderStyles() 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 00000000..ab6bc191 Binary files /dev/null and b/test/assets/double_line.riv differ diff --git a/test/text_test.cpp b/test/text_test.cpp index 6e7298a3..701fcb2a 100644 --- a/test/text_test.cpp +++ b/test/text_test.cpp @@ -247,3 +247,23 @@ TEST_CASE("run modifier ranges select runs", "[text]") } } } + +TEST_CASE("double new line type works", "[text]") +{ + auto file = ReadRiveFile("../../test/assets/double_line.riv"); + auto artboard = file->artboard(); + + auto textObjects = artboard->find(); + REQUIRE(textObjects.size() == 1); + + auto styleObjects = artboard->find(); + REQUIRE(styleObjects.size() == 1); + + auto runObjects = artboard->find(); + REQUIRE(runObjects.size() == 9); + + artboard->advance(0.0f); + auto text = textObjects[0]; + auto lines = text->orderedLines(); + REQUIRE(lines.size() == 3); +}