Author: vhennebert
Date: Mon Aug 10 11:16:45 2009
New Revision: 802752
URL: http://svn.apache.org/viewvc?rev=802752&view=rev
Log:
Fixed issues in PageBoundaries class:
- typos in method name and documentation
- unnecessary conversions from double to int
- a single space between values of bleed and crop-offset is too restrictive;
changed into a sequence of white space characters
Cleanup and improvements of prepress tests:
- split PrepressTest class into two separate PageScaleTest and
PageBoundariesTest test cases
- moved newly created test cases into prepress sub-package
- re-organized tests and made them more complete
Added:
xmlgraphics/fop/trunk/test/java/org/apache/fop/render/extensions/prepress/
xmlgraphics/fop/trunk/test/java/org/apache/fop/render/extensions/prepress/PageBoundariesTest.java
(with props)
xmlgraphics/fop/trunk/test/java/org/apache/fop/render/extensions/prepress/PageScaleTest.java
(with props)
Removed:
xmlgraphics/fop/trunk/test/java/org/apache/fop/render/extensions/PrepressTest.java
Modified:
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/extensions/prepress/PageBoundaries.java
xmlgraphics/fop/trunk/test/java/org/apache/fop/StandardTestSuite.java
Modified:
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/extensions/prepress/PageBoundaries.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/extensions/prepress/PageBoundaries.java?rev=802752&r1=802751&r2=802752&view=diff
==============================================================================
---
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/extensions/prepress/PageBoundaries.java
(original)
+++
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/extensions/prepress/PageBoundaries.java
Mon Aug 10 11:16:45 2009
@@ -60,6 +60,8 @@
private static final Pattern SIZE_UNIT_PATTERN
= Pattern.compile("^(-?\\d*\\.?\\d*)(px|in|cm|mm|pt|pc|mpt)$");
+ private static final Pattern WHITESPACE_PATTERN = Pattern.compile("\\s+");
+
private Rectangle trimBox;
private Rectangle bleedBox;
private Rectangle mediaBox;
@@ -146,8 +148,7 @@
/**
* Returns the crop box for the page. The crop box is used by Adobe
Acrobat to select which
* parts of the document shall be displayed and it also defines the
rectangle to which a
- * RIP will clip the document. For bitmap output, this defines the size of
the size of
- * the bitmap.
+ * RIP will clip the document. For bitmap output, this defines the size of
the bitmap.
* @return the crop box
*/
public Rectangle getCropBox() {
@@ -161,8 +162,8 @@
* @param bleed the given bleed widths
* @return the calculated BleedBox rectangle
*/
- public static Rectangle getBleedBoxRectangle(Rectangle trimBox, String
bleed) {
- return getRectagleUsingOffset(trimBox, bleed);
+ private static Rectangle getBleedBoxRectangle(Rectangle trimBox, String
bleed) {
+ return getRectangleUsingOffset(trimBox, bleed);
}
/**
@@ -172,42 +173,51 @@
* @param cropOffsets the given crop offsets
* @return the calculated MediaBox rectangle
*/
- public static Rectangle getCropMarksAreaRectangle(Rectangle trimBox,
String cropOffsets) {
- return getRectagleUsingOffset(trimBox, cropOffsets);
+ private static Rectangle getCropMarksAreaRectangle(Rectangle trimBox,
String cropOffsets) {
+ return getRectangleUsingOffset(trimBox, cropOffsets);
}
- private static Rectangle getRectagleUsingOffset(Rectangle originalRect,
String offset) {
+ private static Rectangle getRectangleUsingOffset(Rectangle originalRect,
String offset) {
if (offset == null || "".equals(offset) || originalRect == null) {
return originalRect;
}
- String[] bleeds = offset.split(" ");
+ String[] offsets = WHITESPACE_PATTERN.split(offset);
int[] coords = new int[4]; // top, right, bottom, left
- if (bleeds.length == 1) {
- coords[0] = getLengthIntValue(bleeds[0]);
+ switch (offsets.length) {
+ case 1:
+ coords[0] = getLengthIntValue(offsets[0]);
coords[1] = coords[0];
coords[2] = coords[0];
coords[3] = coords[0];
- } else if (bleeds.length == 2) {
- coords[0] = getLengthIntValue(bleeds[0]);
+ break;
+ case 2:
+ coords[0] = getLengthIntValue(offsets[0]);
+ coords[1] = getLengthIntValue(offsets[1]);
coords[2] = coords[0];
- coords[1] = getLengthIntValue(bleeds[1]);
coords[3] = coords[1];
- } else if (bleeds.length == 3) {
- coords[0] = getLengthIntValue(bleeds[0]);
- coords[1] = getLengthIntValue(bleeds[1]);
+ break;
+ case 3:
+ coords[0] = getLengthIntValue(offsets[0]);
+ coords[1] = getLengthIntValue(offsets[1]);
+ coords[2] = getLengthIntValue(offsets[2]);
coords[3] = coords[1];
- coords[2] = getLengthIntValue(bleeds[2]);
- } else if (bleeds.length == 4) {
- coords[0] = getLengthIntValue(bleeds[0]);
- coords[1] = getLengthIntValue(bleeds[1]);
- coords[2] = getLengthIntValue(bleeds[2]);
- coords[3] = getLengthIntValue(bleeds[3]);
+ break;
+ case 4:
+ coords[0] = getLengthIntValue(offsets[0]);
+ coords[1] = getLengthIntValue(offsets[1]);
+ coords[2] = getLengthIntValue(offsets[2]);
+ coords[3] = getLengthIntValue(offsets[3]);
+ break;
+ default:
+ // TODO throw appropriate exception that can be caught by the event
+ // notification mechanism
+ throw new IllegalArgumentException("Too many arguments");
}
- return new Rectangle((int) (originalRect.getX() - coords[3]),
- (int) (originalRect.getY() - coords[0]),
- (int) (originalRect.getWidth() + coords[3] + coords[1]),
- (int) (originalRect.getHeight() + coords[0] + coords[2]));
+ return new Rectangle(originalRect.x - coords[3],
+ originalRect.y - coords[0],
+ originalRect.width + coords[3] + coords[1],
+ originalRect.height + coords[0] + coords[2]);
}
private static int getLengthIntValue(final String length) {
Modified: xmlgraphics/fop/trunk/test/java/org/apache/fop/StandardTestSuite.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/test/java/org/apache/fop/StandardTestSuite.java?rev=802752&r1=802751&r2=802752&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/test/java/org/apache/fop/StandardTestSuite.java
(original)
+++ xmlgraphics/fop/trunk/test/java/org/apache/fop/StandardTestSuite.java Mon
Aug 10 11:16:45 2009
@@ -26,12 +26,13 @@
import org.apache.fop.image.loader.batik.ImageLoaderTestCase;
import org.apache.fop.image.loader.batik.ImagePreloaderTestCase;
import org.apache.fop.intermediate.IFMimickingTestCase;
+import org.apache.fop.render.extensions.prepress.PageBoundariesTest;
+import org.apache.fop.render.extensions.prepress.PageScaleTest;
import org.apache.fop.render.pdf.PDFAConformanceTestCase;
import org.apache.fop.render.pdf.PDFCMapTestCase;
import org.apache.fop.render.pdf.PDFEncodingTestCase;
import org.apache.fop.render.pdf.PDFsRGBSettingsTestCase;
import org.apache.fop.render.rtf.RichTextFormatTestSuite;
-import org.apache.fop.render.extensions.PrepressTest;
/**
* Test suite for basic functionality of FOP.
@@ -57,7 +58,8 @@
suite.addTest(new TestSuite(ImageLoaderTestCase.class));
suite.addTest(new TestSuite(ImagePreloaderTestCase.class));
suite.addTest(new TestSuite(IFMimickingTestCase.class));
- suite.addTest(new TestSuite(PrepressTest.class));
+ suite.addTest(new TestSuite(PageBoundariesTest.class));
+ suite.addTest(new TestSuite(PageScaleTest.class));
//$JUnit-END$
return suite;
}
Added:
xmlgraphics/fop/trunk/test/java/org/apache/fop/render/extensions/prepress/PageBoundariesTest.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/test/java/org/apache/fop/render/extensions/prepress/PageBoundariesTest.java?rev=802752&view=auto
==============================================================================
---
xmlgraphics/fop/trunk/test/java/org/apache/fop/render/extensions/prepress/PageBoundariesTest.java
(added)
+++
xmlgraphics/fop/trunk/test/java/org/apache/fop/render/extensions/prepress/PageBoundariesTest.java
Mon Aug 10 11:16:45 2009
@@ -0,0 +1,126 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.render.extensions.prepress;
+
+import java.awt.Dimension;
+import java.awt.Rectangle;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests for the fox:bleed, fox:crop-offset, fox:crop-box extension properties.
+ */
+public class PageBoundariesTest extends TestCase {
+
+ private static final Dimension TEST_AREA_SIZE = new Dimension(20000,
15000);
+
+ private static final Rectangle TEST_AREA = new Rectangle(TEST_AREA_SIZE);
+
+ private static final String BLEED = "5pt";
+
+ private static final String CROP_OFFSET = "8pt";
+
+ /**
+ * Default constructor.
+ */
+ public PageBoundariesTest() {
+ throw new UnsupportedOperationException("Not implemented"); // TODO
+ }
+
+ /**
+ * Creates a test case with the given name.
+ *
+ * @param name name for the test case
+ */
+ public PageBoundariesTest(String name) {
+ super(name);
+ }
+
+ /** Test for page boundaries. */
+ public void testBoundaries1() {
+ PageBoundaries boundaries = new PageBoundaries(TEST_AREA_SIZE, BLEED,
CROP_OFFSET, null);
+ assertEquals(TEST_AREA, boundaries.getTrimBox());
+
+ Rectangle bleedBox = boundaries.getBleedBox();
+ assertNotNull("Expected not null object", bleedBox);
+ assertEquals(-5000, bleedBox.x);
+ assertEquals(-5000, bleedBox.y);
+ assertEquals(30000, bleedBox.width);
+ assertEquals(25000, bleedBox.height);
+
+ Rectangle mediaBox = boundaries.getMediaBox();
+ assertNotNull("Expected not null object", mediaBox);
+ assertEquals(-8000, mediaBox.x);
+ assertEquals(-8000, mediaBox.y);
+ assertEquals(36000, mediaBox.width);
+ assertEquals(31000, mediaBox.height);
+ }
+
+ /** Test for page boundaries. */
+ public void testBoundaries2() {
+ PageBoundaries boundaries = new PageBoundaries(
+ TEST_AREA_SIZE, BLEED, null, null);
+ Rectangle bleedBox = boundaries.getBleedBox();
+ assertNotNull("Expected not null object", bleedBox);
+ assertEquals(-5000, bleedBox.x);
+ assertEquals(-5000, bleedBox.y);
+ assertEquals(30000, bleedBox.width);
+ assertEquals(25000, bleedBox.height);
+ assertEquals(bleedBox, boundaries.getMediaBox());
+ }
+
+ /** Test for the different values of crop-box. */
+ public void testCropBox() {
+ PageBoundaries boundaries = new PageBoundaries(TEST_AREA_SIZE, BLEED,
CROP_OFFSET, null);
+ assertEquals(boundaries.getMediaBox(), boundaries.getCropBox());
+
+ boundaries = new PageBoundaries(TEST_AREA_SIZE, BLEED, CROP_OFFSET,
"");
+ assertEquals(boundaries.getMediaBox(), boundaries.getCropBox());
+
+ boundaries = new PageBoundaries(TEST_AREA_SIZE, BLEED, CROP_OFFSET,
"trim-box");
+ assertEquals(TEST_AREA, boundaries.getCropBox());
+
+ boundaries = new PageBoundaries(TEST_AREA_SIZE, BLEED, CROP_OFFSET,
"bleed-box");
+ assertEquals(boundaries.getBleedBox(), boundaries.getCropBox());
+
+ boundaries = new PageBoundaries(TEST_AREA_SIZE, BLEED, CROP_OFFSET,
"media-box");
+ assertEquals(boundaries.getMediaBox(), boundaries.getCropBox());
+ }
+
+ /** Test for default values returned when properties are null. */
+ public void testBoundariesNull() {
+ PageBoundaries b = new PageBoundaries(TEST_AREA_SIZE, null, null,
null);
+
+ assertEquals("Result should be the same as TEST_AREA object",
b.getTrimBox(), TEST_AREA);
+ assertEquals("Result should be the same as TEST_AREA object",
b.getBleedBox(), TEST_AREA);
+ assertEquals("Result should be the same as TEST_AREA object",
b.getMediaBox(), TEST_AREA);
+ assertEquals("Result should be the same as TEST_AREA object",
b.getCropBox(), TEST_AREA);
+ }
+
+ /** Units must be specified. */
+ public void testBoundariesFail() {
+ try {
+ new PageBoundaries(TEST_AREA_SIZE, "0", null, null);
+ fail("Expected IllegalArgumentException. Box should have units");
+ } catch (IllegalArgumentException iae) {
+ // Good!
+ }
+ }
+}
Propchange:
xmlgraphics/fop/trunk/test/java/org/apache/fop/render/extensions/prepress/PageBoundariesTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
xmlgraphics/fop/trunk/test/java/org/apache/fop/render/extensions/prepress/PageBoundariesTest.java
------------------------------------------------------------------------------
svn:keywords = Revision Id
Added:
xmlgraphics/fop/trunk/test/java/org/apache/fop/render/extensions/prepress/PageScaleTest.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/test/java/org/apache/fop/render/extensions/prepress/PageScaleTest.java?rev=802752&view=auto
==============================================================================
---
xmlgraphics/fop/trunk/test/java/org/apache/fop/render/extensions/prepress/PageScaleTest.java
(added)
+++
xmlgraphics/fop/trunk/test/java/org/apache/fop/render/extensions/prepress/PageScaleTest.java
Mon Aug 10 11:16:45 2009
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.render.extensions.prepress;
+
+import java.awt.geom.Point2D;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests for the fox:scale extension property.
+ */
+public class PageScaleTest extends TestCase {
+
+ /**
+ * Default constructor.
+ */
+ public PageScaleTest() {
+ super();
+ }
+
+ /**
+ * Creates a test case with the given name.
+ *
+ * @param name name for the test case
+ */
+ public PageScaleTest(String name) {
+ super(name);
+ }
+
+ /** 1 value is used for both x and y. */
+ public void testScale1() {
+ Point2D res = PageScaleAttributes.getScaleAttributes(".5");
+ assertEquals(0.5, res.getX(), 0.0);
+ assertEquals(0.5, res.getY(), 0.0);
+ }
+
+ /** Two values, used resp. for x and y. */
+ public void testScale2() {
+ Point2D res = PageScaleAttributes.getScaleAttributes("1. 1.2");
+ assertEquals(1.0, res.getX(), 0.0);
+ assertEquals(1.2, res.getY(), 0.0);
+ }
+
+ /** Scale must not contain units. */
+ public void testScaleFail() {
+ try {
+ PageScaleAttributes.getScaleAttributes("0.5mm 0.5cm");
+ fail("Expected IllegalArgumentException. Scale shouldn't contain
units");
+ } catch (IllegalArgumentException iae) {
+ // Good!
+ }
+ }
+
+ /** @{code null} is returned when scale is unspecified. */
+ public void testScaleNull() {
+ Point2D res = PageScaleAttributes.getScaleAttributes(null);
+ assertNull("Result should be null", res);
+ }
+
+}
Propchange:
xmlgraphics/fop/trunk/test/java/org/apache/fop/render/extensions/prepress/PageScaleTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
xmlgraphics/fop/trunk/test/java/org/apache/fop/render/extensions/prepress/PageScaleTest.java
------------------------------------------------------------------------------
svn:keywords = Revision Id
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]