computeImageBox function
Size
computeImageBox({
- required Size natural,
- LuckyLength? width,
- LuckyLength? height,
- required double maxWidth,
- required double maxHeight,
根据自然尺寸和可选宽高返回图片绘制尺寸。
百分比各按 maxWidth/maxHeight 解析;只给一边时等比缩放,两边未给则用 natural。
Implementation
Size computeImageBox(
{required Size natural,
LuckyLength? width,
LuckyLength? height,
required double maxWidth,
required double maxHeight}) {
// 上游 lucky.ts:290-316;保留比例计算的括号。
if (width == null && height == null) {
return Size(natural.width, natural.height);
}
if (width != null && height == null) {
final w = width.resolve(maxWidth);
return Size(w, natural.height * (w / natural.width));
}
if (width == null && height != null) {
final h = height.resolve(maxHeight);
return Size(natural.width * (h / natural.height), h);
}
return Size(width!.resolve(maxWidth), height!.resolve(maxHeight));
}