Skip to content

Commit d5cf394

Browse files
committed
Fix - detect element width/height from style
If HTML layout does not display main element and therefore detected dimensions are 0, try to extract width and height from style. In many practical situation it will be perfect match
1 parent c9c29f2 commit d5cf394

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

modules/base/BasePainter.mjs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,14 @@ class BasePainter {
646646

647647
rect.changed = false;
648648

649+
if (!rect.width && !rect.height && !main.empty() && main.attr('style')) {
650+
const ws = main.style('width'), hs = main.style('height');
651+
if (isStr(ws) && isStr(hs) && ws.match(/^\d+px$/) && hs.match(/^\d+px$/)) {
652+
rect.width = parseInt(ws.slice(0, ws.length-2));
653+
rect.height = parseInt(hs.slice(0, hs.length-2));
654+
}
655+
}
656+
649657
if (old_h && old_w && (old_h > 0) && (old_w > 0)) {
650658
if ((old_h !== rect.height) || (old_w !== rect.width))
651659
rect.changed = (check_level > 1) || (rect.width / old_w < 0.99) || (rect.width / old_w > 1.01) || (rect.height / old_h < 0.99) || (rect.height / old_h > 1.01);

0 commit comments

Comments
 (0)