Skip to content

Conversation

ppaszkiewiczcom
Copy link

What does the pull request do?

TextLeadingPrefixCharacterEllipsis can now correctly handle multiple TextRuns.

This is a followup for #17998
And fix for #19339

What is the current behavior?

Current implementation of TextLeadingPrefixCharacterEllipsis only works when TextLine has a single ShapedTextRun.

When there's more (there are emojis or special characters) it breaks by crashing (in debug mode) or incorrectly accumulates availableWidth which ends up excessively trimming the text (in some cases only leaving the ellipsis).

This affects TextTrimming="LeadingCharacterEllipsis" and TextTrimming="PrefixCharacterEllipsis":

image image

What is the updated/expected behavior with this PR?

TextLeadingPrefixCharacterEllipsis should now correctly measure the text and prepare the prefix:

image image

How was the solution implemented (if it's not obvious)?

Update TextLeadingPrefixCharacterEllipsis.Collapse logic.

Checklist

  • Added unit tests (if possible)?

Known issue:

PrefixCharacterEllipsis has inconsistent results with RTL text (ie. hebrew characters)

  • TextFormatterImpl.SplitTextRuns return value might not be correct
  • bidi level of default ellipsis () is lower than rest of text which can cause unexpected reordering of prefix

Fixed issues

Fixes #19339

@avaloniaui-bot
Copy link

You can test this PR using the following package version. 12.0.999-cibuild0058024-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@cla-avalonia
Copy link
Collaborator

cla-avalonia commented Aug 4, 2025

  • All contributors have signed the CLA.

@ppaszkiewiczcom
Copy link
Author

@cla-avalonia agree

@MrJul MrJul requested a review from Gillibald August 5, 2025 14:37
@MrJul MrJul added the backport-candidate-11.3.x Consider this PR for backporting to 11.3 branch label Aug 5, 2025
@Gillibald
Copy link
Contributor

We should probably inherit the bidi level from the split run, so nothing changes.

Could you clarify when TextFormatterImpl.SplitTextRuns produces wrong results?

@avaloniaui-bot
Copy link

You can test this PR using the following package version. 12.0.999-cibuild0058621-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@ppaszkiewiczcom
Copy link
Author

ppaszkiewiczcom commented Sep 4, 2025

There might be an issue when provided text runs have mixed bidi-levels. But I'm not 100% certain because I don't entirely comprehend how mixed bidi-level text is supposed to come out.

Also tried with forced RTL ellipsis (TextFormatter.CreateSymbol(Symbol, FlowDirection.RightToLeft)) but the result gets even more confusing to me

image

@Gillibald
Copy link
Contributor

I think the text trimming implementation needs to be rewritten so it uses the hit testing APIs to find the actual split positions.

We need to find the run that is at the split position and remove glyphs from it until the line fits into the requested width. This is a single position for trailing or leading ellipses and two positions for trimming with a defined prefix/suffix.

In the end, the algorithm should not change the bidi order, etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-textprocessing backport-candidate-11.3.x Consider this PR for backporting to 11.3 branch bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Issue with TextTrimming="PrefixCharacterEllipsis" when using emoji / Japane characters

5 participants