unidoc: github.com/unidoc/unidoc/pdf/contentstream/draw Index | Files

package draw

import "github.com/unidoc/unidoc/pdf/contentstream/draw"

The draw package 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

Package Files

bezier_curve.go doc.go path.go point.go shapes.go utils.go vector.go

func DrawBezierPathWithCreator Uses

func DrawBezierPathWithCreator(bpath CubicBezierPath, creator *pdfcontent.ContentCreator)

Make the bezier path with the content creator. Adds the PDF commands to draw the path to the creator instance.

func DrawPathWithCreator Uses

func DrawPathWithCreator(path Path, creator *pdfcontent.ContentCreator)

Make the path with the content creator. Adds the PDF commands to draw the path to the creator instance.

type BoundingBox Uses

type BoundingBox struct {
    X      float64
    Y      float64
    Width  float64
    Height float64
}

type Circle Uses

type Circle struct {
    X             float64
    Y             float64
    Width         float64
    Height        float64
    FillEnabled   bool // Show fill?
    FillColor     *pdf.PdfColorDeviceRGB
    BorderEnabled bool // Show border?
    BorderWidth   float64
    BorderColor   *pdf.PdfColorDeviceRGB
    Opacity       float64 // Alpha value (0-1).
}

func (Circle) Draw Uses

func (c Circle) Draw(gsName string) ([]byte, *pdf.PdfRectangle, error)

Draw a circle. Can specify a graphics state (gsName) for setting opacity etc. Otherwise leave empty (""). Returns the content stream as a byte array, the bounding box and an error on failure.

type CubicBezierCurve Uses

type CubicBezierCurve struct {
    P0  Point // Starting point.
    P1  Point // Control point 1.
    P2  Point // Control point 2.
    P3  Point // Final point.
}

Cubic bezier curves are 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 Uses

func NewCubicBezierCurve(x0, y0, x1, y1, x2, y2, x3, y3 float64) CubicBezierCurve

func (CubicBezierCurve) AddOffsetXY Uses

func (curve CubicBezierCurve) AddOffsetXY(offX, offY float64) CubicBezierCurve

Add X,Y offset to all points on a curve.

func (CubicBezierCurve) GetBounds Uses

func (curve CubicBezierCurve) GetBounds() model.PdfRectangle

type CubicBezierPath Uses

type CubicBezierPath struct {
    Curves []CubicBezierCurve
}

func NewCubicBezierPath Uses

func NewCubicBezierPath() CubicBezierPath

func (CubicBezierPath) AppendCurve Uses

func (this CubicBezierPath) AppendCurve(curve CubicBezierCurve) CubicBezierPath

func (CubicBezierPath) Copy Uses

func (bpath CubicBezierPath) Copy() CubicBezierPath

func (CubicBezierPath) GetBoundingBox Uses

func (bpath CubicBezierPath) GetBoundingBox() Rectangle

func (CubicBezierPath) Offset Uses

func (bpath CubicBezierPath) Offset(offX, offY float64) CubicBezierPath

type Line Uses

type Line struct {
    X1               float64
    Y1               float64
    X2               float64
    Y2               float64
    LineColor        *pdf.PdfColorDeviceRGB
    Opacity          float64 // Alpha value (0-1).
    LineWidth        float64
    LineEndingStyle1 LineEndingStyle // Line ending style of point 1.
    LineEndingStyle2 LineEndingStyle // Line ending style of point 2.
}

Defines a line 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.

func (Line) Draw Uses

func (line Line) Draw(gsName string) ([]byte, *pdf.PdfRectangle, error)

Draw a line in PDF. Generates the content stream which can be used in page contents or appearance stream of annotation. Returns the stream content, XForm bounding box (local), bounding box and an error if one occurred.

type LineEndingStyle Uses

type LineEndingStyle int

The currently supported line ending styles are None, Arrow (ClosedArrow) and Butt.

const (
    LineEndingStyleNone  LineEndingStyle = 0
    LineEndingStyleArrow LineEndingStyle = 1
    LineEndingStyleButt  LineEndingStyle = 2
)

type Path Uses

type Path struct {
    Points []Point
}

A path consists of straight line connections between each point defined in an array of points.

func NewPath Uses

func NewPath() Path

func (Path) AppendPoint Uses

func (this Path) AppendPoint(point Point) Path

func (Path) Copy Uses

func (path Path) Copy() Path

func (Path) GetBoundingBox Uses

func (path Path) GetBoundingBox() BoundingBox

func (Path) GetPointNumber Uses

func (this Path) GetPointNumber(number int) Point

func (Path) Length Uses

func (this Path) Length() int

func (Path) Offset Uses

func (path Path) Offset(offX, offY float64) Path

func (Path) RemovePoint Uses

func (this Path) RemovePoint(number int) Path

type Point Uses

type Point struct {
    X   float64
    Y   float64
}

func NewPoint Uses

func NewPoint(x, y float64) Point

func (Point) Add Uses

func (p Point) Add(dx, dy float64) Point

func (Point) AddVector Uses

func (this Point) AddVector(v Vector) Point

Add vector to a point.

func (Point) String Uses

func (p Point) String() string

type Rectangle Uses

type Rectangle struct {
    X             float64
    Y             float64
    Width         float64
    Height        float64
    FillEnabled   bool // Show fill?
    FillColor     *pdf.PdfColorDeviceRGB
    BorderEnabled bool // Show border?
    BorderWidth   float64
    BorderColor   *pdf.PdfColorDeviceRGB
    Opacity       float64 // Alpha value (0-1).
}

A rectangle defined with a specified Width and Height and a lower left corner at (X,Y). 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 Uses

func (rect Rectangle) Draw(gsName string) ([]byte, *pdf.PdfRectangle, error)

Draw the circle. Can specify a graphics state (gsName) for setting opacity etc. Otherwise leave empty (""). Returns the content stream as a byte array, bounding box and an error on failure.

type Vector Uses

type Vector struct {
    Dx  float64
    Dy  float64
}

func NewVector Uses

func NewVector(dx, dy float64) Vector

func NewVectorBetween Uses

func NewVectorBetween(a Point, b Point) Vector

func NewVectorPolar Uses

func NewVectorPolar(length float64, theta float64) Vector

func (Vector) Add Uses

func (v Vector) Add(other Vector) Vector

func (Vector) Flip Uses

func (this Vector) Flip() Vector

Change the sign of the vector: -vector.

func (Vector) FlipX Uses

func (v Vector) FlipX() Vector

func (Vector) FlipY Uses

func (v Vector) FlipY() Vector

func (Vector) GetPolarAngle Uses

func (this Vector) GetPolarAngle() float64

func (Vector) Magnitude Uses

func (this Vector) Magnitude() float64

func (Vector) Rotate Uses

func (v Vector) Rotate(phi float64) Vector

func (Vector) Scale Uses

func (this Vector) Scale(factor float64) Vector

Package draw imports 5 packages (graph) and is imported by 4 packages. Updated 2017-08-01. Refresh now. Tools for package owners.