-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimage.go
55 lines (43 loc) · 883 Bytes
/
image.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
53
54
55
package codeview
import (
"github.com/llgcode/draw2d/draw2dimg"
"image"
)
type CodeView struct {
text Text
title string
scale float64
}
func NewCodeView() *CodeView {
return &CodeView{
scale: 1,
text: Text{},
title: projectName,
}
}
func (cv *CodeView) SetText(text Text) {
cv.text = text
}
func (cv *CodeView) SetTitle(title string) {
max := 32 - len(projectName)
if len(title) > max {
title = title[:max-3] + "..."
}
if projectName != "" {
title = title + " - " + projectName
}
cv.title = title
}
func (cv *CodeView) SetScale(scale float64) {
cv.scale = scale
}
func (cv *CodeView) Render() (image.Image, error) {
return _render(cv.text, cv.title, cv.scale)
}
func (cv *CodeView) RenderToPng(path string) error {
img, err := _render(cv.text, cv.title, cv.scale)
if err != nil {
return err
}
return draw2dimg.SaveToPngFile(path, img)
}