Skip to content

Commit 9a328e1

Browse files
committed
Use multiple return values where possible
1 parent c3e9b16 commit 9a328e1

File tree

1 file changed

+72
-44
lines changed

1 file changed

+72
-44
lines changed

vendor/kb_text_shape/kb_text_shape_procs.odin

Lines changed: 72 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -18,59 +18,77 @@ import "core:mem"
1818

1919
@(default_calling_convention="c", link_prefix="kbts_", require_results)
2020
foreign lib {
21-
FontIsValid :: proc(Font: ^font) -> b32 ---
22-
ReadFontHeader :: proc(Font: ^font, Data: rawptr, Size: un) -> un ---
23-
ReadFontData :: proc(Font: ^font, Scratch: rawptr, ScratchSize: un) -> un ---
24-
PostReadFontInitialize :: proc(Font: ^font, Memory: rawptr, MemorySize: un) -> b32 ---
25-
SizeOfShapeState :: proc(Font: ^font) -> un ---
26-
27-
PlaceShapeState :: proc(Address: rawptr, Size: un) -> ^shape_state ---
28-
ResetShapeState :: proc(State: ^shape_state) ---
29-
30-
ShapeConfig :: proc(Font: ^font, Script: script, Language: language) -> shape_config ---
31-
ShaperIsComplex :: proc(Shaper: shaper) -> b32 ---
32-
ScriptIsComplex :: proc(Script: script) -> b32 ---
33-
34-
Shape :: proc(State: ^shape_state, Config: ^shape_config,
35-
MainDirection, RunDirection: direction,
36-
Glyphs: [^]glyph, GlyphCount: ^u32, GlyphCapacity: u32) -> c.int ---
37-
38-
Cursor :: proc(Direction: direction) -> cursor ---
39-
PositionGlyph :: proc(Cursor: ^cursor, Glyph: ^glyph, X, Y: ^i32) ---
40-
BeginBreak :: proc(State: ^break_state, MainDirection: direction, JapaneseLineBreakStyle: japanese_line_break_style) ---
41-
BreakStateIsValid :: proc(State: ^break_state) -> c.int ---
42-
BreakAddCodepoint :: proc(State: ^break_state, Codepoint: rune, PositionIncrement: u32, EndOfText: c.int) ---
43-
BreakFlush :: proc(State: ^break_state) ---
44-
Break :: proc(State: ^break_state, Break: ^break_type) -> c.int ---
45-
DecodeUtf8 :: proc(Utf8: [^]byte, Length: uint) -> decode ---
46-
CodepointToGlyph :: proc(Font: ^font, Codepoint: rune) -> glyph ---
47-
InferScript :: proc(Direction: ^direction, Script: ^script, GlyphScript: script) ---
21+
FontIsValid :: proc(Font: ^font) -> b32 ---
22+
SizeOfShapeState :: proc(Font: ^font) -> un ---
23+
24+
ResetShapeState :: proc(State: ^shape_state) ---
25+
26+
ShapeConfig :: proc(Font: ^font, Script: script, Language: language) -> shape_config ---
27+
ShaperIsComplex :: proc(Shaper: shaper) -> b32 ---
28+
ScriptIsComplex :: proc(Script: script) -> b32 ---
29+
30+
Shape :: proc(State: ^shape_state, Config: ^shape_config,
31+
MainDirection, RunDirection: direction,
32+
Glyphs: [^]glyph, GlyphCount: ^u32, GlyphCapacity: u32) -> c.int ---
33+
34+
Cursor :: proc(Direction: direction) -> cursor ---
35+
BeginBreak :: proc(State: ^break_state, MainDirection: direction, JapaneseLineBreakStyle: japanese_line_break_style) ---
36+
BreakStateIsValid :: proc(State: ^break_state) -> b32 ---
37+
BreakAddCodepoint :: proc(State: ^break_state, Codepoint: rune, PositionIncrement: u32, EndOfText: c.int) ---
38+
BreakFlush :: proc(State: ^break_state) ---
39+
Break :: proc(State: ^break_state, Break: ^break_type) -> b32 ---
40+
CodepointToGlyph :: proc(Font: ^font, Codepoint: rune) -> glyph ---
41+
InferScript :: proc(Direction: ^direction, Script: ^script, GlyphScript: script) ---
4842
}
4943

5044
@(require_results)
51-
PlaceShapeStateFromSlice :: proc "c" (Memory: []byte) -> ^shape_state {
52-
return PlaceShapeState(raw_data(Memory), un(len(Memory)))
45+
PlaceShapeState :: proc "c" (Memory: []byte) -> ^shape_state {
46+
@(default_calling_convention="c", require_results)
47+
foreign lib {
48+
kbts_PlaceShapeState :: proc(Address: rawptr, Size: un) -> ^shape_state ---
49+
}
50+
51+
return kbts_PlaceShapeState(raw_data(Memory), un(len(Memory)))
5352
}
5453

5554
@(require_results)
56-
DecodeUtf8String :: proc "c" (String: string) -> (Codepoint: rune, SourceCharactersConsumed: u32, Valid: b32) {
57-
Decode := DecodeUtf8(raw_data(String), len(String))
58-
Codepoint, SourceCharactersConsumed, Valid = Decode.Codepoint, Decode.SourceCharactersConsumed, Decode.Valid
59-
return
55+
DecodeUtf8 :: proc "contextless" (String: string) -> (Codepoint: rune, SourceCharactersConsumed: u32, Valid: b32) {
56+
@(default_calling_convention="c", require_results)
57+
foreign lib {
58+
kbts_DecodeUtf8 :: proc(Utf8: [^]byte, Length: uint) -> decode ---
59+
}
60+
61+
Decode := kbts_DecodeUtf8(raw_data(String), len(String))
62+
return Decode.Codepoint, Decode.SourceCharactersConsumed, Decode.Valid
6063
}
6164

6265

6366
@(require_results)
64-
ReadFontHeaderFromSlice :: proc "c" (Font: ^font, Data: []byte) -> un {
65-
return ReadFontHeader(Font, raw_data(Data), un(len(Data)))
67+
ReadFontHeader :: proc "c" (Font: ^font, Data: []byte) -> un {
68+
@(default_calling_convention="c", require_results)
69+
foreign lib {
70+
kbts_ReadFontHeader :: proc(Font: ^font, Data: rawptr, Size: un) -> un ---
71+
}
72+
73+
return kbts_ReadFontHeader(Font, raw_data(Data), un(len(Data)))
6674
}
6775
@(require_results)
68-
ReadFontDataFromSlice :: proc "c" (Font: ^font, Scratch: []byte) -> un {
69-
return ReadFontData(Font, raw_data(Scratch), un(len(Scratch)))
76+
ReadFontData :: proc "c" (Font: ^font, Scratch: []byte) -> un {
77+
@(default_calling_convention="c", require_results)
78+
foreign lib {
79+
kbts_ReadFontData :: proc(Font: ^font, Scratch: rawptr, ScratchSize: un) -> un ---
80+
}
81+
82+
return kbts_ReadFontData(Font, raw_data(Scratch), un(len(Scratch)))
7083
}
7184
@(require_results)
72-
PostReadFontInitializeFromSlice :: proc "c" (Font: ^font, Memory: []byte) -> b32 {
73-
return PostReadFontInitialize(Font, raw_data(Memory), un(len(Memory)))
85+
PostReadFontInitialize :: proc "c" (Font: ^font, Memory: []byte) -> b32 {
86+
@(default_calling_convention="c", require_results)
87+
foreign lib {
88+
kbts_PostReadFontInitialize :: proc(Font: ^font, Memory: rawptr, MemorySize: un) -> b32 ---
89+
}
90+
91+
return kbts_PostReadFontInitialize(Font, raw_data(Memory), un(len(Memory)))
7492
}
7593

7694
@(require_results)
@@ -81,9 +99,9 @@ FontFromMemory :: proc(Data: []byte, allocator: mem.Allocator) -> (Result: font,
8199
}
82100
copy(ClonedData, Data)
83101

84-
ScratchSize := ReadFontHeaderFromSlice(&Result, ClonedData)
102+
ScratchSize := ReadFontHeader(&Result, ClonedData)
85103
Scratch := mem.make_aligned([]byte, ScratchSize, 16, allocator) or_return
86-
MemorySize := ReadFontDataFromSlice(&Result, Scratch)
104+
MemorySize := ReadFontData(&Result, Scratch)
87105

88106
Memory := Scratch
89107
if MemorySize > ScratchSize {
@@ -94,7 +112,7 @@ FontFromMemory :: proc(Data: []byte, allocator: mem.Allocator) -> (Result: font,
94112
delete(Memory, allocator)
95113
}
96114

97-
_ = PostReadFontInitializeFromSlice(&Result, Memory)
115+
_ = PostReadFontInitialize(&Result, Memory)
98116
return
99117

100118
}
@@ -108,9 +126,19 @@ FreeFont :: proc(Font: ^font, allocator: mem.Allocator) {
108126
CreateShapeState :: proc(Font: ^font, allocator: mem.Allocator) -> (Result: ^shape_state, Err: mem.Allocator_Error) {
109127
Size := SizeOfShapeState(Font)
110128
Memory := mem.make_aligned([]byte, Size, 16, allocator) or_return
111-
Result = PlaceShapeStateFromSlice(Memory)
129+
Result = PlaceShapeState(Memory)
112130
return
113131
}
114132
FreeShapeState :: proc(State: ^shape_state, allocator: mem.Allocator) {
115133
free(State, allocator)
116-
}
134+
}
135+
136+
@(require_results)
137+
PositionGlyph :: proc(Cursor: ^cursor, Glyph: ^glyph) -> (X, Y: i32) {
138+
@(default_calling_convention="c", require_results)
139+
foreign lib {
140+
kbts_PositionGlyph :: proc(Cursor: ^cursor, Glyph: ^glyph, X, Y: ^i32) ---
141+
}
142+
kbts_PositionGlyph(Cursor, Glyph, &X, &Y)
143+
return
144+
}

0 commit comments

Comments
 (0)