Suppose I have a <span>
tag with some text inside. Span node can also have child nodes(strong, em) tags. I can easily break the span into the wrapped lines by using getClientRects()
. The problem with that however is that I won't be able to track the number of characters in each line (I need to)
I tried putting each word inside of the <n>
tag and comparing .top values of each line and word to calculate the total character count in one line. The solution stopped working once there were other nodes inside the main span. Since putting words into <n>
removed the context of other child. The solution of getting all the child nodes and modifying them seems very ineffective.
Looking forward for any ideas.
Example span:
<span style="font-size:22pt;line-height:1;">
<strong>
Qui
<em>
<u>
<s>
squ
</s>
</u>
</em>
e ac justo pulvinar, efficitur odio nec, convallis ligula. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia curae; Vestibulum ex tortor, pretium ac sapien sed, condimentum fringilla elit. Fusce aliquam ullamcorper magna eget dignissim. In porttitor nec magna non auctor. Nullam feugiat ultrices molestie.
</strong>
</span>
I want to get a number of chars in x, y, and z (See the image below)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…