Skip to content

Commit cf4756e

Browse files
Krister Wicksellgithub-actions[bot]
Krister Wicksell
authored andcommitted
When a font is missing a glyph we try to fallback to using a question mark
As it is now MapServer will fail to render if a layer is using characters that's not available in the font. This commit resolves this by trying to fallback to using a question mark in these situations.
1 parent 3305bb0 commit cf4756e

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

fontcache.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,12 @@ glyph_element* msGetGlyphByIndex(face_element *face, unsigned int size, unsigned
287287
FT_Set_Pixel_Sizes(face->face,0,MS_NINT(size * 96/72.0));
288288
}
289289
error = FT_Load_Glyph(face->face,key.codepoint,FT_LOAD_DEFAULT|FT_LOAD_NO_BITMAP|FT_LOAD_NO_HINTING|FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH);
290+
if (error) {
291+
msDebug("Unable to load glyph %ud for font \"%s\". Using ? as fallback.", key.codepoint, face->font);
292+
// If we can't find a glyph then try to fallback to a question mark.
293+
unsigned int fallbackCodepoint = msGetGlyphIndex(face, 0x3F);
294+
error = FT_Load_Glyph(face->face,fallbackCodepoint,FT_LOAD_DEFAULT|FT_LOAD_NO_BITMAP|FT_LOAD_NO_HINTING|FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH);
295+
}
290296
if(error) {
291297
msSetError(MS_MISCERR, "unable to load glyph %ud for font \"%s\"", "msGetGlyphByIndex()",key.codepoint, face->font);
292298
free(gc);
@@ -335,8 +341,14 @@ outline_element* msGetGlyphOutline(face_element *face, glyph_element *glyph) {
335341
pen.x = pen.y = 0;
336342
FT_Set_Transform(face->face, &matrix, &pen);
337343
error = FT_Load_Glyph(face->face,glyph->key.codepoint,FT_LOAD_DEFAULT|FT_LOAD_NO_BITMAP/*|FT_LOAD_IGNORE_TRANSFORM*/|FT_LOAD_NO_HINTING|FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH);
344+
if (error) {
345+
msDebug("Unable to load glyph %ud for font \"%s\". Using ? as fallback.", glyph->key.codepoint, face->font);
346+
// If we can't find a glyph then try to fallback to a question mark.
347+
unsigned int fallbackCodepoint = msGetGlyphIndex(face, 0x3F);
348+
error = FT_Load_Glyph(face->face,fallbackCodepoint,FT_LOAD_DEFAULT|FT_LOAD_NO_BITMAP/*|FT_LOAD_IGNORE_TRANSFORM*/|FT_LOAD_NO_HINTING|FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH);
349+
}
338350
if(error) {
339-
msSetError(MS_MISCERR, "unable to load glyph %ud for font \"%s\"", "msGetGlyphByIndex()",glyph->key.codepoint, face->font);
351+
msSetError(MS_MISCERR, "unable to load glyph %ud for font \"%s\"", "msGetGlyphOutline()",glyph->key.codepoint, face->font);
340352
#ifdef USE_THREAD
341353
if (use_global_ft_cache)
342354
msReleaseLock(TLOCK_TTF);

0 commit comments

Comments
 (0)