Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes issue #75 #110

Merged
merged 6 commits into from
Dec 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion poishadow/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ repositories {
dependencies {
implementation 'org.apache.poi:poi-ooxml:5.2.5'
implementation 'org.apache.poi:poi-scratchpad:5.2.5'

implementation 'com.fasterxml:aalto-xml:1.3.0'
implementation 'stax:stax-api:1.0.1'
implementation 'org.apache.logging.log4j:log4j-api:2.21.1' // newer log4j fails
Expand Down Expand Up @@ -45,6 +44,14 @@ shadowJar {
// java.awt is not available, but class Color is used in APIs in POI, therefore
// relocate this class to another one where we can include a rewrite
relocate 'java.awt.Color', 'org.apache.poi.java.awt.Color'
relocate 'java.awt.geom.Dimension2D', 'org.apache.poi.java.awt.geom.Dimension2D'
relocate 'java.awt.Dimension', 'org.apache.poi.java.awt.Dimension'
relocate 'java.awt.image.BufferedImage', 'org.apache.poi.java.awt.image.BufferedImage'

relocate 'javax.imageio.ImageIO', 'org.apache.poi.javax.imageio.ImageIO'
relocate 'javax.imageio.ImageReader', 'org.apache.poi.javax.imageio.ImageReader'
relocate 'javax.imageio.stream.ImageInputStream', 'org.apache.poi.javax.imageio.stream.ImageInputStream'
relocate 'javax.imageio.metadata.IIOMetadata', 'org.apache.poi.javax.imageio.metadata.IIOMetadata'
}

jar.dependsOn shadowJar
Expand Down
202 changes: 202 additions & 0 deletions poishadow/src/main/java/org/apache/poi/java/awt/Dimension.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
package org.apache.poi.java.awt;

import java.awt.geom.Dimension2D;
import java.beans.Transient;

/**
* The {@code Dimension} class encapsulates the width and
* height of a component (in integer precision) in a single object.
* The class is
* associated with certain properties of components. Several methods
* defined by the {@code Component} class and the
* {@code LayoutManager} interface return a
* {@code Dimension} object.
* <p>
* Normally the values of {@code width}
* and {@code height} are non-negative integers.
* The constructors that allow you to create a dimension do
* not prevent you from setting a negative value for these properties.
* If the value of {@code width} or {@code height} is
* negative, the behavior of some methods defined by other objects is
* undefined.
*
* @author Sami Shaio
* @author Arthur van Hoff
* @see java.awt.Component
* @see java.awt.LayoutManager
* @since 1.0
*/
public class Dimension extends Dimension2D implements java.io.Serializable {

/**
* The width dimension; negative values can be used.
*
* @serial
* @see #getSize
* @see #setSize
* @since 1.0
*/
public int width;

/**
* The height dimension; negative values can be used.
*
* @serial
* @see #getSize
* @see #setSize
* @since 1.0
*/
public int height;

/*
* JDK 1.1 serialVersionUID
*/
private static final long serialVersionUID = 4723952579491349524L;


/**
* Creates an instance of {@code Dimension} with a width
* of zero and a height of zero.
*/
public Dimension() {
this(0, 0);
}

/**
* Creates an instance of {@code Dimension} whose width
* and height are the same as for the specified dimension.
*
* @param d the specified dimension for the
* {@code width} and
* {@code height} values
*/
public Dimension(java.awt.Dimension d) {
this(d.width, d.height);
}

/**
* Constructs a {@code Dimension} and initializes
* it to the specified width and specified height.
*
* @param width the specified width
* @param height the specified height
*/
public Dimension(int width, int height) {
this.width = width;
this.height = height;
}

/**
* {@inheritDoc}
* @since 1.2
*/
public double getWidth() {
return width;
}

/**
* {@inheritDoc}
* @since 1.2
*/
public double getHeight() {
return height;
}

/**
* Sets the size of this {@code Dimension} object to
* the specified width and height in double precision.
* Note that if {@code width} or {@code height}
* are larger than {@code Integer.MAX_VALUE}, they will
* be reset to {@code Integer.MAX_VALUE}.
*
* @param width the new width for the {@code Dimension} object
* @param height the new height for the {@code Dimension} object
* @since 1.2
*/
public void setSize(double width, double height) {
this.width = (int) Math.ceil(width);
this.height = (int) Math.ceil(height);
}

/**
* Gets the size of this {@code Dimension} object.
* This method is included for completeness, to parallel the
* {@code getSize} method defined by {@code Component}.
*
* @return the size of this dimension, a new instance of
* {@code Dimension} with the same width and height
* @see java.awt.Dimension#setSize
* @see java.awt.Component#getSize
* @since 1.1
*/
@Transient
public java.awt.Dimension getSize() {
return new java.awt.Dimension(width, height);
}

/**
* Sets the size of this {@code Dimension} object to the specified size.
* This method is included for completeness, to parallel the
* {@code setSize} method defined by {@code Component}.
* @param d the new size for this {@code Dimension} object
* @see java.awt.Dimension#getSize
* @see java.awt.Component#setSize
* @since 1.1
*/
public void setSize(java.awt.Dimension d) {
setSize(d.width, d.height);
}

/**
* Sets the size of this {@code Dimension} object
* to the specified width and height.
* This method is included for completeness, to parallel the
* {@code setSize} method defined by {@code Component}.
*
* @param width the new width for this {@code Dimension} object
* @param height the new height for this {@code Dimension} object
* @see java.awt.Dimension#getSize
* @see java.awt.Component#setSize
* @since 1.1
*/
public void setSize(int width, int height) {
this.width = width;
this.height = height;
}

/**
* Checks whether two dimension objects have equal values.
*/
public boolean equals(Object obj) {
if (obj instanceof java.awt.Dimension) {
java.awt.Dimension d = (java.awt.Dimension)obj;
return (width == d.width) && (height == d.height);
}
return false;
}

/**
* Returns the hash code for this {@code Dimension}.
*
* @return a hash code for this {@code Dimension}
*/
public int hashCode() {
int sum = width + height;
return sum * (sum + 1)/2 + width;
}

/**
* Returns a string representation of the values of this
* {@code Dimension} object's {@code height} and
* {@code width} fields. This method is intended to be used only
* for debugging purposes, and the content and format of the returned
* string may vary between implementations. The returned string may be
* empty but may not be {@code null}.
*
* @return a string representation of this {@code Dimension}
* object
*/
public String toString() {
return getClass().getName() + "[width=" + width + ",height=" + height + "]";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package org.apache.poi.java.awt.geom;


/**
* The {@code Dimension2D} class is to encapsulate a width
* and a height dimension.
* <p>
* This class is only the abstract superclass for all objects that
* store a 2D dimension.
* The actual storage representation of the sizes is left to
* the subclass.
*
* @author Jim Graham
* @since 1.2
*/
public abstract class Dimension2D implements Cloneable {

/**
* This is an abstract class that cannot be instantiated directly.
* Type-specific implementation subclasses are available for
* instantiation and provide a number of formats for storing
* the information necessary to satisfy the various accessor
* methods below.
*
* @see java.awt.Dimension
* @since 1.2
*/
protected Dimension2D() {
}

/**
* Returns the width of this {@code Dimension} in double
* precision.
* @return the width of this {@code Dimension}.
* @since 1.2
*/
public abstract double getWidth();

/**
* Returns the height of this {@code Dimension} in double
* precision.
* @return the height of this {@code Dimension}.
* @since 1.2
*/
public abstract double getHeight();

/**
* Sets the size of this {@code Dimension} object to the
* specified width and height.
* This method is included for completeness, to parallel the
* {@link java.awt.Component#getSize getSize} method of
* {@link java.awt.Component}.
* @param width the new width for the {@code Dimension}
* object
* @param height the new height for the {@code Dimension}
* object
* @since 1.2
*/
public abstract void setSize(double width, double height);

/**
* Sets the size of this {@code Dimension2D} object to
* match the specified size.
* This method is included for completeness, to parallel the
* {@code getSize} method of {@code Component}.
* @param d the new size for the {@code Dimension2D}
* object
* @since 1.2
*/
public void setSize(java.awt.geom.Dimension2D d) {
setSize(d.getWidth(), d.getHeight());
}

/**
* Creates a new object of the same class as this object.
*
* @return a clone of this instance.
* @exception OutOfMemoryError if there is not enough memory.
* @see java.lang.Cloneable
* @since 1.2
*/
public Object clone() {
try {
return super.clone();
} catch (CloneNotSupportedException e) {
// this shouldn't happen, since we are Cloneable
throw new InternalError(e);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package org.apache.poi.java.awt.image;

/**
* Shadow class for java.awt.image.BufferedImage. Adds some compatibility to systems that do
* not have access to javax.awt.
*/
public class BufferedImage {
/**
* The pixel width of the image.
*/
private final int width;

/**
* The pixel height of the image.
*/
private final int height;

/**
* Constructor
*
* @param width The pixel width of the image.
* @param height The pixel height of the image.
*/
public BufferedImage(int width, int height) {
this.width = width;
this.height = height;
}

/**
* Returns The pixel width of the image.
*
* @return The pixel width of the image.
*/
public int getWidth() {
return width;
}

/**
* Returns The pixel height of the image.
*
* @return The pixel height of the image.
*/
public int getHeight() {
return height;
}

}
Loading
Loading