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.

AFPImageHandlerRawStream.java 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 java.io.InputStream;
  21. import org.apache.fop.afp.AFPDataObjectInfo;
  22. import org.apache.fop.afp.AFPObjectAreaInfo;
  23. import org.apache.fop.afp.AFPPaintingState;
  24. import org.apache.xmlgraphics.image.loader.ImageFlavor;
  25. import org.apache.xmlgraphics.image.loader.ImageInfo;
  26. import org.apache.xmlgraphics.image.loader.impl.ImageRawCCITTFax;
  27. import org.apache.xmlgraphics.image.loader.impl.ImageRawEPS;
  28. import org.apache.xmlgraphics.image.loader.impl.ImageRawJPEG;
  29. import org.apache.xmlgraphics.image.loader.impl.ImageRawStream;
  30. /**
  31. * AFPImageHandler implementation which handles raw stream images.
  32. */
  33. public class AFPImageHandlerRawStream extends AFPImageHandler {
  34. private static final ImageFlavor[] FLAVORS = new ImageFlavor[] {
  35. ImageFlavor.RAW_JPEG,
  36. ImageFlavor.RAW_CCITTFAX,
  37. ImageFlavor.RAW_EPS,
  38. };
  39. private static final Class[] CLASSES = new Class[] {
  40. ImageRawJPEG.class,
  41. ImageRawCCITTFax.class,
  42. ImageRawEPS.class
  43. };
  44. /** {@inheritDoc} */
  45. public AFPDataObjectInfo generateDataObjectInfo(
  46. AFPRendererImageInfo rendererImageInfo) throws IOException {
  47. AFPDataObjectInfo dataObjectInfo = super.generateDataObjectInfo(rendererImageInfo);
  48. ImageInfo imageInfo = rendererImageInfo.getImageInfo();
  49. String mimeType = imageInfo.getMimeType();
  50. if (mimeType != null) {
  51. dataObjectInfo.setMimeType(mimeType);
  52. }
  53. ImageRawStream rawStream = (ImageRawStream) rendererImageInfo.getImage();
  54. AFPObjectAreaInfo objectAreaInfo = dataObjectInfo.getObjectAreaInfo();
  55. AFPRendererContext rendererContext
  56. = (AFPRendererContext)rendererImageInfo.getRendererContext();
  57. AFPInfo afpInfo = rendererContext.getInfo();
  58. AFPPaintingState paintingState = afpInfo.getPaintingState();
  59. int resolution = paintingState.getResolution();
  60. objectAreaInfo.setWidthRes(resolution);
  61. objectAreaInfo.setHeightRes(resolution);
  62. InputStream inputStream = rawStream.createInputStream();
  63. dataObjectInfo.setInputStream(inputStream);
  64. int dataHeight = rawStream.getSize().getHeightPx();
  65. dataObjectInfo.setDataHeight(dataHeight);
  66. int dataWidth = rawStream.getSize().getWidthPx();
  67. dataObjectInfo.setDataWidth(dataWidth);
  68. return dataObjectInfo;
  69. }
  70. /** {@inheritDoc} */
  71. public int getPriority() {
  72. return 100;
  73. }
  74. /** {@inheritDoc} */
  75. public Class[] getSupportedImageClasses() {
  76. return CLASSES;
  77. }
  78. /** {@inheritDoc} */
  79. public ImageFlavor[] getSupportedImageFlavors() {
  80. return FLAVORS;
  81. }
  82. /** {@inheritDoc} */
  83. protected AFPDataObjectInfo createDataObjectInfo() {
  84. return new AFPDataObjectInfo();
  85. }
  86. }