| 1 | module sfons |
| 2 | |
| 3 | import fontstash |
| 4 | import sokol.f as _ |
| 5 | import sokol.memory |
| 6 | |
| 7 | // create a new Context/font atlas, for rendering glyphs, given its dimensions `width` and `height` |
| 8 | @[inline] |
| 9 | pub fn create(width int, height int, flags int) &fontstash.Context { |
| 10 | assert is_power_of_two(width) |
| 11 | assert is_power_of_two(height) |
| 12 | allocator := C.sfons_allocator_t{ |
| 13 | alloc_fn: memory.salloc |
| 14 | free_fn: memory.sfree |
| 15 | user_data: voidptr(0x100005f0) |
| 16 | } |
| 17 | desc := C.sfons_desc_t{ |
| 18 | width: width |
| 19 | height: height |
| 20 | allocator: allocator |
| 21 | } |
| 22 | return C.sfons_create(&desc) |
| 23 | } |
| 24 | |
| 25 | @[inline] |
| 26 | pub fn destroy(ctx &fontstash.Context) { |
| 27 | C.sfons_destroy(ctx) |
| 28 | } |
| 29 | |
| 30 | @[inline] |
| 31 | pub fn rgba(r u8, g u8, b u8, a u8) u32 { |
| 32 | return C.sfons_rgba(r, g, b, a) |
| 33 | } |
| 34 | |
| 35 | @[inline] |
| 36 | pub fn flush(ctx &fontstash.Context) { |
| 37 | C.sfons_flush(ctx) |
| 38 | } |
| 39 | |
| 40 | fn is_power_of_two(x int) bool { |
| 41 | return x in [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768] |
| 42 | } |
| 43 | |