From 0eaaf971ea81fc7b4197a84242d13d3bc27bdad0 Mon Sep 17 00:00:00 2001 From: Marcin Krzyzanowski Date: Tue, 14 May 2024 12:03:51 +0200 Subject: [PATCH] The use of CGContextSetFontSmoothingStyle is not permitted on the App Store --- Sources/STObjCLandShim/STObjCLandShim.m | 5 +++++ Sources/STTextView/STTextLayoutFragment.swift | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/Sources/STObjCLandShim/STObjCLandShim.m b/Sources/STObjCLandShim/STObjCLandShim.m index e14df40..acb67bb 100644 --- a/Sources/STObjCLandShim/STObjCLandShim.m +++ b/Sources/STObjCLandShim/STObjCLandShim.m @@ -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); @@ -21,3 +25,4 @@ void STContextSetFontSmoothingStyle(CGContextRef context, int style) { int STContextGetFontSmoothingStyle(CGContextRef context) { return CGContextGetFontSmoothingStyle(context); } +#endif diff --git a/Sources/STTextView/STTextLayoutFragment.swift b/Sources/STTextView/STTextLayoutFragment.swift index 157ea40..484fcb0 100644 --- a/Sources/STTextView/STTextLayoutFragment.swift +++ b/Sources/STTextView/STTextLayoutFragment.swift @@ -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 @@ -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)