/
context.go
188 lines (137 loc) · 4.83 KB
/
context.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
package context
import (
"image"
"github.com/dlocmelis/pdfreader/internal/transform"
)
// Context defines operations for rendering to a particular target.
type Context interface {
//
// Graphics state operations
//
// Push adds the current context state on the stack.
Push()
// Pop removes the most recent context state from the stack.
Pop()
//
// Matrix operations
//
// Matrix returns the current transformation matrix.
Matrix() transform.Matrix
// SetMatrix modifies the transformation matrix.
SetMatrix(m transform.Matrix)
// Translate updates the current matrix with a translation.
Translate(x, y float64)
// Scale updates the current matrix with a scaling factor.
// Scaling occurs about the origin.
Scale(x, y float64)
// Rotate updates the current matrix with a anticlockwise rotation.
// Rotation occurs about the origin. Angle is specified in radians.
Rotate(angle float64)
//
// Path operations
//
// MoveTo starts a new subpath within the current path starting at
// the specified point.
MoveTo(x, y float64)
// LineTo adds a line segment to the current path starting at the current
// point.
LineTo(x, y float64)
// CubicTo adds a cubic bezier curve to the current path starting at the
// current point.
CubicTo(x1, y1, x2, y2, x3, y3 float64)
// QuadraticTo adds a quadratic bezier curve to the current path starting
// at the current point.
QuadraticTo(x1, y1, x2, y2 float64)
// NewSubPath starts a new subpath within the current path.
NewSubPath()
// ClosePath adds a line segment from the current point to the beginning
// of the current subpath.
ClosePath()
// ClearPath clears the current path.
ClearPath()
// Clip updates the clipping region by intersecting the current
// clipping region with the current path as it would be filled by Fill().
// The path is cleared after this operation.
Clip()
// ClipPreserve updates the clipping region by intersecting the current
// clipping region with the current path as it would be filled by Fill().
// The path is preserved after this operation.
ClipPreserve()
// ResetClip clears the clipping region.
ResetClip()
//
// Line style operations
//
// LineWidth returns the current line width.
LineWidth() float64
// SetLineWidth sets the line width.
SetLineWidth(lineWidth float64)
// SetLineCap sets the line cap style.
SetLineCap(lineCap LineCap)
// SetLineJoin sets the line join style.
SetLineJoin(lineJoin LineJoin)
// SetDash sets the line dash pattern.
SetDash(dashes ...float64)
// SetDashOffset sets the initial offset into the dash pattern to use when
// stroking dashed paths.
SetDashOffset(offset float64)
//
// Fill and stroke operations
//
// Fill fills the current path with the current color. Open subpaths
// are implicity closed.
Fill()
// FillPreserve fills the current path with the current color. Open subpaths
// are implicity closed. The path is preserved after this operation.
FillPreserve()
// Stroke strokes the current path with the current color, line width,
// line cap, line join and dash settings. The path is cleared after this
// operation.
Stroke()
// StrokePreserve strokes the current path with the current color,
// line width, line cap, line join and dash settings. The path is preserved
// after this operation.
StrokePreserve()
// SetRGBA sets the both the fill and stroke colors.
// r, g, b, a values should be in range 0-1.
SetRGBA(r, g, b, a float64)
// SetRGBA sets the fill color.
// r, g, b, a values should be in range 0-1.
SetFillRGBA(r, g, b, a float64)
// SetStrokeStyle sets current fill pattern.
SetFillStyle(pattern Pattern)
// SetFillRule sets the fill rule.
SetFillRule(fillRule FillRule)
// SetRGBA sets the stroke color.
// r, g, b, a values should be in range 0-1.
SetStrokeRGBA(r, g, b, a float64)
// SetStrokeStyle sets current stroke pattern.
SetStrokeStyle(pattern Pattern)
//
// Text operations
//
// TextState returns the current text state.
TextState() *TextState
// DrawString renders the specified string and the specified position.
DrawString(s string, x, y float64)
// Measure string returns the width and height of the specified string.
MeasureString(s string) (w, h float64)
//
// Draw operations
//
// DrawRectangle draws the specified rectangle.
DrawRectangle(x, y, w, h float64)
// DrawImage draws the specified image at the specified point.
DrawImage(image image.Image, x, y int)
// DrawImageAnchored draws the specified image at the specified anchor point.
// The anchor point is x - w * ax, y - h * ay, where w, h is the size of the
// image. Use ax=0.5, ay=0.5 to center the image at the specified point.
DrawImageAnchored(image image.Image, x, y int, ax, ay float64)
//
// Misc operations
//
// Width returns the width of the rendering area.
Height() int
// Height returns the height of the rendering area.
Width() int
}