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.

AFPImageHandlerGraphics2DTestCase.java 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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.awt.Dimension;
  20. import java.awt.Graphics2D;
  21. import java.awt.Rectangle;
  22. import java.awt.geom.Rectangle2D;
  23. import java.io.ByteArrayInputStream;
  24. import java.io.ByteArrayOutputStream;
  25. import java.io.File;
  26. import java.io.IOException;
  27. import org.junit.Assert;
  28. import org.junit.Test;
  29. import org.apache.xmlgraphics.image.loader.ImageInfo;
  30. import org.apache.xmlgraphics.image.loader.ImageSize;
  31. import org.apache.xmlgraphics.image.loader.impl.ImageGraphics2D;
  32. import org.apache.xmlgraphics.java2d.Graphics2DImagePainter;
  33. import org.apache.fop.afp.AFPPaintingState;
  34. import org.apache.fop.afp.AFPResourceLevel;
  35. import org.apache.fop.afp.AFPResourceLevelDefaults;
  36. import org.apache.fop.afp.AFPResourceManager;
  37. import org.apache.fop.afp.DataStream;
  38. import org.apache.fop.apps.FOUserAgent;
  39. import org.apache.fop.apps.FopFactory;
  40. public class AFPImageHandlerGraphics2DTestCase {
  41. @Test
  42. public void testWrapGocaPSeg() throws IOException {
  43. ImageInfo info = new ImageInfo(null, null);
  44. info.setSize(new ImageSize(100, 100, 72));
  45. ImageGraphics2D imageGraphics2D = new ImageGraphics2D(info, new Graphics2DImagePainter() {
  46. public void paint(Graphics2D g2d, Rectangle2D area) {
  47. }
  48. public Dimension getImageSize() {
  49. return null;
  50. }
  51. });
  52. AFPPaintingState paintingState = new AFPPaintingState();
  53. paintingState.setWrapGocaPSeg(true);
  54. FOUserAgent foUserAgent = FopFactory.newInstance(new File(".").toURI()).newFOUserAgent();
  55. AFPResourceManager resourceManager = new AFPResourceManager(foUserAgent.getResourceResolver());
  56. AFPResourceLevelDefaults resourceLevelDefaults = new AFPResourceLevelDefaults();
  57. resourceLevelDefaults.setDefaultResourceLevel("goca", AFPResourceLevel.valueOf("print-file"));
  58. resourceManager.setResourceLevelDefaults(resourceLevelDefaults);
  59. ByteArrayOutputStream bos = new ByteArrayOutputStream();
  60. DataStream dataStream = resourceManager.createDataStream(null, bos);
  61. dataStream.startPage(0, 0, 0, 0, 0);
  62. AFPRenderingContext afpRenderingContext =
  63. new AFPRenderingContext(null, resourceManager, paintingState, null, null);
  64. AFPImageHandlerGraphics2D imageHandlerGraphics2D = new AFPImageHandlerGraphics2D();
  65. imageHandlerGraphics2D.handleImage(afpRenderingContext, imageGraphics2D, new Rectangle());
  66. StringBuilder sb = new StringBuilder();
  67. new AFPParser(true).read(new ByteArrayInputStream(bos.toByteArray()), sb);
  68. Assert.assertEquals(sb.toString(), "BEGIN RESOURCE_GROUP RG000001\n"
  69. + "BEGIN NAME_RESOURCE RES00001 Triplets: OBJECT_FUNCTION_SET_SPECIFICATION,\n"
  70. + "BEGIN PAGE_SEGMENT S1000001\n"
  71. + "BEGIN GRAPHICS S1000001\n"
  72. + "BEGIN OBJECT_ENVIRONMENT_GROUP OEG00001\n"
  73. + "DESCRIPTOR OBJECT_AREA Triplets: DESCRIPTOR_POSITION,MEASUREMENT_UNITS,OBJECT_AREA_SIZE,\n"
  74. + "POSITION OBJECT_AREA\n"
  75. + "DESCRIPTOR GRAPHICS\n"
  76. + "END OBJECT_ENVIRONMENT_GROUP OEG00001\n"
  77. + "END GRAPHICS S1000001\n"
  78. + "END PAGE_SEGMENT S1000001\n"
  79. + "END NAME_RESOURCE RES00001\n");
  80. }
  81. }