Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "fix Unicode length Calculation in Text Component",
"packageName": "react-native-windows",
"email": "66076509+vineethkuttan@users.noreply.github.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,13 @@ facebook::react::SharedViewEventEmitter ParagraphComponentView::eventEmitterAtPo
uint32_t textPosition = metrics.textPosition;

for (auto fragment : m_attributedStringBox.getValue().getFragments()) {
if (textPosition < fragment.string.length()) {
uint32_t utf16Length =
static_cast<uint32_t>(::Microsoft::Common::Unicode::Utf8ToUtf16(fragment.string).length());
if (textPosition < utf16Length) {
return std::static_pointer_cast<const facebook::react::ViewEventEmitter>(
fragment.parentShadowView.eventEmitter);
}
textPosition -= static_cast<uint32_t>(fragment.string.length());
textPosition -= utf16Length;
}
}
}
Expand Down Expand Up @@ -206,10 +208,12 @@ bool ParagraphComponentView::IsTextSelectableAtPoint(facebook::react::Point pt)

// Finds which fragment contains this text position
for (auto fragment : m_attributedStringBox.getValue().getFragments()) {
if (textPosition < fragment.string.length()) {
uint32_t utf16Length =
static_cast<uint32_t>(::Microsoft::Common::Unicode::Utf8ToUtf16(fragment.string).length());
if (textPosition < utf16Length) {
return true;
}
textPosition -= static_cast<uint32_t>(fragment.string.length());
textPosition -= utf16Length;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void RenderText(
unsigned int position = 0;
unsigned int length = 0;
for (auto fragment : attributedString.getFragments()) {
length = static_cast<UINT32>(fragment.string.length());
length = static_cast<UINT32>(::Microsoft::Common::Unicode::Utf8ToUtf16(fragment.string).length());
DWRITE_TEXT_RANGE range = {position, length};
if (fragment.textAttributes.foregroundColor &&
(fragment.textAttributes.foregroundColor != textAttributes.foregroundColor) ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ void WindowsTextLayoutManager::GetTextLayout(
attachments.push_back(attachment);
position += 1;
} else {
unsigned int length = static_cast<UINT32>(fragment.string.length());
unsigned int length = static_cast<UINT32>(Microsoft::Common::Unicode::Utf8ToUtf16(fragment.string).length());
DWRITE_TEXT_RANGE range = {position, length};
TextAttributes attributes = fragment.textAttributes;
DWRITE_FONT_STYLE fragmentStyle = DWRITE_FONT_STYLE_NORMAL;
Expand Down
Loading