[FOray-commit] SF.net SVN: foray:[12153] trunk/foray
Modular XSL-FO Implementation for Java.
Status: Alpha
Brought to you by:
victormote
|
From: <vic...@us...> - 2021-11-30 14:10:05
|
Revision: 12153
http://sourceforge.net/p/foray/code/12153
Author: victormote
Date: 2021-11-30 14:10:03 +0000 (Tue, 30 Nov 2021)
Log Message:
-----------
Add methods to handle the Monotype "unit" sizing properly.
Modified Paths:
--------------
trunk/foray/foray-font/src/main/java/org/foray/font/util/MockFont.java
trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/FirstFitLbTests.java
trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/LbTestUtilities.java
trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/LineBreaker4aTests.java
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/util/MockFont.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/util/MockFont.java 2021-11-30 12:00:19 UTC (rev 12152)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/util/MockFont.java 2021-11-30 14:10:03 UTC (rev 12153)
@@ -43,6 +43,22 @@
*/
public class MockFont extends Font4a {
+ /**
+ * The factor for conversion of Monotype units to millipoints for a font set at 1 point.
+ * According to para. 54, 18 Monotype units at 12 points is one pica (1/6 of an inch).
+ * In millipoints, this is 72,000 / 6 = 12,000.
+ * To get to 18 Monotype units at 1 point, divide by 12 = 12,000 / 12 = 1,000.
+ * To get to 1 Monotype unit at 1 point, divide by 18 = 1,000 / 18 = 55.555556 millipoints.
+ * We check this against para. 55, which computes the same value at .0007685 inches.
+ * 72000 * .0007685 = 55.332.
+ * The difference is due to the Monotype computation rounding the size of a pica to .166 inches, which is not
+ * exactly 1/6 of an inch.
+ * Since FOray consistently treats one point as being 1/72 of an inch, we will do so here as well.
+ * @see <a href="https://books.google.com/books/download/The_monotype_system.pdf?id=6kU5AAAAMAAJ&output=pdf">1912,
+ * The Monotype System, Philadelphia, Lanston Monotype Machine Co.</a>
+ */
+ public static final double MILLIPOINTS_PER_MONOTYPE_UNIT = 1000 / 18;
+
/** The character set. */
private CharSet charSet;
@@ -86,7 +102,7 @@
}
/**
- * Sets the widths to be used by this instance.
+ * Sets the width of a given codepoint.
* @param codePoint The codepoint for which the new width is to be set.
* @param width The new width, in millipoints, for {@code codePoint}.
*/
@@ -95,6 +111,18 @@
this.widths[metricIndex] = width;
}
+ /**
+ * Sets the width of a given codepoint, using the Monotype "unit" system.
+ * @param codePoint The codepoint for which the new width is to be set.
+ * @param monotypeUnits The number of Monotype "units" for {@code codePoint}.
+ * @see <a href="https://books.google.com/books/download/The_monotype_system.pdf?id=6kU5AAAAMAAJ&output=pdf">1912,
+ * The Monotype System, Philadelphia, Lanston Monotype Machine Co.</a>
+ */
+ public void setMonotypeWidth(final int codePoint, final int monotypeUnits) {
+ final int width = (int) (monotypeUnits * MILLIPOINTS_PER_MONOTYPE_UNIT);
+ setWidth(codePoint, width);
+ }
+
@Override
public boolean isEmbeddable() {
// TODO Auto-generated method stub
Modified: trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/FirstFitLbTests.java
===================================================================
--- trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/FirstFitLbTests.java 2021-11-30 12:00:19 UTC (rev 12152)
+++ trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/FirstFitLbTests.java 2021-11-30 14:10:03 UTC (rev 12153)
@@ -28,7 +28,9 @@
package org.foray.linebreak;
+import org.foray.common.WellKnownConstants;
import org.foray.common.para.ParaBranch4a;
+import org.foray.font.util.MockFont;
import org.axsl.common.para.ParaControl;
import org.axsl.linebreak.LineBreakControl;
@@ -46,7 +48,6 @@
* Test of an extremely short line that should return no line breaks.
*/
@Test
- @Ignore
public void firstFitTestSingleLine() {
final ParaBranch4aTestFixture para = new ParaBranch4aTestFixture(null, '-');
para.addWordAndSpace("Hello World!");
@@ -71,7 +72,11 @@
para.setParaConfig(createMonotypeParaConfig());
final ParaControl paraControl = createParaControl();
/* Line width obtained from "Digital Typography," p. 73.*/
- final LineBreakControl lbControl = createLineBreakControl(390_000);
+ final int lineWidth = (int)
+ (390
+ * (FONT_SIZE / WellKnownConstants.MILLIPOINTS_PER_POINT)
+ * MockFont.MILLIPOINTS_PER_MONOTYPE_UNIT);
+ final LineBreakControl lbControl = createLineBreakControl(lineWidth);
final FirstFitLb out = new FirstFitLb();
final int[] actual = out.breakIntoLines(para, paraControl, lbControl);
Modified: trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/LbTestUtilities.java
===================================================================
--- trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/LbTestUtilities.java 2021-11-30 12:00:19 UTC (rev 12152)
+++ trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/LbTestUtilities.java 2021-11-30 14:10:03 UTC (rev 12153)
@@ -62,66 +62,68 @@
final MockFont font = new MockFont();
font.setCharSet(charSet);
- font.setWidth(' ', 6_000); // Unclear from the table in the Monotype manual what the width of a space is.
- font.setWidth('\'', 5_000);
- font.setWidth(',', 5_000);
- font.setWidth('-', 5_000);
- font.setWidth('.', 5_000);
- font.setWidth(';', 6_000); // Knuth-Plass shows ";" as 5. Unclear which value they actually used.
+ /* It is unclear from the table in the Monotype manual what the width of a "normal" space is. Knuth uses 6 in
+ * most cases, but 8 after a period. */
+ font.setMonotypeWidth(' ', 6);
+ font.setMonotypeWidth('’', 5);
+ font.setMonotypeWidth(',', 5);
+ font.setMonotypeWidth('-', 5);
+ font.setMonotypeWidth('.', 5);
+ font.setMonotypeWidth(';', 6); // Knuth-Plass shows ";" as 5. Unclear which value they actually used.
- font.setWidth('A', 13_000);
- font.setWidth('B', 13_000);
- font.setWidth('C', 13_000);
- font.setWidth('D', 14_000);
- font.setWidth('E', 13_000);
- font.setWidth('F', 12_000);
- font.setWidth('G', 14_000);
- font.setWidth('H', 15_000);
- font.setWidth('I', 8_000); // Knuth-Plass shows "I" as 6. Unclear which value they actually used.
- font.setWidth('J', 9_000);
- font.setWidth('K', 15_000);
- font.setWidth('L', 12_000);
- font.setWidth('M', 18_000);
- font.setWidth('N', 15_000);
- font.setWidth('O', 13_000);
- font.setWidth('P', 12_000);
- font.setWidth('Q', 13_000);
- font.setWidth('R', 14_000);
- font.setWidth('S', 10_000);
- font.setWidth('T', 13_000);
- font.setWidth('U', 14_000);
- font.setWidth('V', 13_000);
- font.setWidth('W', 18_000);
- font.setWidth('X', 15_000);
- font.setWidth('Y', 14_000);
- font.setWidth('Z', 11_000);
+ font.setMonotypeWidth('A', 13);
+ font.setMonotypeWidth('B', 13);
+ font.setMonotypeWidth('C', 13);
+ font.setMonotypeWidth('D', 14);
+ font.setMonotypeWidth('E', 13);
+ font.setMonotypeWidth('F', 12);
+ font.setMonotypeWidth('G', 14);
+ font.setMonotypeWidth('H', 15);
+ font.setMonotypeWidth('I', 8); // Knuth-Plass shows "I" as 6. Unclear which value they actually used.
+ font.setMonotypeWidth('J', 9);
+ font.setMonotypeWidth('K', 15);
+ font.setMonotypeWidth('L', 12);
+ font.setMonotypeWidth('M', 18);
+ font.setMonotypeWidth('N', 15);
+ font.setMonotypeWidth('O', 13);
+ font.setMonotypeWidth('P', 12);
+ font.setMonotypeWidth('Q', 13);
+ font.setMonotypeWidth('R', 14);
+ font.setMonotypeWidth('S', 10);
+ font.setMonotypeWidth('T', 13);
+ font.setMonotypeWidth('U', 14);
+ font.setMonotypeWidth('V', 13);
+ font.setMonotypeWidth('W', 18);
+ font.setMonotypeWidth('X', 15);
+ font.setMonotypeWidth('Y', 14);
+ font.setMonotypeWidth('Z', 11);
- font.setWidth('a', 9_000);
- font.setWidth('b', 10_000);
- font.setWidth('c', 8_000);
- font.setWidth('d', 10_000);
- font.setWidth('e', 8_000);
- font.setWidth('f', 6_000);
- font.setWidth('g', 9_000);
- font.setWidth('h', 10_000);
- font.setWidth('i', 5_000);
- font.setWidth('j', 6_000);
- font.setWidth('k', 10_000);
- font.setWidth('l', 5_000);
- font.setWidth('m', 15_000);
- font.setWidth('n', 10_000);
- font.setWidth('o', 9_000);
- font.setWidth('p', 10_000);
- font.setWidth('q', 10_000);
- font.setWidth('r', 7_000);
- font.setWidth('s', 7_000);
- font.setWidth('t', 7_000);
- font.setWidth('u', 10_000);
- font.setWidth('v', 10_000); // Knuth-Plass shows "v" as 9. Unclear which value they actually used.
- font.setWidth('w', 13_000);
- font.setWidth('x', 9_000); // Knuth-Plass shows "x" as 10. However, it is not used in their example.
- font.setWidth('y', 10_000);
- font.setWidth('z', 8_000);
+ font.setMonotypeWidth('a', 9);
+ font.setMonotypeWidth('b', 10);
+ font.setMonotypeWidth('c', 8);
+ font.setMonotypeWidth('d', 10);
+ font.setMonotypeWidth('e', 8);
+ font.setMonotypeWidth('f', 6);
+ font.setMonotypeWidth('g', 9);
+ font.setMonotypeWidth('h', 10);
+ font.setMonotypeWidth('i', 5);
+ font.setMonotypeWidth('j', 6);
+ font.setMonotypeWidth('k', 10);
+ font.setMonotypeWidth('l', 5);
+ font.setMonotypeWidth('m', 15);
+ font.setMonotypeWidth('n', 10);
+ font.setMonotypeWidth('o', 9);
+ font.setMonotypeWidth('p', 10);
+ font.setMonotypeWidth('q', 10);
+ font.setMonotypeWidth('r', 7);
+ font.setMonotypeWidth('s', 7);
+ font.setMonotypeWidth('t', 7);
+ font.setMonotypeWidth('u', 10);
+ font.setMonotypeWidth('v', 10); // Knuth-Plass shows "v" as 9. Unclear which value they actually used.
+ font.setMonotypeWidth('w', 13);
+ font.setMonotypeWidth('x', 9); // Knuth-Plass shows "x" as 10. However, it is not used in their example.
+ font.setMonotypeWidth('y', 10);
+ font.setMonotypeWidth('z', 8);
return font;
}
Modified: trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/LineBreaker4aTests.java
===================================================================
--- trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/LineBreaker4aTests.java 2021-11-30 12:00:19 UTC (rev 12152)
+++ trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/LineBreaker4aTests.java 2021-11-30 14:10:03 UTC (rev 12153)
@@ -50,6 +50,9 @@
*/
public abstract class LineBreaker4aTests {
+ /** The font size, in millipoints, to be used for testing. */
+ public static final int FONT_SIZE = 11_000;
+
/** A string used for testing line-breaking. This example is used in Knuth, "Digital Typography," 1999, Chapter 3,
* "Breaking Paragraphs into Lines," p. 74 et seq. Knuth cites his source as "Grimm's Fairy Tales." By using an
* example directly from the book, we hope to get some independent expected results. */
@@ -247,7 +250,7 @@
final MockFont font = LbTestUtilities.createMonotypeFont();
final MockFontUse fontUse = new MockFontUse();
fontUse.setFont(font);
- final ParaConfig4a paraConfig = new ParaConfig4a(fontUse, 10_000, null, 0, 0);
+ final ParaConfig4a paraConfig = new ParaConfig4a(fontUse, FONT_SIZE, null, 0, 0);
return paraConfig;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|