fix lint
This commit is contained in:
parent
3d14c9c446
commit
19b85f12c7
30
lib/pen.js
30
lib/pen.js
@ -143,16 +143,16 @@ export default class Painter {
|
||||
}
|
||||
|
||||
_preProcess(view, notClip) {
|
||||
let width=0;
|
||||
let width = 0;
|
||||
let height;
|
||||
let extra;
|
||||
switch (view.type) {
|
||||
case 'text': {
|
||||
const textArray = view.text.split('\n');
|
||||
//处理多个连续的'\n'
|
||||
for(let i = 0; i < textArray.length ; ++i){
|
||||
if(textArray[i]===''){
|
||||
textArray[i]=' ';
|
||||
// 处理多个连续的'\n'
|
||||
for (let i = 0; i < textArray.length; ++i) {
|
||||
if (textArray[i] === '') {
|
||||
textArray[i] = ' ';
|
||||
}
|
||||
}
|
||||
const fontWeight = view.css.fontWeight === 'bold' ? 'bold' : 'normal';
|
||||
@ -160,9 +160,9 @@ export default class Painter {
|
||||
this.ctx.font = `normal ${fontWeight} ${view.css.fontSize.toPx()}px ${view.css.fontFamily ? view.css.fontFamily : 'sans-serif'}`;
|
||||
// this.ctx.setFontSize(view.css.fontSize.toPx());
|
||||
// 计算行数
|
||||
let lines=0;
|
||||
let linesArray=[];
|
||||
for(let i=0; i<textArray.length; ++i){
|
||||
let lines = 0;
|
||||
const linesArray = [];
|
||||
for (let i = 0; i < textArray.length; ++i) {
|
||||
const textLength = this.ctx.measureText(textArray[i]).width;
|
||||
const partWidth = view.css.width ? view.css.width.toPx() : textLength;
|
||||
const calLines = Math.ceil(textLength / partWidth);
|
||||
@ -363,24 +363,24 @@ export default class Painter {
|
||||
lines,
|
||||
lineHeight,
|
||||
textArray,
|
||||
linesArray
|
||||
linesArray,
|
||||
} = extra;
|
||||
// 如果设置了id,则保留 text 的长度
|
||||
if (view.id) {
|
||||
let textWidth = 0;
|
||||
for(let i = 0; i < textArray.length; ++i){
|
||||
for (let i = 0; i < textArray.length; ++i) {
|
||||
textWidth = this.ctx.measureText(textArray[i]).width > textWidth ? this.ctx.measureText(textArray[i]).width : textWidth;
|
||||
}
|
||||
this.globalTextWidth[view.id] = width ? (textWidth < width ? textWidth : width) : textWidth;
|
||||
}
|
||||
let lineIndex=0;
|
||||
for(let j = 0; j < textArray.length; ++j){
|
||||
let lineIndex = 0;
|
||||
for (let j = 0; j < textArray.length; ++j) {
|
||||
const preLineLength = Math.round(textArray[j].length / linesArray[j]);
|
||||
let start = 0;
|
||||
let alreadyCount = 0;
|
||||
for (let i = 0; i < linesArray[j]; ++i) {
|
||||
//绘制行数大于最大行数,则直接跳出循环
|
||||
if(lineIndex >= lines){
|
||||
// 绘制行数大于最大行数,则直接跳出循环
|
||||
if (lineIndex >= lines) {
|
||||
break;
|
||||
}
|
||||
alreadyCount = preLineLength;
|
||||
@ -402,7 +402,7 @@ export default class Painter {
|
||||
}
|
||||
start += text.length;
|
||||
// 如果是最后一行了,发现还有未绘制完的内容,则加...
|
||||
if (lineIndex === lines - 1 && (j < textArray.length -1 || start < textArray[j].length)) {
|
||||
if (lineIndex === lines - 1 && (j < textArray.length - 1 || start < textArray[j].length)) {
|
||||
while (this.ctx.measureText(`${text}...`).width > width) {
|
||||
if (text.length <= 1) {
|
||||
// 如果只有一个字符时,直接跳出循环
|
||||
|
||||
Loading…
Reference in New Issue
Block a user