import static org.apache.poi.hemf.record.emf.HemfRecordIterator.HEADER_SIZE;
import java.awt.geom.AffineTransform;
-import java.awt.geom.NoninvertibleTransformException;
import java.awt.geom.Point2D;
-import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.ArrayList;
final AffineTransform tx;
switch (modifyWorldTransformMode) {
case MWT_LEFTMULTIPLY:
-
- AffineTransform wsTrans;
- final Rectangle2D win = prop.getWindow();
- boolean noSetWindowExYet = win.getWidth() == 1 && win.getHeight() == 1;
- if (noSetWindowExYet) {
- // TODO: understand world-space transformation [MSDN-WRLDPGSPC]
- // experimental and horrible solved, because the world-space transformation behind it
- // is not understood :(
- // only found one example which had landscape bounds and transform of 90 degress
-
- try {
- wsTrans = xForm.createInverse();
- } catch (NoninvertibleTransformException e) {
- wsTrans = new AffineTransform();
- }
-
- Rectangle2D emfBounds = header.getBoundsRectangle();
-
- if (xForm.getShearX() == -1.0 && xForm.getShearY() == 1.0) {
- // rotate 90 deg
- wsTrans.translate(-emfBounds.getHeight(), emfBounds.getHeight());
- }
- } else {
- wsTrans = adaptXForm(xForm, ctx.getTransform());
- }
-
tx = ctx.getTransform();
- tx.concatenate(wsTrans);
+ tx.concatenate(adaptXForm(xForm, ctx.getTransform()));
break;
case MWT_RIGHTMULTIPLY:
tx = ctx.getTransform();
package org.apache.poi.hemf.usermodel;
+import static java.lang.Math.abs;
+
import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.geom.AffineTransform;
import java.util.Spliterator;
import java.util.function.Consumer;
+import org.apache.poi.hemf.draw.HemfDrawProperties;
import org.apache.poi.hemf.draw.HemfGraphics;
import org.apache.poi.hemf.record.emf.HemfHeader;
import org.apache.poi.hemf.record.emf.HemfRecord;
}
/**
- * Returns the bounding box in device-independent units. Usually this is taken from the placeable header.
+ * Returns the bounding box in device-independent units - usually this is in .01 millimeter units
*
- * @return the bounding box
+ * @return the bounding box in device-independent units
*/
public Rectangle2D getBounds() {
- HemfHeader header = (HemfHeader)getRecords().get(0);
- Rectangle2D dim = header.getFrameRectangle();
+ Rectangle2D dim = getHeader().getFrameRectangle();
double x = dim.getX(), y = dim.getY();
double width = dim.getWidth(), height = dim.getHeight();
if (dim.isEmpty() || Math.rint(width) == 0 || Math.rint(height) == 0) {
* @return the image size in points
*/
public Dimension2D getSize() {
- final Rectangle2D bounds = getBounds();
-
- if (bounds.isEmpty()) {
- return new Dimension2DDouble(100,100);
- }
-
- final double coeff = (double) Units.EMU_PER_CENTIMETER / Units.EMU_PER_POINT / 10.;
- double width = Math.abs(bounds.getWidth()*coeff);
- double height = Math.abs(bounds.getHeight()*coeff);
-
- return new Dimension2DDouble(width, height);
+ final Rectangle2D b = getHeader().getBoundsRectangle();
+ return Units.pixelToPoints(new Dimension2DDouble(abs(b.getWidth()), abs(b.getHeight())));
}
private static double minX(Rectangle2D bounds) {
}
public void draw(Graphics2D ctx, Rectangle2D graphicsBounds) {
- final HemfHeader header = (HemfHeader)getRecords().get(0);
-
final Shape clip = ctx.getClip();
final AffineTransform at = ctx.getTransform();
try {
- Rectangle2D emfBounds = header.getBoundsRectangle();
+ Rectangle2D emfBounds = getHeader().getBoundsRectangle();
// scale output bounds to image bounds
- ctx.translate(minX(graphicsBounds), minY(graphicsBounds));
+ ctx.translate(graphicsBounds.getCenterX(), graphicsBounds.getCenterY());
ctx.scale(graphicsBounds.getWidth()/emfBounds.getWidth(), graphicsBounds.getHeight()/emfBounds.getHeight());
- ctx.translate(-minX(emfBounds), -minY(emfBounds));
+ ctx.translate(-emfBounds.getCenterX(), -emfBounds.getCenterY());
- int idx = 0;
HemfGraphics g = new HemfGraphics(ctx, emfBounds);
+ HemfDrawProperties prop = g.getProperties();
+ prop.setViewportOrg(emfBounds.getX(), emfBounds.getY());
+ prop.setViewportExt(emfBounds.getWidth(), emfBounds.getHeight());
+
+ int idx = 0;
for (HemfRecord r : getRecords()) {
try {
g.draw(r);