diff --git a/client/components/Reader/SettingsPage/SettingsPage.vue b/client/components/Reader/SettingsPage/SettingsPage.vue index fc271daf..83bbc001 100644 --- a/client/components/Reader/SettingsPage/SettingsPage.vue +++ b/client/components/Reader/SettingsPage/SettingsPage.vue @@ -187,6 +187,17 @@ Добавлять параметр "__p" + + + + Предварительная обработка текста + + diff --git a/client/components/Reader/TextPage/TextPage.vue b/client/components/Reader/TextPage/TextPage.vue index b82406b1..52fd5a7f 100644 --- a/client/components/Reader/TextPage/TextPage.vue +++ b/client/components/Reader/TextPage/TextPage.vue @@ -308,10 +308,15 @@ class TextPage extends Vue { if (this.lastBook) { (async() => { + //подождем ленивый парсинг + this.stopLazyParse = true; + while (this.doingLazyParse) await sleep(10); + const isParsed = await bookManager.hasBookParsed(this.lastBook); if (!isParsed) { return; } + this.book = await bookManager.getBook(this.lastBook); this.meta = bookManager.metaOnly(this.book); this.fb2 = this.meta.fb2; @@ -332,6 +337,8 @@ class TextPage extends Vue { this.calcPropsAndLoadFonts(); this.refreshTime(); + if (this.lazyParseEnabled) + this.lazyParsePara(); })(); } } @@ -460,7 +467,7 @@ class TextPage extends Vue { lineText += part.text; center = center || part.style.center; if (part.style.center) - centerStyle = part.style.center; + centerStyle = part.style; } let filled = false; @@ -491,7 +498,7 @@ class TextPage extends Vue { // просто выводим текст if (!filled) { let x = indent; - x = (center ? this.indent + (this.w - this.measureText(lineText, centerStyle))/2 : x); + x = (center ? this.indentLR + (this.w - this.measureText(lineText, centerStyle))/2 : x); for (const part of line.parts) { let text = part.text; const font = this.fontByStyle(part.style); @@ -506,7 +513,7 @@ class TextPage extends Vue { return out; } - drawStatusBar() { + drawStatusBar(message) { if (this.w < minLayoutWidth) { this.statusBar = null; return; @@ -519,7 +526,8 @@ class TextPage extends Vue { i--; i = (i > lines.length - 1 ? lines.length - 1 : i); if (i >= 0) { - let message = this.statusBarMessage; + if (!message) + message = this.statusBarMessage; if (!message) message = this.title; this.statusBar = this.drawHelper.drawStatusBar(this.statusBarTop, this.statusBarHeight, @@ -542,6 +550,36 @@ class TextPage extends Vue { this.drawStatusBar(); } + async lazyParsePara() { + if (!this.parsed || this.doingLazyParse) + return; + this.doingLazyParse = true; + let j = 0; + let k = 0; + let prevPerc = 0; + this.stopLazyParse = false; + for (let i = 0; i < this.parsed.para.length; i++) { + j++; + if (j > 1) { + await sleep(1); + j = 0; + } + if (this.stopLazyParse) + break; + this.parsed.parsePara(i); + k++; + if (k > 100) { + let perc = Math.round(i/this.parsed.para.length*100); + if (perc != prevPerc) + this.drawStatusBar(`Обработка текста ${perc}%`); + prevPerc = perc; + k = 0; + } + } + this.drawStatusBar(); + this.doingLazyParse = false; + } + async refreshTime() { if (!this.timeRefreshing) { this.timeRefreshing = true; diff --git a/client/store/modules/reader.js b/client/store/modules/reader.js index 5786b6c9..8e0240c0 100644 --- a/client/store/modules/reader.js +++ b/client/store/modules/reader.js @@ -46,6 +46,7 @@ const settingDefaults = { pageChangeTransitionSpeed: 50, //0-100% allowUrlParamBookPos: false, + lazyParseEnabled: false, fontShifts: {}, };