Skip to content

Commit 13b2806

Browse files
committed
fix(text): preserve macOS font smoothing in keyed text masks
1 parent 419664e commit 13b2806

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

‎Sources/OpenSwiftUICore/Shape/ShapeStyle/ShapeStyleRendering.swift‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,24 @@ package struct _ShapeStyle_RenderedShape {
300300
name: ShapeStyle.Name,
301301
layers: inout ShapeStyle.RenderedLayers
302302
) {
303+
#if os(macOS)
304+
// Font smoothing on macOS depends on the fill color, even in an alpha-only context.
305+
// See https://developer.apple.com/documentation/coregraphics/cgcontext/setshouldsmoothfonts(_:)
306+
let maskColor: ORBColor
307+
switch style.fill {
308+
case let .color(color):
309+
maskColor = ORBColor(
310+
red: color.linearRed,
311+
green: color.linearGreen,
312+
blue: color.linearBlue,
313+
alpha: 1
314+
)
315+
default:
316+
maskColor = environment.colorScheme == .dark ? .white : .black
317+
}
318+
#else
319+
let maskColor = ORBColor.white
320+
#endif
303321
let resolved = text.text
304322
let textLayers = resolved.layers(
305323
for: frame.size,
@@ -327,7 +345,7 @@ package struct _ShapeStyle_RenderedShape {
327345
keyColor: ORBColor
328346
) {
329347
transform.removeAll()
330-
transform.addColorReplacement(from: keyColor, to: .white, colorSpace: .linearSRGB)
348+
transform.addColorReplacement(from: keyColor, to: maskColor, colorSpace: .linearSRGB)
331349
let mask = transform.copyApplying(toDisplayList: list)
332350
let drawing = makeDrawingItem(from: mask, offset: offset, flags: flags.union(.alphaOnly))
333351
layers.beginLayer(id: id, style: style, shape: &self)

0 commit comments

Comments
 (0)