@@ -3,7 +3,7 @@ import UIKit
33
44@ MainActor
55enum T3InstalledFonts {
6- static func describe ( _ font : UIFont , name : String ? = nil ) -> [ String : String ] {
6+ static func describe ( _ font : UIFont , name : String ? = nil ) -> [ String : Any ] {
77 func variant ( _ weight : UIFont . Weight ) -> String {
88 let descriptor = UIFontDescriptor ( fontAttributes : [
99 . family : font . familyName ,
@@ -12,16 +12,27 @@ enum T3InstalledFonts {
1212 let candidate = UIFont ( descriptor : descriptor , size : font . pointSize )
1313 return candidate . familyName == font . familyName ? candidate . fontName : font . fontName
1414 }
15+ // CoreText reports medium as 0.20 while UIKit requests 0.23.
16+ var emphasisFaces : [ String : String ] = [ : ]
17+ for ( key , weight ) in [ ( " 500 " , UIFont . Weight . medium ) , ( " 600 " , . semibold ) , ( " 700 " , . bold ) ] {
18+ let name = variant ( weight )
19+ guard let candidate = UIFont ( name : name , size : font . pointSize ) ,
20+ let traits = candidate . fontDescriptor . object ( forKey : . traits ) as? [ UIFontDescriptor . TraitKey : Any ] ,
21+ let actual = traits [ . weight ] as? NSNumber ,
22+ abs ( actual . doubleValue - Double ( weight . rawValue ) ) < 0.04 else { continue }
23+ emphasisFaces [ key ] = name
24+ }
1525 return [
1626 " name " : name ?? font . fontName ,
1727 " label " : font . familyName ,
1828 " regular " : font . fontName ,
1929 " medium " : variant ( . medium ) ,
2030 " bold " : variant ( . bold ) ,
31+ " emphasisFaces " : emphasisFaces ,
2132 ]
2233 }
2334
24- static func resolve ( _ names : [ String ] , completion : @escaping ( [ [ String : String ] ] ) -> Void ) {
35+ static func resolve ( _ names : [ String ] , completion : @escaping ( [ [ String : Any ] ] ) -> Void ) {
2536 guard ! names . isEmpty else { completion ( [ ] ) ; return }
2637 // Provider fonts must be requested again for each process. Persist names,
2738 // not file URLs: iOS owns the files and the picker grants family access.
@@ -39,11 +50,11 @@ enum T3InstalledFonts {
3950
4051@ MainActor
4152final class T3FontPickerPresentation : NSObject , UIFontPickerViewControllerDelegate , UIAdaptivePresentationControllerDelegate {
42- private let completion : ( [ String : String ] ? ) -> Void
53+ private let completion : ( [ String : Any ] ? ) -> Void
4354 private var picker : UIFontPickerViewController ?
4455 private var finished = false
4556
46- init ( completion : @escaping ( [ String : String ] ? ) -> Void ) {
57+ init ( completion : @escaping ( [ String : Any ] ? ) -> Void ) {
4758 self . completion = completion
4859 }
4960
@@ -79,7 +90,7 @@ final class T3FontPickerPresentation: NSObject, UIFontPickerViewControllerDelega
7990 picker . dismiss ( animated : true ) { self . finish ( nil ) }
8091 }
8192
82- private func finish ( _ result : [ String : String ] ? ) {
93+ private func finish ( _ result : [ String : Any ] ? ) {
8394 guard ! finished else { return }
8495 finished = true
8596 picker ? . delegate = nil
0 commit comments