Use lightningvolt.ttf for coordinates
This commit is contained in:
parent
da5f67df46
commit
e7498352b8
|
@ -12,6 +12,7 @@ import (
|
||||||
|
|
||||||
"golang.org/x/image/font"
|
"golang.org/x/image/font"
|
||||||
"golang.org/x/image/font/basicfont"
|
"golang.org/x/image/font/basicfont"
|
||||||
|
"golang.org/x/image/font/opentype"
|
||||||
"golang.org/x/image/math/fixed"
|
"golang.org/x/image/math/fixed"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -197,11 +198,17 @@ func drawCoordinate(img *image.RGBA, x, y int, flipped bool) {
|
||||||
} else if !flipped {
|
} else if !flipped {
|
||||||
color = Light
|
color = Light
|
||||||
}
|
}
|
||||||
// TODO: use SN font and make it bold
|
|
||||||
|
face, err := loadFontFace("lightningvolt.ttf")
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("error loading font: %v\n", err)
|
||||||
|
face = basicfont.Face7x13
|
||||||
|
}
|
||||||
|
|
||||||
d := &font.Drawer{
|
d := &font.Drawer{
|
||||||
Dst: img,
|
Dst: img,
|
||||||
Src: image.NewUniform(color),
|
Src: image.NewUniform(color),
|
||||||
Face: basicfont.Face7x13,
|
Face: face,
|
||||||
Dot: origin,
|
Dot: origin,
|
||||||
}
|
}
|
||||||
d.DrawString(s)
|
d.DrawString(s)
|
||||||
|
@ -214,11 +221,36 @@ func drawCoordinate(img *image.RGBA, x, y int, flipped bool) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if row != "" {
|
if row != "" {
|
||||||
origin = fixed.P((x+1)*128-12, y*128+15)
|
origin = fixed.P((x+1)*128-20, y*128+23)
|
||||||
drawString(row, origin)
|
drawString(row, origin)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func loadFontFace(path string) (font.Face, error) {
|
||||||
|
fontBytes, err := os.ReadFile(path)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
ttfFont, err := opentype.Parse(fontBytes)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
faceOptions := &opentype.FaceOptions{
|
||||||
|
Size: 32,
|
||||||
|
DPI: 72,
|
||||||
|
Hinting: font.HintingNone,
|
||||||
|
}
|
||||||
|
|
||||||
|
fontFace, err := opentype.NewFace(ttfFont, faceOptions)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return fontFace, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (b *Board) SetPiece(name PieceName, color Color, position string) error {
|
func (b *Board) SetPiece(name PieceName, color Color, position string) error {
|
||||||
var (
|
var (
|
||||||
piece *Piece
|
piece *Piece
|
||||||
|
|
1
go.mod
1
go.mod
|
@ -12,6 +12,7 @@ require (
|
||||||
require (
|
require (
|
||||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||||
|
golang.org/x/text v0.18.0 // indirect
|
||||||
gopkg.in/guregu/null.v4 v4.0.0 // indirect
|
gopkg.in/guregu/null.v4 v4.0.0 // indirect
|
||||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
)
|
)
|
||||||
|
|
2
go.sum
2
go.sum
|
@ -10,6 +10,8 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT
|
||||||
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||||
golang.org/x/image v0.20.0 h1:7cVCUjQwfL18gyBJOmYvptfSHS8Fb3YUDtfLIZ7Nbpw=
|
golang.org/x/image v0.20.0 h1:7cVCUjQwfL18gyBJOmYvptfSHS8Fb3YUDtfLIZ7Nbpw=
|
||||||
golang.org/x/image v0.20.0/go.mod h1:0a88To4CYVBAHp5FXJm8o7QbUl37Vd85ply1vyD8auM=
|
golang.org/x/image v0.20.0/go.mod h1:0a88To4CYVBAHp5FXJm8o7QbUl37Vd85ply1vyD8auM=
|
||||||
|
golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224=
|
||||||
|
golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/guregu/null.v4 v4.0.0 h1:1Wm3S1WEA2I26Kq+6vcW+w0gcDo44YKYD7YIEJNHDjg=
|
gopkg.in/guregu/null.v4 v4.0.0 h1:1Wm3S1WEA2I26Kq+6vcW+w0gcDo44YKYD7YIEJNHDjg=
|
||||||
|
|
Binary file not shown.
Loading…
Reference in New Issue