📄 image.java
字号:
return !Float.isNaN(absoluteY);
}
/**
* Returns the absolute Y position.
*
* @return a position
*/
public float getAbsoluteY() {
return absoluteY;
}
// width and height
/**
* Gets the scaled width of the image.
*
* @return a value
*/
public float getScaledWidth() {
return scaledWidth;
}
/**
* Gets the scaled height of the image.
*
* @return a value
*/
public float getScaledHeight() {
return scaledHeight;
}
/**
* Gets the plain width of the image.
*
* @return a value
*/
public float getPlainWidth() {
return plainWidth;
}
/**
* Gets the plain height of the image.
*
* @return a value
*/
public float getPlainHeight() {
return plainHeight;
}
/**
* Scale the image to an absolute width and an absolute height.
*
* @param newWidth
* the new width
* @param newHeight
* the new height
*/
public void scaleAbsolute(float newWidth, float newHeight) {
plainWidth = newWidth;
plainHeight = newHeight;
float[] matrix = matrix();
scaledWidth = matrix[DX] - matrix[CX];
scaledHeight = matrix[DY] - matrix[CY];
}
/**
* Scale the image to an absolute width.
*
* @param newWidth
* the new width
*/
public void scaleAbsoluteWidth(float newWidth) {
plainWidth = newWidth;
float[] matrix = matrix();
scaledWidth = matrix[DX] - matrix[CX];
scaledHeight = matrix[DY] - matrix[CY];
}
/**
* Scale the image to an absolute height.
*
* @param newHeight
* the new height
*/
public void scaleAbsoluteHeight(float newHeight) {
plainHeight = newHeight;
float[] matrix = matrix();
scaledWidth = matrix[DX] - matrix[CX];
scaledHeight = matrix[DY] - matrix[CY];
}
/**
* Scale the image to a certain percentage.
*
* @param percent
* the scaling percentage
*/
public void scalePercent(float percent) {
scalePercent(percent, percent);
}
/**
* Scale the width and height of an image to a certain percentage.
*
* @param percentX
* the scaling percentage of the width
* @param percentY
* the scaling percentage of the height
*/
public void scalePercent(float percentX, float percentY) {
plainWidth = (getWidth() * percentX) / 100f;
plainHeight = (getHeight() * percentY) / 100f;
float[] matrix = matrix();
scaledWidth = matrix[DX] - matrix[CX];
scaledHeight = matrix[DY] - matrix[CY];
}
/**
* Scales the image so that it fits a certain width and height.
*
* @param fitWidth
* the width to fit
* @param fitHeight
* the height to fit
*/
public void scaleToFit(float fitWidth, float fitHeight) {
scalePercent(100);
float percentX = (fitWidth * 100) / getScaledWidth();
float percentY = (fitHeight * 100) / getScaledHeight();
scalePercent(percentX < percentY ? percentX : percentY);
}
/**
* Returns the transformation matrix of the image.
*
* @return an array [AX, AY, BX, BY, CX, CY, DX, DY]
*/
public float[] matrix() {
float[] matrix = new float[8];
float cosX = (float) Math.cos(rotationRadians);
float sinX = (float) Math.sin(rotationRadians);
matrix[AX] = plainWidth * cosX;
matrix[AY] = plainWidth * sinX;
matrix[BX] = (-plainHeight) * sinX;
matrix[BY] = plainHeight * cosX;
if (rotationRadians < Math.PI / 2f) {
matrix[CX] = matrix[BX];
matrix[CY] = 0;
matrix[DX] = matrix[AX];
matrix[DY] = matrix[AY] + matrix[BY];
} else if (rotationRadians < Math.PI) {
matrix[CX] = matrix[AX] + matrix[BX];
matrix[CY] = matrix[BY];
matrix[DX] = 0;
matrix[DY] = matrix[AY];
} else if (rotationRadians < Math.PI * 1.5f) {
matrix[CX] = matrix[AX];
matrix[CY] = matrix[AY] + matrix[BY];
matrix[DX] = matrix[BX];
matrix[DY] = 0;
} else {
matrix[CX] = 0;
matrix[CY] = matrix[AY];
matrix[DX] = matrix[AX] + matrix[BX];
matrix[DY] = matrix[BY];
}
return matrix;
}
// serial stamping
/** a static that is used for attributing a unique id to each image. */
static long serialId = 0;
/** Creates a new serial id. */
static protected synchronized Long getSerialId() {
++serialId;
return new Long(serialId);
}
/**
* Returns a serial id for the Image (reuse the same image more than once)
*
* @return a serialId
*/
public Long getMySerialId() {
return mySerialId;
}
// rotation, note that the superclass also has a rotation value.
/** This is the rotation of the image in radians. */
protected float rotationRadians;
/** Holds value of property initialRotation. */
private float initialRotation;
/**
* Gets the current image rotation in radians.
* @return the current image rotation in radians
*/
public float getImageRotation() {
double d = 2.0 * Math.PI;
float rot = (float) ((rotationRadians - initialRotation) % d);
if (rot < 0) {
rot += d;
}
return rot;
}
/**
* Sets the rotation of the image in radians.
*
* @param r
* rotation in radians
*/
public void setRotation(float r) {
double d = 2.0 * Math.PI;
rotationRadians = (float) ((r + initialRotation) % d);
if (rotationRadians < 0) {
rotationRadians += d;
}
float[] matrix = matrix();
scaledWidth = matrix[DX] - matrix[CX];
scaledHeight = matrix[DY] - matrix[CY];
}
/**
* Sets the rotation of the image in degrees.
*
* @param deg
* rotation in degrees
*/
public void setRotationDegrees(float deg) {
double d = Math.PI;
setRotation(deg / 180 * (float) d);
}
/**
* Getter for property initialRotation.
* @return Value of property initialRotation.
*/
public float getInitialRotation() {
return this.initialRotation;
}
/**
* Some image formats, like TIFF may present the images rotated that have
* to be compensated.
* @param initialRotation New value of property initialRotation.
*/
public void setInitialRotation(float initialRotation) {
float old_rot = rotationRadians - this.initialRotation;
this.initialRotation = initialRotation;
setRotation(old_rot);
}
// indentations
/** the indentation to the left. */
protected float indentationLeft = 0;
/** the indentation to the right. */
protected float indentationRight = 0;
/** The spacing before the image. */
protected float spacingBefore;
/** The spacing after the image. */
protected float spacingAfter;
/**
* Gets the left indentation.
*
* @return the left indentation
*/
public float getIndentationLeft() {
return indentationLeft;
}
/**
* Sets the left indentation.
*
* @param f
*/
public void setIndentationLeft(float f) {
indentationLeft = f;
}
/**
* Gets the right indentation.
*
* @return the right indentation
*/
public float getIndentationRight() {
return indentationRight;
}
/**
* Sets the right indentation.
*
* @param f
*/
public void setIndentationRight(float f) {
indentationRight = f;
}
/**
* Gets the spacing before this image.
*
* @return the spacing
*/
public float getSpacingBefore() {
return spacingBefore;
}
/**
* Sets the spacing before this image.
*
* @param spacing
* the new spacing
*/
public void setSpacingBefore(float spacing) {
this.spacingBefore = spacing;
}
/**
* Gets the spacing before this image.
*
* @return the spacing
*/
public float getSpacingAfter() {
return spacingAfter;
}
/**
* Sets the spacing after this image.
*
* @param spacing
* the new spacing
*/
public void setSpacingAfter(float spacing) {
this.spacingAfter = spacing;
}
// widthpercentage (for the moment only used in ColumnText)
/**
* Holds value of property widthPercentage.
*/
private float widthPercentage = 100;
/**
* Getter for property widthPercentage.
*
* @return Value of property widthPercentage.
*/
public float getWidthPercentage() {
return this.widthPercentage;
}
/**
* Setter for property widthPercentage.
*
* @param widthPercentage
* New value of property widthPercentage.
*/
public void setWidthPercentage(float widthPercentage) {
this.widthPercentage = widthPercentage;
}
// annotation
/** if the annotation is not null the image will be clickable. */
protected Annotation annotation = null;
/**
* Sets the annotation of this Image.
*
* @param annotation
* the annotation
*/
public void setAnnotation(Annotation annotation) {
this.annotation = annotation;
}
/**
* Gets the annotation.
*
* @return the annotation that is linked to this image
*/
public Annotation getAnnotation() {
return annotation;
}
// Optional Content
/** Optional Content layer to which we want this Image to belong. */
protected PdfOCG layer;
/**
* Gets the layer this image belongs to.
*
* @return the layer this image belongs to or <code>null</code> for no
* layer defined
*/
public PdfOCG getLayer() {
return layer;
}
/**
* Sets the layer this image belongs to.
*
* @param layer
* the layer this image belongs to
*/
public void setLayer(PdfOCG layer) {
this.layer = layer;
}
// interpolation
/** Holds value of property interpolation. */
protected boolean interpolation;
/**
* Getter for property interpolation.
*
* @return Value of property interpolation.
*/
public boolean isInterpolation() {
return interpolation;
}
/**
* Sets the image interpolation. Image interpolation attempts to produce a
* smooth transition between adjacent sample values.
*
* @param interpolation
* New value of property interpolation.
*/
public void setInterpolation(boolean interpolation) {
this.interpolation = interpolation;
}
// original type and data
/** Holds value of property originalType. */
protected int originalType = ORIGINAL_NONE;
/** Holds value of property originalData. */
protected byte[] originalData;
/**
* Getter for property originalType.
*
* @return Value of property originalType.
*
*/
public int getOriginalType() {
return this.originalType;
}
/**
* Setter for property originalType.
*
* @param originalType
* New value of property originalType.
*
*/
public void setOriginalType(int originalType) {
this.originalType = originalType;
}
/**
* Getter for property originalData.
*
* @return Value of property originalData.
*
*/
public byte[] getOriginalData() {
return this.originalData;
}
/**
* Setter for property originalData.
*
* @param originalData
* New value of property originalData.
*
*/
public void setOriginalData(byte[] originalData) {
this.originalData = originalData;
}
// the following values are only set for specific types of images.
/** Holds value of property deflated. */
protected boolean deflated = false;
/**
* Getter for property deflated.
*
* @return Value of property deflated.
*
*/
public boolean isDeflated() {
return this.deflated;
}
/**
* Setter for property deflated.
*
* @param deflated
* New value of property deflated.
*/
public void setDeflated(boolean deflated) {
this.deflated = deflated;
}
// DPI info
/** Holds value of property dpiX. */
protected int dpiX = 0;
/** Holds value of property dpiY. */
protected int dpiY = 0;
/**
* Gets the dots-per-inch in the X direction. Returns 0 if not available.
*
* @return the dots-per-inch in the X direction
*/
public int getDpiX() {
return dpiX;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -