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.

CustomGeometry.java 3.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * ====================================================================
  3. * Licensed to the Apache Software Foundation (ASF) under one or more
  4. * contributor license agreements. See the NOTICE file distributed with
  5. * this work for additional information regarding copyright ownership.
  6. * The ASF licenses this file to You under the Apache License, Version 2.0
  7. * (the "License"); you may not use this file except in compliance with
  8. * the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. * ====================================================================
  18. */
  19. package org.apache.poi.xslf.model.geom;
  20. import java.util.ArrayList;
  21. import java.util.Iterator;
  22. import java.util.List;
  23. import org.openxmlformats.schemas.drawingml.x2006.main.CTCustomGeometry2D;
  24. import org.openxmlformats.schemas.drawingml.x2006.main.CTGeomGuide;
  25. import org.openxmlformats.schemas.drawingml.x2006.main.CTGeomGuideList;
  26. import org.openxmlformats.schemas.drawingml.x2006.main.CTGeomRect;
  27. import org.openxmlformats.schemas.drawingml.x2006.main.CTPath2D;
  28. import org.openxmlformats.schemas.drawingml.x2006.main.CTPath2DList;
  29. /**
  30. * Definition of a custom geometric shape
  31. *
  32. * @author Yegor Kozlov
  33. */
  34. public class CustomGeometry implements Iterable<Path>{
  35. List<Guide> adjusts = new ArrayList<Guide>();
  36. List<Guide> guides = new ArrayList<Guide>();
  37. List<Path> paths = new ArrayList<Path>();
  38. Path textBounds;
  39. @SuppressWarnings("deprecation")
  40. public CustomGeometry(CTCustomGeometry2D geom) {
  41. CTGeomGuideList avLst = geom.getAvLst();
  42. if(avLst != null) for(CTGeomGuide gd : avLst.getGdArray()){
  43. adjusts.add(new AdjustValue(gd));
  44. }
  45. CTGeomGuideList gdLst = geom.getGdLst();
  46. if(gdLst != null) for(CTGeomGuide gd : gdLst.getGdArray()){
  47. guides.add(new Guide(gd));
  48. }
  49. CTPath2DList pathLst = geom.getPathLst();
  50. if(pathLst != null) for(CTPath2D spPath : pathLst.getPathArray()){
  51. paths.add(new Path(spPath));
  52. }
  53. if(geom.isSetRect()) {
  54. CTGeomRect rect = geom.getRect();
  55. textBounds = new Path();
  56. textBounds.addCommand(
  57. new MoveToCommand(rect.getL().toString(), rect.getT().toString()));
  58. textBounds.addCommand(
  59. new LineToCommand(rect.getR().toString(), rect.getT().toString()));
  60. textBounds.addCommand(
  61. new LineToCommand(rect.getR().toString(), rect.getB().toString()));
  62. textBounds.addCommand(
  63. new LineToCommand(rect.getL().toString(), rect.getB().toString()));
  64. textBounds.addCommand(
  65. new ClosePathCommand());
  66. }
  67. }
  68. public Iterator<Path> iterator() {
  69. return paths.iterator();
  70. }
  71. public Path getTextBounds(){
  72. return textBounds;
  73. }
  74. }