Skip to content

Commit

Permalink
Do not calculate size for missing characters.
Browse files Browse the repository at this point in the history
Since we are rendering in only the chosen font, if the character in
question does not exist simply report its size as zero.

```
Fixes fvwmorg#622, fixes fvwmorg#680.
```
  • Loading branch information
topcat001 committed Aug 2, 2022
1 parent 5810409 commit ae1a194
Showing 1 changed file with 7 additions and 47 deletions.
54 changes: 7 additions & 47 deletions libs/Fft.c
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,6 @@ static void MatchFont(Display *dpy,
void (*render_char)(void *, XftCharFontSpec *),
void *user_data)
{
FcPattern *template = NULL;
int codelen = 0, off = 0;

for (off = 0; off < len; off += codelen) {
Expand All @@ -303,56 +302,17 @@ static void MatchFont(Display *dpy,
continue;
}

if (!XftCharExists(dpy, font, sp.ucs4)) {
/* Fallback */
if (!template) {
int slant = 0, weight = 0;
double font_size = 0.0;
FcPatternGetDouble(font->pattern, FC_SIZE, 0, &font_size);
FcPatternGetInteger(font->pattern, FC_WEIGHT, 0, &weight);
FcPatternGetInteger(font->pattern, FC_SLANT, 0, &slant);
template = FcPatternBuild(
NULL,
FC_SIZE, FcTypeDouble, font_size,
FC_WEIGHT, FcTypeInteger, weight,
FC_SLANT, FcTypeInteger, slant,
NULL);
} else {
FcPatternDel(template, FC_CHARSET);
}

FcCharSet *fallback_charset = FcCharSetCreate();
FcCharSetAddChar(fallback_charset, sp.ucs4);
FcPatternAddCharSet(template, FC_CHARSET, fallback_charset);
if (XftCharExists(dpy, font, sp.ucs4)) {
XGlyphInfo info;
XftTextExtents32(dpy, sp.font, &sp.ucs4, 1, &info);
*xoff += info.xOff;
*yoff += info.yOff;

/* Lookup from the cache first! */
FcResult result = FcResultMatch;
FcPattern *font_pattern = MatchCacheFont(sp.ucs4, template, &result);
if (!font_pattern) {
font_pattern = XftFontMatch(dpy, XDefaultScreen(dpy), template, &result);
if (font_pattern) AddCacheFont(sp.ucs4, template, font_pattern);
if (render_char) {
render_char(user_data, &sp);
}
FcCharSetDestroy(fallback_charset);

if (result == FcResultMatch) {
XftFont *fallback_font = XftFontOpenPattern(dpy, font_pattern);
if (fallback_font) sp.font = fallback_font;
else FcPatternDestroy(font_pattern);
}
}
XGlyphInfo info;
XftTextExtents32(dpy, sp.font, &sp.ucs4, 1, &info);
*xoff += info.xOff;
*yoff += info.yOff;

if (render_char) {
render_char(user_data, &sp);
} else if (sp.font != font) {
XftFontClose(dpy, sp.font);
}
}
if (template)
FcPatternDestroy(template);
}

#define NR_CHARFONTSPEC 31
Expand Down

0 comments on commit ae1a194

Please sign in to comment.