fix(ios): display current theme font in image sharing
This commit is contained in:
1 parent
0fa1b21315
commit
d1492c15e9
3 files changed
+27
-3
No files matched your search
@@ -27,6 +27,17 @@ enum NoteImageFontCatalog {
|
||||
(id: "spacegrotesk", zh: "Space Grotesk", en: "Space Grotesk"),
|
||||
(id: "jetbrains", zh: "JetBrains Mono", en: "JetBrains Mono"),
|
||||
]
|
||||
static let templateLabels: [String: (zh: String, en: String, ja: String, pl: String)] = [
|
||||
"glass": (zh: "MiSans", en: "MiSans", ja: "MiSans", pl: "MiSans"),
|
||||
"quote": (zh: "汇文明朝体", en: "Huiwen Mincho", ja: "匯文明朝体", pl: "Huiwen Mincho"),
|
||||
"book": (zh: "思源宋体", en: "Source Han Serif", ja: "源ノ明朝", pl: "Source Han Serif"),
|
||||
"memo": (zh: "MiSans", en: "MiSans", ja: "MiSans", pl: "MiSans"),
|
||||
"bento": (zh: "MiSans", en: "MiSans", ja: "MiSans", pl: "MiSans"),
|
||||
"black-sun": (zh: "Geist Mono / MiSans", en: "Geist Mono / MiSans", ja: "Geist Mono / MiSans", pl: "Geist Mono / MiSans"),
|
||||
"frame": (zh: "思源宋体", en: "Source Han Serif", ja: "源ノ明朝", pl: "Source Han Serif"),
|
||||
"handwritten": (zh: "龙藏体", en: "Long Cang", ja: "Long Cang", pl: "Long Cang"),
|
||||
"code": (zh: "Geist Mono", en: "Geist Mono", ja: "Geist Mono", pl: "Geist Mono"),
|
||||
]
|
||||
}
|
||||
// END GENERATED FONT CATALOG
|
||||
import Observation
|
||||
|
||||
@@ -5,7 +5,7 @@ import WebKit
|
||||
enum NoteImageFontPickerOptions {
|
||||
static func choices(_ preferences: PreferencesStore) -> [(id: String, label: String)] {
|
||||
[
|
||||
("auto", preferences.t("跟随主题", en: "Follow Theme", pl: "Zgodnie z motywem")),
|
||||
("auto", preferences.t("跟随主题", en: "Follow Theme", pl: "Zgodnie z motywem") + " (" + themeLabel(preferences) + ")"),
|
||||
("kai", preferences.t("文楷手书", en: "Handwritten Kai", pl: "Pismo odręczne Kai")),
|
||||
("serif", preferences.t("文艺衬线", en: "Serif", pl: "Szeryfowa")),
|
||||
("sans", preferences.t("现代无衬线", en: "Sans", pl: "Bezszeryfowa")),
|
||||
@@ -13,8 +13,14 @@ enum NoteImageFontPickerOptions {
|
||||
] + NoteImageFontCatalog.choices.map { ($0.id, preferences.t($0.zh, en: $0.en, pl: $0.en)) }
|
||||
}
|
||||
|
||||
private static func themeLabel(_ preferences: PreferencesStore) -> String {
|
||||
guard let labels = NoteImageFontCatalog.templateLabels[preferences.noteImageShare.theme] else { return "" }
|
||||
return preferences.t(labels.zh, en: labels.en, ja: labels.ja, pl: labels.pl)
|
||||
}
|
||||
|
||||
static func label(_ preferences: PreferencesStore) -> String {
|
||||
choices(preferences).first { $0.id == preferences.noteImageShare.fontStyle }?.label ?? ""
|
||||
if preferences.noteImageShare.fontStyle == "auto" { return themeLabel(preferences) }
|
||||
return choices(preferences).first { $0.id == preferences.noteImageShare.fontStyle }?.label ?? ""
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
// Run with Bun after changing the shared directory; Swift uses a generated projection.
|
||||
import { readFile, writeFile } from 'node:fs/promises';
|
||||
import { FONT_CATALOG, FONT_IDS } from '../packages/shared/src/font-catalog.ts';
|
||||
import { NOTE_IMAGE_TEMPLATE_TYPOGRAPHY } from '../packages/shared/src/note-image-card.ts';
|
||||
import { zhCN, enUS, ja, pl } from '../packages/shared/src/i18n/index.ts';
|
||||
const file = new URL('../apps/ios/EdgeEver/Data/Preferences/PreferencesStore.swift', import.meta.url);
|
||||
const begin = '// BEGIN GENERATED FONT CATALOG — bun scripts/sync-font-catalog.mjs';
|
||||
const end = '// END GENERATED FONT CATALOG';
|
||||
@@ -9,7 +11,12 @@ const rows = FONT_IDS.map(id => {
|
||||
const font = FONT_CATALOG[id];
|
||||
return ` (id: ${JSON.stringify(id)}, zh: ${JSON.stringify(font.zh)}, en: ${JSON.stringify(font.en)}),`;
|
||||
}).join('\n');
|
||||
const generated = `${begin}\nenum NoteImageFontCatalog {\n static let choices: [(id: String, zh: String, en: String)] = [\n${rows}\n ]\n}\n${end}`;
|
||||
const templateRows = Object.entries(NOTE_IMAGE_TEMPLATE_TYPOGRAPHY).map(([theme, preset]) => {
|
||||
const labels = [zhCN, enUS, ja, pl].map(locale =>
|
||||
JSON.stringify(preset.body.map(font => locale.editor.imageShare.templateFonts[font]).join(' / ')));
|
||||
return ` ${JSON.stringify(theme)}: (zh: ${labels[0]}, en: ${labels[1]}, ja: ${labels[2]}, pl: ${labels[3]}),`;
|
||||
}).join('\n');
|
||||
const generated = `${begin}\nenum NoteImageFontCatalog {\n static let choices: [(id: String, zh: String, en: String)] = [\n${rows}\n ]\n static let templateLabels: [String: (zh: String, en: String, ja: String, pl: String)] = [\n${templateRows}\n ]\n}\n${end}`;
|
||||
const next = text.includes(begin)
|
||||
? text.slice(0, text.indexOf(begin)) + generated + text.slice(text.indexOf(end) + end.length)
|
||||
: text.replace('import Foundation', `import Foundation\n\n${generated}`);
|
||||
|
||||
Reference in new issue
Block a user