瀏覽代碼

Добавлен параметр compactTextPerc

Book Pauk 5 年之前
父節點
當前提交
39f78ce7e8

+ 13 - 0
client/components/Reader/SettingsPage/SettingsPage.vue

@@ -284,6 +284,19 @@
                                 <el-checkbox v-model="textAlignJustify">По ширине</el-checkbox>
                                 <el-checkbox v-model="textAlignJustify">По ширине</el-checkbox>
                                 <el-checkbox v-model="wordWrap">Перенос по слогам</el-checkbox>
                                 <el-checkbox v-model="wordWrap">Перенос по слогам</el-checkbox>
                             </el-form-item>
                             </el-form-item>
+                            <el-form-item label="">
+                                <el-col :span="12">
+                                    Компактность
+                                </el-col>
+                                <el-tooltip :open-delay="500" effect="light" placement="top">
+                                    <template slot="content">
+                                        Степень компактности текста в процентах.<br>
+                                        Чем больше компактность, тем хуже выравнивание<br>
+                                        по правому краю.
+                                    </template>
+                                    <el-input-number v-model="compactTextPerc" :min="0" :max="100"></el-input-number>
+                                </el-tooltip>
+                            </el-form-item>
                             <el-form-item label="Обработка">
                             <el-form-item label="Обработка">
                                 <el-checkbox v-model="cutEmptyParagraphs">Убирать пустые строки</el-checkbox>
                                 <el-checkbox v-model="cutEmptyParagraphs">Убирать пустые строки</el-checkbox>
                             </el-form-item>
                             </el-form-item>

+ 1 - 0
client/components/Reader/TextPage/TextPage.vue

@@ -221,6 +221,7 @@ class TextPage extends Vue {
             this.parsed.showInlineImagesInCenter = this.showInlineImagesInCenter;
             this.parsed.showInlineImagesInCenter = this.showInlineImagesInCenter;
             this.parsed.imageHeightLines = this.imageHeightLines;
             this.parsed.imageHeightLines = this.imageHeightLines;
             this.parsed.imageFitWidth = this.imageFitWidth;
             this.parsed.imageFitWidth = this.imageFitWidth;
+            this.parsed.compactTextPerc = this.compactTextPerc;
         }
         }
 
 
         //scrolling page
         //scrolling page

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

@@ -620,7 +620,8 @@ export default class BookParser {
             para.parsed.addEmptyParagraphs === this.addEmptyParagraphs &&
             para.parsed.addEmptyParagraphs === this.addEmptyParagraphs &&
             para.parsed.showImages === this.showImages &&
             para.parsed.showImages === this.showImages &&
             para.parsed.imageHeightLines === this.imageHeightLines &&
             para.parsed.imageHeightLines === this.imageHeightLines &&
-            para.parsed.imageFitWidth === this.imageFitWidth
+            para.parsed.imageFitWidth === this.imageFitWidth &&
+            para.parsed.compactTextPerc === this.compactTextPerc
             )
             )
             return para.parsed;
             return para.parsed;
 
 
@@ -635,6 +636,7 @@ export default class BookParser {
             showImages: this.showImages,
             showImages: this.showImages,
             imageHeightLines: this.imageHeightLines,
             imageHeightLines: this.imageHeightLines,
             imageFitWidth: this.imageFitWidth,
             imageFitWidth: this.imageFitWidth,
+            compactTextPerc: this.compactTextPerc,
             visible: !(
             visible: !(
                 (this.cutEmptyParagraphs && para.cut) ||
                 (this.cutEmptyParagraphs && para.cut) ||
                 (para.addIndex > this.addEmptyParagraphs)
                 (para.addIndex > this.addEmptyParagraphs)
@@ -665,6 +667,7 @@ export default class BookParser {
         let style = {};
         let style = {};
         let ofs = 0;//смещение от начала параграфа para.offset
         let ofs = 0;//смещение от начала параграфа para.offset
         let imgW = 0;
         let imgW = 0;
+        const compactWidth = this.measureText('W', {})*this.compactTextPerc/100;
         // тут начинается самый замес, перенос по слогам и стилизация, а также изображения
         // тут начинается самый замес, перенос по слогам и стилизация, а также изображения
         for (const part of parts) {
         for (const part of parts) {
             style = part.style;
             style = part.style;
@@ -749,7 +752,7 @@ export default class BookParser {
                 p = (style.space ? p + parsed.p*style.space : p);
                 p = (style.space ? p + parsed.p*style.space : p);
                 let w = this.measureText(str, style) + p;
                 let w = this.measureText(str, style) + p;
                 let wordTail = word;
                 let wordTail = word;
-                if (w > parsed.w && prevStr != '') {
+                if (w > parsed.w + compactWidth && prevStr != '') {
                     if (parsed.wordWrap) {//по слогам
                     if (parsed.wordWrap) {//по слогам
                         let slogi = this.splitToSlogi(word);
                         let slogi = this.splitToSlogi(word);
 
 
@@ -762,7 +765,7 @@ export default class BookParser {
                             for (let k = 0; k < slogiLen - 1; k++) {
                             for (let k = 0; k < slogiLen - 1; k++) {
                                 let slog = slogi[0];
                                 let slog = slogi[0];
                                 let ww = this.measureText(s + slog + (slog[slog.length - 1] == '-' ? '' : '-'), style) + p;
                                 let ww = this.measureText(s + slog + (slog[slog.length - 1] == '-' ? '' : '-'), style) + p;
-                                if (ww <= parsed.w) {
+                                if (ww <= parsed.w + compactWidth) {
                                     s += slog;
                                     s += slog;
                                     ss += slog;
                                     ss += slog;
                                 } else 
                                 } else 

+ 1 - 0
client/store/modules/reader.js

@@ -176,6 +176,7 @@ const settingDefaults = {
     blinkCachedLoad: true,
     blinkCachedLoad: true,
     showImages: true,
     showImages: true,
     showInlineImagesInCenter: true,
     showInlineImagesInCenter: true,
+    compactTextPerc: 0,
     imageHeightLines: 100,
     imageHeightLines: 100,
     imageFitWidth: true,
     imageFitWidth: true,
     showServerStorageMessages: true,
     showServerStorageMessages: true,