diff options
| author | Po Lu | 2023-08-21 20:44:23 +0800 |
|---|---|---|
| committer | Po Lu | 2023-08-21 20:45:34 +0800 |
| commit | fb5e1b21fbf3475abffc3c0de31437120904f42a (patch) | |
| tree | 93bee99450c1efdff6525c9140b317dd31cf5ea7 /src | |
| parent | c21103bb76e6997064917b23b8fdfbf0a1149375 (diff) | |
| download | emacs-fb5e1b21fbf3475abffc3c0de31437120904f42a.tar.gz emacs-fb5e1b21fbf3475abffc3c0de31437120904f42a.zip | |
Properly enumerate GX fonts of the same family with divergent styles
* doc/emacs/android.texi (Android Fonts): Revise explanation of
GX font replacement during font enumeration.
* src/sfntfont.c (sfnt_replace_fonts_p): If PREV and DESC are of
the same family and both are GX fonts, restrict actions taken to
removing duplicate styles from PREV. Reported by a user who
tried to install GX versions of Cascadia Mono, which are
distributed as two files providing the bold and italic variation
axes respectively.
Diffstat (limited to 'src')
| -rw-r--r-- | src/sfntfont.c | 56 |
1 files changed, 53 insertions, 3 deletions
diff --git a/src/sfntfont.c b/src/sfntfont.c index c48339b6b66..e2dfdaff3b6 100644 --- a/src/sfntfont.c +++ b/src/sfntfont.c | |||
| @@ -834,6 +834,9 @@ sfnt_grok_registry (int fd, struct sfnt_font_desc *desc, | |||
| 834 | newer font description DESC, and should be removed from the list of | 834 | newer font description DESC, and should be removed from the list of |
| 835 | system fonts. | 835 | system fonts. |
| 836 | 836 | ||
| 837 | If both PREV and DESC are variable fonts, remove styles within PREV | ||
| 838 | that overlap with DESC and return false. | ||
| 839 | |||
| 837 | If PREV is a variable font, potentially adjust its list of | 840 | If PREV is a variable font, potentially adjust its list of |
| 838 | instances. */ | 841 | instances. */ |
| 839 | 842 | ||
| @@ -841,8 +844,8 @@ static bool | |||
| 841 | sfnt_replace_fonts_p (struct sfnt_font_desc *prev, | 844 | sfnt_replace_fonts_p (struct sfnt_font_desc *prev, |
| 842 | struct sfnt_font_desc *desc) | 845 | struct sfnt_font_desc *desc) |
| 843 | { | 846 | { |
| 844 | int i, width, weight, slant, count_instance; | 847 | int i, j, width, weight, slant, count_instance; |
| 845 | Lisp_Object tem; | 848 | Lisp_Object tem, tem1; |
| 846 | bool family_equal_p; | 849 | bool family_equal_p; |
| 847 | 850 | ||
| 848 | family_equal_p = !NILP (Fstring_equal (prev->family, | 851 | family_equal_p = !NILP (Fstring_equal (prev->family, |
| @@ -851,7 +854,54 @@ sfnt_replace_fonts_p (struct sfnt_font_desc *prev, | |||
| 851 | if ((!NILP (desc->instances) | 854 | if ((!NILP (desc->instances) |
| 852 | || !NILP (Fstring_equal (prev->style, desc->style))) | 855 | || !NILP (Fstring_equal (prev->style, desc->style))) |
| 853 | && family_equal_p) | 856 | && family_equal_p) |
| 854 | return true; | 857 | { |
| 858 | /* If both inputs are GX fonts... */ | ||
| 859 | if (!NILP (desc->instances) && !NILP (prev->instances)) | ||
| 860 | { | ||
| 861 | /* ...iterate over each of the styles provided by PREV. If | ||
| 862 | they match any styles within DESC, remove the old style | ||
| 863 | from PREV. */ | ||
| 864 | |||
| 865 | count_instance = 0; | ||
| 866 | for (i = 0; i < ASIZE (prev->instances); ++i) | ||
| 867 | { | ||
| 868 | tem = AREF (prev->instances, i); | ||
| 869 | |||
| 870 | if (NILP (tem)) | ||
| 871 | continue; | ||
| 872 | |||
| 873 | for (j = 0; j < ASIZE (desc->instances); ++j) | ||
| 874 | { | ||
| 875 | tem1 = AREF (desc->instances, j); | ||
| 876 | |||
| 877 | if (NILP (tem1)) | ||
| 878 | continue; | ||
| 879 | |||
| 880 | if (!NILP (Fequal (tem1, tem))) | ||
| 881 | { | ||
| 882 | /* tem1 is identical to tem, so opt for it over | ||
| 883 | tem. */ | ||
| 884 | ASET (prev->instances, i, Qnil); | ||
| 885 | goto next; | ||
| 886 | } | ||
| 887 | } | ||
| 888 | |||
| 889 | /* Increment the number of instances remaining within | ||
| 890 | PREV. */ | ||
| 891 | count_instance++; | ||
| 892 | |||
| 893 | next: | ||
| 894 | ; | ||
| 895 | } | ||
| 896 | |||
| 897 | /* Return true if no instances remain inside | ||
| 898 | PREV->instances, so that the now purposeless desc may be | ||
| 899 | removed. */ | ||
| 900 | return !count_instance; | ||
| 901 | } | ||
| 902 | |||
| 903 | return true; | ||
| 904 | } | ||
| 855 | 905 | ||
| 856 | if (NILP (prev->instances) || !family_equal_p) | 906 | if (NILP (prev->instances) || !family_equal_p) |
| 857 | return false; | 907 | return false; |