diff options
| author | Jeroen van Rijn <Kelimion@users.noreply.github.com> | 2025-10-11 01:10:54 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-10-11 01:10:54 +0200 |
| commit | 227be05c0f5b53ef08d92782d690d04f43432eb9 (patch) | |
| tree | dde10bad0007f05f50ac0db7a6a4b5314ab5408e /vendor | |
| parent | 236111864ec8147acf73ce4db1ef3310205cac7a (diff) | |
| parent | a4350b41ae8922d7d4f09c84511ab2043b6a7d7c (diff) | |
Merge pull request #5773 from karl-zylinski/fontstash-ttc-fix
Fix fontstash crash with .TTC files
Diffstat (limited to 'vendor')
| -rw-r--r-- | vendor/fontstash/fontstash.odin | 9 | ||||
| -rw-r--r-- | vendor/fontstash/fontstash_os.odin | 5 | ||||
| -rw-r--r-- | vendor/fontstash/fontstash_other.odin | 1 |
3 files changed, 13 insertions, 2 deletions
diff --git a/vendor/fontstash/fontstash.odin b/vendor/fontstash/fontstash.odin index 0ab97e8cb..772e379f0 100644 --- a/vendor/fontstash/fontstash.odin +++ b/vendor/fontstash/fontstash.odin @@ -324,11 +324,15 @@ __AtlasAddWhiteRect :: proc(ctx: ^FontContext, w, h: int) -> bool { // push a font to the font stack // optionally init with ascii characters at a wanted size +// +// 'fontIndex' controls which font you want to load within a multi-font format such +// as TTC. Leave it as zero if you are loading a single-font format such as TTF. AddFontMem :: proc( ctx: ^FontContext, name: string, data: []u8, freeLoadedData: bool, + fontIndex: int = 0, ) -> int { append(&ctx.fonts, Font{}) res := &ctx.fonts[len(ctx.fonts) - 1] @@ -336,7 +340,10 @@ AddFontMem :: proc( res.freeLoadedData = freeLoadedData res.name = strings.clone(name) - stbtt.InitFont(&res.info, &res.loadedData[0], 0) + num_fonts := stbtt.GetNumberOfFonts(raw_data(data)) + font_index_clamped := num_fonts > 0 ? clamp(i32(fontIndex), 0, num_fonts-1) : 0 + font_offset := stbtt.GetFontOffsetForIndex(raw_data(data), font_index_clamped) + stbtt.InitFont(&res.info, raw_data(data), font_offset) ascent, descent, line_gap: i32 stbtt.GetFontVMetrics(&res.info, &ascent, &descent, &line_gap) diff --git a/vendor/fontstash/fontstash_os.odin b/vendor/fontstash/fontstash_os.odin index ed453926f..e510a4834 100644 --- a/vendor/fontstash/fontstash_os.odin +++ b/vendor/fontstash/fontstash_os.odin @@ -4,10 +4,13 @@ package fontstash import "core:log" import "core:os" +// 'fontIndex' controls which font you want to load within a multi-font format such +// as TTC. Leave it as zero if you are loading a single-font format such as TTF. AddFontPath :: proc( ctx: ^FontContext, name: string, path: string, + fontIndex: int = 0, ) -> int { data, ok := os.read_entire_file(path) @@ -15,6 +18,6 @@ AddFontPath :: proc( log.panicf("FONT: failed to read font at %s", path) } - return AddFontMem(ctx, name, data, true) + return AddFontMem(ctx, name, data, true, fontIndex) } diff --git a/vendor/fontstash/fontstash_other.odin b/vendor/fontstash/fontstash_other.odin index edb76d9db..b0a0e2ab9 100644 --- a/vendor/fontstash/fontstash_other.odin +++ b/vendor/fontstash/fontstash_other.odin @@ -5,6 +5,7 @@ AddFontPath :: proc( ctx: ^FontContext, name: string, path: string, + fontIndex: int = 0, ) -> int { panic("fontstash.AddFontPath is unsupported on the JS target") } |