Add debug package

This commit is contained in:
Sasha Koshka 2024-09-20 00:13:01 -04:00
parent de12ee6bcd
commit 76bd2837d3
3 changed files with 30 additions and 22 deletions

28
debug/debug.go Normal file
View File

@ -0,0 +1,28 @@
package debug
import "image/draw"
import "image/color"
import "golang.org/x/image/math/fixed"
import "git.tebibyte.media/tomo/typeset"
import "git.tebibyte.media/tomo/typeset/internal"
// DrawBounds draws the LayoutBounds, MinimumSize, and LayoutBoundsSpace of a
// TypeSetter to the given image using these colors:
// - Red: LayoutBounds
// - Green: MinimumSize
// - Blue: LayoutBoundsSpace
func DrawBounds (destination draw.Image, setter *typeset.TypeSetter, offset fixed.Point26_6) {
blue := color.RGBA { B: 255, A: 255 }
red := color.RGBA { R: 255, A: 255 }
green := color.RGBA { G: 255, A: 255 }
layoutBoundsSpace := setter.LayoutBoundsSpace()
layoutBounds := setter.LayoutBounds()
minimum := setter.MinimumSize()
minimumRect := internal.RoundRect(fixed.Rectangle26_6 { Max: minimum }.Add(offset).Add(layoutBounds.Min))
internal.DrawRectangleOutline(destination, minimumRect, green)
internal.DrawRectangleOutline(destination, internal.RoundRect(layoutBoundsSpace.Add(offset)), blue)
internal.DrawRectangleOutline(destination, internal.RoundRect(layoutBounds.Add(offset)), red)
}

21
draw.go
View File

@ -50,27 +50,6 @@ func Draw (destination draw.Image, setter *TypeSetter, offset fixed.Point26_6, c
return updatedRegion
}
// DrawBounds draws the LayoutBounds, MinimumSize, and LayoutBoundsSpace of a
// TypeSetter to the given image using these colors:
// - Red: LayoutBounds
// - Green: MinimumSize
// - Blue: LayoutBoundsSpace
func DrawBounds (destination draw.Image, setter *TypeSetter, offset fixed.Point26_6) {
blue := color.RGBA { B: 255, A: 255 }
red := color.RGBA { R: 255, A: 255 }
green := color.RGBA { G: 255, A: 255 }
layoutBoundsSpace := setter.LayoutBoundsSpace()
layoutBounds := setter.LayoutBounds()
minimum := setter.MinimumSize()
minimumRect := internal.RoundRect(fixed.Rectangle26_6 { Max: minimum }.Add(offset).Add(layoutBounds.Min))
internal.DrawRectangleOutline(destination, minimumRect, green)
internal.DrawRectangleOutline(destination, internal.RoundRect(layoutBoundsSpace.Add(offset)), blue)
internal.DrawRectangleOutline(destination, internal.RoundRect(layoutBounds.Add(offset)), red)
}
func drawTofu (
char rune,
destination draw.Image,

View File

@ -9,6 +9,7 @@ import "image/color"
import "golang.org/x/image/math/fixed"
import "git.tebibyte.media/tomo/typeset"
import "golang.org/x/image/font/basicfont"
import "git.tebibyte.media/tomo/typeset/debug"
func main () {
img := image.NewRGBA(image.Rect(0, 0, 2048, 1024))
@ -122,7 +123,7 @@ func drawText (destination subDrawImage, setter *typeset.TypeSetter, bounds imag
Y: metrics.Ascent + fixed.I(bounds.Min.Y),
}
// typeset.Draw(destination, setter, offset, color.Black)
typeset.DrawBounds(subImage, setter, offset)
debug.DrawBounds(subImage, setter, offset)
typeset.Draw(subImage, setter, offset, color.Black)
}