diff --git a/lib/pen.js b/lib/pen.js index 5c5bfde..7a5585c 100644 --- a/lib/pen.js +++ b/lib/pen.js @@ -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: