From 4608182a5278a0ca2cbf62d8e5f1d91bb47da0a3 Mon Sep 17 00:00:00 2001 From: Book Pauk Date: Thu, 17 Jan 2019 08:31:28 +0700 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=20=D0=BD?= =?UTF-8?q?=D0=B0=D0=B4=20=D1=81=D1=82=D0=B8=D0=BB=D0=B8=D0=B7=D0=B0=D1=86?= =?UTF-8?q?=D0=B8=D0=B5=D0=B9=20=D1=82=D0=B5=D0=BA=D1=81=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/Reader/TextPage/TextPage.vue | 24 +++++--- client/components/Reader/share/BookParser.js | 58 ++++++++++--------- 2 files changed, 47 insertions(+), 35 deletions(-) diff --git a/client/components/Reader/TextPage/TextPage.vue b/client/components/Reader/TextPage/TextPage.vue index 8668e1f0..c6be7dfc 100644 --- a/client/components/Reader/TextPage/TextPage.vue +++ b/client/components/Reader/TextPage/TextPage.vue @@ -155,6 +155,7 @@ class TextPage extends Vue { let y = 0; for (let i = 0; i < len; i++) { const line = lines[i]; +console.log(line.parts); /* line: { begin: Number, @@ -167,15 +168,10 @@ class TextPage extends Vue { } }*/ - let text = ''; - for (const part of line.parts) { - text += part.text; - } - let indent = this.indent + (line.first ? this.p : 0); y += this.lineHeight; - let filled = false; + /*let filled = false; if (this.textAlignJustify && !line.last) { const words = text.split(' '); if (words.length > 1) { @@ -192,7 +188,21 @@ class TextPage extends Vue { } if (!filled) - context.fillText(text, indent, y); + context.fillText(text, indent, y); + */ + /*let text = ''; + for (const part of line.parts) { + text += part.text; + } + context.fillText(text, indent, y); + */ + let x = indent; + for (const part of line.parts) { + let text = part.text; + context.font = `${part.style.italic ? 'italic' : ''} ${part.style.bold ? 'bold' : ''} ${this.fontSize}px ${this.fontName}`; + context.fillText(text, x, y); + x += this.measureText(text); + } } this.linesUp = this.parsed.getLines(this.bookPos, -(this.pageLineCount + 1)); diff --git a/client/components/Reader/share/BookParser.js b/client/components/Reader/share/BookParser.js index 9a590bd2..244916b4 100644 --- a/client/components/Reader/share/BookParser.js +++ b/client/components/Reader/share/BookParser.js @@ -333,46 +333,46 @@ export default class BookParser { let parts = this.splitToStyle(para.text); let line = {begin: para.offset, parts: []}; + let partText = '';//накапливаемый кусок со стилем + + let str = '';//измеряемая строка let prevStr = ''; - let str = ''; let prevW = 0; let j = 0;//номер строки let ofs = -1; let word = ''; - let isNewPara = true; - // тут начинается самый замес, перенос по слогам и стилизация + let sp1 = ''; + let text = ''; let style = {}; + + // тут начинается самый замес, перенос по слогам и стилизация for (let part of parts) { - text = part.text; + text = part.text + ' '; style = part.style; + let sp2 = ''; for (let i = 0; i < text.length; i++) { - ofs++; + if (i < text.length - 1) + ofs++; - if (i < text.length - 1) { - if (text[i] != ' ') { - word += text[i]; - continue; - } - } else { - if (text[i] != ' ') { - word += text[i]; - } + if (text[i] != ' ') { + word += text[i]; + continue; } - str += (isNewPara ? '' : ' ') + word; - isNewPara = false; + str += sp1 + word; + sp1 = ' '; let p = (j == 0 ? parsed.p : 0); let w = this.measureText(str) + p; + let wordTail = word; if (w > parsed.w) { - let wordTail; - if (parsed.wordWrap) { let slogi = this.splitToSlogi(word); if (slogi.length > 1) { let s = prevStr + ' '; + let ss = ' '; let pw; const slogiLen = slogi.length; @@ -381,6 +381,7 @@ export default class BookParser { let ww = this.measureText(s + slog + (slog[slog.length - 1] == '-' ? '' : '-')) + p; if (ww <= parsed.w) { s += slog; + ss += slog; } else break; pw = ww; @@ -389,19 +390,13 @@ export default class BookParser { if (pw) { prevW = pw; - prevStr = s + (s[s.length - 1] == '-' ? '' : '-'); + partText += ss + (ss[ss.length - 1] == '-' ? '' : '-'); wordTail = slogi.join(''); - } else { - wordTail = word; } - } else { - wordTail = word; } - } else { - wordTail = word; } - line.parts.push({style, text: prevStr}); + line.parts.push({style, text: partText}); line.end = para.offset + ofs; line.width = prevW; line.first = (j == 0); @@ -409,16 +404,23 @@ export default class BookParser { lines.push(line); line = {begin: para.offset + ofs + 1, parts: []}; + partText = ''; + sp2 = ''; str = wordTail; j++; } - prevW = w; + prevStr = str; + partText += sp2 + wordTail; + sp2 = ' '; word = ''; + prevW = w; } + + line.parts.push({style, text: partText}); + partText = ''; } - line.parts.push({style, text: prevStr}); line.end = para.offset + para.length - 1; line.width = prevW; line.first = (j == 0);