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.

PSSVGLinearGraphics2DTestCase.java 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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.ps.svg;
  19. import java.awt.Color;
  20. import java.awt.geom.AffineTransform;
  21. import java.awt.geom.Rectangle2D;
  22. import java.awt.geom.Rectangle2D.Float;
  23. import java.io.ByteArrayOutputStream;
  24. import java.io.File;
  25. import java.io.IOException;
  26. import org.junit.Test;
  27. import static org.junit.Assert.assertEquals;
  28. import org.apache.commons.io.FileUtils;
  29. import org.apache.batik.ext.awt.LinearGradientPaint;
  30. import org.apache.xmlgraphics.java2d.GraphicContext;
  31. import org.apache.xmlgraphics.ps.PSGenerator;
  32. public class PSSVGLinearGraphics2DTestCase {
  33. float startX = 115f;
  34. float endX = 15f;
  35. float startY = 285f;
  36. float endY = 15f;
  37. float[] fractions = {0.0f, 1.0f};
  38. /**
  39. * Tests a linear gradient generated pattern with certain inputs against
  40. * an expected output.
  41. * @throws IOException
  42. */
  43. @Test
  44. public void testApplyPaint() throws IOException {
  45. ByteArrayOutputStream os = new ByteArrayOutputStream();
  46. PSGenerator gen = new PSGenerator(os);
  47. PSSVGGraphics2D svgGraphics2D = new PSSVGGraphics2D(false, gen);
  48. svgGraphics2D.setGraphicContext(new GraphicContext());
  49. svgGraphics2D.setTransform(new AffineTransform());
  50. Color[] colors = {new Color(255, 255, 0), new Color(255, 0, 0)};
  51. LinearGradientPaint paint = new LinearGradientPaint(startX, startY, endX, endY, fractions, colors);
  52. Float s = new Rectangle2D.Float(115.0f, 15.0f, 170f, 110f);
  53. svgGraphics2D.applyPaint(paint, true);
  54. byte[] test = os.toByteArray();
  55. byte[] expected = FileUtils.readFileToByteArray(
  56. new File("test/java/org/apache/fop/render/ps/svg/axial-shading-expected.dat"));
  57. assertEquals(new String(test), new String(expected));
  58. }
  59. }