From 79dda03baceaa0ade82624bc90698f38e6f3ab0d Mon Sep 17 00:00:00 2001 From: Book Pauk Date: Wed, 23 Dec 2020 22:38:52 +0700 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B5=D1=84=D0=B0=D0=BA=D1=82=D0=BE?= =?UTF-8?q?=D1=80=D0=B8=D0=BD=D0=B3,=20=D0=BF=D0=BB=D1=8E=D1=81=20=D0=BD?= =?UTF-8?q?=D0=B5=D0=B1=D0=BE=D0=BB=D1=8C=D1=88=D0=BE=D0=B5=20=D1=83=D0=BB?= =?UTF-8?q?=D1=83=D1=87=D1=88=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BC=D0=B5=D1=85?= =?UTF-8?q?=D0=B0=D0=BD=D0=B8=D0=B7=D0=BC=D0=B0=20=D0=B7=D0=B0=D0=B3=D1=80?= =?UTF-8?q?=D1=83=D0=B7=D0=BA=D0=B8=20=D1=88=D1=80=D0=B8=D1=84=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/Reader/TextPage/TextPage.vue | 40 +++++++++++-------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/client/components/Reader/TextPage/TextPage.vue b/client/components/Reader/TextPage/TextPage.vue index 32dd8d4b..7247439b 100644 --- a/client/components/Reader/TextPage/TextPage.vue +++ b/client/components/Reader/TextPage/TextPage.vue @@ -228,8 +228,6 @@ class TextPage extends Vue { //parsed if (this.parsed) { - this.testText = 'Это тестовый текст. Его ширина выдается системой неправильно некоторое время.'; - let wideLine = wideLetter; if (!this.drawHelper.measureText(wideLine, {})) throw new Error('Ошибка measureText'); @@ -250,7 +248,7 @@ class TextPage extends Vue { imageHeightLines: this.imageHeightLines, imageFitWidth: this.imageFitWidth, compactTextPerc: this.compactTextPerc, - testWidth: this.drawHelper.measureText(this.testText, {}), + testWidth: 0, measureText: this.drawHelper.measureText.bind(this.drawHelper), }); } @@ -340,22 +338,32 @@ class TextPage extends Vue { this.draw(); } else { // ширина шрифта некоторое время выдается неверно, - // не получилось событийно отловить этот момент, поэтому костыль - const parsed = this.parsed; - - let i = 0; - const t = this.testText; - const tw = this.drawHelper.measureText(t, {}); - //5 секунд проверяем изменения шрифта - while (i++ < 50 && this.parsed === parsed && this.drawHelper.measureText(t, {}) === tw) { - if (i == 10) //через 1 сек - this.draw(); + // не удалось событийно отловить этот момент, поэтому костыль + while (this.checkingFont) { + this.stopCheckingFont = true; await utils.sleep(100); } - if (this.parsed === parsed) { - this.parsed.setSettings({testWidth: this.drawHelper.measureText(t, {})}); - this.draw(); + this.checkingFont = true; + this.stopCheckingFont = false; + try { + const parsed = this.parsed; + + let i = 0; + const t = 'Это тестовый текст. Его ширина выдается системой неправильно некоторое время.'; + let twprev = 0; + //5 секунд проверяем изменения шрифта + while (!this.stopCheckingFont && i++ < 50 && this.parsed === parsed) { + const tw = this.drawHelper.measureText(t, {}); + if (tw !== twprev) { + this.parsed.setSettings({testWidth: tw}); + this.draw(); + twprev = tw; + } + await utils.sleep(100); + } + } finally { + this.checkingFont = false; } } }