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.

PageBoundariesTest.java 6.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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.extensions.prepress;
  19. import static org.junit.Assert.assertEquals;
  20. import static org.junit.Assert.assertNotNull;
  21. import static org.junit.Assert.fail;
  22. import java.awt.Dimension;
  23. import java.awt.Rectangle;
  24. import org.junit.Test;
  25. /**
  26. * Tests for the fox:bleed, fox:crop-offset, fox:crop-box extension properties.
  27. */
  28. public class PageBoundariesTest {
  29. private static final Dimension TEST_AREA_SIZE = new Dimension(20000, 15000);
  30. private static final Rectangle TEST_AREA = new Rectangle(TEST_AREA_SIZE);
  31. private static final String BLEED = "5pt";
  32. private static final String CROP_OFFSET = "8pt";
  33. /** Test for page boundaries. */
  34. @Test
  35. public void testBoundaries1() {
  36. PageBoundaries boundaries = new PageBoundaries(TEST_AREA_SIZE, BLEED, CROP_OFFSET, null);
  37. assertEquals(TEST_AREA, boundaries.getTrimBox());
  38. Rectangle bleedBox = boundaries.getBleedBox();
  39. assertNotNull("Expected not null object", bleedBox);
  40. assertEquals(-5000, bleedBox.x);
  41. assertEquals(-5000, bleedBox.y);
  42. assertEquals(30000, bleedBox.width);
  43. assertEquals(25000, bleedBox.height);
  44. Rectangle mediaBox = boundaries.getMediaBox();
  45. assertNotNull("Expected not null object", mediaBox);
  46. assertEquals(-8000, mediaBox.x);
  47. assertEquals(-8000, mediaBox.y);
  48. assertEquals(36000, mediaBox.width);
  49. assertEquals(31000, mediaBox.height);
  50. }
  51. /** Test for page boundaries. */
  52. @Test
  53. public void testBoundaries2() {
  54. PageBoundaries boundaries = new PageBoundaries(
  55. TEST_AREA_SIZE, BLEED, null, null);
  56. Rectangle bleedBox = boundaries.getBleedBox();
  57. assertNotNull("Expected not null object", bleedBox);
  58. assertEquals(-5000, bleedBox.x);
  59. assertEquals(-5000, bleedBox.y);
  60. assertEquals(30000, bleedBox.width);
  61. assertEquals(25000, bleedBox.height);
  62. assertEquals(bleedBox, boundaries.getMediaBox());
  63. }
  64. /** Two values for the properties. */
  65. @Test
  66. public void testBoundaries2Values() {
  67. PageBoundaries boundaries = new PageBoundaries(
  68. TEST_AREA_SIZE, "5pt 10pt", "6pt \t 12pt", null);
  69. Rectangle bleedBox = boundaries.getBleedBox();
  70. assertEquals(-10000, bleedBox.x);
  71. assertEquals(-5000, bleedBox.y);
  72. assertEquals(40000, bleedBox.width);
  73. assertEquals(25000, bleedBox.height);
  74. Rectangle mediaBox = boundaries.getMediaBox();
  75. assertEquals(-12000, mediaBox.x);
  76. assertEquals(-6000, mediaBox.y);
  77. assertEquals(44000, mediaBox.width);
  78. assertEquals(27000, mediaBox.height);
  79. }
  80. /** Three values for the properties. */
  81. @Test
  82. public void testBoundaries3Values() {
  83. PageBoundaries boundaries = new PageBoundaries(
  84. TEST_AREA_SIZE, "5pt 10pt 7pt", "6pt \t 12pt 14pt", null);
  85. Rectangle bleedBox = boundaries.getBleedBox();
  86. assertEquals(-10000, bleedBox.x);
  87. assertEquals(-5000, bleedBox.y);
  88. assertEquals(40000, bleedBox.width);
  89. assertEquals(27000, bleedBox.height);
  90. Rectangle mediaBox = boundaries.getMediaBox();
  91. assertEquals(-12000, mediaBox.x);
  92. assertEquals(-6000, mediaBox.y);
  93. assertEquals(44000, mediaBox.width);
  94. assertEquals(35000, mediaBox.height);
  95. }
  96. /** Four values for the properties. */
  97. @Test
  98. public void testBoundaries4Values() {
  99. PageBoundaries boundaries = new PageBoundaries(
  100. TEST_AREA_SIZE, "5pt 6pt 7pt 8pt", "9pt 10pt 11pt 12pt", null);
  101. Rectangle bleedBox = boundaries.getBleedBox();
  102. assertEquals(-8000, bleedBox.x);
  103. assertEquals(-5000, bleedBox.y);
  104. assertEquals(34000, bleedBox.width);
  105. assertEquals(27000, bleedBox.height);
  106. Rectangle mediaBox = boundaries.getMediaBox();
  107. assertEquals(-12000, mediaBox.x);
  108. assertEquals(-9000, mediaBox.y);
  109. assertEquals(42000, mediaBox.width);
  110. assertEquals(35000, mediaBox.height);
  111. }
  112. /** Test for the different values of crop-box. */
  113. @Test
  114. public void testCropBox() {
  115. PageBoundaries boundaries = new PageBoundaries(TEST_AREA_SIZE, BLEED, CROP_OFFSET, null);
  116. assertEquals(boundaries.getMediaBox(), boundaries.getCropBox());
  117. boundaries = new PageBoundaries(TEST_AREA_SIZE, BLEED, CROP_OFFSET, "");
  118. assertEquals(boundaries.getMediaBox(), boundaries.getCropBox());
  119. boundaries = new PageBoundaries(TEST_AREA_SIZE, BLEED, CROP_OFFSET, "trim-box");
  120. assertEquals(TEST_AREA, boundaries.getCropBox());
  121. boundaries = new PageBoundaries(TEST_AREA_SIZE, BLEED, CROP_OFFSET, "bleed-box");
  122. assertEquals(boundaries.getBleedBox(), boundaries.getCropBox());
  123. boundaries = new PageBoundaries(TEST_AREA_SIZE, BLEED, CROP_OFFSET, "media-box");
  124. assertEquals(boundaries.getMediaBox(), boundaries.getCropBox());
  125. }
  126. /** Test for default values returned when properties are null. */
  127. @Test
  128. public void testBoundariesNull() {
  129. PageBoundaries b = new PageBoundaries(TEST_AREA_SIZE, null, null, null);
  130. assertEquals("Result should be the same as TEST_AREA object", b.getTrimBox(), TEST_AREA);
  131. assertEquals("Result should be the same as TEST_AREA object", b.getBleedBox(), TEST_AREA);
  132. assertEquals("Result should be the same as TEST_AREA object", b.getMediaBox(), TEST_AREA);
  133. assertEquals("Result should be the same as TEST_AREA object", b.getCropBox(), TEST_AREA);
  134. }
  135. /** Units must be specified. */
  136. @Test
  137. public void testBoundariesFail() {
  138. try {
  139. new PageBoundaries(TEST_AREA_SIZE, "0", null, null);
  140. fail("Expected IllegalArgumentException. Box should have units");
  141. } catch (IllegalArgumentException iae) {
  142. // Good!
  143. }
  144. }
  145. }