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.

Graphics2DImagePainterGOCA.java 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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.afp;
  19. import java.awt.Dimension;
  20. import java.awt.Graphics2D;
  21. import java.awt.geom.Rectangle2D;
  22. import org.apache.batik.bridge.BridgeContext;
  23. import org.apache.batik.gvt.GraphicsNode;
  24. import org.apache.fop.image.loader.batik.Graphics2DImagePainterImpl;
  25. import org.apache.xmlgraphics.java2d.Graphics2DPainterPreparator;
  26. /**
  27. * Graphics2DImagePainter implementation for GOCA
  28. */
  29. public class Graphics2DImagePainterGOCA extends Graphics2DImagePainterImpl {
  30. /**
  31. * Main Constructor
  32. *
  33. * @param root the graphics node root
  34. * @param ctx the bridge context
  35. * @param imageSize the image size
  36. */
  37. public Graphics2DImagePainterGOCA(GraphicsNode root, BridgeContext ctx, Dimension imageSize) {
  38. super(root, ctx, imageSize);
  39. }
  40. /** {@inheritDoc} */
  41. protected Graphics2DPainterPreparator getPreparator() {
  42. return new Graphics2DPainterPreparator() {
  43. /** {@inheritdoc} */
  44. public void prepare(Graphics2D g2d, Rectangle2D area) {
  45. double tx = area.getX();
  46. double ty = area.getHeight() - area.getY();
  47. if (tx != 0 || ty != 0) {
  48. g2d.translate(tx, ty);
  49. }
  50. float iw = (float) ctx.getDocumentSize().getWidth();
  51. float ih = (float) ctx.getDocumentSize().getHeight();
  52. float w = (float) area.getWidth();
  53. float h = (float) area.getHeight();
  54. float sx = w / iw;
  55. float sy = -(h / ih);
  56. if (sx != 1.0 || sy != 1.0) {
  57. g2d.scale(sx, sy);
  58. }
  59. }
  60. };
  61. }
  62. }