Skip to content

Commit

Permalink
还原文本转曲
Browse files Browse the repository at this point in the history
  • Loading branch information
more-strive committed Nov 4, 2023
1 parent 0d6c0a9 commit c57627e
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 42 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# yft-design
> 基于 Canvas 的开源版"创客贴",使用 Vue3 + TypeScript + Fabric.js + Pinia + Element-Plus,支持 文字、图片、形状、线条、二维码 、条形码几种最常用的元素类型,每一种元素都拥有高度可编辑能力,缩略图显示,模板,支持导出json,svg, image文件。
<b>体验Demo:[https://yft.design](https://yft.design)</b>
<!-- <b>体验Demo:[https://yft.design](https://yft.design)</b> -->
<b>体验Demo:[https://dromara.org/yft-design](https://dromara.org/yft-design)</b>
<b>体验Demo:[https://more-strive.github.io/design/](https://more-strive.github.io/design/)</b>
![image](doc/background.gif)
Expand Down
25 changes: 0 additions & 25 deletions depoly.sh

This file was deleted.

2 changes: 0 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { createApp } from "vue"
import { createPinia } from "pinia"
import App from "./App.vue"
// import ElementPlus from "element-plus"
import "@/extension/index"

// import "element-plus/theme-chalk/index.css"
import "@icon-park/vue-next/styles/index.css"
import "@/assets/style/global.scss"
import "@/assets/style/font.scss"
Expand Down
12 changes: 12 additions & 0 deletions src/utils/fonts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,16 @@ export const getSupportFonts = (fontNames: SystemFont[]) => {
}
return getDotArray(arial).join('') !== getDotArray(item.value).join('')
})
}

export async function loadFont(fontFamily: string) {
let font
try {
const fonts = await window.queryLocalFonts();
font = fonts.filter(item => item.family === fontFamily)[0]
} catch(e: any) {
console.log(`Cannot query fonts: ${e.message}`)
} finally {
return font
}
}
11 changes: 0 additions & 11 deletions src/utils/localFonts.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ import { FontSizeLibs, LineHeightLibs, CharSpaceLibs } from '@/configs/texts'
import { WEB_FONTS } from '@/configs/fonts'
import { TextboxElement } from '@/types/canvas'
import { FontGroupOption } from '@/types/elements'
import { loadFont } from '@/utils/localFonts'
import { loadFont } from '@/utils/fonts'
import opentype from "opentype.js"
import ElementPosition from '../Components/ElementPosition.vue'
import ElementStroke from '../Components/ElementStroke.vue'
Expand Down Expand Up @@ -347,7 +347,8 @@ const handleElementCurve = async () => {
// ElMessage
let fontElement: opentype.Font | undefined
if (WEB_FONTS.filter(item => item.value === hasFontFamily.value)[0]) {
fontElement = await opentype.load(`/src/assets/fonts/${hasFontFamily.value}.ttf`)
const fontURL = import.meta.env.MODE === 'production' ? `/assets/${hasFontFamily.value}.ttf` : `/src/assets/fonts/${hasFontFamily.value}.ttf`
fontElement = await opentype.load(fontURL)
} else {
const fontData = await loadFont(hasFontFamily.value)
if (!fontData) return
Expand Down
2 changes: 1 addition & 1 deletion src/worker/pdf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { CanvasElement, TextboxElement, ImageElement, Template } from '@/types/c
import { ElementNames } from '@/types/elements'
import { isBase64, getBase64Type, getLinkType } from '@/utils/common'
import { PDFDocument, StandardFonts, rgb, PDFPage, PDFImage } from 'pdf-lib'
import { loadFont } from '@/utils/localFonts'
import { loadFont } from '@/utils/fonts'
import { WEB_FONTS } from '@/configs/fonts'

// self.addEventListener("message", handleMessage);
Expand Down

0 comments on commit c57627e

Please sign in to comment.