unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: "Elijah G." <eg642616@gmail.com>
To: Po Lu <luangruo@yahoo.com>, Eli Zaretskii <eliz@gnu.org>
Cc: emacs-devel@gnu.org
Subject: Re: Stipples support in MS-Windows port
Date: Sun, 19 May 2024 16:37:07 -0600	[thread overview]
Message-ID: <86zfslctt8.fsf@gmail.com> (raw)
In-Reply-To: <87frulynby.fsf@yahoo.com> (Po Lu's message of "Tue, 14 May 2024 13:28:01 +0800")

[-- Attachment #1: Type: text/plain, Size: 1086 bytes --]

Good news, the stipple implementation is now done, now works using
indent-bars package and other stipples, however there are some
issues that i want to remark

1. Currently it only works for stipple data and not for X Bitmap files,
   I don't know where is stored the code for using X Bitmap in stipples.

2. I had to use `w32_create_pixmap_from_bitmap_data` for make it usable,
   but it is defined before `image_create_bitmap_from_data`, i had to
   copy its code for use it, Is there a problem move that function
   before `image_create_bitmap_from_data` ?

3. The bitmap created using the copied code have colors inverted,
   I fixed it setting text color to background color and bg to fg color,
   I'm not sure how w32_create_pixmap_from_bitmap_data works, as far as
   i could see it does some operations to the memory, something that i
   don't think i can help so much.

After fixing 1 (and maybe 2), I will only need to format the code (and
maybe rename XFillRectangle function) for send the final patch here.

I'm attaching the work done if you all want to test it.

Thanks.


[-- Attachment #2: Test using indent-bars package --]
[-- Type: image/png, Size: 11055 bytes --]

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0001-WIP-Stipple-implementation-for-MS-Windows.patch --]
[-- Type: text/x-patch, Size: 4425 bytes --]

From f5dd217c5d7ae9d2aae9c18247d5d954fa170bf6 Mon Sep 17 00:00:00 2001
From: "Elias G. Perez" <eg642616@gmail.com>
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


  parent reply	other threads:[~2024-05-19 22:37 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-03  2:53 Stipples support in MS-Windows port Elijah G
2024-05-03  6:09 ` Eli Zaretskii
2024-05-03  7:30 ` Po Lu
2024-05-05  3:43   ` Elijah G
2024-05-05  4:04     ` Po Lu
2024-05-05  4:30       ` Po Lu
2024-05-06  5:17         ` Elijah G
2024-05-11  5:10         ` Elijah G
2024-05-11  5:27           ` Po Lu
2024-05-11  8:24             ` Eli Zaretskii
2024-05-12 23:06               ` Elijah G.
2024-05-14  4:07                 ` Elijah G.
2024-05-14  5:28                   ` Po Lu
2024-05-15  1:43                     ` Elijah G.
2024-05-19 22:37                     ` Elijah G. [this message]
2024-05-20 11:15                       ` Eli Zaretskii
2024-05-20 11:19                         ` Po Lu
2024-05-20 12:32                           ` Eli Zaretskii
2024-05-20 13:12                             ` Po Lu
2024-05-20 19:44                         ` Elijah G.
2024-05-21  2:00                           ` Elijah G.
2024-05-21 11:49                             ` Eli Zaretskii
2024-05-22  2:06                               ` Elijah G.
2024-05-24  1:55                                 ` Elijah G.
2024-05-24  6:24                                   ` Po Lu
2024-05-25  7:24                                 ` Eli Zaretskii
2024-05-25 11:30                                   ` Arash Esbati
2024-05-26  2:37                                     ` Po Lu
2024-05-27 15:32                                       ` Arash Esbati
2024-05-26  0:27                                   ` Elijah G.
2024-05-26  8:09                                     ` Yuri Khan
2024-05-27  2:05                                       ` Elijah G.
2024-05-27  6:20                                         ` Yuri Khan
2024-05-28  2:06                                           ` Elijah G.
2024-05-26  8:51                                     ` Eli Zaretskii
2024-05-28  0:23                                       ` Elijah G.

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=86zfslctt8.fsf@gmail.com \
    --to=eg642616@gmail.com \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=luangruo@yahoo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).