VariableFonts

1.0.2

Extends UIFont/NSFont (and SwiftUI Font) for easier variable font support
frzi/swift-variablefonts

What's New

1.0.2

2023-12-08T09:42:50Z
  • Set the supported platform versions to their lowest possible

Variable Fonts

Easier use of variable fonts with AppKit, UIKit and SwiftUI. For iOS, macOS, tvOS, watchOS and visionOS

SwiftUI SwiftUI Swift Xcode MIT

Extends AppKit's NSFont, UIKit's UIFont and SwiftUI's Font with variable font features. Couldn't be easier!

How-to-use

Initializing font with axes.

let font = NSFont(name: "Amstelvar", size: 20, aces: [
	"wght": 650,
	"opsz": 100,
	"XTRA": 700,
])

New font with axes applied

let scienceGothic = UIFont(name: "ScienceGothic", size: 20)!
let slanted = scienceGothic.withAxis("slnt", value: -10)

Get all available axes of a font

let tiltWarp = NSFont(name: "TiltWarp-Regular", size: 100)!
let axes = tiltWarp.allAxes()
print(axes)
/*
[VariableFonts.FontAxis(
	id: 1481789268,
	name: "XROT",
	description: "Rotation in X",
	minimumValue: -45.0,
	maximumValue: 45.0,
	defaultValue: 0.0),
etc...]
*/

SwiftUI

Text("Hello world")
	.font(.custom(name: "Fraunces", size: 40, axes: [
		"wght": 900,
		"SOFT": 100,
		"WONK": 1,
	]))

Example: maxed out font

let nunito = UIFont(name: "NunitoSans", size: 20)!
let axes = nunito.allAxes()

// Creates a UIFont with all axes set to their maximum value.
let megaNunito = nunito.withAxes(
	Dictionary(uniqueKeysWithValues: axes.map { axis in
		return (axis.id, axis.maximumValue)
	})
)

Description

  • Swift Tools 5.9.0
View More Packages from this Author

Dependencies

  • None
Last updated: Tue Apr 09 2024 21:11:14 GMT-0900 (Hawaii-Aleutian Daylight Time)