changeset 423:63ebfa352ae1

core: use err.h in font
author David Demelier <markand@malikania.fr>
date Sat, 15 Oct 2022 14:00:38 +0200
parents b0579ae033ed
children 2f4a8e166128
files src/libmlk-core/core/font.c src/libmlk-core/core/font.h src/libmlk-core/core/texture.c
diffstat 3 files changed, 6 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/src/libmlk-core/core/font.c	Sat Oct 15 13:48:40 2022 +0200
+++ b/src/libmlk-core/core/font.c	Sat Oct 15 14:00:38 2022 +0200
@@ -22,12 +22,11 @@
 #include <SDL_ttf.h>
 
 #include "color.h"
+#include "err.h"
 #include "error.h"
 #include "font.h"
 #include "texture_p.h"
 #include "util.h"
-#include "vfs.h"
-#include "vfs_p.h"
 
 int
 font_open(struct font *font, const char *path, unsigned int size)
@@ -36,7 +35,7 @@
 	assert(path);
 
 	if (!(font->handle = TTF_OpenFont(path, size)))
-		return errorf("%s", SDL_GetError());
+		return ERR_INTERNAL;
 
 	return 0;
 }
@@ -51,23 +50,7 @@
 
 	if (!(ops = SDL_RWFromConstMem(buffer, buflen)) ||
 	   (!(font->handle = TTF_OpenFontRW(ops, 1, size))))
-		return errorf("%s", SDL_GetError());
-
-	return 0;
-}
-
-int
-font_openvfs(struct font *font, struct vfs_file *file, unsigned int size)
-{
-	assert(font);
-	assert(vfs_file_ok(file));
-
-	SDL_RWops *ops;
-
-	if (!(ops = vfs_to_rw(file)))
-		return -1;
-	if (!(font->handle = TTF_OpenFontRW(ops, 1, size)))
-		return errorf("%s", SDL_GetError());
+		return ERR_INTERNAL;
 
 	return 0;
 }
@@ -103,7 +86,7 @@
 	}
 
 	if (!(surface = func(font->handle, text, fg)))
-		return errorf("%s", SDL_GetError());
+		return ERR_INTERNAL;
 
 	return texture_from_surface(tex, surface);
 }
@@ -128,7 +111,7 @@
 		*h = 0;
 
 	if (TTF_SizeUTF8(font->handle, text, (int *)w, (int *)h) != 0)
-		return errorf("%s", SDL_GetError());
+		return ERR_INTERNAL;
 
 	return 0;
 }
--- a/src/libmlk-core/core/font.h	Sat Oct 15 13:48:40 2022 +0200
+++ b/src/libmlk-core/core/font.h	Sat Oct 15 14:00:38 2022 +0200
@@ -24,7 +24,6 @@
 #include "core.h"
 
 struct texture;
-struct vfs_file;
 
 enum font_style {
 	FONT_STYLE_ANTIALIASED,
@@ -46,9 +45,6 @@
 font_openmem(struct font *, const void *, size_t, unsigned int);
 
 int
-font_openvfs(struct font *, struct vfs_file *, unsigned int);
-
-int
 font_ok(const struct font *);
 
 int
--- a/src/libmlk-core/core/texture.c	Sat Oct 15 13:48:40 2022 +0200
+++ b/src/libmlk-core/core/texture.c	Sat Oct 15 14:00:38 2022 +0200
@@ -166,7 +166,7 @@
 
 	if (!(tex->handle = SDL_CreateTextureFromSurface(RENDERER(), surface))) {
 		tex->w = tex->h = 0;
-		return errorf("%s", SDL_GetError());
+		return ERR_INTERNAL;
 	}
 
 	tex->w = surface->w;