[TextKit]Why some special characters could make Chinese characters thinner and smaller

177 Views Asked by At

That happens on TextKit. But everything is all right when I use CoreText.

RichText with TextKit

The rich text in the debug window of Xcode also has the same issue.

enter image description here

So, is it a bug of TextKit? Is there any solution in addition to replace TextKit by CoreText?

1

There are 1 best solutions below

0
On BEST ANSWER

I tried it and the difference really exists between CoreText and TextKit. I guess it caused by the font fallback functions.

For example, we have a string "啦☜啦", and set a font. In case the given font don't have all characters, there usually a list of fallback fonts like:

English font
CJK font
Emoji font
Unicode font (support almost all the unicode character)

There are two ways to find a fallback font.

  1. Find from beginning
    • Find '啦' in given font.
    • Not found, find in fallback fonts in order, found in CJK font.
    • Find '☜' in given font.
    • Not found, find in fallback fonts in order, found in Unicode font.
    • Find '啦' in given font.
    • Not found, find in fallback fonts in order, found in CJK font.
  2. Find from previous
    • Find '啦' in given font.
    • Not found, find in fallback fonts in order, found in CJK font.
    • Find '☜' in CJK font.
    • Not found, find in fallback fonts in order, found in Unicode font.
    • Find '啦' in Unicode font
    • Found.

So if TextKit use the second way, two '啦's may use different fonts because of the character '☜'.

To solve this, you can use attributed string and give '☜' a different font size to break the fallback loop, then the second '啦' use CJK font.