Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[shaping] fix handling of Inherited script in Segmenter.Split #128

Merged
merged 1 commit into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions shaping/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ func (seg *Segmenter) splitByScript() {
// we register paired delimiters

delimIndex := -1
if rScript == language.Common {
if rScript == language.Common || rScript == language.Inherited {
delimIndex = lookupDelimIndex(r)
}

Expand Down Expand Up @@ -274,7 +274,7 @@ func (seg *Segmenter) splitByScript() {
}

// check if we have a 'real' change of script, or not
if rScript == language.Common || rScript == currentInput.Script {
if rScript == language.Common || rScript == language.Inherited || rScript == currentInput.Script {
// no change
continue
} else if currentInput.Script == language.Common {
Expand Down
20 changes: 20 additions & 0 deletions shaping/input_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ func TestSplitScript(t *testing.T) {
commonSource := []rune("()[](][ gamma") // Common at first
commonSource2 := []rune("gamma (Γ) est une lettre")
commonSource3 := []rune("gamma (Γ [п] Γ) est une lettre") // nested delimiters
withInherited := []rune("لمّا")
type run struct {
start, end int
script language.Script
Expand Down Expand Up @@ -358,6 +359,9 @@ func TestSplitScript(t *testing.T) {
{11, 14, language.Greek},
{14, 30, language.Latin},
}},
{withInherited, []run{
{0, 4, language.Arabic},
}},
} {
var seg Segmenter
seg.splitByBidi(Input{Text: test.text, RunEnd: len(test.text), Direction: di.DirectionLTR}) // fills buffer1
Expand Down Expand Up @@ -472,3 +476,19 @@ func TestSplit(t *testing.T) {
}
}
}

func TestIssue127(t *testing.T) {
// regression test for https://github.com/go-text/typesetting/issues/127
str := []rune("لمّا")
input := Input{
Text: str,
RunStart: 0,
RunEnd: len(str),
Direction: di.DirectionRTL,
Language: language.NewLanguage("ar"),
}

inputs := (&Segmenter{}).Split(input, fixedFontmap{benchArFace})
// make sure Inherited script does no create a new run
tu.Assert(t, len(inputs) == 1)
}
Loading