-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfont.go
52 lines (45 loc) · 1.37 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
52
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 returns a Font struct representing a font selection.
// Note that "family" and other attributes are driver-specific.
// Open joint/domain/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 the font selection.
// Note that a closed font can no longer be used.
func (f *Font) Close() {
f.fonter.Close()
f.fonter = nil // TODO: Add notice when the font is closed.
}
// Split breaks the text into lines that fit within the specified width.
// The indent parameter specifies the width to indent the 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 for the given text.
func (f *Font) Size(text string) image.Point {
return f.fonter.Size(text)
}