image 的 width 和 height 支持 auto

This commit is contained in:
feipeng 2019-07-17 17:40:47 +08:00
parent 19b85f12c7
commit 733ff9d213

View File

@ -94,9 +94,9 @@ export default class Painter {
this.ctx.closePath();
this.ctx.fill();
// 在 ios 的 6.6.6 版本上 clip 有 bug禁掉此类型上的 clip也就意味着在此版本微信的 ios 设备下无法使用 border 属性
if (!(getApp().systemInfo &&
getApp().systemInfo.version <= '6.6.6' &&
getApp().systemInfo.platform === 'ios')) {
if (!(getApp().systemInfo
&& getApp().systemInfo.version <= '6.6.6'
&& getApp().systemInfo.platform === 'ios')) {
this.ctx.clip();
}
this.ctx.setGlobalAlpha(1);
@ -182,10 +182,38 @@ export default class Painter {
break;
}
case 'image': {
// image 如果未设置长宽,则使用图片本身的长宽
// image的长宽设置成auto的逻辑处理
const ratio = getApp().systemInfo.pixelRatio ? getApp().systemInfo.pixelRatio : 2;
width = view.css && view.css.width ? view.css.width.toPx() : Math.round(view.sWidth / ratio);
height = view.css && view.css.height ? view.css.height.toPx() : Math.round(view.sHeight / ratio);
if (!view.css) {
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;
}
default: