package org.apache.poi.hemf.record.emf;
import static org.apache.poi.hwmf.record.HwmfDraw.boundsToString;
+import static org.apache.poi.hwmf.record.HwmfDraw.normalizeBounds;
import java.awt.Shape;
import java.awt.geom.Arc2D;
@Override
public void draw(HemfGraphics ctx) {
- ctx.draw(path -> path.append(bounds, false), FillDrawStyle.FILL_DRAW);
+ ctx.draw(path -> path.append(normalizeBounds(bounds), false), FillDrawStyle.FILL_DRAW);
}
}
}
static long readDimensionInt(LittleEndianInputStream leis, Dimension2D dimension) {
- final double width = leis.readUInt();
- final double height = leis.readUInt();
+ // although the spec says "use unsigned ints", there are examples out there using signed ints
+ final double width = leis.readInt();
+ final double height = leis.readInt();
dimension.setSize(width, height);
return 2*LittleEndianConsts.INT_SIZE;
}
import static org.apache.poi.hemf.record.emf.HemfDraw.readRectL;
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;
import java.awt.Shape;
import java.awt.geom.AffineTransform;
return size;
}
+
+ @Override
+ public String toString() {
+ return
+ "{ bounds: " + boundsToString(bounds) +
+ ", dest: " + pointToString(dest) +
+ ", src: " + boundsToString(src) +
+ ", usageSrc: '" + usageSrc + "'" +
+ ", bitmap: " + bitmap +
+ "}";
+ }
}
static long readBitmap(final LittleEndianInputStream leis, final HwmfBitmapDib bitmap,
protected static class LogFontExDv implements LogFontDetails {
protected int[] designVector;
+
+ @Override
+ public String toString() {
+ return "{ designVectorLen: " + (designVector == null ? 0 : designVector.length) + " }";
+ }
}
protected static class LogFontPanose implements LogFontDetails {
protected Letterform letterform;
protected MidLine midLine;
protected XHeight xHeight;
+
+ @Override
+ public String toString() {
+ return
+ "{ styleSize: " + styleSize +
+ ", vendorId: " + vendorId +
+ ", culture: " + culture +
+ ", familyType: '" + familyType + "'" +
+ ", serifStyle: '" + serifStyle + "'" +
+ ", weight: '" + weight + "'" +
+ ", proportion: '" + proportion + "'" +
+ ", contrast: '" + contrast + "'" +
+ ", strokeVariation: '" + strokeVariation + "'" +
+ ", armStyle: '" + armStyle + "'" +
+ ", letterform: '" + letterform + "'" +
+ ", midLine: '" + midLine + "'" +
+ ", xHeight: '" + xHeight + "'" +
+ "}";
+ }
}
protected String fullname;
size += (2+numAxes)*LittleEndianConsts.INT_SIZE;
}
-
-
-
return size;
}
+ @Override
+ public String toString() {
+ return
+ "{ fullname: '" + (fullname == null ? "" : fullname) + "'" +
+ ", style: '" + (style == null ? "" : style) + "'" +
+ ", script: '" + (script == null ? "" : script) + "'" +
+ ", details: " + details +
+ "," + super.toString().substring(1);
+ }
+
@Override
protected int readString(LittleEndianInputStream leis, StringBuilder sb, int limit) throws IOException {
sb.setLength(0);
", bytes: " + bytes +
", records: " + records +
", handles: " + handles +
- ", description: '" + description + "'" +
+ ", description: '" + (description == null ? "" : description) + "'" +
", nPalEntries: " + nPalEntries +
", hasExtension1: " + hasExtension1 +
", cbPixelFormat: " + cbPixelFormat +
@Override
public void applyObject(HwmfGraphics ctx) {
+ if (!bitmap.isValid()) {
+ return;
+ }
HwmfDrawProperties props = ctx.getProperties();
props.setBrushStyle(HwmfBrushStyle.BS_PATTERN);
BufferedImage bmp = bitmap.getImage();
props.setBrushBitmap(bmp);
}
+
+ @Override
+ public String toString() {
+ return
+ "{ penIndex: " + penIndex +
+ ", colorUsage: " + colorUsage +
+ ", bitmap: " + bitmap +
+ "}";
+ }
}
}
@Override
public void draw(HwmfGraphics ctx) {
- ctx.drawString(rawTextBytes, stringLength, reference, bounds, options, dx, isUnicode());
+ // A 32-bit floating-point value that specifies the scale factor to apply along
+ // the axis to convert from page space units to .01mm units.
+ // This SHOULD be used only if the graphics mode specified by iGraphicsMode is GM_COMPATIBLE.
+ Dimension2D scl = graphicsMode == EmfGraphicsMode.GM_COMPATIBLE ? scale : null;
+ ctx.drawString(rawTextBytes, stringLength, reference, scl, bounds, options, dx, isUnicode());
}
@Override
import static org.apache.poi.hemf.record.emf.HemfDraw.readDimensionInt;
import static org.apache.poi.hemf.record.emf.HemfDraw.readPointL;
+import static org.apache.poi.hwmf.record.HwmfDraw.normalizeBounds;
import java.io.IOException;
@Override
public long init(LittleEndianInputStream leis, long recordSize, long recordId) throws IOException {
- return HemfDraw.readRectL(leis, bounds);
+ return HemfDraw.readRectL(leis, normalizeBounds(bounds));
}
}
textVAlignAsian = HwmfTextVerticalAlignment.TOP;
rasterOp = HwmfTernaryRasterOp.PATCOPY;
clip = null;
+ font = new HwmfFont();
+ font.initDefaults();
}
public HwmfDrawProperties(HwmfDrawProperties other) {
import java.awt.font.TextLayout;
import java.awt.geom.AffineTransform;
import java.awt.geom.Area;
+import java.awt.geom.Dimension2D;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
case MM_ANISOTROPIC:
// scale window bounds to output bounds
if (view != null) {
- graphicsCtx.translate(view.getX() - win.getX(), view.getY() - win.getY());
+ graphicsCtx.translate(view.getCenterX(), view.getCenterY());
graphicsCtx.scale(view.getWidth() / win.getWidth(), view.getHeight() / win.getHeight());
+ graphicsCtx.translate(-win.getCenterX(), -win.getCenterY());
}
break;
case MM_ISOTROPIC:
}
public void drawString(byte[] text, int length, Point2D reference) {
- drawString(text, length, reference, null, null, null, false);
+ drawString(text, length, reference, null, null, null, null, false);
}
- public void drawString(byte[] text, int length, Point2D reference, Rectangle2D clip, WmfExtTextOutOptions opts, List<Integer> dx, boolean isUnicode) {
+ public void drawString(byte[] text, int length, Point2D reference, Dimension2D scale, Rectangle2D clip, WmfExtTextOutOptions opts, List<Integer> dx, boolean isUnicode) {
final HwmfDrawProperties prop = getProperties();
HwmfFont font = prop.getFont();
graphicsCtx.translate(reference.getX(), reference.getY());
graphicsCtx.rotate(angle);
+ if (scale != null) {
+ graphicsCtx.scale(scale.getWidth() < 0 ? -1 : 1, scale.getHeight() < 0 ? -1 : 1);
+ }
graphicsCtx.translate(dst.getX(), dst.getY());
graphicsCtx.setColor(prop.getTextColor().getColor());
graphicsCtx.drawString(as.getIterator(), 0, 0);
*/
public class HwmfBitmapDib {
+ private static final POILogger logger = POILogFactory.getLogger(HwmfBitmapDib.class);
+ private static final int BMP_HEADER_SIZE = 14;
private static final int MAX_RECORD_LENGTH = HwmfPicture.MAX_RECORD_LENGTH;
- public static enum BitCount {
+ public enum BitCount {
/**
* The image SHOULD be in either JPEG or PNG format. <6> Neither of these formats includes
* a color table, so this value specifies that no color table is present. See [JFIF] and [RFC2083]
}
}
- public static enum Compression {
+ public enum Compression {
/**
* The bitmap is in uncompressed red green blue (RGB) format that is not compressed
* and does not use color masks.
}
}
- private final static POILogger logger = POILogFactory.getLogger(HwmfBitmapDib.class);
- private static final int BMP_HEADER_SIZE = 14;
-
+
private int headerSize;
private int headerWidth;
private int headerHeight;
}
public boolean isValid() {
- return (imageData != null);
+ // the recordsize ended before the image data
+ if (imageData == null) {
+ return false;
+ }
+
+ // ignore all black mono-brushes
+ if (this.headerBitCount == BitCount.BI_BITCOUNT_1) {
+ if (colorTable == null) {
+ return false;
+ }
+
+ for (Color c : colorTable) {
+ if (!Color.BLACK.equals(c)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ return true;
}
public InputStream getBMPStream() {
}
}
+ @Override
+ public String toString() {
+ return
+ "{ headerSize: " + headerSize +
+ ", width: " + headerWidth +
+ ", height: " + headerHeight +
+ ", planes: " + headerPlanes +
+ ", bitCount: '" + headerBitCount + "'" +
+ ", compression: '" + headerCompression + "'" +
+ ", imageSize: " + headerImageSize +
+ ", xPelsPerMeter: " + headerXPelsPerMeter +
+ ", yPelsPerMeter: " + headerYPelsPerMeter +
+ ", colorUsed: " + headerColorUsed +
+ ", colorImportant: " + headerColorImportant +
+ ", imageSize: " + (imageData == null ? 0 : imageData.length) +
+ "}";
+ }
+
protected BufferedImage getPlaceholder() {
BufferedImage bi = new BufferedImage(headerWidth, headerHeight, BufferedImage.TYPE_INT_ARGB);
Graphics2D g = bi.createGraphics();
return "{ w: "+dim.getWidth()+", h: "+dim.getHeight()+" }";
}
+ @Internal
+ public static Rectangle2D normalizeBounds(Rectangle2D bounds) {
+ return (bounds.getWidth() >= 0 && bounds.getHeight() >= 0) ? bounds
+ : new Rectangle2D.Double(
+ bounds.getWidth() >= 0 ? bounds.getMinX() : bounds.getMaxX(),
+ bounds.getHeight() >= 0 ? bounds.getMinY() : bounds.getMaxY(),
+ Math.abs(bounds.getWidth()),
+ Math.abs(bounds.getHeight())
+ );
+ }
}
prop.setRasterOp(rasterOperation);
if (bitmap.isValid()) {
ctx.drawImage(getImage(), srcBounds, dstBounds);
- } else {
+ } else if (!dstBounds.isEmpty()) {
BufferedImage bi = new BufferedImage((int)dstBounds.getWidth(), (int)dstBounds.getHeight(), BufferedImage.TYPE_INT_ARGB);
ctx.drawImage(bi, dstBounds, dstBounds);
}
return 5*LittleEndianConsts.SHORT_SIZE+8*LittleEndianConsts.BYTE_SIZE+readBytes;
}
+ public void initDefaults() {
+ height = -12;
+ width = 0;
+ escapement = 0;
+ weight = 400;
+ italic = false;
+ underline = false;
+ strikeOut = false;
+ charSet = FontCharset.ANSI;
+ outPrecision = WmfOutPrecision.OUT_DEFAULT_PRECIS;
+ quality = WmfFontQuality.ANTIALIASED_QUALITY;
+ pitchAndFamily = FontFamily.FF_DONTCARE.getFlag() | (FontPitch.DEFAULT.getNativeId() << 6);
+ facename = "SansSerif";
+ }
+
public int getHeight() {
return height;
}
", charset: '"+charSet+"'"+
", outPrecision: '"+outPrecision+"'"+
", clipPrecision: '"+clipPrecision+"'"+
- ", qualtiy: '"+quality+"'"+
+ ", quality: '"+quality+"'"+
", pitch: '"+getPitch()+"'"+
", family: '"+getFamily()+"'"+
", facename: '"+facename+"'"+
@Override
public void applyObject(HwmfGraphics ctx) {
+ if (patternDib != null && !patternDib.isValid()) {
+ return;
+ }
HwmfDrawProperties prop = ctx.getProperties();
prop.setBrushStyle(style);
prop.setBrushBitmap(getImage());
@Override
public void draw(HwmfGraphics ctx) {
- ctx.drawString(rawTextBytes, stringLength, reference, bounds, options, dx, false);
+ ctx.drawString(rawTextBytes, stringLength, reference, null, bounds, options, dx, false);
}
public String getText(Charset charset) throws IOException {
package org.apache.poi.hwmf.record;
import static org.apache.poi.hwmf.record.HwmfDraw.boundsToString;
+import static org.apache.poi.hwmf.record.HwmfDraw.normalizeBounds;
import static org.apache.poi.hwmf.record.HwmfDraw.pointToString;
import static org.apache.poi.hwmf.record.HwmfDraw.readBounds;
import static org.apache.poi.hwmf.record.HwmfDraw.readPointS;
@Override
public void applyObject(HwmfGraphics ctx) {
+ ctx.setClip(normalizeBounds(bounds), HwmfRegionMode.RGN_DIFF, false);
}
@Override