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.

GraphicsObjectPainterAFP.java 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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.render.afp;
  19. import java.awt.Dimension;
  20. import java.awt.Graphics2D;
  21. import java.awt.geom.Rectangle2D;
  22. import org.apache.batik.gvt.GraphicsNode;
  23. import org.apache.commons.logging.Log;
  24. import org.apache.commons.logging.LogFactory;
  25. import org.apache.fop.afp.AFPGraphics2D;
  26. import org.apache.fop.afp.modca.GraphicsObject;
  27. import org.apache.xmlgraphics.java2d.Graphics2DImagePainter;
  28. /**
  29. * Paints SVG as a GOCA Graphics Object using Batik
  30. */
  31. public class GraphicsObjectPainterAFP implements Graphics2DImagePainter {
  32. /** Static logging instance */
  33. protected static Log log = LogFactory.getLog(GraphicsObjectPainterAFP.class);
  34. private final AFPGraphics2D graphics2D;
  35. /** the batik root node of the svg document */
  36. private GraphicsNode root;
  37. /**
  38. * Main constructor
  39. *
  40. * @param graphics an AFP graphics 2D implementation
  41. */
  42. public GraphicsObjectPainterAFP(AFPGraphics2D graphics) {
  43. final boolean textAsShapes = false;
  44. this.graphics2D = new AFPGraphics2D(textAsShapes);
  45. }
  46. /**
  47. * Sets the graphics node
  48. *
  49. * @param rootNode the graphics root node
  50. */
  51. public void setGraphicsNode(GraphicsNode rootNode) {
  52. this.root = rootNode;
  53. }
  54. /** {@inheritDoc} */
  55. public void paint(Graphics2D g2d, Rectangle2D area) {
  56. log.debug("Painting SVG using GOCA");
  57. // tell batik to paint the graphics object
  58. root.paint(g2d);
  59. // dispose of the graphics 2d implementation
  60. g2d.dispose();
  61. }
  62. /** {@inheritDoc} */
  63. public Dimension getImageSize() {
  64. return null;
  65. }
  66. /**
  67. * Sets the GOCA Graphics Object
  68. *
  69. * @param graphicsObject the GOCA Graphics Object
  70. */
  71. public void setGraphicsObject(GraphicsObject graphicsObject) {
  72. this.graphics2D.setGraphicsObject(graphicsObject);
  73. }
  74. }