Промежуточный коммит

This commit is contained in:
Book Pauk
2019-01-16 02:24:24 +07:00
parent cd2d429012
commit 0ec510b499
2 changed files with 34 additions and 5 deletions

View File

@@ -41,7 +41,6 @@
</div> </div>
</el-header> </el-header>
<pre>{{ lastOpenedBook }}</pre>
<el-main> <el-main>
<keep-alive> <keep-alive>
<component ref="page" :is="pageActive" @load-book="loadBook" @book-pos-changed="bookPosChanged"></component> <component ref="page" :is="pageActive" @load-book="loadBook" @book-pos-changed="bookPosChanged"></component>

View File

@@ -3,8 +3,6 @@ import {sleep} from '../../../share/utils';
export default class BookParser { export default class BookParser {
constructor() { constructor() {
this.parser = new EasySAXParser();
// defaults // defaults
this.p = 30;// px, отступ параграфа this.p = 30;// px, отступ параграфа
this.w = 300;// px, ширина страницы this.w = 300;// px, ширина страницы
@@ -87,7 +85,7 @@ export default class BookParser {
paraOffset += p.length; paraOffset += p.length;
}; };
const parser = this.parser; const parser = new EasySAXParser();
parser.on('error', (msgError) => {// eslint-disable-line no-unused-vars parser.on('error', (msgError) => {// eslint-disable-line no-unused-vars
}); });
@@ -222,6 +220,20 @@ export default class BookParser {
return result; return result;
} }
removeTags(s) {
let result = '';
const parser = new EasySAXParser();
parser.on('textNode', (text) => {
result += text;
});
parser.parse(s);
return result;
}
parsePara(paraIndex) { parsePara(paraIndex) {
const para = this.para[paraIndex]; const para = this.para[paraIndex];
@@ -250,7 +262,25 @@ export default class BookParser {
} }
}*/ }*/
// // тут начинается самый замес, перенос и выравниване по ширине
const text = this.removeTags(para.text);
const words = text.split(' ');
let line = {begin: para.offset, parts: []};
let part = '';
for (let i = 0; i < words.length; i++) {
const word = words[i];
if (i > 0)
part += ' ';
part += word;
if (this.measureText(part) >= parsed.w) {
line.parts.push(part);
line.end = line.begin + part.length - 1;
lines.push(line);
part = '';
line = {begin: line.end + 1, parts: []};
}
}
parsed.lines = lines; parsed.lines = lines;
para.parsed = parsed; para.parsed = parsed;