优化流程
This commit is contained in:
parent
67058f7997
commit
fc86eeb33f
29
lib/pen.js
29
lib/pen.js
@ -81,34 +81,29 @@ 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,
|
let r1 = 0,
|
||||||
r2 = 0,
|
r2 = 0,
|
||||||
r3 = 0,
|
r3 = 0,
|
||||||
r4 = 0
|
r4 = 0
|
||||||
if (borderRadius) {
|
if (borderRadius) {
|
||||||
const border = borderRadius.split(' ')
|
const border = borderRadius.split(/\s+/)
|
||||||
if (border.length === 1) {
|
if (border.length === 4) {
|
||||||
r1 = r2 = r3 = r4 = Math.min(borderRadius === '0' ? 0 : borderRadius.toPx(), width / 2, height / 2);
|
r1 = Math.min(border[0].toPx(), width / 2, height / 2);
|
||||||
} else if (border.length === 4) {
|
r2 = Math.min(border[1].toPx(), width / 2, height / 2);
|
||||||
r1 = Math.min(border[0] === '0' ? 0 : border[0].toPx(), width / 2, height / 2);
|
r3 = Math.min(border[2].toPx(), width / 2, height / 2);
|
||||||
r2 = Math.min(border[1] === '0' ? 0 : border[1].toPx(), width / 2, height / 2);
|
r4 = Math.min(border[3].toPx(), width / 2, height / 2);
|
||||||
r3 = Math.min(border[2] === '0' ? 0 : border[2].toPx(), width / 2, height / 2);
|
} else {
|
||||||
r4 = Math.min(border[3] === '0' ? 0 : border[3].toPx(), width / 2, height / 2);
|
r1 = r2 = r3 = r4 = Math.min(borderRadius && borderRadius.toPx(), width / 2, height / 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const lineWidth = borderWidth === '0' ? 0 : borderWidth.toPx();
|
const lineWidth = borderWidth && borderWidth.toPx();
|
||||||
this.ctx.lineWidth = lineWidth;
|
this.ctx.lineWidth = lineWidth;
|
||||||
if (borderStyle === 'dashed') {
|
if (borderStyle === 'dashed') {
|
||||||
this.ctx.setLineDash([2 * lineWidth, 2 * lineWidth]);
|
this.ctx.setLineDash([lineWidth * 4 / 3, lineWidth * 4 / 3]);
|
||||||
// this.ctx.lineDashOffset = 2 * lineWidth
|
// this.ctx.lineDashOffset = 2 * lineWidth
|
||||||
} else if (borderStyle === 'dotted') {
|
} else if (borderStyle === 'dotted') {
|
||||||
this.ctx.setLineDash([lineWidth, lineWidth]);
|
this.ctx.setLineDash([lineWidth, lineWidth]);
|
||||||
} else if (borderStyle !== 'solid') {
|
|
||||||
const segments = borderStyle.split(/\s+/)
|
|
||||||
if (segments.length === 2) {
|
|
||||||
this.ctx.setLineDash([segments[0].toPx(), segments[1].toPx()])
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
const notSolid = borderStyle !== 'solid'
|
const notSolid = borderStyle !== 'solid'
|
||||||
this.ctx.beginPath();
|
this.ctx.beginPath();
|
||||||
@ -641,7 +636,7 @@ export default class Painter {
|
|||||||
if (!view.css || !view.css.shadow) {
|
if (!view.css || !view.css.shadow) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const box = view.css.shadow.replace(/,\s+/g, ',').split(' ');
|
const box = view.css.shadow.replace(/,\s+/g, ',').split(/\s+/);
|
||||||
if (box.length > 4) {
|
if (box.length > 4) {
|
||||||
console.error('shadow don\'t spread option');
|
console.error('shadow don\'t spread option');
|
||||||
return;
|
return;
|
||||||
|
|||||||
@ -679,6 +679,9 @@ function setStringPrototype(screenK, scale) {
|
|||||||
* @param {Boolean} minus 是否支持负数
|
* @param {Boolean} minus 是否支持负数
|
||||||
*/
|
*/
|
||||||
String.prototype.toPx = function toPx(minus) {
|
String.prototype.toPx = function toPx(minus) {
|
||||||
|
if (this === '0') {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
let reg;
|
let reg;
|
||||||
if (minus) {
|
if (minus) {
|
||||||
reg = /^-?[0-9]+([.]{1}[0-9]+){0,1}(rpx|px)$/g;
|
reg = /^-?[0-9]+([.]{1}[0-9]+){0,1}(rpx|px)$/g;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user