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

This commit is contained in:
Book Pauk
2019-01-16 02:49:53 +07:00
parent 0ec510b499
commit b45d4e1156
2 changed files with 10 additions and 9 deletions

View File

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

View File

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