aboutsummaryrefslogtreecommitdiff
path: root/vendor
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2025-06-20 09:03:56 +0100
committergingerBill <bill@gingerbill.org>2025-06-20 09:03:56 +0100
commit8f115c5bc8e0f683f69a239ca2dbe9d6fd70dc05 (patch)
tree94d9cf91cdf84ff4da73b1befba74a5ac5298ff5 /vendor
parentc056fb75127739f7f32b0226bbe0607c4fe63b9d (diff)
Remove need for CRT with kb_text_shape and implement the allocating calls manually
Diffstat (limited to 'vendor')
-rw-r--r--vendor/kb_text_shape/kb_text_shape_procs.odin92
-rw-r--r--vendor/kb_text_shape/kb_text_shape_types.odin2
-rw-r--r--vendor/kb_text_shape/lib/kb_text_shape.libbin710778 -> 699064 bytes
-rw-r--r--vendor/kb_text_shape/src/kb_text_shape.c2
4 files changed, 81 insertions, 15 deletions
diff --git a/vendor/kb_text_shape/kb_text_shape_procs.odin b/vendor/kb_text_shape/kb_text_shape_procs.odin
index 342be282c..30ad97500 100644
--- a/vendor/kb_text_shape/kb_text_shape_procs.odin
+++ b/vendor/kb_text_shape/kb_text_shape_procs.odin
@@ -11,29 +11,30 @@ when ODIN_OS == .Windows {
}
import "core:c"
+import "core:mem"
#assert(size_of(c.int) == size_of(b32))
#assert(size_of(u32) == size_of(b32))
-@(default_calling_convention="c", link_prefix="kbts_")
+@(default_calling_convention="c", link_prefix="kbts_", require_results)
foreign lib {
- // when !TEXT_SHAPE_NO_CRT {
- FontFromFile :: proc(FileName: cstring) -> font ---
- FreeFont :: proc(Font: ^font) ---
- CreateShapeState :: proc(Font: ^font) -> ^shape_state ---
- FreeShapeState :: proc(State: ^shape_state) ---
- // }
-
- FontIsValid :: proc(Font: ^font) -> int ---
+ FontIsValid :: proc(Font: ^font) -> b32 ---
ReadFontHeader :: proc(Font: ^font, Data: rawptr, Size: un) -> un ---
ReadFontData :: proc(Font: ^font, Scratch: rawptr, ScratchSize: un) -> un ---
- PostReadFontInitialize :: proc(Font: ^font, Memory: rawptr, MemorySize: un) -> int ---
+ PostReadFontInitialize :: proc(Font: ^font, Memory: rawptr, MemorySize: un) -> b32 ---
SizeOfShapeState :: proc(Font: ^font) -> un ---
+
PlaceShapeState :: proc(Address: rawptr, Size: un) -> ^shape_state ---
ResetShapeState :: proc(State: ^shape_state) ---
- ShapeConfig :: proc(Font: ^font, Script: u32, Language: u32) -> shape_config ---
+
+ ShapeConfig :: proc(Font: ^font, Script: script, Language: language) -> shape_config ---
ShaperIsComplex :: proc(Shaper: shaper) -> b32 ---
- Shape :: proc(State: ^shape_state, Config: ^shape_config, MainDirection, RunDirection: direction, Glyphs: [^]glyph, GlyphCount: ^u32, GlyphCapacity: u32) -> c.int ---
+ ScriptIsComplex :: proc(Script: script) -> b32 ---
+
+ Shape :: proc(State: ^shape_state, Config: ^shape_config,
+ MainDirection, RunDirection: direction,
+ Glyphs: [^]glyph, GlyphCount: ^u32, GlyphCapacity: u32) -> c.int ---
+
Cursor :: proc(Direction: direction) -> cursor ---
PositionGlyph :: proc(Cursor: ^cursor, Glyph: ^glyph, X, Y: ^i32) ---
BeginBreak :: proc(State: ^break_state, MainDirection: direction, JapaneseLineBreakStyle: japanese_line_break_style) ---
@@ -44,5 +45,70 @@ foreign lib {
DecodeUtf8 :: proc(Utf8: [^]byte, Length: uint) -> decode ---
CodepointToGlyph :: proc(Font: ^font, Codepoint: rune) -> glyph ---
InferScript :: proc(Direction: ^direction, Script: ^script, GlyphScript: script) ---
- ScriptIsComplex :: proc(Script: script) -> b32 ---
+}
+
+@(require_results)
+PlaceShapeStateFromSlice :: proc "c" (Memory: []byte) -> ^shape_state {
+ return PlaceShapeState(raw_data(Memory), un(len(Memory)))
+}
+
+@(require_results)
+DecodeUtf8String :: proc "c" (String: string) -> decode {
+ return DecodeUtf8(raw_data(String), len(String))
+}
+
+
+@(require_results)
+ReadFontHeaderFromSlice :: proc "c" (Font: ^font, Data: []byte) -> un {
+ return ReadFontHeader(Font, raw_data(Data), un(len(Data)))
+}
+@(require_results)
+ReadFontDataFromSlice :: proc "c" (Font: ^font, Scratch: []byte) -> un {
+ return ReadFontData(Font, raw_data(Scratch), un(len(Scratch)))
+}
+@(require_results)
+PostReadFontInitializeFromSlice :: proc "c" (Font: ^font, Memory: []byte) -> b32 {
+ return PostReadFontInitialize(Font, raw_data(Memory), un(len(Memory)))
+}
+
+@(require_results)
+FontFromMemory :: proc(Data: []byte, allocator: mem.Allocator) -> (Result: font, Err: mem.Allocator_Error) {
+ ClonedData := mem.make_aligned([]byte, len(Data), 16, allocator) or_return
+ defer if Err != nil {
+ delete(ClonedData, allocator)
+ }
+ copy(ClonedData, Data)
+
+ ScratchSize := ReadFontHeaderFromSlice(&Result, ClonedData)
+ Scratch := mem.make_aligned([]byte, ScratchSize, 16, allocator) or_return
+ MemorySize := ReadFontDataFromSlice(&Result, Scratch)
+
+ Memory := Scratch
+ if MemorySize > ScratchSize {
+ delete(Scratch, allocator)
+ Memory = mem.make_aligned([]byte, MemorySize, 16, allocator) or_return
+ }
+ defer if Err != nil {
+ delete(Memory, allocator)
+ }
+
+ PostReadFontInitializeFromSlice(&Result, Memory)
+ return
+
+}
+FreeFont :: proc(Font: ^font, allocator: mem.Allocator) {
+ free(Font.FileBase, allocator)
+ free(Font.GlyphLookupMatrix, allocator)
+ Font^ = {}
+}
+
+@(require_results)
+CreateShapeState :: proc(Font: ^font, allocator: mem.Allocator) -> (Result: ^shape_state, Err: mem.Allocator_Error) {
+ Size := SizeOfShapeState(Font)
+ Memory := mem.make_aligned([]byte, Size, 16, allocator) or_return
+ Result = PlaceShapeStateFromSlice(Memory)
+ return
+}
+FreeShapeState :: proc(State: ^shape_state, allocator: mem.Allocator) {
+ free(State, allocator)
} \ No newline at end of file
diff --git a/vendor/kb_text_shape/kb_text_shape_types.odin b/vendor/kb_text_shape/kb_text_shape_types.odin
index c50d3a26e..2868492a2 100644
--- a/vendor/kb_text_shape/kb_text_shape_types.odin
+++ b/vendor/kb_text_shape/kb_text_shape_types.odin
@@ -3,7 +3,7 @@ package vendor_kb_text_shape
import "core:c"
un :: distinct uintptr
-sn :: distinct (i32 when size_of(uintptr) == 4 else i64)
+// sn :: distinct (i32 when size_of(uintptr) == 4 else i64)
joining_feature :: enum u8 {
NONE,
diff --git a/vendor/kb_text_shape/lib/kb_text_shape.lib b/vendor/kb_text_shape/lib/kb_text_shape.lib
index 9ec799712..eb30f917e 100644
--- a/vendor/kb_text_shape/lib/kb_text_shape.lib
+++ b/vendor/kb_text_shape/lib/kb_text_shape.lib
Binary files differ
diff --git a/vendor/kb_text_shape/src/kb_text_shape.c b/vendor/kb_text_shape/src/kb_text_shape.c
index 041023013..1d5ad0255 100644
--- a/vendor/kb_text_shape/src/kb_text_shape.c
+++ b/vendor/kb_text_shape/src/kb_text_shape.c
@@ -1,5 +1,5 @@
-#include <stdlib.h>
#include <stdint.h>
+#define KB_TEXT_SHAPE_NO_CRT
#define KB_TEXT_SHAPE_IMPLEMENTATION
#include "kb_text_shape.h" \ No newline at end of file