Skip to content

Commit

Permalink
improve multi-family output in font desc resolver
Browse files Browse the repository at this point in the history
the problem was exposed by #1987, but was always there

fixes #2041
  • Loading branch information
chearon authored and zbjornson committed Jun 24, 2022
1 parent d4dc2a8 commit 6fa9f38
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -10,6 +10,7 @@ project adheres to [Semantic Versioning](http://semver.org/).
### Changed
### Added
### Fixed
* Wrong fonts used when calling `registerFont` multiple times with the same family name (#2041)

2.9.2
==================
Expand Down
13 changes: 8 additions & 5 deletions src/Canvas.cc
Expand Up @@ -879,18 +879,21 @@ Canvas::ResolveFontDescription(const PangoFontDescription *desc) {
if (streq_casein(family, pangofamily)) {
const char* sys_desc_family_name = pango_font_description_get_family(ff.sys_desc);
bool unseen = seen_families.find(sys_desc_family_name) == seen_families.end();
bool better = best.user_desc == nullptr || pango_font_description_better_match(desc, best.user_desc, ff.user_desc);

// Avoid sending duplicate SFNT font names due to a bug in Pango for macOS:
// https://bugzilla.gnome.org/show_bug.cgi?id=762873
if (unseen) {
seen_families.insert(sys_desc_family_name);
if (renamed_families.size()) renamed_families += ',';
renamed_families += sys_desc_family_name;
}

if (first && (best.user_desc == nullptr || pango_font_description_better_match(desc, best.user_desc, ff.user_desc))) {
best = ff;
if (better) {
renamed_families = string(sys_desc_family_name) + (renamed_families.size() ? "," : "") + renamed_families;
} else {
renamed_families = renamed_families + (renamed_families.size() ? "," : "") + sys_desc_family_name;
}
}

if (first && better) best = ff;
}
}

Expand Down

0 comments on commit 6fa9f38

Please sign in to comment.