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.

AFPBorderPainterTestCase.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 java.awt.Color;
  20. import java.io.ByteArrayOutputStream;
  21. import java.io.OutputStream;
  22. import org.junit.Before;
  23. import org.junit.Test;
  24. import static org.junit.Assert.assertNull;
  25. import static org.junit.Assert.assertTrue;
  26. import org.apache.fop.afp.AFPBorderPainter;
  27. import org.apache.fop.afp.AFPLineDataInfo;
  28. import org.apache.fop.afp.AFPPaintingState;
  29. import org.apache.fop.afp.BorderPaintingInfo;
  30. import org.apache.fop.afp.DataStream;
  31. import org.apache.fop.afp.Factory;
  32. import org.apache.fop.fo.Constants;
  33. public class AFPBorderPainterTestCase {
  34. private ByteArrayOutputStream outStream;
  35. private AFPBorderPainter borderPainter;
  36. private DataStream ds;
  37. private AFPLineDataInfo line;
  38. @Before
  39. public void setUp() throws Exception {
  40. outStream = new ByteArrayOutputStream();
  41. ds = new MyDataStream(new Factory(), null, outStream);
  42. ds.startDocument();
  43. ds.startPage(1000, 1000, 90, 72, 72);
  44. borderPainter = new AFPBorderPainter(new AFPPaintingState(), ds);
  45. }
  46. /**
  47. * This test will fail if either of the below statements isn't true:
  48. * org.apache.fop.render.intermediate.BorderPainter.DASHED_BORDER_SPACE_RATIO = 0.5f:q
  49. * org.apache.fop.render.intermediate.BorderPainter.DASHED_BORDER_LENGTH_FACTOR = 4.0f.
  50. */
  51. @Test
  52. public void testDrawBorderLine() throws Exception {
  53. BorderPaintingInfo paintInfo = new BorderPaintingInfo(0f, 0f, 1000f, 1000f, true,
  54. Constants.EN_DASHED, Color.BLACK);
  55. borderPainter.paint(paintInfo);
  56. ds.endDocument();
  57. assertTrue(line.getX1() == 4999 && line.getX2() == 8332);
  58. }
  59. class MyDataStream extends DataStream {
  60. public MyDataStream(Factory factory, AFPPaintingState paintingState, OutputStream outputStream) {
  61. super(factory, paintingState, outputStream);
  62. }
  63. public void createLine(AFPLineDataInfo lineDataInfo) {
  64. line = lineDataInfo;
  65. }
  66. }
  67. @Test
  68. public void testDrawBorderLineDashed2() throws Exception {
  69. BorderPaintingInfo paintInfo = new BorderPaintingInfo(0, 0, 0, 0, false, Constants.EN_DASHED, Color.BLACK);
  70. borderPainter.paint(paintInfo);
  71. ds.endDocument();
  72. assertNull(line);
  73. }
  74. }