-
Notifications
You must be signed in to change notification settings - Fork 149
Add apple_fontSmoothing style and global default setting #329
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
685f103
8ccd26c
45d2ee2
1e2c329
408dae3
bdaa8ad
5a67ae0
e5a6df2
4bca23c
d067629
6ed01c8
ae5cc57
07ba414
e7faf7a
efc5587
8cbf04a
f158098
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ | |
# that. | ||
gradlew text eol=lf | ||
*.sh text eol=lf | ||
*.command text eol=lf |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
#import <React/RCTLog.h> | ||
|
||
NSString *const RCTTextAttributesIsHighlightedAttributeName = @"RCTTextAttributesIsHighlightedAttributeName"; | ||
NSString *const RCTTextAttributesFontSmoothingAttributeName = @"RCTTextAttributesFontSmoothingAttributeName"; // TODO(OSS Candidate ISS#2710739) | ||
NSString *const RCTTextAttributesTagAttributeName = @"RCTTextAttributesTagAttributeName"; | ||
|
||
@implementation RCTTextAttributes | ||
|
@@ -56,6 +57,7 @@ - (void)applyTextAttributes:(RCTTextAttributes *)textAttributes | |
_fontVariant = textAttributes->_fontVariant ?: _fontVariant; | ||
_allowFontScaling = textAttributes->_allowFontScaling || _allowFontScaling; // * | ||
_letterSpacing = !isnan(textAttributes->_letterSpacing) ? textAttributes->_letterSpacing : _letterSpacing; | ||
_fontSmoothing = textAttributes->_fontSmoothing != RCTFontSmoothingAuto ? textAttributes->_fontSmoothing : _fontSmoothing; // TODO(OSS Candidate ISS#2710739) | ||
|
||
// Paragraph Styles | ||
_lineHeight = !isnan(textAttributes->_lineHeight) ? textAttributes->_lineHeight : _lineHeight; | ||
|
@@ -183,6 +185,12 @@ - (NSParagraphStyle *)effectiveParagraphStyle | |
attributes[RCTTextAttributesIsHighlightedAttributeName] = @YES; | ||
} | ||
|
||
// [TODO(macOS ISS#2323203) | ||
if (_fontSmoothing != RCTFontSmoothingAuto) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it possible it could get set to something other than auto and then set back to auto (which would then fail to update here)? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, that's a good point. Although in practice I doubt anyone is going to be toggling this style on and off. I'll test some stuff out setting it without the condition |
||
attributes[RCTTextAttributesFontSmoothingAttributeName] = @(_fontSmoothing); | ||
} | ||
// ]TODO(macOS ISS#2323203) | ||
|
||
if (_tag) { | ||
attributes[RCTTextAttributesTagAttributeName] = _tag; | ||
} | ||
|
@@ -290,6 +298,7 @@ - (BOOL)isEqual:(RCTTextAttributes *)textAttributes | |
RCTTextAttributesCompareObjects(_fontVariant) && | ||
RCTTextAttributesCompareOthers(_allowFontScaling) && | ||
RCTTextAttributesCompareFloats(_letterSpacing) && | ||
RCTTextAttributesCompareOthers(_fontSmoothing) && // TODO(OSS Candidate ISS#2710739) | ||
// Paragraph Styles | ||
RCTTextAttributesCompareFloats(_lineHeight) && | ||
RCTTextAttributesCompareFloats(_alignment) && | ||
|
@@ -309,4 +318,16 @@ - (BOOL)isEqual:(RCTTextAttributes *)textAttributes | |
RCTTextAttributesCompareOthers(_textTransform); | ||
} | ||
|
||
// [TODO(OSS Candidate ISS#2710739) | ||
static RCTFontSmoothing _fontSmoothingDefault = RCTFontSmoothingAuto; | ||
|
||
+ (RCTFontSmoothing)fontSmoothingDefault { | ||
return _fontSmoothingDefault; | ||
} | ||
|
||
+ (void)setFontSmoothingDefault:(RCTFontSmoothing)fontSmoothingDefault { | ||
_fontSmoothingDefault = fontSmoothingDefault; | ||
} | ||
// ]TODO(OSS Candidate ISS#2710739) | ||
|
||
@end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -159,12 +159,40 @@ - (void)drawRect:(CGRect)rect | |
NSTextContainer *textContainer = layoutManager.textContainers.firstObject; | ||
|
||
NSRange glyphRange = [layoutManager glyphRangeForTextContainer:textContainer]; | ||
[layoutManager drawBackgroundForGlyphRange:glyphRange atPoint:_contentFrame.origin]; | ||
[layoutManager drawGlyphsForGlyphRange:glyphRange atPoint:_contentFrame.origin]; | ||
|
||
__block UIBezierPath *highlightPath = nil; | ||
NSRange characterRange = [layoutManager characterRangeForGlyphRange:glyphRange | ||
actualGlyphRange:NULL]; | ||
// [TODO(OSS Candidate ISS#2710739) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that the feature is awesome. It feels that this property should be part of like So, it should be applied to the whole text node. Or, do we have use cases where it should be applied only for some fragments? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, the biggest reason we can't do that is because mac doesn't work with Fabric yet so we have no ParagraphAttributes 😢. Otherwise, just to be parallel with the w3c |
||
[_textStorage enumerateAttribute:RCTTextAttributesFontSmoothingAttributeName | ||
inRange:characterRange | ||
options:0 | ||
usingBlock: | ||
^(NSNumber *value, NSRange range, __unused BOOL *stop) { | ||
RCTFontSmoothing smoothing = value.integerValue; | ||
if (smoothing == RCTFontSmoothingAuto) { | ||
smoothing = [RCTTextAttributes fontSmoothingDefault]; | ||
} | ||
CGContextRef context = UIGraphicsGetCurrentContext(); | ||
CGContextSaveGState(context); | ||
switch (smoothing) { | ||
case RCTFontSmoothingNone: | ||
CGContextSetShouldAntialias(context, false); | ||
break; | ||
case RCTFontSmoothingAntialiased: | ||
CGContextSetAllowsFontSmoothing(context, false); | ||
CGContextSetShouldSmoothFonts(context, false); | ||
break; | ||
case RCTFontSmoothingAuto: | ||
case RCTFontSmoothingSubpixelAntialiased: | ||
break; | ||
} | ||
NSRange subGlyphRange = [layoutManager glyphRangeForCharacterRange:range actualCharacterRange:nil]; | ||
[layoutManager drawBackgroundForGlyphRange:subGlyphRange atPoint:_contentFrame.origin]; | ||
[layoutManager drawGlyphsForGlyphRange:subGlyphRange atPoint:_contentFrame.origin]; | ||
CGContextRestoreGState(context); | ||
}]; | ||
// ]TODO(OSS Candidate ISS#2710739) | ||
|
||
__block UIBezierPath *highlightPath = nil; | ||
[_textStorage enumerateAttribute:RCTTextAttributesIsHighlightedAttributeName | ||
inRange:characterRange | ||
options:0 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is this deprecated file still used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually don't know. But it contains all the same props as the other files like ViewConfig so I made it parallel.