diff options
| author | Eli Zaretskii | 2022-01-12 16:52:14 +0200 |
|---|---|---|
| committer | Eli Zaretskii | 2022-01-12 16:52:14 +0200 |
| commit | 7ebcb4b6f2f4531ebc893bb3b2f74d6298bf9b41 (patch) | |
| tree | b14de367a636c8ad50272828979e509fce35f872 /src | |
| parent | f373b52ba91ff9b1e04578e6c42efd2414ddf1fa (diff) | |
| download | emacs-7ebcb4b6f2f4531ebc893bb3b2f74d6298bf9b41.tar.gz emacs-7ebcb4b6f2f4531ebc893bb3b2f74d6298bf9b41.zip | |
Avoid assertion violations with variable-weight fonts
* src/font.c (font_score, font_delete_unmatched): Don't assume
weight, slant, and width properties of the font must be fixnums:
some variable-weight fonts violate that assumption. Reported
by Sean Whitton <spwhitton@spwhitton.name>. This is for builds
with Fontconfig < v2.11.91, for which the fix in
'ftfont_pattern_entity' cannot work. (Bug#52888)
Diffstat (limited to 'src')
| -rw-r--r-- | src/font.c | 43 |
1 files changed, 25 insertions, 18 deletions
diff --git a/src/font.c b/src/font.c index 266e5bc75c6..7e0219181c9 100644 --- a/src/font.c +++ b/src/font.c | |||
| @@ -2183,7 +2183,9 @@ font_score (Lisp_Object entity, Lisp_Object *spec_prop) | |||
| 2183 | 2183 | ||
| 2184 | /* Score three style numeric fields. Maximum difference is 127. */ | 2184 | /* Score three style numeric fields. Maximum difference is 127. */ |
| 2185 | for (i = FONT_WEIGHT_INDEX; i <= FONT_WIDTH_INDEX; i++) | 2185 | for (i = FONT_WEIGHT_INDEX; i <= FONT_WIDTH_INDEX; i++) |
| 2186 | if (! NILP (spec_prop[i]) && ! EQ (AREF (entity, i), spec_prop[i])) | 2186 | if (! NILP (spec_prop[i]) |
| 2187 | && ! EQ (AREF (entity, i), spec_prop[i]) | ||
| 2188 | && FIXNUMP (AREF (entity, i))) | ||
| 2187 | { | 2189 | { |
| 2188 | EMACS_INT diff = ((XFIXNUM (AREF (entity, i)) >> 8) | 2190 | EMACS_INT diff = ((XFIXNUM (AREF (entity, i)) >> 8) |
| 2189 | - (XFIXNUM (spec_prop[i]) >> 8)); | 2191 | - (XFIXNUM (spec_prop[i]) >> 8)); |
| @@ -2764,26 +2766,31 @@ font_delete_unmatched (Lisp_Object vec, Lisp_Object spec, int size) | |||
| 2764 | { | 2766 | { |
| 2765 | if (FIXNUMP (AREF (spec, prop))) | 2767 | if (FIXNUMP (AREF (spec, prop))) |
| 2766 | { | 2768 | { |
| 2767 | int required = XFIXNUM (AREF (spec, prop)) >> 8; | 2769 | if (!FIXNUMP (AREF (entity, prop))) |
| 2768 | int candidate = XFIXNUM (AREF (entity, prop)) >> 8; | 2770 | prop = FONT_SPEC_MAX; |
| 2771 | else | ||
| 2772 | { | ||
| 2773 | int required = XFIXNUM (AREF (spec, prop)) >> 8; | ||
| 2774 | int candidate = XFIXNUM (AREF (entity, prop)) >> 8; | ||
| 2769 | 2775 | ||
| 2770 | if (candidate != required | 2776 | if (candidate != required |
| 2771 | #ifdef HAVE_NTGUI | 2777 | #ifdef HAVE_NTGUI |
| 2772 | /* A kludge for w32 font search, where listing a | 2778 | /* A kludge for w32 font search, where listing a |
| 2773 | family returns only 4 standard weights: regular, | 2779 | family returns only 4 standard weights: regular, |
| 2774 | italic, bold, bold-italic. For other values one | 2780 | italic, bold, bold-italic. For other values one |
| 2775 | must specify the font, not just the family in the | 2781 | must specify the font, not just the family in the |
| 2776 | :family attribute of the face. But specifying | 2782 | :family attribute of the face. But specifying |
| 2777 | :family in the face attributes looks for regular | 2783 | :family in the face attributes looks for regular |
| 2778 | weight, so if we require exact match, the | 2784 | weight, so if we require exact match, the |
| 2779 | non-regular font will be rejected. So we relax | 2785 | non-regular font will be rejected. So we relax |
| 2780 | the accuracy of the match here, and let | 2786 | the accuracy of the match here, and let |
| 2781 | font_sort_entities find the best match. */ | 2787 | font_sort_entities find the best match. */ |
| 2782 | && (prop != FONT_WEIGHT_INDEX | 2788 | && (prop != FONT_WEIGHT_INDEX |
| 2783 | || eabs (candidate - required) > 100) | 2789 | || eabs (candidate - required) > 100) |
| 2784 | #endif | 2790 | #endif |
| 2785 | ) | 2791 | ) |
| 2786 | prop = FONT_SPEC_MAX; | 2792 | prop = FONT_SPEC_MAX; |
| 2793 | } | ||
| 2787 | } | 2794 | } |
| 2788 | } | 2795 | } |
| 2789 | if (prop < FONT_SPEC_MAX | 2796 | if (prop < FONT_SPEC_MAX |