Here is the latest version of the double underline and strikeout parts of my
console patchset.

Previously, the double underline was always painted two pixels above the
normal underline.  This worked well for most font sizes, but to improve the
visual effect with the smallest and largest fonts the offset now depends on
the font height.

Index: rasops/rasops.c
===================================================================
RCS file: /cvs/src/sys/dev/rasops/rasops.c,v
retrieving revision 1.69
diff -u -p -r1.69 rasops.c
--- rasops/rasops.c     18 Jan 2023 11:08:49 -0000      1.69
+++ rasops/rasops.c     30 Jan 2023 12:40:55 -0000
@@ -561,7 +561,7 @@ rasops_pack_cattr(void *cookie, int fg, 
        if ((flg & WSATTR_HILIT) != 0 && fg < 8)
                fg += 8;
 
-       *attr = (bg << 16) | (fg << 24) | (flg & WSATTR_UNDERLINE);
+       *attr = (bg << 16) | (fg << 24) | flg;
        return (0);
 }
 
@@ -585,7 +585,7 @@ rasops_pack_mattr(void *cookie, int fg, 
                bg = swap;
        }
 
-       *attr = (bg << 16) | (fg << 24) | (flg & WSATTR_UNDERLINE);
+       *attr = (bg << 16) | (fg << 24) | flg;
        return (0);
 }
 
Index: rasops/rasops32.c
===================================================================
RCS file: /cvs/src/sys/dev/rasops/rasops32.c,v
retrieving revision 1.13
diff -u -p -r1.13 rasops32.c
--- rasops/rasops32.c   18 Jan 2023 11:08:49 -0000      1.13
+++ rasops/rasops32.c   30 Jan 2023 12:40:55 -0000
@@ -202,12 +202,51 @@ rasops32_putchar(void *cookie, int row, 
                }
        }
 
-       /* Do underline a pixel at a time */
-       if ((attr & WSATTR_UNDERLINE) != 0) {
+
+       /* Do underline one pixel at a time.
+        *
+        * Double underline requires single underline to be painted as well.
+        */
+
+       if ((attr & (WSATTR_UNDERLINE | WSATTR_DOUBLE_UNDERLINE)) != 0) {
                rp -= step;
                for (cnt = 0; cnt < width; cnt++)
                        ((int *)rp)[cnt] = f;
        }
+
+       /*
+        * Double underline now just needs to paint the second underline a few
+        * rows up.  The exact height is relative to the font height, to create
+        * a visually pleasing effect regardless of display resolution.
+        */
+#define FONT_HEIGHT ri->ri_font->fontheight
+#define DOUBLE_UL_SHIFT (FONT_HEIGHT < 12 ? 0 : (FONT_HEIGHT <= 32 ? 1 : 2))
+
+       if ((attr & WSATTR_DOUBLE_UNDERLINE)!=0) {
+               rp-=(step << DOUBLE_UL_SHIFT);
+               for (cnt=0; cnt< width; cnt++)
+                       ((int *)rp)[cnt]=f;
+               /*
+                * Reset row pointer to ensure that strikethough appears at a
+                * consistent height if combined with double underlining.
+                */
+
+               rp+=(step << DOUBLE_UL_SHIFT);
+               }
+
+       /*
+        * Reset pointer to ensure that strikethough appears at a consistent
+        * height if combined with single underlining.
+        */
+
+       if ((attr & WSATTR_STRIKE) != 0) {
+               if ((attr & WSATTR_UNDERLINE) != 0) {
+                       rp+=step ;
+                       }
+               rp -= (1 + (ri->ri_font->fontheight >> 1)) * step;
+               for (cnt=0; cnt< width; cnt++)
+                       ((int *)rp)[cnt]=f;
+               }
 
        return 0;
 }
Index: wscons/wsdisplayvar.h
===================================================================
RCS file: /cvs/src/sys/dev/wscons/wsdisplayvar.h,v
retrieving revision 1.38
diff -u -p -r1.38 wsdisplayvar.h
--- wscons/wsdisplayvar.h       13 Sep 2020 10:05:46 -0000      1.38
+++ wscons/wsdisplayvar.h       30 Jan 2023 12:40:55 -0000
@@ -94,11 +94,13 @@ struct wsdisplay_emulops {
 #define WSCOL_CYAN     6
 #define WSCOL_WHITE    7
 /* flag values: */
-#define WSATTR_REVERSE 1
-#define WSATTR_HILIT   2
-#define WSATTR_BLINK   4
-#define WSATTR_UNDERLINE 8
-#define WSATTR_WSCOLORS 16
+#define WSATTR_REVERSE         1
+#define WSATTR_HILIT           2
+#define WSATTR_BLINK           4
+#define WSATTR_UNDERLINE       8       
+#define WSATTR_WSCOLORS                16
+#define WSATTR_DOUBLE_UNDERLINE        32
+#define WSATTR_STRIKE          64
 };
 
 #define        WSSCREEN_NAME_SIZE      16
Index: wscons/wsemul_vt100_subr.c
===================================================================
RCS file: /cvs/src/sys/dev/wscons/wsemul_vt100_subr.c,v
retrieving revision 1.29
diff -u -p -r1.29 wsemul_vt100_subr.c
--- wscons/wsemul_vt100_subr.c  12 Jan 2023 20:39:37 -0000      1.29
+++ wscons/wsemul_vt100_subr.c  30 Jan 2023 12:40:55 -0000
@@ -597,17 +597,27 @@ wsemul_vt100_handle_csi(struct wsemul_vt
                        case 7: /* reverse */
                                flags |= WSATTR_REVERSE;
                                break;
+                       case 9: /* strikeout */
+                               flags |= WSATTR_STRIKE;
+                               break;
+                       case 21: /* double underline */
+                               flags |= WSATTR_DOUBLE_UNDERLINE;
+                               break;
                        case 22: /* ~bold VT300 only */
                                flags &= ~WSATTR_HILIT;
                                break;
-                       case 24: /* ~underline VT300 only */
+                       case 24: /* ~underline ~double underline VT300 only */
                                flags &= ~WSATTR_UNDERLINE;
+                               flags &= ~WSATTR_DOUBLE_UNDERLINE;
                                break;
                        case 25: /* ~blink VT300 only */
                                flags &= ~WSATTR_BLINK;
                                break;
                        case 27: /* ~reverse VT300 only */
                                flags &= ~WSATTR_REVERSE;
+                               break;
+                       case 29: /* ~strikeout */
+                               flags &= ~WSATTR_STRIKE;
                                break;
                        case 30: case 31: case 32: case 33:
                        case 34: case 35: case 36: case 37:

Reply via email to