The bounding boxes of chars are calculated based on <use> elements and enlarged according to their bbox and flow direction automatically. The selection fallback is calculated by:
for (const use of elem.children) {
const useRect = use.getBoundingClientRect();
const selRect = isHorizontalFlow() ? {
left: useRect.left,
right: useRect.right,
top: textRect.top,
bottom: textRect.bottom,
} : {
left: textRect.left,
right: textRect.right,
top: useRect.top,
bottom: useRect.bottom,
};
previousSelRect = unionRect(selRect, previousSelRect);
// set index to end range of this char
useIndex++;
if (inRect(selRect, mouseX, mouseY)) {
foundIndex = useIndex;
} else if (previousSelRect) { // may fallback to space in between chars
if (inRect(previousSelRect, mouseX, mouseY)) {
foundIndex = useIndex - 1;
previousSelRect = selRect;
}
}
}
Corresponds to https://github.com/Myriad-Dreamin/typst.ts/pull/468
The bounding boxes of chars are calculated based on
<use>
elements and enlarged according to their bbox and flow direction automatically. The selection fallback is calculated by:== Demo