From 6d92a2e6679c481c8a88fc50d750e2ea8af67a23 Mon Sep 17 00:00:00 2001 From: bptato Date: Tue, 3 Dec 2024 19:43:22 +0100 Subject: 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. --- src/css/layout.nim | 2 +- src/css/render.nim | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) (limited to 'src/css') 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 -- cgit