Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

AFPImageHandlerGraphics2D.java 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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.io.IOException;
  20. import org.apache.xmlgraphics.image.loader.ImageFlavor;
  21. import org.apache.xmlgraphics.image.loader.impl.ImageGraphics2D;
  22. import org.apache.xmlgraphics.java2d.Graphics2DImagePainter;
  23. import org.apache.xmlgraphics.util.MimeConstants;
  24. import org.apache.fop.afp.AFPDataObjectInfo;
  25. import org.apache.fop.afp.AFPGraphics2D;
  26. import org.apache.fop.afp.AFPGraphicsObjectInfo;
  27. import org.apache.fop.afp.AFPPaintingState;
  28. import org.apache.fop.afp.AFPResourceInfo;
  29. import org.apache.fop.afp.modca.ResourceObject;
  30. /**
  31. * PDFImageHandler implementation which handles Graphics2D images.
  32. */
  33. public class AFPImageHandlerGraphics2D extends AFPImageHandler {
  34. private static final ImageFlavor[] FLAVORS = new ImageFlavor[] {
  35. ImageFlavor.GRAPHICS2D
  36. };
  37. /** {@inheritDoc} */
  38. public AFPDataObjectInfo generateDataObjectInfo(
  39. AFPRendererImageInfo rendererImageInfo) throws IOException {
  40. AFPRendererContext rendererContext
  41. = (AFPRendererContext)rendererImageInfo.getRendererContext();
  42. AFPInfo afpInfo = rendererContext.getInfo();
  43. ImageGraphics2D imageG2D = (ImageGraphics2D)rendererImageInfo.getImage();
  44. Graphics2DImagePainter painter = imageG2D.getGraphics2DImagePainter();
  45. if (afpInfo.paintAsBitmap()) {
  46. int x = afpInfo.getX();
  47. int y = afpInfo.getY();
  48. int width = afpInfo.getWidth();
  49. int height = afpInfo.getHeight();
  50. AFPPaintingState paintingState = afpInfo.getPaintingState();
  51. AFPGraphics2DAdapter g2dAdapter = new AFPGraphics2DAdapter(paintingState);
  52. g2dAdapter.paintImage(painter, rendererContext, x, y, width, height);
  53. return null;
  54. } else {
  55. AFPGraphicsObjectInfo graphicsObjectInfo
  56. = (AFPGraphicsObjectInfo)super.generateDataObjectInfo(rendererImageInfo);
  57. AFPResourceInfo resourceInfo = graphicsObjectInfo.getResourceInfo();
  58. if (!resourceInfo.levelChanged()) {
  59. resourceInfo.setLevel(afpInfo.getResourceManager().getResourceLevelDefaults()
  60. .getDefaultResourceLevel(ResourceObject.TYPE_GRAPHIC));
  61. }
  62. // set mime type (unsupported by MOD:CA registry)
  63. graphicsObjectInfo.setMimeType(MimeConstants.MIME_AFP_GOCA);
  64. // set g2d
  65. boolean textAsShapes = false;
  66. AFPGraphics2D g2d = afpInfo.createGraphics2D(textAsShapes);
  67. graphicsObjectInfo.setGraphics2D(g2d);
  68. // set painter
  69. graphicsObjectInfo.setPainter(painter);
  70. return graphicsObjectInfo;
  71. }
  72. }
  73. /** {@inheritDoc} */
  74. public int getPriority() {
  75. return 200;
  76. }
  77. /** {@inheritDoc} */
  78. public Class getSupportedImageClass() {
  79. return ImageGraphics2D.class;
  80. }
  81. /** {@inheritDoc} */
  82. public ImageFlavor[] getSupportedImageFlavors() {
  83. return FLAVORS;
  84. }
  85. /** {@inheritDoc} */
  86. protected AFPDataObjectInfo createDataObjectInfo() {
  87. return new AFPGraphicsObjectInfo();
  88. }
  89. }