From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Federico Tedin Newsgroups: gmane.emacs.bugs Subject: bug#34001: 26.1.90; :distant-foreground face property fails to work in most cases Date: Tue, 15 Jan 2019 22:08:15 -0300 Message-ID: <87a7k1l88w.fsf@gmail.com> References: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1547600831 11515 195.159.176.226 (16 Jan 2019 01:07:11 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 16 Jan 2019 01:07:11 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) To: Tina Russell , 34001@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Jan 16 02:07:07 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 esmtp (Exim 4.84_2) (envelope-from ) id 1gjZfc-0002qV-Sw for geb-bug-gnu-emacs@m.gmane.org; Wed, 16 Jan 2019 02:07:05 +0100 Original-Received: from localhost ([127.0.0.1]:38405 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gjZhj-0008TK-Db for geb-bug-gnu-emacs@m.gmane.org; Tue, 15 Jan 2019 20:09:15 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:49153) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gjZha-0008T4-RQ for bug-gnu-emacs@gnu.org; Tue, 15 Jan 2019 20:09:07 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gjZhW-0004Wy-JS for bug-gnu-emacs@gnu.org; Tue, 15 Jan 2019 20:09:03 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:32960) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gjZhW-0004VZ-7P for bug-gnu-emacs@gnu.org; Tue, 15 Jan 2019 20:09:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1gjZhW-0002w9-1i for bug-gnu-emacs@gnu.org; Tue, 15 Jan 2019 20:09:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Federico Tedin Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 16 Jan 2019 01:09:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 34001 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 34001-submit@debbugs.gnu.org id=B34001.154760091211251 (code B ref 34001); Wed, 16 Jan 2019 01:09:01 +0000 Original-Received: (at 34001) by debbugs.gnu.org; 16 Jan 2019 01:08:32 +0000 Original-Received: from localhost ([127.0.0.1]:60474 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gjZgy-0002vI-Oc for submit@debbugs.gnu.org; Tue, 15 Jan 2019 20:08:32 -0500 Original-Received: from mail-qt1-f180.google.com ([209.85.160.180]:41491) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gjZgv-0002v1-Vs for 34001@debbugs.gnu.org; Tue, 15 Jan 2019 20:08:26 -0500 Original-Received: by mail-qt1-f180.google.com with SMTP id l12so5287642qtf.8 for <34001@debbugs.gnu.org>; Tue, 15 Jan 2019 17:08:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:references:date:in-reply-to:message-id:user-agent :mime-version; bh=gIFZotwgzaPsQBnRvjEZinpRn+mDYsbOhwyATBfJbSE=; b=Dl+YZHnx/AS8WQ8e78k1Le3u4FWebFhJ3kVx5cQ+w5dpALFv/6z7Q4LiGgjqesoS9r cSMAk8K85xUgZybwy4YrVNtvUGIq7zo5EfC85X7lyhAsKqIt6seVD0qRmnWA5cvC2fP8 DKR/zBcTLL2AUnkaBYNXMRmCrebub0DsHdq8aQWprxw/NhbVFkLpAKlkFLyGaU1fAFkE QyFEFAZfF67bR2rn0K2iwexqBa4Ods+onbP2NBfvZHJzdYqhyof/VHkhQtKX0tO2JOon GkHqMD3QEaKOuk/sk5KPSrGsaM60Hskm7Het00Ht1XK86a/vMlFtGPiI9D5jHZzb3JKz WePw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=gIFZotwgzaPsQBnRvjEZinpRn+mDYsbOhwyATBfJbSE=; b=YIZWPfuW396/1QDuMFb+KuQcWNfifyeTP993QeoADoqwN3U0cAAzRxz+fR3tW2SPJU zRbG9IG6gJW14SEVZwiZ4NYkt2nBwm8s5mVsyTG97Z/4SrVGGb3N27qxmlXvT7m4m5VJ A1eUH6cmtPD9lA4vAgJF5OpnzhmHExf+DLSIKCoF3glNNCD3GrTqIu+D9+eWjqwGI3Pk GjyVnqf4SRmN6sZ6TsqFzFNLH6Y1tStXEqO+AxlgfcWX5ctpCeonslk9VM3CRkAqKHCX mY39hA8+NilZ8w+LkxCic6FpegmXjr3a0fEZFDGR8IhUEf/ufdy1yjtdCDSws6Pr9FIY sU9g== X-Gm-Message-State: AJcUukdn/YfkDkWP3AH3a/9uG5Lulf8zafpAFrM4PMpPhjmxzKxz0KW0 2DIAQSN60Zq13oxLNOiTHmFTOXsQ X-Google-Smtp-Source: ALg8bN6EX64aCFUPdWV8hWDdFnkp7eNbkhRYYpIqtCSjozC/qOFmnmzbO0s3kZ5sPgeY1sBRkDLCvQ== X-Received: by 2002:a0c:8322:: with SMTP id j31mr5155780qva.56.1547600899912; Tue, 15 Jan 2019 17:08:19 -0800 (PST) Original-Received: from hideo ([186.139.31.173]) by smtp.gmail.com with ESMTPSA id t5sm24270467qkl.14.2019.01.15.17.08.17 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 15 Jan 2019 17:08:18 -0800 (PST) In-Reply-To: (Tina Russell's message of "Sun, 6 Jan 2019 14:31:51 -0800") 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:154466 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Tina Russell writes: > :distant-foreground is a very useful concept for a face property: text > will be rendered with the :foreground color, unless it=E2=80=99s too clos= e to > the current background color, in which case :distant-foreground kicks > in. Like, try this in Eshell or IELM: > > (propertize "Greetings, esteemed Emacs developers!" 'face '(:foreground > "yellow" :background "yellow")) > > You=E2=80=99ll get a solid band of yellow, of course. But, with > :distant-foreground=E2=80=A6 > > (propertize "Greetings, esteemed Emacs developers!" 'face '(:foreground > "yellow" :background "yellow" :distant-foreground "black")) > > Now it is a friendly greeting. (Naturally, you wouldn=E2=80=99t normally = set > :background and :distant-foreground in the same face, this is just an > example.) > > But, try this: > > (propertize "Greetings, esteemed Emacs developers!" 'face '(:foreground > "yellow" :background "white" :distant-foreground "black")) > > :distant-foreground doesn=E2=80=99t kick in=E2=80=94and you=E2=80=99re le= ft with yellow-on-white > text that=E2=80=99s impossible to read, the exact scenario that > :distant-foreground was quite rightly designed to avoid. > > I=E2=80=99m not the only one who=E2=80=99s noticed this; there=E2=80=99s = a good StackExchange > thread from 2015 here: > https://emacs.stackexchange.com/questions/7982/ The author notes that > there should be a user option to set the amount of =E2=80=9Cdistance=E2= =80=9D (between > foreground and background colors) that is required for > distant-foreground to kick in, and adds that a good way to measure > color distance in real-world circumstances is described here: > http://web.mst.edu/~rhall/web_design/color_readability.html A commenter > suggested that he file a bug, but I can=E2=80=99t find an Emacs bug report > related to this issue, so I=E2=80=99m filing this now. > > I really hope this gets addressed, because :distant-foreground is a > really nice and clever feature. Thanks! > > In GNU Emacs 26.1.90 (build 2, x86_64-pc-linux-gnu, GTK+ Version 3.22.30) > of 2019-01-02 built on pannychis > Repository revision: 08840f2f7bfc6144bd163dd85efe87d28541e425 > Windowing system distributor 'The X.Org Foundation', version 11.0.11906000 > System Description: Ubuntu 18.04.1 LTS > > Configured using: > 'configure --with-xaw3d --with-modules --with-xwidgets' I've created a patch that introduces a new variable `face-near-same-color-threshold', with a default value of 30000 (as was defined in NEAR_SAME_COLOR_THRESHOLD in xfaces.c). Changing this variable's value will make certain color combinations be considered as 'same', which will lead to :distant-foreground being used. For example: M-: (setq face-near-same-color-threshold 200000) M-: (clear-font-cache) Then, using your third example, the text will be displayed with a black foregound. Is this a reasonable fix, or should we consider implementing another way of measuring distance between colors like Tina mentioned? --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=foreground.patch Content-Description: patch diff --git a/src/xfaces.c b/src/xfaces.c index cffa89e1f3..eeea165187 100644 --- a/src/xfaces.c +++ b/src/xfaces.c @@ -1157,8 +1157,6 @@ load_color (struct frame *f, struct face *face, Lisp_Object name, #ifdef HAVE_WINDOW_SYSTEM -#define NEAR_SAME_COLOR_THRESHOLD 30000 - /* Load colors for face FACE which is used on frame F. Colors are specified by slots LFACE_BACKGROUND_INDEX and LFACE_FOREGROUND_INDEX of ATTRS. If the background color specified is not supported on F, @@ -1198,8 +1196,9 @@ load_face_colors (struct frame *f, struct face *face, face->foreground = load_color2 (f, face, fg, LFACE_FOREGROUND_INDEX, &xfg); dfg = attrs[LFACE_DISTANT_FOREGROUND_INDEX]; + int distance = color_distance (&xbg, &xfg); if (!NILP (dfg) && !UNSPECIFIEDP (dfg) - && color_distance (&xbg, &xfg) < NEAR_SAME_COLOR_THRESHOLD) + && distance < face_near_same_color_threshold) { if (EQ (attrs[LFACE_INVERSE_INDEX], Qt)) face->background = load_color (f, face, dfg, LFACE_BACKGROUND_INDEX); @@ -6768,6 +6767,12 @@ RESCALE-RATIO is a floating point number to specify how much larger a font of 10 point, we actually use a font of 10 * RESCALE-RATIO point. */); Vface_font_rescale_alist = Qnil; + DEFVAR_INT ("face-near-same-color-threshold", face_near_same_color_threshold, + doc: /* Number representing the minimum tolerated distance +between face background and foreground colors before distant-foreground is +used instead (when present). */); + face_near_same_color_threshold = 30000; + #ifdef HAVE_WINDOW_SYSTEM defsubr (&Sbitmap_spec_p); defsubr (&Sx_list_fonts); --=-=-=--