From: "Elijah G." <eg642616@gmail.com>
To: Po Lu <luangruo@yahoo.com>
Cc: emacs-devel@gnu.org, Eli Zaretskii <eliz@gnu.org>
Subject: Re: Stipples support in MS-Windows port
Date: Tue, 14 May 2024 19:43:44 -0600 [thread overview]
Message-ID: <86bk57df3j.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: 2233 bytes --]
Po Lu <luangruo@yahoo.com> writes:
> "Elijah G." <eg642616@gmail.com> writes:
>
>> I'm a bit stuck here, i could make to use the stipple bitmap, however it
>> doesn't uses background and foreground color from propertized string,
>> (and looks very weird).
>>
>> The drawing works fine, but the problem is trying to get stipple bitmap,
>> and makes it work well.
>>
>> One way that i thought for fix this is redefining bitmap stipple for
>> using same string fg and bg colors and bitmap width and height, but for
>> this i need the bitmap bits.
>>
>> I found that image_create_bitmap_from_data also makes stipple bitmap
>> (https://git.savannah.gnu.org/cgit/emacs.git/tree/src/image.c#n601);
>> i tried to found bitmap bits by using stipple bitmap id but some
>> functions/macros are only for X11 (e.g x_bitmap_height and
>> x_bitmap_width).
>>
>> I would be happy to read any advice or feedback.
>>
>> I've attached to this email a patch for the work that i've done and some
>> screenshots for the final results.
>>
>> Thanks.
>
> I don't follow your question, but on the assumption that you've run into
> difficulties with replacing the background and foreground of the pattern
> with those of your choosing, perhaps you must set the "text" and
> "background" colors of the DC as suggested by the documentation:
>
> A brush created by using a monochrome (1 bit per pixel) bitmap has the
> text and background colors of the device context to which it is drawn.
> Pixels represented by a 0 bit are drawn with the current text color;
> pixels represented by a 1 bit are drawn with the current background
> color.
>
> ? Manipulating the stipple bitmap directly should not be necessary, not
> with these facilities.
Thank you, the stipple implementation now is almost done, now the only
problem is that stipple bitmap is not monochromatic, i could test
using other monochromatic bitmap and it now works as it should work.
I found that it's a problem with this var
https://git.savannah.gnu.org/cgit/emacs.git/tree/src/image.c#n604.
I'm not sure why and how, i'm trying to figure how to "modify" it
(note: i've printed the BITS bitmap with printf and pasted it, and works
well, i'm not sure if it can be a posible solution).
[-- Attachment #2: 0001-WIP-Stipple-implementation-for-MS-Windows.patch --]
[-- Type: text/x-patch, Size: 3652 bytes --]
From ddc9f401931204bf099885a1fddf399a77fbb2b1 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 | 8 +++++++-
src/w32term.c | 37 +++++++++++++++++++++++++++++++------
src/w32term.h | 1 +
3 files changed, 39 insertions(+), 7 deletions(-)
diff --git a/src/image.c b/src/image.c
index e93fc3183af..e79371ee292 100644
--- a/src/image.c
+++ b/src/image.c
@@ -602,7 +602,12 @@ 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)
+ /* FIXME: bitmap generated here is not monochromatic, i think it's a
+ * problem with BITS*/
+ Emacs_Pixmap stipple;
+ stipple = CreateBitmap (width, height, 1, 1, bits);
+
+ if (! bitmap)
return -1;
#endif /* HAVE_NTGUI */
@@ -681,6 +686,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..770d6d6c30e 100644
--- a/src/w32term.c
+++ b/src/w32term.c
@@ -1248,6 +1248,32 @@ 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)
+{
+ SetTextColor (hdc, gc->foreground);
+ SetBkColor (hdc, gc->background);
+
+ Emacs_Pixmap bm;
+ HBRUSH hb;
+
+ /* Monochrome Bitmap Test (string BIT was extracted using printf):
+ CreateBitmap (5, 1, 1, 1, "☺"); */
+ bm = FRAME_DISPLAY_INFO (s->f)->bitmaps[s->face->stipple - 1].stipple;
+ hb = CreatePatternBrush (bm);
+
+ 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 +1290,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
[-- Attachment #3: Test screenshot --]
[-- Type: image/png, Size: 8548 bytes --]
next prev parent reply other threads:[~2024-05-15 1:43 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. [this message]
2024-05-19 22:37 ` Elijah G.
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=86bk57df3j.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).