all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#52888: 29.0.50; font_{delete_unmatched,score} do not handle nil FONT_WEIGHT_INDEX
@ 2021-12-30  5:28 Sean Whitton
  2021-12-30  7:33 ` Eli Zaretskii
  2022-01-13 11:54 ` bug#52888: André Silva
  0 siblings, 2 replies; 38+ messages in thread
From: Sean Whitton @ 2021-12-30  5:28 UTC (permalink / raw)
  To: 52888

[-- Attachment #1: Type: text/plain, Size: 870 bytes --]

Hello,

On my system I have a variable weight .ttf font[1] installed somewhere.
When I build with --enable-check-lisp-object-type, the line

    int candidate = XFIXNUM (AREF (entity, prop)) >> 8;

in font_delete_unmatched and the expression

   EMACS_INT diff = ((XFIXNUM (AREF (entity, i)) >> 8)
                     - (XFIXNUM (spec_prop[i]) >> 8));

in font_score have failed assertions because the FONT_WEIGHT_INDEX for
this .ttf file is nil:

    #<font-entity ftcrhb CYRE Inconsolata nil iso10646-1 nil normal nil
     0 nil 100 0 ((:font-entity
     "/usr/share/fonts/inconsolata/Inconsolata-VariableFont_wdth,wght.ttf"
     . 0))>

I don't believe Emacs really knows how to handle these multi-weight .ttf
files?  Thus I propose the attached patch, to handle the value.

[1]  https://github.com/googlefonts/Inconsolata/tree/main/fonts/variable

-- 
Sean Whitton

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Handle-nil-FONT_WEIGHT_INDEX.patch --]
[-- Type: text/x-patch, Size: 3017 bytes --]

From b7eff2c3e1d09f44b1d5790275fc92c11e9be88f Mon Sep 17 00:00:00 2001
From: Sean Whitton <spwhitton@spwhitton.name>
Date: Wed, 29 Dec 2021 21:18:07 -0700
Subject: [PATCH] Handle nil FONT_WEIGHT_INDEX

* src/font.c (font_delete_unmatched, font_score): Handle nil entity
property.  In particular, FONT_WEIGHT_INDEX is nil for some variable
weight fonts.
---
 src/font.c | 42 ++++++++++++++++++++++++------------------
 1 file changed, 24 insertions(+), 18 deletions(-)

diff --git a/src/font.c b/src/font.c
index fa831f2861..cb057abca6 100644
--- a/src/font.c
+++ b/src/font.c
@@ -2183,7 +2183,8 @@ font_score (Lisp_Object entity, Lisp_Object *spec_prop)
 
   /* Score three style numeric fields.  Maximum difference is 127. */
   for (i = FONT_WEIGHT_INDEX; i <= FONT_WIDTH_INDEX; i++)
-    if (! NILP (spec_prop[i]) && ! EQ (AREF (entity, i), spec_prop[i]))
+    if (! NILP (spec_prop[i]) && ! NILP (AREF (entity, i))
+	&& ! EQ (AREF (entity, i), spec_prop[i]))
       {
 	EMACS_INT diff = ((XFIXNUM (AREF (entity, i)) >> 8)
 			  - (XFIXNUM (spec_prop[i]) >> 8));
@@ -2764,26 +2765,31 @@ font_delete_unmatched (Lisp_Object vec, Lisp_Object spec, int size)
 	{
 	  if (FIXNUMP (AREF (spec, prop)))
 	    {
-	      int required = XFIXNUM (AREF (spec, prop)) >> 8;
-	      int candidate = XFIXNUM (AREF (entity, prop)) >> 8;
+	      if (NILP (AREF (entity, prop)))
+		  prop = FONT_SPEC_MAX;
+	      else {
+		int required = XFIXNUM (AREF (spec, prop)) >> 8;
+		int candidate = XFIXNUM (AREF (entity, prop)) >> 8;
 
-	      if (candidate != required
+		if (candidate != required
 #ifdef HAVE_NTGUI
-		  /* A kludge for w32 font search, where listing a
-		     family returns only 4 standard weights: regular,
-		     italic, bold, bold-italic.  For other values one
-		     must specify the font, not just the family in the
-		     :family attribute of the face.  But specifying
-		     :family in the face attributes looks for regular
-		     weight, so if we require exact match, the
-		     non-regular font will be rejected.  So we relax
-		     the accuracy of the match here, and let
-		     font_sort_entities find the best match.  */
-		  && (prop != FONT_WEIGHT_INDEX
-		      || eabs (candidate - required) > 100)
+		    /* A kludge for w32 font search, where listing a
+		       family returns only 4 standard weights:
+		       regular, italic, bold, bold-italic.  For other
+		       values one must specify the font, not just the
+		       family in the :family attribute of the face.
+		       But specifying :family in the face attributes
+		       looks for regular weight, so if we require
+		       exact match, the non-regular font will be
+		       rejected.  So we relax the accuracy of the
+		       match here, and let font_sort_entities find the
+		       best match.  */
+		    && (prop != FONT_WEIGHT_INDEX
+			|| eabs (candidate - required) > 100)
 #endif
-		  )
-		prop = FONT_SPEC_MAX;
+		    )
+		  prop = FONT_SPEC_MAX;
+	      }
 	    }
 	}
       if (prop < FONT_SPEC_MAX
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 38+ messages in thread

end of thread, other threads:[~2022-02-03  7:28 UTC | newest]

Thread overview: 38+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-12-30  5:28 bug#52888: 29.0.50; font_{delete_unmatched,score} do not handle nil FONT_WEIGHT_INDEX Sean Whitton
2021-12-30  7:33 ` Eli Zaretskii
2021-12-30 17:13   ` Sean Whitton
2021-12-30 18:39     ` Eli Zaretskii
2022-01-01  0:30       ` Sean Whitton
2022-01-01  2:35         ` Sean Whitton
2022-01-01  7:15           ` Eli Zaretskii
2022-01-01 22:31             ` Sean Whitton
2022-01-03  2:04               ` Sean Whitton
2022-01-05  2:10             ` Sean Whitton
2022-01-05 12:37               ` Eli Zaretskii
2022-01-05 13:55                 ` Robert Pluim
2022-01-05 14:08                   ` Eli Zaretskii
2022-01-06  5:41                 ` Sean Whitton
2022-01-06 12:29                   ` Eli Zaretskii
2022-01-06 18:10                     ` Sean Whitton
2022-01-12 14:56                       ` Eli Zaretskii
2022-01-12 21:41                         ` Sean Whitton
2022-01-13  6:52                           ` Eli Zaretskii
2022-01-01  6:56         ` Eli Zaretskii
2022-01-01 21:49           ` Can't set conditional break point using AREF/NILP Sean Whitton
2022-01-02  6:42             ` Eli Zaretskii
2022-01-02 22:38               ` Sean Whitton
2022-01-03 12:28                 ` Eli Zaretskii
2022-01-04 21:57                   ` Sean Whitton
2022-01-05 12:11                     ` Eli Zaretskii
2022-01-06 18:20                       ` bug#53058: etc/DEBUG could say more about --enable-check-lisp-object-type Sean Whitton
2022-01-06 20:11                         ` Eli Zaretskii
2022-01-06 23:46                           ` Sean Whitton
2022-01-07  6:58                             ` Eli Zaretskii
2022-01-07 20:41                               ` Sean Whitton
2022-01-08  6:55                                 ` Eli Zaretskii
2022-02-03  0:19                                   ` Sean Whitton
2022-02-03  7:28                                     ` Eli Zaretskii
2022-01-13 11:54 ` bug#52888: André Silva
2022-01-13 16:40   ` bug#52888: Eli Zaretskii
     [not found]     ` <CANfyKeBjec0z2c33Fph1=ESr-4ACH0BNKXq_wW-Vtr6sEfJ_VA@mail.gmail.com>
2022-01-13 18:13       ` bug#52888: Eli Zaretskii
     [not found]         ` <CANfyKeD2-sP4tO0dH0rbjbyD+rR+ahiDgBn+Pnx89EG1iKqiYg@mail.gmail.com>
2022-01-13 19:49           ` bug#52888: Eli Zaretskii

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.