From 1a13a0fee1e9e29b3d83da88e7dd4b839b001722 Mon Sep 17 00:00:00 2001 From: Book Pauk Date: Wed, 9 Dec 2020 22:19:14 +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=D0=BA=D0=BE=D0=BD=D0=B2=D0=B5=D1=80=D1=82=D0=B5?= =?UTF-8?q?=D1=80=D0=BE=D0=BC=20pdf?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/Reader/BookConverter/ConvertPdf.js | 30 +++++++++---------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/server/core/Reader/BookConverter/ConvertPdf.js b/server/core/Reader/BookConverter/ConvertPdf.js index de1432e2..07533441 100644 --- a/server/core/Reader/BookConverter/ConvertPdf.js +++ b/server/core/Reader/BookConverter/ConvertPdf.js @@ -59,7 +59,6 @@ class ConvertPdf extends ConvertHtml { let title = ''; let author = ''; - let prevTop = 0; let i = -1; const loadImage = async(image) => { @@ -97,10 +96,9 @@ class ConvertPdf extends ConvertHtml { //добавим закрывающий тег стиля line.text += line.tClose; - const f = (line.fonts.length ? fonts[line.fonts[0]] : null); - //проверим, возможно это заголовок if (line.fonts.length == 1 && line.pageWidth) { + const f = (line.fonts.length ? fonts[line.fonts[0]] : null); const centerLeft = (line.pageWidth - line.width)/2; if (f && f.isBold && Math.abs(centerLeft - line.left) < 3) { if (!sectionTitleFound) { @@ -112,12 +110,6 @@ class ConvertPdf extends ConvertHtml { } } - //добавим пустую строку, если надо - if (f && f.fontSize && Math.abs(pt - line.top) > f.fontSize*1.5) { - j++; - pl[j] = {text: '
'}; - } - //объединяем if (pt == 0 || Math.abs(pt - line.top) > 3) { j++; @@ -129,13 +121,25 @@ class ConvertPdf extends ConvertHtml { }); //заполняем lines + const lastIndex = i; pl.forEach(line => { putImage(line.top); + + //добавим пустую строку, если надо + const prevLine = (i > lastIndex ? lines[i] : {fonts: [], top: 0}); + if (prevLine && !prevLine.isImage) { + const f = (prevLine.fonts.length ? fonts[prevLine.fonts[0]] : (line.fonts.length ? fonts[line.fonts[0]] : null)); + if (f && f.fontSize && !line.isImage && line.top - prevLine.top > f.fontSize*1.8) { + i++; + lines[i] = {text: '
'}; + } + } + i++; lines[i] = line; }); pagelines = []; - prevTop = 0; + putImage(100000); }; const onStartNode = (tag, tail, singleTag, cutCounter, cutTag) => {// eslint-disable-line no-unused-vars @@ -171,7 +175,6 @@ class ConvertPdf extends ConvertHtml { }; putPageLines(); - putImage(100000); } if (tag == 'textline') { @@ -191,11 +194,7 @@ class ConvertPdf extends ConvertHtml { }; if (line.width != 0 || line.height != 0) { - if (Math.abs(prevTop - line.top) > 3) { - putImage(line.top); - } pagelines.push(line); - prevTop = line.top; } } @@ -255,7 +254,6 @@ class ConvertPdf extends ConvertHtml { }); putPageLines(); - putImage(100000); await Promise.all(loading); await utils.sleep(100);