From ae3dc9b22cb2dd0e48fbb59382cb3c796faacb5f Mon Sep 17 00:00:00 2001 From: Book Pauk Date: Wed, 20 Feb 2019 15:26:54 +0700 Subject: [PATCH 01/10] =?UTF-8?q?=D0=9F=D1=80=D0=BE=D0=BC=D0=B5=D0=B6?= =?UTF-8?q?=D1=83=D1=82=D0=BE=D1=87=D0=BD=D1=8B=D0=B9=20=D0=BA=D0=BE=D0=BC?= =?UTF-8?q?=D0=BC=D0=B8=D1=82,=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=20?= =?UTF-8?q?=D0=BD=D0=B0=D0=B4=20=D0=B8=D0=B7=D0=BE=D0=B1=D1=80=D0=B0=D0=B6?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F=D0=BC=D0=B8,=20=D0=BD=D0=B5=D0=B1?= =?UTF-8?q?=D0=BE=D0=BB=D1=8C=D1=88=D0=BE=D0=B9=20=D1=80=D0=B5=D1=84=D0=B0?= =?UTF-8?q?=D0=BA=D1=82=D0=BE=D1=80=D0=B8=D0=BD=D0=B3=20=D0=BF=D0=BE=D0=BF?= =?UTF-8?q?=D1=83=D1=82=D0=BD=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/Reader/TextPage/DrawHelper.js | 2 +- .../components/Reader/TextPage/TextPage.vue | 3 + client/components/Reader/share/BookParser.js | 83 ++++++++++++------- 3 files changed, 59 insertions(+), 29 deletions(-) diff --git a/client/components/Reader/TextPage/DrawHelper.js b/client/components/Reader/TextPage/DrawHelper.js index acc14c42..4d75d306 100644 --- a/client/components/Reader/TextPage/DrawHelper.js +++ b/client/components/Reader/TextPage/DrawHelper.js @@ -28,7 +28,7 @@ export default class DrawHelper { let out = `
`; + ` line-height: ${this.lineHeight}px;">`; let len = lines.length; const lineCount = this.pageLineCount + (isScrolling ? 1 : 0); diff --git a/client/components/Reader/TextPage/TextPage.vue b/client/components/Reader/TextPage/TextPage.vue index 19a3583f..20ca10cd 100644 --- a/client/components/Reader/TextPage/TextPage.vue +++ b/client/components/Reader/TextPage/TextPage.vue @@ -216,6 +216,9 @@ class TextPage extends Vue { while (this.drawHelper.measureText(t, {}) < this.w) t += 'Щ'; this.parsed.maxWordLength = t.length - 1; this.parsed.measureText = this.drawHelper.measureText.bind(this.drawHelper); + this.parsed.lineHeight = this.lineHeight; + this.parsed.showImages = true; + this.parsed.imageHeightLines = 100; } //statusBar diff --git a/client/components/Reader/share/BookParser.js b/client/components/Reader/share/BookParser.js index 5a4dafcb..b6e9adab 100644 --- a/client/components/Reader/share/BookParser.js +++ b/client/components/Reader/share/BookParser.js @@ -356,10 +356,6 @@ export default class BookParser { let style = {}; let image = {}; - /*let attrs = sax.getAttrsSync(tail); - if (attrs.href.value) - newParagraph(' '.repeat(maxImageLineCount) + ``, maxImageLineCount); -*/ const onTextNode = async(text) => {// eslint-disable-line no-unused-vars result.push({ style: Object.assign({}, style), @@ -379,9 +375,15 @@ export default class BookParser { case 'center': style.center = true; break; - case 'image': - image = {}; - break; + case 'image': { + let attrs = sax.getAttrsSync(tail); + let id = attrs.href.value; + if (id) { + id = id.substr(1); + image = {inline: false, id}; + } + break; + } } }; @@ -412,20 +414,22 @@ export default class BookParser { 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 (!p.image.id) { + 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, image: p.image, text: p.text.substr(0, i + 1)}); - p = {style: p.style, text: p.text.substr(i + 1)}; - spaceIndex = -1; - i = -1; + 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, image: p.image, text: p.text.substr(0, i + 1)}); + p = {style: p.style, text: p.text.substr(i + 1)}; + spaceIndex = -1; + i = -1; + } + i++; } - i++; } result.push(p); } @@ -494,7 +498,9 @@ export default class BookParser { para.parsed.maxWordLength === this.maxWordLength && para.parsed.font === this.font && para.parsed.cutEmptyParagraphs === this.cutEmptyParagraphs && - para.parsed.addEmptyParagraphs === this.addEmptyParagraphs + para.parsed.addEmptyParagraphs === this.addEmptyParagraphs && + para.parsed.showImages === this.showImages && + para.parsed.imageHeightLines === this.imageHeightLines ) return para.parsed; @@ -506,6 +512,8 @@ export default class BookParser { font: this.font, cutEmptyParagraphs: this.cutEmptyParagraphs, addEmptyParagraphs: this.addEmptyParagraphs, + showImages: this.showImages, + imageHeightLines: this.imageHeightLines, visible: !( (this.cutEmptyParagraphs && para.cut) || (para.addIndex > this.addEmptyParagraphs) @@ -521,6 +529,7 @@ export default class BookParser { last: Boolean, parts: array of { style: {bold: Boolean, italic: Boolean, center: Boolean}, + image: {inline: Boolean, id: String, imageLine: Number, lineCount: Number, resize: Boolean}, text: String, } }*/ @@ -531,16 +540,40 @@ export default class BookParser { let str = '';//измеряемая строка let prevStr = '';//строка без крайнего слова - let prevW = 0; let j = 0;//номер строки let style = {}; let ofs = 0;//смещение от начала параграфа para.offset // тут начинается самый замес, перенос по слогам и стилизация for (const part of parts) { - const words = part.text.split(' '); style = part.style; + //изображения + if (part.image.id && !part.image.inline) { + const bin = this.binary[part.image.id]; + + let lineCount = this.imageHeightLines; + const c = Math.ceil(bin.h/this.lineHeight); + lineCount = (c < lineCount ? c : lineCount); + let i = 0; + for (; i < lineCount - 1; i++) { + line.end = para.offset + ofs; + line.first = (j == 0); + line.last = false; + line.parts.push({style, text: '!', image: {inline: false, id: part.image.id, imageLine: i, lineCount, resize: (c > lineCount)}}); + lines.push(line); + line = {begin: line.end + 1, parts: []}; + ofs++; + j++; + } + line.first = (j == 0); + line.last = true; + line.parts.push({style, text: '!', image: {inline: false, id: part.image.id, imageLine: i, lineCount, resize: (c > lineCount)}}); + continue; + } + + const words = part.text.split(' '); + let sp1 = ''; let sp2 = ''; for (let i = 0; i < words.length; i++) { @@ -578,7 +611,6 @@ export default class BookParser { } if (pw) { - prevW = pw; partText += ss + (ss[ss.length - 1] == '-' ? '' : '-'); wordTail = slogi.join(''); } @@ -592,7 +624,6 @@ export default class BookParser { let t = line.parts[line.parts.length - 1].text; if (t[t.length - 1] == ' ') { line.parts[line.parts.length - 1].text = t.trimRight(); - prevW -= this.measureText(' ', style); } } @@ -600,7 +631,6 @@ export default class BookParser { if (line.end - line.begin < 0) console.error(`Parse error, empty line in paragraph ${paraIndex}`); - line.width = prevW; line.first = (j == 0); line.last = false; lines.push(line); @@ -616,7 +646,6 @@ export default class BookParser { partText += sp2 + wordTail; sp1 = ' '; sp2 = ' '; - prevW = w; } if (partText != '') @@ -628,14 +657,12 @@ export default class BookParser { let t = line.parts[line.parts.length - 1].text; if (t[t.length - 1] == ' ') { line.parts[line.parts.length - 1].text = t.trimRight(); - prevW -= this.measureText(' ', style); } line.end = para.offset + para.length - 1; if (line.end - line.begin < 0) console.error(`Parse error, empty line in paragraph ${paraIndex}`); - line.width = prevW; line.first = (j == 0); line.last = true; lines.push(line); From 83fc586e03e43a4c1ecf054b32831f03d7ea4887 Mon Sep 17 00:00:00 2001 From: Book Pauk Date: Wed, 20 Feb 2019 16:49:03 +0700 Subject: [PATCH 02/10] =?UTF-8?q?=D0=A0=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=20?= =?UTF-8?q?=D0=BD=D0=B0=D0=B4=20=D0=B8=D0=B7=D0=BE=D0=B1=D1=80=D0=B0=D0=B6?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F=D0=BC=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/Reader/TextPage/DrawHelper.js | 24 ++++++++++++++--- client/components/Reader/share/BookParser.js | 26 ++++++++++++++----- 2 files changed, 40 insertions(+), 10 deletions(-) diff --git a/client/components/Reader/TextPage/DrawHelper.js b/client/components/Reader/TextPage/DrawHelper.js index 4d75d306..fb10b1c2 100644 --- a/client/components/Reader/TextPage/DrawHelper.js +++ b/client/components/Reader/TextPage/DrawHelper.js @@ -26,10 +26,11 @@ export default class DrawHelper { const font = this.fontByStyle({}); const justify = (this.textAlignJustify ? 'text-align: justify; text-align-last: justify;' : ''); - let out = `
`; + let imageDrawn = new Set(); let len = lines.length; const lineCount = this.pageLineCount + (isScrolling ? 1 : 0); len = (len > lineCount ? lineCount : len); @@ -43,7 +44,8 @@ export default class DrawHelper { first: Boolean, last: Boolean, parts: array of { - style: {bold: Boolean, italic: Boolean, center: Boolean} + style: {bold: Boolean, italic: Boolean, center: Boolean}, + image: {local: Boolean, inline: Boolean, id: String, imageLine: Number, lineCount: Number, resize: Boolean, paraIndex: Number}, text: String, } }*/ @@ -89,10 +91,26 @@ export default class DrawHelper { lineText += `${tOpen}${text}${tClose}`; center = center || part.style.center; + + //избражения + //image: {local: Boolean, inline: Boolean, id: String, imageLine: Number, lineCount: Number, resize: Boolean, paraIndex: Number}, + const img = part.image; + if (img && img.id && !img.inline && !imageDrawn.has(img.paraIndex)) { + if (img.local) { + const bin = this.parsed.binary[img.id]; + const left = (this.w - bin.w)/2; + const s = (img.lineCount*this.lineHeight - bin.h)/2; + const top = s + (i - img.imageLine)*this.lineHeight; + lineText += ``; + } else { + // + } + imageDrawn.add(img.paraIndex); + } } const centerStyle = (center ? `text-align: center; text-align-last: center; width: ${this.w}px` : '') - if (line.first) + if (line.first && !center) 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 b6e9adab..00199d72 100644 --- a/client/components/Reader/share/BookParser.js +++ b/client/components/Reader/share/BookParser.js @@ -349,8 +349,7 @@ export default class BookParser { splitToStyle(s) { let result = [];/*array of { style: {bold: Boolean, italic: Boolean, center: Boolean}, - image: Boolean, - imageId: String, + image: {local: Boolean, inline: Boolean, id: String}, text: String, }*/ let style = {}; @@ -379,8 +378,12 @@ export default class BookParser { let attrs = sax.getAttrsSync(tail); let id = attrs.href.value; if (id) { - id = id.substr(1); - image = {inline: false, id}; + let local = false; + if (id[0] == '#') { + id = id.substr(1); + local = true; + } + image = {local, inline: false, id}; } break; } @@ -529,7 +532,7 @@ export default class BookParser { last: Boolean, parts: array of { style: {bold: Boolean, italic: Boolean, center: Boolean}, - image: {inline: Boolean, id: String, imageLine: Number, lineCount: Number, resize: Boolean}, + image: {local: Boolean, inline: Boolean, id: String, imageLine: Number, lineCount: Number, resize: Boolean, paraIndex: Number}, text: String, } }*/ @@ -560,7 +563,15 @@ export default class BookParser { line.end = para.offset + ofs; line.first = (j == 0); line.last = false; - line.parts.push({style, text: '!', image: {inline: false, id: part.image.id, imageLine: i, lineCount, resize: (c > lineCount)}}); + line.parts.push({style, text: ' ', image: { + local: part.image.local, + inline: false, + id: part.image.id, + imageLine: i, + lineCount, + resize: (c > lineCount), + paraIndex + }}); lines.push(line); line = {begin: line.end + 1, parts: []}; ofs++; @@ -568,7 +579,8 @@ export default class BookParser { } line.first = (j == 0); line.last = true; - line.parts.push({style, text: '!', image: {inline: false, id: part.image.id, imageLine: i, lineCount, resize: (c > lineCount)}}); + line.parts.push({style, text: ' ', + image: {local: part.image.local, inline: false, id: part.image.id, imageLine: i, lineCount, resize: (c > lineCount), paraIndex}}); continue; } From 55d02495a301c9eb7710fbd4f46e077114d8db6f Mon Sep 17 00:00:00 2001 From: Book Pauk Date: Wed, 20 Feb 2019 17:17:51 +0700 Subject: [PATCH 03/10] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D0=BD=D0=B0=D1=81=D1=82=D1=80=D0=BE=D0=B9=D0=BA=D0=B8?= =?UTF-8?q?=20=D0=B4=D0=BB=D1=8F=20=D0=B8=D0=B7=D0=BE=D0=B1=D1=80=D0=B0?= =?UTF-8?q?=D0=B6=D0=B5=D0=BD=D0=B8=D0=B9,=20=D0=B4=D0=BE=D0=B1=D0=B0?= =?UTF-8?q?=D0=B8=D0=BB=20=D0=B0=D0=B2=D1=82=D0=BE=D0=BC=D0=B0=D1=82=D0=B8?= =?UTF-8?q?=D1=87=D0=B5=D1=81=D0=BA=D0=B8=D0=B9=20=D1=80=D0=B5=D1=81=D0=B0?= =?UTF-8?q?=D0=B9=D0=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Reader/SettingsPage/SettingsPage.vue | 20 +++++++++++++++++++ .../components/Reader/TextPage/DrawHelper.js | 18 +++++++++++++---- .../components/Reader/TextPage/TextPage.vue | 4 ++-- client/components/Reader/share/BookParser.js | 6 +++--- client/store/modules/reader.js | 2 ++ 5 files changed, 41 insertions(+), 9 deletions(-) diff --git a/client/components/Reader/SettingsPage/SettingsPage.vue b/client/components/Reader/SettingsPage/SettingsPage.vue index 796db49e..b9d54666 100644 --- a/client/components/Reader/SettingsPage/SettingsPage.vue +++ b/client/components/Reader/SettingsPage/SettingsPage.vue @@ -194,6 +194,26 @@ + + + Показывать + + + +   + + + + + + + + diff --git a/client/components/Reader/TextPage/DrawHelper.js b/client/components/Reader/TextPage/DrawHelper.js index fb10b1c2..c15107e9 100644 --- a/client/components/Reader/TextPage/DrawHelper.js +++ b/client/components/Reader/TextPage/DrawHelper.js @@ -98,10 +98,20 @@ export default class DrawHelper { if (img && img.id && !img.inline && !imageDrawn.has(img.paraIndex)) { if (img.local) { const bin = this.parsed.binary[img.id]; - const left = (this.w - bin.w)/2; - const s = (img.lineCount*this.lineHeight - bin.h)/2; - const top = s + (i - img.imageLine)*this.lineHeight; - lineText += ``; + + let imgH = img.lineCount*this.lineHeight; + imgH = (imgH <= bin.h ? imgH : bin.h); + let imgW = bin.w; + + let resize = ''; + if (bin.h > imgH) { + resize = `height: ${imgH}px`; + imgW = imgW*imgH/bin.h; + } + + const left = (this.w - imgW)/2; + const top = ((img.lineCount*this.lineHeight - imgH)/2) + (i - img.imageLine)*this.lineHeight; + lineText += ``; } else { // } diff --git a/client/components/Reader/TextPage/TextPage.vue b/client/components/Reader/TextPage/TextPage.vue index 20ca10cd..4dd70640 100644 --- a/client/components/Reader/TextPage/TextPage.vue +++ b/client/components/Reader/TextPage/TextPage.vue @@ -217,8 +217,8 @@ class TextPage extends Vue { this.parsed.maxWordLength = t.length - 1; this.parsed.measureText = this.drawHelper.measureText.bind(this.drawHelper); this.parsed.lineHeight = this.lineHeight; - this.parsed.showImages = true; - this.parsed.imageHeightLines = 100; + this.parsed.showImages = this.showImages; + this.parsed.imageHeightLines = this.imageHeightLines; } //statusBar diff --git a/client/components/Reader/share/BookParser.js b/client/components/Reader/share/BookParser.js index 00199d72..d8931f37 100644 --- a/client/components/Reader/share/BookParser.js +++ b/client/components/Reader/share/BookParser.js @@ -532,7 +532,7 @@ export default class BookParser { last: Boolean, parts: array of { style: {bold: Boolean, italic: Boolean, center: Boolean}, - image: {local: Boolean, inline: Boolean, id: String, imageLine: Number, lineCount: Number, resize: Boolean, paraIndex: Number}, + image: {local: Boolean, inline: Boolean, id: String, imageLine: Number, lineCount: Number, paraIndex: Number}, text: String, } }*/ @@ -553,6 +553,7 @@ export default class BookParser { //изображения if (part.image.id && !part.image.inline) { + parsed.visible = this.showImages; const bin = this.binary[part.image.id]; let lineCount = this.imageHeightLines; @@ -569,7 +570,6 @@ export default class BookParser { id: part.image.id, imageLine: i, lineCount, - resize: (c > lineCount), paraIndex }}); lines.push(line); @@ -580,7 +580,7 @@ export default class BookParser { line.first = (j == 0); line.last = true; line.parts.push({style, text: ' ', - image: {local: part.image.local, inline: false, id: part.image.id, imageLine: i, lineCount, resize: (c > lineCount), paraIndex}}); + image: {local: part.image.local, inline: false, id: part.image.id, imageLine: i, lineCount, paraIndex}}); continue; } diff --git a/client/store/modules/reader.js b/client/store/modules/reader.js index 676a49b4..f00c2a56 100644 --- a/client/store/modules/reader.js +++ b/client/store/modules/reader.js @@ -163,6 +163,8 @@ const settingDefaults = { cutEmptyParagraphs: false, addEmptyParagraphs: 0, blinkCachedLoad: true, + showImages: true, + imageHeightLines: 100, fontShifts: {}, }; From 618111ab05b5a121c6bb206428c78ca1be389363 Mon Sep 17 00:00:00 2001 From: Book Pauk Date: Wed, 20 Feb 2019 17:32:26 +0700 Subject: [PATCH 04/10] =?UTF-8?q?=D0=9F=D0=BE=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BA=D0=B0=20=D0=B1=D0=B0=D0=B3=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/components/Reader/share/BookParser.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/components/Reader/share/BookParser.js b/client/components/Reader/share/BookParser.js index d8931f37..f9d0cc95 100644 --- a/client/components/Reader/share/BookParser.js +++ b/client/components/Reader/share/BookParser.js @@ -427,7 +427,7 @@ export default class BookParser { 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, image: p.image, text: p.text.substr(0, i + 1)}); - p = {style: p.style, text: p.text.substr(i + 1)}; + p = {style: p.style, image: p.image, text: p.text.substr(i + 1)}; spaceIndex = -1; i = -1; } From 56d13288ffef22305a1c9c7af167eb1e29e2d16e Mon Sep 17 00:00:00 2001 From: Book Pauk Date: Wed, 20 Feb 2019 18:04:05 +0700 Subject: [PATCH 05/10] =?UTF-8?q?=D0=9F=D0=BE=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BA=D0=B0=20=D0=B1=D0=B0=D0=B3=D0=B0,=20=D0=BA=D0=BE=D0=BC?= =?UTF-8?q?=D0=BC=D0=B5=D0=BD=D1=82=D0=B0=D1=80=D0=B8=D0=B5=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/components/Reader/TextPage/DrawHelper.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/client/components/Reader/TextPage/DrawHelper.js b/client/components/Reader/TextPage/DrawHelper.js index c15107e9..9e5504a2 100644 --- a/client/components/Reader/TextPage/DrawHelper.js +++ b/client/components/Reader/TextPage/DrawHelper.js @@ -45,11 +45,12 @@ export default class DrawHelper { last: Boolean, parts: array of { style: {bold: Boolean, italic: Boolean, center: Boolean}, - image: {local: Boolean, inline: Boolean, id: String, imageLine: Number, lineCount: Number, resize: Boolean, paraIndex: Number}, + image: {local: Boolean, inline: Boolean, id: String, imageLine: Number, lineCount: Number, paraIndex: Number}, text: String, } }*/ let sel = new Set(); + //поиск if (i == 0 && this.searching) { let pureText = ''; for (const part of line.parts) { @@ -73,6 +74,7 @@ export default class DrawHelper { let lineText = ''; let center = false; let j = 0; + //формируем строку for (const part of line.parts) { let tOpen = (part.style.bold ? '' : ''); tOpen += (part.style.italic ? '' : ''); @@ -88,12 +90,15 @@ export default class DrawHelper { } else text = part.text; + if (text.trim() == '') + text = `${text}`; + lineText += `${tOpen}${text}${tClose}`; center = center || part.style.center; //избражения - //image: {local: Boolean, inline: Boolean, id: String, imageLine: Number, lineCount: Number, resize: Boolean, paraIndex: Number}, + //image: {local: Boolean, inline: Boolean, id: String, imageLine: Number, lineCount: Number, paraIndex: Number}, const img = part.image; if (img && img.id && !img.inline && !imageDrawn.has(img.paraIndex)) { if (img.local) { @@ -122,6 +127,7 @@ 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.last || center) lineText = `${lineText}`; From 5496e874c4f7c2861bc2503950538fe36c91f341 Mon Sep 17 00:00:00 2001 From: Book Pauk Date: Wed, 20 Feb 2019 18:19:23 +0700 Subject: [PATCH 06/10] =?UTF-8?q?=D0=A3=D0=BB=D1=83=D1=87=D1=88=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=BF=D0=B0=D1=80=D1=81=D0=B8=D0=BD=D0=B3?= =?UTF-8?q?=D0=B0=20fb2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/components/Reader/share/BookParser.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/client/components/Reader/share/BookParser.js b/client/components/Reader/share/BookParser.js index f9d0cc95..b190fc24 100644 --- a/client/components/Reader/share/BookParser.js +++ b/client/components/Reader/share/BookParser.js @@ -158,6 +158,10 @@ export default class BookParser { center = true; } + if (tag == 'section') { + newParagraph(' ', 1); + } + if (tag == 'emphasis' || tag == 'strong') { growParagraph(`<${tag}>`, 0); } From dd61c04d639b9bc6acf3461b18caa63f2aef0957 Mon Sep 17 00:00:00 2001 From: Book Pauk Date: Wed, 20 Feb 2019 19:25:52 +0700 Subject: [PATCH 07/10] =?UTF-8?q?=D0=9F=D0=BE=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BA=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 != '') { From d3a30b87f4875c8c07cd6a254308054be56af0d9 Mon Sep 17 00:00:00 2001 From: Book Pauk Date: Wed, 20 Feb 2019 19:43:39 +0700 Subject: [PATCH 08/10] =?UTF-8?q?=D0=A3=D0=BB=D1=83=D1=87=D1=88=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=BF=D0=B0=D1=80=D1=81=D0=B8=D0=BD=D0=B3?= =?UTF-8?q?=D0=B0=20fb2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/Reader/TextPage/DrawHelper.js | 6 +++--- client/components/Reader/share/BookParser.js | 21 +++++++++++-------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/client/components/Reader/TextPage/DrawHelper.js b/client/components/Reader/TextPage/DrawHelper.js index 26b629e6..21abb4ad 100644 --- a/client/components/Reader/TextPage/DrawHelper.js +++ b/client/components/Reader/TextPage/DrawHelper.js @@ -73,7 +73,7 @@ export default class DrawHelper { let lineText = ''; let center = false; - let space = false; + let space = 0; let j = 0; //формируем строку for (const part of line.parts) { @@ -97,7 +97,7 @@ export default class DrawHelper { lineText += `${tOpen}${text}${tClose}`; center = center || part.style.center; - space = space || part.style.space; + space = (part.style.space > 0 ? part.style.space : space); //избражения //image: {local: Boolean, inline: Boolean, id: String, imageLine: Number, lineCount: Number, paraIndex: Number}, @@ -129,7 +129,7 @@ export default class DrawHelper { const centerStyle = (center ? `text-align: center; text-align-last: center; width: ${this.w}px` : '') if ((line.first || space) && !center) { let p = (line.first ? this.p : 0); - p = (space ? p + this.p : p); + p = (space ? p + this.p*space : p); lineText = `${lineText}`; } diff --git a/client/components/Reader/share/BookParser.js b/client/components/Reader/share/BookParser.js index 7f8829de..0c5de7fb 100644 --- a/client/components/Reader/share/BookParser.js +++ b/client/components/Reader/share/BookParser.js @@ -39,7 +39,7 @@ export default class BookParser { let center = false; let bold = false; let italic = false; - let space = false; + let space = 0; this.binary = {}; let binaryId = ''; @@ -179,7 +179,7 @@ export default class BookParser { if (tag == 'epigraph') { italic = true; - space = true; + space += 1; } if (tag == 'poem') { @@ -187,7 +187,8 @@ export default class BookParser { } if (tag == 'text-author') { - space = true; + newParagraph(' ', 1); + space += 1; } } }; @@ -214,7 +215,7 @@ export default class BookParser { if (tag == 'epigraph') { italic = false; - space = false; + space -= 1; } if (tag == 'stanza') { @@ -222,7 +223,7 @@ export default class BookParser { } if (tag == 'text-author') { - space = false; + space -= 1; } } @@ -285,7 +286,7 @@ export default class BookParser { let tOpen = (center ? '
' : ''); tOpen += (bold ? '' : ''); tOpen += (italic ? '' : ''); - tOpen += (space ? '' : ''); + tOpen += (space ? `` : ''); let tClose = (space ? '' : ''); tClose += (italic ? '' : ''); tClose += (bold ? '' : ''); @@ -389,7 +390,9 @@ export default class BookParser { style.center = true; break; case 'space': { - style.space = true; + let attrs = sax.getAttrsSync(tail); + if (attrs.w.value) + style.space = attrs.w.value; break; } case 'image': { @@ -420,7 +423,7 @@ export default class BookParser { style.center = false; break; case 'space': - style.space = false; + style.space = 0; break; case 'image': image = {}; @@ -619,7 +622,7 @@ export default class BookParser { str += sp1 + word; let p = (j == 0 ? parsed.p : 0); - p = (style.space ? p + parsed.p : p); + p = (style.space ? p + parsed.p*style.space : p); let w = this.measureText(str, style) + p; let wordTail = word; if (w > parsed.w && prevStr != '') { From 1a7ceb333d575de1ac780c4856a4330580bae0e1 Mon Sep 17 00:00:00 2001 From: Book Pauk Date: Wed, 20 Feb 2019 20:57:34 +0700 Subject: [PATCH 09/10] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B0=20=D0=BE=D0=B1=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=BA=D0=B0=20inline-=D0=B8=D0=B7=D0=BE=D0=B1=D1=80=D0=B0?= =?UTF-8?q?=D0=B6=D0=B5=D0=BD=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/Reader/TextPage/DrawHelper.js | 13 +++++ .../components/Reader/TextPage/TextPage.vue | 1 + client/components/Reader/share/BookParser.js | 48 +++++++++++++++++-- 3 files changed, 58 insertions(+), 4 deletions(-) diff --git a/client/components/Reader/TextPage/DrawHelper.js b/client/components/Reader/TextPage/DrawHelper.js index 21abb4ad..40b81a55 100644 --- a/client/components/Reader/TextPage/DrawHelper.js +++ b/client/components/Reader/TextPage/DrawHelper.js @@ -124,6 +124,19 @@ export default class DrawHelper { } imageDrawn.add(img.paraIndex); } + + if (img && img.id && img.inline) { + if (img.local) { + const bin = this.parsed.binary[img.id]; + let resize = ''; + if (bin.h > this.fontSize) { + resize = `height: ${this.fontSize - 3}px`; + } + lineText += ``; + } else { + // + } + } } const centerStyle = (center ? `text-align: center; text-align-last: center; width: ${this.w}px` : '') diff --git a/client/components/Reader/TextPage/TextPage.vue b/client/components/Reader/TextPage/TextPage.vue index 4dd70640..7e0a845d 100644 --- a/client/components/Reader/TextPage/TextPage.vue +++ b/client/components/Reader/TextPage/TextPage.vue @@ -209,6 +209,7 @@ class TextPage extends Vue { this.parsed.p = this.p; this.parsed.w = this.w;// px, ширина текста this.parsed.font = this.font; + this.parsed.fontSize = this.fontSize; this.parsed.wordWrap = this.wordWrap; this.parsed.cutEmptyParagraphs = this.cutEmptyParagraphs; this.parsed.addEmptyParagraphs = this.addEmptyParagraphs; diff --git a/client/components/Reader/share/BookParser.js b/client/components/Reader/share/BookParser.js index 0c5de7fb..e00fd081 100644 --- a/client/components/Reader/share/BookParser.js +++ b/client/components/Reader/share/BookParser.js @@ -40,6 +40,7 @@ export default class BookParser { let bold = false; let italic = false; let space = 0; + let inPara = false; this.binary = {}; let binaryId = ''; @@ -149,8 +150,12 @@ export default class BookParser { if (tag == 'image') { let attrs = sax.getAttrsSync(tail); - if (attrs.href.value) - newParagraph(`${' '.repeat(maxImageLineCount)}`, maxImageLineCount); + if (attrs.href.value) { + if (inPara) + growParagraph(``, 0); + else + newParagraph(`${' '.repeat(maxImageLineCount)}`, maxImageLineCount); + } } if (path.indexOf('/fictionbook/body') == 0) { @@ -170,6 +175,8 @@ export default class BookParser { if ((tag == 'p' || tag == 'empty-line' || tag == 'v')) { newParagraph(' ', 1); + if (tag == 'p') + inPara = true; } if (tag == 'subtitle') { @@ -209,6 +216,10 @@ export default class BookParser { growParagraph(``, 0); } + if (tag == 'p') { + inPara = false; + } + if (tag == 'subtitle') { bold = false; } @@ -408,6 +419,23 @@ export default class BookParser { } break; } + case 'image-inline': { + let attrs = sax.getAttrsSync(tail); + let id = attrs.href.value; + if (id) { + let local = false; + if (id[0] == '#') { + id = id.substr(1); + local = true; + } + result.push({ + style: Object.assign({}, style), + image: {local, inline: true, id}, + text: '' + }); + } + break; + } } }; @@ -428,6 +456,8 @@ export default class BookParser { case 'image': image = {}; break; + case 'image-inline': + break; } }; @@ -570,8 +600,9 @@ export default class BookParser { let j = 0;//номер строки let style = {}; let ofs = 0;//смещение от начала параграфа para.offset + let imgW = 0; - // тут начинается самый замес, перенос по слогам и стилизация + // тут начинается самый замес, перенос по слогам и стилизация, а также изображения for (const part of parts) { style = part.style; @@ -608,6 +639,14 @@ export default class BookParser { continue; } + if (part.image.id && part.image.inline && this.showImages) { + const bin = this.binary[part.image.id]; + let imgH = (bin.h > this.fontSize ? this.fontSize : bin.h); + imgW += bin.w*imgH/bin.h; + line.parts.push({style, text: '', + image: {local: part.image.local, inline: true, id: part.image.id}}); + } + let words = part.text.split(' '); let sp1 = ''; @@ -621,7 +660,7 @@ export default class BookParser { str += sp1 + word; - let p = (j == 0 ? parsed.p : 0); + let p = (j == 0 ? parsed.p : 0) + imgW; p = (style.space ? p + parsed.p*style.space : p); let w = this.measureText(str, style) + p; let wordTail = word; @@ -676,6 +715,7 @@ export default class BookParser { partText = ''; sp2 = ''; str = wordTail; + imgW = 0; j++; } From dfa7013cbd25f1c02a5d8683cdd1d923961a6237 Mon Sep 17 00:00:00 2001 From: Book Pauk Date: Wed, 20 Feb 2019 21:08:23 +0700 Subject: [PATCH 10/10] =?UTF-8?q?=D0=92=D0=B5=D1=80=D1=81=D0=B8=D1=8F=200.?= =?UTF-8?q?4.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d7dada7b..8e5830c0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "Liberama", - "version": "0.3.5", + "version": "0.4.0", "engines": { "node": ">=10.0.0" },