Skip to content

[0.81] fix: Unicode Text length Calculation#16185

Merged
vineethkuttan merged 2 commits into
0.81-stablefrom
81
May 26, 2026
Merged

[0.81] fix: Unicode Text length Calculation#16185
vineethkuttan merged 2 commits into
0.81-stablefrom
81

Conversation

@vineethkuttan
Copy link
Copy Markdown
Contributor

@vineethkuttan vineethkuttan commented May 26, 2026

Description

The length of text that is being rendered is not calculated for Unicode characters, this change will fix it

Type of Change

  • Bug fix (non-breaking change which fixes an issue)

Why

Text Highlight for Unicode is not working

Screenshots

image

Testing

Tested in Playground

Changelog

Should this change be included in the release notes: yes

(fix: Unicode Text length Calculation)

Microsoft Reviewers: Open in CodeFlow

Copy link
Copy Markdown
Contributor

@sundaramramaswamy sundaramramaswamy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good — correctly fixes the UTF-8 vs UTF-16 length mismatch for DirectWrite text ranges. One suggestion for a follow-up optimization:

Minor optimization: Each Utf8ToUtf16(fragment.string).length() allocates a temporary std::wstring just to get the length. Would it be worth adding a Utf8ToUtf16Length() helper to vnext/Common/unicode.h that calls MultiByteToWideChar with a null output buffer? That would avoid the allocation entirely — could matter in hot paths like RenderText and hit-testing loops.

Not blocking — the fix is correct as-is.

@vineethkuttan
Copy link
Copy Markdown
Contributor Author

vineethkuttan commented May 26, 2026

Looks good — correctly fixes the UTF-8 vs UTF-16 length mismatch for DirectWrite text ranges. One suggestion for a follow-up optimization:

Minor optimization: Each Utf8ToUtf16(fragment.string).length() allocates a temporary std::wstring just to get the length. Would it be worth adding a Utf8ToUtf16Length() helper to vnext/Common/unicode.h that calls MultiByteToWideChar with a null output buffer? That would avoid the allocation entirely — could matter in hot paths like RenderText and hit-testing loops.

Not blocking — the fix is correct as-is.

Will add this while forward porting to main and other stable versions. And for 0.81 will raise the separate PR for this.

@vineethkuttan vineethkuttan enabled auto-merge (squash) May 26, 2026 16:04
@vineethkuttan vineethkuttan merged commit e5ce268 into 0.81-stable May 26, 2026
60 checks passed
@vineethkuttan vineethkuttan deleted the 81 branch May 26, 2026 16:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Nested Text components apply styles at wrong offsets when text contains multi-byte characters

2 participants