aboutsummaryrefslogtreecommitdiffstats
path: root/src/examples
diff options
context:
space:
mode:
authorAndreas Beeker <kiwiwings@apache.org>2020-11-27 22:41:06 +0000
committerAndreas Beeker <kiwiwings@apache.org>2020-11-27 22:41:06 +0000
commit3f83c76321e7d290a983ef3a7ad5dbc188236488 (patch)
tree9e8be380ac041684ecdec8ed281a63f4e072430d /src/examples
parentc6b408b232dfde2e2ba4d930a57ca57d84a7b25f (diff)
downloadpoi-3f83c76321e7d290a983ef3a7ad5dbc188236488.tar.gz
poi-3f83c76321e7d290a983ef3a7ad5dbc188236488.zip
#64716 - wmf display error
prepare binary raster operations git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1883882 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/examples')
-rw-r--r--src/examples/src/org/apache/poi/examples/hwmf/ROP2Table.java106
-rw-r--r--src/examples/src/org/apache/poi/examples/hwmf/ROP3Table.java168
2 files changed, 274 insertions, 0 deletions
diff --git a/src/examples/src/org/apache/poi/examples/hwmf/ROP2Table.java b/src/examples/src/org/apache/poi/examples/hwmf/ROP2Table.java
new file mode 100644
index 0000000000..a6c0b64978
--- /dev/null
+++ b/src/examples/src/org/apache/poi/examples/hwmf/ROP2Table.java
@@ -0,0 +1,106 @@
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.examples.hwmf;
+
+import java.awt.Color;
+import java.awt.Composite;
+import java.awt.Font;
+import java.awt.Graphics2D;
+import java.awt.geom.AffineTransform;
+import java.awt.geom.Rectangle2D;
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.IOException;
+
+import javax.imageio.ImageIO;
+
+import org.apache.poi.hwmf.draw.HwmfROP2Composite;
+import org.apache.poi.hwmf.record.HwmfBinaryRasterOp;
+import org.apache.poi.util.Units;
+
+/**
+ * Generates an image table describing the various binary raster operations
+ *
+ * inspired from http://www.fengyuan.com/sample/samplech8.html
+ */
+public final class ROP2Table {
+ private static final Color[] COLORS = {
+ new Color(0,0,0),
+ new Color(128,0,0),
+ new Color(0,128,0),
+ new Color(128,128,0),
+ new Color(0,0,128),
+ new Color(128,0,128),
+ new Color(0,128,128),
+ new Color(192,192,192),
+ new Color(255,255,255),
+ new Color(128,128,128),
+ new Color(255,0,0),
+ new Color(0,255,0),
+ new Color(255,255,0),
+ new Color(0,0,255),
+ new Color(255,0,255),
+ new Color(0,255,255)
+ };
+
+ private ROP2Table() {
+ }
+
+ public static void main(String[] args) throws IOException {
+ int square = 800;
+ BufferedImage bi = new BufferedImage(square + 500, square, BufferedImage.TYPE_INT_ARGB);
+ Graphics2D g = bi.createGraphics();
+ double space = 0.2;
+ double hbar = square / (COLORS.length + space);
+ double vbar = square / (COLORS.length + space);
+ double y = hbar * space;
+ double x = vbar * space;
+ double w = square - 2*x;
+ double h = square - 2*y;
+
+ Rectangle2D vrect = new Rectangle2D.Double(x, y, vbar * (1-space), h);
+ for (Color c : COLORS) {
+ g.setColor(c);
+ g.fill(vrect);
+ g.translate(vbar, 0);
+ }
+
+ g.setTransform(new AffineTransform());
+ g.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, (int) Units.pixelToPoints(hbar * 0.8)));
+
+ Composite comp = g.getComposite();
+
+ Rectangle2D hrect = new Rectangle2D.Double(x, y, w, hbar * (1-space));
+ int idx = 0;
+ for (HwmfBinaryRasterOp op : HwmfBinaryRasterOp.values()) {
+ g.setComposite(comp);
+ g.setColor(Color.BLACK);
+ g.drawString(op.name(), (int)(square+vbar), (int)(hbar*0.8));
+ g.setComposite(new HwmfROP2Composite(op));
+ g.setColor(Color.RED);
+ g.fill(hrect);
+ g.translate(0, hbar);
+ idx++;
+ }
+
+ g.dispose();
+ ImageIO.write(bi, "PNG", new File("rop2.png"));
+ }
+
+
+}
diff --git a/src/examples/src/org/apache/poi/examples/hwmf/ROP3Table.java b/src/examples/src/org/apache/poi/examples/hwmf/ROP3Table.java
new file mode 100644
index 0000000000..13d49468e8
--- /dev/null
+++ b/src/examples/src/org/apache/poi/examples/hwmf/ROP3Table.java
@@ -0,0 +1,168 @@
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.examples.hwmf;
+
+import java.awt.AlphaComposite;
+import java.awt.Color;
+import java.awt.Font;
+import java.awt.Graphics2D;
+import java.awt.Rectangle;
+import java.awt.Shape;
+import java.awt.TexturePaint;
+import java.awt.font.TextLayout;
+import java.awt.geom.AffineTransform;
+import java.awt.geom.Ellipse2D;
+import java.awt.geom.Rectangle2D;
+import java.awt.image.BufferedImage;
+import java.awt.image.IndexColorModel;
+import java.io.File;
+import java.io.IOException;
+
+import javax.imageio.ImageIO;
+
+import org.apache.poi.hwmf.draw.HwmfROP3Composite;
+import org.apache.poi.hwmf.record.HwmfTernaryRasterOp;
+
+/**
+ * Generates an image table describing the various ternary raster operations
+ *
+ * inspired from http://www.evmsoft.net/en/roptest.html
+ */
+public final class ROP3Table {
+ private ROP3Table() {
+ }
+
+ private static byte[] PATTERN = {
+ 1, 0, 1, 0, 1, 0, 1, 0,
+ 0, 1, 0, 1, 0, 1, 0, 1,
+ 1, 0, 1, 1, 1, 0, 1, 1,
+ 0, 1, 0, 1, 0, 1, 0, 1,
+ 1, 0, 1, 0, 1, 0, 1, 0,
+ 0, 1, 0, 1, 0, 1, 0, 1,
+ 1, 0, 1, 1, 1, 0, 1, 1,
+ 0, 1, 0, 1, 0, 1, 0, 1,
+ };
+
+ private static final HwmfTernaryRasterOp[] OPS = HwmfTernaryRasterOp.values();
+ private static final int COLS = 16;
+ private static final double BOX = 100, SCALE = 1, HEADER = 1.1;
+
+ private static final Rectangle2D RECT = new Rectangle2D.Double(0.05* BOX, 0.05* BOX, 0.90* BOX, 0.90* BOX);
+ private static final Shape CIRCLE_BIG = new Ellipse2D.Double(0.15* BOX, 0.15* BOX, 0.70* BOX, 0.70* BOX);
+ private static final Shape CIRCLE_SMALL = new Ellipse2D.Double(0.40* BOX, 0.40* BOX, 0.20* BOX, 0.20* BOX);
+ private static final Shape LABEL_BOX = new Rectangle.Double(0.06* BOX, 0.85* BOX, 0.88* BOX, 0.10* BOX);
+
+ private static final AlphaComposite SRC_OVER = AlphaComposite.getInstance(AlphaComposite.SRC_OVER);
+
+ private static final AffineTransform INIT_AT = AffineTransform.getScaleInstance(SCALE, SCALE);
+
+ public static void main(String[] args) throws IOException {
+ BufferedImage pattern = getPattern();
+ BufferedImage source = getSource();
+
+ BufferedImage dest = new BufferedImage(
+ (int)(BOX * COLS * SCALE),
+ (int)(BOX *(Math.max(OPS.length/COLS,1) + HEADER)* SCALE),
+ BufferedImage.TYPE_INT_ARGB);
+ Graphics2D g = dest.createGraphics();
+
+ g.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 10));
+
+ g.setTransform(INIT_AT);
+ g.setColor(Color.BLACK);
+
+ for (int i=0; i<3; i++) {
+ String str = new String[]{"Dest:","Source:","Pattern:"}[i];
+ TextLayout t = new TextLayout(str, g.getFont(), g.getFontRenderContext());
+ Rectangle2D b = t.getBounds();
+ g.drawString(str, (float)(((i*2+0.95)*BOX - b.getWidth())), (float)(0.55 * BOX));
+ }
+
+ g.translate(BOX, 0);
+ fillDest(g);
+ g.translate(2*BOX, 0);
+ g.drawImage(source, 0, 0, null);
+ g.translate(2*BOX, 0);
+ g.setPaint(new TexturePaint(pattern, RECT));
+ g.fill(RECT);
+
+ int idx=0;
+ for (HwmfTernaryRasterOp op : OPS) {
+ g.setTransform(INIT_AT);
+ g.translate(0, HEADER * BOX);
+ g.translate(BOX*(idx%COLS), BOX*(idx/COLS));
+
+ fillDest(g);
+ fillPattern(g, op, pattern, source);
+ fillLabel(g, op);
+ idx++;
+ }
+
+ g.dispose();
+ ImageIO.write(dest, "PNG", new File("rop3.png"));
+ }
+
+ private static BufferedImage getPattern() {
+ byte[] bw = { 0, -1 };
+ BufferedImage pattern = new BufferedImage(8, 8, BufferedImage.TYPE_BYTE_INDEXED, new IndexColorModel(1, 2, bw, bw, bw));
+ pattern.getRaster().setDataElements(0, 0, 8, 8, PATTERN);
+ return pattern;
+ }
+
+ private static BufferedImage getSource() {
+ BufferedImage checker = new BufferedImage((int) BOX, (int) BOX, BufferedImage.TYPE_INT_ARGB);
+ Graphics2D cg = checker.createGraphics();
+ cg.setColor(Color.PINK);
+ cg.fill(new Rectangle2D.Double(0.05* BOX, 0.05* BOX, 0.90* BOX, 0.90* BOX));
+ cg.setColor(new Color(0xE6E6FA, false));
+ cg.fill(new Rectangle2D.Double(0.05* BOX, 0.05* BOX, 0.45* BOX, 0.45* BOX));
+ cg.fill(new Rectangle2D.Double(0.50* BOX, 0.50* BOX, 0.45* BOX, 0.45* BOX));
+ cg.dispose();
+ return checker;
+ }
+
+ private static void fillDest(Graphics2D g) {
+ g.setComposite(SRC_OVER);
+ g.setColor(Color.LIGHT_GRAY);
+ g.fill(RECT);
+ g.setColor(new Color(0xDAA520, false));
+ g.fill(CIRCLE_BIG);
+ g.setColor(Color.RED);
+ g.fill(CIRCLE_SMALL);
+ }
+
+ private static void fillPattern(Graphics2D g, HwmfTernaryRasterOp op, BufferedImage pattern, BufferedImage source) {
+ g.setComposite(new HwmfROP3Composite(g.getTransform(), RECT, op, pattern, Color.YELLOW, Color.BLUE));
+ g.setClip(RECT);
+ g.drawImage(source, 0, 0, null);
+ g.setClip(null);
+ g.setComposite(SRC_OVER);
+ }
+
+ private static void fillLabel(Graphics2D g, HwmfTernaryRasterOp op) {
+ g.setColor(Color.WHITE);
+ g.fill(LABEL_BOX);
+ g.setColor(Color.BLACK);
+
+ TextLayout t = new TextLayout(op.name(), g.getFont(), g.getFontRenderContext());
+ Rectangle2D b = t.getBounds();
+ g.drawString(op.name(), (float)((BOX -b.getWidth())/2.), (float)(0.94* BOX));
+
+ }
+
+}