From: "Elijah G." <eg642616@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: luangruo@yahoo.com, emacs-devel@gnu.org
Subject: Re: Stipples support in MS-Windows port
Date: Tue, 21 May 2024 20:06:38 -0600 [thread overview]
Message-ID: <86o78yr45t.fsf@gmail.com> (raw)
In-Reply-To: <86o78z8jw2.fsf@gnu.org> (Eli Zaretskii's message of "Tue, 21 May 2024 14:49:33 +0300")
[-- Attachment #1: Type: text/plain, Size: 2633 bytes --]
Eli Zaretskii <eliz@gnu.org> writes:
>> From: "Elijah G." <eg642616@gmail.com>
>> Cc: luangruo@yahoo.com, emacs-devel@gnu.org
>> Date: Mon, 20 May 2024 20:00:51 -0600
>>
>> "Elijah G." <eg642616@gmail.com> writes:
>>
>> >>> From: "Elijah G." <eg642616@gmail.com>
>> >>> Cc: emacs-devel@gnu.org
>> >>> Date: Sun, 19 May 2024 16:37:07 -0600
>> >>>
>> >>> 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.
>> >>
>> >> Please elaborate: what doesn't work yet with this implementation?
>> >
>> > It's kind of hard for me to explain, but I think that doesn't mean it's
>> > hard to solve.
>> >
>> > In the documentation
>> > (https://www.gnu.org/software/emacs/manual/html_node/elisp/Face-Attributes.html)
>> > specifies that stipples can be a filepath to an X Bitmap file:
>> >
>> > The value can be a string; that should be the name of a file containing
>> > external-format X bitmap data. The file is found in the directories
>> > listed in the variable x-bitmap-file-path.
>> >
>> > That is not done yet ...
>>
>> About this last one, i've forgot that `image_create_bitmap_from_file`
>> can fix this, in case i can solve it, the only issue will be the bitmap
>> having the colors inverted.
>>
>> A more detailed example about that issue:
>>
>> 1111001111 0000110000
>> 1111001111 0000110000
>> 1111001111 0000110000
>> 1111001111 0000110000
>> 1111111111 0000000000
>> 1111001111 0000110000
>>
>> Expected Result
>>
>> in Windows, bitmaps uses 1 for bg color and 0 for fg.
>
> Why is it a problem to invert the bits programmatically? We already
> do that in w32_create_pixmap_from_bitmap_data (maybe you could reuse
> it?).
I'd to use `w32_create_pixmap_from_bitmap_data` for convert the stipple
bitmap to a Windows bitmap but i've noticed it inverts stipple bits.
It's just something that could be confusing in the future specifically
these 2 lines since it's using bc color for the text color and
vice-versa:
+ SetTextColor (hdc, gc->background);
+ SetBkColor (hdc, gc->foreground);
I tried reuse w32_create_pixmap_from_bitmap_data to obtained bitmap but
it doesn't seem to work, I just hope it's not a problem.
For now the stipple implementation is now complete (as far as i could test),
Now uses xbm files and stipple data.
Here an example using gnus.xbm file:
[-- Attachment #2: gnus_stipple.png --]
[-- Type: image/png, Size: 67226 bytes --]
[-- Attachment #3: Type: text/plain, Size: 85 bytes --]
I would like if someone else can test it for see if there are any
issues.
Thanks.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #4: 0001-Stipple-support-for-MS-Windows.patch --]
[-- Type: text/x-patch, Size: 7654 bytes --]
From ef7d9b6fb9411cce26666d5804ee46f20ea1a3ec 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] Stipple support for MS Windows
* src/w32term.h (w32_bitmap_record): Add stipple value.
* src/w32term.c:
(w32_fill_stipple_pattern): New function.
(w32_draw_glyph_string_background, w32_draw_glyph_string_bg_rect)
(w32_draw_stretch_glyph_string): Use new stipple function.
* src/image.c:
(image_create_bitmap_from_data): Create stipple bitmap.
(image_create_bitmap_from_file): Add suuport for pixmap and create
stipple bitmap.
---
src/image.c | 57 +++++++++++++++++++++++++++++++++++++++++++++-----
src/w32term.c | 58 +++++++++++++++++++++++++++++++++------------------
src/w32term.h | 1 +
3 files changed, 91 insertions(+), 25 deletions(-)
diff --git a/src/image.c b/src/image.c
index e93fc3183af..f6c20985fbe 100644
--- a/src/image.c
+++ b/src/image.c
@@ -214,6 +214,13 @@ #define n_planes n_image_planes
static unsigned long *colors_in_color_table (int *n);
#endif
+#ifdef HAVE_NTGUI
+static HBITMAP w32_create_pixmap_from_bitmap_data (int width,
+ int height,
+ char *data);
+
+#endif
+
#if defined (HAVE_WEBP) || defined (HAVE_GIF)
static void anim_prune_animation_cache (Lisp_Object);
#endif
@@ -602,7 +609,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)
+ Emacs_Pixmap stipple;
+
+ /* Convert X bitmap to W32 bitmap */
+ stipple = w32_create_pixmap_from_bitmap_data (width, height, bits);
+
+ if (!bitmap || !stipple)
return -1;
#endif /* HAVE_NTGUI */
@@ -681,6 +693,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 */
@@ -699,7 +712,7 @@ image_create_bitmap_from_data (struct frame *f, char *bits,
#endif /* defined HAVE_ANDROID && !defined ANDROID_STUBIFY */
#if defined HAVE_HAIKU || defined HAVE_NS || defined HAVE_PGTK \
- || defined HAVE_ANDROID
+ || defined HAVE_ANDROID || defined HAVE_NTGUI
static char *slurp_file (image_fd, ptrdiff_t *);
static Lisp_Object image_find_image_fd (Lisp_Object, image_fd *);
static bool xbm_read_bitmap_data (struct frame *, char *, char *,
@@ -711,10 +724,44 @@ image_create_bitmap_from_data (struct frame *f, char *bits,
ptrdiff_t
image_create_bitmap_from_file (struct frame *f, Lisp_Object file)
{
-#if defined (HAVE_NTGUI)
- return -1; /* W32_TODO : bitmap support */
-#else
Display_Info *dpyinfo = FRAME_DISPLAY_INFO (f);
+
+#ifdef HAVE_NTGUI
+ ptrdiff_t id, size;
+ int width, height, rc;
+ image_fd fd;
+ char *contents, *data;
+ Emacs_Pixmap bitmap;
+
+ if (!STRINGP (image_find_image_fd (file, &fd)))
+ return -1;
+
+ contents = slurp_file (fd, &size);
+
+ if (!contents)
+ return -1;
+
+ rc = xbm_read_bitmap_data (f, contents, contents + size,
+ &width, &height, &data, 0);
+
+ if (!rc)
+ {
+ xfree (contents);
+ return -1;
+ }
+
+ id = image_allocate_bitmap_record (f);
+ bitmap = w32_create_pixmap_from_bitmap_data (width, height, data);
+
+ dpyinfo->bitmaps[id - 1].height = width;
+ dpyinfo->bitmaps[id - 1].width = height;
+ dpyinfo->bitmaps[id - 1].stipple = bitmap;
+ dpyinfo->bitmaps[id - 1].file = xlispstrdup (file);
+ printf("%s\n", dpyinfo->bitmaps[id - 1].file);
+
+ xfree (contents);
+ xfree (data);
+ return id;
#endif
#ifdef HAVE_NS
diff --git a/src/w32term.c b/src/w32term.c
index a9aff304771..b68f0b4e3d6 100644
--- a/src/w32term.c
+++ b/src/w32term.c
@@ -1248,6 +1248,37 @@ w32_clear_glyph_string_rect (struct glyph_string *s,
real_w, real_h);
}
+/* Fill background with bitmap pattern from S at specified position
+ given by X and Y. WIDTH and HEIGHT specifies bitmap size, GC is
+ used to get foreground and background color context and HDC where
+ fill it. */
+
+static void
+w32_fill_stipple_pattern (HDC hdc, struct glyph_string *s, Emacs_GC *gc,
+ int x, int y, unsigned int width, unsigned int height)
+{
+ /* BUG: 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;
+ RECT r;
+
+ bm = FRAME_DISPLAY_INFO (s->f)->bitmaps[s->face->stipple - 1].stipple;
+ hb = CreatePatternBrush (bm);
+
+ r.left = x;
+ r.top = y;
+ r.right = x + width;
+ r.bottom = y + height;
+
+ 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,21 +1295,16 @@ 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 (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,
- s->height - 2 * box_line_width);
- XSetFillStyle (s->display, s->gc, FillSolid);
+ w32_fill_stipple_pattern (s->hdc, s, s->gc, s->x,
+ s->y + box_line_width,
+ s->background_width,
+ s->height - 2 * box_line_width);
s->background_filled_p = true;
}
- else
-#endif
- if (FONT_HEIGHT (s->font) < s->height - 2 * box_line_width
+ else if (FONT_HEIGHT (s->font) < s->height - 2 * box_line_width
/* When xdisp.c ignores FONT_HEIGHT, we cannot trust
font dimensions, since the actual glyphs might be
much smaller. So in that case we always clear the
@@ -2286,16 +2312,12 @@ w32_draw_image_foreground_1 (struct glyph_string *s, HBITMAP pixmap)
static void
w32_draw_glyph_string_bg_rect (struct glyph_string *s, int x, int y, int w, int h)
{
-#if 0 /* 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, x, y, w, h);
- XSetFillStyle (s->display, s->gc, FillSolid);
+ w32_fill_stipple_pattern (s->hdc, s, s->gc, x, y, w, h);
}
else
-#endif
w32_clear_glyph_string_rect (s, x, y, w, h);
}
@@ -2500,16 +2522,12 @@ w32_draw_stretch_glyph_string (struct glyph_string *s)
get_glyph_string_clip_rect (s, &r);
w32_set_clip_rectangle (hdc, &r);
-#if 0 /* TODO: stipple */
if (s->face->stipple)
{
/* Fill background with a stipple pattern. */
- XSetFillStyle (s->display, gc, FillOpaqueStippled);
- XFillRectangle (s->display, FRAME_W32_WINDOW (s->f), gc, x, y, w, h);
- XSetFillStyle (s->display, gc, FillSolid);
+ w32_fill_stipple_pattern (s->hdc, s, gc, x, y, w, h);
}
else
-#endif
{
w32_fill_area (s->f, s->hdc, gc->background, x, y, w, h);
}
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
next prev parent reply other threads:[~2024-05-22 2:06 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.
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. [this message]
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=86o78yr45t.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).