Create another For iterator that leaves out the fake null rune
Apparently it was intended behavior. Closes #4
This commit is contained in:
parent
021dd288b6
commit
6a60458484
10
drawer.go
10
drawer.go
@ -13,20 +13,20 @@ type Drawer struct { TypeSetter }
|
||||
// Draw draws the drawer's text onto the specified canvas at the given offset.
|
||||
func (drawer Drawer) Draw (
|
||||
destination draw.Image,
|
||||
color color.Color,
|
||||
col color.Color,
|
||||
offset image.Point,
|
||||
) (
|
||||
updatedRegion image.Rectangle,
|
||||
) {
|
||||
source := image.NewUniform(color)
|
||||
source := image.NewUniform(col)
|
||||
|
||||
drawer.For (func (
|
||||
drawer.ForRunes (func (
|
||||
index int,
|
||||
char rune,
|
||||
position fixed.Point26_6,
|
||||
) bool {
|
||||
// leave empty space for space characters
|
||||
if unicode.IsSpace(char){
|
||||
if unicode.IsSpace(char) {
|
||||
return true
|
||||
}
|
||||
|
||||
@ -37,7 +37,7 @@ func (drawer Drawer) Draw (
|
||||
mask, maskPoint, _, ok := drawer.face.Glyph(dot, char)
|
||||
// tofu
|
||||
if !ok {
|
||||
drawer.drawTofu(char, destination, color, dot)
|
||||
drawer.drawTofu(char, destination, col, dot)
|
||||
return true
|
||||
}
|
||||
|
||||
|
30
setter.go
30
setter.go
@ -259,8 +259,18 @@ type RuneIterator func (
|
||||
)
|
||||
|
||||
// For calls the specified iterator for every rune in the typesetter. If the
|
||||
// iterator returns false, the loop will immediately stop.
|
||||
// iterator returns false, the loop will immediately stop. This method will
|
||||
// insert a fake null rune at the end.
|
||||
func (setter *TypeSetter) For (iterator RuneIterator) {
|
||||
setter.forInternal(iterator, true)
|
||||
}
|
||||
|
||||
// ForRunes is like For, but leaves out the fake null rune.
|
||||
func (setter *TypeSetter) ForRunes (iterator RuneIterator) {
|
||||
setter.forInternal(iterator, false)
|
||||
}
|
||||
|
||||
func (setter *TypeSetter) forInternal (iterator RuneIterator, fakeNull bool) {
|
||||
setter.needAlignedLayout()
|
||||
|
||||
index := 0
|
||||
@ -271,7 +281,7 @@ func (setter *TypeSetter) For (iterator RuneIterator) {
|
||||
for _, word := range line.Words {
|
||||
for _, char := range word.Runes {
|
||||
lastCharRightBound = word.X + char.X + char.Width
|
||||
keepGoing := iterator (index, char.Rune, fixed.Point26_6 {
|
||||
keepGoing := iterator(index, char.Rune, fixed.Point26_6 {
|
||||
X: word.X + char.X,
|
||||
Y: line.Y,
|
||||
})
|
||||
@ -280,7 +290,7 @@ func (setter *TypeSetter) For (iterator RuneIterator) {
|
||||
}}
|
||||
|
||||
if line.BreakAfter {
|
||||
keepGoing := iterator (index, '\n', fixed.Point26_6 {
|
||||
keepGoing := iterator(index, '\n', fixed.Point26_6 {
|
||||
X: lastCharRightBound,
|
||||
Y: line.Y,
|
||||
})
|
||||
@ -289,12 +299,14 @@ func (setter *TypeSetter) For (iterator RuneIterator) {
|
||||
}
|
||||
}
|
||||
|
||||
keepGoing := iterator (index, '\000', fixed.Point26_6 {
|
||||
X: lastCharRightBound,
|
||||
Y: lastLineY,
|
||||
})
|
||||
if !keepGoing { return }
|
||||
index ++
|
||||
if fakeNull {
|
||||
keepGoing := iterator (index, '\000', fixed.Point26_6 {
|
||||
X: lastCharRightBound,
|
||||
Y: lastLineY,
|
||||
})
|
||||
if !keepGoing { return }
|
||||
index ++
|
||||
}
|
||||
}
|
||||
|
||||
// AtPosition returns the index of the rune at the specified position.
|
||||
|
Loading…
Reference in New Issue
Block a user