-
Notifications
You must be signed in to change notification settings - Fork 119
Expand file tree
/
Copy pathFontScaleProperty.swift
More file actions
35 lines (31 loc) · 1.05 KB
/
Copy pathFontScaleProperty.swift
File metadata and controls
35 lines (31 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import Foundation
/// Scales the current font by the given factor.
public struct FontScaleProperty: TextProperty {
private let scale: CGFloat
/// Creates a font scale property.
public init(_ scale: CGFloat) {
self.scale = scale
}
public func apply(in attributes: inout AttributeContainer, environment: TextEnvironmentValues) {
let font = attributes.font ?? environment.font ?? .body
#if compiler(>=6.2)
if #available(iOS 26.0, macOS 26.0, tvOS 26.0, watchOS 26.0, visionOS 26.0, *) {
attributes.font = font.scaled(by: scale)
} else if var provider = font.provider() {
provider.scale = scale
attributes.font = provider.resolve(in: environment)
}
#else
if var provider = font.provider() {
provider.scale = scale
attributes.font = provider.resolve(in: environment)
}
#endif
}
}
extension TextProperty where Self == FontScaleProperty {
/// Scales the font by the given factor.
public static func fontScale(_ scale: CGFloat) -> Self {
FontScaleProperty(scale)
}
}