From 25852712e964c1f9be89c60b386aa83116497966 Mon Sep 17 00:00:00 2001 From: Book Pauk Date: Mon, 28 Jan 2019 02:46:51 +0700 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D1=80=D0=B0=D0=B7=D0=B1=D0=B8=D0=B2=D0=BA=D1=83=20=D0=B4=D0=BB?= =?UTF-8?q?=D0=B8=D0=BD=D0=BD=D1=8B=D1=85=20=D1=81=D0=BB=D0=BE=D0=B2=20?= =?UTF-8?q?=D0=B1=D0=B5=D0=B7=20=D0=BF=D1=80=D0=BE=D0=B1=D0=B5=D0=BB=D0=BE?= =?UTF-8?q?=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/Reader/TextPage/TextPage.vue | 18 +++++++++++- client/components/Reader/share/BookParser.js | 28 +++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/client/components/Reader/TextPage/TextPage.vue b/client/components/Reader/TextPage/TextPage.vue index d37ee191..d2cd37fc 100644 --- a/client/components/Reader/TextPage/TextPage.vue +++ b/client/components/Reader/TextPage/TextPage.vue @@ -33,6 +33,8 @@ import {sleep} from '../../../share/utils'; import bookManager from '../share/bookManager'; import DrawHelper from './DrawHelper'; +const minLayoutWidth = 100; + export default @Component({ watch: { bookPos: function(newValue) { @@ -130,6 +132,9 @@ class TextPage extends Vue { this.parsed.w = this.w;// px, ширина текста this.parsed.font = this.font; this.parsed.wordWrap = this.wordWrap; + let t = ''; + while (this.measureText(t, {}) < this.w) t += 'Щ'; + this.parsed.maxWordLength = t.length - 1; this.parsed.measureText = this.measureText; } @@ -316,8 +321,13 @@ class TextPage extends Vue { } draw() { - if (this.w < 10) + if (this.w < minLayoutWidth) { + this.page1 = null; + this.page2 = null; + this.statusBar = null; return; + } + if (this.book && this.bookPos > 0 && this.bookPos >= this.parsed.textLength) { this.doEnd(); return; @@ -451,6 +461,11 @@ class TextPage extends Vue { } drawStatusBar() { + if (this.w < minLayoutWidth) { + this.statusBar = null; + return; + } + if (this.showStatusBar && this.linesDown) { const lines = this.linesDown; let i = this.pageLineCount; @@ -764,6 +779,7 @@ class TextPage extends Vue { padding: 0; overflow: hidden; position: relative; + min-width: 200px; } .layout { diff --git a/client/components/Reader/share/BookParser.js b/client/components/Reader/share/BookParser.js index bf401956..d01fcb6a 100644 --- a/client/components/Reader/share/BookParser.js +++ b/client/components/Reader/share/BookParser.js @@ -282,6 +282,32 @@ export default class BookParser { onStartNode, onEndNode, onTextNode }); + + //длинные слова (или белиберду без пробелов) тоже разобьем + + const maxWordLength = this.maxWordLength; + const parts = result; + result = []; + for (const part of parts) { + let p = part; + let i = 0; + let spaceIndex = -1; + while (i < p.text.length) { + if (p.text[i] == ' ') + spaceIndex = i; + + if (i - spaceIndex >= maxWordLength && i < p.text.length - 1 && + this.measureText(p.text.substr(spaceIndex + 1, i - spaceIndex), p.style) >= this.w - this.p) { + result.push({style: p.style, text: p.text.substr(0, i + 1)}); + p = {style: p.style, text: p.text.substr(i + 1)}; + spaceIndex = -1; + i = -1; + } + i++; + } + result.push(p); + } + return result; } @@ -343,6 +369,7 @@ export default class BookParser { para.parsed.w === this.w && para.parsed.p === this.p && para.parsed.wordWrap === this.wordWrap && + para.parsed.maxWordLength === this.maxWordLength && para.parsed.font === this.font ) return para.parsed; @@ -351,6 +378,7 @@ export default class BookParser { w: this.w, p: this.p, wordWrap: this.wordWrap, + maxWordLength: this.maxWordLength, font: this.font, };