Documentation
¶
Index ¶
- Constants
- Variables
- func PointsToUnits(unit any, u float64) float64
- func PointsToUnitsCfg(unitCfg unitConfigurator, u float64) float64
- func PointsToUnitsVar(unit any, u ...*float64)
- func PointsToUnitsVarCfg(unitCfg unitConfigurator, u ...*float64)
- func UnitsToPoints(unit any, u float64) float64
- func UnitsToPointsVar(unit any, u ...*float64)
- type Box
- func (b Box) Aspect() float64
- func (b Box) Center() (x, y int)
- func (b Box) Clone() Box
- func (b Box) Constrain(other Box) Box
- func (b Box) Corners() BoxCorners
- func (b Box) Equals(other Box) bool
- func (b Box) Fit(other Box) Box
- func (b Box) GetBottom(defaults ...int) int
- func (b Box) GetLeft(defaults ...int) int
- func (b Box) GetRight(defaults ...int) int
- func (b Box) GetTop(defaults ...int) int
- func (b Box) Grow(other Box) Box
- func (b Box) Height() int
- func (b Box) IsBiggerThan(other Box) bool
- func (b Box) IsSmallerThan(other Box) bool
- func (b Box) IsZero() bool
- func (b Box) OuterConstrain(bounds, other Box) Box
- func (b Box) Shift(x, y int) Box
- func (b Box) String() string
- func (b *Box) UnitsToPoints(unit any) (out *Box)
- func (b Box) Validate() error
- func (b Box) Width() int
- type BoxCorners
- type Margins
- type PageSize
- type Point
- type Rect
Constants ¶
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 ¶
var ( // BoxZero is a preset box that represents an intentional zero value. BoxZero = Box{IsSet: true} )
var PageSize10x14 = &Rect{W: 720, H: 1008, unitOverride: defaultUnitConfig{Unit: UnitPT}}
PageSize10x14 page format
var PageSizeA0 = &Rect{W: 2384, H: 3371, unitOverride: defaultUnitConfig{Unit: UnitPT}}
PageSizeA0 page format
var PageSizeA1 = &Rect{W: 1685, H: 2384, unitOverride: defaultUnitConfig{Unit: UnitPT}}
PageSizeA1 page format
var PageSizeA2 = &Rect{W: 1190, H: 1684, unitOverride: defaultUnitConfig{Unit: UnitPT}}
PageSizeA2 page format
var PageSizeA3 = &Rect{W: 842, H: 1190, unitOverride: defaultUnitConfig{Unit: UnitPT}}
PageSizeA3 page format
var PageSizeA3Landscape = &Rect{W: 1190, H: 842, unitOverride: defaultUnitConfig{Unit: UnitPT}}
PageSizeA3Landscape page format
var PageSizeA4 = &Rect{W: 595, H: 842, unitOverride: defaultUnitConfig{Unit: UnitPT}}
PageSizeA4 page format
var PageSizeA4Landscape = &Rect{W: 842, H: 595, unitOverride: defaultUnitConfig{Unit: UnitPT}}
PageSizeA4Landscape page format
var PageSizeA4Small = &Rect{W: 595, H: 842, unitOverride: defaultUnitConfig{Unit: UnitPT}}
PageSizeA4Small page format
var PageSizeA5 = &Rect{W: 420, H: 595, unitOverride: defaultUnitConfig{Unit: UnitPT}}
PageSizeA5 page format
var PageSizeB4 = &Rect{W: 729, H: 1032, unitOverride: defaultUnitConfig{Unit: UnitPT}}
PageSizeB4 page format
var PageSizeB5 = &Rect{W: 516, H: 729, unitOverride: defaultUnitConfig{Unit: UnitPT}}
PageSizeB5 page format
var PageSizeExecutive = &Rect{W: 540, H: 720, unitOverride: defaultUnitConfig{Unit: UnitPT}}
PageSizeExecutive page format
var PageSizeFolio = &Rect{W: 612, H: 936, unitOverride: defaultUnitConfig{Unit: UnitPT}}
PageSizeFolio page format
var PageSizeLedger = &Rect{W: 1224, H: 792, unitOverride: defaultUnitConfig{Unit: UnitPT}}
PageSizeLedger page format
var PageSizeLegal = &Rect{W: 612, H: 1008, unitOverride: defaultUnitConfig{Unit: UnitPT}}
PageSizeLegal page format
var PageSizeLetter = &Rect{W: 612, H: 792, unitOverride: defaultUnitConfig{Unit: UnitPT}}
PageSizeLetter page format
var PageSizeLetterSmall = &Rect{W: 612, H: 792, unitOverride: defaultUnitConfig{Unit: UnitPT}}
PageSizeLetterSmall page format
var PageSizeQuarto = &Rect{W: 610, H: 780, unitOverride: defaultUnitConfig{Unit: UnitPT}}
PageSizeQuarto page format
var PageSizeStatement = &Rect{W: 396, H: 612, unitOverride: defaultUnitConfig{Unit: UnitPT}}
PageSizeStatement page format
var PageSizeTabloid = &Rect{W: 792, H: 1224, unitOverride: defaultUnitConfig{Unit: UnitPT}}
PageSizeTabloid page format
Functions ¶
func PointsToUnits ¶ added in v0.0.60
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
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
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
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
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 (Box) Constrain ¶
Constrain is similar to `Fit` except that it will work more literally like the opposite of grow.
func (Box) Fit ¶
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) IsBiggerThan ¶
IsBiggerThan returns if a box is bigger than another box.
func (Box) IsSmallerThan ¶
IsSmallerThan returns if a box is smaller than another box.
func (Box) OuterConstrain ¶
OuterConstrain is similar to `Constraint` with the difference that it applies corrections
func (*Box) UnitsToPoints ¶ added in v0.0.60
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
type BoxCorners ¶
type BoxCorners struct {
TopLeft, TopRight, BottomRight, BottomLeft Point
}
BoxCorners is a box with independent corners.
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) Rotate ¶
func (bc BoxCorners) Rotate(thetaDegrees float64) BoxCorners
Rotate rotates the box.
func (BoxCorners) String ¶
func (bc BoxCorners) String() string
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
type Point ¶
type Point struct {
X, Y int
}
Point is an X,Y pair
func (Point) DistanceTo ¶
DistanceTo calculates the distance to another 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
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