text/v2: refactoring

This commit is contained in:
Hajime Hoshi 2024-10-27 18:39:10 +09:00
parent d0db7e1b60
commit 17c2b1b325

View File

@ -17,6 +17,7 @@ package text
import (
"bytes"
"io"
"slices"
"sync"
"github.com/go-text/typesetting/font"
@ -198,11 +199,9 @@ func (g *GoTextFaceSource) shape(text string, face *GoTextFace) ([]shaping.Outpu
var seg shaping.Segmenter
inputs := seg.Split(input, &singleFontmap{face: f})
if face.Direction == DirectionRightToLeft {
// Reverse the input for RTL texts.
for i, j := 0, len(inputs)-1; i < j; i, j = i+1, j-1 {
inputs[i], inputs[j] = inputs[j], inputs[i]
}
if face.Direction == DirectionRightToLeft {
slices.Reverse(inputs)
}
outputs := make([]shaping.Output, len(inputs))