From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Kangas Newsgroups: gmane.emacs.bugs Subject: bug#73384: [PATCH] Draw coloured stipples on NS Date: Sun, 15 Dec 2024 14:21:31 +0000 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="18800"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Rudolf =?UTF-8?Q?Adamkovi=C4=8D?= , 73384@debbugs.gnu.org, Alan Third , JD Smith , Ben Simms To: Arash Esbati Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Dec 15 15:23:16 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 1tMpWd-0004kS-Of for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 15 Dec 2024 15:23:15 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tMpWT-0004s4-39; Sun, 15 Dec 2024 09:23:05 -0500 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 1tMpWQ-0004rM-OJ for bug-gnu-emacs@gnu.org; Sun, 15 Dec 2024 09:23:03 -0500 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 1tMpWQ-0005Z0-EQ for bug-gnu-emacs@gnu.org; Sun, 15 Dec 2024 09:23:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=Date:MIME-Version:References:In-Reply-To:From:To:Subject; bh=ymxMiidLZfzaHEoiL2dIC88fKX9l4oN8C5aTTdPgRho=; b=PT5TjUjhfKhdZ54kuu2UkRHsWAcMAfFHiMlMiuJDrjdrgzdWjQdb37YF9lHHI5jS2/CK/ahznMxF9USUz57Nrh2gy2VP4cCLui7y5m4nUToLn1td3how0gUM0GPKa2fj9r1tokgRlJ9/7MKTNR+5RBHZGw3LRuLKNiuUmnBliqKNSx2k9F+Vdajr4WIEmwDlZsFwnqO20PGXwXgILkEoI8YIowXmkc18SzY3UrfVbRbcjOj13Dm4r6Baxeq0lsTBQLaWMZitYhMn/by60/7vFFhmYyygKwz9JbZ5Rr7wRrCvkHtK1Zf8jy98SPFPkCY0JfpEj7cUsAIFzz29EQuQsw==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tMpWQ-0008F5-1r for bug-gnu-emacs@gnu.org; Sun, 15 Dec 2024 09:23:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Kangas Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 15 Dec 2024 14:23:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 73384 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 73384-submit@debbugs.gnu.org id=B73384.173427256031647 (code B ref 73384); Sun, 15 Dec 2024 14:23:01 +0000 Original-Received: (at 73384) by debbugs.gnu.org; 15 Dec 2024 14:22:40 +0000 Original-Received: from localhost ([127.0.0.1]:50012 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tMpW3-0008EM-Tf for submit@debbugs.gnu.org; Sun, 15 Dec 2024 09:22:40 -0500 Original-Received: from mail-ej1-f47.google.com ([209.85.218.47]:44094) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tMpVz-0008EC-AB for 73384@debbugs.gnu.org; Sun, 15 Dec 2024 09:22:37 -0500 Original-Received: by mail-ej1-f47.google.com with SMTP id a640c23a62f3a-a9f1d76dab1so674932966b.0 for <73384@debbugs.gnu.org>; Sun, 15 Dec 2024 06:22:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734272494; x=1734877294; darn=debbugs.gnu.org; h=cc:to:subject:message-id:date:mime-version:references:in-reply-to :from:from:to:cc:subject:date:message-id:reply-to; bh=ymxMiidLZfzaHEoiL2dIC88fKX9l4oN8C5aTTdPgRho=; b=iDtAS4osZFGHQYSE9pfgWx23LxJo1m8uVrOPOniB9POHLigmow/JNc8RQ2DjIBCS5W XAEIlYvEJmC8YH3oUKdTcpkrpkN8hXbvPHbhdI+TMPzECMp2vogVrMRZTRHuP6M/Czli B0hVQBnOZxdl0hLYGTkCeCenhw6RgHLVP4Hz96KzFUVYs2GkCZvm3w+KFJQ7OQh3Bn9k +3HxbffrhQwu4J7868v7V7+2JfbYO5LtYUCDApAbgFTRSVICCBeJ99z+mYqT8qjotYR9 ZYLOiQqSnuM99xeLQ//BpSzRJZh1pLX7BD345PAHVzyaiSiDk3ZTf8QgHnl1mDi+ewNx /55w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734272494; x=1734877294; h=cc:to:subject:message-id:date:mime-version:references:in-reply-to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ymxMiidLZfzaHEoiL2dIC88fKX9l4oN8C5aTTdPgRho=; b=Mv0B/AxH9xUQGPqlm+q3Xeh+CLHYJnmSvv3GsIJ7gXupOqpoQHi2f1MN+5MFTyuNF5 jCm8108G4K3l8r4JcHzyg1ZxTNgmqFArhg3FALjpliXFvVo76llNbCNJRjH9EYaUDAi6 cwkYL8xRB8uKZ1MEhy/pbvE7qiUlCSy6C4F/kIyJ/7galZobWE55pWcrnQNixAbyaWiy pSST7WN/q8KgW8G/unR/ExhuE7cpB3R1scDIa/T5BpVMBWQW5OmqKLUzjgMsVVV/cKdW yUgH/DlSWyjhGYeqfFoFR0T1Q3+GVEjpGL/AsGAT6RoFQB8lGrfVcuFBasHdUg+TtRWU 3+fw== X-Gm-Message-State: AOJu0YzxnHmdJ3JSVJ6GQ2CyVUX/HzQkG7yC+5UX1Z1tX2SgBQ3PF1Qi vo4rN9O+xeNAzFUsEsn64/I4+6vduLsQ20191UA3Vex9HpOoJZQ5M4NSxYPutPy7eDyYgOmcYJf 52cHbDukLja5G6ZdamDlGE0iFBPA= X-Gm-Gg: ASbGncv0pbgTzeMQnfLWLr9krVJGyEWAE/vrmQu4oUcheisw3v+ZF4RSPTBlGa+Eqxj sKe2689YS1aFU3c6PmORD16+FmWWh+e32NJiNyDI= X-Google-Smtp-Source: AGHT+IF421QqGfDbBVmj8GmCY7Py0bD7OFf6rxcQRzYOE8stJrzuqaJJfzee1RDpM5822flglfVSWzvBoKi6hkQ/TSg= X-Received: by 2002:a17:907:2cc6:b0:aa6:8bb4:502e with SMTP id a640c23a62f3a-aab778c7b34mr1019119266b.6.1734272492455; Sun, 15 Dec 2024 06:21:32 -0800 (PST) Original-Received: from 753933720722 named unknown by gmailapi.google.com with HTTPREST; Sun, 15 Dec 2024 14:21:31 +0000 In-Reply-To: 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:297106 Archived-At: Alan, do you have any comments on the below patch? Thanks in advance. Arash Esbati writes: > Arash Esbati writes: > >> Stefan, did you have a chance to look at this again? I'm attaching the >> patch Ben sent me off-list. Maybe you can advise how to proceed and get >> this installed. TIA. > > Ping! > > Do you see a chance to install this change? Or should I ask Alan Third > if he can kindly have a look? > > From 1c4b8efb82bd0e35c91d98f2759217702f3a7c65 Mon Sep 17 00:00:00 2001 > From: Ben Simms > Date: Mon, 14 Oct 2024 19:32:53 +0100 > Subject: [PATCH] Use masked coregraphics images on cocoa NS > > --- > src/nsimage.m | 31 +++++++++++++++++++++++++++++++ > src/nsterm.h | 8 ++++++++ > src/nsterm.m | 47 +++++++++++++++++++++++++++++++++++++++++++++-- > 3 files changed, 84 insertions(+), 2 deletions(-) > > diff --git a/src/nsimage.m b/src/nsimage.m > index ee72d6e0ea1..e36cbe5dc87 100644 > --- a/src/nsimage.m > +++ b/src/nsimage.m > @@ -35,6 +35,9 @@ Updated by Christian Limpach (chris@nice.ch) > #include "frame.h" > #include "coding.h" > > +#ifdef NS_IMPL_COCOA > +#include > +#endif > > #if defined (NS_IMPL_GNUSTEP) || MAC_OS_X_VERSION_MAX_ALLOWED < 1070 > # define COLORSPACE_NAME NSCalibratedRGBColorSpace > @@ -289,7 +292,11 @@ + (instancetype)allocInitFromFile: (Lisp_Object)file > > - (void)dealloc > { > +#ifdef NS_IMPL_COCOA > + CGImageRelease(stippleMask); > +#else > [stippleMask release]; > +#endif > [bmRep release]; > [transform release]; > [super dealloc]; > @@ -300,7 +307,11 @@ - (id)copyWithZone:(NSZone *)zone > { > EmacsImage *copy = [super copyWithZone:zone]; > > +#ifdef NS_IMPL_COCOA > + copy->stippleMask = CGImageCreateCopy(stippleMask); > +#else > copy->stippleMask = [stippleMask copyWithZone:zone]; > +#endif /* NS_IMPL_COCOA */ > copy->bmRep = [bmRep copyWithZone:zone]; > copy->transform = [transform copyWithZone:zone]; > > @@ -509,6 +520,25 @@ - (void) setAlphaAtX: (int) x Y: (int) y to: (unsigned char) a > } > } > > +#ifdef NS_IMPL_COCOA > +/* Returns a cached CGImageMask of the stipple pattern */ > +- (CGImageRef)stippleMask > +{ > + if (stippleMask == nil) { > + CGDataProviderRef provider = CGDataProviderCreateWithData (NULL, [bmRep bitmapData], > + [self sizeInBytes], NULL); > + CGImageRef mask = CGImageMaskCreate( > + [self size].width, > + [self size].height, > + 8, 8, [self size].width, > + provider, NULL, 0); > + > + CGDataProviderRelease(provider); > + stippleMask = CGImageRetain(mask); > + } > + return stippleMask; > +} > +#else > /* Returns a pattern color, which is cached here. */ > - (NSColor *)stippleMask > { > @@ -516,6 +546,7 @@ - (NSColor *)stippleMask > stippleMask = [[NSColor colorWithPatternImage: self] retain]; > return stippleMask; > } > +#endif /* NS_IMPL_COCOA */ > > /* Find the first NSBitmapImageRep which has multiple frames. */ > - (NSBitmapImageRep *)getAnimatedBitmapImageRep > diff --git a/src/nsterm.h b/src/nsterm.h > index 6c67653705e..2370f6ea3fb 100644 > --- a/src/nsterm.h > +++ b/src/nsterm.h > @@ -671,7 +671,11 @@ #define NSTRACE_UNSILENCE() > { > NSBitmapImageRep *bmRep; /* used for accessing pixel data */ > unsigned char *pixmapData[5]; /* shortcut to access pixel data */ > +#ifdef NS_IMPL_COCOA > + CGImageRef stippleMask; > +#else > NSColor *stippleMask; > +#endif // NS_IMPL_COCOA > @public > NSAffineTransform *transform; > BOOL smoothing; > @@ -688,7 +692,11 @@ #define NSTRACE_UNSILENCE() > green: (unsigned char)g blue: (unsigned char)b > alpha:(unsigned char)a; > - (void)setAlphaAtX: (int)x Y: (int)y to: (unsigned char)a; > +#ifdef NS_IMPL_COCOA > +- (CGImageRef)stippleMask; > +#else > - (NSColor *)stippleMask; > +#endif // NS_IMPL_COCOA > - (Lisp_Object)getMetadata; > - (BOOL)setFrame: (unsigned int) index; > - (void)setTransform: (double[3][3]) m; > diff --git a/src/nsterm.m b/src/nsterm.m > index f68a22d9fbc..a617669cb4d 100644 > --- a/src/nsterm.m > +++ b/src/nsterm.m > @@ -3823,8 +3823,31 @@ Function modeled after x_draw_glyph_string_box (). > if (s->stippled_p) > { > struct ns_display_info *dpyinfo = FRAME_DISPLAY_INFO (s->f); > +#ifdef NS_IMPL_COCOA > + [[NSColor colorWithUnsignedLong:face->background] set]; > + r = NSMakeRect (s->x, s->y + box_line_width, > + s->background_width, > + s->height - 2 * box_line_width); > + NSRectFill (r); > + s->background_filled_p = 1; > + CGImageRef mask = [dpyinfo->bitmaps[face->stipple - 1].img stippleMask]; > + CGRect bounds = CGRectMake (s->x, s->y + box_line_width, > + s->background_width, > + s->height - 2 * box_line_width); > + NSGraphicsContext *ctx = [NSGraphicsContext currentContext]; > + [ctx saveGraphicsState]; > + CGContextRef context = [ctx CGContext]; > + CGContextClipToRect (context, bounds); > + CGContextScaleCTM (context, 1, -1); > + [[NSColor colorWithUnsignedLong:face->foreground] set]; > + CGRect imageSize = CGRectMake (0, 0, CGImageGetWidth (mask), CGImageGetHeight (mask)); > + CGContextDrawTiledImage (context, imageSize, mask); > + [[NSGraphicsContext currentContext] restoreGraphicsState]; > +#else > [[dpyinfo->bitmaps[face->stipple-1].img stippleMask] set]; > goto fill; > +#endif /* NS_IMPL_COCOA */ > + > } > else if (FONT_HEIGHT (s->font) < s->height - 2 * box_line_width > /* When xdisp.c ignores FONT_HEIGHT, we cannot trust font > @@ -3847,7 +3870,9 @@ Function modeled after x_draw_glyph_string_box (). > else > [FRAME_CURSOR_COLOR (s->f) set]; > > +#ifndef NS_IMPL_COCOA > fill: > +#endif /* !NS_IMPL_COCOA */ > r = NSMakeRect (s->x, s->y + box_line_width, > s->background_width, > s->height - 2 * box_line_width); > @@ -4171,8 +4196,26 @@ Function modeled after x_draw_glyph_string_box (). > dpyinfo = FRAME_DISPLAY_INFO (s->f); > if (s->hl == DRAW_CURSOR) > [FRAME_CURSOR_COLOR (s->f) set]; > - else if (s->stippled_p) > - [[dpyinfo->bitmaps[s->face->stipple - 1].img stippleMask] set]; > + else if (s->stippled_p) { > +#ifdef NS_IMPL_COCOA > + [[NSColor colorWithUnsignedLong:s->face->background] set]; > + NSRectFill (NSMakeRect (x, s->y, background_width, s->height)); > + CGImageRef mask = [dpyinfo->bitmaps[s->face->stipple - 1].img stippleMask]; > + CGRect bounds = CGRectMake (s->x, s->y, s->background_width, s->height); > + NSGraphicsContext *ctx = [NSGraphicsContext currentContext]; > + [ctx saveGraphicsState]; > + CGContextRef context = [ctx CGContext]; > + CGContextClipToRect(context, bounds); > + CGContextScaleCTM (context, 1, -1); > + [[NSColor colorWithUnsignedLong:s->face->foreground] set]; > + CGRect imageSize = CGRectMake (0, 0, CGImageGetWidth (mask), > + CGImageGetHeight (mask)); > + CGContextDrawTiledImage (context, imageSize, mask); > + [[NSGraphicsContext currentContext] restoreGraphicsState]; > +#else > + [[dpyinfo->bitmaps[s->face->stipple - 1].img stippleMask] set]; > +#endif /* NS_IMPL_COCOA */ > + } > else > [[NSColor colorWithUnsignedLong: s->face->background] set]; > > -- > 2.46.0