-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5ca82fd
commit ede7bec
Showing
13 changed files
with
411 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Xcode | ||
# | ||
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore | ||
|
||
## Build generated | ||
build/ | ||
DerivedData/ | ||
|
||
## Various settings | ||
*.pbxuser | ||
!default.pbxuser | ||
*.mode1v3 | ||
!default.mode1v3 | ||
*.mode2v3 | ||
!default.mode2v3 | ||
*.perspectivev3 | ||
!default.perspectivev3 | ||
xcuserdata/ | ||
|
||
## Other | ||
*.moved-aside | ||
*.xccheckout | ||
*.xcscmblueprint | ||
|
||
## Obj-C/Swift specific | ||
*.hmap | ||
*.ipa | ||
*.dSYM.zip | ||
*.dSYM | ||
|
||
## Playgrounds | ||
timeline.xctimeline | ||
playground.xcworkspace | ||
|
||
# Swift Package Manager | ||
# | ||
# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. | ||
# Packages/ | ||
# Package.pins | ||
# Package.resolved | ||
.build/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// | ||
// FontDetails.swift | ||
// GoogleFontPreview | ||
// | ||
// Created by Scott Andrew on 12/13/22. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct DetailsView: View { | ||
var font: GoogleFont | ||
|
||
var body: some View { | ||
VStack { | ||
Text(font.family) | ||
.font(.system(size: 25, weight: .bold)) | ||
Spacer() | ||
ScrollView { | ||
LazyVStack(alignment: .leading) { | ||
ForEach(font.files, id: \.id) { value in | ||
StyleCell(style: value) | ||
} | ||
} | ||
} | ||
.id(font.family) | ||
} | ||
.padding() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// | ||
// Font+Utils.swift | ||
// GoogleFontPreview | ||
// | ||
// Created by Scott Andrew on 12/13/22. | ||
// | ||
|
||
import SwiftUI | ||
|
||
extension Font { | ||
static func register(url: URL, size: CGFloat = 18) async throws -> Font? { | ||
do { | ||
let request = URLRequest(url: url) | ||
let (data, _) = try await URLSession.shared.data(for: request) | ||
|
||
guard let provider = CGDataProvider(data: data as CFData), | ||
let cgFont = CGFont(provider) | ||
else { | ||
print("Unsucessfully registered font") | ||
return nil | ||
} | ||
|
||
let ctFont = CTFontCreateWithGraphicsFont(cgFont, size, nil, nil) | ||
|
||
return Font(ctFont) | ||
} catch { | ||
print(error) | ||
} | ||
|
||
return nil | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// | ||
// FontList.swift | ||
// GoogleFontPreview | ||
// | ||
// Created by Scott Andrew on 12/17/22. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct FontList: View { | ||
@Binding var selectedFont: GoogleFont? | ||
var fonts: [GoogleFont] | ||
|
||
var body: some View { | ||
List(fonts, selection: $selectedFont) { font in | ||
NavigationLink(value: font) { | ||
VStack(alignment: .leading) { | ||
Text(font.family) | ||
.font(.system(size: 14, weight: .bold)) | ||
Text("\(font.files.count) styles") | ||
.font(.system(size: 14)) | ||
} | ||
.padding(8) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// | ||
// GoogleFont.swift | ||
// DuffleBag | ||
// | ||
// Created by Scott Andrew on 10/26/22. | ||
// | ||
|
||
import Foundation | ||
|
||
struct GoogleResponse: Decodable { | ||
let kind: String | ||
let items: [GoogleFont] | ||
} | ||
|
||
struct FontFile: Hashable, Identifiable { | ||
let style: Style | ||
let id = UUID() | ||
let url: URL | ||
} | ||
|
||
struct GoogleFont: Hashable, Decodable, Identifiable { | ||
var id: String { family } | ||
|
||
let family: String | ||
let files: [FontFile] | ||
let version: String | ||
let category: String | ||
|
||
enum CodingKeys: CodingKey { | ||
case family | ||
case files | ||
case version | ||
case category | ||
} | ||
|
||
init(from decoder: Decoder) throws { | ||
let container = try decoder.container(keyedBy: CodingKeys.self) | ||
self.family = try container.decode(String.self, forKey: .family) | ||
let files = try container.decode([String: String].self, forKey: .files) | ||
self.version = try container.decode(String.self, forKey: .version) | ||
self.category = try container.decode(String.self, forKey: .category) | ||
|
||
var keys = Array(files.keys) | ||
|
||
// lets do a bit of work to get our files that we want. | ||
keys.sort { item1, item2 in | ||
func itemFixer(_ value: String) -> String { | ||
if value == "regular" { | ||
return "400" | ||
} else if value == "italic" { | ||
return "400Italic" | ||
} | ||
|
||
return value | ||
} | ||
|
||
let fixedItem1 = itemFixer(item1) | ||
let fixedItem2 = itemFixer(item2) | ||
|
||
return fixedItem1 < fixedItem2 | ||
} | ||
|
||
self.files = keys.compactMap { key in | ||
guard let style = Style(rawValue: key), | ||
let location = files[key]?.replacingOccurrences(of: "http", with: "https") | ||
else { | ||
return nil | ||
} | ||
|
||
return FontFile(style: style, url: URL(string: location)!) | ||
} | ||
} | ||
} |
Oops, something went wrong.