buildDisplayedText

Reconstructs the text actually drawn by layout, line by line: on each line the platform ellipsis run (getEllipsisStart/getEllipsisCount) is replaced with the ellipsis glyph, exactly the substitution the platform makes when drawing the line. Lines with no ellipsis are copied verbatim, so a custom ellipsis baked into the text is preserved — and a custom ellipsis the framework re-ellipsized is shown cut, as actually rendered.


Line-walking core, split out so tests can drive a mocked Layout with the text supplied out-of-band: Robolectric's real StaticLayout never populates ellipsis metadata, and Layout.getText is final so a mock cannot return it. Production always passes layout.text via the single-argument overload above. The clamp is a backstop only for AOSP StaticLayout defects (notably Android 15/16) that return line offsets outside their own text — it degrades the reconstruction rather than throwing IndexOutOfBoundsException.