fix linking with allegro primitives, fix header name when installed, update readme

This commit is contained in:
2026-09-22 19:08:40 -05:00
parent 07395f7777
commit a9c82c406d
5 changed files with 23 additions and 8 deletions

View File

@@ -3,7 +3,7 @@ include_directories(../font)
set(TTF_SOURCES allegro_schrift.c schrift.c) 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}) #set_our_header_properties(${TTF_INCLUDE_FILES})
@@ -16,7 +16,7 @@ add_our_addon_library(allegro_ttf
AllegroTTF-${ALLEGRO_SOVERSION} AllegroTTF-${ALLEGRO_SOVERSION}
"${TTF_SOURCES};${TTF_INCLUDE_FILES}" "${TTF_SOURCES};${TTF_INCLUDE_FILES}"
"-DALLEGRO_TTF_SRC" "-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") #target_compile_options(allegro_ttf PRIVATE "-fsanitize=undefined" "-lasan")

View File

@@ -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`. 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) ![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 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 - 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. - 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). 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. - 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. - 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.
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 `cache_text` setting in allegro5.cfg is now reused to determine what glyphs can be rendered at all. `skip_cache_misses` has no effect. - 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) 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. - **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. - 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)

View File

@@ -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 #ifndef __al_included_allegro5_allegro_ttf_h
#define __al_included_allegro5_allegro_ttf_h #define __al_included_allegro5_allegro_ttf_h

View File

@@ -4,7 +4,7 @@
#include "allegro5/internal/aintern.h" #include "allegro5/internal/aintern.h"
#include "allegro5/internal/aintern_vector.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_font.h"
#include "allegro5/internal/aintern_dtor.h" #include "allegro5/internal/aintern_dtor.h"
#include "allegro5/internal/aintern_system.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, ALLEGRO_FONT *al_load_ttf_font_f(ALLEGRO_FILE *file,
char const *filename, int size, int flags) 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 CLEANUP free(filebuf); if (gtex) al_destroy_bitmap(gtex); al_set_target_bitmap(tgt)
#define FAIL CLEANUP; return NULL #define FAIL CLEANUP; return NULL

BIN
schrift_demo_wip.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 256 KiB