...

Package context

Overview ▾

type Context

Context defines operations for rendering to a particular target.

type Context interface {

    // Push adds the current context state on the stack.
    Push()

    // Pop removes the most recent context state from the stack.
    Pop()

    // 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)

    // 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()

    // 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 fills the current path with the current color. Open subpaths
    // are implicitly closed.
    Fill()

    // FillPreserve fills the current path with the current color. Open subpaths
    // are implicitly 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)

    // SetFillRGBA sets the fill color.
    // r, g, b, a values should be in range 0-1.
    SetFillRGBA(r, g, b, a float64)

    // SetFillStyle sets current fill pattern.
    SetFillStyle(pattern Pattern)

    // SetFillRule sets the fill rule.
    SetFillRule(fillRule FillRule)

    // SetStrokeRGBA 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)

    // TextState returns the current text state.
    TextState() *TextState

    // DrawString renders the specified string and the specified position.
    DrawString(s string, x, y float64)

    // MeasureString returns the width and height of the specified string.
    MeasureString(s string) (w, h float64)

    // 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)

    // Height returns the width of the rendering area.
    Height() int

    // Width returns the height of the rendering area.
    Width() int
}

type FillRule

FillRule represents the fill style used by a context instance.

type FillRule int

Fill rules.

const (
    FillRuleWinding FillRule = iota
    FillRuleEvenOdd
)

type Gradient

Gradient represents a gradient pattern which can be rendered by a context instance.

type Gradient interface {
    Pattern
    AddColorStop(offset float64, color color.Color)
}

type LineCap

LineCap represents the line cap style used by a context instance.

type LineCap int

Line cap styles.

const (
    LineCapRound LineCap = iota
    LineCapButt
    LineCapSquare
)

type LineJoin

LineJoin represents the line join style used by a context instance.

type LineJoin int

Line join styles.

const (
    LineJoinRound LineJoin = iota
    LineJoinBevel
)

type Pattern

Pattern represents a pattern which can be rendered by a context instance.

type Pattern interface {
    ColorAt(x, y int) color.Color
}

type TextFont

TextFont represents a font used to draw text to a target, through a rendering context.

type TextFont struct {
    Font *model.PdfFont
    Face font.Face
    Size float64
    // contains filtered or unexported fields
}

func NewTextFont

func NewTextFont(font *model.PdfFont, size float64) (*TextFont, error)

NewTextFont returns a new text font instance based on the specified PDF font and the specified font size.

func NewTextFontFromPath

func NewTextFontFromPath(filePath string, size float64) (*TextFont, error)

NewTextFontFromPath returns a new text font instance based on the specified font file and the specified font size.

func (*TextFont) BytesToCharcodes

func (tf *TextFont) BytesToCharcodes(data []byte) []textencoding.CharCode

BytesToCharcodes converts the specified byte data to character codes, using the encapsulated PDF font instance.

func (*TextFont) CharcodesToUnicode

func (tf *TextFont) CharcodesToUnicode(charcodes []textencoding.CharCode) []rune

CharcodesToUnicode converts the specified character codes to a slice of runes, using the encapsulated PDF font instance.

func (*TextFont) GetCharMetrics

func (tf *TextFont) GetCharMetrics(code textencoding.CharCode) (float64, float64, bool)

GetCharMetrics returns the metrics of the specified character code. The character metrics are calculated by the internal PDF font.

func (*TextFont) GetRuneMetrics

func (tf *TextFont) GetRuneMetrics(r rune) (float64, float64, bool)

GetRuneMetrics returns the metrics of the specified rune. The character metrics are calculated by the internal PDF font.

func (*TextFont) WithSize

func (tf *TextFont) WithSize(size float64, originalFont *model.PdfFont) *TextFont

WithSize returns a new text font instance based on the current text font, with the specified font size.

type TextState

TextState holds a representation of a PDF text state. The text state processes different text related operations which may occur in PDF content streams. It is used as a part of a renderding context in order to manipulate and display text.

type TextState struct {
    Tc  float64          // Character spacing.
    Tw  float64          // Word spacing.
    Th  float64          // Horizontal scaling.
    Tl  float64          // Leading.
    Tf  *TextFont        // Font
    Ts  float64          // Text rise.
    Tm  transform.Matrix // Text matrix.
    Tlm transform.Matrix // Text line matrix.
}

func NewTextState

func NewTextState() *TextState

NewTextState returns a new TextState instance.

func (*TextState) ProcDQ

func (ts *TextState) ProcDQ(data []byte, aw, ac float64, ctx Context)

ProcDQ processes a `"` operation, which advances the text state to a new line and then displays a text string using aw and ac as word and character spacing.

See section 9.4.3 "Text Showing Operators" and Table 209 (pp. 258-259 PDF32000_2008).

func (*TextState) ProcQ

func (ts *TextState) ProcQ(data []byte, ctx Context)

ProcQ processes a `'` operation, which advances the text state to a new line and then displays a text string.

See section 9.4.3 "Text Showing Operators" and Table 209 (pp. 258-259 PDF32000_2008).

func (*TextState) ProcTD

func (ts *TextState) ProcTD(tx, ty float64)

ProcTD processes a `TD` operation, which advances the text state to a new line with offsets `tx`,`ty`.

See section 9.4.2 "Text Positioning Operators" and Table 108 (pp. 257-258 PDF32000_2008).

func (*TextState) ProcTStar

func (ts *TextState) ProcTStar()

ProcTStar processes a `T*` operation, which advances the text state to a new line.

See section 9.4.2 "Text Positioning Operators" and Table 108 (pp. 257-258 PDF32000_2008).

func (*TextState) ProcTd

func (ts *TextState) ProcTd(tx, ty float64)

ProcTd processes a `Td` operation, which advances the text state to a new line with offsets `tx`,`ty`.

See section 9.4.2 "Text Positioning Operators" and Table 108 (pp. 257-258 PDF32000_2008).

func (*TextState) ProcTf

func (ts *TextState) ProcTf(font *TextFont)

ProcTf processes a `Tf` operation which sets the font and its size.

See section 9.3 "Text State Parameters and Operators" and Table 105 (pp. 251-252 PDF32000_2008).

func (*TextState) ProcTj

func (ts *TextState) ProcTj(data []byte, ctx Context)

ProcTj processes a `Tj` operation, which displays a text string.

See section 9.4.3 "Text Showing Operators" and Table 209 (pp. 258-259 PDF32000_2008).

func (*TextState) ProcTm

func (ts *TextState) ProcTm(a, b, c, d, e, f float64)

ProcTm processes a `Tm` operation, which sets the current text matrix.

See section 9.4.2 "Text Positioning Operators" and Table 108 (pp. 257-258 PDF32000_2008).

func (*TextState) Reset

func (ts *TextState) Reset()

Reset resets both the text matrix and the line matrix.

func (*TextState) Translate

func (ts *TextState) Translate(tx, ty float64)

Translate translates the current text matrix with `tx`,`ty`.

Subdirectories

Name Synopsis
..