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.

PSSVGGraphics2DTestCase.java 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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.RadialGradientPaint;
  30. import org.apache.xmlgraphics.java2d.GraphicContext;
  31. import org.apache.xmlgraphics.ps.PSGenerator;
  32. public class PSSVGGraphics2DTestCase {
  33. float cx = 841.891f;
  34. float cy = 178.583f;
  35. float r = 16.4331f;
  36. float[] fractions = {0.2f, 0.6012f, 0.8094f, 1.0f};
  37. /**
  38. * Tests a radial gradient generated pattern with certain inputs against
  39. * an expected output.
  40. * @throws IOException
  41. */
  42. @Test
  43. public void testApplyPaint() throws IOException {
  44. ByteArrayOutputStream os = new ByteArrayOutputStream();
  45. PSGenerator gen = new PSGenerator(os);
  46. PSSVGGraphics2D svgGraphics2D = new PSSVGGraphics2D(false, gen);
  47. svgGraphics2D.setGraphicContext(new GraphicContext());
  48. svgGraphics2D.setTransform(new AffineTransform());
  49. Color[] colors = {new Color(255, 255, 255), new Color(200, 200, 200),
  50. new Color(170, 170, 170), new Color(140, 140, 140)};
  51. RadialGradientPaint paint = new RadialGradientPaint(cx, cy, r, fractions, colors);
  52. Float s = new Rectangle2D.Float(7.0f, 3.0f, 841.891f, 178.583f);
  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/expected.ps"));
  57. assertEquals(new String(test), new String(expected));
  58. }
  59. }