Рефакторинг
This commit is contained in:
@@ -360,10 +360,13 @@ class TextPage extends Vue {
|
|||||||
this.linesDown = this.linesDownNext;
|
this.linesDown = this.linesDownNext;
|
||||||
this.linesUp = this.linesUpNext;
|
this.linesUp = this.linesUpNext;
|
||||||
} else {
|
} else {
|
||||||
|
const lines = this.getLines(this.bookPos);
|
||||||
|
this.linesDown = lines.linesDown;
|
||||||
|
this.linesUp = lines.linesUp;
|
||||||
if (this.toggleLayout)
|
if (this.toggleLayout)
|
||||||
this.page1 = this.drawPage(this.bookPos);
|
this.page1 = this.drawPage(lines.linesDown);
|
||||||
else
|
else
|
||||||
this.page2 = this.drawPage(this.bookPos);
|
this.page2 = this.drawPage(lines.linesDown);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.currentTransition) {
|
if (this.currentTransition) {
|
||||||
@@ -386,100 +389,99 @@ class TextPage extends Vue {
|
|||||||
this.doEnd();
|
this.doEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
drawPage(bookPos, nextChangeLines) {
|
getLines(bookPos) {
|
||||||
|
if (!this.parsed || this.pageLineCount < 1)
|
||||||
|
return {};
|
||||||
|
|
||||||
|
return {
|
||||||
|
linesDown: this.parsed.getLines(bookPos, 2*this.pageLineCount),
|
||||||
|
linesUp: this.parsed.getLines(bookPos, -2*this.pageLineCount)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
drawPage(lines) {
|
||||||
if (!this.lastBook || this.pageLineCount < 1)
|
if (!this.lastBook || this.pageLineCount < 1)
|
||||||
return '';
|
return '';
|
||||||
|
|
||||||
let out = `<div class="layout" style="width: ${this.realWidth}px; height: ${this.realHeight}px;` +
|
let out = `<div class="layout" style="width: ${this.realWidth}px; height: ${this.realHeight}px;` +
|
||||||
` color: ${this.textColor}; background-color: ${this.backgroundColor}">`;
|
` color: ${this.textColor}; background-color: ${this.backgroundColor}">`;
|
||||||
|
|
||||||
if (!this.book || !this.parsed.textLength) {
|
if (!this.book || !lines || !this.parsed.textLength) {
|
||||||
out += '</div>';
|
out += '</div>';
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
const spaceWidth = this.measureText(' ', {});
|
const spaceWidth = this.measureText(' ', {});
|
||||||
|
|
||||||
const lines = this.parsed.getLines(bookPos, 2*this.pageLineCount);
|
let y = this.indentTB - this.lineInterval/2 + (this.h - this.pageLineCount*this.lineHeight)/2 + this.fontSize*this.fontShift;
|
||||||
if (!nextChangeLines) {
|
if (this.showStatusBar)
|
||||||
this.linesDown = lines;
|
y += this.statusBarHeight*(this.statusBarTop ? 1 : 0);
|
||||||
this.linesUp = this.parsed.getLines(bookPos, -2*this.pageLineCount);
|
|
||||||
} else {
|
|
||||||
this.linesDownNext = lines;
|
|
||||||
this.linesUpNext = this.parsed.getLines(bookPos, -2*this.pageLineCount);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (lines) {
|
let len = lines.length;
|
||||||
let y = this.indentTB - this.lineInterval/2 + (this.h - this.pageLineCount*this.lineHeight)/2 + this.fontSize*this.fontShift;
|
len = (len > this.pageLineCount ? len = this.pageLineCount : len);
|
||||||
if (this.showStatusBar)
|
for (let i = 0; i < len; i++) {
|
||||||
y += this.statusBarHeight*(this.statusBarTop ? 1 : 0);
|
const line = lines[i];
|
||||||
|
/* line:
|
||||||
let len = lines.length;
|
{
|
||||||
len = (len > this.pageLineCount ? len = this.pageLineCount : len);
|
begin: Number,
|
||||||
for (let i = 0; i < len; i++) {
|
end: Number,
|
||||||
const line = lines[i];
|
first: Boolean,
|
||||||
/* line:
|
last: Boolean,
|
||||||
{
|
parts: array of {
|
||||||
begin: Number,
|
style: {bold: Boolean, italic: Boolean, center: Boolean}
|
||||||
end: Number,
|
text: String,
|
||||||
first: Boolean,
|
|
||||||
last: Boolean,
|
|
||||||
parts: array of {
|
|
||||||
style: {bold: Boolean, italic: Boolean, center: Boolean}
|
|
||||||
text: String,
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
let indent = this.indentLR + (line.first ? this.p : 0);
|
|
||||||
|
|
||||||
let lineText = '';
|
|
||||||
let center = false;
|
|
||||||
let centerStyle = {};
|
|
||||||
for (const part of line.parts) {
|
|
||||||
lineText += part.text;
|
|
||||||
center = center || part.style.center;
|
|
||||||
if (part.style.center)
|
|
||||||
centerStyle = part.style.center;
|
|
||||||
}
|
}
|
||||||
|
}*/
|
||||||
|
|
||||||
let filled = false;
|
let indent = this.indentLR + (line.first ? this.p : 0);
|
||||||
// если выравнивание по ширине включено
|
|
||||||
if (this.textAlignJustify && !line.last && !center) {
|
|
||||||
const words = lineText.split(' ');
|
|
||||||
|
|
||||||
if (words.length > 1) {
|
let lineText = '';
|
||||||
const spaceCount = words.length - 1;
|
let center = false;
|
||||||
|
let centerStyle = {};
|
||||||
const space = (this.w - line.width + spaceWidth*spaceCount)/spaceCount;
|
for (const part of line.parts) {
|
||||||
|
lineText += part.text;
|
||||||
let x = indent;
|
center = center || part.style.center;
|
||||||
for (const part of line.parts) {
|
if (part.style.center)
|
||||||
const font = this.fontByStyle(part.style);
|
centerStyle = part.style.center;
|
||||||
let partWords = part.text.split(' ');
|
|
||||||
|
|
||||||
for (let i = 0; i < partWords.length; i++) {
|
|
||||||
let word = partWords[i];
|
|
||||||
out += this.drawHelper.fillText(word, x, y, font);
|
|
||||||
x += this.measureText(word, part.style) + (i < partWords.length - 1 ? space : 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
filled = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// просто выводим текст
|
|
||||||
if (!filled) {
|
|
||||||
let x = indent;
|
|
||||||
x = (center ? this.indent + (this.w - this.measureText(lineText, centerStyle))/2 : x);
|
|
||||||
for (const part of line.parts) {
|
|
||||||
let text = part.text;
|
|
||||||
const font = this.fontByStyle(part.style);
|
|
||||||
out += this.drawHelper.fillText(text, x, y, font);
|
|
||||||
x += this.measureText(text, part.style);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
y += this.lineHeight;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let filled = false;
|
||||||
|
// если выравнивание по ширине включено
|
||||||
|
if (this.textAlignJustify && !line.last && !center) {
|
||||||
|
const words = lineText.split(' ');
|
||||||
|
|
||||||
|
if (words.length > 1) {
|
||||||
|
const spaceCount = words.length - 1;
|
||||||
|
|
||||||
|
const space = (this.w - line.width + spaceWidth*spaceCount)/spaceCount;
|
||||||
|
|
||||||
|
let x = indent;
|
||||||
|
for (const part of line.parts) {
|
||||||
|
const font = this.fontByStyle(part.style);
|
||||||
|
let partWords = part.text.split(' ');
|
||||||
|
|
||||||
|
for (let i = 0; i < partWords.length; i++) {
|
||||||
|
let word = partWords[i];
|
||||||
|
out += this.drawHelper.fillText(word, x, y, font);
|
||||||
|
x += this.measureText(word, part.style) + (i < partWords.length - 1 ? space : 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
filled = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// просто выводим текст
|
||||||
|
if (!filled) {
|
||||||
|
let x = indent;
|
||||||
|
x = (center ? this.indent + (this.w - this.measureText(lineText, centerStyle))/2 : x);
|
||||||
|
for (const part of line.parts) {
|
||||||
|
let text = part.text;
|
||||||
|
const font = this.fontByStyle(part.style);
|
||||||
|
out += this.drawHelper.fillText(text, x, y, font);
|
||||||
|
x += this.measureText(text, part.style);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
y += this.lineHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
out += '</div>';
|
out += '</div>';
|
||||||
@@ -555,11 +557,15 @@ class TextPage extends Vue {
|
|||||||
i--;
|
i--;
|
||||||
if (i >= 0 && this.linesDown.length > i) {
|
if (i >= 0 && this.linesDown.length > i) {
|
||||||
this.bookPosPrepared = this.linesDown[i].begin;
|
this.bookPosPrepared = this.linesDown[i].begin;
|
||||||
|
|
||||||
|
const lines = this.getLines(this.bookPosPrepared);
|
||||||
|
this.linesDownNext = lines.linesDown;
|
||||||
|
this.linesUpNext = lines.linesUp;
|
||||||
|
|
||||||
if (this.toggleLayout)
|
if (this.toggleLayout)
|
||||||
this.page2 = this.drawPage(this.bookPosPrepared, true);//наоборот
|
this.page2 = this.drawPage(lines.linesDown);//наоборот
|
||||||
else
|
else
|
||||||
this.page1 = this.drawPage(this.bookPosPrepared, true);
|
this.page1 = this.drawPage(lines.linesDown);
|
||||||
|
|
||||||
this.pagePrepared = true;
|
this.pagePrepared = true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user