From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Alex Gramiak Newsgroups: gmane.emacs.bugs Subject: bug#35468: [PATCH] Refactor draw_glyph_string on X and w32 Date: Fri, 03 May 2019 13:01:18 -0600 Message-ID: <877eb7l5vl.fsf@gmail.com> References: <877ebeor2d.fsf@gmail.com> <83tveit5ph.fsf@gnu.org> <87pnp5oqu1.fsf@gmail.com> <877ebcogg4.fsf@gmail.com> <83sgu0rsue.fsf@gnu.org> <8736lznzjf.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="260147"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.2 (gnu/linux) Cc: 35468@debbugs.gnu.org To: mituharu@math.s.chiba-u.ac.jp Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri May 03 23:14:49 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hMfW1-0012u5-Rp for geb-bug-gnu-emacs@m.gmane.org; Fri, 03 May 2019 23:14:45 +0200 Original-Received: from localhost ([127.0.0.1]:46114 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hMdRh-0003of-5R for geb-bug-gnu-emacs@m.gmane.org; Fri, 03 May 2019 15:02:09 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:55611) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hMdRb-0003oX-BI for bug-gnu-emacs@gnu.org; Fri, 03 May 2019 15:02:04 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hMdRa-0003wn-7J for bug-gnu-emacs@gnu.org; Fri, 03 May 2019 15:02:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:36127) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hMdRa-0003wZ-3l for bug-gnu-emacs@gnu.org; Fri, 03 May 2019 15:02:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hMdRZ-0002CN-Ta for bug-gnu-emacs@gnu.org; Fri, 03 May 2019 15:02:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Alex Gramiak Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 03 May 2019 19:02:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 35468 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 35468-submit@debbugs.gnu.org id=B35468.15569100868411 (code B ref 35468); Fri, 03 May 2019 19:02:01 +0000 Original-Received: (at 35468) by debbugs.gnu.org; 3 May 2019 19:01:26 +0000 Original-Received: from localhost ([127.0.0.1]:49671 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hMdR0-0002Ba-E2 for submit@debbugs.gnu.org; Fri, 03 May 2019 15:01:26 -0400 Original-Received: from mail-pg1-f171.google.com ([209.85.215.171]:36022) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hMdQy-0002BN-Q5 for 35468@debbugs.gnu.org; Fri, 03 May 2019 15:01:25 -0400 Original-Received: by mail-pg1-f171.google.com with SMTP id 85so3142177pgc.3 for <35468@debbugs.gnu.org>; Fri, 03 May 2019 12:01:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=Qey9XNZXA29HJ4q1ubc7hQaeY6l7CqRUnBfHZA5Itm4=; b=uw55Fq6llW3KN+S87p0ptJZNEli51kMQGblSaCAS9+05o8v2eVPIgfI2WB10h5qbwN PvUBcA7HO6C8yhk3u5TM28sggG/csOg1HwWCb1gqCT7phLhHNQuKo1utojXLXXq3DPzj dxZE4Gm0lYitjkmRii0IIyQhR7Z/9L23Hsu9mdjQI2NiDJXEyeq2FXuFoCsbfzDF4hMG 1tDry6wl5MtoSZAASrobcyfLB2Tv63RJxBa7SrbQYTgBBgDYal+S4zD+yBbemkUvrwtW NMqmXQ5GDYb+W/zuN/NDztHyA+YIsffMP4NyRhcUSVempiZZL4o8L7b6OlrPAPI4h26w Xy7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=Qey9XNZXA29HJ4q1ubc7hQaeY6l7CqRUnBfHZA5Itm4=; b=reOY7c5RDU5DtCeRc0/z3oRAyzkpJ7uqzhtMMClpPqYt3YWL2vqnx4WKJycKcNlKIe ZExsB4KHZ0x6XImvbivMssgDt98J58c1JvkLcIbNiV5BDB7f0vJhSD0ekX9MlpcBL7W3 BH64cGNqpGPgg1HnR1hPiicrS9Dcf9EBbLqvAn/lDArT5KmnMybE0g+KMl2AKdGTdJB1 BPHJtZU+IknO1lOXMYD7bvTEHETPf/wfEKCb8Fgl9fDYnKjUIXzt+aztTnTUrZsy+m6R grAgvUMnJyvvnaQNJSGekSKuYJHHvy4HfFxBFbeodfgU9pGyCJ26heJS83EEJgTxL/C1 Xj4w== X-Gm-Message-State: APjAAAX5r6hRkrUY+MaavWqFZbef3dlzOFrHbBnims5mxwYN9U8bMyBy gdJKRmdU7JOmi07Cl4Jwi0wn0ZGK X-Google-Smtp-Source: APXvYqy39BjK8heARRF7p8ojZ/OGJZJ+clry3VVEbs/wVHlZvxGIIfNAZAUeHhg/tC+I9Hk8LSEPkw== X-Received: by 2002:a62:a503:: with SMTP id v3mr13278764pfm.32.1556910078450; Fri, 03 May 2019 12:01:18 -0700 (PDT) Original-Received: from lylat ([2604:3d09:e37f:1500:1a72:4878:e793:7302]) by smtp.gmail.com with ESMTPSA id e29sm3343515pgb.37.2019.05.03.12.01.16 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 03 May 2019 12:01:17 -0700 (PDT) In-Reply-To: (mituharu@math.s.chiba-u.ac.jp's message of "Wed, 1 May 2019 09:14:50 +0900") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 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.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:158689 Archived-At: mituharu@math.s.chiba-u.ac.jp writes: > Unlike the NS port, the terminal code in the Mac port is much like the X11 > version. I looked at your code and fortunately it indeed looks like the same abstractions for glyph drawing that would work for the X11 version would work for the Mac port. > But there is one notable difference in the above respect. > It defines mac_erase_rectangle, which is like mac_fill_rectangle (the > XFillRectangle counterpart) > but uses the background color of GC and also handles stipples: > > /* Mac replacement for XFillRectangle. */ > > static void > mac_fill_rectangle (struct frame *f, GC gc, int x, int y, int width, int > height) > { > MAC_BEGIN_DRAW_TO_FRAME (f, gc, context); > CGContextSetFillColorWithColor (context, gc->cg_fore_color); > { > CGRect rect = mac_rect_make (f, x, y, width, height); > > CGContextFillRects (context, &rect, 1); > } > MAC_END_DRAW_TO_FRAME (f); > } > > static void > mac_erase_rectangle (struct frame *f, GC gc, int x, int y, > int width, int height) > { > MAC_BEGIN_DRAW_TO_FRAME (f, gc, context); > { > CGRect rect = mac_rect_make (f, x, y, width, height); > > CG_CONTEXT_FILL_RECT_WITH_GC_BACKGROUND (f, context, rect, gc); > if (gc->xgcv.fill_style == FillOpaqueStippled && gc->xgcv.stipple) > { > CGContextClipToRects (context, &rect, 1); > CGContextSetFillColorWithColor (context, gc->cg_fore_color); > int scale = CFArrayGetCount (gc->xgcv.stipple); > if (FRAME_BACKING_SCALE_FACTOR (f) < scale) > scale = FRAME_BACKING_SCALE_FACTOR (f); > CGImageRef image_mask = > (CGImageRef) CFArrayGetValueAtIndex (gc->xgcv.stipple, scale - 1); > rect = CGRectMake (0, 0, CGImageGetWidth (image_mask) / (CGFloat) scale, > CGImageGetHeight (image_mask) / (CGFloat) scale); > CGContextScaleCTM (context, 1, -1); > CGContextSetInterpolationQuality (context, kCGInterpolationNone); > CGContextDrawTiledImage (context, rect, image_mask); > } > } > MAC_END_DRAW_TO_FRAME (f); > } Why does it use the background color of GC? It appears that the Cairo version uses the foreground color of GC; is that because the Cairo version doesn't handle stippling? > I guess introducing the erase_rectagle handler makes things simpler and > efficient. Looking over the code, and considering that stippling is quite uncommon nowadays (GTK 3 removed it, AFAIK), I think the best approach would be to define 3 separate interface procedures: 1) fill_rectangle: handles x_fill_rectangle/mac_fill_rectangle 2) fill_rectangle_with_color: handles (1), but also with the temporary overriding of the GC that's done frequently for mac_erase_rectangle. 3) fill_rectangle_with_stipple: handles the temporary XFillStyle overriding of the GC. A third procedure wouldn't be inelegant in comparison to the alternatives, since otherwise I would need a set_context_stipple procedure to indicate stippling. Then mac_fill_rectangle can be assigned to fill_rectangle, and mac_erase_rectangle can be assigned to fill_rectangle_with_stipple.