Documentation ¶
Overview ¶
Package draw has handy features for defining paths which can be used to draw content on a PDF page. Handles defining paths as points, vector calculations and conversion to PDF content stream data which can be used in page content streams and XObject forms and thus also in annotation appearance streams.
Also defines utility functions for drawing common shapes such as rectangles, lines and circles (ovals).
Index ¶
- func DrawBezierPathWithCreator(bpath CubicBezierPath, creator *_cd.ContentCreator)
- func DrawPathWithCreator(path Path, creator *_cd.ContentCreator)
- type BasicLine
- type BoundingBox
- type Circle
- type CubicBezierCurve
- type CubicBezierPath
- type CurvePolygon
- type Line
- type LineEndingStyle
- type LineStyle
- type Path
- type Point
- type PolyBezierCurve
- type Polygon
- type Polyline
- type Rectangle
- type Vector
- func (_bcf Vector) Add(other Vector) Vector
- func (_ffe Vector) Flip() Vector
- func (_fgg Vector) FlipX() Vector
- func (_cae Vector) FlipY() Vector
- func (_dcf Vector) GetPolarAngle() float64
- func (_edab Vector) Magnitude() float64
- func (_efac Vector) Rotate(phi float64) Vector
- func (_eec Vector) Scale(factor float64) Vector
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DrawBezierPathWithCreator ¶
func DrawBezierPathWithCreator(bpath CubicBezierPath, creator *_cd.ContentCreator)
DrawBezierPathWithCreator makes the bezier path with the content creator. Adds the PDF commands to draw the path to the creator instance.
func DrawPathWithCreator ¶
func DrawPathWithCreator(path Path, creator *_cd.ContentCreator)
DrawPathWithCreator makes the path with the content creator. Adds the PDF commands to draw the path to the creator instance.
Types ¶
type BasicLine ¶
type BasicLine struct { X1 float64 Y1 float64 X2 float64 Y2 float64 LineColor _a.PdfColor Opacity float64 LineWidth float64 LineStyle LineStyle DashArray []int64 DashPhase int64 }
BasicLine defines a line between point 1 (X1,Y1) and point 2 (X2,Y2). The line has a specified width, color and opacity.
type BoundingBox ¶
BoundingBox represents the smallest rectangular area that encapsulates an object.
func (BoundingBox) ToPdfRectangle ¶
func (_bc BoundingBox) ToPdfRectangle() *_a.PdfRectangle
ToPdfRectangle returns the bounding box as a PDF rectangle.
type Circle ¶
type Circle struct { X float64 Y float64 Width float64 Height float64 FillEnabled bool FillColor _a.PdfColor BorderEnabled bool BorderWidth float64 BorderColor _a.PdfColor Opacity float64 }
Circle represents a circle shape with fill and border properties that can be drawn to a PDF content stream.
type CubicBezierCurve ¶
CubicBezierCurve is defined by: R(t) = P0*(1-t)^3 + P1*3*t*(1-t)^2 + P2*3*t^2*(1-t) + P3*t^3 where P0 is the current point, P1, P2 control points and P3 the final point.
func NewCubicBezierCurve ¶
func NewCubicBezierCurve(x0, y0, x1, y1, x2, y2, x3, y3 float64) CubicBezierCurve
NewCubicBezierCurve returns a new cubic Bezier curve.
func (CubicBezierCurve) AddOffsetXY ¶
func (_eg CubicBezierCurve) AddOffsetXY(offX, offY float64) CubicBezierCurve
AddOffsetXY adds X,Y offset to all points on a curve.
func (CubicBezierCurve) GetBounds ¶
func (_g CubicBezierCurve) GetBounds() _a.PdfRectangle
GetBounds returns the bounding box of the Bezier curve.
type CubicBezierPath ¶
type CubicBezierPath struct{ Curves []CubicBezierCurve }
CubicBezierPath represents a collection of cubic Bezier curves.
func NewCubicBezierPath ¶
func NewCubicBezierPath() CubicBezierPath
NewCubicBezierPath returns a new empty cubic Bezier path.
func (CubicBezierPath) AppendCurve ¶
func (_fc CubicBezierPath) AppendCurve(curve CubicBezierCurve) CubicBezierPath
AppendCurve appends the specified Bezier curve to the path.
func (CubicBezierPath) Copy ¶
func (_gf CubicBezierPath) Copy() CubicBezierPath
Copy returns a clone of the Bezier path.
func (CubicBezierPath) GetBoundingBox ¶
func (_da CubicBezierPath) GetBoundingBox() Rectangle
GetBoundingBox returns the bounding box of the Bezier path.
func (CubicBezierPath) Offset ¶
func (_egb CubicBezierPath) Offset(offX, offY float64) CubicBezierPath
Offset shifts the Bezier path with the specified offsets.
type CurvePolygon ¶
type CurvePolygon struct { Rings [][]CubicBezierCurve FillEnabled bool FillColor _a.PdfColor BorderEnabled bool BorderColor _a.PdfColor BorderWidth float64 }
CurvePolygon is a multi-point shape with rings containing curves that can be drawn to a PDF content stream.
func (CurvePolygon) Draw ¶
func (_egf CurvePolygon) Draw(gsName string) ([]byte, *_a.PdfRectangle, error)
Draw draws the composite curve polygon. A graphics state name can be specified for setting the curve properties (e.g. setting the opacity). Otherwise leave empty (""). Returns the content stream as a byte array and the bounding box of the polygon.
type Line ¶
type Line struct { X1 float64 Y1 float64 X2 float64 Y2 float64 LineColor _a.PdfColor Opacity float64 LineWidth float64 LineEndingStyle1 LineEndingStyle LineEndingStyle2 LineEndingStyle LineStyle LineStyle }
Line defines a line shape between point 1 (X1,Y1) and point 2 (X2,Y2). The line ending styles can be none (regular line), or arrows at either end. The line also has a specified width, color and opacity.
type LineEndingStyle ¶
type LineEndingStyle int
LineEndingStyle defines the line ending style for lines. The currently supported line ending styles are None, Arrow (ClosedArrow) and Butt.
const ( LineEndingStyleNone LineEndingStyle = 0 LineEndingStyleArrow LineEndingStyle = 1 LineEndingStyleButt LineEndingStyle = 2 )
type Path ¶
type Path struct{ Points []Point }
Path consists of straight line connections between each point defined in an array of points.
func (Path) AppendPoint ¶
AppendPoint adds the specified point to the path.
func (Path) GetBoundingBox ¶
func (_gb Path) GetBoundingBox() BoundingBox
GetBoundingBox returns the bounding box of the path.
func (Path) GetPointNumber ¶
GetPointNumber returns the path point at the index specified by number. The index is 1-based.
func (Path) RemovePoint ¶
RemovePoint removes the point at the index specified by number from the path. The index is 1-based.
type Point ¶
Point represents a two-dimensional point.
type PolyBezierCurve ¶
type PolyBezierCurve struct { Curves []CubicBezierCurve BorderWidth float64 BorderColor _a.PdfColor FillEnabled bool FillColor _a.PdfColor }
PolyBezierCurve represents a composite curve that is the result of joining multiple cubic Bezier curves.
func (PolyBezierCurve) Draw ¶
func (_faa PolyBezierCurve) Draw(gsName string) ([]byte, *_a.PdfRectangle, error)
Draw draws the composite Bezier curve. A graphics state name can be specified for setting the curve properties (e.g. setting the opacity). Otherwise leave empty (""). Returns the content stream as a byte array and the curve bounding box.
type Polygon ¶
type Polygon struct { Points [][]Point FillEnabled bool FillColor _a.PdfColor BorderEnabled bool BorderColor _a.PdfColor BorderWidth float64 }
Polygon is a multi-point shape that can be drawn to a PDF content stream.
type Polyline ¶
Polyline defines a slice of points that are connected as straight lines.
type Rectangle ¶
type Rectangle struct { // Position and size properties. X float64 Y float64 Width float64 Height float64 // Fill properties. FillEnabled bool FillColor _a.PdfColor // Border properties. BorderEnabled bool BorderColor _a.PdfColor BorderWidth float64 BorderRadiusTopLeft float64 BorderRadiusTopRight float64 BorderRadiusBottomLeft float64 BorderRadiusBottomRight float64 // Shape opacity (0-1 interval). Opacity float64 }
Rectangle is a shape with a specified Width and Height and a lower left corner at (X,Y) that can be drawn to a PDF content stream. The rectangle can optionally have a border and a filling color. The Width/Height includes the border (if any specified), i.e. is positioned inside.
func (Rectangle) Draw ¶
Draw draws the rectangle. A graphics state can be specified for setting additional properties (e.g. opacity). Otherwise pass an empty string for the `gsName` parameter. The method returns the content stream as a byte array and the bounding box of the shape.
func (Rectangle) ToPdfRectangle ¶
func (_ecbe Rectangle) ToPdfRectangle() *_a.PdfRectangle
ToPdfRectangle returns the rectangle as a PDF rectangle.
type Vector ¶
Vector represents a two-dimensional vector.
func NewVectorBetween ¶
NewVectorBetween returns a new vector with the direction specified by the subtraction of point a from point b (b-a).
func NewVectorPolar ¶
NewVectorPolar returns a new vector calculated from the specified magnitude and angle.
func (Vector) GetPolarAngle ¶
GetPolarAngle returns the angle the magnitude of the vector forms with the positive X-axis going counterclockwise.