From 76bd2837d386facd89fa60b840ffb176c090d84c Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Fri, 20 Sep 2024 00:13:01 -0400 Subject: [PATCH] Add debug package --- debug/debug.go | 28 ++++++++++++++++++++++++++++ draw.go | 21 --------------------- examples/test/main.go | 3 ++- 3 files changed, 30 insertions(+), 22 deletions(-) create mode 100644 debug/debug.go diff --git a/debug/debug.go b/debug/debug.go new file mode 100644 index 0000000..e8d5134 --- /dev/null +++ b/debug/debug.go @@ -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) +} diff --git a/draw.go b/draw.go index af9706b..b95021c 100644 --- a/draw.go +++ b/draw.go @@ -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, diff --git a/examples/test/main.go b/examples/test/main.go index 0103c6d..ac50b27 100644 --- a/examples/test/main.go +++ b/examples/test/main.go @@ -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) }