You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ki...@apache.org on 2019/06/06 22:32:41 UTC
svn commit: r1860732 [1/2] - in /poi/trunk/src/scratchpad:
src/org/apache/poi/hemf/draw/ src/org/apache/poi/hemf/record/emf/
src/org/apache/poi/hemf/record/emfplus/ src/org/apache/poi/hemf/usermodel/
src/org/apache/poi/hwmf/draw/ src/org/apache/poi/hwm...
Author: kiwiwings
Date: Thu Jun 6 22:32:41 2019
New Revision: 1860732
URL: http://svn.apache.org/viewvc?rev=1860732&view=rev
Log:
Bug 60656 - EMF image support in slideshows
Modified:
poi/trunk/src/scratchpad/src/org/apache/poi/hemf/draw/HemfDrawProperties.java
poi/trunk/src/scratchpad/src/org/apache/poi/hemf/draw/HemfGraphics.java
poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emf/HemfComment.java
poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emf/HemfDraw.java
poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emf/HemfFill.java
poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emf/HemfMisc.java
poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emfplus/HemfPlusBrush.java
poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emfplus/HemfPlusDraw.java
poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emfplus/HemfPlusFont.java
poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emfplus/HemfPlusHeader.java
poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emfplus/HemfPlusImage.java
poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emfplus/HemfPlusMisc.java
poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emfplus/HemfPlusObject.java
poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emfplus/HemfPlusPath.java
poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emfplus/HemfPlusPen.java
poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emfplus/HemfPlusRecord.java
poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emfplus/HemfPlusRegion.java
poi/trunk/src/scratchpad/src/org/apache/poi/hemf/usermodel/HemfEmbeddedIterator.java
poi/trunk/src/scratchpad/src/org/apache/poi/hemf/usermodel/HemfPicture.java
poi/trunk/src/scratchpad/src/org/apache/poi/hwmf/draw/HwmfGraphics.java
poi/trunk/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfDraw.java
poi/trunk/src/scratchpad/testcases/org/apache/poi/hemf/usermodel/HemfPictureTest.java
Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hemf/draw/HemfDrawProperties.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hemf/draw/HemfDrawProperties.java?rev=1860732&r1=1860731&r2=1860732&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hemf/draw/HemfDrawProperties.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hemf/draw/HemfDrawProperties.java Thu Jun 6 22:32:41 2019
@@ -17,9 +17,10 @@
package org.apache.poi.hemf.draw;
-import java.awt.Shape;
import java.awt.geom.Path2D;
+import java.awt.image.BufferedImage;
+import org.apache.poi.hemf.record.emfplus.HemfPlusBrush.EmfPlusHatchStyle;
import org.apache.poi.hwmf.draw.HwmfDrawProperties;
public class HemfDrawProperties extends HwmfDrawProperties {
@@ -27,6 +28,8 @@ public class HemfDrawProperties extends
/** Path for path bracket operations */
protected Path2D path = null;
protected boolean usePathBracket = false;
+ private EmfPlusHatchStyle emfPlusBrushHatch;
+ private BufferedImage emfPlusImage;
public HemfDrawProperties() {
@@ -35,8 +38,11 @@ public class HemfDrawProperties extends
public HemfDrawProperties(HemfDrawProperties other) {
super(other);
path = (other.path != null) ? (Path2D)other.path.clone() : null;
+ usePathBracket = other.usePathBracket;
+ emfPlusBrushHatch = other.emfPlusBrushHatch;
// TODO: check how to clone
clip = other.clip;
+ emfPlusImage = other.emfPlusImage;
}
/**
@@ -66,4 +72,20 @@ public class HemfDrawProperties extends
public void setUsePathBracket(boolean usePathBracket) {
this.usePathBracket = usePathBracket;
}
+
+ public EmfPlusHatchStyle getEmfPlusBrushHatch() {
+ return emfPlusBrushHatch;
+ }
+
+ public void setEmfPlusBrushHatch(EmfPlusHatchStyle emfPlusBrushHatch) {
+ this.emfPlusBrushHatch = emfPlusBrushHatch;
+ }
+
+ public BufferedImage getEmfPlusImage() {
+ return emfPlusImage;
+ }
+
+ public void setEmfPlusImage(BufferedImage emfPlusImage) {
+ this.emfPlusImage = emfPlusImage;
+ }
}
Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hemf/draw/HemfGraphics.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hemf/draw/HemfGraphics.java?rev=1860732&r1=1860731&r2=1860732&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hemf/draw/HemfGraphics.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hemf/draw/HemfGraphics.java Thu Jun 6 22:32:41 2019
@@ -22,12 +22,15 @@ import static org.apache.poi.hwmf.record
import java.awt.Color;
import java.awt.Graphics2D;
+import java.awt.Paint;
import java.awt.geom.Path2D;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.util.function.Consumer;
+import org.apache.poi.hemf.record.emf.HemfComment.EmfComment;
import org.apache.poi.hemf.record.emf.HemfRecord;
+import org.apache.poi.hemf.record.emfplus.HemfPlusRecord;
import org.apache.poi.hwmf.draw.HwmfDrawProperties;
import org.apache.poi.hwmf.draw.HwmfGraphics;
import org.apache.poi.hwmf.record.HwmfColorRef;
@@ -37,12 +40,20 @@ import org.apache.poi.util.Internal;
public class HemfGraphics extends HwmfGraphics {
+ public enum EmfRenderState {
+ INITIAL,
+ EMF_ONLY,
+ EMFPLUS_ONLY,
+ EMF_DCONTEXT
+ }
+
private static final HwmfColorRef WHITE = new HwmfColorRef(Color.WHITE);
private static final HwmfColorRef LTGRAY = new HwmfColorRef(new Color(0x00C0C0C0));
private static final HwmfColorRef GRAY = new HwmfColorRef(new Color(0x00808080));
private static final HwmfColorRef DKGRAY = new HwmfColorRef(new Color(0x00404040));
private static final HwmfColorRef BLACK = new HwmfColorRef(Color.BLACK);
+ private EmfRenderState renderState = EmfRenderState.INITIAL;
public HemfGraphics(Graphics2D graphicsCtx, Rectangle2D bbox) {
super(graphicsCtx,bbox);
@@ -62,8 +73,49 @@ public class HemfGraphics extends HwmfGr
: new HemfDrawProperties((HemfDrawProperties)oldProps);
}
+ public EmfRenderState getRenderState() {
+ return renderState;
+ }
+
+ public void setRenderState(EmfRenderState renderState) {
+ this.renderState = renderState;
+ }
+
public void draw(HemfRecord r) {
- r.draw(this);
+ switch (renderState) {
+ case EMF_DCONTEXT:
+ // keep the dcontext state, if the next record is an EMF+ record
+ // only reset it, when we are processing EMF records again
+ if (!(r instanceof EmfComment)) {
+ renderState = EmfRenderState.INITIAL;
+ }
+ r.draw(this);
+ break;
+ case INITIAL:
+ r.draw(this);
+ break;
+ case EMF_ONLY:
+ case EMFPLUS_ONLY:
+ if ((r instanceof EmfComment) == (renderState == EmfRenderState.EMFPLUS_ONLY)) {
+ r.draw(this);
+ }
+ break;
+ default:
+ break;
+ }
+ }
+
+ public void draw(HemfPlusRecord r) {
+ switch (renderState) {
+ case EMFPLUS_ONLY:
+ case EMF_DCONTEXT:
+ case INITIAL:
+ r.draw(this);
+ break;
+ case EMF_ONLY:
+ default:
+ break;
+ }
}
@Internal
@@ -131,14 +183,36 @@ public class HemfGraphics extends HwmfGr
* @see HwmfGraphics#addObjectTableEntry(HwmfObjectTableEntry)
*/
public void addObjectTableEntry(HwmfObjectTableEntry entry, int index) {
- if (index < 1) {
- throw new IndexOutOfBoundsException("Object table entry index in EMF must be > 0 - invalid index: "+index);
- }
-
+ checkTableEntryIndex(index);
objectIndexes.set(index);
objectTable.put(index, entry);
}
+ /**
+ * Gets a record which was registered earliser
+ * @param index the record index
+ * @return the record or {@code null} if it doesn't exist
+ */
+ public HwmfObjectTableEntry getObjectTableEntry(int index) {
+ checkTableEntryIndex(index);
+ return objectTable.get(index);
+ }
+
+ private void checkTableEntryIndex(int index) {
+ if (renderState != EmfRenderState.EMFPLUS_ONLY) {
+ // in EMF the index must > 0
+ if (index < 1) {
+ throw new IndexOutOfBoundsException("Object table entry index in EMF must be > 0 - invalid index: "+index);
+ }
+ } else {
+ // in EMF+ the index must be between 0 and 63
+ if (index < 0 || index > 63) {
+ throw new IndexOutOfBoundsException("Object table entry index in EMF+ must be [0..63] - invalid index: "+index);
+ }
+ }
+ }
+
+
@Override
public void applyObjectTableEntry(int index) {
if ((index & 0x80000000) != 0) {
@@ -256,4 +330,10 @@ public class HemfGraphics extends HwmfGr
break;
}
}
+
+ @Override
+ protected Paint getHatchedFill() {
+ // TODO: use EmfPlusHatchBrushData
+ return super.getHatchedFill();
+ }
}
Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emf/HemfComment.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emf/HemfComment.java?rev=1860732&r1=1860731&r2=1860732&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emf/HemfComment.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emf/HemfComment.java Thu Jun 6 22:32:41 2019
@@ -26,6 +26,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.function.Supplier;
+import org.apache.poi.hemf.draw.HemfGraphics;
import org.apache.poi.hemf.record.emfplus.HemfPlusRecord;
import org.apache.poi.hemf.record.emfplus.HemfPlusRecordIterator;
import org.apache.poi.hwmf.usermodel.HwmfPicture;
@@ -103,6 +104,17 @@ public class HemfComment {
}
@Override
+ public void draw(HemfGraphics ctx) {
+ if (data instanceof EmfCommentDataPlus) {
+ if (ctx.getRenderState() == HemfGraphics.EmfRenderState.INITIAL) {
+ ctx.setRenderState(HemfGraphics.EmfRenderState.EMFPLUS_ONLY);
+ }
+
+ ((EmfCommentDataPlus)data).draw(ctx);
+ }
+ }
+
+ @Override
public String toString() {
return "{ data: "+data+" }";
}
@@ -255,6 +267,10 @@ public class HemfComment {
public List<HemfPlusRecord> getRecords() {
return Collections.unmodifiableList(records);
}
+
+ public void draw(HemfGraphics ctx) {
+ records.forEach(ctx::draw);
+ }
}
public static class EmfCommentDataBeginGroup implements EmfCommentData {
Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emf/HemfDraw.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emf/HemfDraw.java?rev=1860732&r1=1860731&r2=1860732&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emf/HemfDraw.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emf/HemfDraw.java Thu Jun 6 22:32:41 2019
@@ -21,6 +21,7 @@ import static org.apache.poi.hwmf.record
import static org.apache.poi.hwmf.record.HwmfDraw.normalizeBounds;
import java.awt.Shape;
+import java.awt.geom.AffineTransform;
import java.awt.geom.Arc2D;
import java.awt.geom.Dimension2D;
import java.awt.geom.Path2D;
@@ -34,6 +35,7 @@ import org.apache.poi.hemf.draw.HemfGrap
import org.apache.poi.hwmf.draw.HwmfGraphics.FillDrawStyle;
import org.apache.poi.hwmf.record.HwmfDraw;
import org.apache.poi.hwmf.record.HwmfDraw.WmfSelectObject;
+import org.apache.poi.util.Internal;
import org.apache.poi.util.LittleEndianConsts;
import org.apache.poi.util.LittleEndianInputStream;
@@ -1153,4 +1155,16 @@ public class HemfDraw {
ctx.draw((path) -> path.append(pi, true), fillDrawStyle);
}
+
+
+ @Internal
+ public static String xformToString(AffineTransform xForm) {
+ return (xForm == null) ? "null" :
+ "{ scaleX: "+xForm.getScaleX()+
+ ", shearX: "+xForm.getShearX()+
+ ", transX: "+xForm.getTranslateX()+
+ ", scaleY: "+xForm.getScaleY()+
+ ", shearY: "+xForm.getShearY()+
+ ", transY: "+xForm.getTranslateY()+" }";
+ }
}
Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emf/HemfFill.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emf/HemfFill.java?rev=1860732&r1=1860731&r2=1860732&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emf/HemfFill.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emf/HemfFill.java Thu Jun 6 22:32:41 2019
@@ -19,6 +19,7 @@ package org.apache.poi.hemf.record.emf;
import static org.apache.poi.hemf.record.emf.HemfDraw.readPointL;
import static org.apache.poi.hemf.record.emf.HemfDraw.readRectL;
+import static org.apache.poi.hemf.record.emf.HemfDraw.xformToString;
import static org.apache.poi.hemf.record.emf.HemfRecordIterator.HEADER_SIZE;
import static org.apache.poi.hwmf.record.HwmfDraw.boundsToString;
import static org.apache.poi.hwmf.record.HwmfDraw.pointToString;
@@ -186,7 +187,7 @@ public class HemfFill {
public String toString() {
return
"{ bounds: "+boundsToString(bounds)+
- ", xFormSrc: { scaleX: "+xFormSrc.getScaleX()+", shearX: "+xFormSrc.getShearX()+", transX: "+xFormSrc.getTranslateX()+", scaleY: "+xFormSrc.getScaleY()+", shearY: "+xFormSrc.getShearY()+", transY: "+xFormSrc.getTranslateY()+" }"+
+ ", xFormSrc: " + xformToString(xFormSrc) +
", bkColorSrc: "+bkColorSrc+
","+super.toString().substring(1);
}
@@ -705,6 +706,10 @@ public class HemfFill {
xform.setTransform(m00, m10, m01, m11, m02, m12);
+ if (xform.isIdentity()) {
+ xform.setToIdentity();
+ }
+
return 6 * LittleEndian.INT_SIZE;
}
Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emf/HemfMisc.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emf/HemfMisc.java?rev=1860732&r1=1860731&r2=1860732&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emf/HemfMisc.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emf/HemfMisc.java Thu Jun 6 22:32:41 2019
@@ -18,6 +18,7 @@
package org.apache.poi.hemf.record.emf;
import static org.apache.poi.hemf.record.emf.HemfDraw.readPointL;
+import static org.apache.poi.hemf.record.emf.HemfDraw.xformToString;
import static org.apache.poi.hemf.record.emf.HemfFill.readBitmap;
import static org.apache.poi.hemf.record.emf.HemfFill.readXForm;
import static org.apache.poi.hemf.record.emf.HemfRecordIterator.HEADER_SIZE;
@@ -621,14 +622,7 @@ public class HemfMisc {
@Override
public String toString() {
- return
- "{ xForm: " +
- "{ scaleX: "+xForm.getScaleX()+
- ", shearX: "+xForm.getShearX()+
- ", transX: "+xForm.getTranslateX()+
- ", scaleY: "+xForm.getScaleY()+
- ", shearY: "+xForm.getShearY()+
- ", transY: "+xForm.getTranslateY()+" } }";
+ return "{ xForm: " + xformToString(xForm)+" }";
}
}
@@ -695,7 +689,7 @@ public class HemfMisc {
wsTrans.translate(-emfBounds.getHeight(), emfBounds.getHeight());
}
} else {
- wsTrans = adaptXForm(ctx.getTransform());
+ wsTrans = adaptXForm(xForm, ctx.getTransform());
}
tx = ctx.getTransform();
@@ -703,7 +697,7 @@ public class HemfMisc {
break;
case MWT_RIGHTMULTIPLY:
tx = ctx.getTransform();
- tx.preConcatenate(adaptXForm(tx));
+ tx.preConcatenate(adaptXForm(xForm, tx));
break;
case MWT_IDENTITY:
ctx.updateWindowMapMode();
@@ -713,40 +707,16 @@ public class HemfMisc {
case MWT_SET:
ctx.updateWindowMapMode();
tx = ctx.getTransform();
- tx.concatenate(adaptXForm(tx));
+ tx.concatenate(adaptXForm(xForm, tx));
break;
}
ctx.setTransform(tx);
}
- /**
- * adapt xform depending on the base transformation (... experimental ...)
- */
- private AffineTransform adaptXForm(AffineTransform other) {
- // normalize signed zero
- Function<Double,Double> nn = (d) -> (d == 0. ? 0. : d);
- double yDiff = Math.signum(nn.apply(xForm.getTranslateY())) == Math.signum(nn.apply(other.getTranslateY())) ? 1. : -1.;
- double xDiff = Math.signum(nn.apply(xForm.getTranslateX())) == Math.signum(nn.apply(other.getTranslateX())) ? 1. : -1.;
- return new AffineTransform(
- xForm.getScaleX() == 0 ? 1. : xForm.getScaleX(),
- yDiff * xForm.getShearY(),
- xDiff * xForm.getShearX(),
- xForm.getScaleY() == 0. ? 1. : xForm.getScaleY(),
- xForm.getTranslateX(),
- xForm.getTranslateY()
- );
- }
-
@Override
public String toString() {
return
- "{ xForm: " +
- "{ scaleX: "+xForm.getScaleX()+
- ", shearX: "+xForm.getShearX()+
- ", transX: "+xForm.getTranslateX()+
- ", scaleY: "+xForm.getScaleY()+
- ", shearY: "+xForm.getShearY()+
- ", transY: "+xForm.getTranslateY()+" }"+
+ "{ xForm: " + xformToString(xForm) +
", modifyWorldTransformMode: '"+modifyWorldTransformMode+"' }";
}
}
@@ -825,4 +795,23 @@ public class HemfMisc {
"}";
}
}
+
+
+ /**
+ * adapt xform depending on the base transformation (... experimental ...)
+ */
+ public static AffineTransform adaptXForm(AffineTransform xForm, AffineTransform other) {
+ // normalize signed zero
+ Function<Double,Double> nn = (d) -> (d == 0. ? 0. : d);
+ double yDiff = Math.signum(nn.apply(xForm.getTranslateY())) == Math.signum(nn.apply(other.getTranslateY())) ? 1. : -1.;
+ double xDiff = Math.signum(nn.apply(xForm.getTranslateX())) == Math.signum(nn.apply(other.getTranslateX())) ? 1. : -1.;
+ return new AffineTransform(
+ xForm.getScaleX() == 0 ? 1. : xForm.getScaleX(),
+ yDiff * xForm.getShearY(),
+ xDiff * xForm.getShearX(),
+ xForm.getScaleY() == 0. ? 1. : xForm.getScaleY(),
+ xForm.getTranslateX(),
+ xForm.getTranslateY()
+ );
+ }
}
Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emfplus/HemfPlusBrush.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emfplus/HemfPlusBrush.java?rev=1860732&r1=1860731&r2=1860732&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emfplus/HemfPlusBrush.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emfplus/HemfPlusBrush.java Thu Jun 6 22:32:41 2019
@@ -17,27 +17,40 @@
package org.apache.poi.hemf.record.emfplus;
+import static java.util.stream.Collectors.joining;
+import static org.apache.poi.hemf.record.emf.HemfDraw.xformToString;
import static org.apache.poi.hemf.record.emf.HemfFill.readXForm;
import static org.apache.poi.hemf.record.emfplus.HemfPlusDraw.readARGB;
import static org.apache.poi.hemf.record.emfplus.HemfPlusDraw.readPointF;
import static org.apache.poi.hemf.record.emfplus.HemfPlusDraw.readRectF;
+import static org.apache.poi.hwmf.record.HwmfDraw.boundsToString;
+import static org.apache.poi.hwmf.record.HwmfDraw.pointToString;
import java.awt.Color;
import java.awt.geom.AffineTransform;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.io.IOException;
+import java.util.Arrays;
+import java.util.List;
import java.util.function.Consumer;
import java.util.function.Supplier;
+import java.util.stream.Stream;
+import org.apache.poi.hemf.draw.HemfDrawProperties;
+import org.apache.poi.hemf.draw.HemfGraphics;
import org.apache.poi.hemf.record.emfplus.HemfPlusHeader.EmfPlusGraphicsVersion;
import org.apache.poi.hemf.record.emfplus.HemfPlusImage.EmfPlusImage;
import org.apache.poi.hemf.record.emfplus.HemfPlusImage.EmfPlusWrapMode;
import org.apache.poi.hemf.record.emfplus.HemfPlusObject.EmfPlusObjectData;
import org.apache.poi.hemf.record.emfplus.HemfPlusObject.EmfPlusObjectType;
import org.apache.poi.hemf.record.emfplus.HemfPlusPath.EmfPlusPath;
+import org.apache.poi.hwmf.record.HwmfBrushStyle;
+import org.apache.poi.hwmf.record.HwmfColorRef;
+import org.apache.poi.hwmf.record.HwmfDraw;
import org.apache.poi.util.BitField;
import org.apache.poi.util.BitFieldFactory;
+import org.apache.poi.util.Internal;
import org.apache.poi.util.LittleEndianConsts;
import org.apache.poi.util.LittleEndianInputStream;
@@ -68,58 +81,149 @@ public class HemfPlusBrush {
}
public enum EmfPlusHatchStyle {
+ /** Specifies equally spaced horizontal lines. */
HORIZONTAL(0X00000000),
+ /** Specifies equally spaced vertical lines. */
VERTICAL(0X00000001),
+ /** Specifies lines on a diagonal from upper left to lower right. */
FORWARD_DIAGONAL(0X00000002),
+ /** Specifies lines on a diagonal from upper right to lower left. */
BACKWARD_DIAGONAL(0X00000003),
+ /** Specifies crossing horizontal and vertical lines. */
LARGE_GRID(0X00000004),
+ /** Specifies crossing forward diagonal and backward diagonal lines with anti-aliasing. */
DIAGONAL_CROSS(0X00000005),
+ /** Specifies a 5-percent hatch, which is the ratio of foreground color to background color equal to 5:100. */
PERCENT_05(0X00000006),
+ /** Specifies a 10-percent hatch, which is the ratio of foreground color to background color equal to 10:100. */
PERCENT_10(0X00000007),
+ /** Specifies a 20-percent hatch, which is the ratio of foreground color to background color equal to 20:100. */
PERCENT_20(0X00000008),
+ /** Specifies a 25-percent hatch, which is the ratio of foreground color to background color equal to 25:100. */
PERCENT_25(0X00000009),
+ /** Specifies a 30-percent hatch, which is the ratio of foreground color to background color equal to 30:100. */
PERCENT_30(0X0000000A),
+ /** Specifies a 40-percent hatch, which is the ratio of foreground color to background color equal to 40:100. */
PERCENT_40(0X0000000B),
+ /** Specifies a 50-percent hatch, which is the ratio of foreground color to background color equal to 50:100. */
PERCENT_50(0X0000000C),
+ /** Specifies a 60-percent hatch, which is the ratio of foreground color to background color equal to 60:100. */
PERCENT_60(0X0000000D),
+ /** Specifies a 70-percent hatch, which is the ratio of foreground color to background color equal to 70:100. */
PERCENT_70(0X0000000E),
+ /** Specifies a 75-percent hatch, which is the ratio of foreground color to background color equal to 75:100. */
PERCENT_75(0X0000000F),
+ /** Specifies an 80-percent hatch, which is the ratio of foreground color to background color equal to 80:100. */
PERCENT_80(0X00000010),
+ /** Specifies a 90-percent hatch, which is the ratio of foreground color to background color equal to 90:100. */
PERCENT_90(0X00000011),
+ /**
+ * Specifies diagonal lines that slant to the right from top to bottom points with no anti-aliasing.
+ * They are spaced 50 percent further apart than lines in the FORWARD_DIAGONAL pattern
+ */
LIGHT_DOWNWARD_DIAGONAL(0X00000012),
+ /**
+ * Specifies diagonal lines that slant to the left from top to bottom points with no anti-aliasing.
+ * They are spaced 50 percent further apart than lines in the BACKWARD_DIAGONAL pattern.
+ */
LIGHT_UPWARD_DIAGONAL(0X00000013),
+ /**
+ * Specifies diagonal lines that slant to the right from top to bottom points with no anti-aliasing.
+ * They are spaced 50 percent closer and are twice the width of lines in the FORWARD_DIAGONAL pattern.
+ */
DARK_DOWNWARD_DIAGONAL(0X00000014),
+ /**
+ * Specifies diagonal lines that slant to the left from top to bottom points with no anti-aliasing.
+ * They are spaced 50 percent closer and are twice the width of lines in the BACKWARD_DIAGONAL pattern.
+ */
DARK_UPWARD_DIAGONAL(0X00000015),
+ /**
+ * Specifies diagonal lines that slant to the right from top to bottom points with no anti-aliasing.
+ * They have the same spacing between lines in WIDE_DOWNWARD_DIAGONAL pattern and FORWARD_DIAGONAL pattern,
+ * but WIDE_DOWNWARD_DIAGONAL has the triple line width of FORWARD_DIAGONAL.
+ */
WIDE_DOWNWARD_DIAGONAL(0X00000016),
+ /**
+ * Specifies diagonal lines that slant to the left from top to bottom points with no anti-aliasing.
+ * They have the same spacing between lines in WIDE_UPWARD_DIAGONAL pattern and BACKWARD_DIAGONAL pattern,
+ * but WIDE_UPWARD_DIAGONAL has the triple line width of WIDE_UPWARD_DIAGONAL.
+ */
WIDE_UPWARD_DIAGONAL(0X00000017),
+ /** Specifies vertical lines that are spaced 50 percent closer together than lines in the VERTICAL pattern. */
LIGHT_VERTICAL(0X00000018),
+ /** Specifies horizontal lines that are spaced 50 percent closer than lines in the HORIZONTAL pattern. */
LIGHT_HORIZONTAL(0X00000019),
+ /**
+ * Specifies vertical lines that are spaced 75 percent closer than lines in the VERTICAL pattern;
+ * or 25 percent closer than lines in the LIGHT_VERTICAL pattern.
+ */
NARROW_VERTICAL(0X0000001A),
+ /**
+ * Specifies horizontal lines that are spaced 75 percent closer than lines in the HORIZONTAL pattern;
+ * or 25 percent closer than lines in the LIGHT_HORIZONTAL pattern.
+ */
NARROW_HORIZONTAL(0X0000001B),
+ /** Specifies lines that are spaced 50 percent closer than lines in the VERTICAL pattern. */
DARK_VERTICAL(0X0000001C),
+ /** Specifies lines that are spaced 50 percent closer than lines in the HORIZONTAL pattern. */
DARK_HORIZONTAL(0X0000001D),
+ /** Specifies dashed diagonal lines that slant to the right from top to bottom points. */
DASHED_DOWNWARD_DIAGONAL(0X0000001E),
+ /** Specifies dashed diagonal lines that slant to the left from top to bottom points. */
DASHED_UPWARD_DIAGONAL(0X0000001F),
+ /** Specifies dashed horizontal lines. */
DASHED_HORIZONTAL(0X00000020),
+ /** Specifies dashed vertical lines. */
DASHED_VERTICAL(0X00000021),
+ /** Specifies a pattern of lines that has the appearance of confetti. */
SMALL_CONFETTI(0X00000022),
+ /**
+ * Specifies a pattern of lines that has the appearance of confetti, and is composed of larger pieces
+ * than the SMALL_CONFETTI pattern.
+ */
LARGE_CONFETTI(0X00000023),
+ /** Specifies horizontal lines that are composed of zigzags. */
ZIGZAG(0X00000024),
+ /** Specifies horizontal lines that are composed of tildes. */
WAVE(0X00000025),
+ /**
+ * Specifies a pattern of lines that has the appearance of layered bricks that slant to the left from
+ * top to bottom points.
+ */
DIAGONAL_BRICK(0X00000026),
+ /** Specifies a pattern of lines that has the appearance of horizontally layered bricks. */
HORIZONTAL_BRICK(0X00000027),
+ /** Specifies a pattern of lines that has the appearance of a woven material. */
WEAVE(0X00000028),
+ /** Specifies a pattern of lines that has the appearance of a plaid material. */
PLAID(0X00000029),
+ /** Specifies a pattern of lines that has the appearance of divots. */
DIVOT(0X0000002A),
+ /** Specifies crossing horizontal and vertical lines, each of which is composed of dots. */
DOTTED_GRID(0X0000002B),
+ /** Specifies crossing forward and backward diagonal lines, each of which is composed of dots. */
DOTTED_DIAMOND(0X0000002C),
+ /**
+ * Specifies a pattern of lines that has the appearance of diagonally layered
+ * shingles that slant to the right from top to bottom points.
+ */
SHINGLE(0X0000002D),
+ /** Specifies a pattern of lines that has the appearance of a trellis. */
TRELLIS(0X0000002E),
+ /** Specifies a pattern of lines that has the appearance of spheres laid adjacent to each other. */
SPHERE(0X0000002F),
+ /** Specifies crossing horizontal and vertical lines that are spaced 50 percent closer together than LARGE_GRID. */
SMALL_GRID(0X00000030),
+ /** Specifies a pattern of lines that has the appearance of a checkerboard. */
SMALL_CHECKER_BOARD(0X00000031),
+ /**
+ * Specifies a pattern of lines that has the appearance of a checkerboard, with squares that are twice the
+ * size of the squares in the SMALL_CHECKER_BOARD pattern.
+ */
LARGE_CHECKER_BOARD(0X00000032),
+ /** Specifies crossing forward and backward diagonal lines; the lines are not anti-aliased. */
OUTLINED_DIAMOND(0X00000033),
+ /** Specifies a pattern of lines that has the appearance of a checkerboard placed diagonally. */
SOLID_DIAMOND(0X00000034)
;
@@ -204,17 +308,19 @@ public class HemfPlusBrush {
BitField DO_NOT_TRANSFORM = BitFieldFactory.getInstance(0x00000100);
long init(LittleEndianInputStream leis, long dataSize) throws IOException;
+
+ void applyObject(HemfGraphics ctx, List<? extends EmfPlusObjectData> continuedObjectData);
}
/** The EmfPlusBrush object specifies a graphics brush for filling regions. */
public static class EmfPlusBrush implements EmfPlusObjectData {
- private final EmfPlusGraphicsVersion version = new EmfPlusGraphicsVersion();
+ private final EmfPlusGraphicsVersion graphicsVersion = new EmfPlusGraphicsVersion();
private EmfPlusBrushType brushType;
private EmfPlusBrushData brushData;
@Override
public long init(LittleEndianInputStream leis, long dataSize, EmfPlusObjectType objectType, int flags) throws IOException {
- long size = version.init(leis);
+ long size = graphicsVersion.init(leis);
brushType = EmfPlusBrushType.valueOf(leis.readInt());
size += LittleEndianConsts.INT_SIZE;
@@ -224,6 +330,23 @@ public class HemfPlusBrush {
return size;
}
+
+ @Override
+ public void applyObject(HemfGraphics ctx, List<? extends EmfPlusObjectData> continuedObjectData) {
+ brushData.applyObject(ctx, continuedObjectData);
+ }
+
+ @Override
+ public EmfPlusGraphicsVersion getGraphicsVersion() {
+ return graphicsVersion;
+ }
+
+ @Override
+ public String toString() {
+ return
+ "{ brushType: '"+brushType+"'" +
+ ", brushData: "+brushData+" }";
+ }
}
/** The EmfPlusSolidBrushData object specifies a solid color for a graphics brush. */
@@ -234,6 +357,17 @@ public class HemfPlusBrush {
solidColor = readARGB(leis.readInt());
return LittleEndianConsts.INT_SIZE;
}
+
+ @Override
+ public void applyObject(HemfGraphics ctx, List<? extends EmfPlusObjectData> continuedObjectData) {
+ HemfDrawProperties prop = ctx.getProperties();
+ prop.setBackgroundColor(new HwmfColorRef(solidColor));
+ }
+
+ @Override
+ public String toString() {
+ return "{ solidColor: "+new HwmfColorRef(solidColor)+" }";
+ }
}
@@ -247,6 +381,22 @@ public class HemfPlusBrush {
backColor = readARGB(leis.readInt());
return 3*LittleEndianConsts.INT_SIZE;
}
+
+ @Override
+ public void applyObject(HemfGraphics ctx, List<? extends EmfPlusObjectData> continuedObjectData) {
+ HemfDrawProperties prop = ctx.getProperties();
+ prop.setBrushColor(new HwmfColorRef(foreColor));
+ prop.setBackgroundColor(new HwmfColorRef(backColor));
+ prop.setEmfPlusBrushHatch(style);
+ }
+
+ @Override
+ public String toString() {
+ return
+ "{ style: '"+style+"'" +
+ ", foreColor: "+new HwmfColorRef(foreColor) +
+ ", backColor: "+new HwmfColorRef(backColor) + " }";
+ }
}
/** The EmfPlusLinearGradientBrushData object specifies a linear gradient for a graphics brush. */
@@ -303,6 +453,32 @@ public class HemfPlusBrush {
return size;
}
+
+ @Override
+ public void applyObject(HemfGraphics ctx, List<? extends EmfPlusObjectData> continuedObjectData) {
+ HemfDrawProperties prop = ctx.getProperties();
+ // TODO: implement
+ }
+
+ @Override
+ public String toString() {
+ return
+ "{ flags: "+dataFlags+
+ ", wrapMode: '"+wrapMode+"'"+
+ ", rect: "+boundsToString(rect)+
+ ", startColor: "+new HwmfColorRef(startColor)+
+ ", endColor: "+new HwmfColorRef(endColor)+
+ ", transform: "+xformToString(transform)+
+ ", positions: "+ Arrays.toString(positions)+
+ ", blendColors: "+ colorsToString(blendColors)+
+ ", positionsV: "+ Arrays.toString(positionsV)+
+ ", blendFactorsV: "+ Arrays.toString(blendFactorsV)+
+ ", positionsH: "+ Arrays.toString(positionsH)+
+ ", blendFactorsH: "+ Arrays.toString(blendFactorsH)+
+ "}";
+ }
+
+
}
/** The EmfPlusPathGradientBrushData object specifies a path gradient for a graphics brush. */
@@ -409,6 +585,31 @@ public class HemfPlusBrush {
return size;
}
+
+ @Override
+ public void applyObject(HemfGraphics ctx, List<? extends EmfPlusObjectData> continuedObjectData) {
+
+ }
+
+ @Override
+ public String toString() {
+ return
+ "{ flags: "+dataFlags+
+ ", wrapMode: '"+wrapMode+"'"+
+ ", centerColor: "+new HwmfColorRef(centerColor)+
+ ", centerPoint: "+pointToString(centerPoint)+
+ ", surroundingColor: "+colorsToString(surroundingColor)+
+ ", boundaryPath: "+(boundaryPath == null ? "null" : boundaryPath)+
+ ", boundaryPoints: "+pointsToString(boundaryPoints)+
+ ", transform: "+xformToString(transform)+
+ ", positions: "+Arrays.toString(positions)+
+ ", blendColors: "+colorsToString(blendColors)+
+ ", blendFactorsH: "+Arrays.toString(blendFactorsH)+
+ ", focusScaleX: "+focusScaleX+
+ ", focusScaleY: "+focusScaleY+
+ "}"
+ ;
+ }
}
/** The EmfPlusTextureBrushData object specifies a texture image for a graphics brush. */
@@ -440,6 +641,24 @@ public class HemfPlusBrush {
return size;
}
+
+ @Override
+ public void applyObject(HemfGraphics ctx, List<? extends EmfPlusObjectData> continuedObjectData) {
+ image.applyObject(ctx, continuedObjectData);
+ HemfDrawProperties prop = ctx.getProperties();
+ prop.setBrushBitmap(prop.getEmfPlusImage());
+ prop.setBrushStyle(HwmfBrushStyle.BS_PATTERN);
+ }
+
+ @Override
+ public String toString() {
+ return
+ "{ flags: "+dataFlags+
+ ", wrapMode: '"+wrapMode+"'"+
+ ", transform: "+xformToString(transform)+
+ ", image: "+image+
+ "]";
+ }
}
private static int readPositions(LittleEndianInputStream leis, Consumer<double[]> pos) {
@@ -477,4 +696,18 @@ public class HemfPlusBrush {
facs.accept(factors);
return size + factors.length * LittleEndianConsts.INT_SIZE;
}
+
+ @Internal
+ public static String colorsToString(Color[] colors) {
+ return (colors == null ? "null" :
+ Stream.of(colors).map(HwmfColorRef::new).map(Object::toString).
+ collect(joining(",", "{", "}")));
+ }
+
+ @Internal
+ public static String pointsToString(Point2D[] points) {
+ return (points == null ? "null" :
+ Stream.of(points).map(HwmfDraw::pointToString).
+ collect(joining(",", "{", "}")));
+ }
}
Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emfplus/HemfPlusDraw.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emfplus/HemfPlusDraw.java?rev=1860732&r1=1860731&r2=1860732&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emfplus/HemfPlusDraw.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emfplus/HemfPlusDraw.java Thu Jun 6 22:32:41 2019
@@ -17,10 +17,18 @@
package org.apache.poi.hemf.record.emfplus;
+import static java.util.stream.Collectors.joining;
+import static org.apache.poi.hemf.record.emf.HemfDraw.xformToString;
+import static org.apache.poi.hwmf.record.HwmfDraw.boundsToString;
+import static org.apache.poi.hwmf.record.HwmfDraw.pointToString;
+
import java.awt.Color;
import java.awt.geom.AffineTransform;
+import java.awt.geom.Area;
+import java.awt.geom.Path2D;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
+import java.awt.image.BufferedImage;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.ArrayList;
@@ -30,8 +38,17 @@ import java.util.function.BiFunction;
import org.apache.commons.math3.linear.LUDecomposition;
import org.apache.commons.math3.linear.MatrixUtils;
import org.apache.commons.math3.linear.RealMatrix;
+import org.apache.poi.hemf.draw.HemfDrawProperties;
+import org.apache.poi.hemf.draw.HemfGraphics;
import org.apache.poi.hemf.record.emf.HemfFill;
+import org.apache.poi.hemf.record.emfplus.HemfPlusImage.EmfPlusImage;
import org.apache.poi.hemf.record.emfplus.HemfPlusMisc.EmfPlusObjectId;
+import org.apache.poi.hemf.record.emfplus.HemfPlusObject.EmfPlusObject;
+import org.apache.poi.hwmf.record.HwmfBrushStyle;
+import org.apache.poi.hwmf.record.HwmfColorRef;
+import org.apache.poi.hwmf.record.HwmfDraw;
+import org.apache.poi.hwmf.record.HwmfMisc.WmfSetBkMode.HwmfBkMode;
+import org.apache.poi.hwmf.record.HwmfTernaryRasterOp;
import org.apache.poi.util.BitField;
import org.apache.poi.util.BitFieldFactory;
import org.apache.poi.util.IOUtils;
@@ -116,12 +133,45 @@ public class HemfPlusDraw {
}
}
+ public interface EmfPlusSolidColor {
+ /**
+ * If set, brushId specifies a color as an EmfPlusARGB object.
+ * If clear, brushId contains the index of an EmfPlusBrush object in the EMF+ Object Table.
+ */
+ BitField SOLID_COLOR = BitFieldFactory.getInstance(0x8000);
+
+ int getFlags();
+
+ int getBrushIdValue();
+
+ default boolean isSolidColor() {
+ return SOLID_COLOR.isSet(getFlags());
+ }
+
+ default int getBrushId() {
+ return (isSolidColor()) ? -1 : getBrushIdValue();
+ }
+
+ default Color getSolidColor() {
+ return (isSolidColor()) ? readARGB(getBrushIdValue()) : null;
+ }
+
+ default void applyColor(HemfGraphics ctx) {
+ HemfDrawProperties prop = ctx.getProperties();
+ if (isSolidColor()) {
+ prop.setBrushStyle(HwmfBrushStyle.BS_SOLID);
+ prop.setBrushColor(new HwmfColorRef(getSolidColor()));
+ } else {
+ ctx.applyObjectTableEntry(getBrushId());
+ }
+ }
+ }
/**
* The EmfPlusDrawPath record specifies drawing a graphics path
*/
- public static class EmfPlusDrawPath implements HemfPlusRecord {
+ public static class EmfPlusDrawPath implements HemfPlusRecord, EmfPlusObjectId {
private int flags;
private int penId;
@@ -148,18 +198,31 @@ public class HemfPlusDraw {
return LittleEndianConsts.INT_SIZE;
}
+
+ @Override
+ public void draw(HemfGraphics ctx) {
+ ctx.applyObjectTableEntry(penId);
+ ctx.applyObjectTableEntry(getObjectId());
+
+ HemfDrawProperties prop = ctx.getProperties();
+ final Path2D path = prop.getPath();
+ if (path != null) {
+ ctx.draw(path);
+ }
+ }
+
+ @Override
+ public String toString() {
+ return
+ "{ flags: "+flags+
+ ", penId: "+penId+" }";
+ }
}
/**
* The EmfPlusFillRects record specifies filling the interiors of a series of rectangles.
*/
- public static class EmfPlusFillRects implements HemfPlusRecord, EmfPlusCompressed {
- /**
- * If set, brushId specifies a color as an EmfPlusARGB object.
- * If clear, brushId contains the index of an EmfPlusBrush object in the EMF+ Object Table.
- */
- private static final BitField SOLID_COLOR = BitFieldFactory.getInstance(0x8000);
-
+ public static class EmfPlusFillRects implements HemfPlusRecord, EmfPlusCompressed, EmfPlusSolidColor {
private int flags;
private int brushId;
private final ArrayList<Rectangle2D> rectData = new ArrayList<>();
@@ -198,6 +261,29 @@ public class HemfPlusDraw {
return size;
}
+
+ @Override
+ public void draw(HemfGraphics ctx) {
+ applyColor(ctx);
+
+ Area area = new Area();
+ rectData.stream().map(Area::new).forEach(area::add);
+ ctx.fill(area);
+ }
+
+ @Override
+ public int getBrushIdValue() {
+ return brushId;
+ }
+
+ @Override
+ public String toString() {
+ return
+ "{ flags: "+flags+
+ ", brushId: "+brushId+
+ ", rectData: "+rectData.stream().map(HwmfDraw::boundsToString).collect(joining(",", "{", "}"))+
+ "}";
+ }
}
public static class EmfPlusDrawImagePoints implements HemfPlusRecord, EmfPlusObjectId, EmfPlusCompressed, EmfPlusRelativePosition {
@@ -302,6 +388,58 @@ public class HemfPlusDraw {
return size;
}
+
+ @Override
+ public void draw(HemfGraphics ctx) {
+ HemfDrawProperties prop = ctx.getProperties();
+
+ ctx.applyObjectTableEntry(imageAttributesID);
+ ctx.applyObjectTableEntry(getObjectId());
+
+ AffineTransform txSaved = ctx.getTransform(), tx = new AffineTransform(txSaved);
+ try {
+ tx.concatenate(trans);
+ ctx.setTransform(tx);
+
+ EmfPlusObject imgObj = (EmfPlusObject)ctx.getObjectTableEntry(getObjectId());
+ EmfPlusImage img = imgObj.getObjectData();
+ Rectangle2D srcBounds = img.getBounds(imgObj.getContinuedObject());
+ BufferedImage bi = prop.getEmfPlusImage();
+
+ prop.setRasterOp(HwmfTernaryRasterOp.SRCCOPY);
+ prop.setBkMode(HwmfBkMode.TRANSPARENT);
+
+ // the buffered image might be rescaled, so we need to calculate a new src rect to take
+ // the image data from
+ AffineTransform srcTx = new AffineTransform();
+ srcTx.translate(-srcBounds.getX(), srcBounds.getY());
+ srcTx.scale(bi.getWidth()/srcBounds.getWidth(), bi.getHeight()/srcBounds.getHeight());
+ srcTx.translate(bi.getMinX(), bi.getMinY());
+
+ Rectangle2D biRect = srcTx.createTransformedShape(srcRect).getBounds2D();
+
+ // TODO: handle srcUnit
+ Rectangle2D destRect = new Rectangle2D.Double(0, 0, biRect.getWidth(), biRect.getHeight());
+ ctx.drawImage(bi, srcRect, destRect);
+ } finally {
+ ctx.setTransform(txSaved);
+ }
+ }
+
+ @Override
+ public String toString() {
+ return
+ "{ flags: "+flags+
+ ", imageAttributesID: "+imageAttributesID+
+ ", srcUnit: '"+srcUnit+"'"+
+ ", srcRect: "+boundsToString(srcRect)+
+ ", upperLeft: "+pointToString(upperLeft)+
+ ", lowerLeft: "+pointToString(lowerLeft)+
+ ", lowerRight: "+pointToString(lowerRight)+
+ ", transform: "+xformToString(trans)+
+ "}"
+ ;
+ }
}
/** The EmfPlusDrawImage record specifies drawing a scaled image. */
@@ -347,12 +485,34 @@ public class HemfPlusDraw {
return size;
}
+
+ @Override
+ public void draw(HemfGraphics ctx) {
+ ctx.applyObjectTableEntry(imageAttributesID);
+ ctx.applyObjectTableEntry(getObjectId());
+
+ HemfDrawProperties prop = ctx.getProperties();
+ prop.setRasterOp(HwmfTernaryRasterOp.SRCCOPY);
+ prop.setBkMode(HwmfBkMode.TRANSPARENT);
+
+ ctx.drawImage(prop.getEmfPlusImage(), srcRect, rectData);
+ }
+
+ @Override
+ public String toString() {
+ return
+ "{ flags: "+flags+
+ ", imageAttributesID: "+imageAttributesID+
+ ", srcUnit: '"+srcUnit+"'"+
+ ", srcRect: "+boundsToString(srcRect)+
+ ", rectData: "+boundsToString(rectData)+
+ "}"
+ ;
+ }
}
/** The EmfPlusFillRegion record specifies filling the interior of a graphics region. */
- public static class EmfPlusFillRegion implements HemfPlusRecord {
- private static final BitField SOLID_COLOR = BitFieldFactory.getInstance(0x8000);
-
+ public static class EmfPlusFillRegion implements HemfPlusRecord, EmfPlusSolidColor, EmfPlusObjectId {
private int flags;
private int brushId;
@@ -366,16 +526,9 @@ public class HemfPlusDraw {
return flags;
}
- public boolean isSolidColor() {
- return SOLID_COLOR.isSet(getFlags());
- }
-
- public int getBrushId() {
- return (isSolidColor()) ? -1 : brushId;
- }
-
- public Color getSolidColor() {
- return (isSolidColor()) ? readARGB(brushId) : null;
+ @Override
+ public int getBrushIdValue() {
+ return brushId;
}
@Override
@@ -390,6 +543,21 @@ public class HemfPlusDraw {
return LittleEndianConsts.INT_SIZE;
}
+
+ @Override
+ public void draw(HemfGraphics ctx) {
+ applyColor(ctx);
+ ctx.applyObjectTableEntry(getObjectId());
+ HemfDrawProperties prop = ctx.getProperties();
+ ctx.fill(prop.getPath());
+ }
+
+ @Override
+ public String toString() {
+ return
+ "{ flags: "+flags+
+ ", brushId: "+brushId+" }";
+ }
}
/** The EmfPlusFillPath record specifies filling the interior of a graphics path. */
@@ -403,13 +571,7 @@ public class HemfPlusDraw {
}
/** The EmfPlusDrawDriverString record specifies text output with character positions. */
- public static class EmfPlusDrawDriverString implements HemfPlusRecord, EmfPlusObjectId {
- /**
- * If set, brushId specifies a color as an EmfPlusARGB object.
- * If clear, brushId contains the index of an EmfPlusBrush object in the EMF+ Object Table.
- */
- private static final BitField SOLID_COLOR = BitFieldFactory.getInstance(0x8000);
-
+ public static class EmfPlusDrawDriverString implements HemfPlusRecord, EmfPlusObjectId, EmfPlusSolidColor {
/**
* If set, the positions of character glyphs SHOULD be specified in a character map lookup table.
* If clear, the glyph positions SHOULD be obtained from an array of coordinates.
@@ -454,6 +616,11 @@ public class HemfPlusDraw {
}
@Override
+ public int getBrushIdValue() {
+ return brushId;
+ }
+
+ @Override
public long init(LittleEndianInputStream leis, long dataSize, long recordId, int flags) throws IOException {
this.flags = flags;
@@ -615,7 +782,7 @@ public class HemfPlusDraw {
}
static Color readARGB(int argb) {
- return new Color( (argb >>> 8) & 0xFF, (argb >>> 16) & 0xFF, (argb >>> 24) & 0xFF, argb & 0xFF);
+ return new Color((argb >>> 16) & 0xFF, (argb >>> 8) & 0xFF, argb & 0xFF, (argb >>> 24) & 0xFF);
}
}
Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emfplus/HemfPlusFont.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emfplus/HemfPlusFont.java?rev=1860732&r1=1860731&r2=1860732&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emfplus/HemfPlusFont.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emfplus/HemfPlusFont.java Thu Jun 6 22:32:41 2019
@@ -18,7 +18,9 @@
package org.apache.poi.hemf.record.emfplus;
import java.io.IOException;
+import java.util.List;
+import org.apache.poi.hemf.draw.HemfGraphics;
import org.apache.poi.hemf.record.emfplus.HemfPlusDraw.EmfPlusUnitType;
import org.apache.poi.hemf.record.emfplus.HemfPlusHeader.EmfPlusGraphicsVersion;
import org.apache.poi.hemf.record.emfplus.HemfPlusObject.EmfPlusObjectData;
@@ -60,7 +62,7 @@ public class HemfPlusFont {
private static final BitField STRIKEOUT = BitFieldFactory.getInstance(0x00000008);
- private final EmfPlusGraphicsVersion version = new EmfPlusGraphicsVersion();
+ private final EmfPlusGraphicsVersion graphicsVersion = new EmfPlusGraphicsVersion();
private double emSize;
private EmfPlusUnitType sizeUnit;
private int styleFlags;
@@ -70,7 +72,7 @@ public class HemfPlusFont {
public long init(LittleEndianInputStream leis, long dataSize, HemfPlusObject.EmfPlusObjectType objectType, int flags) throws IOException {
// An EmfPlusGraphicsVersion object that specifies the version of operating system graphics that was used
// to create this object.
- long size = version.init(leis);
+ long size = graphicsVersion.init(leis);
// A 32-bit floating-point value that specifies the em size of the font in units specified by the SizeUnit field.
emSize = leis.readFloat();
@@ -96,5 +98,15 @@ public class HemfPlusFont {
return size;
}
+
+ @Override
+ public void applyObject(HemfGraphics ctx, List<? extends EmfPlusObjectData> continuedObjectData) {
+
+ }
+
+ @Override
+ public EmfPlusGraphicsVersion getGraphicsVersion() {
+ return graphicsVersion;
+ }
}
}
Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emfplus/HemfPlusHeader.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emfplus/HemfPlusHeader.java?rev=1860732&r1=1860731&r2=1860732&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emfplus/HemfPlusHeader.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emfplus/HemfPlusHeader.java Thu Jun 6 22:32:41 2019
@@ -20,6 +20,8 @@ package org.apache.poi.hemf.record.emfpl
import java.io.IOException;
+import org.apache.poi.hemf.draw.HemfGraphics;
+import org.apache.poi.hemf.draw.HemfGraphics.EmfRenderState;
import org.apache.poi.util.BitField;
import org.apache.poi.util.BitFieldFactory;
import org.apache.poi.util.Internal;
@@ -85,6 +87,19 @@ public class HemfPlusHeader implements H
return version;
}
+ /**
+ * If set, this flag indicates that this metafile is "dual-mode", which means that it contains two sets of records,
+ * each of which completely specifies the graphics content. If clear, the graphics content is specified by EMF+
+ * records, and possibly EMF records that are preceded by an EmfPlusGetDC record. If this flag is set, EMF records
+ * alone SHOULD suffice to define the graphics content. Note that whether the "dual-mode" flag is set or not, some
+ * EMF records are always present, namely EMF control records and the EMF records that contain EMF+ records.
+ *
+ * @return {@code true} if dual-mode is enabled
+ */
+ public boolean isEmfPlusDualMode() {
+ return (emfPlusFlags & 1) == 1;
+ }
+
public long getEmfPlusFlags() {
return emfPlusFlags;
}
@@ -98,6 +113,13 @@ public class HemfPlusHeader implements H
}
@Override
+ public void draw(HemfGraphics ctx) {
+ // currently EMF is better supported than EMF+ ... so if there's a complete set of EMF records available,
+ // disable EMF+ rendering for now
+ ctx.setRenderState(isEmfPlusDualMode() ? EmfRenderState.EMF_ONLY : EmfRenderState.EMFPLUS_ONLY);
+ }
+
+ @Override
public String toString() {
return "HemfPlusHeader{" +
"flags=" + flags +
Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emfplus/HemfPlusImage.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emfplus/HemfPlusImage.java?rev=1860732&r1=1860731&r2=1860732&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emfplus/HemfPlusImage.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emfplus/HemfPlusImage.java Thu Jun 6 22:32:41 2019
@@ -20,18 +20,45 @@ package org.apache.poi.hemf.record.emfpl
import static org.apache.poi.hemf.record.emfplus.HemfPlusDraw.readARGB;
import java.awt.Color;
+import java.awt.Graphics2D;
+import java.awt.RenderingHints;
+import java.awt.Transparency;
+import java.awt.color.ColorSpace;
+import java.awt.geom.Dimension2D;
+import java.awt.geom.Rectangle2D;
+import java.awt.image.BufferedImage;
+import java.awt.image.ComponentColorModel;
+import java.awt.image.DataBuffer;
+import java.awt.image.DataBufferByte;
+import java.awt.image.PixelInterleavedSampleModel;
+import java.awt.image.Raster;
+import java.awt.image.WritableRaster;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
import java.io.IOException;
+import java.util.List;
+import java.util.function.BiConsumer;
+import javax.imageio.ImageIO;
+
+import org.apache.poi.hemf.draw.HemfDrawProperties;
+import org.apache.poi.hemf.draw.HemfGraphics;
import org.apache.poi.hemf.record.emfplus.HemfPlusHeader.EmfPlusGraphicsVersion;
import org.apache.poi.hemf.record.emfplus.HemfPlusObject.EmfPlusObjectData;
import org.apache.poi.hemf.record.emfplus.HemfPlusObject.EmfPlusObjectType;
+import org.apache.poi.hemf.usermodel.HemfPicture;
+import org.apache.poi.hwmf.usermodel.HwmfPicture;
import org.apache.poi.util.BitField;
import org.apache.poi.util.BitFieldFactory;
import org.apache.poi.util.IOUtils;
import org.apache.poi.util.LittleEndianConsts;
import org.apache.poi.util.LittleEndianInputStream;
+import org.apache.poi.util.Units;
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. */
@@ -302,7 +329,7 @@ public class HemfPlusImage {
leis.mark(LittleEndianConsts.INT_SIZE);
long size = graphicsVersion.init(leis);
- if (graphicsVersion.getGraphicsVersion() == null || graphicsVersion.getMetafileSignature() != 0xDBC01) {
+ if (isContinuedRecord()) {
// CONTINUABLE is not always correctly set, so we check the version field if this record is continued
imageDataType = EmfPlusImageDataType.CONTINUED;
leis.reset();
@@ -385,8 +412,193 @@ public class HemfPlusImage {
return size + fileSize;
}
+
+ @Override
+ public EmfPlusGraphicsVersion getGraphicsVersion() {
+ return graphicsVersion;
+ }
+
+ public Rectangle2D getBounds(List<? extends EmfPlusObjectData> continuedObjectData) {
+ try {
+ switch (getImageDataType()) {
+ case BITMAP:
+ if (getBitmapType() == EmfPlusBitmapDataType.PIXEL) {
+ return new Rectangle2D.Double(0, 0, bitmapWidth, bitmapHeight);
+ } else {
+ BufferedImage bi = ImageIO.read(new ByteArrayInputStream(getRawData(continuedObjectData)));
+ return new Rectangle2D.Double(bi.getMinX(), bi.getMinY(), bi.getWidth(), bi.getHeight());
+ }
+ case METAFILE:
+ ByteArrayInputStream bis = new ByteArrayInputStream(getRawData(continuedObjectData));
+ switch (getMetafileType()) {
+ case Wmf:
+ case WmfPlaceable:
+ HwmfPicture wmf = new HwmfPicture(bis);
+ return wmf.getBounds();
+ case Emf:
+ case EmfPlusDual:
+ case EmfPlusOnly:
+ HemfPicture emf = new HemfPicture(bis);
+ return emf.getBounds();
+ }
+ break;
+ default:
+ break;
+ }
+ } catch (Exception ignored) {
+ }
+ return new Rectangle2D.Double(1,1,1,1);
+ }
+
+ public byte[] getRawData(List<? extends EmfPlusObjectData> continuedObjectData) {
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ try {
+ bos.write(getImageData());
+ if (continuedObjectData != null) {
+ for (EmfPlusObjectData od : continuedObjectData) {
+ bos.write(((EmfPlusImage)od).getImageData());
+ }
+ }
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ return bos.toByteArray();
+ }
+
+ @Override
+ public void applyObject(HemfGraphics ctx, List<? extends EmfPlusObjectData> continuedObjectData) {
+ HemfDrawProperties prop = ctx.getProperties();
+ BufferedImage bi = readImage(getRawData(continuedObjectData));
+ prop.setEmfPlusImage(bi);
+ }
+
+ /**
+ * Converts the gdi pixel data to a buffered image
+ * @param data the image data of all EmfPlusImage parts
+ * @return the BufferedImage
+ */
+ public BufferedImage readGDIImage(final byte[] data) {
+ if (getImageDataType() != EmfPlusImageDataType.BITMAP || getBitmapType() != EmfPlusBitmapDataType.PIXEL) {
+ throw new RuntimeException("image data is not a GDI image");
+ }
+
+ final int width = getBitmapWidth();
+ final int height = getBitmapHeight();
+ final int stride = getBitmapStride();
+ final EmfPlusPixelFormat pf = getPixelFormat();
+
+ int[] nBits, bOffs;
+ switch (pf) {
+ case ARGB_32BPP:
+ nBits = new int[]{8, 8, 8, 8};
+ bOffs = new int[]{2, 1, 0, 3};
+ break;
+ case RGB_24BPP:
+ nBits = new int[]{8, 8, 8};
+ bOffs = new int[]{2, 1, 0};
+ break;
+ default:
+ throw new RuntimeException("not yet implemented");
+ }
+
+ ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
+ ComponentColorModel cm = new ComponentColorModel
+ (cs, nBits, pf.isAlpha(), pf.isPreMultiplied(), Transparency.TRANSLUCENT, DataBuffer.TYPE_BYTE);
+ PixelInterleavedSampleModel csm =
+ new PixelInterleavedSampleModel(cm.getTransferType(), width, height, cm.getNumComponents(), stride, bOffs);
+
+ DataBufferByte dbb = new DataBufferByte(data, data.length);
+ WritableRaster raster = (WritableRaster) Raster.createRaster(csm, dbb, null);
+
+ return new BufferedImage(cm, raster, cm.isAlphaPremultiplied(), null);
+ }
+
+ private BufferedImage readImage(final byte[] data) {
+ // TODO: instead of returning a BufferedImage, we might return a pair of raw data + image renderer
+ // instead, so metafiles aren't pixelated, but directly written to the output graphics context
+ try {
+ switch (getImageDataType()) {
+ case BITMAP: {
+ BufferedImage bi = (getBitmapType() == EmfPlusBitmapDataType.PIXEL)
+ ? readGDIImage(data)
+ : ImageIO.read(new ByteArrayInputStream(data));
+
+// final int w = bi.getWidth();
+// final int h = bi.getHeight();
+//
+// int[] line = new int[w];
+//
+// WritableRaster wr = bi.getRaster();
+// for (int row=0; row<h; row++) {
+// wr.get
+// for (int x=0; x<w; x++) {
+// // TODO: use clamp color here
+// if ((line[x] & 0xFFFFFF) == 0) {
+// // make it transparent
+// line[x] &= 0xFFFFFF;
+// }
+// }
+// wr.setPixels(0, row, w, 1, line);
+// }
+
+
+ return bi;
+ }
+ case METAFILE:
+ assert (getMetafileType() != null);
+ switch (getMetafileType()) {
+ case Wmf:
+ case WmfPlaceable:
+ HwmfPicture wmf = new HwmfPicture(new ByteArrayInputStream(data));
+ return readImage(wmf.getSize(), wmf::draw);
+
+ case Emf:
+ case EmfPlusDual:
+ case EmfPlusOnly:
+ HemfPicture emf = new HemfPicture(new ByteArrayInputStream(data));
+ return readImage(emf.getSize(), emf::draw);
+
+ default:
+ break;
+ }
+ default:
+ break;
+ }
+ } catch (IOException ignored) {
+ }
+
+ // fallback to empty image
+ return new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
+ }
+
+ private BufferedImage readImage(final Dimension2D dim, final BiConsumer<Graphics2D,Rectangle2D> draw) {
+ int width = Units.pointsToPixel(dim.getWidth());
+ // keep aspect ratio for height
+ int height = Units.pointsToPixel(dim.getHeight());
+ double longSide = Math.max(width,height);
+ if (longSide > MAX_IMAGE_SIZE) {
+ double scale = MAX_IMAGE_SIZE / longSide;
+ width *= scale;
+ height *= scale;
+ }
+
+ BufferedImage bufImg = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
+ Graphics2D g = bufImg.createGraphics();
+ g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+ g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
+ g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
+ g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
+
+ draw.accept(g, new Rectangle2D.Double(0, 0, width, height));
+
+ g.dispose();
+
+ return bufImg;
+ }
}
+
+
public static class EmfPlusImageAttributes implements EmfPlusObjectData {
private final EmfPlusGraphicsVersion graphicsVersion = new EmfPlusGraphicsVersion();
private EmfPlusWrapMode wrapMode;
@@ -434,6 +646,10 @@ public class HemfPlusImage {
public EmfPlusObjectClamp getObjectClamp() {
return objectClamp;
}
+
+ @Override
+ public void applyObject(HemfGraphics ctx, List<? extends EmfPlusObjectData> continuedObjectData) {
+ }
}
}
Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emfplus/HemfPlusMisc.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emfplus/HemfPlusMisc.java?rev=1860732&r1=1860731&r2=1860732&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emfplus/HemfPlusMisc.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emfplus/HemfPlusMisc.java Thu Jun 6 22:32:41 2019
@@ -17,6 +17,7 @@
package org.apache.poi.hemf.record.emfplus;
+import static org.apache.poi.hemf.record.emf.HemfMisc.adaptXForm;
import static org.apache.poi.hemf.record.emfplus.HemfPlusDraw.readRectF;
import java.awt.geom.AffineTransform;
@@ -24,10 +25,10 @@ import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.io.IOException;
+import org.apache.poi.hemf.draw.HemfGraphics;
import org.apache.poi.hemf.record.emf.HemfFill;
import org.apache.poi.util.BitField;
import org.apache.poi.util.BitFieldFactory;
-import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.LittleEndianConsts;
import org.apache.poi.util.LittleEndianInputStream;
@@ -134,6 +135,12 @@ public class HemfPlusMisc {
* SHOULD be processed.
*/
public static class EmfPlusGetDC extends EmfPlusFlagOnly {
+ @Override
+ public void draw(HemfGraphics ctx) {
+ if (ctx.getRenderState() == HemfGraphics.EmfRenderState.EMFPLUS_ONLY) {
+ ctx.setRenderState(HemfGraphics.EmfRenderState.EMF_DCONTEXT);
+ }
+ }
}
/**
@@ -174,6 +181,18 @@ public class HemfPlusMisc {
return HemfFill.readXForm(leis, matrixData);
}
+
+ public AffineTransform getMatrixData() {
+ return matrixData;
+ }
+
+ @Override
+ public void draw(HemfGraphics ctx) {
+ ctx.updateWindowMapMode();
+ AffineTransform tx = ctx.getTransform();
+ tx.concatenate(getMatrixData());
+ ctx.setTransform(tx);
+ }
}
/**
@@ -185,6 +204,15 @@ public class HemfPlusMisc {
public HemfPlusRecordType getEmfPlusRecordType() {
return HemfPlusRecordType.multiplyWorldTransform;
}
+
+ @Override
+ public void draw(HemfGraphics ctx) {
+ ctx.updateWindowMapMode();
+ AffineTransform tx = ctx.getTransform();
+ tx.preConcatenate(adaptXForm(getMatrixData(), tx));
+ tx.concatenate(getMatrixData());
+ ctx.setTransform(tx);
+ }
}
/**
Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emfplus/HemfPlusObject.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emfplus/HemfPlusObject.java?rev=1860732&r1=1860731&r2=1860732&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emfplus/HemfPlusObject.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emfplus/HemfPlusObject.java Thu Jun 6 22:32:41 2019
@@ -18,8 +18,11 @@
package org.apache.poi.hemf.record.emfplus;
import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
import java.util.function.Supplier;
+import org.apache.poi.hemf.draw.HemfGraphics;
import org.apache.poi.hemf.record.emfplus.HemfPlusBrush.EmfPlusBrush;
import org.apache.poi.hemf.record.emfplus.HemfPlusFont.EmfPlusFont;
import org.apache.poi.hemf.record.emfplus.HemfPlusHeader.EmfPlusGraphicsVersion;
@@ -29,6 +32,8 @@ import org.apache.poi.hemf.record.emfplu
import org.apache.poi.hemf.record.emfplus.HemfPlusPath.EmfPlusPath;
import org.apache.poi.hemf.record.emfplus.HemfPlusPen.EmfPlusPen;
import org.apache.poi.hemf.record.emfplus.HemfPlusRegion.EmfPlusRegion;
+import org.apache.poi.hwmf.draw.HwmfGraphics;
+import org.apache.poi.hwmf.record.HwmfObjectTableEntry;
import org.apache.poi.util.BitField;
import org.apache.poi.util.BitFieldFactory;
import org.apache.poi.util.IOUtils;
@@ -107,7 +112,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.
*/
- public static class EmfPlusObject implements HemfPlusRecord, EmfPlusObjectId {
+ public static class EmfPlusObject implements HemfPlusRecord, EmfPlusObjectId, HwmfObjectTableEntry {
/**
@@ -126,6 +131,7 @@ public class HemfPlusObject {
// for debugging
private int objectId;
private EmfPlusObjectData objectData;
+ private List<EmfPlusObjectData> continuedObjectData;
private int totalObjectSize;
@Override
@@ -174,10 +180,50 @@ public class HemfPlusObject {
return size;
}
+
+ @Override
+ public void draw(HemfGraphics ctx) {
+ HwmfObjectTableEntry entry = ctx.getObjectTableEntry(getObjectId());
+ if (objectData.isContinuedRecord()) {
+ EmfPlusObject other;
+ if (entry instanceof EmfPlusObject && objectData.getClass().isInstance((other = (EmfPlusObject)entry).getObjectData())) {
+ other.linkContinuedObject(objectData);
+ return;
+ } else {
+ throw new RuntimeException("can't find previous record for continued record");
+ }
+ }
+ ctx.addObjectTableEntry(this, getObjectId());
+ }
+
+ @Override
+ public void applyObject(HwmfGraphics ctx) {
+ objectData.applyObject((HemfGraphics)ctx, continuedObjectData);
+ }
+
+ void linkContinuedObject(EmfPlusObjectData continueObject) {
+ if (continuedObjectData == null) {
+ continuedObjectData = new ArrayList<>();
+ }
+ continuedObjectData.add(continueObject);
+ }
+
+ List<EmfPlusObjectData> getContinuedObject() {
+ return continuedObjectData;
+ }
}
public interface EmfPlusObjectData {
long init(LittleEndianInputStream leis, long dataSize, EmfPlusObjectType objectType, int flags) throws IOException;
+
+ void applyObject(HemfGraphics ctx, List<? extends EmfPlusObjectData> continuedObjectData);
+
+ EmfPlusGraphicsVersion getGraphicsVersion();
+
+ default boolean isContinuedRecord() {
+ EmfPlusGraphicsVersion gv = getGraphicsVersion();
+ return (gv.getGraphicsVersion() == null || gv.getMetafileSignature() != 0xDBC01);
+ }
}
public static class EmfPlusUnknownData implements EmfPlusObjectData {
@@ -195,5 +241,15 @@ public class HemfPlusObject {
return dataSize;
}
+
+ @Override
+ public void applyObject(HemfGraphics ctx, List<? extends EmfPlusObjectData> continuedObjectData) {
+
+ }
+
+ @Override
+ public EmfPlusGraphicsVersion getGraphicsVersion() {
+ return graphicsVersion;
+ }
}
}
Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emfplus/HemfPlusPath.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emfplus/HemfPlusPath.java?rev=1860732&r1=1860731&r2=1860732&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emfplus/HemfPlusPath.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emfplus/HemfPlusPath.java Thu Jun 6 22:32:41 2019
@@ -17,11 +17,15 @@
package org.apache.poi.hemf.record.emfplus;
+import java.awt.geom.Path2D;
import java.awt.geom.Point2D;
import java.io.IOException;
import java.util.Arrays;
+import java.util.List;
import java.util.function.BiFunction;
+import org.apache.poi.hemf.draw.HemfDrawProperties;
+import org.apache.poi.hemf.draw.HemfGraphics;
import org.apache.poi.hemf.record.emfplus.HemfPlusDraw.EmfPlusCompressed;
import org.apache.poi.hemf.record.emfplus.HemfPlusDraw.EmfPlusRelativePosition;
import org.apache.poi.hemf.record.emfplus.HemfPlusObject.EmfPlusObjectData;
@@ -69,14 +73,14 @@ public class HemfPlusPath {
private static final BitField POINT_RLE_COUNT = BitFieldFactory.getInstance(0x3F);
- private final HemfPlusHeader.EmfPlusGraphicsVersion version = new HemfPlusHeader.EmfPlusGraphicsVersion();
+ private final HemfPlusHeader.EmfPlusGraphicsVersion graphicsVersion = new HemfPlusHeader.EmfPlusGraphicsVersion();
private int pointFlags;
private Point2D[] pathPoints;
private byte[] pointTypes;
@Override
public long init(LittleEndianInputStream leis, long dataSize, EmfPlusObjectType objectType, int flags) throws IOException {
- long size = version.init(leis);
+ long size = graphicsVersion.init(leis);
// A 32-bit unsigned integer that specifies the number of points and associated point types that
// are defined by this object.
@@ -124,6 +128,11 @@ public class HemfPlusPath {
return size;
}
+ @Override
+ public HemfPlusHeader.EmfPlusGraphicsVersion getGraphicsVersion() {
+ return graphicsVersion;
+ }
+
public boolean isPointDashed(int index) {
return POINT_TYPE_DASHED.isSet(pointTypes[index]);
}
@@ -144,6 +153,38 @@ public class HemfPlusPath {
public int getFlags() {
return pointFlags;
}
+
+
+
+ @Override
+ public void applyObject(HemfGraphics ctx, List<? extends EmfPlusObjectData> continuedObjectData) {
+ HemfDrawProperties prop = ctx.getProperties();
+ Path2D path = new Path2D.Double(Path2D.WIND_NON_ZERO);
+ prop.setPath(path);
+
+ for (int idx=0; idx < pathPoints.length; idx++) {
+ Point2D p1 = pathPoints[idx];
+ switch (getPointType(idx)) {
+ case START:
+ path.moveTo(p1.getX(), p1.getY());
+ break;
+ case LINE:
+ path.lineTo(p1.getX(), p1.getY());
+ break;
+ case BEZIER: {
+ Point2D p2 = pathPoints[++idx];
+ Point2D p3 = pathPoints[++idx];
+ path.curveTo(p1.getX(), p1.getY(), p2.getX(), p2.getY(), p3.getX(), p3.getY());
+ break;
+ }
+ }
+ if (isPointClosed(idx)) {
+ path.closePath();
+ }
+ }
+ }
+
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org