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.

AFPGraphics2DTestCase.java 3.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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.afp;
  19. import java.awt.BasicStroke;
  20. import java.awt.Rectangle;
  21. import java.awt.geom.Area;
  22. import java.awt.geom.Ellipse2D;
  23. import java.io.ByteArrayInputStream;
  24. import java.io.ByteArrayOutputStream;
  25. import java.io.IOException;
  26. import org.junit.Assert;
  27. import org.junit.Test;
  28. import static org.mockito.Mockito.mock;
  29. import static org.mockito.Mockito.verify;
  30. import static org.mockito.Mockito.when;
  31. import org.apache.xmlgraphics.java2d.GraphicContext;
  32. import org.apache.fop.afp.modca.GraphicsObject;
  33. import org.apache.fop.fonts.FontInfo;
  34. public class AFPGraphics2DTestCase {
  35. private final float lineWidth = 1.0f;
  36. private final float correction = 2.5f;
  37. private final BasicStroke stroke = mock(BasicStroke.class);
  38. private final GraphicsObject gObject = mock(GraphicsObject.class);
  39. private final AFPPaintingState paintingState = mock(AFPPaintingState.class);
  40. private final AFPResourceManager resourceManager = mock(AFPResourceManager.class);
  41. private final AFPResourceInfo resourceInfo = mock(AFPResourceInfo.class);
  42. private final FontInfo fontInfo = mock(FontInfo.class);
  43. private AFPGraphics2D graphics2D = new AFPGraphics2D(false, paintingState, resourceManager, resourceInfo,
  44. fontInfo);
  45. @Test
  46. public void testApplyStroke() {
  47. // note: this only tests the setLineWidth in the GraphicsObject
  48. float correctedLineWidth = lineWidth * correction;
  49. when(stroke.getLineWidth()).thenReturn(lineWidth);
  50. when(paintingState.getLineWidthCorrection()).thenReturn(correction);
  51. graphics2D.setGraphicsObject(gObject);
  52. graphics2D.applyStroke(stroke);
  53. verify(gObject).setLineWidth(correctedLineWidth);
  54. }
  55. @Test
  56. public void testDrawGraphicsFillet() throws IOException {
  57. GraphicContext gc = new GraphicContext();
  58. gc.setClip(new Rectangle(0, 0, 2, 2));
  59. graphics2D.setGraphicContext(gc);
  60. GraphicsObject go = new GraphicsObject(new Factory(), "test");
  61. graphics2D.setGraphicsObject(go);
  62. graphics2D.draw(new Area(new Ellipse2D.Double(0, 0, 100, 100)));
  63. ByteArrayOutputStream bos = new ByteArrayOutputStream();
  64. go.writeToStream(bos);
  65. ByteArrayInputStream is = new ByteArrayInputStream(bos.toByteArray());
  66. is.skip(17 + 9 + 14 + 6);
  67. int graphicsFilletMarker = 0x85;
  68. Assert.assertEquals(is.read(), graphicsFilletMarker);
  69. int sizeOfGraphicsFillet = 128;
  70. Assert.assertEquals(is.read(), sizeOfGraphicsFillet);
  71. }
  72. }