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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /* $Id$
  2. * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
  3. * For details on use and redistribution please refer to the
  4. * LICENSE file included with these sources.
  5. */
  6. package org.apache.fop.plan;
  7. import java.awt.geom.Point2D;
  8. import org.apache.fop.fo.FONode;
  9. import org.apache.fop.apps.FOPException;
  10. import org.w3c.dom.Document;
  11. import org.xml.sax.Attributes;
  12. public class PlanElement extends PlanObj {
  13. Document svgDoc = null;
  14. float width;
  15. float height;
  16. boolean converted;
  17. public PlanElement(FONode parent) {
  18. super(parent);
  19. }
  20. public void handleAttrs(Attributes attlist) throws FOPException {
  21. super.handleAttrs(attlist);
  22. createBasicDocument();
  23. }
  24. public void convertToSVG() {
  25. try {
  26. if(!converted) {
  27. converted = true;
  28. PlanRenderer pr = new PlanRenderer();
  29. pr.setFontInfo("Helvetica", 12);
  30. svgDoc = pr.createSVGDocument(doc);
  31. width = pr.getWidth();
  32. height = pr.getHeight();
  33. doc = svgDoc;
  34. }
  35. } catch(Throwable t) {
  36. log.error("Could not convert Plan to SVG", t);
  37. width = 0;
  38. height = 0;
  39. }
  40. }
  41. public Document getDocument() {
  42. convertToSVG();
  43. return doc;
  44. }
  45. public String getDocumentNamespace() {
  46. if(svgDoc == null) {
  47. return PlanElementMapping.URI;
  48. }
  49. return "http://www.w3.org/2000/svg";
  50. }
  51. public Point2D getDimension(Point2D view) {
  52. convertToSVG();
  53. return new Point2D.Float(width, height);
  54. }
  55. }