From dd61c04d639b9bc6acf3461b18caa63f2aef0957 Mon Sep 17 00:00:00 2001 From: Book Pauk Date: Wed, 20 Feb 2019 19:25:52 +0700 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=BE=D0=BF=D1=80=D0=B0=D0=B2=D0=BA?= =?UTF-8?q?=D0=B8=20=D0=B1=D0=B0=D0=B3=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/Reader/TextPage/DrawHelper.js | 9 +++- client/components/Reader/share/BookParser.js | 46 +++++++++++++------ 2 files changed, 39 insertions(+), 16 deletions(-) diff --git a/client/components/Reader/TextPage/DrawHelper.js b/client/components/Reader/TextPage/DrawHelper.js index 9e5504a2..26b629e6 100644 --- a/client/components/Reader/TextPage/DrawHelper.js +++ b/client/components/Reader/TextPage/DrawHelper.js @@ -73,6 +73,7 @@ export default class DrawHelper { let lineText = ''; let center = false; + let space = false; let j = 0; //формируем строку for (const part of line.parts) { @@ -96,6 +97,7 @@ export default class DrawHelper { lineText += `${tOpen}${text}${tClose}`; center = center || part.style.center; + space = space || part.style.space; //избражения //image: {local: Boolean, inline: Boolean, id: String, imageLine: Number, lineCount: Number, paraIndex: Number}, @@ -125,8 +127,11 @@ export default class DrawHelper { } const centerStyle = (center ? `text-align: center; text-align-last: center; width: ${this.w}px` : '') - if (line.first && !center) - lineText = `${lineText}`; + if ((line.first || space) && !center) { + let p = (line.first ? this.p : 0); + p = (space ? p + this.p : p); + lineText = `${lineText}`; + } if (line.last || center) lineText = `${lineText}`; diff --git a/client/components/Reader/share/BookParser.js b/client/components/Reader/share/BookParser.js index b190fc24..7f8829de 100644 --- a/client/components/Reader/share/BookParser.js +++ b/client/components/Reader/share/BookParser.js @@ -39,6 +39,8 @@ export default class BookParser { let center = false; let bold = false; let italic = false; + let space = false; + this.binary = {}; let binaryId = ''; let binaryType = ''; @@ -177,6 +179,7 @@ export default class BookParser { if (tag == 'epigraph') { italic = true; + space = true; } if (tag == 'poem') { @@ -184,7 +187,7 @@ export default class BookParser { } if (tag == 'text-author') { - newParagraph(' ', 4); + space = true; } } }; @@ -211,11 +214,16 @@ export default class BookParser { if (tag == 'epigraph') { italic = false; + space = false; } if (tag == 'stanza') { newParagraph(' ', 1); } + + if (tag == 'text-author') { + space = false; + } } path = path.substr(0, path.length - tag.length - 1); @@ -277,7 +285,9 @@ export default class BookParser { let tOpen = (center ? '
' : ''); tOpen += (bold ? '' : ''); tOpen += (italic ? '' : ''); - let tClose = (italic ? '' : ''); + tOpen += (space ? '' : ''); + let tClose = (space ? '' : ''); + tClose += (italic ? '' : ''); tClose += (bold ? '' : ''); tClose += (center ? '
' : ''); @@ -352,7 +362,7 @@ export default class BookParser { splitToStyle(s) { let result = [];/*array of { - style: {bold: Boolean, italic: Boolean, center: Boolean}, + style: {bold: Boolean, italic: Boolean, center: Boolean, space: Number}, image: {local: Boolean, inline: Boolean, id: String}, text: String, }*/ @@ -378,19 +388,23 @@ export default class BookParser { case 'center': style.center = true; break; + case 'space': { + style.space = true; + break; + } case 'image': { - let attrs = sax.getAttrsSync(tail); - let id = attrs.href.value; - if (id) { - let local = false; - if (id[0] == '#') { - id = id.substr(1); - local = true; - } - image = {local, inline: false, id}; + let attrs = sax.getAttrsSync(tail); + let id = attrs.href.value; + if (id) { + let local = false; + if (id[0] == '#') { + id = id.substr(1); + local = true; } - break; + image = {local, inline: false, id}; } + break; + } } }; @@ -405,6 +419,9 @@ export default class BookParser { case 'center': style.center = false; break; + case 'space': + style.space = false; + break; case 'image': image = {}; break; @@ -588,7 +605,7 @@ export default class BookParser { continue; } - const words = part.text.split(' '); + let words = part.text.split(' '); let sp1 = ''; let sp2 = ''; @@ -602,6 +619,7 @@ export default class BookParser { str += sp1 + word; let p = (j == 0 ? parsed.p : 0); + p = (style.space ? p + parsed.p : p); let w = this.measureText(str, style) + p; let wordTail = word; if (w > parsed.w && prevStr != '') {