Добавил динамическую загрузку онлайн шрифтов

This commit is contained in:
Book Pauk
2019-01-25 00:03:40 +07:00
parent b181a602dc
commit 0d48954e7b
3 changed files with 20 additions and 4 deletions

View File

@@ -24,6 +24,7 @@
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
import Vue from 'vue'; import Vue from 'vue';
import Component from 'vue-class-component'; import Component from 'vue-class-component';
import {loadCSS} from 'fg-loadcss';
import _ from 'lodash'; import _ from 'lodash';
import {sleep} from '../../../share/utils'; import {sleep} from '../../../share/utils';
@@ -170,6 +171,7 @@ class TextPage extends Vue {
ReaderDefault: 0, ReaderDefault: 0,
Roboto: 0, Roboto: 0,
OpenSans: 0, OpenSans: 0,
XoloniumRegular: 0,
} }
this.fontList = []; this.fontList = [];
for (let fontName in this.fontShifts) for (let fontName in this.fontShifts)
@@ -180,8 +182,8 @@ class TextPage extends Vue {
this.backgroundColor = '#478355'; this.backgroundColor = '#478355';
this.fontStyle = '';// 'bold','italic' this.fontStyle = '';// 'bold','italic'
this.fontSize = 33;// px this.fontSize = 33;// px
this.fontName = 'ReaderDefault'; this.fontName = 'XoloniumRegular';
this.fontCss = ''; this.fontCssUrl = 'https://fontlibrary.org/face/xolonium';
this.lineInterval = 7;// px, межстрочный интервал this.lineInterval = 7;// px, межстрочный интервал
this.textAlignJustify = true;// выравнивание по ширине this.textAlignJustify = true;// выравнивание по ширине
this.p = 50;// px, отступ параграфа this.p = 50;// px, отступ параграфа
@@ -226,8 +228,16 @@ class TextPage extends Vue {
this.parsed = parsed; this.parsed = parsed;
this.calcDrawProps(); this.calcDrawProps();
//await this.loadFontCss(); loadCSS(this.fontCssUrl);
await this.loadFonts(); let done = false;
while (!done) {
try {
await this.loadFonts();
done = true;
} catch (e) {
await sleep(100);
}
}
this.draw(); this.draw();
this.refreshTime(); this.refreshTime();

5
package-lock.json generated
View File

@@ -4135,6 +4135,11 @@
"pend": "~1.2.0" "pend": "~1.2.0"
} }
}, },
"fg-loadcss": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/fg-loadcss/-/fg-loadcss-2.1.0.tgz",
"integrity": "sha512-HpvR2uRoKvrYAEwimw+k4Fr2NVHYPfld5Lc/f9uy3mKeUTXhS5urL24XA2rqyq5b2i410EXCLir4Uhsb8J1QaQ=="
},
"figgy-pudding": { "figgy-pudding": {
"version": "3.5.1", "version": "3.5.1",
"resolved": "https://registry.npmjs.org/figgy-pudding/-/figgy-pudding-3.5.1.tgz", "resolved": "https://registry.npmjs.org/figgy-pudding/-/figgy-pudding-3.5.1.tgz",

View File

@@ -63,6 +63,7 @@
"detect-file-type": "^0.2.0", "detect-file-type": "^0.2.0",
"element-ui": "^2.4.11", "element-ui": "^2.4.11",
"express": "^4.16.4", "express": "^4.16.4",
"fg-loadcss": "^2.1.0",
"fs-extra": "^7.0.1", "fs-extra": "^7.0.1",
"got": "^9.5.1", "got": "^9.5.1",
"iconv-lite": "^0.4.24", "iconv-lite": "^0.4.24",