fix: Text opacity modifier falloff with feathering applied (#13089) 476a0f6f85 xes #13081. When a text has an opacity modifier with falloff, glyphs are bucketed by opacity and the non-opaque buckets are drawn with a pool of RenderPaints that is shared across all of the style's fills/strokes. A fill with a feather stamped its strength onto those pooled paints and nothing ever reset it, so: a second, non-feathered fill drew its falloff glyphs feathered (blurred to near-invisible, reading as "cut" instead of fading), and the feather persisted on falloff glyphs even after the feathered fill was deleted. Fix Always assign feather on the pooled paint — the feather's strength when present, 0 otherwise. Co-authored-by: Philip Chung <philterdesign@gmail.com>
diff --git a/.rive_head b/.rive_head index 878174b..07ac448 100644 --- a/.rive_head +++ b/.rive_head
@@ -1 +1 @@ -9bcb8fe4a7b02df429f8789f3029c6a0845c0ffb +476a0f6f85fff4bd0126576b9d7f4ca9404f4a15
diff --git a/include/rive/text/text_style_paint.hpp b/include/rive/text/text_style_paint.hpp index 9b33053..d64aec3 100644 --- a/include/rive/text/text_style_paint.hpp +++ b/include/rive/text/text_style_paint.hpp
@@ -3,7 +3,7 @@ #include "rive/generated/text/text_style_paint_base.hpp" #include "rive/shapes/shape_paint_container.hpp" #include "rive/shapes/shape_paint_path.hpp" -#include <unordered_map> +#include <map> namespace rive { @@ -28,7 +28,7 @@ private: Artboard* getArtboard() override { return artboard(); } - std::unordered_map<float, ShapePaintPath> m_opacityPaths; + std::map<float, ShapePaintPath> m_opacityPaths; std::vector<rcp<RenderPaint>> m_paintPool; ShapePaintPath m_path; bool m_hasContents = false;
diff --git a/src/text/text_style_paint.cpp b/src/text/text_style_paint.cpp index 877488d..0a828e4 100644 --- a/src/text/text_style_paint.cpp +++ b/src/text/text_style_paint.cpp
@@ -86,10 +86,11 @@ } RenderPaint* renderPaint = m_paintPool[paintIndex++].get(); shapePaint->applyTo(renderPaint, itr->first); - if (auto feather = shapePaint->feather()) - { - renderPaint->feather(feather->strength()); - } + // Pooled paints are shared across shape paints; always set feather + // so one paint's feather doesn't leak into the others. + auto feather = shapePaint->feather(); + renderPaint->feather(feather != nullptr ? feather->strength() + : 0.0f); ShapePaintPath& path = itr->second; shapePaint->draw(renderer, &path,
diff --git a/tests/unit_tests/assets/text_feather_falloff.riv b/tests/unit_tests/assets/text_feather_falloff.riv new file mode 100644 index 0000000..7306430 --- /dev/null +++ b/tests/unit_tests/assets/text_feather_falloff.riv Binary files differ
diff --git a/tests/unit_tests/runtime/text_modifier_test.cpp b/tests/unit_tests/runtime/text_modifier_test.cpp index 19ddb8f..f963e6f 100644 --- a/tests/unit_tests/runtime/text_modifier_test.cpp +++ b/tests/unit_tests/runtime/text_modifier_test.cpp
@@ -1,11 +1,15 @@ #include "rive/text/text.hpp" #include "rive/text/text_style.hpp" +#include "rive/text/text_style_paint.hpp" #include "rive/text/text_value_run.hpp" #include "rive/text/text_modifier_group.hpp" #include "rive/text/text_modifier_range.hpp" +#include "rive/shapes/paint/shape_paint.hpp" +#include "rive/animation/linear_animation_instance.hpp" #include "rive_file_reader.hpp" #include "rive_testing.hpp" #include <utils/no_op_renderer.hpp> +#include <utils/serializing_factory.hpp> TEST_CASE("text modifiers load correctly", "[text]") { @@ -25,3 +29,72 @@ auto range = modifierGroup->ranges()[0]; REQUIRE(range->interpolator() != nullptr); } + +TEST_CASE("text opacity falloff with feathered and plain fills", "[silver]") +{ + rive::SerializingFactory silver; + auto file = ReadRiveFile("assets/text_feather_falloff.riv", &silver); + + auto artboard = file->artboardDefault(); + REQUIRE(artboard != nullptr); + + // Validate the asset still exercises the repro: at least one text driven + // by a modifier range, and at least one style with two fills of which + // exactly one is feathered. + auto textObjects = artboard->find<rive::Text>(); + REQUIRE(textObjects.size() == 3); + int textsWithModifiers = 0; + for (auto text : textObjects) + { + if (!text->modifierGroups().empty() && + !text->modifierGroups()[0]->ranges().empty()) + { + textsWithModifiers++; + } + } + REQUIRE(textsWithModifiers == 2); + + auto styles = artboard->find<rive::TextStylePaint>(); + int reproStyles = 0; + for (auto style : styles) + { + auto& shapePaints = style->shapePaints(); + if (shapePaints.size() != 2) + { + continue; + } + int featheredCount = 0; + for (auto shapePaint : shapePaints) + { + if (shapePaint->feather() != nullptr) + { + featheredCount++; + } + } + if (featheredCount == 1) + { + reproStyles++; + } + } + REQUIRE(reproStyles >= 1); + + silver.frameSize(artboard->width(), artboard->height()); + + REQUIRE(artboard->animationCount() > 0); + auto animation = artboard->animationAt(0); + animation->advanceAndApply(0.0f); + auto renderer = silver.makeRenderer(); + artboard->draw(renderer.get()); + + // Draw every frame of the animation. + uint32_t frames = animation->duration(); + float frameDuration = 1.0f / animation->fps(); + for (uint32_t i = 0; i < frames; i++) + { + silver.addFrame(); + animation->advanceAndApply(frameDuration); + artboard->draw(renderer.get()); + } + + CHECK(silver.matches("text_feather_falloff")); +}
diff --git a/tests/unit_tests/silvers/text_feather_falloff.sriv b/tests/unit_tests/silvers/text_feather_falloff.sriv new file mode 100644 index 0000000..2c5f333 --- /dev/null +++ b/tests/unit_tests/silvers/text_feather_falloff.sriv Binary files differ