format and fix bugs
This commit is contained in:
parent
5f84e5943e
commit
7dac57c93b
55
lib/pen.js
55
lib/pen.js
@ -85,7 +85,13 @@ export default class Painter {
|
||||
}
|
||||
}
|
||||
|
||||
_border({ borderRadius = 0, width, height, borderWidth = 0, borderStyle = 'solid' }) {
|
||||
_border({
|
||||
borderRadius = 0,
|
||||
width,
|
||||
height,
|
||||
borderWidth = 0,
|
||||
borderStyle = 'solid'
|
||||
}) {
|
||||
let r1 = 0,
|
||||
r2 = 0,
|
||||
r3 = 0,
|
||||
@ -144,7 +150,12 @@ export default class Painter {
|
||||
// globalAlpha 在 1.9.90 起支持,低版本下无效,但把 fillStyle 设为了 white,相对默认的 black 要好点
|
||||
this.ctx.globalAlpha = 0;
|
||||
this.ctx.fillStyle = 'white';
|
||||
this._border({ borderRadius, width, height, borderStyle })
|
||||
this._border({
|
||||
borderRadius,
|
||||
width,
|
||||
height,
|
||||
borderStyle
|
||||
})
|
||||
this.ctx.fill();
|
||||
// 在 ios 的 6.6.6 版本上 clip 有 bug,禁掉此类型上的 clip,也就意味着,在此版本微信的 ios 设备下无法使用 border 属性
|
||||
if (!(getApp().systemInfo &&
|
||||
@ -175,7 +186,13 @@ export default class Painter {
|
||||
this.ctx.save();
|
||||
this._preProcess(view, true);
|
||||
this.ctx.strokeStyle = (borderColor || 'black');
|
||||
this._border({ borderRadius, width, height, borderWidth, borderStyle })
|
||||
this._border({
|
||||
borderRadius,
|
||||
width,
|
||||
height,
|
||||
borderWidth,
|
||||
borderStyle
|
||||
})
|
||||
this.ctx.stroke();
|
||||
this.ctx.restore();
|
||||
}
|
||||
@ -196,7 +213,9 @@ export default class Painter {
|
||||
}
|
||||
const fontWeight = view.css.fontWeight === 'bold' ? 'bold' : 'normal';
|
||||
const textStyle = view.css.textStyle === 'italic' ? 'italic' : 'normal';
|
||||
const fontSize = view.css.fontSize ? view.css.fontSize.toPx() : '20rpx'.toPx();
|
||||
if (!view.css.fontSize) {
|
||||
view.css.fontSize = '20rpx';
|
||||
}
|
||||
this.ctx.font = `${textStyle} ${fontWeight} ${view.css.fontSize.toPx()}px ${view.css.fontFamily ? view.css.fontFamily : 'sans-serif'}`;
|
||||
// 计算行数
|
||||
let lines = 0;
|
||||
@ -547,7 +566,7 @@ export default class Painter {
|
||||
}
|
||||
let lineIndex = 0;
|
||||
for (let j = 0; j < textArray.length; ++j) {
|
||||
const preLineLength = Math.floor(textArray[j].length / linesArray[j]);
|
||||
const preLineLength = Math.ceil(textArray[j].length / linesArray[j]);
|
||||
let start = 0;
|
||||
let alreadyCount = 0;
|
||||
for (let i = 0; i < linesArray[j]; ++i) {
|
||||
@ -638,7 +657,17 @@ export default class Painter {
|
||||
this.ctx.stroke();
|
||||
}
|
||||
if (!this.isMoving) {
|
||||
this.callbackInfo.lineArray ? this.callbackInfo.lineArray.push({ text, x, y, measuredWith }) : this.callbackInfo.lineArray = [{ text, x, y, measuredWith }]
|
||||
this.callbackInfo.lineArray ? this.callbackInfo.lineArray.push({
|
||||
text,
|
||||
x,
|
||||
y,
|
||||
measuredWith
|
||||
}) : this.callbackInfo.lineArray = [{
|
||||
text,
|
||||
x,
|
||||
y,
|
||||
measuredWith
|
||||
}]
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -658,8 +687,18 @@ export default class Painter {
|
||||
} else {
|
||||
this.ctx.fillStyle = view.css.color;
|
||||
}
|
||||
const { borderRadius, borderStyle, borderWidth } = view.css
|
||||
this._border({ borderRadius, width, height, borderWidth, borderStyle })
|
||||
const {
|
||||
borderRadius,
|
||||
borderStyle,
|
||||
borderWidth
|
||||
} = view.css
|
||||
this._border({
|
||||
borderRadius,
|
||||
width,
|
||||
height,
|
||||
borderWidth,
|
||||
borderStyle
|
||||
})
|
||||
this.ctx.fill();
|
||||
this.ctx.restore();
|
||||
this._doBorder(view, width, height);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user