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.7KB

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