mirror of
https://github.com/odin-lang/Odin.git
synced 2026-04-19 13:00:28 +00:00
Merge pull request #5773 from karl-zylinski/fontstash-ttc-fix
Fix fontstash crash with .TTC files
This commit is contained in:
9
vendor/fontstash/fontstash.odin
vendored
9
vendor/fontstash/fontstash.odin
vendored
@@ -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)
|
||||
|
||||
5
vendor/fontstash/fontstash_os.odin
vendored
5
vendor/fontstash/fontstash_os.odin
vendored
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
1
vendor/fontstash/fontstash_other.odin
vendored
1
vendor/fontstash/fontstash_other.odin
vendored
@@ -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")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user