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.

PlanElementMapping.java 2.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * Copyright 1999-2004,2006 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 org.apache.fop.fo.FONode;
  19. import org.apache.fop.fo.ElementMapping;
  20. import org.apache.fop.image.analyser.XMLReader;
  21. import org.apache.fop.image.FopImage;
  22. import org.w3c.dom.DOMImplementation;
  23. import org.w3c.dom.Document;
  24. /**
  25. * This class provides the element mapping for FOP.
  26. */
  27. public class PlanElementMapping extends ElementMapping {
  28. /** Plan Namespace */
  29. public static final String NAMESPACE = "http://xmlgraphics.apache.org/fop/plan";
  30. /** Main constructor. */
  31. public PlanElementMapping() {
  32. this.namespaceURI = NAMESPACE;
  33. }
  34. /** @see org.apache.fop.fo.ElementMapping#getDOMImplementation() */
  35. public DOMImplementation getDOMImplementation() {
  36. return getDefaultDOMImplementation();
  37. }
  38. /** @see org.apache.fop.fo.ElementMapping#initialize() */
  39. protected void initialize() {
  40. if (foObjs == null) {
  41. foObjs = new java.util.HashMap();
  42. foObjs.put("plan", new PE());
  43. foObjs.put(DEFAULT, new PlanMaker());
  44. XMLReader.setConverter(this.namespaceURI, new PlanConverter());
  45. }
  46. }
  47. static class PlanMaker extends ElementMapping.Maker {
  48. public FONode make(FONode parent) {
  49. return new PlanObj(parent);
  50. }
  51. }
  52. static class PE extends ElementMapping.Maker {
  53. public FONode make(FONode parent) {
  54. return new PlanElement(parent);
  55. }
  56. }
  57. static class PlanConverter implements XMLReader.Converter {
  58. public FopImage.ImageInfo convert(Document doc) {
  59. try {
  60. PlanRenderer pr = new PlanRenderer();
  61. pr.setFontInfo("Helvetica", 12);
  62. FopImage.ImageInfo info = new FopImage.ImageInfo();
  63. info.data = pr.createSVGDocument(doc);
  64. info.width = (int)pr.getWidth();
  65. info.height = (int)pr.getHeight();
  66. info.mimeType = "image/svg+xml";
  67. info.str = "http://www.w3.org/2000/svg";
  68. return info;
  69. } catch (Throwable t) {
  70. /**@todo Log this properly! */
  71. }
  72. return null;
  73. }
  74. }
  75. }