Skip to content

Commit 6afc67a

Browse files
Added custom chinese font (#1057)
* Added custom chinese font * Fix fonts folder copying * Add clear PSPDFKit cache guard to do so when incremented --------- Co-authored-by: Miltiadis Vasilakis <[email protected]>
1 parent 5928649 commit 6afc67a

File tree

5 files changed

+36
-2
lines changed

5 files changed

+36
-2
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,5 @@ fastlane/test_output
8080
bundled/translators
8181
bundled/styles
8282
bundled/locales
83-
bundled/note_editor
83+
bundled/note_editor
84+
fonts

Zotero.xcodeproj/project.pbxproj

+4
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
618404262A4456A9005AAF22 /* IdentifierLookupController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 618404252A4456A9005AAF22 /* IdentifierLookupController.swift */; };
4040
618D83E72BAAC88C00E7966B /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = 618D83E62BAAC88C00E7966B /* PrivacyInfo.xcprivacy */; };
4141
618D83E82BAAC88C00E7966B /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = 618D83E62BAAC88C00E7966B /* PrivacyInfo.xcprivacy */; };
42+
61975C422D38E6E8005BB41A /* fonts in Resources */ = {isa = PBXBuildFile; fileRef = 61975C412D38E6E8005BB41A /* fonts */; };
4243
61A0C8472B8F669C0048FF92 /* PSPDFKitUI+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61A0C8462B8F669B0048FF92 /* PSPDFKitUI+Extensions.swift */; };
4344
61ABA7512A6137D1002A4219 /* ShareableImage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61ABA7502A6137D1002A4219 /* ShareableImage.swift */; };
4445
61BD13952A5831EF008A0704 /* TextKit1TextView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61BD13942A5831EF008A0704 /* TextKit1TextView.swift */; };
@@ -1307,6 +1308,7 @@
13071308
61639F842AE03B8500026003 /* InstantPresenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstantPresenter.swift; sourceTree = "<group>"; };
13081309
618404252A4456A9005AAF22 /* IdentifierLookupController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IdentifierLookupController.swift; sourceTree = "<group>"; };
13091310
618D83E62BAAC88C00E7966B /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = PrivacyInfo.xcprivacy; sourceTree = "<group>"; };
1311+
61975C412D38E6E8005BB41A /* fonts */ = {isa = PBXFileReference; lastKnownFileType = folder; path = fonts; sourceTree = "<group>"; };
13101312
61A0C8462B8F669B0048FF92 /* PSPDFKitUI+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "PSPDFKitUI+Extensions.swift"; sourceTree = "<group>"; };
13111313
61ABA7502A6137D1002A4219 /* ShareableImage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShareableImage.swift; sourceTree = "<group>"; };
13121314
61BD13942A5831EF008A0704 /* TextKit1TextView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextKit1TextView.swift; sourceTree = "<group>"; };
@@ -2843,6 +2845,7 @@
28432845
isa = PBXGroup;
28442846
children = (
28452847
B3F6415E2A28B1EF00A78CB0 /* ci_scripts */,
2848+
61975C412D38E6E8005BB41A /* fonts */,
28462849
B30BA8C3255D415600361D25 /* Bundled */,
28472850
B32A495A2A44730C00080945 /* licenses */,
28482851
B30D59572206F60400884C4A /* Zotero */,
@@ -4511,6 +4514,7 @@
45114514
isa = PBXResourcesBuildPhase;
45124515
buildActionMask = 2147483647;
45134516
files = (
4517+
61975C422D38E6E8005BB41A /* fonts in Resources */,
45144518
B3593F33241A61C700760E20 /* ItemDetailNoteContentView.xib in Resources */,
45154519
618D83E72BAAC88C00E7966B /* PrivacyInfo.xcprivacy in Resources */,
45164520
B32A273D254841B80081E061 /* CreatorEditViewController.xib in Resources */,

Zotero/AppDelegate.swift

+9-1
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,15 @@ extension AppDelegate: SceneActivityCounter {
210210
extension AppDelegate: UIApplicationDelegate {
211211
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
212212
if let key = Licenses.shared.pspdfkitKey {
213-
PSPDFKit.SDK.setLicenseKey(key)
213+
let additionalFontDirectory = Bundle.main.bundleURL.appendingPathComponent("fonts", isDirectory: true).path
214+
let options: [SDK.Setting: Any] = [.additionalFontDirectories: [additionalFontDirectory]]
215+
PSPDFKit.SDK.setLicenseKey(key, options: options)
216+
}
217+
DDLogInfo("AppDelegate: clearPSPDFKitCacheGuard: \(Defaults.shared.clearPSPDFKitCacheGuard); currentClearPSPDFKitCacheGuard: \(Defaults.currentClearPSPDFKitCacheGuard)")
218+
if Defaults.shared.clearPSPDFKitCacheGuard < Defaults.currentClearPSPDFKitCacheGuard {
219+
PSPDFKit.SDK.shared.cache.clear()
220+
DDLogInfo("AppDelegate: did clear PSPDFKit cache")
221+
Defaults.shared.clearPSPDFKitCacheGuard = Defaults.currentClearPSPDFKitCacheGuard
214222
}
215223
PSPDFKit.SDK.shared.styleManager.setLastUsedValue(AnnotationsConfig.imageAnnotationLineWidth,
216224
forProperty: "lineWidth",

Zotero/Models/Defaults.swift

+5
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,11 @@ final class Defaults {
175175
@UserDefault(key: "DidPerformFullSyncFix", defaultValue: true)
176176
var didPerformFullSyncFix: Bool
177177

178+
// Increment currentClearPSPDFKitCacheGuard by 1, whenever the upcoming release should clear the PSPDFKit cache.
179+
static let currentClearPSPDFKitCacheGuard = 1
180+
@UserDefault(key: "ClearPSPDFKitCacheGuard", defaultValue: currentClearPSPDFKitCacheGuard - 1)
181+
var clearPSPDFKitCacheGuard: Int
182+
178183
// MARK: - Actions
179184

180185
func reset() {

ci_scripts/ci_post_clone.sh

+16
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,22 @@
88

99
set -euo pipefail
1010

11+
# Download missing fonts (remove if fixed in PSPDFKit)
12+
font_url="https://raw.githubusercontent.com/notofonts/noto-cjk/refs/heads/main/google-fonts/NotoSansSC%5Bwght%5D.ttf"
13+
output_directory="fonts"
14+
mkdir -p $output_directory
15+
output_filename="NotoSansSC[wght].ttf"
16+
output_path="$output_directory/$output_filename"
17+
curl -fL -o "$output_path" $font_url || { echo "Font download failed"; exit 1; }
18+
echo "Verifying downloaded font file..."
19+
if file "$output_path" | grep -q "TrueType Font data"; then
20+
echo "Font file verification passed: $output_path is a TTF file."
21+
else
22+
echo "Font file verification failed: $output_path is not a TTF file."
23+
rm -f "$output_path"
24+
exit 1
25+
fi
26+
1127
which swiftgen || HOMEBREW_NO_AUTO_UPDATE=1 HOMEBREW_NO_INSTALL_CLEANUP=1 brew install swiftgen
1228
which swiftlint || HOMEBREW_NO_AUTO_UPDATE=1 HOMEBREW_NO_INSTALL_CLEANUP=1 brew install swiftlint
1329
which openssl || HOMEBREW_NO_AUTO_UPDATE=1 HOMEBREW_NO_INSTALL_CLEANUP=1 brew install openssl

0 commit comments

Comments
 (0)