Skip to content

Text rendering with word wrap and RTL often clips #664

@oisact

Description

@oisact
  • A bug in the API:
    • Phaser version(s): 2.12.0, 2.15.0
    • What steps produce the bug: Use RTL text, such as Arabic, with word wrap, so the text wraps.
    • What should happen: All letters should render properly.
    • What happens instead: One more more letters of the widest line(s) will be truncated on the right.

When the word wrapping routine splits text into words by spaces, each line's string (except possibly the last line) has a trailing space. Each line is then measured, and the width of a space is removed from the line length to account for that trailing space (necessary for accurate Center or Right alignment). For LTR languages, the trailing space for the widest line(s) are actually clipped off by the right side of the context's rectangle because of this. Since spaces are not visible, this is not an issue.

For a RTL language the trailing space is actually drawn on the left. Since text rendering is positioned by the left edge, the subtraction of the width of a space from the width of the line may result in the right side of the text clipped by the width of the space.

Fix: Instead of measuring lines of word wrapped split text with trailing space included, then subtracting the width of a space, simply trim the trailing space of each word wrapped line from the string.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions