Slimmed down imports

This commit is contained in:
Sasha Koshka 2023-05-03 17:36:14 -04:00
parent 83d0b32fba
commit 794ab1b5e8
5 changed files with 4 additions and 311 deletions

View File

@ -11,7 +11,6 @@ import "git.tebibyte.media/sashakoshka/tomo/textdraw"
import "git.tebibyte.media/sashakoshka/tomo/artist/shapes" import "git.tebibyte.media/sashakoshka/tomo/artist/shapes"
import "git.tebibyte.media/sashakoshka/tomo/artist/artutil" import "git.tebibyte.media/sashakoshka/tomo/artist/artutil"
import "git.tebibyte.media/sashakoshka/tomo/artist/patterns" import "git.tebibyte.media/sashakoshka/tomo/artist/patterns"
import defaultfont "git.tebibyte.media/sashakoshka/tomo/default/font"
// Artist is an element that displays shapes and patterns drawn by the artist // Artist is an element that displays shapes and patterns drawn by the artist
// package in order to test it. // package in order to test it.
@ -140,7 +139,10 @@ func (element *Artist) Draw (destination artist.Canvas) {
// how long did that take to render? // how long did that take to render?
drawTime := time.Since(drawStart) drawTime := time.Since(drawStart)
textDrawer := textdraw.Drawer { } textDrawer := textdraw.Drawer { }
textDrawer.SetFace(defaultfont.FaceRegular) textDrawer.SetFace(element.entity.Theme().FontFace (
tomo.FontStyleRegular,
tomo.FontSizeNormal,
tomo.C("tomo", "artist")))
textDrawer.SetText ([]rune (fmt.Sprintf ( textDrawer.SetText ([]rune (fmt.Sprintf (
"%dms\n%dus", "%dms\n%dus",
drawTime.Milliseconds(), drawTime.Milliseconds(),

9
go.mod
View File

@ -4,19 +4,10 @@ go 1.19
require ( require (
git.tebibyte.media/sashakoshka/ezprof v0.0.0-20230309044548-401cba83602b git.tebibyte.media/sashakoshka/ezprof v0.0.0-20230309044548-401cba83602b
github.com/faiface/beep v1.1.0
github.com/jezek/xgbutil v0.0.0-20230403164920-e2f86723ca07 github.com/jezek/xgbutil v0.0.0-20230403164920-e2f86723ca07
golang.org/x/image v0.7.0 golang.org/x/image v0.7.0
) )
require (
github.com/hajimehoshi/oto v0.7.1 // indirect
github.com/pkg/errors v0.9.1 // indirect
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8 // indirect
golang.org/x/mobile v0.0.0-20190415191353-3e0bab5405d6 // indirect
golang.org/x/sys v0.5.0 // indirect
)
require ( require (
github.com/BurntSushi/freetype-go v0.0.0-20160129220410-b763ddbfe298 // indirect github.com/BurntSushi/freetype-go v0.0.0-20160129220410-b763ddbfe298 // indirect
github.com/BurntSushi/graphics-go v0.0.0-20160129215708-b43f31a4a966 // indirect github.com/BurntSushi/graphics-go v0.0.0-20160129215708-b43f31a4a966 // indirect

41
go.sum
View File

@ -4,52 +4,17 @@ github.com/BurntSushi/freetype-go v0.0.0-20160129220410-b763ddbfe298 h1:1qlsVAQJ
github.com/BurntSushi/freetype-go v0.0.0-20160129220410-b763ddbfe298/go.mod h1:D+QujdIlUNfa0igpNMk6UIvlb6C252URs4yupRUV4lQ= github.com/BurntSushi/freetype-go v0.0.0-20160129220410-b763ddbfe298/go.mod h1:D+QujdIlUNfa0igpNMk6UIvlb6C252URs4yupRUV4lQ=
github.com/BurntSushi/graphics-go v0.0.0-20160129215708-b43f31a4a966 h1:lTG4HQym5oPKjL7nGs+csTgiDna685ZXjxijkne828g= github.com/BurntSushi/graphics-go v0.0.0-20160129215708-b43f31a4a966 h1:lTG4HQym5oPKjL7nGs+csTgiDna685ZXjxijkne828g=
github.com/BurntSushi/graphics-go v0.0.0-20160129215708-b43f31a4a966/go.mod h1:Mid70uvE93zn9wgF92A/r5ixgnvX8Lh68fxp9KQBaI0= github.com/BurntSushi/graphics-go v0.0.0-20160129215708-b43f31a4a966/go.mod h1:Mid70uvE93zn9wgF92A/r5ixgnvX8Lh68fxp9KQBaI0=
github.com/DATA-DOG/go-sqlmock v1.3.3/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
github.com/d4l3k/messagediff v1.2.2-0.20190829033028-7e0a312ae40b/go.mod h1:Oozbb1TVXFac9FtSIxHBMnBCq2qeH/2KkEQxENCrlLo=
github.com/faiface/beep v1.1.0 h1:A2gWP6xf5Rh7RG/p9/VAW2jRSDEGQm5sbOb38sf5d4c=
github.com/faiface/beep v1.1.0/go.mod h1:6I8p6kK2q4opL/eWb+kAkk38ehnTunWeToJB+s51sT4=
github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg=
github.com/gdamore/tcell v1.3.0/go.mod h1:Hjvr+Ofd+gLglo7RYKxxnzCBmev3BzsS67MebKS4zMM=
github.com/go-audio/audio v1.0.0/go.mod h1:6uAu0+H2lHkwdGsAY+j2wHPNPpPoeg5AaEFh9FlA+Zs=
github.com/go-audio/riff v1.0.0/go.mod h1:l3cQwc85y79NQFCRB7TiPoNiaijp6q8Z0Uv38rVG498=
github.com/go-audio/wav v1.0.0/go.mod h1:3yoReyQOsiARkvPl3ERCi8JFjihzG6WhjYpZCf5zAWE=
github.com/hajimehoshi/go-mp3 v0.3.0/go.mod h1:qMJj/CSDxx6CGHiZeCgbiq2DSUkbK0UbtXShQcnfyMM=
github.com/hajimehoshi/oto v0.6.1/go.mod h1:0QXGEkbuJRohbJaxr7ZQSxnju7hEhseiPx2hrh6raOI=
github.com/hajimehoshi/oto v0.7.1 h1:I7maFPz5MBCwiutOrz++DLdbr4rTzBsbBuV2VpgU9kk=
github.com/hajimehoshi/oto v0.7.1/go.mod h1:wovJ8WWMfFKvP587mhHgot/MBr4DnNy9m6EepeVGnos=
github.com/icza/bitio v1.0.0/go.mod h1:0jGnlLAx8MKMr9VGnn/4YrvZiprkvBelsVIbA9Jjr9A=
github.com/icza/mighty v0.0.0-20180919140131-cfd07d671de6/go.mod h1:xQig96I1VNBDIWGCdTt54nHt6EeI639SmHycLYL7FkA=
github.com/jezek/xgb v1.1.0 h1:wnpxJzP1+rkbGclEkmwpVFQWpuE2PUGNUzP8SbfFobk= github.com/jezek/xgb v1.1.0 h1:wnpxJzP1+rkbGclEkmwpVFQWpuE2PUGNUzP8SbfFobk=
github.com/jezek/xgb v1.1.0/go.mod h1:nrhwO0FX/enq75I7Y7G8iN1ubpSGZEiA3v9e9GyRFlk= github.com/jezek/xgb v1.1.0/go.mod h1:nrhwO0FX/enq75I7Y7G8iN1ubpSGZEiA3v9e9GyRFlk=
github.com/jezek/xgbutil v0.0.0-20210302171758-530099784e66 h1:+wPhoJD8EH0/bXipIq8Lc2z477jfox9zkXPCJdhvHj8=
github.com/jezek/xgbutil v0.0.0-20210302171758-530099784e66/go.mod h1:KACeV+k6b+aoLTVrrurywEbu3UpqoQcQywj4qX8aQKM=
github.com/jezek/xgbutil v0.0.0-20230403164920-e2f86723ca07 h1:Fr2Oaa4N2oo30/PGecdDkkrth26nD2/yfQFAoddzXmU= github.com/jezek/xgbutil v0.0.0-20230403164920-e2f86723ca07 h1:Fr2Oaa4N2oo30/PGecdDkkrth26nD2/yfQFAoddzXmU=
github.com/jezek/xgbutil v0.0.0-20230403164920-e2f86723ca07/go.mod h1:AHecLyFNy6AN9f/+0AH/h1MI7X1+JL5bmCz4XlVZk7Y= github.com/jezek/xgbutil v0.0.0-20230403164920-e2f86723ca07/go.mod h1:AHecLyFNy6AN9f/+0AH/h1MI7X1+JL5bmCz4XlVZk7Y=
github.com/jfreymuth/oggvorbis v1.0.1/go.mod h1:NqS+K+UXKje0FUYUPosyQ+XTVvjmVjps1aEZH1sumIk=
github.com/jfreymuth/vorbis v1.0.0/go.mod h1:8zy3lUAm9K/rJJk223RKy6vjCZTWC61NA2QD06bfOE0=
github.com/lucasb-eyer/go-colorful v1.0.2/go.mod h1:0MS4r+7BZKSJ5mw4/S5MPN+qHFF1fYclkSPilDOKW0s=
github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
github.com/mewkiz/flac v1.0.7/go.mod h1:yU74UH277dBUpqxPouHSQIar3G1X/QIclVbFahSd1pU=
github.com/mewkiz/pkg v0.0.0-20190919212034-518ade7978e2/go.mod h1:3E2FUC/qYUfM8+r9zAwpeHJzqRVVMIYnpzD/clwWxyA=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8 h1:idBdZTd9UioThJp8KpM/rTSinK/ChZFBE43/WtIy8zg=
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/image v0.0.0-20190220214146-31aff87c08e9/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.3.0 h1:HTDXbdK9bjfSWkPzDJIw89W8CAtfFGduujWs33NLLsg=
golang.org/x/image v0.3.0/go.mod h1:fXd9211C/0VTlYuAcOhW8dY/RtEJqODXOWBDpmYBf+A=
golang.org/x/image v0.7.0 h1:gzS29xtG1J5ybQlv0PuyfE3nmc6R4qB73m6LUUmvFuw= golang.org/x/image v0.7.0 h1:gzS29xtG1J5ybQlv0PuyfE3nmc6R4qB73m6LUUmvFuw=
golang.org/x/image v0.7.0/go.mod h1:nd/q4ef1AKKYl/4kft7g+6UyGbdiqWqTP1ZAbRoV7Rg= golang.org/x/image v0.7.0/go.mod h1:nd/q4ef1AKKYl/4kft7g+6UyGbdiqWqTP1ZAbRoV7Rg=
golang.org/x/mobile v0.0.0-20190415191353-3e0bab5405d6 h1:vyLBGJPIl9ZYbcQFM2USFmJBK6KI+t+z6jL0lbwjrnc=
golang.org/x/mobile v0.0.0-20190415191353-3e0bab5405d6/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
@ -58,15 +23,10 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190429190828-d89cdac9e872/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190626150813-e07cf5db2756/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f h1:v4INt8xihDGvnrfjMDVXGxw9wrfxYyCjk0KbXjhR55s=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
@ -74,7 +34,6 @@ golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.6.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=

View File

@ -1,111 +0,0 @@
package textdraw
import "testing"
import "golang.org/x/image/math/fixed"
import defaultfont "git.tebibyte.media/sashakoshka/tomo/default/font"
func TestDoWord (test *testing.T) {
text := []rune("The quick brown fox")
word, remaining := DoWord(text, defaultfont.FaceRegular)
expect := "quick brown fox"
if string(remaining) != expect {
test.Fatalf (
`text: "%s", remaining: "%s" expected: "%s"`,
string(text), string(remaining), expect)
}
if len(word.Runes) != 4 {
test.Fatalf(`wrong rune length %d`, len(word.Runes))
}
if word.SpaceAfter != fixed.I(7) {
test.Fatalf(`wrong space after %d`, word.SpaceAfter.Round())
}
if word.FirstRune() != 'T' {
test.Fatalf(`wrong first rune %s`, string(word.FirstRune()))
}
if word.LastRune() != ' ' {
test.Fatalf(`wrong last rune %s`, string(word.FirstRune()))
}
}
func TestDoLine (test *testing.T) {
// case 1
text := []rune("The quick brown fox\njumped over the lazy dog")
line, remaining := DoLine(text, defaultfont.FaceRegular, 0)
expect := "jumped over the lazy dog"
if string(remaining) != expect {
test.Fatalf (
`text: "%s", remaining: "%s" expected: "%s"`,
string(text), string(remaining), expect)
}
if len(line.Words) != 4 {
test.Fatalf(`wrong word count %d`, len(line.Words))
}
if !line.BreakAfter {
test.Fatalf(`did not set BreakAfter to true`)
}
// case 2
text = []rune("jumped over the lazy dog")
line, remaining = DoLine(text, defaultfont.FaceRegular, 0)
expect = ""
if string(remaining) != expect {
test.Fatalf (
`text: "%s", remaining: "%s" expected: "%s"`,
string(text), string(remaining), expect)
}
if len(line.Words) != 5 {
test.Fatalf(`wrong word count %d`, len(line.Words))
}
if line.BreakAfter {
test.Fatalf(`did not set BreakAfter to false`)
}
// case 3
text = []rune("jumped over the lazy dog")
line, remaining = DoLine(text, defaultfont.FaceRegular, fixed.I(7 * 12))
expect = "the lazy dog"
if string(remaining) != expect {
test.Fatalf (
`text: "%s", remaining: "%s" expected: "%s"`,
string(text), string(remaining), expect)
}
if len(line.Words) != 2 {
test.Fatalf(`wrong word count %d`, len(line.Words))
}
if line.BreakAfter {
test.Fatalf(`did not set BreakAfter to false`)
}
// case 4
text = []rune("jumped over the lazy dog")
line, remaining = DoLine(text, defaultfont.FaceRegular, fixed.I(10))
expect = "over the lazy dog"
if string(remaining) != expect {
test.Fatalf (
`text: "%s", remaining: "%s" expected: "%s"`,
string(text), string(remaining), expect)
}
if len(line.Words) != 1 {
test.Fatalf(`wrong word count %d`, len(line.Words))
}
if line.BreakAfter {
test.Fatalf(`did not set BreakAfter to false`)
}
}

View File

@ -1,148 +0,0 @@
package textdraw
import "image"
import "testing"
import "golang.org/x/image/math/fixed"
import "git.tebibyte.media/sashakoshka/tomo/fixedutil"
import defaultfont "git.tebibyte.media/sashakoshka/tomo/default/font"
func TestSetterLength (test *testing.T) {
// case 1
text := []rune("The quick brown fox\njumped over the lazy dog.")
setter := TypeSetter { }
setter.SetText(text)
setter.SetFace(defaultfont.FaceRegular)
length := 0
setter.For (func (i int, r rune, p fixed.Point26_6) bool {
length ++
return true
})
if length != len(text) {
test.Fatalf (
`setter rune count: %d, expected: %d`,
length, len(text))
}
// case 2
setter.SetMaxWidth(10)
length = 0
setter.For (func (i int, r rune, p fixed.Point26_6) bool {
length ++
return true
})
if length != len(text) {
test.Fatalf (
`setter rune count: %d, expected: %d`,
length, len(text))
}
}
func TestSetterBounds (test *testing.T) {
setter := TypeSetter { }
setter.SetText([]rune("The quick brown fox\njumped over the lazy dog."))
setter.SetFace(defaultfont.FaceRegular)
bounds := setter.LayoutBounds()
expectDy := 13 * 2
if expectDy != bounds.Dy() {
test.Fatalf (
`setter bounds Dy: %d, expected: %d`,
bounds.Dy(), expectDy)
}
expectDx := 7 * 25
if expectDx != bounds.Dx() {
test.Fatalf (
`setter bounds Dx: %d, expected: %d`,
bounds.Dx(), expectDx)
}
testLargeRecHeight(test, 256)
testLargeRecHeight(test, 100)
testLargeRecHeight(test, 20)
testLargeRecHeight(test, 400)
}
func testLargeRecHeight (test *testing.T, width int) {
setter := TypeSetter { }
setter.SetText([]rune(lipsum))
setter.SetFace(defaultfont.FaceRegular)
setter.SetMaxWidth(width)
recHeight := setter.ReccomendedHeightFor(width)
bounds := setter.LayoutBounds()
if recHeight != bounds.Dy() {
test.Fatalf (
`setter bounds mismatch rec. height: %d, Dy: %d ` +
`for width: %d`,
recHeight, bounds.Dy(), width)
}
}
func TestSetterPosition (test *testing.T) {
setter := TypeSetter { }
setter.SetText([]rune("The quick brown fox\njumped over the lazy dog."))
setter.SetFace(defaultfont.FaceRegular)
index := 20
pos := fixedutil.RoundPt(setter.PositionAt(index))
expect := image.Pt(0, 13)
if pos != expect {
test.Fatalf (
`setter pos at %d: (%d, %d), expected: (%d, %d)`,
index, pos.X, pos.Y, expect.X, expect.Y)
}
}
func TestSetterIndex (test *testing.T) {
setter := TypeSetter { }
setter.SetText([]rune("The quick brown fox\njumped over the lazy dog."))
setter.SetFace(defaultfont.FaceRegular)
pos := fixed.P(3, 8)
index := setter.AtPosition(pos)
expect := 20
if index != expect {
test.Fatalf (
`setter index at (%d, %d): %d, expected: %d`,
pos.X.Round(), pos.Y.Round(), index, expect)
}
pos = fixed.P(-59, 230)
index = setter.AtPosition(pos)
expect = 20
if index != expect {
test.Fatalf (
`setter index at (%d, %d): %d, expected: %d`,
pos.X.Round(), pos.Y.Round(), index, expect)
}
pos = fixed.P(-500, -500)
index = setter.AtPosition(pos)
expect = 0
if index != expect {
test.Fatalf (
`setter index at (%d, %d): %d, expected: %d`,
pos.X.Round(), pos.Y.Round(), index, expect)
}
pos = fixed.P(500, -500)
index = setter.AtPosition(pos)
expect = 19
if index != expect {
test.Fatalf (
`setter index at (%d, %d): %d, expected: %d`,
pos.X.Round(), pos.Y.Round(), index, expect)
}
pos = fixed.P(500, 500)
index = setter.AtPosition(pos)
expect = setter.Length()
if index != expect {
test.Fatalf (
`setter index at (%d, %d): %d, expected: %d`,
pos.X.Round(), pos.Y.Round(), index, expect)
}
}
const lipsum = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Fermentum et sollicitudin ac orci phasellus egestas tellus rutrum. Aliquam vestibulum morbi blandit cursus risus at ultrices mi. Gravida dictum fusce ut placerat. Cursus metus aliquam eleifend mi in nulla posuere. Sit amet nulla facilisi morbi tempus iaculis urna id. Amet volutpat consequat mauris nunc congue nisi vitae. Varius duis at consectetur lorem donec massa sapien faucibus et. Vitae elementum curabitur vitae nunc sed velit dignissim. In hac habitasse platea dictumst quisque sagittis purus. Enim nulla aliquet porttitor lacus luctus accumsan tortor. Lectus magna fringilla urna porttitor rhoncus dolor purus non.\n\nNon pulvinar neque laoreet suspendisse. Viverra adipiscing at in tellus integer. Vulputate dignissim suspendisse in est ante. Purus in mollis nunc sed id semper. In est ante in nibh mauris cursus. Risus pretium quam vulputate dignissim suspendisse in est. Blandit aliquam etiam erat velit scelerisque in dictum. Lectus quam id leo in. Odio tempor orci dapibus ultrices in iaculis. Pharetra sit amet aliquam id. Elit ut aliquam purus sit. Egestas dui id ornare arcu odio ut sem nulla pharetra. Massa tempor nec feugiat nisl pretium fusce id. Dui accumsan sit amet nulla facilisi morbi. A lacus vestibulum sed arcu non odio euismod. Nam libero justo laoreet sit amet cursus. Mattis rhoncus urna neque viverra justo nec. Mauris augue neque gravida in fermentum et sollicitudin ac. Vulputate mi sit amet mauris. Ut sem nulla pharetra diam sit amet."