Add main view
This commit is contained in:
parent
f0c8823091
commit
0ca6154229
|
|
@ -13,6 +13,9 @@
|
|||
5705571D262C5EA1004A1FE3 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57055708262C5EA0004A1FE3 /* ContentView.swift */; };
|
||||
5705571E262C5EA1004A1FE3 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 57055709262C5EA1004A1FE3 /* Assets.xcassets */; };
|
||||
5705571F262C5EA1004A1FE3 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 57055709262C5EA1004A1FE3 /* Assets.xcassets */; };
|
||||
5705572E262C5F8B004A1FE3 /* FontModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5705572D262C5F8B004A1FE3 /* FontModel.swift */; };
|
||||
57055733262C602A004A1FE3 /* CharacterCellView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57055732262C602A004A1FE3 /* CharacterCellView.swift */; };
|
||||
5705573A262C61DF004A1FE3 /* NSCharacterSetExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57055739262C61DF004A1FE3 /* NSCharacterSetExtension.swift */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
|
|
@ -24,6 +27,9 @@
|
|||
57055716262C5EA1004A1FE3 /* FontFace.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = FontFace.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
57055718262C5EA1004A1FE3 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
57055719262C5EA1004A1FE3 /* macOS.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = macOS.entitlements; sourceTree = "<group>"; };
|
||||
5705572D262C5F8B004A1FE3 /* FontModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FontModel.swift; sourceTree = "<group>"; };
|
||||
57055732262C602A004A1FE3 /* CharacterCellView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CharacterCellView.swift; sourceTree = "<group>"; };
|
||||
57055739262C61DF004A1FE3 /* NSCharacterSetExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NSCharacterSetExtension.swift; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
|
|
@ -57,6 +63,9 @@
|
|||
57055706262C5EA0004A1FE3 /* Shared */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
57055738262C61CF004A1FE3 /* Utils */,
|
||||
57055731262C600D004A1FE3 /* View */,
|
||||
5705572C262C5F4D004A1FE3 /* Model */,
|
||||
57055707262C5EA0004A1FE3 /* FontFaceApp.swift */,
|
||||
57055708262C5EA0004A1FE3 /* ContentView.swift */,
|
||||
57055709262C5EA1004A1FE3 /* Assets.xcassets */,
|
||||
|
|
@ -90,6 +99,30 @@
|
|||
path = macOS;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
5705572C262C5F4D004A1FE3 /* Model */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
5705572D262C5F8B004A1FE3 /* FontModel.swift */,
|
||||
);
|
||||
path = Model;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
57055731262C600D004A1FE3 /* View */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
57055732262C602A004A1FE3 /* CharacterCellView.swift */,
|
||||
);
|
||||
path = View;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
57055738262C61CF004A1FE3 /* Utils */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
57055739262C61DF004A1FE3 /* NSCharacterSetExtension.swift */,
|
||||
);
|
||||
path = Utils;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
/* End PBXGroup section */
|
||||
|
||||
/* Begin PBXNativeTarget section */
|
||||
|
|
@ -198,6 +231,9 @@
|
|||
files = (
|
||||
5705571D262C5EA1004A1FE3 /* ContentView.swift in Sources */,
|
||||
5705571B262C5EA1004A1FE3 /* FontFaceApp.swift in Sources */,
|
||||
5705572E262C5F8B004A1FE3 /* FontModel.swift in Sources */,
|
||||
5705573A262C61DF004A1FE3 /* NSCharacterSetExtension.swift in Sources */,
|
||||
57055733262C602A004A1FE3 /* CharacterCellView.swift in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -8,12 +8,56 @@
|
|||
import SwiftUI
|
||||
|
||||
struct ContentView: View {
|
||||
|
||||
let columns = [
|
||||
GridItem(.flexible()),
|
||||
GridItem(.flexible()),
|
||||
GridItem(.flexible()),
|
||||
GridItem(.flexible()),
|
||||
GridItem(.flexible()),
|
||||
GridItem(.flexible()),
|
||||
]
|
||||
|
||||
var body: some View {
|
||||
Text("Hello, world!")
|
||||
.padding()
|
||||
ZStack(alignment: .top) {
|
||||
ScrollView {
|
||||
LazyVGrid(columns: columns) {
|
||||
ForEach(fetchFontList(), id: \.self) { characterModel in
|
||||
CharacterCellView(name: "PingFang", characterModel: characterModel)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.padding()
|
||||
.frame(minWidth: 600, idealWidth: 700, minHeight: 400, idealHeight: 800, alignment: .center)
|
||||
.toolbar {
|
||||
ToolbarItem(placement: .primaryAction) {
|
||||
Menu {
|
||||
|
||||
} label: {
|
||||
Image(systemName: "square.and.arrow.up.on.square.fill")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 获取字符集及其 Unicode
|
||||
/// - Returns: StringCharacter
|
||||
func fetchFontList() -> [CharacterModel] {
|
||||
if let name = NSFontManager.shared.availableFontFamilies.first {
|
||||
|
||||
if let font = NSFontManager.shared.font(withFamily: name, traits: .boldFontMask, weight: 1, size: 30) {
|
||||
|
||||
let set = font.coveredCharacterSet as NSCharacterSet
|
||||
|
||||
return set.characters
|
||||
}
|
||||
}
|
||||
|
||||
return []
|
||||
}
|
||||
|
||||
struct ContentView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
ContentView()
|
||||
|
|
|
|||
|
|
@ -0,0 +1,22 @@
|
|||
//
|
||||
// FontModel.swift
|
||||
// FontFace (macOS)
|
||||
//
|
||||
// Created by 吕俊 on 2021/4/18.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
struct FontModel: Hashable {
|
||||
var name: String
|
||||
var characters: [CharacterModel]
|
||||
}
|
||||
|
||||
struct CharacterModel: Hashable {
|
||||
var character: String
|
||||
var unicode: String
|
||||
}
|
||||
|
||||
let mockFontModel = FontModel(name: "PingFang", characters: [mockCharacterModel])
|
||||
|
||||
let mockCharacterModel = CharacterModel(character: "T", unicode: "\u{e638}")
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
//
|
||||
// NSCharacterSetExtension.swift
|
||||
// FontFace (macOS)
|
||||
//
|
||||
// Created by 吕俊 on 2021/4/18.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
extension NSCharacterSet {
|
||||
var characters:[CharacterModel] {
|
||||
var results = [CharacterModel]()
|
||||
for plane:UInt8 in 0...16 {
|
||||
if self.hasMemberInPlane(plane) {
|
||||
let p0 = UInt32(plane) << 16
|
||||
let p1 = (UInt32(plane) + 1) << 16
|
||||
for c:UTF32Char in p0..<p1 {
|
||||
if self.longCharacterIsMember(c) {
|
||||
var c1 = c.littleEndian
|
||||
let s = NSString(bytes: &c1, length: 4, encoding: String.Encoding.utf32LittleEndian.rawValue)!
|
||||
let dataenc = s.data(using: String.Encoding.nonLossyASCII.rawValue)
|
||||
let unicodeValue = String(data: dataenc!, encoding: String.Encoding.utf8) ?? ""
|
||||
|
||||
let v = CharacterModel(character: String(s), unicode: unicodeValue)
|
||||
|
||||
results.append(v)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return results
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
//
|
||||
// CharacterCellView.swift
|
||||
// FontFace (macOS)
|
||||
//
|
||||
// Created by 吕俊 on 2021/4/18.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct CharacterCellView: View {
|
||||
|
||||
var name: String
|
||||
var characterModel: CharacterModel
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .center) {
|
||||
Text(characterModel.character)
|
||||
.font(Font.custom(name, size: 30))
|
||||
.foregroundColor(.red)
|
||||
.padding(.bottom, 3)
|
||||
Text(characterModel.unicode)
|
||||
.font(.body)
|
||||
.foregroundColor(.gray)
|
||||
}
|
||||
.frame(width: 80, height: 80)
|
||||
.padding()
|
||||
}
|
||||
}
|
||||
|
||||
struct FontCellView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
CharacterCellView(name: "PingFang", characterModel: mockCharacterModel)
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue