troika icon indicating copy to clipboard operation
troika copied to clipboard

Util function getCaretAtPoint can't get the uniform text caret vertical position for number/character and Chinese text.

Open HawtinZeng opened this issue 2 years ago • 5 comments

https://stackblitz.com/edit/vitejs-vite-xq3mug?file=package.json,src%2Fmain.js, click this link, and click the text in the scene, you will find get different vertical position for number/character and Chinese text. The compareing screentshot as below: number or character: image Chinese text: image

HawtinZeng avatar Dec 24 '23 06:12 HawtinZeng

when i test selection in troika examples, there is differenct height between number/charcter and Chinese text, can u give me some suggestions to solve this problem, I wanna take part in your project. image

HawtinZeng avatar Dec 24 '23 07:12 HawtinZeng

Currently i don't use the y value returned by getCaretAtPoint, instead , I align the origin of a plane mesh to the origin of Text, solve this problem, but it seems not perfect. image

HawtinZeng avatar Dec 24 '23 07:12 HawtinZeng

Hi, @lojjic , I have complated a demo for in-place text editing, link, I wanna to contribute it to your repo, how do u think? And where I should put this text editing example in?

HawtinZeng avatar Jan 01 '24 10:01 HawtinZeng

Thanks for the report!

The caretTop and caretHeight are calculated here -- the difference is due to the Latin and Chinese font files containing different ascender/descender metrics. I'm open to changing how those values are chosen, if you know of a good reliable method that would make them match.

As for your example, I think keeping it external is best, it can stay on Stackblitz and maybe we can add a link to it in the documentation.

lojjic avatar Jan 02 '24 18:01 lojjic

I will append the demo link into the doc soon, and by the way, do u know how to calculate the font length before text.sync, i want to draw some lines and dots based on text length before drawing troika text😂😂

HawtinZeng avatar Jan 03 '24 04:01 HawtinZeng