*
* @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();
}
}
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> {
}
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();
@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;
}
}
@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.
return leis.getReadIndex()-startIdx;
}
+
public Rectangle2D getBounds() {
return bounds;
}
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;
}
}
@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.
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());
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)
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
}
@Override
- public Enum getGenericRecordType() {
+ public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
}
@Override
- public Enum getGenericRecordType() {
+ public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
}
@Override
- public Enum getGenericRecordType() {
+ public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
return readPointL(leis, point);
}
+ @SuppressWarnings("unused")
@Override
public long init(LittleEndianInputStream leis, long recordSize, long recordId) throws IOException {
long size = readRectL(leis, bounds);
}
@Override
- public Enum getGenericRecordType() {
+ public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
}
@Override
- public Enum getGenericRecordType() {
+ public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
}
@Override
- public Enum getGenericRecordType() {
+ public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
}
@Override
- public Enum getGenericRecordType() {
+ public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
}
@Override
- public Enum getGenericRecordType() {
+ public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
}
@Override
- public Enum getGenericRecordType() {
+ public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
}
@Override
- public Enum getGenericRecordType() {
+ public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
}
@Override
- public Enum getGenericRecordType() {
+ public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
}
@Override
- public Enum getGenericRecordType() {
+ public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
}
@Override
- public Enum getGenericRecordType() {
+ public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
}
@Override
- public Enum getGenericRecordType() {
+ public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
}
@Override
- public Enum getGenericRecordType() {
+ public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
* 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;
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.
}
@Override
- public Enum getGenericRecordType() {
+ public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
}
@Override
- public Enum getGenericRecordType() {
+ public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
}
@Override
- public Enum getGenericRecordType() {
+ public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
}
@Override
- public Enum getGenericRecordType() {
+ public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
return HemfRecordType.frameRgn;
}
+ @SuppressWarnings("unused")
@Override
public long init(LittleEndianInputStream leis, long recordSize, long recordId) throws IOException {
long size = readRectL(leis, bounds);
}
@Override
- public Enum getGenericRecordType() {
+ public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
return HemfRecordType.invertRgn;
}
+ @SuppressWarnings("unused")
@Override
public long init(LittleEndianInputStream leis, long recordSize, long recordId) throws IOException {
long size = readRectL(leis, bounds);
return HemfRecordType.fillRgn;
}
+ @SuppressWarnings("unused")
@Override
public long init(LittleEndianInputStream leis, long recordSize, long recordId) throws IOException {
long size = readRectL(leis, bounds);
}
@Override
- public Enum getGenericRecordType() {
+ public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
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
@Override
public void draw(HemfGraphics ctx) {
- HemfDrawProperties prop = ctx.getProperties();
ctx.setClip(getShape(), regionMode, true);
}
return HemfRecordType.setDiBitsToDevice;
}
+ @SuppressWarnings("unused")
@Override
public long init(LittleEndianInputStream leis, long recordSize, long recordId) throws IOException {
int startIdx = leis.getReadIndex();
}
+ @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.
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);
}
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
}
@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);
@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;
return HemfRecordType.header;
}
+ @SuppressWarnings("unused")
@Override
public long init(LittleEndianInputStream leis, long recordSize, long recordId) throws IOException {
if (recordId != HemfRecordType.header.id) {
return HemfRecordType.eof;
}
+ @SuppressWarnings("unused")
@Override
public long init(LittleEndianInputStream leis, long recordSize, long recordId) throws IOException {
final int startIdx = leis.getReadIndex();
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;
}
@Override
- public Enum getGenericRecordType() {
+ public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
}
@Override
- public Enum getGenericRecordType() {
+ public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
}
@Override
- public Enum getGenericRecordType() {
+ public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
}
@Override
- public Enum getGenericRecordType() {
+ public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
}
@Override
- public Enum getGenericRecordType() {
+ public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
}
@Override
- public Enum getGenericRecordType() {
+ public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
}
@Override
- public Enum getGenericRecordType() {
+ public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
}
@Override
- public Enum getGenericRecordType() {
+ public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
}
@Override
- public Enum getGenericRecordType() {
+ public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
}
@Override
- public Enum getGenericRecordType() {
+ public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
}
@Override
- public Enum getGenericRecordType() {
+ public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
}
@Override
- public Enum getGenericRecordType() {
+ public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
}
@Override
- public Enum getGenericRecordType() {
+ public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
}
@Override
- public Enum getGenericRecordType() {
+ public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
}
@Override
- public Enum getGenericRecordType() {
+ public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
}
@Override
- public Enum getGenericRecordType() {
+ public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
}
@Override
- public Enum getGenericRecordType() {
+ public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
}
@Override
- public Enum getGenericRecordType() {
+ public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
default void setHeader(HemfHeader header) {}
@Override
- default Enum getGenericRecordType() {
+ default HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
}
@Override
- public Enum getGenericRecordType() {
+ public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
}
@Override
- public Enum getGenericRecordType() {
+ public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
}
@Override
- public Enum getGenericRecordType() {
+ public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
}
@Override
- public Enum getGenericRecordType() {
+ public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
}
@Override
- public Enum getGenericRecordType() {
+ public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
}
@Override
- public Enum getGenericRecordType() {
+ public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
}
@Override
- public Enum getGenericRecordType() {
+ public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
}
@Override
- public Enum getGenericRecordType() {
+ public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
}
@Override
- public Enum getGenericRecordType() {
+ public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
}
@Override
- public Enum getGenericRecordType() {
+ public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
}
@Override
- public Enum getGenericRecordType() {
+ public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
}
@Override
- public Enum getGenericRecordType() {
+ public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
}
@Override
- public Enum getGenericRecordType() {
+ public HemfRecordType getGenericRecordType() {
return getEmfRecordType();
}
}
}
+ @SuppressWarnings("unused")
public interface EmfPlusBrushData extends GenericRecord {
/**
* This flag is meaningful in EmfPlusPathGradientBrushData objects.
}
@Override
- public Enum getGenericRecordType() {
+ public EmfPlusBrushType getGenericRecordType() {
return EmfPlusBrushType.SOLID_COLOR;
}
}
@Override
- public Enum getGenericRecordType() {
+ public EmfPlusBrushType getGenericRecordType() {
return EmfPlusBrushType.HATCH_FILL;
}
}
@Override
- public Enum getGenericRecordType() {
+ public EmfPlusBrushType getGenericRecordType() {
return EmfPlusBrushType.LINEAR_GRADIENT;
}
@Override
- public Enum getGenericRecordType() {
+ public EmfPlusBrushType getGenericRecordType() {
return EmfPlusBrushType.PATH_GRADIENT;
}
}
@Override
- public Enum getGenericRecordType() {
+ public EmfPlusBrushType getGenericRecordType() {
return EmfPlusBrushType.TEXTURE_FILL;
}
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),
* 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);
}
/** 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.
}
/** 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.
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;
}
@Override
- public void loadImage(byte[] data, String contentType) throws IOException {
+ public void loadImage(byte[] data, String contentType) {
img = readGDIImage(data);
}
*
* @return {@code true} if dual-mode is enabled
*/
+ @SuppressWarnings("unused")
public boolean isEmfPlusDualMode() {
return (flags & 1) == 1;
}
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. */
}
}
+ @SuppressWarnings("unused")
public enum EmfPlusPixelFormat {
UNDEFINED(0X00000000),
INDEXED_1BPP(0X00030101),
@Override
public void draw(HemfGraphics ctx) {
- HemfDrawProperties prop = ctx.getProperties();
-
AffineTransform tx = ctx.getInitTransform();
tx.concatenate(getMatrixData());
ctx.setTransform(tx);
}
/** 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);
* 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
private int flags;
// for debugging
+ @SuppressWarnings("FieldCanBeLocal")
private int objectId;
private EmfPlusObjectData objectData;
private List<EmfPlusObjectData> continuedObjectData;
return EmfPlusObjectType.valueOf(OBJECT_TYPE.getValue(flags));
}
+ @SuppressWarnings("unchecked")
public <T extends EmfPlusObjectData> T getObjectData() {
return (T)objectData;
}
// 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,
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;
@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());
- public static class EmfPlusPen implements EmfPlusObjectData {
+ // 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.
*/
}
}
- 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.
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;
// 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());
-
- // 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;
+ size += super.init(leis);
- // 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);
+ size += initPath(leis, FILL_PATH, p -> fillPath = p);
+ size += initPath(leis, LINE_PATH, p -> outlinePath = p);
- if (FILL_PATH.isSet(dataFlags)) {
- int fillSize = leis.readInt();
- size += LittleEndianConsts.INT_SIZE;
- fillPath = new EmfPlusPath();
- size += fillPath.init(leis, fillSize, EmfPlusObjectType.PATH, -1);
- }
+ return size;
+ }
- if (LINE_PATH.isSet(dataFlags)) {
- int pathSize = leis.readInt();
- size += LittleEndianConsts.INT_SIZE;
- outlinePath = new EmfPlusPath();
- size += outlinePath.init(leis, pathSize, EmfPlusObjectType.PATH, -1);
+ private long initPath(LittleEndianInputStream leis, BitField bitField, Consumer<EmfPlusPath> setter) throws IOException {
+ if (!bitField.isSet(dataFlags)) {
+ return 0;
}
-
- return size;
+ 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 {
// 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
+ );
}
}
}
}
@Override
- default Enum getGenericRecordType() {
+ default HemfPlusRecordType getGenericRecordType() {
return getEmfPlusRecordType();
}
}
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);
@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() {
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;
- }
-
- public byte[] getRecordBytes() {
- //should probably defensively return a copy.
- return recordBytes;
+ long skipped = IOUtils.skipFully(leis, dataSize);
+ if (skipped < dataSize) {
+ throw new IOException("End of stream reached before record read");
+ }
+ return skipped;
}
@Override
public Map<String, Supplier<?>> getGenericProperties() {
return GenericRecordUtil.getGenericProperties(
- "flags", this::getFlags,
- "recordBytes", () -> recordBytes
+ "flags", this::getFlags
);
}
}
\ No newline at end of file