Skip to content

Commit 20b7ec1

Browse files
authored
Merge pull request #634 from imsyy/dev-perf
🎈 perf: 完善歌词字体自定义
2 parents 2e0dec3 + e42787b commit 20b7ec1

6 files changed

Lines changed: 141 additions & 88 deletions

File tree

src/components/Player/MainAMLyric.vue

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
'--amll-lyric-player-font-size': settingStore.lyricFontSize + 'px',
2121
'--ja-font-family':
2222
settingStore.japaneseLyricFont !== 'follow' ? settingStore.japaneseLyricFont : '',
23+
'--en-font-family':
24+
settingStore.englishLyricFont !== 'follow' ? settingStore.englishLyricFont : '',
25+
'--ko-font-family':
26+
settingStore.koreanLyricFont !== 'follow' ? settingStore.koreanLyricFont : '',
2327
'font-weight': settingStore.lyricFontBold ? 'bold' : 'normal',
2428
'font-family': settingStore.LyricFont !== 'follow' ? settingStore.LyricFont : '',
2529
}"
@@ -157,10 +161,15 @@ onBeforeUnmount(() => {
157161
}
158162
}
159163
}
160-
161164
:lang(ja) {
162165
font-family: var(--ja-font-family);
163166
}
167+
:lang(en) {
168+
font-family: var(--en-font-family);
169+
}
170+
:lang(ko) {
171+
font-family: var(--ko-font-family);
172+
}
164173
}
165174
166175
.lyric-loading {

src/components/Player/MainLyric.vue

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
'--lrc-bold': settingStore.lyricFontBold ? 'bold' : 'normal',
88
'--ja-font-family':
99
settingStore.japaneseLyricFont !== 'follow' ? settingStore.japaneseLyricFont : '',
10+
'--en-font-family':
11+
settingStore.englishLyricFont !== 'follow' ? settingStore.englishLyricFont : '',
12+
'--ko-font-family':
13+
settingStore.koreanLyricFont !== 'follow' ? settingStore.koreanLyricFont : '',
1014
'font-family': settingStore.LyricFont !== 'follow' ? settingStore.LyricFont : '',
1115
cursor: statusStore.playerMetaShow ? 'auto' : 'none',
1216
}"
@@ -447,6 +451,12 @@ onBeforeUnmount(() => {
447451
&:lang(ja) {
448452
font-family: var(--ja-font-family);
449453
}
454+
&:lang(en) {
455+
font-family: var(--en-font-family);
456+
}
457+
&:lang(ko) {
458+
font-family: var(--ko-font-family);
459+
}
450460
}
451461
.tran {
452462
margin-top: 8px;

src/components/Setting/GeneralSetting.vue

Lines changed: 8 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -213,62 +213,6 @@
213213
/>
214214
</n-flex>
215215
</n-card>
216-
<n-card class="set-item">
217-
<div class="label">
218-
<n-text class="name">歌词区域字体</n-text>
219-
<n-text class="tip" :depth="3"> 是否独立更改歌词区域字体 </n-text>
220-
</div>
221-
<n-flex>
222-
<Transition name="fade" mode="out-in">
223-
<n-button
224-
v-if="settingStore.LyricFont !== 'follow'"
225-
type="primary"
226-
strong
227-
secondary
228-
@click="settingStore.LyricFont = 'follow'"
229-
>
230-
恢复默认
231-
</n-button>
232-
</Transition>
233-
<n-select
234-
v-model:value="settingStore.LyricFont"
235-
:options="[
236-
{ label: '跟随全局', value: 'follow' },
237-
...allFontsData.filter((v) => v.value !== 'default'),
238-
]"
239-
class="set"
240-
filterable
241-
/>
242-
</n-flex>
243-
</n-card>
244-
<n-card class="set-item">
245-
<div class="label">
246-
<n-text class="name">日语歌词字体</n-text>
247-
<n-text class="tip" :depth="3"> 是否在歌词为日语时单独设置字体 </n-text>
248-
</div>
249-
<n-flex>
250-
<Transition name="fade" mode="out-in">
251-
<n-button
252-
v-if="settingStore.japaneseLyricFont !== 'follow'"
253-
type="primary"
254-
strong
255-
secondary
256-
@click="settingStore.japaneseLyricFont = 'follow'"
257-
>
258-
恢复默认
259-
</n-button>
260-
</Transition>
261-
<n-select
262-
v-model:value="settingStore.japaneseLyricFont"
263-
:options="[
264-
{ label: '跟随全局', value: 'follow' },
265-
...allFontsData.filter((v) => v.value !== 'default'),
266-
]"
267-
class="set"
268-
filterable
269-
/>
270-
</n-flex>
271-
</n-card>
272216
<n-card class="set-item">
273217
<div class="label">
274218
<n-text class="name">关闭软件时</n-text>
@@ -322,7 +266,12 @@
322266
该协议通常用于官方网页端唤起官方客户端, 启用后可能导致官方客户端无法被唤起
323267
</n-text>
324268
</div>
325-
<n-switch v-model:value="settingStore.registryProtocol.orpheus" class="set" :round="false" @update:value="orpheusChange" />
269+
<n-switch
270+
v-model:value="settingStore.registryProtocol.orpheus"
271+
class="set"
272+
:round="false"
273+
@update:value="orpheusChange"
274+
/>
326275
</n-card>
327276
<n-card class="set-item">
328277
<div class="label">
@@ -448,12 +397,12 @@ const modeChange = (val: boolean) => {
448397
449398
// 全局着色更改
450399
const themeGlobalColorChange = (val: boolean) => {
451-
if (val) getCoverColor(musicStore.songCover);
400+
if (val) getCoverColor(musicStore.songCover);
452401
};
453402
454403
// 注册或取消注册协议
455404
const orpheusChange = async (isRegistry: boolean) => {
456-
sendRegisterProtocol("orpheus", isRegistry)
405+
sendRegisterProtocol("orpheus", isRegistry);
457406
};
458407
459408
onMounted(() => {

src/components/Setting/LyricsSetting.vue

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,64 @@
119119
</n-input-number>
120120
</n-flex>
121121
</n-card>
122+
<n-card class="set-item">
123+
<div class="label">
124+
<n-text class="name">歌词区域字体</n-text>
125+
<n-text class="tip" :depth="3"> 是否独立更改歌词区域字体 </n-text>
126+
</div>
127+
<n-flex>
128+
<Transition name="fade" mode="out-in">
129+
<n-button
130+
v-if="settingStore.LyricFont !== 'follow'"
131+
type="primary"
132+
strong
133+
secondary
134+
@click="settingStore.LyricFont = 'follow'"
135+
>
136+
恢复默认
137+
</n-button>
138+
</Transition>
139+
<n-select
140+
v-model:value="settingStore.LyricFont"
141+
:options="[
142+
{ label: '跟随全局', value: 'follow' },
143+
...allFontsData.filter((v) => v.value !== 'default'),
144+
]"
145+
class="set"
146+
filterable
147+
/>
148+
</n-flex>
149+
</n-card>
150+
<n-collapse-transition :show="settingStore.LyricFont !== 'follow'">
151+
<n-card v-for="item in languageFontSettings" :key="item.key" class="set-item">
152+
<div class="label">
153+
<n-text class="name">{{ item.name }}歌词字体</n-text>
154+
<n-text class="tip" :depth="3"> {{ item.tip }} </n-text>
155+
</div>
156+
<n-flex>
157+
<Transition name="fade" mode="out-in">
158+
<n-button
159+
v-if="settingStore[item.key] !== 'follow'"
160+
type="primary"
161+
strong
162+
secondary
163+
@click="settingStore[item.key] = 'follow'"
164+
>
165+
恢复默认
166+
</n-button>
167+
</Transition>
168+
<n-select
169+
v-model:value="settingStore[item.key]"
170+
:options="[
171+
{ label: '跟随全局', value: 'follow' },
172+
...allFontsData.filter((v) => v.value !== 'default'),
173+
]"
174+
class="set"
175+
filterable
176+
/>
177+
</n-flex>
178+
</n-card>
179+
</n-collapse-transition>
122180
<n-card class="set-item">
123181
<div class="label">
124182
<n-text class="name">歌词字体加粗</n-text>
@@ -649,6 +707,25 @@ const restoreDesktopLyricConfig = () => {
649707
}
650708
};
651709
710+
// 语言字体配置
711+
const languageFontSettings = [
712+
{
713+
name: "英语",
714+
key: "englishLyricFont" as const,
715+
tip: "是否在歌词为英语时单独设置字体",
716+
},
717+
{
718+
name: "日语",
719+
key: "japaneseLyricFont" as const,
720+
tip: "是否在歌词为日语时单独设置字体",
721+
},
722+
{
723+
name: "韩语",
724+
key: "koreanLyricFont" as const,
725+
tip: "是否在歌词为韩语时单独设置字体",
726+
},
727+
];
728+
652729
// 获取全部系统字体
653730
const getAllSystemFonts = async () => {
654731
const allFonts = await window.electron.ipcRenderer.invoke("get-all-fonts");

src/stores/setting.ts

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@ export interface SettingState {
1212
themeMode: "light" | "dark" | "auto";
1313
/** 主题类别 */
1414
themeColorType:
15-
| "default"
16-
| "orange"
17-
| "blue"
18-
| "pink"
19-
| "brown"
20-
| "indigo"
21-
| "green"
22-
| "purple"
23-
| "yellow"
24-
| "teal"
25-
| "custom";
15+
| "default"
16+
| "orange"
17+
| "blue"
18+
| "pink"
19+
| "brown"
20+
| "indigo"
21+
| "green"
22+
| "purple"
23+
| "yellow"
24+
| "teal"
25+
| "custom";
2626
/** 主题自定义颜色 */
2727
themeCustomColor: string;
2828
/** 全局着色 */
@@ -35,6 +35,10 @@ export interface SettingState {
3535
LyricFont: "follow" | string;
3636
/** 日语歌词字体 */
3737
japaneseLyricFont: "follow" | string;
38+
/** 英语歌词字体 */
39+
englishLyricFont: "follow" | string;
40+
/** 韩语歌词字体 */
41+
koreanLyricFont: "follow" | string;
3842
/** 隐藏 VIP 标签 */
3943
showCloseAppTip: boolean;
4044
/** 关闭应用方式 */
@@ -99,14 +103,14 @@ export interface SettingState {
99103
proxyPort: number;
100104
/** 歌曲音质 */
101105
songLevel:
102-
| "standard"
103-
| "higher"
104-
| "exhigh"
105-
| "lossless"
106-
| "hires"
107-
| "jyeffect"
108-
| "sky"
109-
| "jymaster";
106+
| "standard"
107+
| "higher"
108+
| "exhigh"
109+
| "lossless"
110+
| "hires"
111+
| "jyeffect"
112+
| "sky"
113+
| "jymaster";
110114
/** 播放设备 */
111115
playDevice: "default" | string;
112116
/** 自动播放 */
@@ -259,6 +263,8 @@ export const useSettingStore = defineStore("setting", {
259263
globalFont: "default",
260264
LyricFont: "follow",
261265
japaneseLyricFont: "follow",
266+
englishLyricFont: "follow",
267+
koreanLyricFont: "follow",
262268
hideVipTag: false,
263269
showSearchHistory: true,
264270
menuShowCover: true,
@@ -426,12 +432,11 @@ export const useSettingStore = defineStore("setting", {
426432
}
427433
window.$message.info(
428434
`已切换至
429-
${
430-
this.themeMode === "auto"
431-
? "跟随系统"
432-
: this.themeMode === "light"
433-
? "浅色模式"
434-
: "深色模式"
435+
${this.themeMode === "auto"
436+
? "跟随系统"
437+
: this.themeMode === "light"
438+
? "浅色模式"
439+
: "深色模式"
435440
}`,
436441
{
437442
showIcon: false,

src/utils/format.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,11 +277,14 @@ const getCoverSizeUrl = (url: string, size: number | null = null) => {
277277
* @param lyric 歌词内容
278278
* @returns 语言代码("ja" | "zh-CN" | "en")
279279
*/
280-
export const getLyricLanguage = (lyric: string): string => {
280+
export const getLyricLanguage = (lyric: string): "ja" | "ko" | "zh-CN" | "en" => {
281+
if (!lyric || typeof lyric !== "string") return "en";
281282
// 判断日语 根据平假名和片假名
282-
if (/[\u3040-\u309f\u30a0-\u30ff]/.test(lyric)) return "ja";
283+
if (/[\u3040-\u309F\u30A0-\u30FF]/.test(lyric)) return "ja";
284+
// 判断韩语 根据韩文音节
285+
if (/[\uAC00-\uD7AF]/.test(lyric)) return "ko";
283286
// 判断简体中文 根据中日韩统一表意文字基本区
284-
if (/[\u4e00-\u9fa5]/.test(lyric)) return "zh-CN";
287+
if (/[\u4E00-\u9FFF]/.test(lyric)) return "zh-CN";
285288
// 默认英语
286289
return "en";
287290
};

0 commit comments

Comments
 (0)