-1

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?

Swain
  • 21
  • 5
  • Some special unicode characters will cause the problem, such as ♬, ☜ – Swain Aug 28 '17 at 04:06
  • I don't see a single special character in the picture you post. – El Tomato Aug 28 '17 at 04:07
  • @ElTomato ☜ is the special character in the case. The characters "啦啦啦啦" before ☜ are rendered correctly, but the characters after ☜ are rendered abnormally. – Swain Aug 28 '17 at 08:06
  • ☜ is not a special character. It's a UNICODE symbol. Most likely, the font family you have selected does cover it. Anyway, your topic has little to do with programming. – El Tomato Aug 28 '17 at 08:32
  • Why the Chinese characters after ☜ are rendered thinner, but the same Chinese characters before ☜ are rendered correctly? @ElTomato – Swain Aug 29 '17 at 07:30

1 Answers1

0

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.

Geansea
  • 26
  • 2