]> git.ipfire.org Git - thirdparty/plymouth.git/commitdiff
label-freetype: Handle font failing to load more gracefully
authorRay Strode <rstrode@redhat.com>
Tue, 26 Dec 2023 18:20:39 +0000 (13:20 -0500)
committerRay Strode <halfline@gmail.com>
Wed, 27 Dec 2023 19:54:29 +0000 (19:54 +0000)
We currently crash if the font fails to load.

This commit attempts to handle the situation more gracefully.

src/plugins/controls/label-freetype/plugin.c

index d20f14f17b3fe79c854fcfa459cd233da3f362c0..424127ec96e50e37387ea5ee5e40e32be5e732b0 100644 (file)
@@ -248,6 +248,9 @@ load_glyph (ply_label_plugin_control_t *label,
         wchar_t character;
         FT_Int32 load_flags = FT_LOAD_TARGET_LIGHT;
 
+        if (label->face == NULL)
+                return NULL;
+
         character_size = mbrtowc (&character, input_text, PLY_UTF8_CHARACTER_SIZE_MAX, NULL);
 
         if (character_size <= 0) {
@@ -428,6 +431,9 @@ finish_measuring_line (ply_label_plugin_control_t *label,
         ply_freetype_unit_t line_height;
         ply_rectangle_t *entry;
 
+        if (label->face == NULL)
+                return;
+
         line_height.as_integer = label->face->size->metrics.ascender + -label->face->size->metrics.descender;
 
         dimensions->x = label->area.x;
@@ -536,9 +542,6 @@ load_glyphs (ply_label_plugin_control_t *label,
                         return;
         }
 
-        /* Make sure that the first row fits */
-        glyph_y.as_integer += label->face->size->metrics.ascender;
-
         /* Go through each line */
         do {
                 bool should_stop;
@@ -584,6 +587,11 @@ load_glyphs (ply_label_plugin_control_t *label,
                 if (glyph == NULL)
                         continue;
 
+                if (is_first_character) {
+                        /* Move pen to the first character's base line */
+                        glyph_y.as_integer += label->face->size->metrics.ascender;
+                }
+
                 if (*current_character == '\n') {
                         if (action == PLY_LOAD_GLYPH_ACTION_MEASURE)
                                 finish_measuring_line (label, &glyph_x, &glyph_y, line_dimensions);
@@ -762,8 +770,11 @@ set_font_for_control (ply_label_plugin_control_t *label,
                         label->is_monospaced = false;
                 }
         }
-        if (error)
+        if (error) {
                 FT_Done_Face (label->face);
+                label->face = NULL;
+                return;
+        }
 
         /* Format is "Family 1[,Family 2[,..]] [25[px]]" .
          * [] means optional. */