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.

AbstractBitmapRendererConfiguratorTest.java 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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.bitmap;
  19. import java.awt.image.BufferedImage;
  20. import org.junit.Test;
  21. import org.apache.fop.apps.AbstractRendererConfiguratorTest;
  22. import org.apache.fop.apps.BitmapRendererConfBuilder;
  23. import org.apache.fop.render.intermediate.IFDocumentHandler;
  24. import org.apache.fop.util.ColorUtil;
  25. import static org.apache.fop.render.bitmap.BitmapRendererOption.COLOR_MODE_BILEVEL;
  26. import static org.apache.fop.render.bitmap.BitmapRendererOption.COLOR_MODE_BINARY;
  27. import static org.apache.fop.render.bitmap.BitmapRendererOption.COLOR_MODE_GRAY;
  28. import static org.apache.fop.render.bitmap.BitmapRendererOption.COLOR_MODE_RGB;
  29. import static org.apache.fop.render.bitmap.BitmapRendererOption.COLOR_MODE_RGBA;
  30. import static org.apache.fop.render.bitmap.BitmapRendererOption.RENDERING_QUALITY;
  31. import static org.apache.fop.render.bitmap.BitmapRendererOption.RENDERING_SPEED;
  32. import static org.junit.Assert.assertEquals;
  33. import static org.junit.Assert.assertFalse;
  34. import static org.junit.Assert.assertTrue;
  35. import static org.mockito.Mockito.when;
  36. public abstract class AbstractBitmapRendererConfiguratorTest extends
  37. AbstractRendererConfiguratorTest<BitmapRendererConfigurator, BitmapRendererConfBuilder> {
  38. public AbstractBitmapRendererConfiguratorTest(String mimeType,
  39. Class<? extends IFDocumentHandler> docHandlerClass) {
  40. super(mimeType, BitmapRendererConfBuilder.class, docHandlerClass);
  41. }
  42. BitmapRenderingSettings settings;
  43. @Override
  44. public void setUpDocumentHandler() {
  45. settings = new BitmapRenderingSettings();
  46. when(((AbstractBitmapDocumentHandler) docHandler).getSettings()).thenReturn(settings);
  47. }
  48. @Test
  49. public void testSetPageBackgroundColor() throws Exception {
  50. // Try a few different colours
  51. parseConfig(createBuilder().setBackgroundColor("Blue"));
  52. assertEquals(ColorUtil.parseColorString(null, "Blue"), settings.getPageBackgroundColor());
  53. parseConfig(createBuilder().setBackgroundColor("Black"));
  54. assertEquals(ColorUtil.parseColorString(null, "Black"), settings.getPageBackgroundColor());
  55. }
  56. @Test
  57. public void testAntiAliasing() throws Exception {
  58. parseConfig(createBuilder().setAntiAliasing(true));
  59. assertTrue(settings.isAntiAliasingEnabled());
  60. parseConfig(createBuilder().setAntiAliasing(false));
  61. assertFalse(settings.isAntiAliasingEnabled());
  62. }
  63. @Test
  64. public void testTransparentBackground() throws Exception {
  65. parseConfig(createBuilder().setPageBackgroundTransparency(true));
  66. assertTrue(settings.hasTransparentPageBackground());
  67. parseConfig(createBuilder().setPageBackgroundTransparency(false));
  68. assertFalse(settings.hasTransparentPageBackground());
  69. }
  70. @Test
  71. public void testRendererQuality() throws Exception {
  72. parseConfig(createBuilder().setRenderingQuality(RENDERING_QUALITY.getName()));
  73. assertTrue(settings.isQualityRenderingEnabled());
  74. parseConfig(createBuilder().setRenderingQuality(RENDERING_SPEED.getName()));
  75. assertFalse(settings.isQualityRenderingEnabled());
  76. parseConfig(createBuilder());
  77. assertTrue(settings.isQualityRenderingEnabled());
  78. }
  79. @Test
  80. public void testColorModes() throws Exception {
  81. parseConfig(createBuilder().setColorMode(COLOR_MODE_RGBA.getName()));
  82. assertEquals(BufferedImage.TYPE_INT_ARGB, settings.getBufferedImageType());
  83. parseConfig(createBuilder().setColorMode(COLOR_MODE_RGB.getName()));
  84. assertEquals(BufferedImage.TYPE_INT_RGB, settings.getBufferedImageType());
  85. parseConfig(createBuilder().setColorMode(COLOR_MODE_GRAY.getName()));
  86. assertEquals(BufferedImage.TYPE_BYTE_GRAY, settings.getBufferedImageType());
  87. parseConfig(createBuilder().setColorMode(COLOR_MODE_BINARY.getName()));
  88. assertEquals(BufferedImage.TYPE_BYTE_BINARY, settings.getBufferedImageType());
  89. parseConfig(createBuilder().setColorMode(COLOR_MODE_BILEVEL.getName()));
  90. assertEquals(BufferedImage.TYPE_BYTE_BINARY, settings.getBufferedImageType());
  91. parseConfig(createBuilder());
  92. assertEquals(BufferedImage.TYPE_INT_ARGB, settings.getBufferedImageType());
  93. }
  94. }