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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 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.Document;
  23. import java.util.HashMap;
  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://xml.apache.org/fop/plan";
  30. public PlanElementMapping() {
  31. this.namespaceURI = NAMESPACE;
  32. }
  33. protected void initialize() {
  34. if (foObjs == null) {
  35. foObjs = new java.util.HashMap();
  36. foObjs.put("plan", new PE());
  37. foObjs.put(DEFAULT, new PlanMaker());
  38. XMLReader.setConverter(this.namespaceURI, new PlanConverter());
  39. }
  40. }
  41. static class PlanMaker extends ElementMapping.Maker {
  42. public FONode make(FONode parent) {
  43. return new PlanObj(parent);
  44. }
  45. }
  46. static class PE extends ElementMapping.Maker {
  47. public FONode make(FONode parent) {
  48. return new PlanElement(parent);
  49. }
  50. }
  51. static class PlanConverter implements XMLReader.Converter {
  52. public FopImage.ImageInfo convert(Document doc) {
  53. try {
  54. PlanRenderer pr = new PlanRenderer();
  55. pr.setFontInfo("Helvetica", 12);
  56. FopImage.ImageInfo info = new FopImage.ImageInfo();
  57. info.data = pr.createSVGDocument(doc);
  58. info.width = (int)pr.getWidth();
  59. info.height = (int)pr.getHeight();
  60. info.mimeType = "image/svg+xml";
  61. info.str = "http://www.w3.org/2000/svg";
  62. return info;
  63. } catch (Throwable t) {
  64. /**@todo Log this properly! */
  65. }
  66. return null;
  67. }
  68. }
  69. }