void TextField::layoutText() {
buildParagraph();
// layout
paragraph_->layout(rect_.width());
paragraph_->ensureUTF16Mapping();
// create mapping
textToDisplaySequence_.clear();
auto paraUnicode = paragraph_->getUnicode();
for (size_t i = 0; i < text_.size(); i++) {
auto isGraphemeStart = paragraph_->codeUnitHasProperty(
i, SkUnicode::CodeUnitFlags::kGraphemeStart
);
if (isGraphemeStart) {
auto lineNumber = static_cast<size_t>(paragraph_->getLineNumberAt(i));
// find the utf16 end index
size_t utf8End = i;
bool isNextGraphemeStart = false;
do {
utf8End++;
isNextGraphemeStart = paragraph_->codeUnitHasProperty(
utf8End, SkUnicode::CodeUnitFlags::kGraphemeStart
);
} while (utf8End < text_.size() && !isNextGraphemeStart);
auto mapping = TextToDisplayIndex{
.textIndex = i,
.utf16Start = paragraph_->getUTF16Index(i),
.utf16End = paragraph_->getUTF16Index(utf8End),
.lineNumber = lineNumber,
};
getLogger()->trace(
"U16 index: {}, Line: {}", mapping.utf16Start, mapping.lineNumber
);
textToDisplaySequence_.push_back(mapping);
}
}
}