Skip to content

Commit

Permalink
[frame] Attempt at making chop more robust.
Browse files Browse the repository at this point in the history
Part of work on #30. Make chop immune to failure when attempting
to chop the very end of the box model.
  • Loading branch information
rjkroege committed Apr 21, 2018
1 parent a884301 commit 0a6d6c3
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions frame/insert.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,25 +98,23 @@ func (f *Frame) chop(pt image.Point, p, bn int) {
f.Logboxes(" -- chop, invalid bn=%d --\n", bn)
panic("chop bn too large")
}
for {
if bn >= len(f.box) {
f.Logboxes(" -- chop, invalid bn=%d inside of the loop --\n", bn)
panic("chop bn inside of loop is too large")
}
b := f.box[bn]
pt = f.cklinewrap(pt, b)
if bn >= len(f.box) || pt.Y >= f.Rect.Max.Y {
break

// better version
for i, bx := range f.box[bn:] {
pt = f.cklinewrap(pt, bx)
if pt.Y >= f.Rect.Max.Y {
f.nchars = p
f.nlines = f.maxlines
f.box = f.box[0:bn+i]
return
}
p += nrune(b)
pt = f.advance(pt, b)
bn++

p += nrune(bx)
pt = f.advance(pt, bx)
}

f.nchars = p
f.nlines = f.maxlines
if bn < len(f.box) { // BUG
f.delbox(bn, len(f.box)-1)
}
}

type points struct {
Expand Down

0 comments on commit 0a6d6c3

Please sign in to comment.