diff --git a/CMakeLists.txt b/CMakeLists.txt index d26697f..bb1622f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ include_directories(../font) set(TTF_SOURCES allegro_schrift.c schrift.c) -set(TTF_INCLUDE_FILES allegro5/allegro_schrift.h) +set(TTF_INCLUDE_FILES allegro5/allegro_ttf.h) #set_our_header_properties(${TTF_INCLUDE_FILES}) @@ -16,7 +16,7 @@ add_our_addon_library(allegro_ttf AllegroTTF-${ALLEGRO_SOVERSION} "${TTF_SOURCES};${TTF_INCLUDE_FILES}" "-DALLEGRO_TTF_SRC" - "${FONT_LINK_WITH};${TTF_LIBRARIES}" + "${FONT_LINK_WITH};${PRIMITIVES_LINK_WITH};${TTF_LIBRARIES}" ) #target_compile_options(allegro_ttf PRIVATE "-fsanitize=undefined" "-lasan") diff --git a/README.md b/README.md index de86f03..91b9bcf 100644 --- a/README.md +++ b/README.md @@ -3,19 +3,27 @@ Drop-in replacement for Allegro_TTF that contains libschrift, instead of using F It is 100% API compatible with the vanilla TrueType addon. Compile Allegro with these files inside of `/addons/ttf`. +Requires the primitives addon. + ![Comparison between FreeType2 and schrift when running Allegro's ex_ttf demo](comparison.png) -Pros: +## Pros - It doesn't require NT 6 kernel calls - It doesn't dynamically link against hundreds of thousands of lines of ugly corporate-backed C code you can't read - Our addon is only a couple or few hundred lines, and libschrift is less than 2,000. They're compiled together. The original Allegro_TTF is over 1,000 lines (for a good reason) and has a relatively massive dependency weight (for a stupid reason). -Caveats: +## Caveats - Pre-stretching is not implemented. -- The entire caching system is gone, fonts are baked to textures immediately and no further. This makes supporting some languages with this add-on inconvenient, or impossible. -If your usecase doesn't need every fancy rendering feature and can use schrift, you probably aren't supporting enough characters and languages to need on-the-fly caching, so we consider this an acceptable tradeoff. +- The entire caching system is gone, fonts are baked to textures immediately and no further. This makes supporting some languages with this add-on inconvenient, and increases load times. For many users this an acceptable tradeoff. - The `cache_text` setting in allegro5.cfg is now reused to determine what glyphs can be rendered at all. `skip_cache_misses` has no effect. When `cache_text` is undefined, the [Latin](https://en.wikipedia.org/wiki/ASCII), [Germanic, and Romance](https://en.wikipedia.org/wiki/Latin_Extended-A) alphabets will be generated by default. (not necessarily 32 - 255) - **TODO** Alternatively, the developer can force a custom range of unicode characters to be generated using a new parameter in the `al_load_ttf_font` function. -- Kerning, per-character advance and offsets, and other features which are exposed by libschrift are not currently implemented, but doing so is possible. See the above comparison screenshot. \ No newline at end of file +- Kerning, per-character advance and offsets, and other features which are exposed by libschrift are not currently implemented, but doing so is possible. See the above comparison screenshot. + +## In Practice +You can see here some of the flaws with this implementation. Line heights are taller than they should be, and there's an issue with string endings or other characters. + +Not visible in the below example is the atlas size to hold glyph data. + +![Time Falcon main menu with the allegro_schrift plugin, work in progress](schrift_demo_wip.png) \ No newline at end of file diff --git a/allegro5/allegro_schrift.h b/allegro5/allegro_ttf.h similarity index 95% rename from allegro5/allegro_schrift.h rename to allegro5/allegro_ttf.h index ce8a710..52900b0 100644 --- a/allegro5/allegro_schrift.h +++ b/allegro5/allegro_ttf.h @@ -1,3 +1,5 @@ +// this header needs to be named allegro_ttf.h so it replaces the FreeType header + #ifndef __al_included_allegro5_allegro_ttf_h #define __al_included_allegro5_allegro_ttf_h diff --git a/allegro_schrift.c b/allegro_schrift.c index f3c2e00..8f146fa 100644 --- a/allegro_schrift.c +++ b/allegro_schrift.c @@ -4,7 +4,7 @@ #include "allegro5/internal/aintern.h" #include "allegro5/internal/aintern_vector.h" -#include "allegro5/allegro_schrift.h" +#include "allegro5/allegro_ttf.h" #include "allegro5/internal/aintern_font.h" #include "allegro5/internal/aintern_dtor.h" #include "allegro5/internal/aintern_system.h" @@ -48,6 +48,11 @@ ALLEGRO_BITMAP *grow_bitmap(ALLEGRO_BITMAP *bmp, uint16_t add) { ALLEGRO_FONT *al_load_ttf_font_f(ALLEGRO_FILE *file, char const *filename, int size, int flags) { + if (!al_is_primitives_addon_initialized() && !al_init_primitives_addon()) { + ALLEGRO_ERROR("Can't load font %s: primitives couldn't be set up\n", filename); + return NULL; + } + #define CLEANUP free(filebuf); if (gtex) al_destroy_bitmap(gtex); al_set_target_bitmap(tgt) #define FAIL CLEANUP; return NULL diff --git a/schrift_demo_wip.png b/schrift_demo_wip.png new file mode 100644 index 0000000..244d79b Binary files /dev/null and b/schrift_demo_wip.png differ