objcio / attributed-string-builder

Attributed String Builders
108 stars 8 forks source link

Allow font creation to fail and fallback to a safe font #5

Closed onevcat closed 1 year ago

onevcat commented 1 year ago

For some languages (such as CJK), there is no "italic" version of the font. For these fonts, if the traits contains .italic, NSFont.init(descriptor:size:) will fail to create the font and return nil.

I understand that it can be an "author error" to use a font without italic version, but use *some word* to make text italic. But I guess a hard crash for this error is too strict. Unless modifying every italic case in the original text, I won't be able to use a new font, which is not ideal and painful.

onevcat commented 1 year ago

截屏2023-07-05 0 04 18

chriseidhof commented 1 year ago

This makes sense, thank you!