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.

AFPImageRawStreamFactory.java 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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.ImageInfo;
  25. import org.apache.xmlgraphics.image.loader.impl.ImageRawStream;
  26. /**
  27. * A raw stream image data object info factory
  28. */
  29. public class AFPImageRawStreamFactory extends AFPDataObjectInfoFactory {
  30. /**
  31. * Main constructor
  32. *
  33. * @param state the AFP painting state
  34. */
  35. public AFPImageRawStreamFactory(AFPPaintingState state) {
  36. super(state);
  37. }
  38. /** {@inheritDoc} */
  39. public AFPDataObjectInfo create(AFPRendererImageInfo rendererImageInfo) throws IOException {
  40. AFPDataObjectInfo dataObjectInfo = super.create(rendererImageInfo);
  41. ImageInfo imageInfo = rendererImageInfo.getImageInfo();
  42. String mimeType = imageInfo.getMimeType();
  43. if (mimeType != null) {
  44. dataObjectInfo.setMimeType(mimeType);
  45. }
  46. ImageRawStream rawStream = (ImageRawStream) rendererImageInfo.getImage();
  47. int resolution = state.getResolution();
  48. AFPObjectAreaInfo objectAreaInfo = dataObjectInfo.getObjectAreaInfo();
  49. objectAreaInfo.setWidthRes(resolution);
  50. objectAreaInfo.setHeightRes(resolution);
  51. InputStream inputStream = rawStream.createInputStream();
  52. dataObjectInfo.setInputStream(inputStream);
  53. int dataHeight = rawStream.getSize().getHeightPx();
  54. dataObjectInfo.setDataHeight(dataHeight);
  55. int dataWidth = rawStream.getSize().getWidthPx();
  56. dataObjectInfo.setDataWidth(dataWidth);
  57. return dataObjectInfo;
  58. }
  59. /** {@inheritDoc} */
  60. protected AFPDataObjectInfo createDataObjectInfo() {
  61. return new AFPDataObjectInfo();
  62. }
  63. }