I read the source code of TextPosition.insertDiacritic(int i, TextPosition diacritic, TextNormalize normalize). I don't understand why width2[i+1] is set to 0. This will lead to an error where after I insert a character, the corresponding width is 0. If I do another insert, this yields an error. I replace that line to:
width2[i+1] = diacritic.getWidth();
Please let me know if you mean to set it to zero and if I misunderstand your implementation.