feat(font): 신규 폰트 사용 설정을 추가한다
This commit is contained in:
@@ -989,6 +989,8 @@
|
|||||||
<string>NotoSansJP-Medium.ttf</string>
|
<string>NotoSansJP-Medium.ttf</string>
|
||||||
<string>NotoSansJP-Light.ttf</string>
|
<string>NotoSansJP-Light.ttf</string>
|
||||||
<string>NotoSansJP-Regular.ttf</string>
|
<string>NotoSansJP-Regular.ttf</string>
|
||||||
|
<string>Pattaya-Regular.ttf</string>
|
||||||
|
<string>Phosphate-Solid.ttf</string>
|
||||||
</array>
|
</array>
|
||||||
<key>UIBackgroundModes</key>
|
<key>UIBackgroundModes</key>
|
||||||
<array>
|
<array>
|
||||||
|
|||||||
BIN
SodaLive/Resources/Font/Pattaya-Regular.ttf
Normal file
BIN
SodaLive/Resources/Font/Pattaya-Regular.ttf
Normal file
Binary file not shown.
BIN
SodaLive/Resources/Font/Phosphate-Solid.ttf
Normal file
BIN
SodaLive/Resources/Font/Phosphate-Solid.ttf
Normal file
Binary file not shown.
@@ -989,6 +989,8 @@
|
|||||||
<string>NotoSansJP-Medium.ttf</string>
|
<string>NotoSansJP-Medium.ttf</string>
|
||||||
<string>NotoSansJP-Light.ttf</string>
|
<string>NotoSansJP-Light.ttf</string>
|
||||||
<string>NotoSansJP-Regular.ttf</string>
|
<string>NotoSansJP-Regular.ttf</string>
|
||||||
|
<string>Pattaya-Regular.ttf</string>
|
||||||
|
<string>Phosphate-Solid.ttf</string>
|
||||||
</array>
|
</array>
|
||||||
<key>UIBackgroundModes</key>
|
<key>UIBackgroundModes</key>
|
||||||
<array>
|
<array>
|
||||||
|
|||||||
@@ -53,6 +53,12 @@ enum SodaTypography {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum SodaFontFamily {
|
||||||
|
case localized
|
||||||
|
case pattaya
|
||||||
|
case phosphate
|
||||||
|
}
|
||||||
|
|
||||||
private func resolvedLanguageCode(currentLocale: Locale) -> String? {
|
private func resolvedLanguageCode(currentLocale: Locale) -> String? {
|
||||||
if let raw = UserDefaults.standard.string(forKey: "app.language"),
|
if let raw = UserDefaults.standard.string(forKey: "app.language"),
|
||||||
let option = LanguageOption(rawValue: raw),
|
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 {
|
struct FontModifier: ViewModifier {
|
||||||
@Environment(\.locale) private var locale
|
@Environment(\.locale) private var locale
|
||||||
let size: CGFloat
|
let size: CGFloat
|
||||||
let weight: SwiftUI.Font.Weight
|
let weight: SwiftUI.Font.Weight
|
||||||
|
let family: SodaFontFamily
|
||||||
|
|
||||||
func body(content: Content) -> some View {
|
func body(content: Content) -> some View {
|
||||||
switch resolvedLanguageCode(currentLocale: locale) {
|
if let fontName = fontName(for: family, weight: weight, locale: locale) {
|
||||||
case "ko":
|
content.font(.custom(fontName, size: size))
|
||||||
content.font(.custom(koreanFontName(for: weight), size: size))
|
} else {
|
||||||
|
|
||||||
case "ja":
|
|
||||||
content.font(.custom(japaneseFontName(for: weight), size: size))
|
|
||||||
|
|
||||||
default:
|
|
||||||
content.font(.system(size: size, weight: weight))
|
content.font(.system(size: size, weight: weight))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension View {
|
extension View {
|
||||||
func appFont(size: CGFloat, weight: SwiftUI.Font.Weight = .regular) -> some View {
|
func appFont(
|
||||||
self.modifier(FontModifier(size: size, weight: weight))
|
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 {
|
func appFont(_ typography: SodaTypography, family: SodaFontFamily = .localized) -> some View {
|
||||||
appFont(size: typography.size, weight: typography.weight)
|
appFont(size: typography.size, weight: typography.weight, family: family)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension Text {
|
extension Text {
|
||||||
func appFont(size: CGFloat, weight: SwiftUI.Font.Weight = .regular) -> Text {
|
func appFont(
|
||||||
if resolvedLanguageCode(currentLocale: .autoupdatingCurrent) == "ko" {
|
size: CGFloat,
|
||||||
return self.font(.custom(koreanFontName(for: weight), size: size))
|
weight: SwiftUI.Font.Weight = .regular,
|
||||||
}
|
family: SodaFontFamily = .localized
|
||||||
|
) -> Text {
|
||||||
if resolvedLanguageCode(currentLocale: .autoupdatingCurrent) == "ja" {
|
if let fontName = fontName(for: family, weight: weight, locale: .autoupdatingCurrent) {
|
||||||
return self.font(.custom(japaneseFontName(for: weight), size: size))
|
return self.font(.custom(fontName, size: size))
|
||||||
}
|
}
|
||||||
|
|
||||||
return self.font(.system(size: size, weight: weight))
|
return self.font(.system(size: size, weight: weight))
|
||||||
}
|
}
|
||||||
|
|
||||||
func appFont(_ typography: SodaTypography) -> Text {
|
func appFont(_ typography: SodaTypography, family: SodaFontFamily = .localized) -> Text {
|
||||||
appFont(size: typography.size, weight: typography.weight)
|
appFont(size: typography.size, weight: typography.weight, family: family)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,4 +13,8 @@ enum Font: String {
|
|||||||
case preRegular = "Pretendard-Regular"
|
case preRegular = "Pretendard-Regular"
|
||||||
|
|
||||||
case preLight = "Pretendard-Light"
|
case preLight = "Pretendard-Light"
|
||||||
|
|
||||||
|
case pattayaRegular = "Pattaya-Regular"
|
||||||
|
|
||||||
|
case phosphateSolid = "PhosphateSolid"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user