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.

PSGraphics2DAdapterTestCase.java 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. package org.apache.fop.render.ps;
  18. import java.awt.Dimension;
  19. import java.awt.Graphics2D;
  20. import java.awt.geom.Rectangle2D;
  21. import java.io.ByteArrayOutputStream;
  22. import java.io.IOException;
  23. import org.junit.Assert;
  24. import org.junit.Test;
  25. import org.apache.xmlgraphics.java2d.GeneralGraphics2DImagePainter;
  26. import org.apache.xmlgraphics.java2d.ps.PSGraphics2D;
  27. import org.apache.xmlgraphics.ps.PSGenerator;
  28. import org.apache.fop.fonts.FontInfo;
  29. public class PSGraphics2DAdapterTestCase {
  30. @Test
  31. public void testFontFallback() throws IOException {
  32. PSGenerator gen = new PSGenerator(new ByteArrayOutputStream());
  33. FontInfo fi = new FontInfo();
  34. fi.addFontProperties("a", "b", "c", 400);
  35. PSGraphics2DAdapter psGraphics2DAdapter = new PSGraphics2DAdapter(gen, true, fi);
  36. MyPainter painter = new MyPainter();
  37. psGraphics2DAdapter.paintImage(painter, null, 0, 0, 0, 0);
  38. Assert.assertEquals(painter.font, "b");
  39. }
  40. static class MyPainter implements GeneralGraphics2DImagePainter {
  41. String font;
  42. public Graphics2D getGraphics(boolean textAsShapes, PSGenerator gen) {
  43. return new PSGraphics2D(true);
  44. }
  45. public void addFallbackFont(String name, Object font) {
  46. this.font = name;
  47. }
  48. public void paint(Graphics2D g2d, Rectangle2D area) {
  49. }
  50. public Dimension getImageSize() {
  51. return new Dimension();
  52. }
  53. }
  54. }