Добавил разбивку длинных слов без пробелов
This commit is contained in:
@@ -33,6 +33,8 @@ import {sleep} from '../../../share/utils';
|
|||||||
import bookManager from '../share/bookManager';
|
import bookManager from '../share/bookManager';
|
||||||
import DrawHelper from './DrawHelper';
|
import DrawHelper from './DrawHelper';
|
||||||
|
|
||||||
|
const minLayoutWidth = 100;
|
||||||
|
|
||||||
export default @Component({
|
export default @Component({
|
||||||
watch: {
|
watch: {
|
||||||
bookPos: function(newValue) {
|
bookPos: function(newValue) {
|
||||||
@@ -130,6 +132,9 @@ class TextPage extends Vue {
|
|||||||
this.parsed.w = this.w;// px, ширина текста
|
this.parsed.w = this.w;// px, ширина текста
|
||||||
this.parsed.font = this.font;
|
this.parsed.font = this.font;
|
||||||
this.parsed.wordWrap = this.wordWrap;
|
this.parsed.wordWrap = this.wordWrap;
|
||||||
|
let t = '';
|
||||||
|
while (this.measureText(t, {}) < this.w) t += 'Щ';
|
||||||
|
this.parsed.maxWordLength = t.length - 1;
|
||||||
this.parsed.measureText = this.measureText;
|
this.parsed.measureText = this.measureText;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -316,8 +321,13 @@ class TextPage extends Vue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
draw() {
|
draw() {
|
||||||
if (this.w < 10)
|
if (this.w < minLayoutWidth) {
|
||||||
|
this.page1 = null;
|
||||||
|
this.page2 = null;
|
||||||
|
this.statusBar = null;
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (this.book && this.bookPos > 0 && this.bookPos >= this.parsed.textLength) {
|
if (this.book && this.bookPos > 0 && this.bookPos >= this.parsed.textLength) {
|
||||||
this.doEnd();
|
this.doEnd();
|
||||||
return;
|
return;
|
||||||
@@ -451,6 +461,11 @@ class TextPage extends Vue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
drawStatusBar() {
|
drawStatusBar() {
|
||||||
|
if (this.w < minLayoutWidth) {
|
||||||
|
this.statusBar = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (this.showStatusBar && this.linesDown) {
|
if (this.showStatusBar && this.linesDown) {
|
||||||
const lines = this.linesDown;
|
const lines = this.linesDown;
|
||||||
let i = this.pageLineCount;
|
let i = this.pageLineCount;
|
||||||
@@ -764,6 +779,7 @@ class TextPage extends Vue {
|
|||||||
padding: 0;
|
padding: 0;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
position: relative;
|
position: relative;
|
||||||
|
min-width: 200px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.layout {
|
.layout {
|
||||||
|
|||||||
@@ -282,6 +282,32 @@ export default class BookParser {
|
|||||||
onStartNode, onEndNode, onTextNode
|
onStartNode, onEndNode, onTextNode
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
//длинные слова (или белиберду без пробелов) тоже разобьем
|
||||||
|
|
||||||
|
const maxWordLength = this.maxWordLength;
|
||||||
|
const parts = result;
|
||||||
|
result = [];
|
||||||
|
for (const part of parts) {
|
||||||
|
let p = part;
|
||||||
|
let i = 0;
|
||||||
|
let spaceIndex = -1;
|
||||||
|
while (i < p.text.length) {
|
||||||
|
if (p.text[i] == ' ')
|
||||||
|
spaceIndex = i;
|
||||||
|
|
||||||
|
if (i - spaceIndex >= maxWordLength && i < p.text.length - 1 &&
|
||||||
|
this.measureText(p.text.substr(spaceIndex + 1, i - spaceIndex), p.style) >= this.w - this.p) {
|
||||||
|
result.push({style: p.style, text: p.text.substr(0, i + 1)});
|
||||||
|
p = {style: p.style, text: p.text.substr(i + 1)};
|
||||||
|
spaceIndex = -1;
|
||||||
|
i = -1;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
result.push(p);
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -343,6 +369,7 @@ export default class BookParser {
|
|||||||
para.parsed.w === this.w &&
|
para.parsed.w === this.w &&
|
||||||
para.parsed.p === this.p &&
|
para.parsed.p === this.p &&
|
||||||
para.parsed.wordWrap === this.wordWrap &&
|
para.parsed.wordWrap === this.wordWrap &&
|
||||||
|
para.parsed.maxWordLength === this.maxWordLength &&
|
||||||
para.parsed.font === this.font
|
para.parsed.font === this.font
|
||||||
)
|
)
|
||||||
return para.parsed;
|
return para.parsed;
|
||||||
@@ -351,6 +378,7 @@ export default class BookParser {
|
|||||||
w: this.w,
|
w: this.w,
|
||||||
p: this.p,
|
p: this.p,
|
||||||
wordWrap: this.wordWrap,
|
wordWrap: this.wordWrap,
|
||||||
|
maxWordLength: this.maxWordLength,
|
||||||
font: this.font,
|
font: this.font,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user