forked from joejulian/gio
text: use upstream bidi visual order algorithm
We've migrated the processing of bidi run ordering into the upstream typesetting package, so now we can just consume the already-ordered runs instead of computing their ordering ourselves. Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
This commit is contained in:
@@ -3,7 +3,6 @@ package text
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"testing"
|
||||
|
||||
@@ -450,120 +449,6 @@ func TestToLine(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestComputeVisualOrder(t *testing.T) {
|
||||
type testcase struct {
|
||||
name string
|
||||
input line
|
||||
expectedVisualOrder []int
|
||||
}
|
||||
for _, tc := range []testcase{
|
||||
{
|
||||
name: "ltr",
|
||||
input: line{
|
||||
direction: system.LTR,
|
||||
runs: []runLayout{
|
||||
{Direction: system.LTR},
|
||||
{Direction: system.LTR},
|
||||
{Direction: system.LTR},
|
||||
},
|
||||
},
|
||||
expectedVisualOrder: []int{0, 1, 2},
|
||||
},
|
||||
{
|
||||
name: "rtl",
|
||||
input: line{
|
||||
direction: system.RTL,
|
||||
runs: []runLayout{
|
||||
{Direction: system.RTL},
|
||||
{Direction: system.RTL},
|
||||
{Direction: system.RTL},
|
||||
},
|
||||
},
|
||||
expectedVisualOrder: []int{2, 1, 0},
|
||||
},
|
||||
{
|
||||
name: "bidi-ltr",
|
||||
input: line{
|
||||
direction: system.LTR,
|
||||
runs: []runLayout{
|
||||
{Direction: system.LTR},
|
||||
{Direction: system.RTL},
|
||||
{Direction: system.RTL},
|
||||
{Direction: system.RTL},
|
||||
{Direction: system.LTR},
|
||||
},
|
||||
},
|
||||
expectedVisualOrder: []int{0, 3, 2, 1, 4},
|
||||
},
|
||||
{
|
||||
name: "bidi-ltr-complex",
|
||||
input: line{
|
||||
direction: system.LTR,
|
||||
runs: []runLayout{
|
||||
{Direction: system.RTL},
|
||||
{Direction: system.RTL},
|
||||
{Direction: system.LTR},
|
||||
{Direction: system.RTL},
|
||||
{Direction: system.RTL},
|
||||
{Direction: system.LTR},
|
||||
{Direction: system.RTL},
|
||||
{Direction: system.RTL},
|
||||
{Direction: system.LTR},
|
||||
{Direction: system.RTL},
|
||||
{Direction: system.RTL},
|
||||
},
|
||||
},
|
||||
expectedVisualOrder: []int{1, 0, 2, 4, 3, 5, 7, 6, 8, 10, 9},
|
||||
},
|
||||
{
|
||||
name: "bidi-rtl",
|
||||
input: line{
|
||||
direction: system.RTL,
|
||||
runs: []runLayout{
|
||||
{Direction: system.RTL},
|
||||
{Direction: system.LTR},
|
||||
{Direction: system.LTR},
|
||||
{Direction: system.LTR},
|
||||
{Direction: system.RTL},
|
||||
},
|
||||
},
|
||||
expectedVisualOrder: []int{4, 1, 2, 3, 0},
|
||||
},
|
||||
{
|
||||
name: "bidi-rtl-complex",
|
||||
input: line{
|
||||
direction: system.RTL,
|
||||
runs: []runLayout{
|
||||
{Direction: system.LTR},
|
||||
{Direction: system.LTR},
|
||||
{Direction: system.RTL},
|
||||
{Direction: system.LTR},
|
||||
{Direction: system.LTR},
|
||||
{Direction: system.RTL},
|
||||
{Direction: system.LTR},
|
||||
{Direction: system.LTR},
|
||||
{Direction: system.RTL},
|
||||
{Direction: system.LTR},
|
||||
{Direction: system.LTR},
|
||||
},
|
||||
},
|
||||
expectedVisualOrder: []int{9, 10, 8, 6, 7, 5, 3, 4, 2, 0, 1},
|
||||
},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
computeVisualOrder(&tc.input)
|
||||
if !reflect.DeepEqual(tc.input.visualOrder, tc.expectedVisualOrder) {
|
||||
t.Errorf("expected visual order %v, got %v", tc.expectedVisualOrder, tc.input.visualOrder)
|
||||
}
|
||||
for i, visualIndex := range tc.input.visualOrder {
|
||||
if pos := tc.input.runs[visualIndex].VisualPosition; pos != i {
|
||||
t.Errorf("line.VisualOrder[%d]=%d, but line.Runs[%d].VisualPosition=%d", i, visualIndex, visualIndex, pos)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func FuzzLayout(f *testing.F) {
|
||||
ltrFace, _ := opentype.Parse(goregular.TTF)
|
||||
rtlFace, _ := opentype.Parse(nsareg.TTF)
|
||||
|
||||
Reference in New Issue
Block a user