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.

ArcToCommand.java 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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.CTPath2DArcTo;
  21. import java.awt.geom.Arc2D;
  22. import java.awt.geom.GeneralPath;
  23. import java.awt.geom.Point2D;
  24. /**
  25. * ArcTo command within a shape path in DrawingML:
  26. *
  27. * <arcTo wR="wr" hR="hr" stAng="stAng" swAng="swAng"/>
  28. *
  29. * Where <code>wr</code> and <code>wh</code> are the height and width radiuses
  30. * of the supposed circle being used to draw the arc. This gives the circle
  31. * a total height of (2 * hR) and a total width of (2 * wR)
  32. *
  33. * stAng is the <code>start</code> angle and <code></>swAng</code> is the swing angle
  34. *
  35. * @author Yegor Kozlov
  36. */
  37. public class ArcToCommand implements PathCommand {
  38. private String hr, wr, stAng, swAng;
  39. ArcToCommand(CTPath2DArcTo arc){
  40. hr = arc.getHR().toString();
  41. wr = arc.getWR().toString();
  42. stAng = arc.getStAng().toString();
  43. swAng = arc.getSwAng().toString();
  44. }
  45. public void execute(GeneralPath path, Context ctx){
  46. double rx = ctx.getValue(wr);
  47. double ry = ctx.getValue(hr);
  48. double start = ctx.getValue(stAng) / 60000;
  49. double extent = ctx.getValue(swAng) / 60000;
  50. Point2D pt = path.getCurrentPoint();
  51. double x0 = pt.getX() - rx - rx * Math.cos(Math.toRadians(start));
  52. double y0 = pt.getY() - ry - ry * Math.sin(Math.toRadians(start));
  53. Arc2D arc = new Arc2D.Double(
  54. x0,
  55. y0,
  56. 2 * rx, 2 * ry,
  57. -start, -extent,
  58. Arc2D.OPEN);
  59. path.append(arc, true);
  60. }
  61. }