image 的 width 和 height 支持 auto
This commit is contained in:
parent
19b85f12c7
commit
733ff9d213
40
lib/pen.js
40
lib/pen.js
@ -94,9 +94,9 @@ export default class Painter {
|
|||||||
this.ctx.closePath();
|
this.ctx.closePath();
|
||||||
this.ctx.fill();
|
this.ctx.fill();
|
||||||
// 在 ios 的 6.6.6 版本上 clip 有 bug,禁掉此类型上的 clip,也就意味着,在此版本微信的 ios 设备下无法使用 border 属性
|
// 在 ios 的 6.6.6 版本上 clip 有 bug,禁掉此类型上的 clip,也就意味着,在此版本微信的 ios 设备下无法使用 border 属性
|
||||||
if (!(getApp().systemInfo &&
|
if (!(getApp().systemInfo
|
||||||
getApp().systemInfo.version <= '6.6.6' &&
|
&& getApp().systemInfo.version <= '6.6.6'
|
||||||
getApp().systemInfo.platform === 'ios')) {
|
&& getApp().systemInfo.platform === 'ios')) {
|
||||||
this.ctx.clip();
|
this.ctx.clip();
|
||||||
}
|
}
|
||||||
this.ctx.setGlobalAlpha(1);
|
this.ctx.setGlobalAlpha(1);
|
||||||
@ -182,10 +182,38 @@ export default class Painter {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'image': {
|
case 'image': {
|
||||||
// image 如果未设置长宽,则使用图片本身的长宽
|
// image的长宽设置成auto的逻辑处理
|
||||||
const ratio = getApp().systemInfo.pixelRatio ? getApp().systemInfo.pixelRatio : 2;
|
const ratio = getApp().systemInfo.pixelRatio ? getApp().systemInfo.pixelRatio : 2;
|
||||||
width = view.css && view.css.width ? view.css.width.toPx() : Math.round(view.sWidth / ratio);
|
if (!view.css) {
|
||||||
height = view.css && view.css.height ? view.css.height.toPx() : Math.round(view.sHeight / ratio);
|
width = Math.round(view.sWidth / ratio);
|
||||||
|
height = Math.round(view.sHeight / ratio);
|
||||||
|
} else {
|
||||||
|
if (!view.css.width) {
|
||||||
|
width = Math.round(view.sWidth / ratio);
|
||||||
|
if ((!view.css.height) || view.css.height === 'auto') {
|
||||||
|
height = Math.round(view.sHeight / ratio);
|
||||||
|
} else {
|
||||||
|
height = view.css.height.toPx();
|
||||||
|
}
|
||||||
|
} else if (view.css.width === 'auto') {
|
||||||
|
if ((!view.css.height) || view.css.height === 'auto') {
|
||||||
|
width = Math.round(view.sWidth / ratio);
|
||||||
|
height = Math.round(view.sHeight / ratio);
|
||||||
|
} else {
|
||||||
|
height = view.css.height.toPx();
|
||||||
|
width = view.sWidth / view.sHeight * height;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
width = view.css.width.toPx();
|
||||||
|
if (!view.css.height) {
|
||||||
|
height = Math.round(view.sHeight / ratio);
|
||||||
|
} else if (view.css.height === 'auto') {
|
||||||
|
height = view.sHeight / view.sWidth * width;
|
||||||
|
} else {
|
||||||
|
height = view.css.height.toPx();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user