From 439296bf049f3b889abdb538f7798cf2878251c6 Mon Sep 17 00:00:00 2001 From: Book Pauk Date: Thu, 17 Jan 2019 01:15:12 +0700 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20?= =?UTF-8?q?=D0=BF=D0=B5=D1=80=D0=B5=D0=BD=D0=BE=D1=81=20=D0=BF=D0=BE=20?= =?UTF-8?q?=D1=81=D0=BB=D0=BE=D0=B3=D0=B0=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/Reader/TextPage/TextPage.vue | 4 +- client/components/Reader/share/BookParser.js | 56 +++++++++++++++---- 2 files changed, 46 insertions(+), 14 deletions(-) diff --git a/client/components/Reader/TextPage/TextPage.vue b/client/components/Reader/TextPage/TextPage.vue index 4cead01f..4c83d807 100644 --- a/client/components/Reader/TextPage/TextPage.vue +++ b/client/components/Reader/TextPage/TextPage.vue @@ -54,7 +54,7 @@ class TextPage extends Vue { this.canvas.height = this.$refs.main.clientHeight; this.lineHeight = this.fontSize + this.lineInterval; this.pageLineCount = Math.floor(this.canvas.height/this.lineHeight); - this.w = this.canvas.width - 2*this.indent - 200; + this.w = this.canvas.width - 2*this.indent; if (this.parsed) { this.parsed.p = this.p; @@ -82,7 +82,7 @@ class TextPage extends Vue { this.textColor = 'black'; this.backgroundColor = '#478355'; this.fontStyle = '';// 'bold','italic' - this.fontSize = 20;// px + this.fontSize = 40;// px this.fontName = 'arial'; this.lineInterval = 5;// px, межстрочный интервал this.textAlignJustify = true;// выравнивание по ширине diff --git a/client/components/Reader/share/BookParser.js b/client/components/Reader/share/BookParser.js index f5ad6f54..64cc2445 100644 --- a/client/components/Reader/share/BookParser.js +++ b/client/components/Reader/share/BookParser.js @@ -237,22 +237,35 @@ export default class BookParser { 'Б', 'В', 'Г', 'Д', 'Ж', 'З', 'Й', 'К', 'Л', 'М', 'Н', 'П', 'Р', 'С', 'Т', 'Ф', 'Х', 'Ч', 'Ц', 'Ш', 'Щ' ]); const znak = new Set(['ь', 'Ь', 'ъ', 'Ъ', 'й', 'Й']); - const alpha = new Set(...glas, ...soglas, ...znak); + const alpha = new Set([...glas, ...soglas, ...znak, ' ']); let slog = ''; let slogLen = 0; const len = word.length; - word += ' '; + word += ' '; for (let i = 0; i < len; i++) { slog += word[i]; if (alpha.has(word[i])) slogLen++; if (slogLen > 1 && i < len - 2 && ( - (glas.has(word[i]) && !(soglas.has(word[i + 1]) && soglas.has(word[i + 2]))) || - (soglas.has(word[i]) && soglas.has(word[i + 1]) && (glas.has(word[i + 2]) || soglas.has(word[i + 2]))) || + //гласная, а следом не 2 согласные буквы + (glas.has(word[i]) && !(soglas.has(word[i + 1]) && + soglas.has(word[i + 2])) && alpha.has(word[i + 1]) && alpha.has(word[i + 2]) + ) || + //предыдущая не согласная буква, текущая согласная, а следом согласная и согласная|гласная буквы + (alpha.has(word[i - 1]) && !soglas.has(word[i - 1]) && + soglas.has(word[i]) && soglas.has(word[i + 1]) && + (glas.has(word[i + 2]) || soglas.has(word[i + 2])) && + alpha.has(word[i + 1]) && alpha.has(word[i + 2]) + ) || + //мягкий или твердый знак или Й (znak.has(word[i])) - )) { + ) && + //нельзя оставлять окончания на ь, ъ, й + !(znak.has(word[i + 2]) && !alpha.has(word[i + 3])) + + ) { result.push(slog); slog = ''; slogLen = 0; @@ -308,17 +321,36 @@ export default class BookParser { const word = words[i]; part += word; - let w = this.measureText(part) + (j == 0 ? parsed.p : 0); + let p = (j == 0 ? parsed.p : 0); + let w = this.measureText(part) + p; if (w > parsed.w) { let wordTail; - if (parsed.wordWrap) { + + if (parsed.wordWrap) { let slogi = this.splitToSlogi(word); - /*for (let k = 0; k < slogi.length - 1; k++) { - }*/ + if (slogi.length > 1) { - prevPart += ' ' + slogi[0] + '-'; - slogi.shift(); - wordTail = slogi.join(''); + let s = prevPart + ' '; + let pw; + + const slogiLen = slogi.length; + for (let k = 0; k < slogiLen - 1; k++) { + let ww = this.measureText(s + slogi[0] + '-') + p; + if (ww <= parsed.w) { + s += slogi[0]; + } else + break; + pw = ww; + slogi.shift(); + } + + if (pw) { + prevW = pw; + prevPart = s + '-'; + wordTail = slogi.join(''); + } else { + wordTail = word; + } } else { wordTail = word; }