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.

PlanElement.java 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * Copyright 1999-2004 The Apache Software Foundation.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /* $Id$ */
  17. package org.apache.fop.plan;
  18. import java.awt.geom.Point2D;
  19. import org.apache.fop.fo.FONode;
  20. import org.apache.fop.apps.FOPException;
  21. import org.w3c.dom.Document;
  22. import org.xml.sax.Attributes;
  23. /**
  24. * This class defines the plan element.
  25. */
  26. public class PlanElement extends PlanObj {
  27. private Document svgDoc = null;
  28. private float width;
  29. private float height;
  30. private boolean converted;
  31. /**
  32. * @see org.apache.fop.fo.FONode#FONode(FONode)
  33. */
  34. public PlanElement(FONode parent) {
  35. super(parent);
  36. }
  37. /**
  38. * @see org.apache.fop.fo.FONode#handleAttrs(Attributes)
  39. */
  40. public void handleAttrs(Attributes attlist) throws FOPException {
  41. super.handleAttrs(attlist);
  42. createBasicDocument();
  43. }
  44. /**
  45. * Converts the element to SVG.
  46. */
  47. public void convertToSVG() {
  48. try {
  49. if (!converted) {
  50. converted = true;
  51. PlanRenderer pr = new PlanRenderer();
  52. pr.setFontInfo("Helvetica", 12);
  53. svgDoc = pr.createSVGDocument(doc);
  54. width = pr.getWidth();
  55. height = pr.getHeight();
  56. doc = svgDoc;
  57. }
  58. } catch (Throwable t) {
  59. getLogger().error("Could not convert Plan to SVG", t);
  60. width = 0;
  61. height = 0;
  62. }
  63. }
  64. /**
  65. * @see org.apache.fop.fo.XMLObj#getDocument()
  66. */
  67. public Document getDocument() {
  68. convertToSVG();
  69. return doc;
  70. }
  71. /**
  72. * @see org.apache.fop.fo.XMLObj#getDocumentNamespace()
  73. */
  74. public String getDocumentNamespace() {
  75. if (svgDoc == null) {
  76. return PlanElementMapping.NAMESPACE;
  77. }
  78. return "http://www.w3.org/2000/svg";
  79. }
  80. /**
  81. * @see org.apache.fop.fo.XMLObj#getDimension(Point2D)
  82. */
  83. public Point2D getDimension(Point2D view) {
  84. convertToSVG();
  85. return new Point2D.Float(width, height);
  86. }
  87. }