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.

Java2DGraphics2DAdapter.java 2.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * Copyright 2005 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.render.java2d;
  18. import java.awt.Color;
  19. import java.awt.Dimension;
  20. import java.awt.geom.AffineTransform;
  21. import java.awt.geom.Rectangle2D;
  22. import java.io.IOException;
  23. import org.apache.fop.render.Graphics2DAdapter;
  24. import org.apache.fop.render.Graphics2DImagePainter;
  25. import org.apache.fop.render.RendererContext;
  26. /**
  27. * Graphics2DAdapter implementation for Java2D.
  28. */
  29. public class Java2DGraphics2DAdapter implements Graphics2DAdapter {
  30. private Java2DGraphicsState state;
  31. /**
  32. * Main constructor
  33. * @param renderer the Renderer instance to which this instance belongs
  34. */
  35. public Java2DGraphics2DAdapter(Java2DGraphicsState state) {
  36. this.state = state;
  37. }
  38. /** @see org.apache.fop.render.Graphics2DAdapter */
  39. public void paintImage(Graphics2DImagePainter painter,
  40. RendererContext context,
  41. int x, int y, int width, int height) throws IOException {
  42. float fwidth = width / 1000f;
  43. float fheight = height / 1000f;
  44. float fx = x / 1000f;
  45. float fy = y / 1000f;
  46. // get the 'width' and 'height' attributes of the SVG document
  47. Dimension dim = painter.getImageSize();
  48. float imw = (float)dim.getWidth() / 1000f;
  49. float imh = (float)dim.getHeight() / 1000f;
  50. float sx = fwidth / (float)imw;
  51. float sy = fheight / (float)imh;
  52. state.push();
  53. state.getGraph().setColor(Color.black);
  54. state.getGraph().setBackground(Color.black);
  55. //TODO Clip to the image area.
  56. // transform so that the coordinates (0,0) is from the top left
  57. // and positive is down and to the right. (0,0) is where the
  58. // viewBox puts it.
  59. state.getGraph().translate(fx, fy);
  60. AffineTransform at = AffineTransform.getScaleInstance(sx, sy);
  61. if (!at.isIdentity()) {
  62. state.getGraph().transform(at);
  63. }
  64. Rectangle2D area = new Rectangle2D.Double(0.0, 0.0, imw, imh);
  65. painter.paint(state.getGraph(), area);
  66. state.pop();
  67. }
  68. }