[aXSL-commit] SF.net SVN: axsl:[2978] trunk/axsl
An API for XSL-FO.
Status: Alpha
Brought to you by:
victormote
|
From: <vic...@us...> - 2026-03-06 17:05:28
|
Revision: 2978
http://sourceforge.net/p/axsl/code/2978
Author: victormote
Date: 2026-03-06 17:05:25 +0000 (Fri, 06 Mar 2026)
Log Message:
-----------
Convert PdfExplicitDestination dimensions to BigDecimal.
Modified Paths:
--------------
trunk/axsl/axsl-constants/src/main/java/org/axsl/constants/TypographicConstants.java
trunk/axsl/axsl-pdf/src/main/java/org/axsl/pdf/interact/PdfExplicitDestination.java
Added Paths:
-----------
trunk/axsl/axsl-constants/src/test/java/org/axsl/constants/
trunk/axsl/axsl-constants/src/test/java/org/axsl/constants/TypographicConstantsTests.java
Modified: trunk/axsl/axsl-constants/src/main/java/org/axsl/constants/TypographicConstants.java
===================================================================
--- trunk/axsl/axsl-constants/src/main/java/org/axsl/constants/TypographicConstants.java 2026-03-06 14:18:28 UTC (rev 2977)
+++ trunk/axsl/axsl-constants/src/main/java/org/axsl/constants/TypographicConstants.java 2026-03-06 17:05:25 UTC (rev 2978)
@@ -32,10 +32,18 @@
/**
* Well-known constant used to convert millipoints to/from points, which is {@value}.
- * @see #MILLIPOINTS_PER_POINT_BD for the BigDecimal equivalent. */
+ * @see #MILLIPOINTS_PER_POINT_BD for the BigDecimal equivalent.
+ */
public static final int MILLIPOINTS_PER_POINT = 1_000;
/**
+ * The scale used to convert millipoints to points, i.e. the number of places the decimal point must be moved to
+ * the left to convert from millipoints to points or to the right to convert points to millipoints.
+ * Value is {@value}.
+ */
+ public static final int MILLIPOINTS_TO_POINTS_SCALE = 3;
+
+ /**
* Well-known constant used to convert millipoints to/from points, which is 1000.
* @see #MILLIPOINTS_PER_POINT for the primitive equivalent.
* @apiNote Both primitive and {@link BigDecimal} constants are maintained in this class to avoid unnecessary
@@ -43,9 +51,11 @@
*/
public static final BigDecimal MILLIPOINTS_PER_POINT_BD = BigDecimal.valueOf(MILLIPOINTS_PER_POINT);
- /** The number of points per inch, which is {@value}.
+ /**
+ * The number of points per inch, which is {@value}.
* A "point" is a somewhat nebulous term, but here we use the term as standardized by Adobe in their concept of text
- * space units. */
+ * space units.
+ */
public static final int POINTS_PER_INCH = 72;
/** The number of picas per inch, which is {@value}. */
@@ -106,4 +116,13 @@
return Math.round(raw);
}
+ /**
+ * Converts millipoints expressed as an integer to points expressed as a {@link BigDecimal}.
+ * @param millipoints The millipoints to be converted.
+ * @return The {@link BigDecimal} equivalent in points of {@code millipoints}.
+ */
+ public static BigDecimal millipointsToPoints(final int millipoints) {
+ return BigDecimal.valueOf(millipoints, MILLIPOINTS_TO_POINTS_SCALE);
+ }
+
}
Added: trunk/axsl/axsl-constants/src/test/java/org/axsl/constants/TypographicConstantsTests.java
===================================================================
--- trunk/axsl/axsl-constants/src/test/java/org/axsl/constants/TypographicConstantsTests.java (rev 0)
+++ trunk/axsl/axsl-constants/src/test/java/org/axsl/constants/TypographicConstantsTests.java 2026-03-06 17:05:25 UTC (rev 2978)
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2026 The aXSL Project.
+ * http://www.axsl.org
+ *
+ * Licensed 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.
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.axsl.constants;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import org.junit.jupiter.api.Test;
+
+import java.math.BigDecimal;
+
+/**
+ * Tests of {@link TypographicConstants}.
+ */
+public class TypographicConstantsTests {
+
+ /**
+ * Tests of {@link TypographicConstants#millipointsToPoints(int)}.
+ */
+ @Test
+ public void testMillipointsToPoints() {
+ BigDecimal expected = new BigDecimal("15.999");
+ BigDecimal actual = TypographicConstants.millipointsToPoints(15_999);
+ assertEquals(expected, actual);
+
+ expected = BigDecimal.ZERO;
+ actual = TypographicConstants.millipointsToPoints(0);
+ /* Want to do identity equality check here, but BigDecimal actually caches 15 different zero values. */
+ assertEquals(0, expected.compareTo(actual));
+
+ expected = BigDecimal.ONE;
+ actual = TypographicConstants.millipointsToPoints(1000);
+ assertEquals(0, expected.compareTo(actual));
+ }
+
+}
Property changes on: trunk/axsl/axsl-constants/src/test/java/org/axsl/constants/TypographicConstantsTests.java
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Rev
\ No newline at end of property
Modified: trunk/axsl/axsl-pdf/src/main/java/org/axsl/pdf/interact/PdfExplicitDestination.java
===================================================================
--- trunk/axsl/axsl-pdf/src/main/java/org/axsl/pdf/interact/PdfExplicitDestination.java 2026-03-06 14:18:28 UTC (rev 2977)
+++ trunk/axsl/axsl-pdf/src/main/java/org/axsl/pdf/interact/PdfExplicitDestination.java 2026-03-06 17:05:25 UTC (rev 2978)
@@ -23,6 +23,8 @@
package org.axsl.pdf.interact;
+import java.math.BigDecimal;
+
/**
* A PDF explicit destination.
*/
@@ -101,32 +103,32 @@
interface Coordinates {
/**
- * The left coordinate of the display window, either "null" or a number of points.
+ * The left coordinate of the display window, expressed in points.
* A null value implies that the coordinate should remain unchanged from its current state.
* @return The left coordinate of the display window.
*/
- String getLeft();
+ BigDecimal getLeft();
/**
- * The bottom coordinate of the display window, either "null" or a number of points.
+ * The bottom coordinate of the display window, expressed in points.
* A null value implies that the coordinate should remain unchanged from its current state.
* @return The bottom coordinate of the display window.
*/
- String getBottom();
+ BigDecimal getBottom();
/**
- * The right coordinate of the display window, either "null" or a number of points.
+ * The right coordinate of the display window, expressed in points.
* A null value implies that the coordinate should remain unchanged from its current state.
* @return The right coordinate of the display window.
*/
- String getRight();
+ BigDecimal getRight();
/**
- * The top coordinate of the display window, either "null" or a number of points.
+ * The top coordinate of the display window, expressed in points.
* A null value implies that the coordinate should remain unchanged from its current state.
* @return The top coordinate of the display window.
*/
- String getTop();
+ BigDecimal getTop();
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|