Fix bug of text stylizing which contains surrogate-paired chars.

improve code quality.