فهرست منبع

Поправки багов

Book Pauk 6 سال پیش
والد
کامیت
b45d4e1156
2فایلهای تغییر یافته به همراه10 افزوده شده و 9 حذف شده
  1. 4 3
      client/components/Reader/TextPage/TextPage.vue
  2. 6 6
      client/components/Reader/share/BookParser.js

+ 4 - 3
client/components/Reader/TextPage/TextPage.vue

@@ -1,5 +1,6 @@
 <template>
     <div ref="main" class="main">
+        <!--pre>{{ meta }}</pre-->
         <p v-for="item in items" :key="item.id">
             {{ item.text }}
         </p>        
@@ -23,6 +24,7 @@ export default @Component({
     },
 })
 class TextPage extends Vue {
+    meta = null;
     lastBook = null;
     bookPos = 0;
 
@@ -69,7 +71,7 @@ class TextPage extends Vue {
                     if (style == 'bold')
                         return text.length*12;
                     else
-                        return text.length*10;
+                        return text.length*3;
                 };                
 
                 this.parsed = parsed;
@@ -87,11 +89,11 @@ class TextPage extends Vue {
 
         if (!this.book)
             return;
-
         const lines = this.parsed.getLines(this.bookPos, 30);
 
         let newItems = [];
         for (const line of lines) {
+console.log(line);
             /* line:
             {
                 begin: Number,
@@ -108,7 +110,6 @@ class TextPage extends Vue {
             }
             newItems.push(item);
         }
-
         this.items = newItems;
     }
 

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

@@ -199,13 +199,12 @@ export default class BookParser {
 
     findParaIndex(bookPos) {
         let result = undefined;
- 
         //дихотомия
         let first = 0;
         let last = this.para.length - 1;
         while (first < last) {
             let mid = first + Math.floor((last - first)/2);
-            if (bookPos >= this.para[mid].offset)
+            if (bookPos <= this.para[mid].offset)
                 last = mid;
             else
                 first = mid + 1;
@@ -229,7 +228,7 @@ export default class BookParser {
             result += text;
         });
 
-        parser.parse(s);
+        parser.parse(`<p>${s}</p>`);
 
         return result;
     }
@@ -264,6 +263,7 @@ export default class BookParser {
         
         // тут начинается самый замес, перенос и выравниване по ширине
         const text = this.removeTags(para.text);
+
         const words = text.split(' ');
         let line = {begin: para.offset, parts: []};
         let part = '';
@@ -273,8 +273,8 @@ export default class BookParser {
                 part += ' ';
             part += word;
 
-            if (this.measureText(part) >= parsed.w) {
-                line.parts.push(part);
+            if (this.measureText(part) >= parsed.w || i == words.length - 1) {
+                line.parts.push({style: '', text: part});
                 line.end = line.begin + part.length - 1;
                 lines.push(line);
                 part = '';
@@ -296,7 +296,7 @@ export default class BookParser {
         let last = lines.length - 1;
         while (first < last) {
             let mid = first + Math.floor((last - first)/2);
-            if (bookPos >= lines[mid].begin)
+            if (bookPos <= lines[mid].begin)
                 last = mid;
             else
                 first = mid + 1;