Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

AFPImageHandlerRawCCITTFax.java 3.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 org.apache.xmlgraphics.image.loader.Image;
  20. import org.apache.xmlgraphics.image.loader.ImageFlavor;
  21. import org.apache.xmlgraphics.image.loader.impl.ImageRawCCITTFax;
  22. import org.apache.xmlgraphics.image.loader.impl.ImageRawStream;
  23. import org.apache.xmlgraphics.util.MimeConstants;
  24. import org.apache.fop.afp.AFPDataObjectInfo;
  25. import org.apache.fop.afp.AFPImageObjectInfo;
  26. import org.apache.fop.render.RenderingContext;
  27. /**
  28. * AFPImageHandler implementation which handles CCITT encoded images (CCITT fax group 3/4).
  29. */
  30. public class AFPImageHandlerRawCCITTFax extends AbstractAFPImageHandlerRawStream {
  31. private static final ImageFlavor[] FLAVORS = new ImageFlavor[] {
  32. ImageFlavor.RAW_CCITTFAX,
  33. };
  34. /** {@inheritDoc} */
  35. protected void setAdditionalParameters(AFPDataObjectInfo dataObjectInfo,
  36. ImageRawStream image) {
  37. AFPImageObjectInfo imageObjectInfo = (AFPImageObjectInfo)dataObjectInfo;
  38. ImageRawCCITTFax ccitt = (ImageRawCCITTFax)image;
  39. int compression = ccitt.getCompression();
  40. imageObjectInfo.setCompression(compression);
  41. imageObjectInfo.setBitsPerPixel(1);
  42. //CCITTFax flavor doesn't have TIFF associated but the AFP library listens to
  43. //that to identify CCITT encoded images. CCITT is not exclusive to TIFF.
  44. imageObjectInfo.setMimeType(MimeConstants.MIME_TIFF);
  45. }
  46. /** {@inheritDoc} */
  47. protected AFPDataObjectInfo createDataObjectInfo() {
  48. return new AFPImageObjectInfo();
  49. }
  50. /** {@inheritDoc} */
  51. public int getPriority() {
  52. return 400;
  53. }
  54. /** {@inheritDoc} */
  55. public Class getSupportedImageClass() {
  56. return ImageRawCCITTFax.class;
  57. }
  58. /** {@inheritDoc} */
  59. public ImageFlavor[] getSupportedImageFlavors() {
  60. return FLAVORS;
  61. }
  62. /** {@inheritDoc} */
  63. public boolean isCompatible(RenderingContext targetContext, Image image) {
  64. if (targetContext instanceof AFPRenderingContext) {
  65. AFPRenderingContext afpContext = (AFPRenderingContext)targetContext;
  66. return (afpContext.getPaintingState().isNativeImagesSupported())
  67. && (image == null || image instanceof ImageRawCCITTFax);
  68. }
  69. return false;
  70. }
  71. }