aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-11-08 16:03:02 +0100
committerdec05eba <dec05eba@protonmail.com>2021-11-08 16:03:02 +0100
commitc4f84e1969f4c856a5bf0352e99fcb73a4cf56cf (patch)
tree989fbe845a051d10f750bb6baeb0b58823a611bd /include
parente3c90b41386986ef53e512994d6e2f7ceadfc177 (diff)
Do not check for valid utf8 in set text, render the invalid utf8 instead. Mmap fonts instead of loading the whole font
Diffstat (limited to 'include')
-rw-r--r--include/mgl/graphics/text.h4
-rw-r--r--include/mgl/system/fileutils.h15
-rw-r--r--include/mgl/system/utf8.h3
3 files changed, 20 insertions, 2 deletions
diff --git a/include/mgl/graphics/text.h b/include/mgl/graphics/text.h
index 2311d23..a645b0b 100644
--- a/include/mgl/graphics/text.h
+++ b/include/mgl/graphics/text.h
@@ -28,14 +28,14 @@ typedef struct {
Note: keeps a reference to |text|. |text| needs to be valid as long as |self| is used.
|font| and |text| may be NULL.
*/
-int mgl_text_init(mgl_text *self, mgl_font *font, const char *str, size_t str_size);
+void mgl_text_init(mgl_text *self, mgl_font *font, const char *str, size_t str_size);
void mgl_text_deinit(mgl_text *self);
/*
Note: keeps a reference to |text|. |text| needs to be valid as long as |self| is used.
|text| may be NULL.
*/
-int mgl_text_set_string(mgl_text *self, const char *str, size_t str_size);
+void mgl_text_set_string(mgl_text *self, const char *str, size_t str_size);
/* |font| may be NULL */
void mgl_text_set_font(mgl_text *self, mgl_font *font);
void mgl_text_set_position(mgl_text *self, mgl_vec2f position);
diff --git a/include/mgl/system/fileutils.h b/include/mgl/system/fileutils.h
index 7696679..5e45cb3 100644
--- a/include/mgl/system/fileutils.h
+++ b/include/mgl/system/fileutils.h
@@ -13,8 +13,23 @@ typedef struct {
bool null_terminated; /* false by default */
} mgl_file_load_options;
+typedef struct {
+ void *data;
+ size_t size;
+ int fd;
+} mgl_memory_mapped_file;
+
+typedef struct {
+ bool readable; /* true by default */
+ bool writable; /* true by default */
+} mgl_memory_mapped_file_load_options;
+
/* |load_options| can be null, in which case the default options are used */
int mgl_load_file(const char *filepath, mgl_filedata *filedata, mgl_file_load_options *load_options);
void mgl_filedata_free(mgl_filedata *self);
+/* |load_options| can be null, in which case the default options are used */
+int mgl_mapped_file_load(const char *filepath, mgl_memory_mapped_file *memory_mapped_file, mgl_memory_mapped_file_load_options *load_options);
+void mgl_mapped_file_unload(mgl_memory_mapped_file *memory_mapped_file);
+
#endif /* MGL_FILEUTILS_H */
diff --git a/include/mgl/system/utf8.h b/include/mgl/system/utf8.h
index f745be7..7120f1a 100644
--- a/include/mgl/system/utf8.h
+++ b/include/mgl/system/utf8.h
@@ -5,6 +5,9 @@
#include <stdint.h>
#include <stdbool.h>
+/*
+ Returns false on failure. |decoded_codepoint| is set to |str[0]| if size > 0 and |codepoint_length| is set to 1
+*/
bool mgl_utf8_decode(const unsigned char *str, size_t size, uint32_t *decoded_codepoint, size_t *codepoint_length);
#endif /* MGL_UTF8_H */