You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ROP2Table.java 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /* ====================================================================
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. ==================================================================== */
  15. package org.apache.poi.examples.hwmf;
  16. import java.awt.Color;
  17. import java.awt.Composite;
  18. import java.awt.Font;
  19. import java.awt.Graphics2D;
  20. import java.awt.geom.AffineTransform;
  21. import java.awt.geom.Rectangle2D;
  22. import java.awt.image.BufferedImage;
  23. import java.io.File;
  24. import java.io.IOException;
  25. import javax.imageio.ImageIO;
  26. import org.apache.poi.hwmf.draw.HwmfROP2Composite;
  27. import org.apache.poi.hwmf.record.HwmfBinaryRasterOp;
  28. import org.apache.poi.util.Units;
  29. /**
  30. * Generates an image table describing the various binary raster operations
  31. *
  32. * inspired from http://www.fengyuan.com/sample/samplech8.html
  33. */
  34. public final class ROP2Table {
  35. private static final Color[] COLORS = {
  36. new Color(0,0,0),
  37. new Color(128,0,0),
  38. new Color(0,128,0),
  39. new Color(128,128,0),
  40. new Color(0,0,128),
  41. new Color(128,0,128),
  42. new Color(0,128,128),
  43. new Color(192,192,192),
  44. new Color(255,255,255),
  45. new Color(128,128,128),
  46. new Color(255,0,0),
  47. new Color(0,255,0),
  48. new Color(255,255,0),
  49. new Color(0,0,255),
  50. new Color(255,0,255),
  51. new Color(0,255,255)
  52. };
  53. private ROP2Table() {
  54. }
  55. public static void main(String[] args) throws IOException {
  56. int square = 800;
  57. BufferedImage bi = new BufferedImage(square + 500, square, BufferedImage.TYPE_INT_ARGB);
  58. Graphics2D g = bi.createGraphics();
  59. double space = 0.2;
  60. double hbar = square / (COLORS.length + space);
  61. double vbar = square / (COLORS.length + space);
  62. double y = hbar * space;
  63. double x = vbar * space;
  64. double w = square - 2*x;
  65. double h = square - 2*y;
  66. Rectangle2D vrect = new Rectangle2D.Double(x, y, vbar * (1-space), h);
  67. for (Color c : COLORS) {
  68. g.setColor(c);
  69. g.fill(vrect);
  70. g.translate(vbar, 0);
  71. }
  72. g.setTransform(new AffineTransform());
  73. g.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, (int) Units.pixelToPoints(hbar * 0.8)));
  74. Composite comp = g.getComposite();
  75. Rectangle2D hrect = new Rectangle2D.Double(x, y, w, hbar * (1-space));
  76. int idx = 0;
  77. for (HwmfBinaryRasterOp op : HwmfBinaryRasterOp.values()) {
  78. g.setComposite(comp);
  79. g.setColor(Color.BLACK);
  80. g.drawString(op.name(), (int)(square+vbar), (int)(hbar*0.8));
  81. g.setComposite(new HwmfROP2Composite(op));
  82. g.setColor(Color.RED);
  83. g.fill(hrect);
  84. g.translate(0, hbar);
  85. idx++;
  86. }
  87. g.dispose();
  88. ImageIO.write(bi, "PNG", new File("rop2.png"));
  89. }
  90. }