canvas

package
v0.0.62 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 3, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UnitUnset = iota // No units were set, when conversion is called on nothing will happen
	UnitPT           // Points - 1/72 of an inch, traditional unit in PDF documents
	UnitMM           // Millimeters - 1/10 of a centimeter, metric measurement unit
	UnitCM           // Centimeters - 1/100 of a meter, metric measurement unit
	UnitIN           // Inches - Imperial unit equal to 72 points
	UnitPX           // Pixels - screen unit (by default 96 DPI, thus 72/96 = 3/4 point)

)

The units that can be used in the document

Variables

View Source
var (
	// BoxZero is a preset box that represents an intentional zero value.
	BoxZero = Box{IsSet: true}
)
View Source
var PageSize10x14 = &Rect{W: 720, H: 1008, unitOverride: defaultUnitConfig{Unit: UnitPT}}

PageSize10x14 page format

View Source
var PageSizeA0 = &Rect{W: 2384, H: 3371, unitOverride: defaultUnitConfig{Unit: UnitPT}}

PageSizeA0 page format

View Source
var PageSizeA1 = &Rect{W: 1685, H: 2384, unitOverride: defaultUnitConfig{Unit: UnitPT}}

PageSizeA1 page format

View Source
var PageSizeA2 = &Rect{W: 1190, H: 1684, unitOverride: defaultUnitConfig{Unit: UnitPT}}

PageSizeA2 page format

View Source
var PageSizeA3 = &Rect{W: 842, H: 1190, unitOverride: defaultUnitConfig{Unit: UnitPT}}

PageSizeA3 page format

View Source
var PageSizeA3Landscape = &Rect{W: 1190, H: 842, unitOverride: defaultUnitConfig{Unit: UnitPT}}

PageSizeA3Landscape page format

View Source
var PageSizeA4 = &Rect{W: 595, H: 842, unitOverride: defaultUnitConfig{Unit: UnitPT}}

PageSizeA4 page format

View Source
var PageSizeA4Landscape = &Rect{W: 842, H: 595, unitOverride: defaultUnitConfig{Unit: UnitPT}}

PageSizeA4Landscape page format

View Source
var PageSizeA4Small = &Rect{W: 595, H: 842, unitOverride: defaultUnitConfig{Unit: UnitPT}}

PageSizeA4Small page format

View Source
var PageSizeA5 = &Rect{W: 420, H: 595, unitOverride: defaultUnitConfig{Unit: UnitPT}}

PageSizeA5 page format

View Source
var PageSizeB4 = &Rect{W: 729, H: 1032, unitOverride: defaultUnitConfig{Unit: UnitPT}}

PageSizeB4 page format

View Source
var PageSizeB5 = &Rect{W: 516, H: 729, unitOverride: defaultUnitConfig{Unit: UnitPT}}

PageSizeB5 page format

View Source
var PageSizeExecutive = &Rect{W: 540, H: 720, unitOverride: defaultUnitConfig{Unit: UnitPT}}

PageSizeExecutive page format

View Source
var PageSizeFolio = &Rect{W: 612, H: 936, unitOverride: defaultUnitConfig{Unit: UnitPT}}

PageSizeFolio page format

View Source
var PageSizeLedger = &Rect{W: 1224, H: 792, unitOverride: defaultUnitConfig{Unit: UnitPT}}

PageSizeLedger page format

View Source
var PageSizeLegal = &Rect{W: 612, H: 1008, unitOverride: defaultUnitConfig{Unit: UnitPT}}

PageSizeLegal page format

View Source
var PageSizeLetter = &Rect{W: 612, H: 792, unitOverride: defaultUnitConfig{Unit: UnitPT}}

PageSizeLetter page format

View Source
var PageSizeLetterSmall = &Rect{W: 612, H: 792, unitOverride: defaultUnitConfig{Unit: UnitPT}}

PageSizeLetterSmall page format

View Source
var PageSizeQuarto = &Rect{W: 610, H: 780, unitOverride: defaultUnitConfig{Unit: UnitPT}}

PageSizeQuarto page format

View Source
var PageSizeStatement = &Rect{W: 396, H: 612, unitOverride: defaultUnitConfig{Unit: UnitPT}}

PageSizeStatement page format

View Source
var PageSizeTabloid = &Rect{W: 792, H: 1224, unitOverride: defaultUnitConfig{Unit: UnitPT}}

PageSizeTabloid page format

Functions

func PointsToUnits added in v0.0.60

func PointsToUnits(unit any, u float64) float64

pointsToUnits convierte un valor de puntos al sistema de unidades especificado Parámetros:

  • unit: Entero representando tipo de unidad o una interfaz unitConfigurator
  • u: El valor en puntos a convertir

Retorna:

  • El valor equivalente en el sistema de unidades especificado

func PointsToUnitsCfg added in v0.0.60

func PointsToUnitsCfg(unitCfg unitConfigurator, u float64) float64

pointsToUnits is an internal function that converts points to the specified unit system using the provided unit configuration. It handles custom conversion factors and standard unit types.

Parameters:

  • unitCfg: The unit configuration that specifies the unit type and any custom conversion factor
  • u: The value in points to convert

Returns:

  • The equivalent value in the specified unit system

func PointsToUnitsVar added in v0.0.61

func PointsToUnitsVar(unit any, u ...*float64)

PointsToUnitsVar convierte múltiples valores de puntos al sistema de unidades especificado Parámetros:

  • unit: Entero representando tipo de unidad o una interfaz unitConfigurator
  • u: Punteros a valores a convertir (modificados en el lugar)

func PointsToUnitsVarCfg added in v0.0.60

func PointsToUnitsVarCfg(unitCfg unitConfigurator, u ...*float64)

PointsToUnitsVar is an internal function that converts multiple values from points to units using the provided unit configuration.

Parameters:

  • unitCfg: The unit configuration that specifies the unit type and any custom conversion factor
  • u: Pointers to values to convert (modified in place)

func UnitsToPoints added in v0.0.60

func UnitsToPoints(unit any, u float64) float64

UnitsToPoints convierte un valor desde el sistema de unidades especificado a puntos Parámetros:

  • unit: Entero representando tipo de unidad o una interfaz unitConfigurator
  • u: El valor a convertir

Retorna:

  • El valor equivalente en puntos

func UnitsToPointsVar added in v0.0.60

func UnitsToPointsVar(unit any, u ...*float64)

unitsToPointsVar convierte múltiples valores al sistema de unidades especificado a puntos Parámetros:

  • unit: Entero representando tipo de unidad o una interfaz unitConfigurator
  • u: Punteros a valores a convertir (modificados en el lugar)

Types

type Box

type Box struct {
	Top    int
	Left   int
	Right  int
	Bottom int
	IsSet  bool // IsSet is true if the box is set to a values explicitly.
	// contains filtered or unexported fields
}

Box represents the main 4 dimensions of a box. in chart graphs, in pdf document box represents a rectangular area with explicit coordinates for all four sides. It is used for defining boundaries in PDF documents, such as margins.Margins, trim boxes, etc. The coordinates are stored in the current unit system (points by default, but can be mm, cm, inches, or pixels).

func NewBox

func NewBox(top, left, right, bottom int) Box

NewBox returns a new (set) box.

func (Box) Aspect

func (b Box) Aspect() float64

Aspect returns the aspect ratio of the box.

func (Box) Center

func (b Box) Center() (x, y int)

Center returns the center of the box

func (Box) Clone

func (b Box) Clone() Box

Clone returns a new copy of the box.

func (Box) Constrain

func (b Box) Constrain(other Box) Box

Constrain is similar to `Fit` except that it will work more literally like the opposite of grow.

func (Box) Corners

func (b Box) Corners() BoxCorners

Corners returns the box as a set of corners.

func (Box) Equals

func (b Box) Equals(other Box) bool

Equals returns if the box equals another box.

func (Box) Fit

func (b Box) Fit(other Box) Box

Fit is functionally the inverse of grow. Fit maintains the original aspect ratio of the `other` box, but constrains it to the bounds of the target box.

func (Box) GetBottom

func (b Box) GetBottom(defaults ...int) int

GetBottom returns a coalesced value with a default.

func (Box) GetLeft

func (b Box) GetLeft(defaults ...int) int

GetLeft returns a coalesced value with a default.

func (Box) GetRight

func (b Box) GetRight(defaults ...int) int

GetRight returns a coalesced value with a default.

func (Box) GetTop

func (b Box) GetTop(defaults ...int) int

GetTop returns a coalesced value with a default.

func (Box) Grow

func (b Box) Grow(other Box) Box

Grow grows a box based on another box.

func (Box) Height

func (b Box) Height() int

Height returns the height

func (Box) IsBiggerThan

func (b Box) IsBiggerThan(other Box) bool

IsBiggerThan returns if a box is bigger than another box.

func (Box) IsSmallerThan

func (b Box) IsSmallerThan(other Box) bool

IsSmallerThan returns if a box is smaller than another box.

func (Box) IsZero

func (b Box) IsZero() bool

IsZero returns if the box is set or not.

func (Box) OuterConstrain

func (b Box) OuterConstrain(bounds, other Box) Box

OuterConstrain is similar to `Constraint` with the difference that it applies corrections

func (Box) Shift

func (b Box) Shift(x, y int) Box

Shift pushes a box by x,y.

func (Box) String

func (b Box) String() string

String returns a string representation of the box.

func (*Box) UnitsToPoints added in v0.0.60

func (b *Box) UnitsToPoints(unit any) (out *Box)

UnitsToPoints converts the box coordinates to Points. When this is called it is assumed the values of the box are in the specified unit system. The method creates a new box instance with coordinates converted to points.

Parameters:

  • unit: Either an integer representing a unit type (UnitPT, UnitMM, etc.) or a unitConfigurator interface

Returns:

  • A new box pointer with coordinates converted to points

func (Box) Validate

func (b Box) Validate() error

func (Box) Width

func (b Box) Width() int

Width returns the width

type BoxCorners

type BoxCorners struct {
	TopLeft, TopRight, BottomRight, BottomLeft Point
}

BoxCorners is a box with independent corners.

func (BoxCorners) Box

func (bc BoxCorners) Box() Box

Box return the BoxCorners as a regular box.

func (BoxCorners) Center

func (bc BoxCorners) Center() (x, y int)

Center returns the center of the box

func (BoxCorners) Equals

func (bc BoxCorners) Equals(other BoxCorners) bool

Equals returns if the box equals another box.

func (BoxCorners) Height

func (bc BoxCorners) Height() int

Height returns the height

func (BoxCorners) Rotate

func (bc BoxCorners) Rotate(thetaDegrees float64) BoxCorners

Rotate rotates the box.

func (BoxCorners) String

func (bc BoxCorners) String() string

func (BoxCorners) Width

func (bc BoxCorners) Width() int

Width returns the width

type Margins added in v0.0.60

type Margins struct {
	Left, Top, Right, Bottom float64
}

Margins type.

type PageSize added in v0.0.60

type PageSize struct {
	Width  float64 // Width of the page
	Height float64 // Height of the page
	Unit   int     // Unit type (canvas.UnitPT, canvas.UnitMM, canvas.UnitCM, canvas.UnitIN, canvas.UnitPX)
}

PageSize provides an intuitive way to define custom page sizes It allows users to specify width and height in their preferred unit of measurement

func (PageSize) ToRect added in v0.0.60

func (ps PageSize) ToRect() *Rect

ToRect converts a PageSize to a canvas.Rect for internal use

type Point

type Point struct {
	X, Y int
}

Point is an X,Y pair

func (Point) DistanceTo

func (p Point) DistanceTo(other Point) float64

DistanceTo calculates the distance to another point.

func (Point) Equals

func (p Point) Equals(other Point) bool

Equals returns if a point equals another point.

func (Point) String

func (p Point) String() string

String returns a string representation of the point.

type Rect added in v0.0.60

type Rect struct {
	W float64 // Width of the rectangle
	H float64 // Height of the rectangle
	// contains filtered or unexported fields
}

canvas.Rect defines a rectangle by its width and height. This is used for defining page sizes, content areas, and other rectangular regions in PDF documents. The dimensions are stored in the current unit system (points by default, but can be mm, cm, inches, or pixels).

func (*Rect) UnitsToPoints added in v0.0.60

func (rect *Rect) UnitsToPoints(unit any) (r *Rect)

UnitsToPoints converts the rectangle's dimensions to points based on the provided unit information. When this is called it is assumed the values of the rectangle are in the specified units. The method creates a new canvas.Rect instance with dimensions converted to points.

Parameters:

  • unit: Either an integer representing a unit type (UnitPT, UnitMM, etc.) or a unitConfigurator interface

Returns:

  • A new canvas.Rect pointer with dimensions converted to points

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL