2019-03-05 20:52:18 +00:00
|
|
|
package allg5ui
|
|
|
|
|
|
|
|
import (
|
2019-12-19 06:07:43 +00:00
|
|
|
"opslag.de/schobers/allg5"
|
2019-03-05 20:52:18 +00:00
|
|
|
"opslag.de/schobers/geom"
|
|
|
|
)
|
|
|
|
|
|
|
|
type FontDefinition struct {
|
|
|
|
Name string
|
|
|
|
Size int
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewFontDefinition(name string, size int) FontDefinition {
|
|
|
|
return FontDefinition{Name: name, Size: size}
|
|
|
|
}
|
|
|
|
|
|
|
|
type font struct {
|
2020-05-13 14:49:45 +00:00
|
|
|
*allg5.Font
|
2019-03-05 20:52:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func newFont(f *allg5.Font) *font {
|
|
|
|
return &font{f}
|
|
|
|
}
|
|
|
|
|
2020-05-15 13:42:24 +00:00
|
|
|
func (f *font) Destroy() error {
|
2020-05-13 14:49:45 +00:00
|
|
|
f.Font.Destroy()
|
2020-05-15 13:42:24 +00:00
|
|
|
return nil
|
2019-03-05 20:52:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (f *font) Height() float32 {
|
|
|
|
if f == nil {
|
|
|
|
return 0
|
|
|
|
}
|
2020-05-13 14:49:45 +00:00
|
|
|
return f.Font.Height()
|
2019-03-05 20:52:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (f *font) WidthOf(t string) float32 {
|
2020-05-13 14:49:45 +00:00
|
|
|
return f.TextWidth(t)
|
2019-03-05 20:52:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (f *font) Measure(t string) geom.RectangleF32 {
|
|
|
|
if f == nil {
|
|
|
|
return geom.RectangleF32{}
|
|
|
|
}
|
2020-05-13 14:49:45 +00:00
|
|
|
var x, y, w, h = f.TextDimensions(t)
|
2019-03-05 20:52:18 +00:00
|
|
|
return geom.RectF32(x, y, x+w, y+h)
|
|
|
|
}
|