Skip to content

Commit 233fc40

Browse files
committed
fix fz_load_html_font() to not load same font multiple times
1 parent 0a571c9 commit 233fc40

1 file changed

Lines changed: 20 additions & 16 deletions

File tree

mupdf/source/html/html-font.c

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,26 @@ fz_load_html_font(fz_context *ctx, fz_html_font_set *set,
7575
fz_font *best_font = NULL;
7676
int size;
7777

78-
/* SumatraPDF */
78+
for (custom = set->custom; custom; custom = custom->next)
79+
{
80+
if (!strcmp(family, custom->family))
81+
{
82+
int score =
83+
1 * (is_bold == custom->is_bold) +
84+
2 * (is_italic == custom->is_italic) +
85+
4 * (is_small_caps == custom->is_small_caps);
86+
if (score > best_score)
87+
{
88+
best_score = score;
89+
best_font = custom->font;
90+
}
91+
}
92+
}
93+
94+
/* SumatraPDF: return if perfect match, then try to load exact, if not available, return the best match */
95+
if (best_score == 7)
96+
return best_font;
97+
7998
fz_font* font = fz_load_system_font(ctx, family, is_bold, is_italic, 0);
8099
if (font) {
81100
fz_font_flags_t *flags = fz_font_flags(font);
@@ -105,21 +124,6 @@ fz_load_html_font(fz_context *ctx, fz_html_font_set *set,
105124
return fz_load_html_default_font(ctx, set, family, is_bold, is_italic);
106125

107126
/* SumatraPDF */
108-
for (custom = set->custom; custom; custom = custom->next)
109-
{
110-
if (!strcmp(family, custom->family))
111-
{
112-
int score =
113-
1 * (is_bold == custom->is_bold) +
114-
2 * (is_italic == custom->is_italic) +
115-
4 * (is_small_caps == custom->is_small_caps);
116-
if (score > best_score)
117-
{
118-
best_score = score;
119-
best_font = custom->font;
120-
}
121-
}
122-
}
123127
if (best_font)
124128
return best_font;
125129

0 commit comments

Comments
 (0)