Use CGColor and remove PlatformColor

This commit is contained in:
Guille Gonzalez
2026-01-04 07:09:56 +01:00
parent fe6df90c4a
commit 6e1a38ede7
5 changed files with 33 additions and 41 deletions

View File

@@ -5,8 +5,8 @@ import Foundation
extension CGContext {
func draw(_ displayNode: Math.DisplayNode, foregroundColor: CGColor) {
let foregroundColor =
displayNode.localTextColor?.cgColor
?? displayNode.textColor?.cgColor
displayNode.localTextColor
?? displayNode.textColor
?? foregroundColor
switch displayNode {

View File

@@ -9,9 +9,9 @@ extension Math {
var position: CGPoint = .zero
var range: NSRange = NSRange(location: 0, length: 0)
var hasScript: Bool = false
var textColor: PlatformColor?
var localTextColor: PlatformColor?
var localBackgroundColor: PlatformColor?
var textColor: CGColor?
var localTextColor: CGColor?
var localBackgroundColor: CGColor?
func bounds() -> CGRect {
CGRect(x: position.x, y: position.y - descent, width: width, height: ascent + descent)

View File

@@ -1,3 +1,4 @@
import CoreGraphics
import CoreText
import Foundation
@@ -423,7 +424,9 @@ extension Math {
return line
}
static var placeholderColor: PlatformColor { PlatformColor.blue }
static var placeholderColor: CGColor {
CGColor(srgbRed: 0, green: 0, blue: 1, alpha: 1)
}
init(
withFont font: PlatformFont?, style: Style.Level, cramped: Bool, spaced: Bool,
@@ -986,7 +989,7 @@ extension Math {
let colorAtom = atom as! Color
let display = Typesetter.createLineForMathList(
colorAtom.innerList, font: font, style: style, maxWidth: maxWidth)
display!.localTextColor = PlatformColor(fromHexString: colorAtom.colorString)
display!.localTextColor = CGColor.fromHexString(colorAtom.colorString)
// Check if we need to break before adding this colored content
let shouldBreak = shouldBreakBeforeDisplay(
@@ -1013,7 +1016,7 @@ extension Math {
let colorAtom = atom as! TextColor
let display = Typesetter.createLineForMathList(
colorAtom.innerList, font: font, style: style, maxWidth: maxWidth)
display!.localTextColor = PlatformColor(fromHexString: colorAtom.colorString)
display!.localTextColor = CGColor.fromHexString(colorAtom.colorString)
// Check if we need to break before adding this colored content
let shouldBreak = shouldBreakBeforeDisplay(
@@ -1051,7 +1054,7 @@ extension Math {
let display = Typesetter.createLineForMathList(
colorboxAtom.innerList, font: font, style: style, maxWidth: maxWidth)
display!.localBackgroundColor = PlatformColor(fromHexString: colorboxAtom.colorString)
display!.localBackgroundColor = CGColor.fromHexString(colorboxAtom.colorString)
// Check if we need to break before adding this colorbox
let shouldBreak = shouldBreakBeforeDisplay(
@@ -1387,7 +1390,7 @@ extension Math {
let color = Typesetter.placeholderColor
current = NSAttributedString(
string: atom.nucleus,
attributes: [kCTForegroundColorAttributeName as NSAttributedString.Key: color.cgColor]
attributes: [kCTForegroundColorAttributeName as NSAttributedString.Key: color]
)
} else {
current = NSAttributedString(string: atom.nucleus)