From 1a7ceb333d575de1ac780c4856a4330580bae0e1 Mon Sep 17 00:00:00 2001 From: Book Pauk Date: Wed, 20 Feb 2019 20:57:34 +0700 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=BE=D0=B1=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=BA?= =?UTF-8?q?=D0=B0=20inline-=D0=B8=D0=B7=D0=BE=D0=B1=D1=80=D0=B0=D0=B6?= =?UTF-8?q?=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++; }