Skip to content

Commit

Permalink
feat: TextStyle
Browse files Browse the repository at this point in the history
  • Loading branch information
alsh0807 committed Jul 23, 2024
1 parent 93e66b6 commit 98c177d
Show file tree
Hide file tree
Showing 6 changed files with 157 additions and 10 deletions.
28 changes: 28 additions & 0 deletions Sources/SDS/Foundation/Typography/Font+Ext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,32 @@ extension Font {
public static func pretendard( _ weight: SopoFont.Pretendard = .regular, size: CGFloat ) -> Font {
return weight.font(size: size)
}

public static func title( _ style: SopoTextStyle.Title1 ) -> Font {
return style.font
}

public static func title2( _ style: SopoTextStyle.Title2 ) -> Font {
return style.font
}

public static func headline( _ style: SopoTextStyle.Headline1 ) -> Font {
return style.font
}

public static func headline2( _ style: SopoTextStyle.Headline2 ) -> Font {
return style.font
}

public static func body( _ style: SopoTextStyle.Body ) -> Font {
return style.font
}

public static func label( _ style: SopoTextStyle.Label ) -> Font {
return style.font
}

public static func caption( _ style: SopoTextStyle.Caption ) -> Font {
return style.font
}
}
2 changes: 1 addition & 1 deletion Sources/SDS/Foundation/Typography/Pretendard+Ext.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import SwiftUI

extension SopoFont.Pretendard: SopoFont.Fontable {
extension SopoFont.Pretendard: SopoFont.CanDefine {
public var name: String {
switch self {
case .thin:
Expand Down
17 changes: 9 additions & 8 deletions Sources/SDS/Foundation/Typography/SopoFont+Ext.swift
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import SwiftUI

extension SopoFont {
public protocol Fontable {
public protocol CanDefine {
var name: String { get }
}

public protocol Fontable {
var font: Font { get }
}
}

enum SopoFontError: Error {
case fileNotFound
}


extension SopoFont.Fontable {
private func loadFont() {

extension SopoFont.CanDefine {
public func loadFont() {
guard let asset = NSDataAsset(name: self.name, bundle: .module),
let provider = CGDataProvider(data: asset.data as NSData),
let font = CGFont(provider),
Expand All @@ -22,7 +24,6 @@ extension SopoFont.Fontable {
}

public func font( size: CGFloat ) -> Font {
self.loadFont()
return Font.custom(name, size: size)
return Font.custom(self.name, size: size)
}
}
10 changes: 9 additions & 1 deletion Sources/SDS/Foundation/Typography/SopoFont.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import SwiftUI

public struct SopoFont {
public enum Pretendard { case thin, extraLight, light, regular, medium, semibold, bold, extraBold, black }
init() {
Pretendard.allCases.forEach { item in
item.loadFont()
}
}

public enum Pretendard: CaseIterable { case thin, extraLight, light, regular, medium, semibold, bold, extraBold, black }


}
93 changes: 93 additions & 0 deletions Sources/SDS/Foundation/Typography/SopoTextStyle+Ext.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import SwiftUI

extension SopoTextStyle.Title1: SopoFont.Fontable {
public var font: Font {
switch self {
case .bold:
.pretendard(.extraBold, size: 32)
case .medium:
.pretendard(.medium, size: 32)
case .regular:
.pretendard(.regular, size: 32)
}
}
}

extension SopoTextStyle.Title2: SopoFont.Fontable {
public var font: Font {
switch self {
case .bold:
.pretendard(.bold, size: 28)
case .medium:
.pretendard(.medium, size: 28)
case .regular:
.pretendard(.regular, size: 28)
}
}
}

extension SopoTextStyle.Headline1: SopoFont.Fontable {
public var font: Font {
switch self {
case .bold:
.pretendard(.bold, size: 24)
case .medium:
.pretendard(.medium, size: 24)
case .regular:
.pretendard(.regular, size: 24)
}
}
}

extension SopoTextStyle.Headline2: SopoFont.Fontable {
public var font: Font {
switch self {
case .bold:
.pretendard(.bold, size: 20)
case .medium:
.pretendard(.medium, size: 20)
case .regular:
.pretendard(.regular, size: 20)
}
}
}

extension SopoTextStyle.Body: SopoFont.Fontable {
public var font: Font {
switch self {
case .bold:
.pretendard(.bold, size: 16)
case .medium:
.pretendard(.medium, size: 16)
case .regular:
.pretendard(.regular, size: 16)
}
}
}


extension SopoTextStyle.Label: SopoFont.Fontable {
public var font: Font {
switch self {
case .bold:
.pretendard(.bold, size: 14)
case .medium:
.pretendard(.medium, size: 14)
case .regular:
.pretendard(.regular, size: 14)
}
}
}

extension SopoTextStyle.Caption: SopoFont.Fontable {
public var font: Font {
switch self {
case .bold:
.pretendard(.bold, size: 12)
case .medium:
.pretendard(.medium, size: 12)
case .regular:
.pretendard(.regular, size: 12)
}
}
}
17 changes: 17 additions & 0 deletions Sources/SDS/Foundation/Typography/SopoTextStyle.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import SwiftUI

public struct SopoTextStyle {

public enum Title1 { case bold, medium, regular }
public enum Title2 { case bold, medium, regular }

public enum Headline1 { case bold, medium, regular }
public enum Headline2 { case bold, medium, regular }

public enum Body { case bold, medium, regular }

public enum Label { case bold, medium, regular }

public enum Caption { case bold, medium, regular }

}

0 comments on commit 98c177d

Please sign in to comment.