From f5dd217c5d7ae9d2aae9c18247d5d954fa170bf6 Mon Sep 17 00:00:00 2001 From: "Elias G. Perez" Date: Fri, 10 May 2024 20:36:42 -0600 Subject: [PATCH] [WIP] Stipple implementation for MS Windows --- src/image.c | 32 +++++++++++++++++++++++++++++++- src/w32term.c | 38 ++++++++++++++++++++++++++++++++------ src/w32term.h | 1 + 3 files changed, 64 insertions(+), 7 deletions(-) diff --git a/src/image.c b/src/image.c index e93fc3183af..95da8353787 100644 --- a/src/image.c +++ b/src/image.c @@ -602,7 +602,36 @@ image_create_bitmap_from_data (struct frame *f, char *bits, FRAME_DISPLAY_INFO (XFRAME (frame))->n_planes, FRAME_DISPLAY_INFO (XFRAME (frame))->n_cbits, bits); - if (! bitmap) + Emacs_Pixmap stipple; + + /* code extracted from `w32_create_pixmap_from_bitmap_data` */ + + static unsigned char swap_nibble[16] + = { 0x0, 0x8, 0x4, 0xc, /* 0000 1000 0100 1100 */ + 0x2, 0xa, 0x6, 0xe, /* 0010 1010 0110 1110 */ + 0x1, 0x9, 0x5, 0xd, /* 0001 1001 0101 1101 */ + 0x3, 0xb, 0x7, 0xf }; /* 0011 1011 0111 1111 */ + int i, j, w1, w2; + unsigned char *data, *p; + + w1 = (width + 7) / 8; /* nb of 8bits elt in X bitmap */ + w2 = ((width + 15) / 16) * 2; /* nb of 16bits elt in W32 bitmap */ + data = alloca (height * w2); + memset (data, 0, height * w2); + for (i = 0; i < height; i++) + { + p = data + i*w2; + for (j = 0; j < w1; j++) + { + /* Bitswap XBM bytes to match how Windows does things. */ + unsigned char c = *bits++; + *p++ = (unsigned char)((swap_nibble[c & 0xf] << 4) + | (swap_nibble[(c>>4) & 0xf])); + } + } + stipple = CreateBitmap (width, height, 1, 1, (char *) data); + + if (!bitmap || !stipple) return -1; #endif /* HAVE_NTGUI */ @@ -681,6 +710,7 @@ image_create_bitmap_from_data (struct frame *f, char *bits, #ifdef HAVE_NTGUI dpyinfo->bitmaps[id - 1].pixmap = bitmap; + dpyinfo->bitmaps[id - 1].stipple = stipple; dpyinfo->bitmaps[id - 1].hinst = NULL; dpyinfo->bitmaps[id - 1].depth = 1; #endif /* HAVE_NTGUI */ diff --git a/src/w32term.c b/src/w32term.c index a9aff304771..c72870e0b67 100644 --- a/src/w32term.c +++ b/src/w32term.c @@ -1248,6 +1248,33 @@ w32_clear_glyph_string_rect (struct glyph_string *s, real_w, real_h); } +/* Fill background with bitmap S glyph, with GC, X, Y, WIDTH, HEIGHT, HDC. */ +static void +XFillRectangle (HDC hdc, struct glyph_string *s, Emacs_GC *gc, + int x, int y, unsigned int width, unsigned int height) +{ + /* NOTE: stipple bitmap has the inverted colors, inverting those 2 + * functions color must fix this. */ + SetTextColor (hdc, gc->background); + SetBkColor (hdc, gc->foreground); + + Emacs_Pixmap bm; + HBRUSH hb; + + bm = FRAME_DISPLAY_INFO (s->f)->bitmaps[s->face->stipple - 1].stipple; + hb = CreatePatternBrush (bm); + + /* Is this part below written correctly? */ + RECT r; + r.left = x; + r.top = y; + r.right = x + width + 1; + r.bottom = y + height + 1; + + FillRect (hdc, &r, hb); + + DeleteObject (hb); +} /* Draw the background of glyph_string S. If S->background_filled_p is non-zero don't draw it. FORCE_P non-zero means draw the @@ -1264,16 +1291,15 @@ w32_draw_glyph_string_background (struct glyph_string *s, bool force_p) { int box_line_width = max (s->face->box_horizontal_line_width, 0); -#if 0 /* TODO: stipple */ +#if 1 /* TODO: stipple */ if (s->stippled_p) { /* Fill background with a stipple pattern. */ - XSetFillStyle (s->display, s->gc, FillOpaqueStippled); - XFillRectangle (s->display, FRAME_W32_WINDOW (s->f), s->gc, s->x, - s->y + box_line_width, - s->background_width, + /* XSetFillStyle (s->display, s->gc, FillOpaqueStippled); */ + XFillRectangle (s->hdc, s, s->gc, s->x, + s->y + box_line_width, s->background_width, s->height - 2 * box_line_width); - XSetFillStyle (s->display, s->gc, FillSolid); + /* XSetFillStyle (s->display, s->gc, FillSolid); */ s->background_filled_p = true; } else diff --git a/src/w32term.h b/src/w32term.h index 3120c8bd71f..1eb6a660248 100644 --- a/src/w32term.h +++ b/src/w32term.h @@ -58,6 +58,7 @@ #define CP_DEFAULT 1004 { Emacs_Pixmap pixmap; char *file; + Emacs_Pixmap stipple; HINSTANCE hinst; /* Used to load the file */ int refcount; /* Record some info about this pixmap. */ -- 2.44.0.windows.1