protectwise / troika

A JavaScript framework for interactive 3D and 2D visualizations

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

HawtinZeng opened this issue · 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

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

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

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?

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.

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😂😂