Skip to content

Commit

Permalink
Added custom chinese font (#1057)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
michalrentka and mvasilak committed Jan 16, 2025
1 parent 5928649 commit 6afc67a
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,5 @@ fastlane/test_output
bundled/translators
bundled/styles
bundled/locales
bundled/note_editor
bundled/note_editor
fonts
4 changes: 4 additions & 0 deletions Zotero.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
618404262A4456A9005AAF22 /* IdentifierLookupController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 618404252A4456A9005AAF22 /* IdentifierLookupController.swift */; };
618D83E72BAAC88C00E7966B /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = 618D83E62BAAC88C00E7966B /* PrivacyInfo.xcprivacy */; };
618D83E82BAAC88C00E7966B /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = 618D83E62BAAC88C00E7966B /* PrivacyInfo.xcprivacy */; };
61975C422D38E6E8005BB41A /* fonts in Resources */ = {isa = PBXBuildFile; fileRef = 61975C412D38E6E8005BB41A /* fonts */; };
61A0C8472B8F669C0048FF92 /* PSPDFKitUI+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61A0C8462B8F669B0048FF92 /* PSPDFKitUI+Extensions.swift */; };
61ABA7512A6137D1002A4219 /* ShareableImage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61ABA7502A6137D1002A4219 /* ShareableImage.swift */; };
61BD13952A5831EF008A0704 /* TextKit1TextView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61BD13942A5831EF008A0704 /* TextKit1TextView.swift */; };
Expand Down Expand Up @@ -1307,6 +1308,7 @@
61639F842AE03B8500026003 /* InstantPresenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstantPresenter.swift; sourceTree = "<group>"; };
618404252A4456A9005AAF22 /* IdentifierLookupController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IdentifierLookupController.swift; sourceTree = "<group>"; };
618D83E62BAAC88C00E7966B /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = PrivacyInfo.xcprivacy; sourceTree = "<group>"; };
61975C412D38E6E8005BB41A /* fonts */ = {isa = PBXFileReference; lastKnownFileType = folder; path = fonts; sourceTree = "<group>"; };
61A0C8462B8F669B0048FF92 /* PSPDFKitUI+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "PSPDFKitUI+Extensions.swift"; sourceTree = "<group>"; };
61ABA7502A6137D1002A4219 /* ShareableImage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShareableImage.swift; sourceTree = "<group>"; };
61BD13942A5831EF008A0704 /* TextKit1TextView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextKit1TextView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2843,6 +2845,7 @@
isa = PBXGroup;
children = (
B3F6415E2A28B1EF00A78CB0 /* ci_scripts */,
61975C412D38E6E8005BB41A /* fonts */,
B30BA8C3255D415600361D25 /* Bundled */,
B32A495A2A44730C00080945 /* licenses */,
B30D59572206F60400884C4A /* Zotero */,
Expand Down Expand Up @@ -4511,6 +4514,7 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
61975C422D38E6E8005BB41A /* fonts in Resources */,
B3593F33241A61C700760E20 /* ItemDetailNoteContentView.xib in Resources */,
618D83E72BAAC88C00E7966B /* PrivacyInfo.xcprivacy in Resources */,
B32A273D254841B80081E061 /* CreatorEditViewController.xib in Resources */,
Expand Down
10 changes: 9 additions & 1 deletion Zotero/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,15 @@ extension AppDelegate: SceneActivityCounter {
extension AppDelegate: UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
if let key = Licenses.shared.pspdfkitKey {
PSPDFKit.SDK.setLicenseKey(key)
let additionalFontDirectory = Bundle.main.bundleURL.appendingPathComponent("fonts", isDirectory: true).path
let options: [SDK.Setting: Any] = [.additionalFontDirectories: [additionalFontDirectory]]
PSPDFKit.SDK.setLicenseKey(key, options: options)
}
DDLogInfo("AppDelegate: clearPSPDFKitCacheGuard: \(Defaults.shared.clearPSPDFKitCacheGuard); currentClearPSPDFKitCacheGuard: \(Defaults.currentClearPSPDFKitCacheGuard)")
if Defaults.shared.clearPSPDFKitCacheGuard < Defaults.currentClearPSPDFKitCacheGuard {
PSPDFKit.SDK.shared.cache.clear()
DDLogInfo("AppDelegate: did clear PSPDFKit cache")
Defaults.shared.clearPSPDFKitCacheGuard = Defaults.currentClearPSPDFKitCacheGuard
}
PSPDFKit.SDK.shared.styleManager.setLastUsedValue(AnnotationsConfig.imageAnnotationLineWidth,
forProperty: "lineWidth",
Expand Down
5 changes: 5 additions & 0 deletions Zotero/Models/Defaults.swift
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,11 @@ final class Defaults {
@UserDefault(key: "DidPerformFullSyncFix", defaultValue: true)
var didPerformFullSyncFix: Bool

// Increment currentClearPSPDFKitCacheGuard by 1, whenever the upcoming release should clear the PSPDFKit cache.
static let currentClearPSPDFKitCacheGuard = 1
@UserDefault(key: "ClearPSPDFKitCacheGuard", defaultValue: currentClearPSPDFKitCacheGuard - 1)
var clearPSPDFKitCacheGuard: Int

// MARK: - Actions

func reset() {
Expand Down
16 changes: 16 additions & 0 deletions ci_scripts/ci_post_clone.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,22 @@

set -euo pipefail

# Download missing fonts (remove if fixed in PSPDFKit)
font_url="https://raw.githubusercontent.com/notofonts/noto-cjk/refs/heads/main/google-fonts/NotoSansSC%5Bwght%5D.ttf"
output_directory="fonts"
mkdir -p $output_directory
output_filename="NotoSansSC[wght].ttf"
output_path="$output_directory/$output_filename"
curl -fL -o "$output_path" $font_url || { echo "Font download failed"; exit 1; }
echo "Verifying downloaded font file..."
if file "$output_path" | grep -q "TrueType Font data"; then
echo "Font file verification passed: $output_path is a TTF file."
else
echo "Font file verification failed: $output_path is not a TTF file."
rm -f "$output_path"
exit 1
fi

which swiftgen || HOMEBREW_NO_AUTO_UPDATE=1 HOMEBREW_NO_INSTALL_CLEANUP=1 brew install swiftgen
which swiftlint || HOMEBREW_NO_AUTO_UPDATE=1 HOMEBREW_NO_INSTALL_CLEANUP=1 brew install swiftlint
which openssl || HOMEBREW_NO_AUTO_UPDATE=1 HOMEBREW_NO_INSTALL_CLEANUP=1 brew install openssl
Expand Down

0 comments on commit 6afc67a

Please sign in to comment.