Commit e2e8a4ae0cf494a28036bda6fe96be3442f1e2fd

Thomas de Grivel 2023-11-28T00:58:13

search font file

diff --git a/libc3/window/cairo/cairo_font.c b/libc3/window/cairo/cairo_font.c
index 53ebbba..994c548 100644
--- a/libc3/window/cairo/cairo_font.c
+++ b/libc3/window/cairo/cairo_font.c
@@ -25,6 +25,7 @@ void cairo_font_clean (s_cairo_font *font)
   cairo_font_face_destroy(font->cairo_font_face);
   FT_Done_Face(font->ft_face);
   str_clean(&font->path);
+  str_clean(&font->real_path);
 }
 
 static FT_Library * cairo_font_ft (void)
@@ -44,7 +45,7 @@ static FT_Library * cairo_font_ft (void)
   return g_cairo_font_ft;
 }
 
-s_cairo_font * cairo_font_init (s_cairo_font *font, s_str *path)
+s_cairo_font * cairo_font_init (s_cairo_font *font, const s_str *path)
 {
   FT_Library *ft;
   assert(font);
@@ -52,8 +53,16 @@ s_cairo_font * cairo_font_init (s_cairo_font *font, s_str *path)
   if (! (ft = cairo_font_ft()))
     return NULL;
   str_init_copy(&font->path, path);
-  if (FT_New_Face(*ft, path->ptr.ps8, 0, &font->ft_face)) {
-    warnx("cairo_font_init(%s): Error loading font", path->ptr.ps8);
+  if (! file_search(path, sym_1("r"), &font->real_path)) {
+    warnx("cairo_font_init(%s): file not found", path->ptr.ps8);
+    str_clean(&font->path);
+    return NULL;
+  }
+  if (FT_New_Face(*ft, font->real_path.ptr.ps8, 0, &font->ft_face)) {
+    warnx("cairo_font_init(%s): Error loading font",
+          font->real_path.ptr.ps8);
+    str_clean(&font->path);
+    str_clean(&font->real_path);
     return NULL;
   }
   font->cairo_font_face = cairo_ft_font_face_create_for_ft_face
diff --git a/libc3/window/cairo/types.h b/libc3/window/cairo/types.h
index 20d9b19..506ae02 100644
--- a/libc3/window/cairo/types.h
+++ b/libc3/window/cairo/types.h
@@ -64,6 +64,7 @@ struct cairo_font {
   cairo_font_face_t *cairo_font_face;
   FT_Face ft_face;
   s_str path;
+  s_str real_path;
 };
 
 struct cairo_sprite {