]> git.neil.brown.name Git - edlib.git/commitdiff
display-x11: draw outline cursor entirely inside box.
authorNeilBrown <neil@brown.name>
Mon, 11 Sep 2023 08:51:05 +0000 (18:51 +1000)
committerNeilBrown <neil@brown.name>
Mon, 11 Sep 2023 12:26:57 +0000 (22:26 +1000)
The stroke draws either side of the line given. We
need to allow for that if we want to stay entirely inside
the allowed space.

Signed-off-by: NeilBrown <neil@brown.name>
DOC/TODO.md
display-x11-xcb.c

index 689e924d9ca07662e854402bbaf014268fc97a31..cbf5b08c79cb7360d48f069dd200baf0da72ac19 100644 (file)
@@ -9,7 +9,7 @@ the file.
 
 ### Triage
 
-- [ ] adding new lines at end of doc in x11 leaves phantom underline
+- [X] adding new lines at end of doc in x11 leaves phantom underline
       cursors.
 - [ ] 20230908090027.6AA0DC05B9@prodcs.lwn.net has a wrapped
       <a> tag which isn't parsed well.
index 779ebe4a204bc4bea1639015533fe9d5ee061400..fc8c732edd7e23d948468187d724c5aacf0dc0e5 100644 (file)
@@ -748,6 +748,7 @@ DEF_CMD(xcb_draw_text)
                PangoRectangle curs;
                bool in_focus = xd->in_focus;
                struct pane *f = ci->focus;
+               double cx, cy, cw, ch;
 
                pango_layout_index_to_pos(layout, ci->num, &curs);
                if (curs.width <= 0) {
@@ -756,9 +757,14 @@ DEF_CMD(xcb_draw_text)
                        pango_layout_get_extents(layout, NULL, &log);
                        curs.width = log.width;
                }
-               cairo_rectangle(ctx, x+curs.x/PANGO_SCALE, y-baseline+curs.y/PANGO_SCALE,
-                               (curs.width - PANGO_SCALE/2) / PANGO_SCALE,
-                               (curs.height - PANGO_SCALE/2) / PANGO_SCALE);
+
+               /* Add half to x,y as stroke is either side of the line */
+               cx = x * PANGO_SCALE + curs.x + PANGO_SCALE/2;
+               cy = (y - baseline) * PANGO_SCALE + curs.y + PANGO_SCALE/2;
+               ch = curs.height - PANGO_SCALE;
+               cw = curs.width - PANGO_SCALE;
+               cairo_rectangle(ctx, cx/PANGO_SCALE, cy/PANGO_SCALE,
+                               cw/PANGO_SCALE, ch/PANGO_SCALE);
                cairo_set_line_width(ctx, 1.0);
                cairo_stroke(ctx);