66static const CGFloat kObliquenessFallback = 0.2 ;
77
88typedef NS_ENUM (NSInteger , ItalicKind) {
9- // whitespace and other invisible characters - takes over the kind of its
10- // neighbours
11- ItalicKindNeutral,
12- // character must not be slanted at all (text attachments)
9+ // character must not be slanted at all (whitespace, control characters,
10+ // text attachments)
1311 ItalicKindNone,
1412 // font has a real italic glyph for the character
1513 ItalicKindFont,
@@ -97,8 +95,6 @@ + (void)applyItalicForFont:(UIFont *)font
9795 hasItalicFace: hasItalicFace])];
9896 }];
9997
100- [self resolveNeutralKinds: clusterKinds];
101-
10298 // merge neighbouring clusters of the same kind and apply the style
10399 NSUInteger index = 0 ;
104100 while (index < clusterKinds.count ) {
@@ -129,7 +125,7 @@ + (ItalicKind)kindForCluster:(NSString *)cluster
129125 hasItalicFace : (BOOL )hasItalicFace {
130126 if ([cluster rangeOfCharacterFromSet: [NeutralCharacters () invertedSet ]]
131127 .location == NSNotFound ) {
132- return ItalicKindNeutral ;
128+ return ItalicKindNone ;
133129 }
134130
135131 // we just need to analyze the first unicode character to classify the whole
@@ -154,23 +150,10 @@ + (ItalicKind)kindForCluster:(NSString *)cluster
154150 return ItalicKindFont;
155151 }
156152
157- // italic is not supported, we use the slate instead
153+ // italic is not supported, we use the slant instead
158154 return ItalicKindOblique;
159155}
160156
161- // neutral clusters take over the preceding kind
162- + (void )resolveNeutralKinds : (NSMutableArray <NSNumber *> *)kinds {
163- ItalicKind previous = ItalicKindNeutral;
164- for (NSUInteger i = 0 ; i < kinds.count ; i += 1 ) {
165- ItalicKind kind = (ItalicKind)[kinds[i] integerValue ];
166- if (kind == ItalicKindNeutral) {
167- kinds[i] = @(previous);
168- } else {
169- previous = kind;
170- }
171- }
172- }
173-
174157+ (void )applyKind : (ItalicKind)kind
175158 toSegment : (NSRange )segment
176159 inTextStorage : (NSTextStorage *)textStorage
@@ -188,7 +171,6 @@ + (void)applyKind:(ItalicKind)kind
188171 range: segment];
189172 break ;
190173 case ItalicKindNone:
191- case ItalicKindNeutral:
192174 [textStorage removeAttribute: NSObliquenessAttributeName range: segment];
193175 break ;
194176 }
0 commit comments