fix IntelliJ warnings

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1874338 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andreas Beeker 2020-02-21 21:14:31 +00:00
parent fd4410d50b
commit 159ad62a47
22 changed files with 213 additions and 232 deletions

View File

@ -96,10 +96,10 @@ public class HemfComment {
*
* @param ctx the graphics context to modify
*/
default void draw(HemfGraphics ctx) {};
default void draw(HemfGraphics ctx) {}
@Override
default Enum getGenericRecordType() {
default HemfCommentRecordType getGenericRecordType() {
return getCommentRecordType();
}
}
@ -137,6 +137,14 @@ public class HemfComment {
public Map<String, Supplier<?>> getGenericProperties() {
return GenericRecordUtil.getGenericProperties("data", this::getCommentData);
}
static void validateCommentType(final LittleEndianInputStream leis, HemfCommentRecordType commentType) {
int commentIdentifier = (int)leis.readUInt();
if (commentIdentifier == HemfCommentRecordType.emfPublic.id) {
commentIdentifier = (int)leis.readUInt();
}
assert(commentIdentifier == commentType.id);
}
}
public static class EmfCommentDataIterator implements Iterator<EmfCommentData> {
@ -172,20 +180,19 @@ public class HemfComment {
}
private EmfCommentData _next() {
long type, recordSize;
long recordSize;
if (currentRecord == null && emfParent) {
type = HemfRecordType.comment.id;
recordSize = limit;
} else {
// A 32-bit unsigned integer from the RecordType enumeration that identifies this record
// as a comment record. This value MUST be 0x00000046.
try {
type = leis.readUInt();
long type = leis.readUInt();
assert(type == HemfRecordType.comment.id);
} catch (RuntimeException e) {
// EOF
return null;
}
assert(type == HemfRecordType.comment.id);
// A 32-bit unsigned integer that specifies the size in bytes of this record in the
// metafile. This value MUST be a multiple of 4 bytes.
recordSize = leis.readUInt();
@ -288,9 +295,8 @@ public class HemfComment {
@Override
public long init(final LittleEndianInputStream leis, final long dataSize)
throws IOException {
long startIdx = leis.getReadIndex();
int commentIdentifier = leis.readInt();
assert (commentIdentifier == HemfCommentRecordType.emfPlus.id);
final int startIdx = leis.getReadIndex();
EmfComment.validateCommentType(leis, HemfCommentRecordType.emfPlus);
new HemfPlusRecordIterator(leis, (int)dataSize-LittleEndianConsts.INT_SIZE).forEachRemaining(records::add);
return leis.getReadIndex()-startIdx;
}
@ -328,13 +334,9 @@ public class HemfComment {
}
@Override
public long init(final LittleEndianInputStream leis, final long dataSize)
throws IOException {
public long init(final LittleEndianInputStream leis, final long dataSize) throws IOException {
final int startIdx = leis.getReadIndex();
final int commentIdentifier = (int)leis.readUInt();
assert(commentIdentifier == HemfCommentRecordType.emfPublic.id);
final int publicCommentIdentifier = (int)leis.readUInt();
assert(publicCommentIdentifier == HemfCommentRecordType.emfBeginGroup.id);
EmfComment.validateCommentType(leis, HemfCommentRecordType.emfBeginGroup);
HemfDraw.readRectL(leis, bounds);
// The number of Unicode characters in the optional description string that follows.
@ -347,6 +349,7 @@ public class HemfComment {
return leis.getReadIndex()-startIdx;
}
public Rectangle2D getBounds() {
return bounds;
}
@ -374,10 +377,7 @@ public class HemfComment {
public long init(final LittleEndianInputStream leis, final long dataSize)
throws IOException {
final int startIdx = leis.getReadIndex();
final int commentIdentifier = (int)leis.readUInt();
assert(commentIdentifier == HemfCommentRecordType.emfPublic.id);
final int publicCommentIdentifier = (int)leis.readUInt();
assert(publicCommentIdentifier == HemfCommentRecordType.emfEndGroup.id);
EmfComment.validateCommentType(leis, HemfCommentRecordType.emfEndGroup);
return leis.getReadIndex()-startIdx;
}
@ -397,13 +397,9 @@ public class HemfComment {
}
@Override
public long init(final LittleEndianInputStream leis, final long dataSize)
throws IOException {
public long init(final LittleEndianInputStream leis, final long dataSize) throws IOException {
final int startIdx = leis.getReadIndex();
final int commentIdentifier = (int)leis.readUInt();
assert(commentIdentifier == HemfCommentRecordType.emfPublic.id);
final int publicCommentIdentifier = (int)leis.readUInt();
assert(publicCommentIdentifier == HemfCommentRecordType.emfMultiFormats.id);
EmfComment.validateCommentType(leis, HemfCommentRecordType.emfMultiFormats);
HemfDraw.readRectL(leis, bounds);
// A 32-bit unsigned integer that specifies the number of graphics formats contained in this record.
@ -487,6 +483,7 @@ public class HemfComment {
private int offData;
private byte[] rawData;
@SuppressWarnings("unused")
public long init(final LittleEndianInputStream leis, final long dataSize, long startIdx) throws IOException {
// A 32-bit unsigned integer that specifies the format of the image data.
signature = EmfFormatSignature.getById(leis.readInt());
@ -539,13 +536,11 @@ public class HemfComment {
return HemfCommentRecordType.emfWMF;
}
@SuppressWarnings("unused")
@Override
public long init(final LittleEndianInputStream leis, final long dataSize) throws IOException {
final int startIdx = leis.getReadIndex();
final int commentIdentifier = (int)leis.readUInt();
assert(commentIdentifier == HemfCommentRecordType.emfPublic.id);
final int publicCommentIdentifier = (int)leis.readUInt();
assert(publicCommentIdentifier == HemfCommentRecordType.emfWMF.id);
EmfComment.validateCommentType(leis, HemfCommentRecordType.emfWMF);
// A 16-bit unsigned integer that specifies the WMF metafile version in terms
//of support for device-independent bitmaps (DIBs)

View File

@ -42,7 +42,9 @@ import org.apache.poi.util.GenericRecordUtil;
import org.apache.poi.util.LittleEndianConsts;
import org.apache.poi.util.LittleEndianInputStream;
public class HemfDraw {
public final class HemfDraw {
private HemfDraw() {}
/**
* The EMR_SELECTOBJECT record adds a graphics object to the current metafile playback device
* context. The object is specified either by its index in the EMF Object Table or by its
@ -102,7 +104,7 @@ public class HemfDraw {
}
@Override
public Enum getGenericRecordType() {
public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
@ -212,7 +214,7 @@ public class HemfDraw {
}
@Override
public Enum getGenericRecordType() {
public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
@ -313,7 +315,7 @@ public class HemfDraw {
}
@Override
public Enum getGenericRecordType() {
public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
@ -456,6 +458,7 @@ public class HemfDraw {
return readPointL(leis, point);
}
@SuppressWarnings("unused")
@Override
public long init(LittleEndianInputStream leis, long recordSize, long recordId) throws IOException {
long size = readRectL(leis, bounds);
@ -521,7 +524,7 @@ public class HemfDraw {
}
@Override
public Enum getGenericRecordType() {
public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
@ -593,7 +596,7 @@ public class HemfDraw {
}
@Override
public Enum getGenericRecordType() {
public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
@ -618,7 +621,7 @@ public class HemfDraw {
}
@Override
public Enum getGenericRecordType() {
public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
@ -647,7 +650,7 @@ public class HemfDraw {
}
@Override
public Enum getGenericRecordType() {
public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
@ -677,7 +680,7 @@ public class HemfDraw {
}
@Override
public Enum getGenericRecordType() {
public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
@ -706,7 +709,7 @@ public class HemfDraw {
}
@Override
public Enum getGenericRecordType() {
public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
@ -733,7 +736,7 @@ public class HemfDraw {
}
@Override
public Enum getGenericRecordType() {
public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
@ -759,7 +762,7 @@ public class HemfDraw {
}
@Override
public Enum getGenericRecordType() {
public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
@ -792,7 +795,7 @@ public class HemfDraw {
}
@Override
public Enum getGenericRecordType() {
public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
@ -818,7 +821,7 @@ public class HemfDraw {
}
@Override
public Enum getGenericRecordType() {
public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
@ -848,7 +851,7 @@ public class HemfDraw {
}
@Override
public Enum getGenericRecordType() {
public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
@ -958,7 +961,7 @@ public class HemfDraw {
}
@Override
public Enum getGenericRecordType() {
public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
@ -1215,8 +1218,6 @@ public class HemfDraw {
* path by using the current pen, and fills its interior by using the current brush.
*/
public static class EmfStrokeAndFillPath extends EmfStrokePath {
protected final Rectangle2D bounds = new Rectangle2D.Double();
@Override
public HemfRecordType getEmfRecordType() {
return HemfRecordType.strokeAndFillPath;

View File

@ -53,8 +53,8 @@ import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.LittleEndianConsts;
import org.apache.poi.util.LittleEndianInputStream;
public class HemfFill {
private static final int MAX_RECORD_LENGTH = 10_000_000;
public final class HemfFill {
private HemfFill() {}
/**
* The EMR_SETPOLYFILLMODE record defines polygon fill mode.
@ -75,7 +75,7 @@ public class HemfFill {
}
@Override
public Enum getGenericRecordType() {
public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
@ -98,7 +98,7 @@ public class HemfFill {
}
@Override
public Enum getGenericRecordType() {
public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
@ -224,7 +224,7 @@ public class HemfFill {
}
@Override
public Enum getGenericRecordType() {
public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
@ -309,7 +309,7 @@ public class HemfFill {
}
@Override
public Enum getGenericRecordType() {
public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
@ -341,6 +341,7 @@ public class HemfFill {
return HemfRecordType.frameRgn;
}
@SuppressWarnings("unused")
@Override
public long init(LittleEndianInputStream leis, long recordSize, long recordId) throws IOException {
long size = readRectL(leis, bounds);
@ -386,7 +387,7 @@ public class HemfFill {
}
@Override
public Enum getGenericRecordType() {
public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
@ -401,6 +402,7 @@ public class HemfFill {
return HemfRecordType.invertRgn;
}
@SuppressWarnings("unused")
@Override
public long init(LittleEndianInputStream leis, long recordSize, long recordId) throws IOException {
long size = readRectL(leis, bounds);
@ -453,6 +455,7 @@ public class HemfFill {
return HemfRecordType.fillRgn;
}
@SuppressWarnings("unused")
@Override
public long init(LittleEndianInputStream leis, long recordSize, long recordId) throws IOException {
long size = readRectL(leis, bounds);
@ -486,7 +489,7 @@ public class HemfFill {
}
@Override
public Enum getGenericRecordType() {
public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
@ -500,6 +503,7 @@ public class HemfFill {
return HemfRecordType.extSelectClipRgn;
}
@SuppressWarnings("unused")
@Override
public long init(LittleEndianInputStream leis, long recordSize, long recordId) throws IOException {
// A 32-bit unsigned integer that specifies the size of region data in bytes
@ -522,7 +526,6 @@ public class HemfFill {
@Override
public void draw(HemfGraphics ctx) {
HemfDrawProperties prop = ctx.getProperties();
ctx.setClip(getShape(), regionMode, true);
}
@ -692,6 +695,7 @@ public class HemfFill {
return HemfRecordType.setDiBitsToDevice;
}
@SuppressWarnings("unused")
@Override
public long init(LittleEndianInputStream leis, long recordSize, long recordId) throws IOException {
int startIdx = leis.getReadIndex();
@ -804,6 +808,7 @@ public class HemfFill {
}
@SuppressWarnings("unused")
static long readRgnData(final LittleEndianInputStream leis, final List<Rectangle2D> rgnRects) {
// *** RegionDataHeader ***
// A 32-bit unsigned integer that specifies the size of this object in bytes. This MUST be 0x00000020.
@ -873,7 +878,7 @@ public class HemfFill {
return 6 * LittleEndian.INT_SIZE;
}
protected static Shape getRgnShape(List<Rectangle2D> rgnRects) {
static Shape getRgnShape(List<Rectangle2D> rgnRects) {
if (rgnRects.size() == 1) {
return rgnRects.get(0);
}

View File

@ -237,6 +237,7 @@ public class HemfFont extends HwmfFont {
protected LogFontDetails details;
@SuppressWarnings("unused")
@Override
public int init(LittleEndianInputStream leis, long recordSize) throws IOException {
// A 32-bit signed integer that specifies the height, in logical units, of the font's
@ -517,7 +518,7 @@ public class HemfFont extends HwmfFont {
}
@Override
protected int readString(LittleEndianInputStream leis, StringBuilder sb, int limit) throws IOException {
protected int readString(LittleEndianInputStream leis, StringBuilder sb, int limit) {
sb.setLength(0);
byte[] buf = new byte[limit * 2];
leis.readFully(buf);

View File

@ -43,9 +43,6 @@ import org.apache.poi.util.LittleEndianInputStream;
@Internal
public class HemfHeader implements HemfRecord {
private static final int MAX_RECORD_LENGTH = 1_000_000;
private final Rectangle2D boundsRectangle = new Rectangle2D.Double();
private final Rectangle2D frameRectangle = new Rectangle2D.Double();
private long bytes;
@ -131,6 +128,7 @@ public class HemfHeader implements HemfRecord {
return HemfRecordType.header;
}
@SuppressWarnings("unused")
@Override
public long init(LittleEndianInputStream leis, long recordSize, long recordId) throws IOException {
if (recordId != HemfRecordType.header.id) {

View File

@ -100,6 +100,7 @@ public class HemfMisc {
return HemfRecordType.eof;
}
@SuppressWarnings("unused")
@Override
public long init(LittleEndianInputStream leis, long recordSize, long recordId) throws IOException {
final int startIdx = leis.getReadIndex();
@ -112,7 +113,7 @@ public class HemfMisc {
int size = 2 * LittleEndianConsts.INT_SIZE;
if (nPalEntries > 0 && offPalEntries > 0) {
int undefinedSpace1 = (int) (offPalEntries - (size + HEADER_SIZE));
int undefinedSpace1 = offPalEntries - (size + HEADER_SIZE);
assert (undefinedSpace1 >= 0);
leis.skipFully(undefinedSpace1);
size += undefinedSpace1;
@ -165,7 +166,7 @@ public class HemfMisc {
}
@Override
public Enum getGenericRecordType() {
public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
@ -191,7 +192,7 @@ public class HemfMisc {
}
@Override
public Enum getGenericRecordType() {
public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
@ -213,7 +214,7 @@ public class HemfMisc {
}
@Override
public Enum getGenericRecordType() {
public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
@ -240,7 +241,7 @@ public class HemfMisc {
}
@Override
public Enum getGenericRecordType() {
public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
@ -260,7 +261,7 @@ public class HemfMisc {
}
@Override
public Enum getGenericRecordType() {
public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
@ -283,7 +284,7 @@ public class HemfMisc {
}
@Override
public Enum getGenericRecordType() {
public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
@ -306,7 +307,7 @@ public class HemfMisc {
}
@Override
public Enum getGenericRecordType() {
public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
@ -331,7 +332,7 @@ public class HemfMisc {
}
@Override
public Enum getGenericRecordType() {
public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
@ -385,7 +386,7 @@ public class HemfMisc {
}
@Override
public Enum getGenericRecordType() {
public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
@ -454,7 +455,7 @@ public class HemfMisc {
}
@Override
public Enum getGenericRecordType() {
public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
@ -477,7 +478,7 @@ public class HemfMisc {
}
@Override
public Enum getGenericRecordType() {
public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
@ -538,7 +539,7 @@ public class HemfMisc {
}
@Override
public Enum getGenericRecordType() {
public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
@ -668,7 +669,7 @@ public class HemfMisc {
}
@Override
public Enum getGenericRecordType() {
public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}

View File

@ -48,7 +48,7 @@ public class HemfPalette {
}
@Override
public Enum getGenericRecordType() {
public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
@ -96,7 +96,7 @@ public class HemfPalette {
}
@Override
public Enum getGenericRecordType() {
public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
@ -144,7 +144,7 @@ public class HemfPalette {
}
@Override
public Enum getGenericRecordType() {
public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
@ -191,7 +191,7 @@ public class HemfPalette {
}
@Override
public Enum getGenericRecordType() {
public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
@ -212,7 +212,7 @@ public class HemfPalette {
}
@Override
public Enum getGenericRecordType() {
public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}

View File

@ -63,7 +63,7 @@ public interface HemfRecord extends GenericRecord {
default void setHeader(HemfHeader header) {}
@Override
default Enum getGenericRecordType() {
default HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}

View File

@ -225,7 +225,7 @@ public class HemfText {
}
@Override
public Enum getGenericRecordType() {
public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
@ -266,7 +266,7 @@ public class HemfText {
}
@Override
public Enum getGenericRecordType() {
public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
@ -286,7 +286,7 @@ public class HemfText {
}
@Override
public Enum getGenericRecordType() {
public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
@ -338,7 +338,7 @@ public class HemfText {
}
@Override
public Enum getGenericRecordType() {
public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}

View File

@ -53,7 +53,7 @@ public class HemfWindowing {
}
@Override
public Enum getGenericRecordType() {
public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
@ -73,7 +73,7 @@ public class HemfWindowing {
}
@Override
public Enum getGenericRecordType() {
public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
@ -93,7 +93,7 @@ public class HemfWindowing {
}
@Override
public Enum getGenericRecordType() {
public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
@ -113,7 +113,7 @@ public class HemfWindowing {
}
@Override
public Enum getGenericRecordType() {
public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
@ -134,7 +134,7 @@ public class HemfWindowing {
}
@Override
public Enum getGenericRecordType() {
public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
@ -155,7 +155,7 @@ public class HemfWindowing {
}
@Override
public Enum getGenericRecordType() {
public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
@ -176,7 +176,7 @@ public class HemfWindowing {
}
@Override
public Enum getGenericRecordType() {
public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
@ -197,7 +197,7 @@ public class HemfWindowing {
}
@Override
public Enum getGenericRecordType() {
public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
@ -218,7 +218,7 @@ public class HemfWindowing {
}
@Override
public Enum getGenericRecordType() {
public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}

View File

@ -251,6 +251,7 @@ public class HemfPlusBrush {
}
@SuppressWarnings("unused")
public interface EmfPlusBrushData extends GenericRecord {
/**
* This flag is meaningful in EmfPlusPathGradientBrushData objects.
@ -458,7 +459,7 @@ public class HemfPlusBrush {
}
@Override
public Enum getGenericRecordType() {
public EmfPlusBrushType getGenericRecordType() {
return EmfPlusBrushType.SOLID_COLOR;
}
@ -500,7 +501,7 @@ public class HemfPlusBrush {
}
@Override
public Enum getGenericRecordType() {
public EmfPlusBrushType getGenericRecordType() {
return EmfPlusBrushType.HATCH_FILL;
}
@ -600,7 +601,7 @@ public class HemfPlusBrush {
}
@Override
public Enum getGenericRecordType() {
public EmfPlusBrushType getGenericRecordType() {
return EmfPlusBrushType.LINEAR_GRADIENT;
}
@ -810,7 +811,7 @@ public class HemfPlusBrush {
@Override
public Enum getGenericRecordType() {
public EmfPlusBrushType getGenericRecordType() {
return EmfPlusBrushType.PATH_GRADIENT;
}
@ -884,7 +885,7 @@ public class HemfPlusBrush {
}
@Override
public Enum getGenericRecordType() {
public EmfPlusBrushType getGenericRecordType() {
return EmfPlusBrushType.TEXTURE_FILL;
}

View File

@ -62,9 +62,11 @@ import org.apache.poi.util.LittleEndianInputStream;
import org.apache.poi.util.StringUtil;
@SuppressWarnings("WeakerAccess")
public class HemfPlusDraw {
public final class HemfPlusDraw {
private static final int MAX_OBJECT_SIZE = 1_000_000;
private HemfPlusDraw() {}
public enum EmfPlusUnitType {
/** Specifies a unit of logical distance within the world space. */
World(0x00),
@ -126,9 +128,9 @@ public class HemfPlusDraw {
* If set, each element in PointData specifies a location in the coordinate space that is relative to the
* location specified by the previous element in the array. In the case of the first element in PointData,
* a previous location at coordinates (0,0) is assumed.
* If clear, PointData specifies absolute locations according to the {@link #isCompressed()} flag.
* If clear, PointData specifies absolute locations according to the {@link EmfPlusCompressed#isCompressed()} flag.
*
* Note If this flag is set, the {@link #isCompressed()} flag (above) is undefined and MUST be ignored.
* Note If this flag is set, the {@link EmfPlusCompressed#isCompressed()} flag (above) is undefined and MUST be ignored.
*/
BitField POSITION = BitFieldFactory.getInstance(0x0800);
@ -330,6 +332,7 @@ public class HemfPlusDraw {
}
/** The EmfPlusDrawImagePoints record specifies drawing a scaled image inside a parallelogram. */
@SuppressWarnings("unused")
public static class EmfPlusDrawImagePoints implements HemfPlusRecord, EmfPlusObjectId, EmfPlusCompressed, EmfPlusRelativePosition {
/**
* This bit indicates that the rendering of the image includes applying an effect.
@ -625,6 +628,7 @@ public class HemfPlusDraw {
}
/** The EmfPlusDrawDriverString record specifies text output with character positions. */
@SuppressWarnings("unused")
public static class EmfPlusDrawDriverString implements HemfPlusRecord, EmfPlusObjectId, EmfPlusSolidColor {
/**
* If set, the positions of character glyphs SHOULD be specified in a character map lookup table.

View File

@ -32,6 +32,7 @@ import java.io.InputStream;
import org.apache.poi.sl.draw.BitmapImageRenderer;
import org.apache.poi.util.IOUtils;
@SuppressWarnings("unused")
public class HemfPlusGDIImageRenderer extends BitmapImageRenderer {
private int width;
private int height;
@ -81,7 +82,7 @@ public class HemfPlusGDIImageRenderer extends BitmapImageRenderer {
}
@Override
public void loadImage(byte[] data, String contentType) throws IOException {
public void loadImage(byte[] data, String contentType) {
img = readGDIImage(data);
}

View File

@ -110,6 +110,7 @@ public class HemfPlusHeader implements HemfPlusRecord {
*
* @return {@code true} if dual-mode is enabled
*/
@SuppressWarnings("unused")
public boolean isEmfPlusDualMode() {
return (flags & 1) == 1;
}

View File

@ -52,9 +52,6 @@ import org.apache.poi.util.LittleEndianConsts;
import org.apache.poi.util.LittleEndianInputStream;
public class HemfPlusImage {
/** Maximum image dimension for converting embedded metafiles */
private static final int MAX_IMAGE_SIZE = 1500;
/** The ImageDataType enumeration defines types of image data formats. */
public enum EmfPlusImageDataType {
/** The type of image is not known. */
@ -80,6 +77,7 @@ public class HemfPlusImage {
}
}
@SuppressWarnings("unused")
public enum EmfPlusPixelFormat {
UNDEFINED(0X00000000),
INDEXED_1BPP(0X00030101),

View File

@ -243,8 +243,6 @@ public class HemfPlusMisc {
@Override
public void draw(HemfGraphics ctx) {
HemfDrawProperties prop = ctx.getProperties();
AffineTransform tx = ctx.getInitTransform();
tx.concatenate(getMatrixData());
ctx.setTransform(tx);
@ -318,6 +316,7 @@ public class HemfPlusMisc {
}
/** The EmfPlusSetClipRect record combines the current clipping region with a rectangle. */
@SuppressWarnings("unused")
public static class EmfPlusSetClipRect implements HemfPlusRecord {
private static final BitField COMBINE_MODE = BitFieldFactory.getInstance(0x0F00);

View File

@ -117,6 +117,7 @@ public class HemfPlusObject {
* The EmfPlusObject record specifies an object for use in graphics operations. The object definition
* can span multiple records), which is indicated by the value of the Flags field.
*/
@SuppressWarnings("unused")
public static class EmfPlusObject implements HemfPlusRecord, EmfPlusObjectId, HwmfObjectTableEntry {
/**
* Indicates that the object definition continues on in the next EmfPlusObject
@ -136,6 +137,7 @@ public class HemfPlusObject {
private int flags;
// for debugging
@SuppressWarnings("FieldCanBeLocal")
private int objectId;
private EmfPlusObjectData objectData;
private List<EmfPlusObjectData> continuedObjectData;
@ -155,6 +157,7 @@ public class HemfPlusObject {
return EmfPlusObjectType.valueOf(OBJECT_TYPE.getValue(flags));
}
@SuppressWarnings("unchecked")
public <T extends EmfPlusObjectData> T getObjectData() {
return (T)objectData;
}

View File

@ -55,9 +55,10 @@ public class HemfPlusPath {
// not defined
UNUSED,
/** Specifies that the point is an endpoint or control point of a cubic Bezier curve */
BEZIER;
BEZIER
}
@SuppressWarnings("unused")
public static class EmfPlusPath implements EmfPlusObjectData, EmfPlusCompressed, EmfPlusRelativePosition {
/**
* If set, the point types in the PathPointTypes array are specified by EmfPlusPathPointTypeRLE objects,

View File

@ -46,6 +46,7 @@ import org.apache.poi.hwmf.record.HwmfPenStyle.HwmfLineDash;
import org.apache.poi.hwmf.record.HwmfPenStyle.HwmfLineJoin;
import org.apache.poi.util.BitField;
import org.apache.poi.util.BitFieldFactory;
import org.apache.poi.util.GenericRecordUtil;
import org.apache.poi.util.Internal;
import org.apache.poi.util.LittleEndianConsts;
import org.apache.poi.util.LittleEndianInputStream;
@ -233,14 +234,64 @@ public class HemfPlusPen {
@Internal
public interface EmfPlusCustomLineCap extends GenericRecord {
long init(LittleEndianInputStream leis) throws IOException;
public static abstract class EmfPlusCustomLineCap implements GenericRecord {
private EmfPlusLineCapType startCap;
private EmfPlusLineCapType endCap;
private EmfPlusLineJoin join;
private double miterLimit;
private double widthScale;
private final Point2D fillHotSpot = new Point2D.Double();
private final Point2D lineHotSpot = new Point2D.Double();
protected long init(LittleEndianInputStream leis) throws IOException {
// A 32-bit unsigned integer that specifies the value in the LineCap enumeration that indicates the line
// cap used at the start/end of the line to be drawn.
startCap = EmfPlusLineCapType.valueOf(leis.readInt());
endCap = EmfPlusLineCapType.valueOf(leis.readInt());
// A 32-bit unsigned integer that specifies the value in the LineJoin enumeration, which specifies how
// to join two lines that are drawn by the same pen and whose ends meet. At the intersection of the two
// line ends, a line join makes the connection look more continuous.
join = EmfPlusLineJoin.valueOf(leis.readInt());
// A 32-bit floating-point value that contains the limit of the thickness of the join on a mitered corner
// by setting the maximum allowed ratio of miter length to line width.
miterLimit = leis.readFloat();
// A 32-bit floating-point value that specifies the amount by which to scale the custom line cap with
// respect to the width of the EmfPlusPen object that is used to draw the lines.
widthScale = leis.readFloat();
long size = 5*LittleEndianConsts.INT_SIZE;
// An EmfPlusPointF object that is not currently used. It MUST be set to {0.0, 0.0}.
size += readPointF(leis, fillHotSpot);
size += readPointF(leis, lineHotSpot);
return size;
}
@Override
public Map<String, Supplier<?>> getGenericProperties() {
final Map<String,Supplier<?>> m = new LinkedHashMap<>();
m.put("startCap", () -> startCap);
m.put("endCap", () -> endCap);
m.put("join", () -> join);
m.put("miterLimit", () -> miterLimit);
m.put("widthScale", () -> widthScale);
m.put("fillHotSpot", () -> fillHotSpot);
m.put("lineHotSpot", () -> lineHotSpot);
return m;
}
@Override
public final EmfPlusObjectType getGenericRecordType() {
return EmfPlusObjectType.CUSTOM_LINE_CAP;
}
}
public static class EmfPlusPen implements EmfPlusObjectData {
/**
* If set, a 2x3 transform matrix MUST be specified in the OptionalData field of an EmfPlusPenData object.
*/
@ -581,7 +632,7 @@ public class HemfPlusPen {
}
}
public static class EmfPlusPathArrowCap implements EmfPlusCustomLineCap {
public static class EmfPlusPathArrowCap extends EmfPlusCustomLineCap {
/**
* If set, an EmfPlusFillPath object MUST be specified in the OptionalData field of the
* EmfPlusCustomLineCapData object for filling the custom line cap.
@ -600,13 +651,6 @@ public class HemfPlusPen {
private int dataFlags;
private EmfPlusLineCapType baseCap;
private double baseInset;
private EmfPlusLineCapType startCap;
private EmfPlusLineCapType endCap;
private EmfPlusLineJoin join;
private double miterLimit;
private double widthScale;
private final Point2D fillHotSpot = new Point2D.Double();
private final Point2D lineHotSpot = new Point2D.Double();
private EmfPlusPath fillPath;
private EmfPlusPath outlinePath;
@ -624,78 +668,44 @@ public class HemfPlusPen {
// beginning of the line cap and the end of the line.
baseInset = leis.readFloat();
// A 32-bit unsigned integer that specifies the value in the LineCap enumeration that indicates the line
// cap used at the start/end of the line to be drawn.
startCap = EmfPlusLineCapType.valueOf(leis.readInt());
endCap = EmfPlusLineCapType.valueOf(leis.readInt());
long size = 3*LittleEndianConsts.INT_SIZE;
// A 32-bit unsigned integer that specifies the value in the LineJoin enumeration, which specifies how
// to join two lines that are drawn by the same pen and whose ends meet. At the intersection of the two
// line ends, a line join makes the connection look more continuous.
join = EmfPlusLineJoin.valueOf(leis.readInt());
size += super.init(leis);
// A 32-bit floating-point value that contains the limit of the thickness of the join on a mitered corner
// by setting the maximum allowed ratio of miter length to line width.
miterLimit = leis.readFloat();
// A 32-bit floating-point value that specifies the amount by which to scale the custom line cap with
// respect to the width of the EmfPlusPen object that is used to draw the lines.
widthScale = leis.readFloat();
int size = 8* LittleEndianConsts.INT_SIZE;
// An EmfPlusPointF object that is not currently used. It MUST be set to {0.0, 0.0}.
size += readPointF(leis, fillHotSpot);
size += readPointF(leis, lineHotSpot);
if (FILL_PATH.isSet(dataFlags)) {
int fillSize = leis.readInt();
size += LittleEndianConsts.INT_SIZE;
fillPath = new EmfPlusPath();
size += fillPath.init(leis, fillSize, EmfPlusObjectType.PATH, -1);
}
if (LINE_PATH.isSet(dataFlags)) {
int pathSize = leis.readInt();
size += LittleEndianConsts.INT_SIZE;
outlinePath = new EmfPlusPath();
size += outlinePath.init(leis, pathSize, EmfPlusObjectType.PATH, -1);
}
size += initPath(leis, FILL_PATH, p -> fillPath = p);
size += initPath(leis, LINE_PATH, p -> outlinePath = p);
return size;
}
private long initPath(LittleEndianInputStream leis, BitField bitField, Consumer<EmfPlusPath> setter) throws IOException {
if (!bitField.isSet(dataFlags)) {
return 0;
}
int pathSize = leis.readInt();
EmfPlusPath path = new EmfPlusPath();
setter.accept(path);
return LittleEndianConsts.INT_SIZE + path.init(leis, pathSize, EmfPlusObjectType.PATH, -1);
}
@Override
public Map<String, Supplier<?>> getGenericProperties() {
final Map<String,Supplier<?>> m = new LinkedHashMap<>();
m.put("flags", getBitsAsString(() -> dataFlags, FLAGS_MASKS, FLAGS_NAMES));
m.put("baseCap", () -> baseCap);
m.put("baseInset", () -> baseInset);
m.put("startCap", () -> startCap);
m.put("endCap", () -> endCap);
m.put("join", () -> join);
m.put("miterLimit", () -> miterLimit);
m.put("widthScale", () -> widthScale);
m.put("fillHotSpot", () -> fillHotSpot);
m.put("lineHotSpot", () -> lineHotSpot);
m.put("fillPath", () -> fillPath);
m.put("outlinePath", () -> outlinePath);
return Collections.unmodifiableMap(m);
return GenericRecordUtil.getGenericProperties(
"flags", getBitsAsString(() -> dataFlags, FLAGS_MASKS, FLAGS_NAMES),
"baseCap", () -> baseCap,
"baseInset", () -> baseInset,
"base", super::getGenericProperties,
"fillPath", () -> fillPath,
"outlinePath", () -> outlinePath
);
}
}
public static class EmfPlusAdjustableArrowCap implements EmfPlusCustomLineCap {
public static class EmfPlusAdjustableArrowCap extends EmfPlusCustomLineCap {
private double width;
private double height;
private double middleInset;
private boolean isFilled;
private EmfPlusLineCapType startCap;
private EmfPlusLineCapType endCap;
private EmfPlusLineJoin join;
private double miterLimit;
private double widthScale;
private final Point2D fillHotSpot = new Point2D.Double();
private final Point2D lineHotSpot = new Point2D.Double();
@Override
public long init(LittleEndianInputStream leis) throws IOException {
@ -719,51 +729,19 @@ public class HemfPlusPen {
// If the arrow cap is not filled, only the outline is drawn.
isFilled = (leis.readInt() != 0);
// A 32-bit unsigned integer that specifies the value in the LineCap enumeration that indicates
// the line cap to be used at the start/end of the line to be drawn.
startCap = EmfPlusLineCapType.valueOf(leis.readInt());
endCap = EmfPlusLineCapType.valueOf(leis.readInt());
// 32-bit unsigned integer that specifies the value in the LineJoin enumeration that specifies how to
// join two lines that are drawn by the same pen and whose ends meet. At the intersection of the two
// line ends, a line join makes the connection look more continuous.
join = EmfPlusLineJoin.valueOf(leis.readInt());
// A 32-bit floating-point value that specifies the limit of the thickness of the join on a mitered
// corner by setting the maximum allowed ratio of miter length to line width.
miterLimit = leis.readFloat();
// A 32-bit floating-point value that specifies the amount by which to scale an EmfPlusCustomLineCap
// object with respect to the width of the graphics pen that is used to draw the lines.
widthScale = leis.readFloat();
int size = 9 * LittleEndianConsts.INT_SIZE;
// An EmfPlusPointF object that is not currently used. It MUST be set to {0.0, 0.0}.
size += readPointF(leis, fillHotSpot);
// An EmfPlusPointF object that is not currently used. It MUST be set to {0.0, 0.0}.
size += readPointF(leis, lineHotSpot);
return size;
return 4*LittleEndianConsts.INT_SIZE + super.init(leis);
}
@Override
public Map<String, Supplier<?>> getGenericProperties() {
final Map<String,Supplier<?>> m = new LinkedHashMap<>();
m.put("width", () -> width);
m.put("height", () -> height);
m.put("middleInset", () -> middleInset);
m.put("isFilled", () -> isFilled);
m.put("startCap", () -> startCap);
m.put("endCap", () -> endCap);
m.put("join", () -> join);
m.put("miterLimit", () -> miterLimit);
m.put("widthScale", () -> widthScale);
m.put("fillHotSpot", () -> fillHotSpot);
m.put("lineHotSpot", () -> lineHotSpot);
return Collections.unmodifiableMap(m);
return GenericRecordUtil.getGenericProperties(
"width", () -> width,
"height", () -> height,
"middleInset", () -> middleInset,
"isFilled", () -> isFilled,
"base", super::getGenericProperties
);
}
}
}

View File

@ -56,7 +56,7 @@ public interface HemfPlusRecord extends GenericRecord {
}
@Override
default Enum getGenericRecordType() {
default HemfPlusRecordType getGenericRecordType() {
return getEmfPlusRecordType();
}
}

View File

@ -108,6 +108,7 @@ public class HemfPlusRegion {
private final EmfPlusGraphicsVersion graphicsVersion = new EmfPlusGraphicsVersion();
private EmfPlusRegionNodeData regionNode;
@SuppressWarnings("unused")
@Override
public long init(LittleEndianInputStream leis, long dataSize, EmfPlusObjectType objectType, int flags) throws IOException {
long size = graphicsVersion.init(leis);

View File

@ -30,11 +30,8 @@ import org.apache.poi.util.LittleEndianInputStream;
@Internal
public class UnimplementedHemfPlusRecord implements HemfPlusRecord {
private static final int MAX_RECORD_LENGTH = 1_000_000;
private HemfPlusRecordType recordType;
private int flags;
private byte[] recordBytes;
@Override
public HemfPlusRecordType getEmfPlusRecordType() {
@ -50,21 +47,17 @@ public class UnimplementedHemfPlusRecord implements HemfPlusRecord {
public long init(LittleEndianInputStream leis, long dataSize, long recordId, int flags) throws IOException {
recordType = HemfPlusRecordType.getById(recordId);
this.flags = flags;
recordBytes = IOUtils.safelyAllocate(dataSize, MAX_RECORD_LENGTH);
leis.readFully(recordBytes);
return recordBytes.length;
long skipped = IOUtils.skipFully(leis, dataSize);
if (skipped < dataSize) {
throw new IOException("End of stream reached before record read");
}
public byte[] getRecordBytes() {
//should probably defensively return a copy.
return recordBytes;
return skipped;
}
@Override
public Map<String, Supplier<?>> getGenericProperties() {
return GenericRecordUtil.getGenericProperties(
"flags", this::getFlags,
"recordBytes", () -> recordBytes
"flags", this::getFlags
);
}
}