#60656 - Support export file that contains emf and render it correctly

git-svn-id: https://svn.apache.org/repos/asf/poi/branches/hemf@1844524 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andreas Beeker 2018-10-21 22:42:03 +00:00
parent 82f118a7d7
commit 11e4643e5b
4 changed files with 14 additions and 20 deletions

View File

@ -106,19 +106,21 @@ public class HemfGraphics extends HwmfGraphics {
final Path2D path; final Path2D path;
if (useBracket) { if (useBracket) {
path = prop.getPath(); path = prop.getPath();
if (path.getCurrentPoint() == null) {
// workaround if a path has been started and no MoveTo command
// has been specified before the first lineTo/splineTo
final Point2D loc = prop.getLocation();
path.moveTo(loc.getX(), loc.getY());
}
} else { } else {
path = new Path2D.Double(); path = new Path2D.Double();
Point2D pnt = prop.getLocation(); Point2D pnt = prop.getLocation();
path.moveTo(pnt.getX(),pnt.getY()); path.moveTo(pnt.getX(),pnt.getY());
} }
pathConsumer.accept(path); try {
pathConsumer.accept(path);
} catch (Exception e) {
// workaround if a path has been started and no MoveTo command
// has been specified before the first lineTo/splineTo
final Point2D loc = prop.getLocation();
path.moveTo(loc.getX(), loc.getY());
pathConsumer.accept(path);
}
prop.setLocation(path.getCurrentPoint()); prop.setLocation(path.getCurrentPoint());
if (!useBracket) { if (!useBracket) {

View File

@ -17,10 +17,6 @@
package org.apache.poi.hemf.record.emf; package org.apache.poi.hemf.record.emf;
import static org.apache.poi.hwmf.record.HwmfBrushStyle.BS_NULL;
import static org.apache.poi.hwmf.record.HwmfBrushStyle.BS_SOLID;
import java.awt.Color;
import java.awt.geom.Arc2D; import java.awt.geom.Arc2D;
import java.awt.geom.Area; import java.awt.geom.Area;
import java.awt.geom.Dimension2D; import java.awt.geom.Dimension2D;
@ -32,10 +28,8 @@ import java.io.IOException;
import org.apache.poi.hemf.draw.HemfDrawProperties; import org.apache.poi.hemf.draw.HemfDrawProperties;
import org.apache.poi.hemf.draw.HemfGraphics; import org.apache.poi.hemf.draw.HemfGraphics;
import org.apache.poi.hwmf.record.HwmfColorRef;
import org.apache.poi.hwmf.record.HwmfDraw; import org.apache.poi.hwmf.record.HwmfDraw;
import org.apache.poi.hwmf.record.HwmfDraw.WmfSelectObject; import org.apache.poi.hwmf.record.HwmfDraw.WmfSelectObject;
import org.apache.poi.hwmf.record.HwmfPenStyle;
import org.apache.poi.util.LittleEndianConsts; import org.apache.poi.util.LittleEndianConsts;
import org.apache.poi.util.LittleEndianInputStream; import org.apache.poi.util.LittleEndianInputStream;
@ -242,6 +236,7 @@ public class HemfDraw {
// if this path is connected to the current position (= has no start point) // if this path is connected to the current position (= has no start point)
// the first entry is a dummy entry and will be skipped later // the first entry is a dummy entry and will be skipped later
poly.moveTo(0,0); poly.moveTo(0,0);
poly.lineTo(pnt.getX(), pnt.getY());
} }
} else { } else {
poly.lineTo(pnt.getX(), pnt.getY()); poly.lineTo(pnt.getX(), pnt.getY());
@ -952,7 +947,6 @@ public class HemfDraw {
path.closePath(); path.closePath();
prop.setLocation(path.getCurrentPoint()); prop.setLocation(path.getCurrentPoint());
} }
} }
@Override @Override

View File

@ -106,8 +106,8 @@ public enum HemfRecordType {
setDiBitsToDevice(0x00000050, HemfFill.EmfSetDiBitsToDevice::new), setDiBitsToDevice(0x00000050, HemfFill.EmfSetDiBitsToDevice::new),
stretchDiBits(0x00000051, HemfFill.EmfStretchDiBits::new), stretchDiBits(0x00000051, HemfFill.EmfStretchDiBits::new),
extCreateFontIndirectW(0x00000052, HemfText.ExtCreateFontIndirectW::new), extCreateFontIndirectW(0x00000052, HemfText.ExtCreateFontIndirectW::new),
exttextouta(0x00000053, HemfText.EmfExtTextOutA::new), extTextOutA(0x00000053, HemfText.EmfExtTextOutA::new),
exttextoutw(0x00000054, HemfText.EmfExtTextOutW::new), extTextOutW(0x00000054, HemfText.EmfExtTextOutW::new),
polyBezier16(0x00000055, HemfDraw.EmfPolyBezier16::new), polyBezier16(0x00000055, HemfDraw.EmfPolyBezier16::new),
polygon16(0x00000056, HemfDraw.EmfPolygon16::new), polygon16(0x00000056, HemfDraw.EmfPolygon16::new),
polyline16(0x00000057, HemfDraw.EmfPolyline16::new), polyline16(0x00000057, HemfDraw.EmfPolyline16::new),

View File

@ -28,7 +28,6 @@ import java.awt.geom.Rectangle2D;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import org.apache.commons.codec.Charsets;
import org.apache.poi.hemf.draw.HemfGraphics; import org.apache.poi.hemf.draw.HemfGraphics;
import org.apache.poi.hwmf.draw.HwmfGraphics; import org.apache.poi.hwmf.draw.HwmfGraphics;
import org.apache.poi.hwmf.record.HwmfText; import org.apache.poi.hwmf.record.HwmfText;
@ -38,7 +37,6 @@ import org.apache.poi.util.IOUtils;
import org.apache.poi.util.Internal; import org.apache.poi.util.Internal;
import org.apache.poi.util.LittleEndianConsts; import org.apache.poi.util.LittleEndianConsts;
import org.apache.poi.util.LittleEndianInputStream; import org.apache.poi.util.LittleEndianInputStream;
import org.apache.poi.util.LocaleUtil;
import org.apache.poi.util.RecordFormatException; import org.apache.poi.util.RecordFormatException;
/** /**
@ -72,7 +70,7 @@ public class HemfText {
@Override @Override
public HemfRecordType getEmfRecordType() { public HemfRecordType getEmfRecordType() {
return HemfRecordType.exttextouta; return HemfRecordType.extTextOutA;
} }
@Override @Override
@ -209,7 +207,7 @@ public class HemfText {
@Override @Override
public HemfRecordType getEmfRecordType() { public HemfRecordType getEmfRecordType() {
return HemfRecordType.exttextoutw; return HemfRecordType.extTextOutW;
} }
public String getText() throws IOException { public String getText() throws IOException {