From 69f8f7e81ca73ffbf1a0d76ccbd6cf8545caff57 Mon Sep 17 00:00:00 2001 From: Ruben Beltran del Rio Date: Mon, 7 Jul 2025 13:22:22 +0200 Subject: Add font customization --- .../MapRender/MapRenderView.swift | 3 +++ .../Preferences/MapPreferencesView.swift | 14 ++++++++++ Map/Presentation/Theme/Font+theme.swift | 31 ++++++++++++++++++---- 3 files changed, 43 insertions(+), 5 deletions(-) (limited to 'Map/Presentation') diff --git a/Map/Presentation/Complex Components/MapRender/MapRenderView.swift b/Map/Presentation/Complex Components/MapRender/MapRenderView.swift index 2357013..7fd4092 100644 --- a/Map/Presentation/Complex Components/MapRender/MapRenderView.swift +++ b/Map/Presentation/Complex Components/MapRender/MapRenderView.swift @@ -22,6 +22,8 @@ struct MapRenderView: View { @Binding var document: MapDocument @Binding var evolution: StageType @AppStorage("showMapBackground") var showMapBackground: Bool = true + @AppStorage("useCustomFont") var useCustomFont: Bool = false + @AppStorage("customFontName") var customFontName: String = "Helvetica" var stage: Stage { Stage.stages(evolution) @@ -77,6 +79,7 @@ struct MapRenderView: View { MapNotes( mapSize: mapSize, lineWidth: lineWidth, notes: parsedMap.notes) } + .id("\(useCustomFont)-\(customFontName)") .offset(x: padding, y: padding).frame( width: mapSize.width + 2 * padding, height: mapSize.height + 2 * padding, alignment: .topLeading diff --git a/Map/Presentation/Preferences/MapPreferencesView.swift b/Map/Presentation/Preferences/MapPreferencesView.swift index f8c976e..c5a9236 100644 --- a/Map/Presentation/Preferences/MapPreferencesView.swift +++ b/Map/Presentation/Preferences/MapPreferencesView.swift @@ -18,6 +18,8 @@ import SwiftUI struct MapPreferencesView: View { @AppStorage("showMapBackground") private var showBackground = true @AppStorage("useSmartEditor") private var useSmartEditor = false + @AppStorage("useCustomFont") private var useCustomFont = false + @AppStorage("customFontName") private var customFontName = "Helvetica" var body: some View { VStack(alignment: .center, spacing: Dimensions.Spacing.loose) { @@ -30,6 +32,18 @@ struct MapPreferencesView: View { Toggle(isOn: $showBackground, label: { Text("preferences.map.map_style.show_background") .font(.Theme.Body.regular) }) + + Toggle(isOn: $useCustomFont, label: { Text("preferences.map.map_style.use_custom_font") + .font(.Theme.Body.regular) + }) + + Picker("", selection: $customFontName) { + ForEach(NSFontManager.shared.availableFontFamilies, id: \.self) { fontFamily in + Text(fontFamily).tag(fontFamily) + } + } + .pickerStyle(MenuPickerStyle()) + .disabled(!useCustomFont) } .frame(maxWidth: .infinity, alignment: .leading) } diff --git a/Map/Presentation/Theme/Font+theme.swift b/Map/Presentation/Theme/Font+theme.swift index cc80fc4..079c0de 100644 --- a/Map/Presentation/Theme/Font+theme.swift +++ b/Map/Presentation/Theme/Font+theme.swift @@ -46,11 +46,32 @@ extension Font { } struct Map { - static let note = Font.libertinus(size: Dimensions.FontSize.Map.note).weight(.regular) - static let axisLabel = Font.libertinus(size: Dimensions.FontSize.Map.axisLabel).weight( - .regular) - static let vertexLabel = Font.libertinus(size: Dimensions.FontSize.Map.vertexLabel).weight( - .regular) + static var note: Font { + if UserDefaults.standard.bool(forKey: "useCustomFont"), + let customFontName = UserDefaults.standard.string(forKey: "customFontName"), + !customFontName.isEmpty { + return Font.custom(customFontName, size: Dimensions.FontSize.Map.note).weight(.regular) + } + return Font.libertinus(size: Dimensions.FontSize.Map.note).weight(.regular) + } + + static var axisLabel: Font { + if UserDefaults.standard.bool(forKey: "useCustomFont"), + let customFontName = UserDefaults.standard.string(forKey: "customFontName"), + !customFontName.isEmpty { + return Font.custom(customFontName, size: Dimensions.FontSize.Map.axisLabel).weight(.regular) + } + return Font.libertinus(size: Dimensions.FontSize.Map.axisLabel).weight(.regular) + } + + static var vertexLabel: Font { + if UserDefaults.standard.bool(forKey: "useCustomFont"), + let customFontName = UserDefaults.standard.string(forKey: "customFontName"), + !customFontName.isEmpty { + return Font.custom(customFontName, size: Dimensions.FontSize.Map.vertexLabel).weight(.regular) + } + return Font.libertinus(size: Dimensions.FontSize.Map.vertexLabel).weight(.regular) + } } } } -- cgit