mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-05 23:28:48 +00:00
add freeLoadedData flag in case you dont want to remove font memory (e.g. #load)
This commit is contained in:
Vendored
+9
-2
@@ -50,6 +50,7 @@ Font :: struct {
|
|||||||
|
|
||||||
info: stbtt.fontinfo,
|
info: stbtt.fontinfo,
|
||||||
loadedData: []byte,
|
loadedData: []byte,
|
||||||
|
freeLoadedData: bool, // in case you dont want loadedData to be removed
|
||||||
|
|
||||||
ascender: f32,
|
ascender: f32,
|
||||||
descender: f32,
|
descender: f32,
|
||||||
@@ -147,7 +148,11 @@ Init :: proc(using ctx: ^FontContext, w, h: int, loc: QuadLocation) {
|
|||||||
|
|
||||||
Destroy :: proc(using ctx: ^FontContext) {
|
Destroy :: proc(using ctx: ^FontContext) {
|
||||||
for font in &fonts {
|
for font in &fonts {
|
||||||
delete(font.loadedData)
|
if font.freeLoadedData {
|
||||||
|
delete(font.loadedData)
|
||||||
|
}
|
||||||
|
|
||||||
|
delete(font.name)
|
||||||
delete(font.glyphs)
|
delete(font.glyphs)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -349,7 +354,7 @@ AddFontPath :: proc(
|
|||||||
log.panicf("FONT: failed to read font at %s", path)
|
log.panicf("FONT: failed to read font at %s", path)
|
||||||
}
|
}
|
||||||
|
|
||||||
return AddFontMem(ctx, name, data)
|
return AddFontMem(ctx, name, data, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
// push a font to the font stack
|
// push a font to the font stack
|
||||||
@@ -358,10 +363,12 @@ AddFontMem :: proc(
|
|||||||
ctx: ^FontContext,
|
ctx: ^FontContext,
|
||||||
name: string,
|
name: string,
|
||||||
data: []u8,
|
data: []u8,
|
||||||
|
freeLoadedData: bool,
|
||||||
) -> int {
|
) -> int {
|
||||||
append(&ctx.fonts, Font {})
|
append(&ctx.fonts, Font {})
|
||||||
res := &ctx.fonts[len(ctx.fonts) - 1]
|
res := &ctx.fonts[len(ctx.fonts) - 1]
|
||||||
res.loadedData = data
|
res.loadedData = data
|
||||||
|
res.freeLoadedData = freeLoadedData
|
||||||
res.name = strings.clone(name)
|
res.name = strings.clone(name)
|
||||||
|
|
||||||
stbtt.InitFont(&res.info, &res.loadedData[0], 0)
|
stbtt.InitFont(&res.info, &res.loadedData[0], 0)
|
||||||
|
|||||||
Reference in New Issue
Block a user