diff options
| author | bptato <nincsnevem662@gmail.com> | 2024-12-03 19:43:22 +0100 |
|---|---|---|
| committer | bptato <nincsnevem662@gmail.com> | 2024-12-03 19:43:22 +0100 |
| commit | 6d92a2e6679c481c8a88fc50d750e2ea8af67a23 (patch) | |
| tree | e462bef801a80242cbb42608595d6377236af799 /src/css | |
| parent | 05b97c934468ef23cf83f11083b1b9aef883dfb0 (diff) | |
| download | chawan-6d92a2e6679c481c8a88fc50d750e2ea8af67a23.tar.gz | |
pager, term: use cell offset with kitty images
Gets rid of rounding errors when positioning images.
Theoretically this is possible with Sixel too, but as always, it's
ten times as difficult to implement as with Kitty, so I'll leave it
for later.
Diffstat (limited to 'src/css')
| -rw-r--r-- | src/css/layout.nim | 2 | ||||
| -rw-r--r-- | src/css/render.nim | 12 |
2 files changed, 11 insertions, 3 deletions
diff --git a/src/css/layout.nim b/src/css/layout.nim index fe5afdcc..2e1fcd03 100644 --- a/src/css/layout.nim +++ b/src/css/layout.nim @@ -1599,7 +1599,7 @@ proc addInlineImage(ictx: var InlineContext; state: var InlineState; let atom = InlineAtom( t: iatImage, bmp: bmp, - size: size(w = int(bmp.width), h = int(bmp.height)) #TODO overflow + size: size(w = bmp.width, h = bmp.height) #TODO overflow ) let computed = state.fragment.computed let lctx = ictx.lctx diff --git a/src/css/render.nim b/src/css/render.nim index 8e8185dc..d7d57e35 100644 --- a/src/css/render.nim +++ b/src/css/render.nim @@ -230,6 +230,8 @@ type PosBitmap* = ref object x*: int y*: int + offx*: int + offy*: int width*: int height*: int bmp*: NetworkBitmap @@ -367,9 +369,15 @@ proc renderInlineFragment(grid: var FlexibleGrid; state: var RenderState; # "paint" background, i.e. add formatting (but don't actually color it) grid.paintBackground(state, defaultColor, x1, y1, x2, y2, fragment.node, noPaint = true) + let x = (offset.x div state.attrs.ppc).toInt + let y = (offset.y div state.attrs.ppl).toInt + let offx = (offset.x - x.toLayoutUnit * state.attrs.ppc).toInt + let offy = (offset.y - y.toLayoutUnit * state.attrs.ppl).toInt state.images.add(PosBitmap( - x: (offset.x div state.attrs.ppc).toInt, - y: (offset.y div state.attrs.ppl).toInt, + x: x, + y: y, + offx: offx, + offy: offy, width: atom.size.w.toInt, height: atom.size.h.toInt, bmp: atom.bmp |