aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-12-20 00:21:09 +0100
committerbptato <nincsnevem662@gmail.com>2024-12-20 00:21:09 +0100
commit92aab607b238d41c4b33f0920ca36fa5454bf323 (patch)
tree1872f2a4e84e06ebf6e296fb6c7e7abdef0e7344 /src
parent84ad5010cd955796238407ae767c9ba239683db6 (diff)
downloadchawan-92aab607b238d41c4b33f0920ca36fa5454bf323.tar.gz
layout, render: image sizing fixes/workarounds
* fix clip for image * switch back img's display to inline * fix image width calculation without specified width/height I'm not 100% sure if this is correct, but it certainly looks better.
Diffstat (limited to 'src')
-rw-r--r--src/css/layout.nim20
-rw-r--r--src/css/render.nim8
2 files changed, 16 insertions, 12 deletions
diff --git a/src/css/layout.nim b/src/css/layout.nim
index 2316c23c..53ffcdce 100644
--- a/src/css/layout.nim
+++ b/src/css/layout.nim
@@ -1650,13 +1650,15 @@ proc addImage(ictx: var InlineContext; state: var InlineState;
if computed{"max-width"}.canpx(ictx.space.w):
let w = computed{"max-width"}.spx(ictx.space.w, computed, padding)
atom.size.w = min(atom.size.w, w)
- if computed{"min-width"}.canpx(ictx.space.w):
+ let hasMinWidth = computed{"min-width"}.canpx(ictx.space.w)
+ if hasMinWidth:
let w = computed{"min-width"}.spx(ictx.space.w, computed, padding)
atom.size.w = max(atom.size.w, w)
if computed{"max-height"}.canpx(ictx.space.h):
let h = computed{"max-height"}.spx(ictx.space.h, computed, padding)
atom.size.h = min(atom.size.h, h)
- if computed{"min-height"}.canpx(ictx.space.h):
+ let hasMinHeight = computed{"min-height"}.canpx(ictx.space.h)
+ if hasMinHeight:
let h = computed{"min-height"}.spx(ictx.space.h, computed, padding)
atom.size.h = max(atom.size.h, h)
if not hasWidth and ictx.space.w.isDefinite():
@@ -1664,7 +1666,8 @@ proc addImage(ictx: var InlineContext; state: var InlineState;
if not hasHeight and ictx.space.h.isDefinite():
atom.size.h = min(ictx.space.h.u, atom.size.h)
if not hasHeight and not hasWidth:
- if osize.w >= osize.h:
+ if osize.w >= osize.h or
+ not ictx.space.h.isDefinite() and ictx.space.w.isDefinite():
if osize.w > 0:
atom.size.h = osize.h div osize.w * atom.size.w
else:
@@ -1686,12 +1689,13 @@ proc addImage(ictx: var InlineContext; state: var InlineState;
# parent size yet. e.g. <img width=100% ...> with an indefinite containing
# size (i.e. the first table cell pass) would resolve to an intr.w of
# image.width, stretching out the table to an uncomfortably large size.
- if ictx.space.w.t == scStretch or computed{"width"}.u != clPerc and
- computed{"min-width"}.u != clPerc:
+ # The issue is similar with intr.h, which is relevant in flex layout.
+ #
+ # So check if any dimension is fixed, and if yes, report the intrinsic
+ # minimum dimension as that or the atom size (whichever is greater).
+ if ictx.space.w.t == scStretch or hasWidth or hasMinWidth:
ictx.state.intr.w = max(ictx.state.intr.w, atom.size.w)
- # Similarly for height, except in this case it happens in flex sizing.
- if computed{"height"}.canpx(ictx.space.h) or
- computed{"min-height"}.canpx(ictx.space.h):
+ if ictx.space.h.t == scStretch or hasHeight or hasMinHeight:
ictx.lbstate.intrh = max(ictx.lbstate.intrh, atom.size.h)
proc layoutInline(ictx: var InlineContext; fragment: InlineFragment) =
diff --git a/src/css/render.nim b/src/css/render.nim
index 9f869ad9..efaa4910 100644
--- a/src/css/render.nim
+++ b/src/css/render.nim
@@ -373,20 +373,20 @@ proc renderInlineFragment(grid: var FlexibleGrid; state: var RenderState;
else:
let format = fragment.computed.toFormat()
for atom in fragment.state.atoms:
+ let offset = offset + atom.offset
case atom.t
of iatInlineBlock:
- grid.renderBlockBox(state, atom.innerbox, offset + atom.offset)
+ grid.renderBlockBox(state, atom.innerbox, offset)
of iatWord:
if fragment.computed{"visibility"} == VisibilityVisible:
- grid.setText(state, atom.str, offset + atom.offset, format,
- fragment.node)
+ grid.setText(state, atom.str, offset, format, fragment.node)
of iatImage:
if fragment.computed{"visibility"} == VisibilityVisible:
let x2p = offset.x + atom.size.w
let y2p = offset.y + atom.size.h
let clipBox = addr state.clipBoxes[^1]
#TODO implement proper image clipping
- if offset.x < clipBox.send.y and offset.y < clipBox.send.y and
+ if offset.x < clipBox.send.x and offset.y < clipBox.send.y and
x2p >= clipBox.start.x and y2p >= clipBox.start.y:
let x1 = offset.x.toInt
let y1 = offset.y.toInt