mirror of
https://github.com/bloeys/nterm.git
synced 2025-12-29 14:38:19 +00:00
Basic run extraction
This commit is contained in:
@ -143,14 +143,35 @@ func (gr *GlyphRend) DrawTextOpenGLAbs(text string, screenPos *gglm.Vec3, color
|
|||||||
|
|
||||||
func (gr *GlyphRend) GetTextRuns(t string) [][]rune {
|
func (gr *GlyphRend) GetTextRuns(t string) [][]rune {
|
||||||
|
|
||||||
// rs := []rune(t)
|
rs := []rune(t)
|
||||||
// runScript := unicode.Arabic
|
|
||||||
// runStartIndex := 0
|
|
||||||
// runs := make([][]rune, 0)
|
|
||||||
// for i := 0; i < len(rs); i++ {
|
|
||||||
|
|
||||||
// }
|
if len(rs) == 0 {
|
||||||
return nil
|
return [][]rune{}
|
||||||
|
}
|
||||||
|
|
||||||
|
runs := make([][]rune, 0, 1)
|
||||||
|
currRunScript := RuneInfos[rs[0]].ScriptTable
|
||||||
|
|
||||||
|
runStartIndex := 0
|
||||||
|
for i := 1; i < len(rs); i++ {
|
||||||
|
|
||||||
|
r := rs[i]
|
||||||
|
ri := RuneInfos[r]
|
||||||
|
if ri.ScriptTable == currRunScript || ri.ScriptTable == unicode.Common {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
runs = append(runs, rs[runStartIndex:i])
|
||||||
|
|
||||||
|
runStartIndex = i
|
||||||
|
currRunScript = ri.ScriptTable
|
||||||
|
}
|
||||||
|
|
||||||
|
if runStartIndex != len(rs)-1 {
|
||||||
|
runs = append(runs, rs[runStartIndex:])
|
||||||
|
}
|
||||||
|
|
||||||
|
return runs
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gr *GlyphRend) glyphFromRunes(curr, prev, next rune) *FontAtlasGlyph {
|
func (gr *GlyphRend) glyphFromRunes(curr, prev, next rune) *FontAtlasGlyph {
|
||||||
|
|||||||
3
main.go
3
main.go
@ -100,6 +100,9 @@ func (p *program) Init() {
|
|||||||
|
|
||||||
p.gridMat = materials.NewMaterial("grid", "./res/shaders/grid.glsl")
|
p.gridMat = materials.NewMaterial("grid", "./res/shaders/grid.glsl")
|
||||||
p.handleWindowResize()
|
p.handleWindowResize()
|
||||||
|
|
||||||
|
// runs := p.GlyphRend.GetTextRuns("hello there يا friend")
|
||||||
|
// fmt.Printf("%+v\n%s\n%s\n%s\n", runs, string(runs[0]), string(runs[1]), string(runs[2]))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *program) Update() {
|
func (p *program) Update() {
|
||||||
|
|||||||
Reference in New Issue
Block a user