Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

DrawGroupShape.java 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package org.apache.poi.sl.draw;
  2. import java.awt.Graphics2D;
  3. import java.awt.geom.AffineTransform;
  4. import java.awt.geom.Rectangle2D;
  5. import org.apache.poi.sl.usermodel.*;
  6. public class DrawGroupShape<T extends GroupShape<? extends Shape>> extends DrawShape<T> implements Drawable {
  7. public DrawGroupShape(T shape) {
  8. super(shape);
  9. }
  10. public void draw(Graphics2D graphics) {
  11. // the coordinate system of this group of shape
  12. Rectangle2D interior = shape.getInteriorAnchor();
  13. // anchor of this group relative to the parent shape
  14. Rectangle2D exterior = shape.getAnchor();
  15. AffineTransform tx = (AffineTransform)graphics.getRenderingHint(Drawable.GROUP_TRANSFORM);
  16. AffineTransform tx0 = new AffineTransform(tx);
  17. double scaleX = interior.getWidth() == 0. ? 1.0 : exterior.getWidth() / interior.getWidth();
  18. double scaleY = interior.getHeight() == 0. ? 1.0 : exterior.getHeight() / interior.getHeight();
  19. tx.translate(exterior.getX(), exterior.getY());
  20. tx.scale(scaleX, scaleY);
  21. tx.translate(-interior.getX(), -interior.getY());
  22. DrawFactory drawFact = DrawFactory.getInstance(graphics);
  23. AffineTransform at2 = graphics.getTransform();
  24. for (Shape child : shape) {
  25. // remember the initial transform and restore it after we are done with the drawing
  26. AffineTransform at = graphics.getTransform();
  27. graphics.setRenderingHint(Drawable.GSAVE, true);
  28. Drawable draw = drawFact.getDrawable(child);
  29. draw.applyTransform(graphics);
  30. draw.draw(graphics);
  31. // restore the coordinate system
  32. graphics.setTransform(at);
  33. graphics.setRenderingHint(Drawable.GRESTORE, true);
  34. }
  35. graphics.setTransform(at2);
  36. graphics.setRenderingHint(Drawable.GROUP_TRANSFORM, tx0);
  37. }
  38. }