From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: "Elijah G." Newsgroups: gmane.emacs.bugs Subject: bug#71159: [PATCH] Stipple support for MS Windows Date: Sat, 01 Jun 2024 12:54:22 -0600 Message-ID: <86r0dg4hpd.fsf@gmail.com> References: <86cypcuhhk.fsf@gmail.com> <86jzjcgq00.fsf@gmail.com> <86sexydekl.fsf@gmail.com> <87ed9gkber.fsf@yahoo.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="5190"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/30.0.50 (windows-nt) Cc: luangruo@yahoo.com, eliz@gnu.org To: 71159@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Jun 01 20:55:11 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1sDTsl-00018V-7L for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 01 Jun 2024 20:55:11 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sDTsR-0004Sk-AT; Sat, 01 Jun 2024 14:54:51 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sDTsQ-0004RB-C6 for bug-gnu-emacs@gnu.org; Sat, 01 Jun 2024 14:54:50 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sDTsQ-0005NE-2S for bug-gnu-emacs@gnu.org; Sat, 01 Jun 2024 14:54:50 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sDTsb-0005gZ-KH for bug-gnu-emacs@gnu.org; Sat, 01 Jun 2024 14:55:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: "Elijah G." Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 01 Jun 2024 18:55:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 71159 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: Po Lu via "Bug reports for GNU Emacs, the Swiss army knife of text editors" X-Debbugs-Original-Cc: Po Lu , 71159@debbugs.gnu.org, Eli Zaretskii Original-Received: via spool by submit@debbugs.gnu.org id=B.171726808821832 (code B ref -1); Sat, 01 Jun 2024 18:55:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 1 Jun 2024 18:54:48 +0000 Original-Received: from localhost ([127.0.0.1]:57405 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sDTsN-0005g3-Ee for submit@debbugs.gnu.org; Sat, 01 Jun 2024 14:54:48 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:38340) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sDTsK-0005fu-8v for submit@debbugs.gnu.org; Sat, 01 Jun 2024 14:54:45 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sDTs4-0004Ni-NQ for bug-gnu-emacs@gnu.org; Sat, 01 Jun 2024 14:54:32 -0400 Original-Received: from mail-ot1-x341.google.com ([2607:f8b0:4864:20::341]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sDTs2-0005JW-IF; Sat, 01 Jun 2024 14:54:28 -0400 Original-Received: by mail-ot1-x341.google.com with SMTP id 46e09a7af769-6f8ef894ecdso1903068a34.1; Sat, 01 Jun 2024 11:54:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717268064; x=1717872864; darn=gnu.org; h=mime-version:user-agent:message-id:date:references:in-reply-to :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=G5jt0IEqqMWyO1Eym1qpLZyoGCHO5C6cFFKK/rh9Mw4=; b=JeuVUV4Iw8f2mSCaWGxX0jhs2n6hLg2+uD1u9dwxQ9NCgOD51jW49FGHW3ZmoAsyYj YQC7f7R8vQdDna9dhN3kRXV31ybtGYHE/OoI8uy2OGqbS+sOEycL8289d0z9WQ47EuEM MMsX/PBhGhvwNy6X3Dfq9l/Pgk3JaDBGgJHkt41wXYflPB+uZAI0Eg95wPhao6L0Afct 44uOWWTKGJleTpyUYEbBppmV5nnP6bupqrjji6e26q7CDAp6Gqyt3i8aPj6Ohr6yDs2L BXSxpokkxWyBL8UdqniZOiCqjkaGp9Nf3zywQqG/6jhKblmvDNIz93e+xKRMvHK4U85F Wfaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717268064; x=1717872864; h=mime-version:user-agent:message-id:date:references:in-reply-to :subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=G5jt0IEqqMWyO1Eym1qpLZyoGCHO5C6cFFKK/rh9Mw4=; b=gQh4jrryFxXQzEKgFo5FHnXyKNrVF9J3UrAkmuAPaQDRNMTdBth0HclAOwXW03hbM0 Kh5BKm+Z+SzcPnQZaQp/a3uMvhO19rQrx0LNqx//8yvXmB7AvPW43NAI/RKks6rKYzT3 IT/e4NLmnrYk/Hx/6o5bhg2oStCSjJ7iRXCwGYoxmhm1WxeCFVfCqhH33KjcRwS17aPG yltjeoGEoQFTMYUAHr1F/BRaz1SW7SuJ4e+Nja7vjeL1aQlXn6c0mh3ta3r1ed8xp6x0 mzjmxOfDl46izr91N0d1eijUDuBwezc1qM670BDGozpa8wQNnL7FKU0xP/r64OaPmcsr cUmQ== X-Forwarded-Encrypted: i=1; AJvYcCUSuVR52FJy68EEjr0RbXonfafqOSkn6cfko0q+Em3jvHbMC99Hy90Y5Qtoc3ExeChwOhz129968lltZo0= X-Gm-Message-State: AOJu0YyJINZqPq47mVts4K5VxyFc4D9FftaRMaxgmidXD0Y5xoH1CsAs q7oVdRkevmomTXm5m5bpomWRFimj4ZxY8rdUC0p9wyc6XMBYqwNLs0nQ5Wd7 X-Google-Smtp-Source: AGHT+IES9+g3QrRnq8T6FPVAy7ZD5BzPTPskkgKn42Da6v5kREFDtgVRnB34s46bwcBXO8Bin8DKxQ== X-Received: by 2002:a9d:6755:0:b0:6f8:d23e:78e0 with SMTP id 46e09a7af769-6f911fc9917mr4990202a34.38.1717268064379; Sat, 01 Jun 2024 11:54:24 -0700 (PDT) Original-Received: from LIBERO ([187.184.27.187]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-5ba004b3d60sm877082eaf.38.2024.06.01.11.54.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 01 Jun 2024 11:54:23 -0700 (PDT) In-Reply-To: <87ed9gkber.fsf@yahoo.com> (Po Lu via's message of "Sat, 01 Jun 2024 22:03:40 +0800") Received-SPF: pass client-ip=2607:f8b0:4864:20::341; envelope-from=eg642616@gmail.com; helo=mail-ot1-x341.google.com X-Spam_score_int: 1 X-Spam_score: 0.1 X-Spam_bar: / X-Spam_report: (0.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, PDS_OTHER_BAD_TLD=1.999, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:286345 Archived-At: --=-=-= Content-Type: text/plain Po Lu via "Bug reports for GNU Emacs, the Swiss army knife of text editors" writes: > "Elijah G." writes: > >> I've updated the patch for delete all the conflicts generated by >> ae7d0e86b37eabc434c48f85f56df0a221e0e7c7 commit. > > Thank you. Please find several comments below: > >> * 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. > > Please delete the redundant colon after the file name. > >> * src/image.c: >> (image_create_bitmap_from_data): Create stipple bitmap. >> (image_create_bitmap_from_file): Add suuport for pixmap and create >> stipple bitmap. > > Likewise. This commit message is also excessively wide, and must be > filled to remain within 64 columns. It's now fixed, sorry about that i couldn't find how to insert change-log skeleton or amend with vc.el, those where generated by `diff-add-change-log-entries-other-window'. >> +#ifdef HAVE_NTGUI >> +static HBITMAP w32_create_pixmap_from_bitmap_data (int width, >> + int height, >> + char *data); >> + >> +#endif > > It should be aesthetically better if the parameter names were deleted > from this declaration's type list, and all of the types placed on one > line. Done. >> + int nbytes, i; >> + ptrdiff_t sa_avail; /* Used only for SAFE_NALLOCA. */ > > ??? Please insert this boilerplate by means of the `USE_SAFE_ALLOCA' > macro. > >> + invertedBits = bits; >> + nbytes = (width + CHAR_BIT - 1) / CHAR_BIT * height; >> + sa_avail = MAX_ALLOCA >> + >> + SAFE_NALLOCA (bits, 1, nbytes); > > Shouldn't you subsequently call SAFE_FREE? Thank you, i forgot calling SAFE_FREE, i only defined sa_avail instead using USE_SAFE_ALLOCA because i was getting an unused variable warning. It's now fixed. >> + for (i = 0; i < nbytes; i++) >> + bits[i] = XBM_BIT_SHUFFLE(invertedBits[i]); > > Absent space between macro name and parameters. > >> + data[i] = XBM_BIT_SHUFFLE(data[i]); > > Here also. Done. >> + Emacs_Pixmap stipple; > > Should not the object in this field be released in `free_bitmap_record'? Yes, i forgot about it, it's fixed. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Stipple-support-for-MS-Windows.patch >From 6db0266a99dff476eb66ff00b310f650bd3ad0ea Mon Sep 17 00:00:00 2001 From: "Elias G. Perez" Date: Fri, 10 May 2024 20:36:42 -0600 Subject: [PATCH] Stipple support for MS Windows * etc/NEWS: Announce support for stipples in 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. (free_bitmap_record): Release stipple. --- etc/NEWS | 3 ++ src/image.c | 101 ++++++++++++++++++++++++++++++++++++++++++-------- src/w32term.c | 55 +++++++++++++++++---------- src/w32term.h | 1 + 4 files changed, 125 insertions(+), 35 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index 3c672ffed8f..f0aec17371f 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -2827,6 +2827,9 @@ thumbnail images and show them in the thumbnail buffer. Unlike with using 'convert', this fallback method is synchronous, so Emacs will wait until all the thumbnails are created and displayed, before showing them. +--- +*** Emacs on MS-Windows now supports the :stipple face attribute + ---------------------------------------------------------------------- This file is part of GNU Emacs. diff --git a/src/image.c b/src/image.c index 3138ef25a63..42f72780c24 100644 --- a/src/image.c +++ b/src/image.c @@ -130,6 +130,12 @@ #define NO_PIXMAP 0 #define PIX_MASK_RETAIN 0 #define PIX_MASK_DRAW 1 +#define XBM_BIT_SHUFFLE(b) (~(b)) + +#else + +#define XBM_BIT_SHUFFLE(b) (b) + #endif /* HAVE_NTGUI */ #ifdef HAVE_NS @@ -214,6 +220,11 @@ #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, int, char *); + +#endif + #if defined (HAVE_WEBP) || defined (HAVE_GIF) static void anim_prune_animation_cache (Lisp_Object); #endif @@ -596,13 +607,34 @@ image_create_bitmap_from_data (struct frame *f, char *bits, #endif /* HAVE_ANDROID && !defined ANDROID_STUBIFY */ #ifdef HAVE_NTGUI - Lisp_Object frame UNINIT; /* The value is not used. */ - Emacs_Pixmap bitmap; + Emacs_Pixmap stipple, bitmap; bitmap = CreateBitmap (width, height, - FRAME_DISPLAY_INFO (XFRAME (frame))->n_planes, - FRAME_DISPLAY_INFO (XFRAME (frame))->n_cbits, + dpyinfo->n_planes, + dpyinfo->n_cbits, bits); - if (! bitmap) + + /* Convert X bitmap to W32 bitmap. */ + /* Windows mono bitmaps are reversed compared with X. */ + USE_SAFE_ALLOCA; + + { + char *invertedBits; + int nbytes, i; + + invertedBits = bits; + nbytes = (width + CHAR_BIT - 1) / CHAR_BIT * height; + + SAFE_NALLOCA (bits, 1, nbytes); + + for (i = 0; i < nbytes; i++) + bits[i] = XBM_BIT_SHUFFLE (invertedBits[i]); + } + + stipple = w32_create_pixmap_from_bitmap_data (width, height, bits); + + SAFE_FREE (); + + if (!bitmap || !stipple) return -1; #endif /* HAVE_NTGUI */ @@ -681,6 +713,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 +732,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 +744,53 @@ 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; + } + + { + /* Windows mono bitmaps are reversed compared with X. */ + + int nbytes, i; + nbytes = (width + CHAR_BIT - 1) / CHAR_BIT * height; + + for (i = 0; i < nbytes; i++) + data[i] = XBM_BIT_SHUFFLE (data[i]); + } + + 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); + + xfree (contents); + xfree (data); + return id; #endif #ifdef HAVE_NS @@ -1037,6 +1113,7 @@ free_bitmap_record (Display_Info *dpyinfo, Bitmap_Record *bm) #ifdef HAVE_NTGUI DeleteObject (bm->pixmap); + DeleteObject (bm->stipple); #endif /* HAVE_NTGUI */ #ifdef HAVE_NS @@ -4800,12 +4877,6 @@ convert_mono_to_color_image (struct frame *f, struct image *img, img->pixmap = new_pixmap; } -#define XBM_BIT_SHUFFLE(b) (~(b)) - -#else - -#define XBM_BIT_SHUFFLE(b) (b) - #endif /* HAVE_NTGUI */ diff --git a/src/w32term.c b/src/w32term.c index 2bcd5d86a38..3ef6d0f11f1 100644 --- a/src/w32term.c +++ b/src/w32term.c @@ -1248,6 +1248,34 @@ 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) +{ + SetTextColor (hdc, gc->foreground); + SetBkColor (hdc, gc->background); + + RECT r; + Emacs_Pixmap bm; + HBRUSH hb; + + r.left = x; + r.top = y; + r.right = x + width; + r.bottom = y + height; + + bm = FRAME_DISPLAY_INFO (s->f)->bitmaps[s->face->stipple - 1].stipple; + + hb = CreatePatternBrush (bm); + 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 +1292,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 +2309,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 +2519,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 a19be1a9e6a..38eac4230dd 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 --=-=-=--