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.

PCLImageHandlerRenderedImage.java 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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.pcl;
  19. import java.awt.Dimension;
  20. import java.awt.Rectangle;
  21. import java.awt.geom.Point2D;
  22. import java.awt.image.RenderedImage;
  23. import java.io.IOException;
  24. import org.apache.xmlgraphics.image.loader.Image;
  25. import org.apache.xmlgraphics.image.loader.ImageFlavor;
  26. import org.apache.xmlgraphics.image.loader.impl.ImageRendered;
  27. import org.apache.fop.render.ImageHandler;
  28. import org.apache.fop.render.RenderingContext;
  29. /**
  30. * Image handler implementation that paints {@link RenderedImage} instances in PCL.
  31. */
  32. public class PCLImageHandlerRenderedImage implements ImageHandler {
  33. /** {@inheritDoc} */
  34. public int getPriority() {
  35. return 300;
  36. }
  37. /** {@inheritDoc} */
  38. public Class getSupportedImageClass() {
  39. return ImageRendered.class;
  40. }
  41. /** {@inheritDoc} */
  42. public ImageFlavor[] getSupportedImageFlavors() {
  43. return new ImageFlavor[] {
  44. ImageFlavor.BUFFERED_IMAGE,
  45. ImageFlavor.RENDERED_IMAGE,
  46. };
  47. }
  48. /** {@inheritDoc} */
  49. public void handleImage(RenderingContext context, Image image, Rectangle pos)
  50. throws IOException {
  51. PCLRenderingContext pclContext = (PCLRenderingContext)context;
  52. ImageRendered imageRend = (ImageRendered)image;
  53. PCLGenerator gen = pclContext.getPCLGenerator();
  54. RenderedImage ri = imageRend.getRenderedImage();
  55. Point2D transPoint = pclContext.transformedPoint(pos.x, pos.y);
  56. gen.setCursorPos(transPoint.getX(), transPoint.getY());
  57. gen.paintBitmap(ri, new Dimension(pos.width, pos.height),
  58. pclContext.isSourceTransparencyEnabled(), pclContext.getPCLUtil());
  59. }
  60. /** {@inheritDoc} */
  61. public boolean isCompatible(RenderingContext targetContext, Image image) {
  62. return (image == null || image instanceof ImageRendered)
  63. && targetContext instanceof PCLRenderingContext;
  64. }
  65. }