Class AbstractGradientBuilder
java.lang.Object
com.itextpdf.kernel.colors.gradients.AbstractGradientBuilder
- All Implemented Interfaces:
-
IGradientBuilder
- Direct Known Subclasses:
-
AbstractLinearGradientBuilder,AbstractRadialGradientBuilder
Base class for gradient builders implementations.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddStopColor(GradientColorStop gradientColorStop) Adds the new color stop to the end (more info).buildColor(Rectangle targetBoundingBox, AffineTransform contextTransform, PdfDocument document) Builds theColorobject representing the gradient with specified configuration that fills the target bounding box.protected abstract double[]computeCoveringDomain(T[] coords, Rectangle toCover) Computes the minimal domain that covers the box with vector normals.protected abstract PdfArraycreateCoordsDictEntry(T[] coordinates) Converts gradient vector into pdf coordinates array for shading.protected abstract T[]createCoordsForNewDomain(double[] newDomain, T[] baseVector) Expand the base vector to cover the new domainprotected abstract T[]createCoveringCoordinates(Rectangle targetBoundingBox) Creates some gradient vector which would cover the target bounding box.protected abstract AbstractPdfShadingcreatePdfShading(PdfColorSpace colorSpace, PdfArray coordinates, PdfArray coordinatesDomain, IPdfFunction stopsFunction) Creates the gradient shading object.protected abstract doublegetBaseVectorLength(T[] coordinates) Evaluates base vector length for future color stops spreading.protected Tuple2<T[],AffineTransform> getGradientVectorWithTransform(Rectangle targetBoundingBox, AffineTransform contextTransform) Returns the base gradient vector in gradient vector space and the current space to gradient vector space transformations that should be applied to the shading color.Get the current spread methodGet the copy of current color stops list.protected static AffineTransformgetToIntervalTransform(Point domainStart, Point domainEnd, double scale) ConstructsAffineTransformwhich represents transformation from current coordinates into the coordinates in which domainStart would be (0,0), domain end would be on X axes (i.e.protected static booleanisZero(double d) Checks whether the argument is close to 0setSpread(GradientSpreadMethod gradientSpreadMethod) Set the spread method to use for the gradient.setSvgLuminanceMode(boolean svgLuminanceMode) Sets whether to build a DeviceGray gradient using the SVG luminance coefficients.
-
Constructor Details
-
AbstractGradientBuilder
public AbstractGradientBuilder()
-
-
Method Details
-
addStopColor
Adds the new color stop to the end (more info).Note: if the previously added color stop's offset would have greater offset than the added one, then the new offset would be normalized to be equal to the previous one. (Comparison made between relative on coordinates vector offsets. If any of them has the absolute offset, then the absolute value would be converted to relative first.)
- Specified by:
-
addStopColorin interfaceIGradientBuilder - Parameters:
-
gradientColorStop- the gradient stop color to add - Returns:
- the current builder instance
-
setSpread
Set the spread method to use for the gradient.- Specified by:
-
setSpreadin interfaceIGradientBuilder - Parameters:
-
gradientSpreadMethod- the gradient spread method to set - Returns:
- the current builder instance
-
setSvgLuminanceMode
Sets whether to build a DeviceGray gradient using the SVG luminance coefficients. This method is SVG-specific because PDF and SVG use different luminance formulas. By default, gradients are built in DeviceRGB. The original RGB stop colors are not modified.- Specified by:
-
setSvgLuminanceModein interfaceIGradientBuilder - Parameters:
-
svgLuminanceMode-trueto build a luminance gradient,falseto build an RGB gradient - Returns:
- the current builder instance
-
getStopColors
Get the copy of current color stops list. Note that the stop colors are not copied here- Returns:
- the copy of current stop colors list
-
getSpread
Get the current spread method- Returns:
- the current spread method
-
buildColor
public Color buildColor(Rectangle targetBoundingBox, AffineTransform contextTransform, PdfDocument document) Builds theColorobject representing the gradient with specified configuration that fills the target bounding box.- Specified by:
-
buildColorin interfaceIGradientBuilder - Parameters:
-
targetBoundingBox- the bounding box to be filled in current space -
contextTransform- the transformation from the base coordinates space into the current space. Thenullvalue is valid and can be used if there is no transformation from base coordinates to current space specified, or it is equal to identity transformation. -
document- thePdfDocumentfor which the linear gradient would be built. - Returns:
-
the constructed
Colorornullif no color to be applied or base gradient vector has been specified
-
getGradientVectorWithTransform
protected Tuple2<T[],AffineTransform> getGradientVectorWithTransform(Rectangle targetBoundingBox, AffineTransform contextTransform) Returns the base gradient vector in gradient vector space and the current space to gradient vector space transformations that should be applied to the shading color.The vector would be set as shading coordinates vector and its length would be used to translate all color stops absolute offsets into the relatives.
The transformation should be invertible as the current target bounding box coordinates should be transformed into the resulted shading space coordinates.
- Parameters:
-
targetBoundingBox- the rectangle to be covered by constructed color in current space -
contextTransform- the current canvas transformation - Returns:
-
the pair of the vector, which is an array of exactly two elements specifying the gradient coordinates vector, and the additional transformation to be concatenated to the current for resulted shading or
nullif no additional transformation is specified
-
computeCoveringDomain
Computes the minimal domain that covers the box with vector normals. The domain corresponding to the initial vector is [0, 1].- Parameters:
-
coords- the array of exactly two elements that describe the base vector (corresponding to [0,1] domain, that need to be adjusted to cover the box -
toCover- the box that needs to be covered - Returns:
- the array of two elements in ascending order specifying the calculated covering domain
-
createCoordsForNewDomain
Expand the base vector to cover the new domain- Parameters:
-
newDomain- the array of exactly two elements that specifies the domain that should be covered by the created vector -
baseVector- the array of exactly two elements that specifies the base vector which corresponds to [0, 1] domain - Returns:
- the array of two
-
createCoveringCoordinates
Creates some gradient vector which would cover the target bounding box.- Parameters:
-
targetBoundingBox- the bounding box to cover - Returns:
- constructed gradient vector
-
getBaseVectorLength
Evaluates base vector length for future color stops spreading.- Parameters:
-
coordinates- the base vector - Returns:
- base vector length
-
createCoordsDictEntry
Converts gradient vector into pdf coordinates array for shading.- Parameters:
-
coordinates- vector to convert - Returns:
- constructed pdf array
-
createPdfShading
protected abstract AbstractPdfShading createPdfShading(PdfColorSpace colorSpace, PdfArray coordinates, PdfArray coordinatesDomain, IPdfFunction stopsFunction) Creates the gradient shading object.- Parameters:
-
colorSpace- colorspace to use -
coordinates- gradient coordinates -
coordinatesDomain- gradient coordinates domain -
stopsFunction- color stops function - Returns:
- constructed gradient shading
-
getToIntervalTransform
protected static AffineTransform getToIntervalTransform(Point domainStart, Point domainEnd, double scale) ConstructsAffineTransformwhich represents transformation from current coordinates into the coordinates in which domainStart would be (0,0), domain end would be on X axes (i.e. (X,0) coordinate) and the surface scaled both on X and Y byscalefactor.- Parameters:
-
domainStart- the point to become (0,0) -
domainEnd- the point to be placed on X axes -
scale- the scale factor - Returns:
- the constructed transformation
-
isZero
protected static boolean isZero(double d) Checks whether the argument is close to 0- Parameters:
-
d- to check - Returns:
-
trueif the argument is close to 0
-