Merge branch 'release/0.3.0'
This commit is contained in:
@@ -23,17 +23,17 @@ export default class DrawHelper {
|
|||||||
if (!this.lastBook || this.pageLineCount < 1 || !this.book || !lines || !this.parsed.textLength)
|
if (!this.lastBook || this.pageLineCount < 1 || !this.book || !lines || !this.parsed.textLength)
|
||||||
return '';
|
return '';
|
||||||
|
|
||||||
const spaceWidth = this.measureText(' ', {});
|
const font = this.fontByStyle({});
|
||||||
|
const justify = (this.textAlignJustify ? 'text-align: justify; text-align-last: justify;' : '');
|
||||||
|
|
||||||
let out = `<div class="layout" style="width: ${this.realWidth}px; height: ${this.realHeight}px;` +
|
let out = `<div class="layout" style="width: ${this.w}px; height: ${this.h}px;` +
|
||||||
` color: ${this.textColor}">`;
|
` position: absolute; top: ${this.fontSize*this.textShift}px; color: ${this.textColor}; font: ${font}; ${justify}` +
|
||||||
|
` line-height: ${this.lineHeight}px;">`;
|
||||||
|
|
||||||
let len = lines.length;
|
let len = lines.length;
|
||||||
const lineCount = this.pageLineCount + (isScrolling ? 1 : 0);
|
const lineCount = this.pageLineCount + (isScrolling ? 1 : 0);
|
||||||
len = (len > lineCount ? lineCount : len);
|
len = (len > lineCount ? lineCount : len);
|
||||||
|
|
||||||
let y = this.fontSize*this.textShift;
|
|
||||||
|
|
||||||
for (let i = 0; i < len; i++) {
|
for (let i = 0; i < len; i++) {
|
||||||
const line = lines[i];
|
const line = lines[i];
|
||||||
/* line:
|
/* line:
|
||||||
@@ -47,77 +47,57 @@ export default class DrawHelper {
|
|||||||
text: String,
|
text: String,
|
||||||
}
|
}
|
||||||
}*/
|
}*/
|
||||||
|
let sel = new Set();
|
||||||
|
if (i == 0 && this.searching) {
|
||||||
|
let pureText = '';
|
||||||
|
for (const part of line.parts) {
|
||||||
|
pureText += part.text;
|
||||||
|
}
|
||||||
|
|
||||||
let indent = line.first ? this.p : 0;
|
pureText = pureText.toLowerCase();
|
||||||
|
let j = 0;
|
||||||
|
while (1) {// eslint-disable-line no-constant-condition
|
||||||
|
j = pureText.indexOf(this.needle, j);
|
||||||
|
if (j >= 0) {
|
||||||
|
for (let k = 0; k < this.needle.length; k++) {
|
||||||
|
sel.add(j + k);
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
break;
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let lineText = '';
|
let lineText = '';
|
||||||
let center = false;
|
let center = false;
|
||||||
let centerStyle = {};
|
let j = 0;
|
||||||
for (const part of line.parts) {
|
for (const part of line.parts) {
|
||||||
lineText += part.text;
|
let tOpen = (part.style.bold ? '<b>' : '');
|
||||||
|
tOpen += (part.style.italic ? '<i>' : '');
|
||||||
|
let tClose = (part.style.italic ? '</i>' : '');
|
||||||
|
tClose += (part.style.bold ? '</b>' : '');
|
||||||
|
|
||||||
|
let text = '';
|
||||||
|
if (i == 0 && this.searching) {
|
||||||
|
for (let k = 0; k < part.text.length; k++) {
|
||||||
|
text += (sel.has(j) ? `<ins>${part.text[k]}</ins>` : part.text[k]);
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
text = part.text;
|
||||||
|
|
||||||
|
lineText += `${tOpen}${text}${tClose}`;
|
||||||
|
|
||||||
center = center || part.style.center;
|
center = center || part.style.center;
|
||||||
if (part.style.center)
|
|
||||||
centerStyle = part.style;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let filled = false;
|
const centerStyle = (center ? `text-align: center; text-align-last: center; width: ${this.w}px` : '')
|
||||||
// если выравнивание по ширине включено
|
if (line.first)
|
||||||
if (this.textAlignJustify && !line.last && !center) {
|
lineText = `<span style="display: inline-block; margin-left: ${this.p}px"></span>${lineText}`;
|
||||||
const words = lineText.split(' ');
|
if (line.last || center)
|
||||||
|
lineText = `<span style="display: inline-block; ${centerStyle}">${lineText}</span>`;
|
||||||
|
|
||||||
if (words.length > 1) {
|
out += (i > 0 ? '<br>' : '') + lineText;
|
||||||
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 j = 0; j < partWords.length; j++) {
|
|
||||||
let f = font;
|
|
||||||
let style = part.style;
|
|
||||||
let word = partWords[j];
|
|
||||||
if (i == 0 && this.searching && word.toLowerCase().indexOf(this.needle) >= 0) {
|
|
||||||
style = Object.assign({}, part.style, {bold: true});
|
|
||||||
f = this.fontByStyle(style);
|
|
||||||
}
|
|
||||||
out += this.fillText(word, x, y, f);
|
|
||||||
x += this.measureText(word, style) + (j < partWords.length - 1 ? space : 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
filled = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// просто выводим текст
|
|
||||||
if (!filled) {
|
|
||||||
let x = indent;
|
|
||||||
x = (center ? (this.w - this.measureText(lineText, centerStyle))/2 : x);
|
|
||||||
for (const part of line.parts) {
|
|
||||||
let font = this.fontByStyle(part.style);
|
|
||||||
|
|
||||||
if (i == 0 && this.searching) {//для поиска, разбивка по словам
|
|
||||||
let partWords = part.text.split(' ');
|
|
||||||
for (let j = 0; j < partWords.length; j++) {
|
|
||||||
let f = font;
|
|
||||||
let style = part.style;
|
|
||||||
let word = partWords[j];
|
|
||||||
if (word.toLowerCase().indexOf(this.needle) >= 0) {
|
|
||||||
style = Object.assign({}, part.style, {bold: true});
|
|
||||||
f = this.fontByStyle(style);
|
|
||||||
}
|
|
||||||
out += this.fillText(word, x, y, f);
|
|
||||||
x += this.measureText(word, style) + (j < partWords.length - 1 ? spaceWidth : 0);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
out += this.fillText(part.text, x, y, font);
|
|
||||||
x += this.measureText(part.text, part.style);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
y += this.lineHeight;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
out += '</div>';
|
out += '</div>';
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<div ref="main" class="main">
|
<div ref="main" class="main">
|
||||||
<div class="layout back">
|
<div class="layout back" @wheel.prevent.stop="onMouseWheel">
|
||||||
<div v-html="background"></div>
|
<div v-html="background"></div>
|
||||||
<!-- img -->
|
<!-- img -->
|
||||||
</div>
|
</div>
|
||||||
@@ -436,15 +436,7 @@ class TextPage extends Vue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
startSearch(needle) {
|
startSearch(needle) {
|
||||||
this.drawHelper.needle = '';
|
this.drawHelper.needle = needle;
|
||||||
const words = needle.split(' ');
|
|
||||||
for (const word of words) {
|
|
||||||
if (word != '') {
|
|
||||||
this.drawHelper.needle = word;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.drawHelper.searching = true;
|
this.drawHelper.searching = true;
|
||||||
this.draw();
|
this.draw();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ const fonts = [
|
|||||||
{name: 'Arimo', fontVertShift: 0},
|
{name: 'Arimo', fontVertShift: 0},
|
||||||
{name: 'Avrile', fontVertShift: -10},
|
{name: 'Avrile', fontVertShift: -10},
|
||||||
{name: 'OpenSans', fontVertShift: -5},
|
{name: 'OpenSans', fontVertShift: -5},
|
||||||
{name: 'Roboto', fontVertShift: 10},
|
{name: 'Roboto', fontVertShift: 0},
|
||||||
{name: 'Rubik', fontVertShift: 0},
|
{name: 'Rubik', fontVertShift: 0},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "Liberama",
|
"name": "Liberama",
|
||||||
"version": "0.2.2",
|
"version": "0.3.0",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=10.0.0"
|
"node": ">=10.0.0"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -284,11 +284,9 @@ class BookConverter {
|
|||||||
openTag('p');
|
openTag('p');
|
||||||
break;
|
break;
|
||||||
case 'i':
|
case 'i':
|
||||||
openTag('emphasis');
|
|
||||||
italic = true;
|
italic = true;
|
||||||
break;
|
break;
|
||||||
case 'b':
|
case 'b':
|
||||||
openTag('strong');
|
|
||||||
bold = true;
|
bold = true;
|
||||||
break;
|
break;
|
||||||
case 'div':
|
case 'div':
|
||||||
@@ -334,11 +332,9 @@ class BookConverter {
|
|||||||
closeTag('p');
|
closeTag('p');
|
||||||
break;
|
break;
|
||||||
case 'i':
|
case 'i':
|
||||||
closeTag('emphasis');
|
|
||||||
italic = false;
|
italic = false;
|
||||||
break;
|
break;
|
||||||
case 'b':
|
case 'b':
|
||||||
closeTag('strong');
|
|
||||||
bold = false;
|
bold = false;
|
||||||
break;
|
break;
|
||||||
case 'div':
|
case 'div':
|
||||||
|
|||||||
Reference in New Issue
Block a user