[FOray-commit] SF.net SVN: foray:[12989] trunk/foray/foray-fotree/src
Modular XSL-FO Implementation for Java.
Status: Alpha
Brought to you by:
victormote
|
From: <vic...@us...> - 2022-12-31 18:06:38
|
Revision: 12989
http://sourceforge.net/p/foray/code/12989
Author: victormote
Date: 2022-12-31 18:06:36 +0000 (Sat, 31 Dec 2022)
Log Message:
-----------
Add length tests. Fix bug in picas computation revealed by test.
Modified Paths:
--------------
trunk/foray/foray-fotree/src/main/java/org/foray/fotree/value/DtLength_Picas.java
trunk/foray/foray-fotree/src/test/java/org/foray/fotree/value/DtLengthTests.java
Modified: trunk/foray/foray-fotree/src/main/java/org/foray/fotree/value/DtLength_Picas.java
===================================================================
--- trunk/foray/foray-fotree/src/main/java/org/foray/fotree/value/DtLength_Picas.java 2022-12-31 17:35:07 UTC (rev 12988)
+++ trunk/foray/foray-fotree/src/main/java/org/foray/fotree/value/DtLength_Picas.java 2022-12-31 18:06:36 UTC (rev 12989)
@@ -50,8 +50,8 @@
@Override
public int getValue(final int fontSize) {
- return Math.round(this.value * TypographicConstants.PICAS_PER_INCH
- * TypographicConstants.MILLIPOINTS_PER_POINT);
+ return Math.round(this.value / TypographicConstants.PICAS_PER_INCH
+ * TypographicConstants.POINTS_PER_INCH * TypographicConstants.MILLIPOINTS_PER_POINT);
}
@Override
Modified: trunk/foray/foray-fotree/src/test/java/org/foray/fotree/value/DtLengthTests.java
===================================================================
--- trunk/foray/foray-fotree/src/test/java/org/foray/fotree/value/DtLengthTests.java 2022-12-31 17:35:07 UTC (rev 12988)
+++ trunk/foray/foray-fotree/src/test/java/org/foray/fotree/value/DtLengthTests.java 2022-12-31 18:06:36 UTC (rev 12989)
@@ -36,18 +36,84 @@
*/
public class DtLengthTests {
- /** A bogus point size to use when we don't care what it is. */
- private static final byte POINT_SIZE_DONT_CARE = 12;
+ /** A point size to use for these tests. */
+ private static final int POINT_SIZE = 12_000;
/**
- * Unit test for a centimeter length.
+ * Unit test for a points length.
*/
@Test
- public void testCentimeters() {
- final DtLength length = DtLength.procureInstance("3.7cm");
- final int resolvedLength = length.getValue(DtLengthTests.POINT_SIZE_DONT_CARE);
+ public void pointsTest() {
+ final DtLength length = DtLength.procureInstance("18.5pt");
+ final int resolvedLength = length.getValue(DtLengthTests.POINT_SIZE);
/* Return value is in millipoints. */
- assertEquals(104882, resolvedLength);
+ assertEquals(18_500, resolvedLength);
}
+ /**
+ * Unit test for an ems length.
+ */
+ @Test
+ public void emsTest() {
+ final DtLength length = DtLength.procureInstance("1.2em");
+ final int resolvedLength = length.getValue(DtLengthTests.POINT_SIZE);
+ /* Return value is in millipoints. */
+ assertEquals(14_400, resolvedLength);
+ }
+
+ /**
+ * Unit test for an inches length.
+ */
+ @Test
+ public void inchesTest() {
+ final DtLength length = DtLength.procureInstance("2.5in");
+ final int resolvedLength = length.getValue(DtLengthTests.POINT_SIZE);
+ /* Return value is in millipoints. */
+ assertEquals(180_000, resolvedLength);
+ }
+
+ /**
+ * Unit test for a centimeters length.
+ */
+ @Test
+ public void centimetersTest() {
+ final DtLength length = DtLength.procureInstance("3.7cm");
+ final int resolvedLength = length.getValue(DtLengthTests.POINT_SIZE);
+ /* Return value is in millipoints. 3.7 / 2.54 * 72,000. */
+ assertEquals(104_882, resolvedLength);
+ }
+
+ /**
+ * Unit test for a millimeters length.
+ */
+ @Test
+ public void millimetersTest() {
+ final DtLength length = DtLength.procureInstance("89.3mm");
+ final int resolvedLength = length.getValue(DtLengthTests.POINT_SIZE);
+ /* Return value is in millipoints. 89.3 / 10 / 2.54 * 72,000. */
+ assertEquals(253_134, resolvedLength);
+ }
+
+ /**
+ * Unit test for a picas length.
+ */
+ @Test
+ public void picasTest() {
+ final DtLength length = DtLength.procureInstance("6.5pc");
+ final int resolvedLength = length.getValue(DtLengthTests.POINT_SIZE);
+ /* Return value is in millipoints. 6.5 / 6 * 72,000. */
+ assertEquals(78_000, resolvedLength);
+ }
+
+ /**
+ * Unit test for a pixels length.
+ */
+ @Test
+ public void pixelsTest() {
+ final DtLength length = DtLength.procureInstance("300px");
+ final int resolvedLength = length.getValue(DtLengthTests.POINT_SIZE);
+ /* Return value is in millipoints. The pixels-per-inch value is 72. 300 / 72 * 72,000. */
+ assertEquals(300_000, resolvedLength);
+ }
+
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|