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.9KB

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