Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Width of seperate letters in compound words of arabic content

I have arabic content which is compound of words like ضضضضضضض. I want to get the width of the first letter of a given word ( which is not the same as the width of an independent letter i.e. ض ).

I used getBoundingClientRect() method and tried to get the width , but it is giving the width of an independent character , not the compound one which's thiner than the returned value by getBoundingClientRect method

In the above word , the width of ض (first letter) given by getBoundingClientRect() is 16.109375 , but the character is compound one i.e. visibily it is truncated as you see. It is less than the given value.

I tried and got the EXACT(visible) width of first letter by subtracting width given getBoundingClientRect() by of first two characters and width of first character which would be 12px which is correct.

Is there any better method than this so that I can get exact visible width of every character like this in any word?

like image 573
psp psph Avatar asked Dec 21 '16 17:12

psp psph


1 Answers

You should know that the unicode of what you see is not the unicode stored. All letters in your example ضضضضضضض are stored as a standard Dhad ض \u0636 but shown as:

  1. ﺿ \ufebf (start)
  2. \ufec0 (middle)
  3. \ufebe (end)
  4. \ufebd (independent)

So to get the real length, you should apply your length function on those representation unicodes.

like image 113
Assem Avatar answered Oct 05 '22 22:10

Assem