CSMeasureUtils
in package
This utility class provides measuring utilities.
Tags
Table of Contents
- CSYS_INVERT_X = 'CSYS_INVERT_X'
- CSYS_INVERT_Y = 'CSYS_INVERT_Y'
- CSYS_OFFSET = 'CSYS_OFFSET'
- Coordinate system properties
- CSYS_TRANSPOSE = 'CSYS_TRANSPOSE'
- DIM_HEIGHT = self::DIM_Y
- DIM_HORIZONTAL = self::DIM_X
- DIM_VERTICAL = self::DIM_Y
- DIM_WIDTH = self::DIM_X
- DIM_X = 'GUI_EDIT_DIMENSION_HORIZONTAL'
- Size/point dimension descriptors (and corresponding aliases)
- DIM_Y = 'GUI_EDIT_DIMENSION_VERTICAL'
- FORMULA_REGEX = '/^[0-9\.\-\*\+\/\(\) X]*$/'
- Regex matching conversion formula
- $COORDSYS_PAPER_PDF : mixed
- $COORDSYS_SCREEN : mixed
- Coordinate systems definitions Warning: Offsets may need to be adjusted for printable media systems prior to any conversion call.
- compareSizeByArea() : int
- Compares two size structures by their occupied area (regardless of their units). Be aware that this method does not perform separate single-dimension checks. The method is output-compatible to e.g. string comparing functions, so the method can be used as a user-defined callback for built-in PHP sort functions like "usort()".
- flattenRange() : mixed
- Limits a given number to specified minimum and/or maximum values.
- getDimensionsType() : string
- Returns the master data type of a point/size structure.
- getOriginByMediaSize() : array<string|int, mixed>
- Calculates a coordinate system's absolute origin according to the size of a medium.
- getPointX() : mixed
- Returns the horizontal position of a point structure as created by the {@see makePoint()} method.
- getPointY() : mixed
- Returns the vertical position of a point structure as created by the {@see makePoint()} method.
- getSizeHeight() : mixed
- Returns the height dimension of a size structure as created by the {@see makeSize()} method.
- getSizeWidth() : mixed
- Returns the width dimension of a size structure as created by the {@see makeSize()} method.
- isWithinBounds() : bool
- Checks whether a given point or size exceeds specified minimum and/or maximum coordinates or dimensions.
- isWithinRange() : bool
- Checks whether a given number exceeds specified minimum and/or maximum values.
- makePoint() : array<string|int, mixed>
- Creates a tuple of coordinates that is safe for use with CSImageUtils operations.
- makeSize() : array<string|int, mixed>
- Creates a tuple of dimensions that is safe for use with CSImageUtils operations.
- relocatePoint() : array<string|int, mixed>
- Recalculates the position of a point for a different coordinate system.
- setCartesianOrigin() : array<string|int, mixed>
- Moves the origin of a given coordinate system to a new absolute (cartesian) position.
Constants
CSYS_INVERT_X
public
mixed
CSYS_INVERT_X
= 'CSYS_INVERT_X'
Tags
CSYS_INVERT_Y
public
mixed
CSYS_INVERT_Y
= 'CSYS_INVERT_Y'
Tags
CSYS_OFFSET
Coordinate system properties
public
mixed
CSYS_OFFSET
= 'CSYS_OFFSET'
Tags
CSYS_TRANSPOSE
public
mixed
CSYS_TRANSPOSE
= 'CSYS_TRANSPOSE'
Tags
DIM_HEIGHT
public
mixed
DIM_HEIGHT
= self::DIM_Y
Tags
DIM_HORIZONTAL
public
mixed
DIM_HORIZONTAL
= self::DIM_X
Tags
DIM_VERTICAL
public
mixed
DIM_VERTICAL
= self::DIM_Y
Tags
DIM_WIDTH
public
mixed
DIM_WIDTH
= self::DIM_X
Tags
DIM_X
Size/point dimension descriptors (and corresponding aliases)
public
mixed
DIM_X
= 'GUI_EDIT_DIMENSION_HORIZONTAL'
Tags
DIM_Y
public
mixed
DIM_Y
= 'GUI_EDIT_DIMENSION_VERTICAL'
Tags
FORMULA_REGEX
Regex matching conversion formula
public
mixed
FORMULA_REGEX
= '/^[0-9\.\-\*\+\/\(\) X]*$/'
IMPORTANT: The regex below is very crucial when it comes to security, as the formula is auser input which allows manipulations in case we are not taking care to filter characters that might be missused for dangerous code injections! Please keep this in mind when changing it!
Tags
Properties
$COORDSYS_PAPER_PDF
public
static mixed
$COORDSYS_PAPER_PDF
= array(self::CSYS_OFFSET => array(0.0, 0.0), self::CSYS_TRANSPOSE => \FALSE, self::CSYS_INVERT_X => \FALSE, self::CSYS_INVERT_Y => \FALSE)
Tags
$COORDSYS_SCREEN
Coordinate systems definitions Warning: Offsets may need to be adjusted for printable media systems prior to any conversion call.
public
static mixed
$COORDSYS_SCREEN
= array(self::CSYS_OFFSET => array(0.0, 0.0), self::CSYS_TRANSPOSE => \FALSE, self::CSYS_INVERT_X => \FALSE, self::CSYS_INVERT_Y => \TRUE)
Tags
Methods
compareSizeByArea()
Compares two size structures by their occupied area (regardless of their units). Be aware that this method does not perform separate single-dimension checks. The method is output-compatible to e.g. string comparing functions, so the method can be used as a user-defined callback for built-in PHP sort functions like "usort()".
public
static compareSizeByArea(mixed $amSize1, mixed $amSize2) : int
Parameters
- $amSize1 : mixed
-
A size structure, which will be compared to $amSize2. Size structure components specified by NULL will be mapped to zero ("0.0"), resulting in an area of zero square units.
- $amSize2 : mixed
-
A size structure, which will be compared to $amSize1. Size structure components specified by NULL will be mapped to zero ("0.0"), resulting in an area of zero square units.
Tags
Return values
int —If both size structures cover the same area, the return value is zero ("0"). If $amSize1 covers an area smaller than the one of $amSize2, the return value is minus one ("-1"). If $amSize1 covers an area bigger than the one of $amSize2, the return value is plus one ("1").
flattenRange()
Limits a given number to specified minimum and/or maximum values.
public
static flattenRange(mixed $mValue[, mixed $mMinimum = NULL ][, mixed $mMaximum = NULL ]) : mixed
Parameters
- $mValue : mixed
-
The value for which the range checks should be performed.
- $mMinimum : mixed = NULL
-
The lower boundary for the range check or NULL, if not applicable.
- $mMaximum : mixed = NULL
-
The upper boundary for the range check or NULL, if not applicable.
Tags
Return values
mixed —If $mValue is between applicable boundaries, the value itself is returned. Otherwise, if a boundary has been hit, the appropriate limiting value is returned. A value of NULL is returned unchanged.
getDimensionsType()
Returns the master data type of a point/size structure.
public
static getDimensionsType(array<string|int, mixed> $amDimensions) : string
Parameters
- $amDimensions : array<string|int, mixed>
-
The point/size structure whose master data type should be determined.
Tags
Return values
string —The string "double", if both components are NULL or at least one dimension uses a numeric format which can only expressed safely when converted to the "double" data type. Data types interpreted as "double" are "float", "double" and "string". (Strings are interpreted as "double" even if they contain a value that would fit into an "int", because later typecasting to an "int" would mean a potential loss of information). If no component matches the criteria specified above, the return value is the string "integer". Both return values use the same spelling and case as the internal PHP function "gettype()" does.
getOriginByMediaSize()
Calculates a coordinate system's absolute origin according to the size of a medium.
public
static getOriginByMediaSize(array<string|int, mixed> $amMediaSize, array<string|int, mixed> $amCoordinateSystem) : array<string|int, mixed>
Parameters
- $amMediaSize : array<string|int, mixed>
-
A size structure describing the size of a medium (regardless of the measuring unit).
- $amCoordinateSystem : array<string|int, mixed>
-
The coordinate system for which the resulting origin is going to be used.
Tags
Return values
array<string|int, mixed> —A point structure, which describes the new point of origin for the media size in the specified coordinate system.
getPointX()
Returns the horizontal position of a point structure as created by the {@see makePoint()} method.
public
static getPointX(array<string|int, mixed> $amPoint) : mixed
This is an alias for the getSizeWidth() method.
Parameters
- $amPoint : array<string|int, mixed>
-
The point structure to be queried.
Tags
Return values
mixed —A double or integer value describing the horizontal position.
getPointY()
Returns the vertical position of a point structure as created by the {@see makePoint()} method.
public
static getPointY(array<string|int, mixed> $amPoint) : mixed
This is an alias for the getSizeHeight() method.
Parameters
- $amPoint : array<string|int, mixed>
-
The point structure to be queried.
Tags
Return values
mixed —A double or integer value describing the vertical position.
getSizeHeight()
Returns the height dimension of a size structure as created by the {@see makeSize()} method.
public
static getSizeHeight(array<string|int, mixed> $amSize) : mixed
Parameters
- $amSize : array<string|int, mixed>
-
The size structure to be queried.
Tags
Return values
mixed —A double or integer value describing the height dimension.
getSizeWidth()
Returns the width dimension of a size structure as created by the {@see makeSize()} method.
public
static getSizeWidth(array<string|int, mixed> $amSize) : mixed
Parameters
- $amSize : array<string|int, mixed>
-
The size structure to be queried.
Tags
Return values
mixed —A double or integer value describing the width dimension.
isWithinBounds()
Checks whether a given point or size exceeds specified minimum and/or maximum coordinates or dimensions.
public
static isWithinBounds([mixed $amSize = array() ][, mixed $amMinima = array() ][, mixed $amMaxima = array() ]) : bool
Parameters
- $amSize : mixed = array()
-
The point or size structure for which the range checks should be performed.
- $amMinima : mixed = array()
-
A point/size struct providing the lower boundaries for each dimension. This should be created using the makePoint() or makeSize() method. A limit of NULL for a specific dimension means that it is not being limited.
- $amMaxima : mixed = array()
-
A point/size struct providing the upper boundaries for each dimension. This should be created using the makePoint() or makeSize() method. A limit of NULL for a specific dimension means that it is not being limited.
Tags
Return values
bool —TRUE, if both dimensions of $amValues are equal to or between applicable boundaries, or FALSE, if at least one of them is not.
isWithinRange()
Checks whether a given number exceeds specified minimum and/or maximum values.
public
static isWithinRange(mixed $mValue[, mixed $mMinimum = NULL ][, mixed $mMaximum = NULL ]) : bool
Parameters
- $mValue : mixed
-
The value for which the range checks should be performed.
- $mMinimum : mixed = NULL
-
The lower boundary for the range check or NULL, if not applicable.
- $mMaximum : mixed = NULL
-
The upper boundary for the range check or NULL, if not applicable.
Tags
Return values
bool —TRUE, if $mValue is equal to or between applicable boundaries, or FALSE, if it is not.
makePoint()
Creates a tuple of coordinates that is safe for use with CSImageUtils operations.
public
static makePoint([mixed $mPositionX = NULL ][, mixed $mPositionY = NULL ]) : array<string|int, mixed>
This is an alias for the makeSize() method.
Parameters
- $mPositionX : mixed = NULL
-
A numeric value for the horizontal position of the point or NULL, if unspecified.
- $mPositionY : mixed = NULL
-
A numeric value for the vertical position of the point or NULL, if unspecified.
Tags
Return values
array<string|int, mixed> —An array containing both values, indexed with CSImageUtils::DIM_* constants. The indices are used to query the appropriate dimension during image operations. Be aware that floating point types and strings are converted to "double", while all other types (except NULL) are converted to "integer". If type evaluation detects that at least one component of the structure is of the "double" type, both components will be converted to it. If it does not, both components will be converted to "integer".
makeSize()
Creates a tuple of dimensions that is safe for use with CSImageUtils operations.
public
static makeSize([mixed $mWidth = NULL ][, mixed $mHeight = NULL ]) : array<string|int, mixed>
Parameters
- $mWidth : mixed = NULL
-
A numeric value for the horizontal position of the point or NULL, if unspecified.
- $mHeight : mixed = NULL
-
A numeric value for the vertical position of the point or NULL, if unspecified.
Tags
Return values
array<string|int, mixed> —An array containing both values, indexed with CSImageUtils::DIM_* constants. The indices are used to query the appropriate dimension during image operations. Be aware that floating point types and strings are converted to "double", while all other types (except NULL) are converted to "integer". If type evaluation detects that at least one component of the structure is of the "double" type, both components (except NULL values) will be converted to it. If it does not, both components will be converted to "integer".
relocatePoint()
Recalculates the position of a point for a different coordinate system.
public
static relocatePoint(array<string|int, mixed> $amSourcePoint, array<string|int, mixed> $amSourceCoordSys, array<string|int, mixed> $amTargetCoordSys) : array<string|int, mixed>
This becomes necessary when converting screen to paper/PDF coordinates.
Parameters
- $amSourcePoint : array<string|int, mixed>
-
A point structure, describing the coordinates which should be converted to the target coordinate system.
- $amSourceCoordSys : array<string|int, mixed>
-
The source coordinate system where the point originates from.
- $amTargetCoordSys : array<string|int, mixed>
-
The target coordinate system where the point should be placed.
Tags
Return values
array<string|int, mixed> —A point structure describing the new coordinates of the point in the target coordinate system.
setCartesianOrigin()
Moves the origin of a given coordinate system to a new absolute (cartesian) position.
public
static setCartesianOrigin(array<string|int, mixed> $amOrigin, array<string|int, mixed> $amCoordinateSystem) : array<string|int, mixed>
This becomes necessary when converting screen to paper/PDF coordinates, which depend on the paper size.
Parameters
- $amOrigin : array<string|int, mixed>
-
A point structure describing the new cartesian origin of the coordinate system.
- $amCoordinateSystem : array<string|int, mixed>
-
The coordinate system to patch.
Tags
Return values
array<string|int, mixed> —The modified coordinate system structure.
