From 96768b68e6cf697403502e711a0333ba9613325d Mon Sep 17 00:00:00 2001 From: Zhuowei Zhang Date: Tue, 27 Dec 2022 20:45:28 -0500 Subject: [PATCH] overwrite PingFang.ttc --- WDBFontOverwrite/ContentView.swift | 22 ++++++++++++++++++++++ repackfonts/make_noto_serif_sc.sh | 24 ++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100755 repackfonts/make_noto_serif_sc.sh diff --git a/WDBFontOverwrite/ContentView.swift b/WDBFontOverwrite/ContentView.swift index 0969942..e2cbec7 100644 --- a/WDBFontOverwrite/ContentView.swift +++ b/WDBFontOverwrite/ContentView.swift @@ -86,6 +86,28 @@ struct ContentView: View { Text("Import custom emoji") }.padding(8) } + Button(action: { + message = "Running" + overwriteWithCustomFont( + name: "CustomPingFang.woff2", + targetName: "/System/Library/Fonts/LanguageSupport/PingFang.ttc" + ) { + message = $0 + } + }) { + Text("Custom PingFang.ttc") + }.padding(8) + Button(action: { + message = "Importing" + importCustomFont(name: "CustomPingFang.woff2") { + message = $0 + } + }) { + Text("Import custom PingFang.ttc") + }.padding(8) + Text( + "Custom fonts require font files that are ported for iOS.\nSee https://github.com/zhuowei/WDBFontOverwrite for details." + ).font(.system(size: 12)) } } } diff --git a/repackfonts/make_noto_serif_sc.sh b/repackfonts/make_noto_serif_sc.sh new file mode 100755 index 0000000..cf7cb71 --- /dev/null +++ b/repackfonts/make_noto_serif_sc.sh @@ -0,0 +1,24 @@ +#!/bin/bash +# this isn't very usable since there's no fallback font for Chinese, so bold fonts become blank squares +# this is for demo only +set -e +rm -rf PreviewFonts XmlFonts XmlFontsRenamed RecompiledFonts RepackedFonts || true +mkdir -p PreviewFonts XmlFonts XmlFontsRenamed RecompiledFonts RepackedFonts || true + +IFS=" +" +fonts="OriginalFonts/Noto_Serif_SC/NotoSerifSC-Regular.otf:NotoSerifSC-Regular" +for fontandname in $fonts +do + font="$(echo "$fontandname" | cut -d ":" -f 1)" + fontpsname="$(echo "$fontandname" | cut -d ":" -f 2)" + fontname="$(basename -s .otf "$(basename -s .ttf "$font")")" + + cp "$font" PreviewFonts/ + + ttx -d XmlFonts "$font" + sed -e "s/$fontpsname/.PingFangSC-Regular/g" "XmlFonts/$fontname.ttx" > "XmlFontsRenamed/$fontname.ttx" + ttx -d RecompiledFonts --flavor woff2 "XmlFontsRenamed/$fontname.ttx" + + ./BrotliPadding "RecompiledFonts/$fontname.woff2" "RepackedFonts/$fontname.woff2" +done