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