Skip to content
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

[Catalyst][Text] Fix Catalyst text rendering by disabling inappropriate subpixel-antialiasing #29609

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Libraries/Text/Text/RCTTextView.m
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,15 @@ - (void)drawRect:(CGRect)rect
NSLayoutManager *layoutManager = _textStorage.layoutManagers.firstObject;
NSTextContainer *textContainer = layoutManager.textContainers.firstObject;

#if TARGET_OS_MACCATALYST
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSaveGState(context);
// NSLayoutManager tries to draw text with sub-pixel anti-aliasing by default on
// macOS, but rendering SPAA onto a transparent background produces poor results.
// CATextLayer disables font smoothing by default now on macOS; we follow suit.
CGContextSetShouldSmoothFonts(context, NO);
#endif

NSRange glyphRange = [layoutManager glyphRangeForTextContainer:textContainer];
[layoutManager drawBackgroundForGlyphRange:glyphRange atPoint:_contentFrame.origin];
[layoutManager drawGlyphsForGlyphRange:glyphRange atPoint:_contentFrame.origin];
Expand Down Expand Up @@ -148,6 +157,10 @@ - (void)drawRect:(CGRect)rect
[_highlightLayer removeFromSuperlayer];
_highlightLayer = nil;
}

#if TARGET_OS_MACCATALYST
CGContextRestoreGState(context);
#endif
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,19 @@ - (void)drawAttributedString:(AttributedString)attributedString
NSLayoutManager *layoutManager = textStorage.layoutManagers.firstObject;
NSTextContainer *textContainer = layoutManager.textContainers.firstObject;

#if TARGET_OS_MACCATALYST
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSaveGState(context);
CGContextSetShouldSmoothFonts(context, NO);
#endif

NSRange glyphRange = [layoutManager glyphRangeForTextContainer:textContainer];
[layoutManager drawBackgroundForGlyphRange:glyphRange atPoint:frame.origin];
[layoutManager drawGlyphsForGlyphRange:glyphRange atPoint:frame.origin];

#if TARGET_OS_MACCATALYST
CGContextRestoreGState(context);
#endif
}

- (LinesMeasurements)getLinesForAttributedString:(facebook::react::AttributedString)attributedString
Expand Down