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 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 org.openxmlformats.schemas.drawingml.x2006.main.*;
  21. import java.util.ArrayList;
  22. import java.util.Iterator;
  23. import java.util.List;
  24. import java.awt.geom.Rectangle2D;
  25. /**
  26. * Definition of a custom geometric shape
  27. *
  28. * @author Yegor Kozlov
  29. */
  30. public class CustomGeometry implements Iterable<Path>{
  31. List<Guide> adjusts = new ArrayList<Guide>();
  32. List<Guide> guides = new ArrayList<Guide>();
  33. List<Path> paths = new ArrayList<Path>();
  34. Path textBounds;
  35. public CustomGeometry(CTCustomGeometry2D geom) {
  36. CTGeomGuideList avLst = geom.getAvLst();
  37. if(avLst != null) for(CTGeomGuide gd : avLst.getGdList()){
  38. adjusts.add(new AdjustValue(gd));
  39. }
  40. CTGeomGuideList gdLst = geom.getGdLst();
  41. if(gdLst != null) for(CTGeomGuide gd : gdLst.getGdList()){
  42. guides.add(new Guide(gd));
  43. }
  44. CTPath2DList pathLst = geom.getPathLst();
  45. if(pathLst != null) for(CTPath2D spPath : pathLst.getPathList()){
  46. paths.add(new Path(spPath));
  47. }
  48. if(geom.isSetRect()) {
  49. CTGeomRect rect = geom.getRect();
  50. textBounds = new Path();
  51. textBounds.addCommand(
  52. new MoveToCommand(rect.getL().toString(), rect.getT().toString()));
  53. textBounds.addCommand(
  54. new LineToCommand(rect.getR().toString(), rect.getT().toString()));
  55. textBounds.addCommand(
  56. new LineToCommand(rect.getR().toString(), rect.getB().toString()));
  57. textBounds.addCommand(
  58. new LineToCommand(rect.getL().toString(), rect.getB().toString()));
  59. textBounds.addCommand(
  60. new ClosePathCommand());
  61. }
  62. }
  63. public Iterator<Path> iterator() {
  64. return paths.iterator();
  65. }
  66. public Path getTextBounds(){
  67. return textBounds;
  68. }
  69. }