2024-01-13 18:17:34 +03:00
|
|
|
package gg
|
|
|
|
|
|
|
|
import (
|
|
|
|
//"strings"
|
|
|
|
"golang.org/x/image/font"
|
|
|
|
"golang.org/x/image/font/opentype"
|
|
|
|
"github.com/hajimehoshi/ebiten/v2/text"
|
|
|
|
"github.com/hajimehoshi/ebiten/v2"
|
|
|
|
"io"
|
|
|
|
//"fmt"
|
|
|
|
)
|
|
|
|
|
|
|
|
//type FontOptions = font.Options
|
|
|
|
var (
|
|
|
|
FontHintingNone = font.HintingNone
|
|
|
|
)
|
|
|
|
|
|
|
|
type Face = font.Face
|
|
|
|
|
|
|
|
type TtfFont = opentype.Font
|
|
|
|
type TtfFaceOptions = opentype.FaceOptions
|
|
|
|
type TtfFace = opentype.Face
|
|
|
|
|
|
|
|
func MakeFaceFromTtf(src io.ReaderAt, opts *TtfFaceOptions) (Face, error) {
|
|
|
|
fnt, err := ParseTtfFont(src)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
face, err := NewTtfFace(fnt, opts)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return face, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func ParseTtfFont(src io.ReaderAt) (*TtfFont, error) {
|
|
|
|
return opentype.ParseReaderAt(src)
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewTtfFace(fnt *TtfFont, opts *TtfFaceOptions) (Face, error) {
|
|
|
|
return opentype.NewFace(fnt, opts)
|
|
|
|
}
|
|
|
|
|
|
|
|
// The type implements basic drawable text.
|
|
|
|
// (Now needs to implement rotation, scaling etc, cause now only position)
|
|
|
|
type Text struct {
|
|
|
|
Object
|
|
|
|
Transform
|
2024-01-14 03:51:11 +03:00
|
|
|
Data string
|
2024-01-13 18:17:34 +03:00
|
|
|
Face Face
|
|
|
|
Colority
|
|
|
|
Visibility
|
|
|
|
}
|
|
|
|
|
|
|
|
func (txt *Text) Draw(c *Context) []EVertex {
|
|
|
|
m := txt.Matrix()
|
|
|
|
m.Concat(c.Camera.RealMatrix())
|
|
|
|
//x, y := txt.Position.XY()
|
|
|
|
//text.Draw(c.Image)
|
2024-01-14 03:51:11 +03:00
|
|
|
text.DrawWithOptions(c.Image, txt.Data, txt.Face,
|
2024-01-13 18:17:34 +03:00
|
|
|
&ebiten.DrawImageOptions{
|
|
|
|
GeoM: m,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|