From 38dafbfd653ff1618115ab4d1350013cb2fc309a Mon Sep 17 00:00:00 2001 From: bloeys Date: Mon, 11 Jul 2022 11:29:12 +0400 Subject: [PATCH] Fast path shaping non-joining chars --- glyphs/glyphs.go | 20 +++++--------------- main.go | 6 +++--- 2 files changed, 8 insertions(+), 18 deletions(-) diff --git a/glyphs/glyphs.go b/glyphs/glyphs.go index 3b575c1..2d81930 100755 --- a/glyphs/glyphs.go +++ b/glyphs/glyphs.go @@ -270,6 +270,7 @@ func (gr *GlyphRend) GetTextRuns(t string, textRunsBuf *[]TextRun) { } } +//GlyphFromRunes does shaping where it selects the proper rune based (e.g. end Alef) on the surrounding runes func GlyphFromRunes(glyphTable map[rune]FontAtlasGlyph, curr, prev, next rune) FontAtlasGlyph { //PERF: Map access times are absolute garbage to the point that ~85%+ of the runtime of this func @@ -287,11 +288,13 @@ func GlyphFromRunes(glyphTable map[rune]FontAtlasGlyph, curr, prev, next rune) F //Isolated case if !prevIsValid && !nextIsValid { - g := glyphTable[curr] - return g + return glyphTable[curr] } ri := RuneInfos[curr] + if ri.JoinType == JoiningType_None || ri.JoinType == JoiningType_Transparent { + return glyphTable[curr] + } prevJoinType := RuneInfos[prev].JoinType joinWithRight := prevIsValid && @@ -351,19 +354,6 @@ func GlyphFromRunes(glyphTable map[rune]FontAtlasGlyph, curr, prev, next rune) F break } } - - case PosCtx_isolated: - - // equivRunes := RuneInfos[curr].EquivalentRunes - // for i := 0; i < len(equivRunes); i++ { - - // otherRune := equivRunes[i] - // otherRuneInfo := RuneInfos[otherRune] - // if otherRuneInfo.DecompTag == DecompTag_isolated { - // curr = otherRune - // break - // } - // } } return glyphTable[curr] diff --git a/main.go b/main.go index d1883a6..409b453 100755 --- a/main.go +++ b/main.go @@ -95,8 +95,8 @@ func (p *program) Init() { fmt.Printf("DPI: %f, font size: %d\n", dpi, p.FontSize) w, h := p.win.SDLWin.GetSize() - p.GlyphRend, err = glyphs.NewGlyphRend("./res/fonts/tajawal-regular-var.ttf", &truetype.Options{Size: float64(p.FontSize), DPI: p.Dpi, SubPixelsX: subPixelX, SubPixelsY: subPixelY, Hinting: hinting}, w, h) - // p.GlyphRend, err = glyphs.NewGlyphRend("./res/fonts/alm-fixed.ttf", &truetype.Options{Size: float64(p.FontSize), DPI: p.Dpi, SubPixelsX: subPixelX, SubPixelsY: subPixelY, Hinting: hinting}, w, h) + // p.GlyphRend, err = glyphs.NewGlyphRend("./res/fonts/tajawal-regular-var.ttf", &truetype.Options{Size: float64(p.FontSize), DPI: p.Dpi, SubPixelsX: subPixelX, SubPixelsY: subPixelY, Hinting: hinting}, w, h) + p.GlyphRend, err = glyphs.NewGlyphRend("./res/fonts/alm-fixed.ttf", &truetype.Options{Size: float64(p.FontSize), DPI: p.Dpi, SubPixelsX: subPixelX, SubPixelsY: subPixelY, Hinting: hinting}, w, h) if err != nil { panic("Failed to create atlas from font file. Err: " + err.Error()) } @@ -194,7 +194,7 @@ func (p *program) Update() { var isDrawingBounds = false var drawManyLines = false -var textToShow = "Hello there يا friend. اسميعمر wow!" +var textToShow = "Hello there, friend!" var xOff float32 = 0 var yOff float32 = 0