forked from ikuaitu/vue-fabric-editor
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: 翻译 * feat: 水印颜色自定义功能 * fix: 修复文字阴影首次绘制为黑色问题
- Loading branch information
1 parent
1e241b2
commit a6130c2
Showing
3 changed files
with
60 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* @Author: June | ||
* @Description: 获取免费字体 | ||
* @Date: 2024-03-24 10:19:05 | ||
* @LastEditors: June | ||
* @LastEditTime: 2024-03-24 11:00:31 | ||
*/ | ||
import FontFaceObserver from 'fontfaceobserver'; | ||
import fontList from '@/assets/fonts/font'; | ||
import axios from 'axios'; | ||
import { Spin, Message } from 'view-ui-plus'; | ||
import { useI18n } from 'vue-i18n'; | ||
|
||
const repoSrc = import.meta.env.APP_REPO; | ||
|
||
const _fontList = ref<any[]>([]); | ||
|
||
export function useFont() { | ||
const { t } = useI18n(); | ||
|
||
const initFont = () => { | ||
if (unref(_fontList).length > 0) return; | ||
axios.get(`${repoSrc}/font/free-font.json`).then((res) => { | ||
_fontList.value = [...Object.entries(res.data).map(([, value]) => value)]; | ||
}); | ||
}; | ||
|
||
const fontsList = computed(() => [...fontList, ...unref(_fontList)]); | ||
|
||
const loadFont = (fontName: string) => { | ||
if (!fontName) return false; | ||
return new Promise((resolve: any) => { | ||
Spin.show(); | ||
const font = new FontFaceObserver(fontName); | ||
font | ||
.load(null, 150000) | ||
.then(() => { | ||
Message.success(t('alert.loading_fonts_success')); | ||
Spin.hide(); | ||
resolve(true); | ||
}) | ||
.catch(() => { | ||
Message.error(t('alert.loading_fonts_failed')); | ||
Spin.hide(); | ||
resolve(false); | ||
}); | ||
}); | ||
}; | ||
|
||
onMounted(initFont); | ||
return { | ||
initFont, | ||
fontsList, | ||
loadFont, | ||
}; | ||
} |