Explorar el Código

Работа на двухстраничным режимом

Book Pauk hace 4 años
padre
commit
a207a0554c

+ 1 - 1
client/components/Reader/SettingsPage/include/ViewTab/Text.inc

@@ -123,7 +123,7 @@
 <div class="item row">
     <div class="label-2"></div>
     <div class="col row">
-        <q-checkbox v-model="imageFitWidth" :disable="!showImages" size="xs" label="Ширина не более размера экрана" />
+        <q-checkbox v-model="imageFitWidth" size="xs" label="Ширина не более размера страницы" :disable="!showImages || dualPageMode"/>
     </div>
 </div>
 

+ 11 - 10
client/components/Reader/TextPage/DrawHelper.js

@@ -19,7 +19,7 @@ export default class DrawHelper {
         return this.context.measureText(text).width;
     }
 
-    drawLine(line, lineIndex, sel, imageDrawn) {
+    drawLine(line, lineIndex, baseLineIndex, sel, imageDrawn) {
         /* line:
         {
             begin: Number,
@@ -81,7 +81,7 @@ export default class DrawHelper {
                     }
 
                     const left = (this.w - img.w)/2;
-                    const top = ((img.lineCount*this.lineHeight - img.h)/2) + (lineIndex - img.imageLine)*this.lineHeight;
+                    const top = ((img.lineCount*this.lineHeight - img.h)/2) + (lineIndex - baseLineIndex - img.imageLine)*this.lineHeight;
                     if (img.local) {
                         lineText += `<img src="data:${bin.type};base64,${bin.data}" style="position: absolute; left: ${left}px; top: ${top}px; ${resize}"/>`;
                     } else {
@@ -131,10 +131,11 @@ export default class DrawHelper {
 
         const boxH = this.h + (isScrolling ? this.lineHeight : 0);
         let out = `<div style="width: ${this.boxW}px; height: ${boxH}px;` + 
-            ` position: absolute; top: ${this.fontSize*this.textShift}px; color: ${this.textColor}; font: ${font}; ${justify}` +
+            ` position: relative; top: ${this.fontSize*this.textShift}px; color: ${this.textColor}; font: ${font}; ${justify}` +
             ` line-height: ${this.lineHeight}px; white-space: nowrap;">`;
 
-        let imageDrawn = new Set();
+        let imageDrawn1 = new Set();
+        let imageDrawn2 = new Set();
         let len = lines.length;
         const lineCount = this.pageLineCount + (isScrolling ? 1 : 0);
         len = (len > lineCount ? lineCount : len);
@@ -165,19 +166,19 @@ export default class DrawHelper {
         //отрисовка строк
         if (!this.dualPageMode) {
             for (let i = 0; i < len; i++) {
-                out += this.drawLine(lines[i], i, sel, imageDrawn);
+                out += this.drawLine(lines[i], i, 0, sel, imageDrawn1);
             }
         } else {
-            out += `<div style="width: ${this.w}px; margin: 0 ${this.dualIndentLR}px 0 ${this.dualIndentLR}px; display: inline-block;">`;
-            const l2 = len/2;
+            out += `<div style="width: ${this.w}px; margin: 0 ${this.dualIndentLR}px 0 ${this.dualIndentLR}px; position: relative; display: inline-block;">`;
+            const l2 = parseInt(Math.ceil(len/2), 10);
             for (let i = 0; i < l2; i++) {
-                out += this.drawLine(lines[i], i, sel, imageDrawn);
+                out += this.drawLine(lines[i], i, 0, sel, imageDrawn1);
             }
             out += '</div>';
 
-            out += `<div style="width: ${this.w}px; margin: 0 ${this.dualIndentLR}px 0 ${this.dualIndentLR}px; display: inline-block;">`;
+            out += `<div style="width: ${this.w}px; margin: 0 ${this.dualIndentLR}px 0 ${this.dualIndentLR}px; position: relative; display: inline-block;">`;
             for (let i = l2; i < len; i++) {
-                out += this.drawLine(lines[i], i, sel, imageDrawn);
+                out += this.drawLine(lines[i], i, l2, sel, imageDrawn2);
             }
             out += '</div>';
         }

+ 3 - 2
client/components/Reader/share/BookParser.js

@@ -20,6 +20,7 @@ const defaultSettings = {
     showInlineImagesInCenter: true, //выносить изображения в центр, работает на этапе первичного парсинга (parse)
     imageHeightLines: 100, //кол-во строк, максимальная высота изображения
     imageFitWidth: true, //ширина изображения не более ширины страницы
+    dualPageMode: false, //двухстраничный режим
     compactTextPerc: 0, //проценты, степень компактности текста
     testWidth: 0, //ширина тестовой строки, пересчитывается извне при изменении шрифта браузером
     isTesting: false, //тестовый режим
@@ -793,7 +794,7 @@ export default class BookParser {
             para.parsed.lineHeight === s.lineHeight &&
             para.parsed.showImages === s.showImages &&
             para.parsed.imageHeightLines === s.imageHeightLines &&
-            para.parsed.imageFitWidth === s.imageFitWidth &&
+            para.parsed.imageFitWidth === (s.imageFitWidth || s.dualPageMode) &&
             para.parsed.compactTextPerc === s.compactTextPerc &&
             para.parsed.testWidth === s.testWidth
             )
@@ -811,7 +812,7 @@ export default class BookParser {
             lineHeight: s.lineHeight,
             showImages: s.showImages,
             imageHeightLines: s.imageHeightLines,
-            imageFitWidth: s.imageFitWidth,
+            imageFitWidth: (s.imageFitWidth || s.dualPageMode),
             compactTextPerc: s.compactTextPerc,
             testWidth: s.testWidth,
             visible: true, //вычисляется позже