diff --git a/text/shaped/shapers/shapedgt/shaper.go b/text/shaped/shapers/shapedgt/shaper.go index 8c6c4faec1..5a6a6da523 100644 --- a/text/shaped/shapers/shapedgt/shaper.go +++ b/text/shaped/shapers/shapedgt/shaper.go @@ -59,7 +59,7 @@ func (nl *nilLogger) Printf(format string, args ...any) {} // NewShaper returns a new text shaper. func NewShaper() shaped.Shaper { sh := &Shaper{} - sh.fontMap = fontscan.NewFontMap(nil) // &nilLogger{} + sh.fontMap = fontscan.NewFontMap(&nilLogger{}) // TODO(text): figure out cache dir situation (especially on mobile and web) str, err := os.UserCacheDir() if errors.Log(err) != nil { diff --git a/text/shaped/shapers/shapedgt/wrap.go b/text/shaped/shapers/shapedgt/wrap.go index 8ef06f11bc..e935bdb788 100644 --- a/text/shaped/shapers/shapedgt/wrap.go +++ b/text/shaped/shapers/shapedgt/wrap.go @@ -30,17 +30,17 @@ func (sh *Shaper) WrapLines(tx rich.Text, defSty *rich.Style, tsty *text.Style, tsty.FontSize.Dots = 16 } + lht := sh.lineHeight(defSty, tsty, rts) // note: this overwrites output buffer so must do outs after! txt := tx.Join() outs := sh.ShapeTextOutput(tx, tsty, rts, txt) - return sh.WrapLinesOutput(outs, txt, tx, defSty, tsty, rts, size) + return sh.WrapLinesOutput(outs, txt, tx, defSty, tsty, lht, rts, size) } -func (sh *Shaper) WrapLinesOutput(outs []shaping.Output, txt []rune, tx rich.Text, defSty *rich.Style, tsty *text.Style, rts *rich.Settings, size math32.Vector2) *shaped.Lines { +func (sh *Shaper) WrapLinesOutput(outs []shaping.Output, txt []rune, tx rich.Text, defSty *rich.Style, tsty *text.Style, lht float32, rts *rich.Settings, size math32.Vector2) *shaped.Lines { fsz := tsty.FontSize.Dots dir := shaped.GoTextDirection(rich.Default, tsty) - lht := sh.lineHeight(defSty, tsty, rts) lns := &shaped.Lines{Source: tx, Color: tsty.Color, SelectionColor: tsty.SelectColor, HighlightColor: tsty.HighlightColor, LineHeight: lht} lgap := lns.LineHeight - (lns.LineHeight / tsty.LineSpacing) // extra added for spacing diff --git a/text/shaped/shapers/shapedjs/font.go b/text/shaped/shapers/shapedjs/font.go index f5fb8aaaad..935ae1e91a 100644 --- a/text/shaped/shapers/shapedjs/font.go +++ b/text/shaped/shapers/shapedjs/font.go @@ -30,6 +30,6 @@ func SetFontStyle(ctx js.Value, fn *text.Font, tsty *text.Style, lineHeight floa // font: font-style font-variant font-weight font-size/line-height font-family parts := []string{fsty.Slant.String(), "normal", fmt.Sprintf("%g", fsty.Weight.ToFloat32()), fsz, fam} fspec := strings.Join(parts, " ") - fmt.Println("fspec:", fspec) + // fmt.Println("fspec:", fspec) ctx.Set("font", fspec) } diff --git a/text/shaped/shapers/shapedjs/shaper.go b/text/shaped/shapers/shapedjs/shaper.go index 6d5c2275d6..4676f2f386 100644 --- a/text/shaped/shapers/shapedjs/shaper.go +++ b/text/shaped/shapers/shapedjs/shaper.go @@ -71,6 +71,7 @@ func (sh *Shaper) Shape(tx rich.Text, tsty *text.Style, rts *rich.Settings) []sh // use slices.Clone if needed longer than that. func (sh *Shaper) ShapeAdjust(tx rich.Text, tsty *text.Style, rts *rich.Settings, txt []rune) []shaped.Run { return sh.AdjustRuns(sh.ShapeText(tx, tsty, rts, txt), tx, tsty, rts) + // return sh.ShapeText(tx, tsty, rts, txt) } // AdjustRuns adjusts the given run metrics based on the html measureText results. @@ -98,6 +99,7 @@ func (sh *Shaper) WrapLines(tx rich.Text, defSty *rich.Style, tsty *text.Style, tsty.FontSize.Dots = 16 } + lht := sh.lineHeight(defSty, tsty, rts) // note: this overwrites output buffer so must do outs after! txt := tx.Join() outs := sh.ShapeTextOutput(tx, tsty, rts, txt) for oi := range outs { @@ -107,7 +109,7 @@ func (sh *Shaper) WrapLines(tx rich.Text, defSty *rich.Style, tsty *text.Style, fnt := text.NewFont(sty, tsty) sh.AdjustOutput(out, fnt, tx, tsty, rts) } - lns := sh.WrapLinesOutput(outs, txt, tx, defSty, tsty, rts, size) + lns := sh.WrapLinesOutput(outs, txt, tx, defSty, tsty, lht, rts, size) // todo: adjust again? return lns } @@ -116,12 +118,12 @@ func (sh *Shaper) WrapLines(tx rich.Text, defSty *rich.Style, tsty *text.Style, func (sh *Shaper) AdjustOutput(out *shaping.Output, fnt *text.Font, tx rich.Text, tsty *text.Style, rts *rich.Settings) { rng := textpos.Range{out.Runes.Offset, out.Runes.Offset + out.Runes.Count} si, sn, ri := tx.Index(rng.Start) - sty, stx := tx.Span(si) + _, stx := tx.Span(si) ri -= sn - fmt.Println(string(stx)) + // fmt.Println(string(stx)) rtx := stx[ri : ri+rng.Len()] SetFontStyle(ctx, fnt, tsty, 0) - fmt.Println("si:", si, ri, sty, string(rtx)) + // fmt.Println("si:", si, ri, sty, string(rtx)) spm := MeasureText(ctx, string(rtx)) msz := spm.FontBoundingBoxAscent + spm.FontBoundingBoxDescent