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