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] Trailing spaces #164

Merged
merged 2 commits into from
May 5, 2024
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
5 changes: 3 additions & 2 deletions shaping/wrapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -838,12 +838,13 @@ func (l *LineWrapper) postProcessLine(finalLine Line, done bool) (WrappedLine, b
// zero trailing whitespace advance,
// to be coherent with Output.advanceSpaceAware
if L := len(finalRun.Glyphs); L != 0 {
g := &finalRun.Glyphs[L-1]
if finalRun.Direction.IsVertical() {
if g := &finalRun.Glyphs[L-1]; g.Height == 0 {
if g.Height == 0 {
g.YAdvance = 0
}
} else { // horizontal
if g := finalRun.Glyphs[L-1]; g.Width == 0 {
if g.Width == 0 {
g.XAdvance = 0
}
}
Expand Down
16 changes: 13 additions & 3 deletions shaping/wrapping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2196,7 +2196,7 @@ func TestTruncationWithBreaking(t *testing.T) {
BreakPolicy: tc.policy,
TruncateAfterLines: 1,
Truncator: truncator,
}, tc.width, inputText, NewSliceIterator([]Output{output}))
}, tc.width, inputText, NewSliceIterator([]Output{output.copy()}))
if truncated != tc.truncated {
t.Errorf("expected %d truncated runes, got %d (total %d)", tc.truncated, truncated, len(inputText))
}
Expand Down Expand Up @@ -2233,7 +2233,11 @@ func TestGraphemeBreakingRegression(t *testing.T) {
// Wrap at increasingly unreasonable widths, checking for sane wrapping decisions.
for maxWidth := maxWidth; maxWidth > 0; maxWidth-- {
t.Run(fmt.Sprintf("maxWidth=%d", maxWidth), func(t *testing.T) {
lines, truncated := wrapper.WrapParagraph(WrapConfig{BreakPolicy: Always}, maxWidth, bidiText2, NewSliceIterator(shaped))
runs := make([]Output, len(shaped))
for i, run := range shaped {
runs[i] = run.copy()
}
lines, truncated := wrapper.WrapParagraph(WrapConfig{BreakPolicy: Always}, maxWidth, bidiText2, NewSliceIterator(runs))
checkRuneCounts(t, bidiText2, lines, truncated)

for i, baseLine := range lines[:len(lines)-1] {
Expand Down Expand Up @@ -2642,6 +2646,12 @@ func TestGraphemeBreakLigature(t *testing.T) {
}
}

func (out Output) copy() Output {
copy := out
copy.Glyphs = append([]Glyph(nil), out.Glyphs...)
return copy
}

func TestLineWrapperBreakSpecific(t *testing.T) {
type expectation struct {
name string
Expand Down Expand Up @@ -2974,7 +2984,7 @@ func TestLineWrapperBreakSpecific(t *testing.T) {
for _, expec := range tc.expectations {
t.Run(expec.name, func(t *testing.T) {
expec.config.Truncator = shapedTrunc
lines, truncated := w.WrapParagraph(expec.config, tc.maxWidth, tc.paragraph, NewSliceIterator([]Output{out}))
lines, truncated := w.WrapParagraph(expec.config, tc.maxWidth, tc.paragraph, NewSliceIterator([]Output{out.copy()}))
actualCounts := checkRuneCounts(t, tc.paragraph, lines, truncated)
if truncated != expec.truncatedCount {
t.Errorf("expected %d truncated runes, got %d", expec.truncatedCount, truncated)
Expand Down