gg/text.go

69 lines
1.3 KiB
Go

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
Data string
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)
text.DrawWithOptions(c.Image, txt.Data, txt.Face,
&ebiten.DrawImageOptions{
GeoM: m,
},
)
return nil
}