我在我们的应用程序中使用自定义字体系列“阿列尔错字”用功能支持多国语言文字编辑(UITextView的)和使用 -文本字体回退与自定义字体应用于NSAttributedString
“AllerTypo淡味”纯文本(无型面)
“AllerTypo正规”的大胆。
“AllerTypo-LightItalic” 为斜体。
“AllerTypo斜体” 为粗斜体。
问题是当我申请在此字体系列不支持文本(字形)的字体,它大概是回退到字体(如“黑体”家族俄文本)重新应用客户端字型特征,但不知道我使用“AllerTypo-Regular”版本的事实,因为它的大胆 -ness。请帮我解决这个问题。
请参见下面的代码片段是我上面讲的。
// Apply current theme on default attributes (like font, text color)
NSMutableAttributedString *updatedAttribText = [attribText mutableCopy];
[updatedAttribText beginEditing];
[attribText enumerateAttributesInRange:NSMakeRange(0, attribText.length)
options:0
usingBlock:^(NSDictionary *attrs, NSRange range, BOOL *stop) {
// Check for font attributes
UIFont *textRunfont = [attrs objectForKey:NSFontAttributeName];
NSMutableDictionary *updatedAttribs = [attrs mutableCopy];
[updatedAttribs updateAttributesWithTextStyle:textRunfont.fontDescriptor.symbolicTraits action:YES fontFamily:@"Aller Typo"];
// Check for default text color now
UIColor *textRunColor = [attrs objectForKey:NSForegroundColorAttributeName];
if ([textRunColor isEqual:[UIColor colorWithRed:0 green:0 blue:0 alpha:1.0]]) {
UIColor *defaultTextColor = [[QGThemeHelper currentTheme] uiTextViewTextColor];
[updatedAttribs setValue:defaultTextColor forKey:NSForegroundColorAttributeName];
}
[updatedAttribText setAttributes:updatedAttribs range:range];
}];
[updatedAttribText endEditing];
上面使用的NSMutableDictionary类别方法来更新文本属性。
- (void)updateAttributesWithTextStyle:(UIFontDescriptorSymbolicTraits)updateStyleTraits action:(BOOL)addAction fontFamily:(NSString *)familyName
{
UIFont *currentFont = [self objectForKey:NSFontAttributeName];
UIFontDescriptorSymbolicTraits updatedTraits = 0;
// Fetch existing traits and then apply the text style
if (!addAction) { // Remove
updatedTraits = ([currentFont qg_textStyleTraits] & ~updateStyleTraits);
}
else { // Apply
updatedTraits = ([currentFont qg_textStyleTraits] | updateStyleTraits);
}
// Appropriate font from the family with mentioned traits (bold, italic, bold italic).
NSString *updatedFontName = [UIFont qg_fontNameFromFamily:familyName withTextStyleTraits:updatedTraits];
UIFont *updatedFont = [UIFont fontWithName:updatedFontName size:currentFont.pointSize];
[self setObject:updatedFont forKey:NSFontAttributeName];
}
换句话说,有什么办法可以与fallback系统沟通我的意图(字体定制)吗?斜体功能正常工作,因为“AllerTypo-Italic”字体带有该特性,系统在故障预置期间重新应用该特性。
补充说明 - 文本内容源(属性文本)进行编码存储在CoreData HTML标签被同步回我们的web应用程序也是如此。