String width via fontmetrics calculation is very slow if there are arabic or persian letters in text

后端 未结 4 1369
一向
一向 2021-01-04 03:50

I have a problem. My application interface works much slower if i use eastern languages there. Especially i felt it in components such as JList, JCombobox, JTable.

4条回答
  •  礼貌的吻别
    2021-01-04 04:26

    I performed some tests with other languages using your code. First you are right: calculations of Persian string took a lot of time.

    I played with font type and size and did not see significant differences. But the result definitely depend on the script you are using. Here are the results I got on my machine.

    Calculation time for Persian: 2877 ms
    Calculation time for English: 8 ms
    Calculation time for Russian: 47 ms
    Calculation time for Hebrew:  16815 ms
    

    As you can see Russian is 6 times slower than English. I believe that it is because the internal representation of strings is unicode. In UTF-8 English characters occupy one byte, all others 2 bytes.

    I am not sure it can satisfy you :) but Hebrew test is 4 times slower than Persian. Both are slow, so I guess that right-to-left calculations kill it.

    It seems that we have nothing to do with this.

提交回复
热议问题