Skip to content

Commit

Permalink
The use of CGContextSetFontSmoothingStyle is not permitted on the App…
Browse files Browse the repository at this point in the history
… Store
  • Loading branch information
krzyzanowskim committed May 14, 2024
1 parent 42ef18d commit 0eaaf97
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Sources/STObjCLandShim/STObjCLandShim.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
// CGContextSetFontSmoothingStyle(ctx, 16);
// }


#ifdef USE_FONT_SMOOTHING_STYLE
// The use of non-public or deprecated APIs is not permitted on the App Store

extern void CGContextSetFontSmoothingStyle(CGContextRef, int);
extern int CGContextGetFontSmoothingStyle(CGContextRef);

Expand All @@ -21,3 +25,4 @@ void STContextSetFontSmoothingStyle(CGContextRef context, int style) {
int STContextGetFontSmoothingStyle(CGContextRef context) {
return CGContextGetFontSmoothingStyle(context);
}
#endif
5 changes: 5 additions & 0 deletions Sources/STTextView/STTextLayoutFragment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,18 @@ final class STTextLayoutFragment: NSTextLayoutFragment {

context.saveGState()

#if USE_FONT_SMOOTHING_STYLE
// This seems to be available at least on 10.8 and later. The only reference to it is in
// WebKit. This causes text to render just a little lighter, which looks nicer.
let useThinStrokes = true // shouldSmooth
var savedFontSmoothingStyle: Int32 = 0

if useThinStrokes {
context.setShouldSmoothFonts(true)
savedFontSmoothingStyle = STContextGetFontSmoothingStyle(context)
STContextSetFontSmoothingStyle(context, 16)
}
#endif

for lineFragment in textLineFragments {
// Determine paragraph style. Either from the fragment string or default for the text view
Expand All @@ -64,9 +67,11 @@ final class STTextLayoutFragment: NSTextLayoutFragment {
}
}

#if USE_FONT_SMOOTHING_STYLE
if (useThinStrokes) {
STContextSetFontSmoothingStyle(context, savedFontSmoothingStyle);
}
#endif

if showsInvisibleCharacters {
drawInvisibles(at: point, in: context)
Expand Down

0 comments on commit 0eaaf97

Please sign in to comment.