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.

PCLPainterTestCase.java 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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.pcl;
  19. import java.awt.Color;
  20. import java.awt.Dimension;
  21. import java.awt.Rectangle;
  22. import java.io.ByteArrayOutputStream;
  23. import java.io.File;
  24. import javax.xml.transform.stream.StreamResult;
  25. import org.junit.Test;
  26. import org.apache.fop.apps.FOUserAgent;
  27. import org.apache.fop.apps.FopFactory;
  28. import org.apache.fop.render.intermediate.IFContext;
  29. import org.apache.fop.render.intermediate.IFException;
  30. import junit.framework.Assert;
  31. public class PCLPainterTestCase {
  32. private FOUserAgent ua = FopFactory.newInstance(new File(".").toURI()).newFOUserAgent();
  33. @Test
  34. public void testFillRect() throws IFException {
  35. Rectangle size = new Rectangle(1, 1);
  36. PCLPageDefinition pclPageDef = new PCLPageDefinition("", 0, new Dimension(), size, true);
  37. PCLDocumentHandler documentHandler = new PCLDocumentHandler(new IFContext(ua));
  38. ByteArrayOutputStream output = new ByteArrayOutputStream();
  39. documentHandler.setResult(new StreamResult(output));
  40. documentHandler.startDocument();
  41. PCLPainter pclPainter = new PCLPainter(documentHandler, pclPageDef);
  42. pclPainter.fillRect(size, Color.RED);
  43. Assert.assertTrue(output.toString().contains("*c4Q\u001B*c0.01h0.01V\u001B*c32G\u001B*c4P"));
  44. output.reset();
  45. pclPainter.getPCLUtil().setColorEnabled(true);
  46. pclPainter.fillRect(size, Color.RED);
  47. Assert.assertFalse(output.toString().contains("*c4P"));
  48. Assert.assertTrue(output.toString().contains("*v255a0b0c0I\u001B*v0S\u001B*c0.01h0.01V\u001B*c0P"));
  49. }
  50. }