wasm: support vendor:stb/truetype and vendor:fontstash

This commit is contained in:
Laytan Laats
2024-07-02 16:03:42 +02:00
parent 4e18e1b191
commit 10c68a8951
8 changed files with 168 additions and 18 deletions
+3 -17
View File
@@ -1,14 +1,14 @@
//+build windows, linux, darwin
//+vet !using-param
package fontstash
import "base:runtime"
import "core:log"
import "core:os"
import "core:mem"
import "core:math"
import "core:strings"
import "core:slice"
import stbtt "vendor:stb/truetype"
// This is a port from Fontstash into odin - specialized for nanovg
@@ -321,20 +321,6 @@ __AtlasAddWhiteRect :: proc(ctx: ^FontContext, w, h: int) -> bool {
return true
}
AddFontPath :: proc(
ctx: ^FontContext,
name: string,
path: string,
) -> int {
data, ok := os.read_entire_file(path)
if !ok {
log.panicf("FONT: failed to read font at %s", path)
}
return AddFontMem(ctx, name, data, true)
}
// push a font to the font stack
// optionally init with ascii characters at a wanted size
AddFontMem :: proc(
@@ -1192,4 +1178,4 @@ EndState :: proc(using ctx: ^FontContext) {
}
__dirtyRectReset(ctx)
}
}
}
+20
View File
@@ -0,0 +1,20 @@
//+build !js
package fontstash
import "core:log"
import "core:os"
AddFontPath :: proc(
ctx: ^FontContext,
name: string,
path: string,
) -> int {
data, ok := os.read_entire_file(path)
if !ok {
log.panicf("FONT: failed to read font at %s", path)
}
return AddFontMem(ctx, name, data, true)
}