Skip to content

Commit aa52bcd

Browse files
authored
Merge pull request #984 from chearon/fix-977
macOS font selection improvement (see #977)
2 parents 28a063a + 7158478 commit aa52bcd

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/Canvas.cc

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,7 @@ Canvas::ResolveFontDescription(const PangoFontDescription *desc) {
742742
// if someone registered two different fonts under the same family name.
743743
// https://drafts.csswg.org/css-fonts-3/#font-style-matching
744744
char **families = g_strsplit(pango_font_description_get_family(desc), ",", -1);
745+
GHashTable *seen_families = g_hash_table_new(g_str_hash, g_str_equal);
745746
GString *resolved_families = g_string_new("");
746747

747748
for (int i = 0; families[i]; ++i) {
@@ -750,8 +751,14 @@ Canvas::ResolveFontDescription(const PangoFontDescription *desc) {
750751

751752
for (; it != _font_face_list.end(); ++it) {
752753
if (g_ascii_strcasecmp(families[i], pango_font_description_get_family(it->user_desc)) == 0) {
753-
if (renamed_families->len) g_string_append(renamed_families, ",");
754-
g_string_append(renamed_families, pango_font_description_get_family(it->sys_desc));
754+
char *name = g_strdup(pango_font_description_get_family(it->sys_desc));
755+
756+
// Avoid sending duplicate SFNT font names due to a bug in Pango for macOS:
757+
// https://bugzilla.gnome.org/show_bug.cgi?id=762873
758+
if (g_hash_table_add(seen_families, name)) {
759+
if (renamed_families->len) g_string_append(renamed_families, ",");
760+
g_string_append(renamed_families, name);
761+
}
755762

756763
if (i == 0 && (best.user_desc == NULL || pango_font_description_better_match(desc, best.user_desc, it->user_desc))) {
757764
best = *it;
@@ -769,6 +776,7 @@ Canvas::ResolveFontDescription(const PangoFontDescription *desc) {
769776

770777
g_strfreev(families);
771778
g_string_free(resolved_families, false);
779+
g_hash_table_destroy(seen_families);
772780

773781
return ret;
774782
}

0 commit comments

Comments
 (0)