Skip to content

Commit a637fd7

Browse files
Caldisclaude
andcommitted
fix: tint template icons with labelColor in brand-prefixed images
Template SF Symbol icons render as black by default when drawn into a non-template composite image context. Use labelColor + sourceAtop compositing to make them adapt to light/dark mode automatically. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 1390e26 commit a637fd7

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

Mos/Components/BrandTag.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,14 @@ struct BrandTag {
150150
from: .zero, operation: .sourceOver, fraction: 1.0)
151151
// Original icon
152152
if let icon = original {
153-
icon.draw(in: NSRect(x: tagSize.width + gap, y: (totalHeight - iconSize.height) / 2, width: iconSize.width, height: iconSize.height),
154-
from: .zero, operation: .sourceOver, fraction: 1.0)
153+
let iconRect = NSRect(x: tagSize.width + gap, y: (totalHeight - iconSize.height) / 2, width: iconSize.width, height: iconSize.height)
154+
icon.draw(in: iconRect, from: .zero, operation: .sourceOver, fraction: 1.0)
155+
// 模板图标在 lockFocus 上下文中默认渲染为黑色,
156+
// 用 labelColor + sourceAtop 着色, 使其在暗色模式下自动变为白色
157+
if icon.isTemplate {
158+
NSColor.labelColor.setFill()
159+
iconRect.fill(using: .sourceAtop)
160+
}
155161
}
156162
image.unlockFocus()
157163
image.isTemplate = false

0 commit comments

Comments
 (0)