Basic run extraction

This commit is contained in:
bloeys
2022-07-05 07:29:33 +04:00
parent 603409e58e
commit ed1ec0d67e
2 changed files with 31 additions and 7 deletions

View File

@ -143,14 +143,35 @@ func (gr *GlyphRend) DrawTextOpenGLAbs(text string, screenPos *gglm.Vec3, color
func (gr *GlyphRend) GetTextRuns(t string) [][]rune {
// rs := []rune(t)
// runScript := unicode.Arabic
// runStartIndex := 0
// runs := make([][]rune, 0)
// for i := 0; i < len(rs); i++ {
rs := []rune(t)
// }
return nil
if len(rs) == 0 {
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 {

View File

@ -100,6 +100,9 @@ func (p *program) Init() {
p.gridMat = materials.NewMaterial("grid", "./res/shaders/grid.glsl")
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() {