feat(font): 신규 폰트 사용 설정을 추가한다

This commit is contained in:
Yu Sung
2026-06-02 11:54:27 +09:00
parent d9b3990e06
commit 6f8ccc7b1a
6 changed files with 53 additions and 21 deletions

View File

@@ -53,6 +53,12 @@ enum SodaTypography {
}
}
enum SodaFontFamily {
case localized
case pattaya
case phosphate
}
private func resolvedLanguageCode(currentLocale: Locale) -> String? {
if let raw = UserDefaults.standard.string(forKey: "app.language"),
let option = LanguageOption(rawValue: raw),
@@ -88,49 +94,67 @@ private func japaneseFontName(for weight: SwiftUI.Font.Weight) -> String {
}
}
private func fontName(for family: SodaFontFamily, weight: SwiftUI.Font.Weight, locale: Locale) -> String? {
switch family {
case .localized:
switch resolvedLanguageCode(currentLocale: locale) {
case "ko":
return koreanFontName(for: weight)
case "ja":
return japaneseFontName(for: weight)
default:
return nil
}
case .pattaya:
return "Pattaya-Regular"
case .phosphate:
return "PhosphateSolid"
}
}
struct FontModifier: ViewModifier {
@Environment(\.locale) private var locale
let size: CGFloat
let weight: SwiftUI.Font.Weight
let family: SodaFontFamily
func body(content: Content) -> some View {
switch resolvedLanguageCode(currentLocale: locale) {
case "ko":
content.font(.custom(koreanFontName(for: weight), size: size))
case "ja":
content.font(.custom(japaneseFontName(for: weight), size: size))
default:
if let fontName = fontName(for: family, weight: weight, locale: locale) {
content.font(.custom(fontName, size: size))
} else {
content.font(.system(size: size, weight: weight))
}
}
}
extension View {
func appFont(size: CGFloat, weight: SwiftUI.Font.Weight = .regular) -> some View {
self.modifier(FontModifier(size: size, weight: weight))
func appFont(
size: CGFloat,
weight: SwiftUI.Font.Weight = .regular,
family: SodaFontFamily = .localized
) -> some View {
self.modifier(FontModifier(size: size, weight: weight, family: family))
}
func appFont(_ typography: SodaTypography) -> some View {
appFont(size: typography.size, weight: typography.weight)
func appFont(_ typography: SodaTypography, family: SodaFontFamily = .localized) -> some View {
appFont(size: typography.size, weight: typography.weight, family: family)
}
}
extension Text {
func appFont(size: CGFloat, weight: SwiftUI.Font.Weight = .regular) -> Text {
if resolvedLanguageCode(currentLocale: .autoupdatingCurrent) == "ko" {
return self.font(.custom(koreanFontName(for: weight), size: size))
}
if resolvedLanguageCode(currentLocale: .autoupdatingCurrent) == "ja" {
return self.font(.custom(japaneseFontName(for: weight), size: size))
func appFont(
size: CGFloat,
weight: SwiftUI.Font.Weight = .regular,
family: SodaFontFamily = .localized
) -> Text {
if let fontName = fontName(for: family, weight: weight, locale: .autoupdatingCurrent) {
return self.font(.custom(fontName, size: size))
}
return self.font(.system(size: size, weight: weight))
}
func appFont(_ typography: SodaTypography) -> Text {
appFont(size: typography.size, weight: typography.weight)
func appFont(_ typography: SodaTypography, family: SodaFontFamily = .localized) -> Text {
appFont(size: typography.size, weight: typography.weight, family: family)
}
}