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

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>
<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;
}

View File

@@ -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;