mirror of
https://github.com/apache/poi.git
synced 2026-02-27 20:40:08 +08:00
#64716 - wmf display error
update heuristic to respect location of bounding box git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1894206 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
defd26493f
commit
6583f68d2f
@ -30,6 +30,7 @@ import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Stream;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
@ -56,6 +57,9 @@ class TestPPTX2PNG {
|
||||
private static boolean xslfOnly;
|
||||
private static final POIDataSamples samples = POIDataSamples.getSlideShowInstance();
|
||||
|
||||
private static final Pattern XSLF_EXT = Pattern.compile("(?i).*\\.pptx$");
|
||||
private static final Pattern ALL_EXT = Pattern.compile("(?i).*\\.(ppt.?|emf|wmf)$");
|
||||
|
||||
private static final File basedir = null;
|
||||
|
||||
private static final String files =
|
||||
@ -91,27 +95,32 @@ class TestPPTX2PNG {
|
||||
public static Stream<Arguments> data() throws IOException {
|
||||
// Junit closes all closable arguments after the usage
|
||||
// therefore we need to wrap the archive in non-closable arrays
|
||||
|
||||
Stream<Arguments> result;
|
||||
if (basedir != null && basedir.getName().endsWith(".zip")) {
|
||||
ZipFile zipFile = new ZipFile(basedir);
|
||||
archive = zipFile;
|
||||
return zipFile.stream().map(f -> Arguments.of(f.getName(), f, new ZipFile[]{zipFile}));
|
||||
result = zipFile.stream().
|
||||
map(f -> Arguments.of(new File(f.getName()).getName(), f, new ZipFile[]{zipFile}));
|
||||
} else if (basedir != null && basedir.getName().endsWith(".7z")) {
|
||||
SevenZFile sevenZFile = new SevenZFile(basedir);
|
||||
archive = sevenZFile;
|
||||
return ((ArrayList<SevenZArchiveEntry>)sevenZFile.getEntries()).stream().filter(f -> !f.isDirectory()).map(f -> Arguments.of(f.getName(), f, new SevenZFile[]{sevenZFile}));
|
||||
result = ((ArrayList<SevenZArchiveEntry>)sevenZFile.getEntries()).stream().
|
||||
filter(f -> !f.isDirectory()).
|
||||
map(f -> Arguments.of(f.getName(), f, new SevenZFile[]{sevenZFile}));
|
||||
} else {
|
||||
return Stream.of(files.split(", ?")).
|
||||
result = Stream.of(files.split(", ?")).
|
||||
map(basedir == null ? samples::getFile : f -> new File(basedir, f)).
|
||||
map(f -> Arguments.of(f.getName(), f, f.getParentFile()));
|
||||
}
|
||||
|
||||
return result.filter(args -> (xslfOnly ? XSLF_EXT : ALL_EXT).matcher((String)args.get()[0]).find());
|
||||
|
||||
}
|
||||
|
||||
// use filename instead of File object to omit full pathname in test name
|
||||
@ParameterizedTest(name = "{0} ({index})")
|
||||
@MethodSource("data")
|
||||
void render(String fileName, Object fileObj, Object fileContainer) throws Exception {
|
||||
assumeFalse(xslfOnly && fileName.matches(".*\\.(ppt|emf|wmf)$"), "ignore HSLF (.ppt) / HEMF (.emf) / HWMF (.wmf) files in no-scratchpad run");
|
||||
PPTX2PNG.main(getArgs(fileName, fileObj, fileContainer, "null"));
|
||||
if (svgFiles.contains(fileName)) {
|
||||
PPTX2PNG.main(getArgs(fileName, fileObj, fileContainer, "svg"));
|
||||
|
||||
@ -27,6 +27,7 @@ import java.awt.Graphics2D;
|
||||
import java.awt.Shape;
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.awt.geom.Dimension2D;
|
||||
import java.awt.geom.Point2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.Charset;
|
||||
@ -36,6 +37,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Spliterator;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@ -230,9 +232,8 @@ public class HemfPicture implements Iterable<HemfRecord>, GenericRecord {
|
||||
? winBounds
|
||||
: emfBounds;
|
||||
} else {
|
||||
double recHyp = dia(recBounds);
|
||||
b = Stream.of(emfBounds, winBounds, viewBounds).
|
||||
min(comparingDouble(r -> abs(dia(r) - recHyp))).get();
|
||||
min(comparingDouble(r -> diff(r, recBounds))).get();
|
||||
}
|
||||
|
||||
ctx.translate(graphicsBounds.getCenterX(), graphicsBounds.getCenterY());
|
||||
@ -258,8 +259,14 @@ public class HemfPicture implements Iterable<HemfRecord>, GenericRecord {
|
||||
}
|
||||
}
|
||||
|
||||
private static double dia(Rectangle2D bounds) {
|
||||
return Math.sqrt(bounds.getWidth()*bounds.getWidth() + bounds.getHeight()*bounds.getWidth());
|
||||
private static double diff(Rectangle2D bounds, Rectangle2D target) {
|
||||
double d = 0;
|
||||
for (int i=0; i<4; i++) {
|
||||
Function<Rectangle2D,Double> fx = (i < 2) ? Rectangle2D::getMinX : Rectangle2D::getMaxX;
|
||||
Function<Rectangle2D,Double> fy = (i % 2 == 0) ? Rectangle2D::getMinY : Rectangle2D::getMaxY;
|
||||
d += Point2D.distanceSq(fx.apply(bounds), fy.apply(bounds), fx.apply(target), fy.apply(target));
|
||||
}
|
||||
return d;
|
||||
}
|
||||
|
||||
public Iterable<HwmfEmbedded> getEmbeddings() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user