From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Arash Esbati Newsgroups: gmane.emacs.bugs Subject: bug#73384: [PATCH] Draw coloured stipples on NS Date: Mon, 21 Oct 2024 20:23:57 +0200 Message-ID: References: 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="12723"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: Rudolf =?UTF-8?Q?Adamkovi=C4=8D?= , 73384@debbugs.gnu.org, Stefan Kangas To: Ben Simms Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Oct 21 20:24:51 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 1t2x5F-00039J-Vx for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 21 Oct 2024 20:24:50 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t2x56-0008UP-Pw; Mon, 21 Oct 2024 14:24:40 -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 1t2x51-0008U7-L1 for bug-gnu-emacs@gnu.org; Mon, 21 Oct 2024 14:24:37 -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 1t2x51-0001Wd-Cl for bug-gnu-emacs@gnu.org; Mon, 21 Oct 2024 14:24:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:Date:References:In-Reply-To:From:To:Subject; bh=yq45uyNMa9twezFac4zCPBm+IgY2CQ7yCNFjvb3v3TQ=; b=gHWDmNPx/ltGAwIR5+tnPriItwE6eFWsEgOn5z2LCMQ4VLUQGHLAsTmcCuox/cQDxCcxiZqITCOEDNL0TO+wBKZG2cnGieYxMTd6mk3yP4mqvJuc0BuRWv8NBmWzlF8fe0lsIh9o+XK3bw+rjRZ0wLAsMUiwBXXvV7Vblb8EsjsTd68Sw+UE7divrxItH6o/qvJyowyaOo5TLb4ZP7ZXuK9Doc0K0Y83LmhFBxtxRmGrH6qpmqddejMVjFeAjPvsUQACWdxyHTx3RzZnGLEgyEXJoO1eO1ZPFJZfwShGSqyEqYCvMDqLGBRxY0ICC/C4vcHeOl0NZe3TctC07exggg==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1t2x5S-0007Al-4P for bug-gnu-emacs@gnu.org; Mon, 21 Oct 2024 14:25:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Arash Esbati Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 21 Oct 2024 18:25:02 +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.172953507927532 (code B ref 73384); Mon, 21 Oct 2024 18:25:02 +0000 Original-Received: (at 73384) by debbugs.gnu.org; 21 Oct 2024 18:24:39 +0000 Original-Received: from localhost ([127.0.0.1]:53327 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1t2x54-00079z-SK for submit@debbugs.gnu.org; Mon, 21 Oct 2024 14:24:39 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:42160) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1t2x51-00079i-MB for 73384@debbugs.gnu.org; Mon, 21 Oct 2024 14:24:37 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t2x4S-0001Vo-OP; Mon, 21 Oct 2024 14:24:01 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:Date:References:In-Reply-To:Subject:To: From; bh=yq45uyNMa9twezFac4zCPBm+IgY2CQ7yCNFjvb3v3TQ=; b=OxxH3Hgd+aBRZnBuRIHP QYRz0QZd+DZOR9EZJ9Eebd1Ixh5JFYo9Mxy0Qf52IdHOq7MvbWuK+3aHaFq8aKlWAB+rYzZBAcsZZ X+ftQ3Nn8nu8UwKJlff2xveVrN/JZ4MxN4TMeIT8+cAozrrljS/J80EB+lajtvhzGSINUMyQxKe0z ncNI36RGFbRZ4bNTviFMYt6MpmxdeXXfN6ZppFO1E6aZPYumysZDK6+0+mbh2uiqxGnVKVg2k7N9I rVzfaE+2/4+Dl+NRR7KmivgBVYs2Ui9R7jUI/zj3P9y3id1VFGE0zKOmQUVUdzo2dn0/UmFznLXBS A6hAem+r4JCijQ==; In-Reply-To: (Ben Simms's message of "Sat, 19 Oct 2024 10:34:02 +0200") 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:294080 Archived-At: --=-=-= Content-Type: text/plain Ben Simms writes: > Sure, this is the patch from 6213ca44 Thanks. I copied the patch into the file attached and tried it again, but still no avail: $ git apply 00stipple.patch 00stipple.patch:179: trailing whitespace. #else error: patch failed: src/nsterm.m:3823 error: src/nsterm.m: patch does not apply What am I missing? Best, Arash --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=00stipple.patch >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 --=-=-=--