From ed1ec0d67ed54e9710281564541c97811e4de596 Mon Sep 17 00:00:00 2001 From: bloeys Date: Tue, 5 Jul 2022 07:29:33 +0400 Subject: [PATCH] Basic run extraction --- glyphs/glyphs.go | 35 ++++++++++++++++++++++++++++------- main.go | 3 +++ 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/glyphs/glyphs.go b/glyphs/glyphs.go index 28418b9..8eaf184 100755 --- a/glyphs/glyphs.go +++ b/glyphs/glyphs.go @@ -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 { diff --git a/main.go b/main.go index 3fb9dd7..b363683 100755 --- a/main.go +++ b/main.go @@ -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() {