Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added font-weight support #54

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 36 additions & 1 deletion Source/Model/Primitives/SVGFont.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,47 @@ public class SVGFont: SerializableBlock {
}

public func toSwiftUI() -> Font {
return Font.custom(name, size: size)//.weight(fontWeight)
return Font.custom(name, size: size).weight(fontWeight(from: weight))
}

func serialize(_ serializer: Serializer) {
serializer.add("name", name, "Serif").add("size", size, 16).add("weight", weight, "normal")
}

private func fontWeight(from: String) -> Font.Weight {
// TODO: lighter and bolder are context-based, this is temporary.
switch from {
case "lighter":
return .light
case "normal":
return .regular
case "bold":
return .bold
case "bolder":
return .black
case "100":
return .ultraLight
case "200":
return .thin
case "300":
return .light
case "400":
return .regular
case "500":
return .medium
case "600":
return .semibold
case "700":
return .bold
case "800":
return .heavy
case "900":
return .black
default:
return .regular
}
}

}


4 changes: 4 additions & 0 deletions Source/UI/MBezierPath+Extension_macOS.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ extension MBezierPath {

case .closePath:
path.closeSubpath()
case .cubicCurveTo:
fallthrough
case .quadraticCurveTo:
fallthrough
@unknown default:
fatalError("Type of element undefined")
}
Expand Down