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.

XSSFChildAnchor.java 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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.xssf.usermodel;
  16. import org.apache.poi.util.Internal;
  17. import org.openxmlformats.schemas.drawingml.x2006.main.CTPoint2D;
  18. import org.openxmlformats.schemas.drawingml.x2006.main.CTPositiveSize2D;
  19. import org.openxmlformats.schemas.drawingml.x2006.main.CTTransform2D;
  20. public final class XSSFChildAnchor extends XSSFAnchor {
  21. private CTTransform2D t2d;
  22. public XSSFChildAnchor(int x, int y, int cx, int cy) {
  23. t2d = CTTransform2D.Factory.newInstance();
  24. CTPoint2D off = t2d.addNewOff();
  25. CTPositiveSize2D ext = t2d.addNewExt();
  26. off.setX(x);
  27. off.setY(y);
  28. ext.setCx(Math.abs(cx - x));
  29. ext.setCy(Math.abs(cy - y));
  30. if(x > cx) t2d.setFlipH(true);
  31. if(y > cy) t2d.setFlipV(true);
  32. }
  33. public XSSFChildAnchor(CTTransform2D t2d) {
  34. this.t2d = t2d;
  35. }
  36. @Internal
  37. public CTTransform2D getCTTransform2D() {
  38. return t2d;
  39. }
  40. public int getDx1() {
  41. return (int)t2d.getOff().getX();
  42. }
  43. public void setDx1(int dx1) {
  44. t2d.getOff().setX(dx1);
  45. }
  46. public int getDy1() {
  47. return (int)t2d.getOff().getY();
  48. }
  49. public void setDy1(int dy1) {
  50. t2d.getOff().setY(dy1);
  51. }
  52. public int getDy2() {
  53. return (int)(getDy1() + t2d.getExt().getCy());
  54. }
  55. public void setDy2(int dy2) {
  56. t2d.getExt().setCy(dy2 - (long)getDy1());
  57. }
  58. public int getDx2() {
  59. return (int)(getDx1() + t2d.getExt().getCx());
  60. }
  61. public void setDx2(int dx2) {
  62. t2d.getExt().setCx(dx2 - (long)getDx1());
  63. }
  64. }