Skip to content

Commit

Permalink
Read passed any empty runs when iterating glyphs.
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
luigi-rosso and luigi-rosso committed Sep 12, 2023
1 parent d76d2a8 commit 64515c6
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .rive_head
Original file line number Diff line number Diff line change
@@ -1 +1 @@
b9382846d3152fd87ee8ffc8e7a86ea2b5933a9b
85b2b6ed1965d66f5f268993e54f5f89f30a2e29
6 changes: 5 additions & 1 deletion include/rive/text/text.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
25 changes: 18 additions & 7 deletions src/text/text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down
Binary file added test/assets/double_line.riv
Binary file not shown.
20 changes: 20 additions & 0 deletions test/text_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<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);
}

0 comments on commit 64515c6

Please sign in to comment.