-
Notifications
You must be signed in to change notification settings - Fork 0
/
font.go
51 lines (44 loc) · 1.23 KB
/
font.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package impress
import (
"image"
"github.com/codeation/impress/driver"
)
// Font represents a font selection
type Font struct {
fonter driver.Fonter
Height int
LineHeight int
Baseline int
Ascent int
Descent int
Attributes map[string]string
}
// NewFont return a font selection struct.
// Note than "family" and other attributes are driver specific.
// Open duo/font.go for details.
func (app *Application) NewFont(height int, attributes map[string]string) *Font {
fonter := app.driver.NewFont(height, attributes)
return &Font{
fonter: fonter,
Height: height,
LineHeight: fonter.LineHeight(),
Baseline: fonter.Baseline(),
Ascent: fonter.Ascent(),
Descent: fonter.Descent(),
Attributes: attributes,
}
}
// Close destroys font selection
func (f *Font) Close() {
f.fonter.Close()
f.fonter = nil // TODO notice when the font is closed
}
// Split breaks the text into lines that fit in the specified width;
// indent is a width to indent first line
func (f *Font) Split(text string, edge int, indent int) []string {
return f.fonter.Split(text, edge, indent)
}
// Size returns the width and height of the drawing area
func (f *Font) Size(text string) image.Point {
return f.fonter.Size(text)
}