foray-commit Mailing List for FOray (Page 70)
Modular XSL-FO Implementation for Java.
Status: Alpha
Brought to you by:
victormote
You can subscribe to this list here.
| 2006 |
Jan
|
Feb
|
Mar
(139) |
Apr
(98) |
May
(250) |
Jun
(394) |
Jul
(84) |
Aug
(13) |
Sep
(420) |
Oct
(186) |
Nov
(1) |
Dec
(3) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2007 |
Jan
(108) |
Feb
(202) |
Mar
(291) |
Apr
(247) |
May
(374) |
Jun
(227) |
Jul
(231) |
Aug
(60) |
Sep
(31) |
Oct
(45) |
Nov
(18) |
Dec
|
| 2008 |
Jan
(38) |
Feb
(71) |
Mar
(142) |
Apr
|
May
(59) |
Jun
(6) |
Jul
(10) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2009 |
Jan
(12) |
Feb
(4) |
Mar
(88) |
Apr
(121) |
May
(17) |
Jun
(30) |
Jul
|
Aug
(5) |
Sep
|
Oct
(1) |
Nov
|
Dec
|
| 2010 |
Jan
(11) |
Feb
(76) |
Mar
(11) |
Apr
|
May
(11) |
Jun
|
Jul
|
Aug
(44) |
Sep
(14) |
Oct
(7) |
Nov
|
Dec
|
| 2011 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(9) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(10) |
Nov
|
Dec
|
| 2012 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(3) |
Jul
(4) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2016 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(168) |
| 2017 |
Jan
(77) |
Feb
(11) |
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2018 |
Jan
|
Feb
|
Mar
(1) |
Apr
(6) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2019 |
Jan
|
Feb
(88) |
Mar
(118) |
Apr
(1) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2020 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(6) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(141) |
| 2021 |
Jan
(170) |
Feb
(20) |
Mar
|
Apr
|
May
|
Jun
|
Jul
(1) |
Aug
|
Sep
|
Oct
(62) |
Nov
(189) |
Dec
(162) |
| 2022 |
Jan
(201) |
Feb
(118) |
Mar
(8) |
Apr
|
May
(2) |
Jun
(47) |
Jul
(19) |
Aug
(14) |
Sep
(3) |
Oct
|
Nov
(28) |
Dec
(235) |
| 2023 |
Jan
(112) |
Feb
(23) |
Mar
(2) |
Apr
(2) |
May
|
Jun
(1) |
Jul
|
Aug
(70) |
Sep
(92) |
Oct
(20) |
Nov
(1) |
Dec
(1) |
| 2024 |
Jan
|
Feb
|
Mar
(1) |
Apr
(1) |
May
(14) |
Jun
(11) |
Jul
(1) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2025 |
Jan
(10) |
Feb
(29) |
Mar
|
Apr
(162) |
May
(245) |
Jun
(83) |
Jul
|
Aug
(1) |
Sep
|
Oct
|
Nov
(4) |
Dec
|
|
From: <vic...@us...> - 2021-11-30 12:00:22
|
Revision: 12152
http://sourceforge.net/p/foray/code/12152
Author: victormote
Date: 2021-11-30 12:00:19 +0000 (Tue, 30 Nov 2021)
Log Message:
-----------
Minor improvements to test infrastructure.
Modified Paths:
--------------
trunk/foray/foray-font/src/main/java/org/foray/font/FontUse4a.java
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/FontUse4a.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/FontUse4a.java 2021-11-30 00:31:57 UTC (rev 12151)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/FontUse4a.java 2021-11-30 12:00:19 UTC (rev 12152)
@@ -198,7 +198,8 @@
final Orthography orthography) {
final IntArrayBuilder metricIndexes = new IntArrayBuilder(chars.length());
for (int i = 0; i < chars.length(); i ++) {
- final int metricIndex = getFont().metricIndex(chars.charAt(i));
+ final char c = chars.charAt(i);
+ final int metricIndex = getFont().metricIndex(c);
if (metricIndex < 0) {
metricIndexes.append(0);
} else {
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 00:31:57 UTC (rev 12151)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/util/MockFont.java 2021-11-30 12:00:19 UTC (rev 12152)
@@ -29,7 +29,6 @@
package org.foray.font.util;
import org.foray.common.WellKnownConstants;
-import org.foray.common.sequence.IntArray;
import org.foray.font.Font4a;
import org.foray.font.format.Kerning;
@@ -44,8 +43,11 @@
*/
public class MockFont extends Font4a {
+ /** The character set. */
+ private CharSet charSet;
+
/** The array of glyph widths. */
- private IntArray widths;
+ private int[] widths;
/**
* Constructor.
@@ -80,15 +82,17 @@
@Override
public int width(final int metricIndex, final int fontSize) {
- return this.widths.intAt(metricIndex) * fontSize / WellKnownConstants.MILLIUNITS_PER_UNIT;
+ return this.widths[metricIndex] * fontSize / WellKnownConstants.MILLIUNITS_PER_UNIT;
}
/**
* Sets the widths to be used by this instance.
- * @param widths The array of widths to be used.
+ * @param codePoint The codepoint for which the new width is to be set.
+ * @param width The new width, in millipoints, for {@code codePoint}.
*/
- public void setWidths(final IntArray widths) {
- this.widths = widths;
+ public void setWidth(final int codePoint, final int width) {
+ final int metricIndex = metricIndex(codePoint);
+ this.widths[metricIndex] = width;
}
@Override
@@ -267,10 +271,18 @@
@Override
public CharSet getCharSet() {
- // TODO Auto-generated method stub
- return null;
+ return this.charSet;
}
+ /**
+ * Sets the character set.
+ * @param charSet The new character set.
+ */
+ public void setCharSet(final CharSet charSet) {
+ this.charSet = charSet;
+ this.widths = new int[charSet.size()];
+ }
+
@Override
public int extractBaseline(final WritingMode writingMode, final Baseline baselineType, final int fontSize) {
// TODO Auto-generated method stub
@@ -291,8 +303,11 @@
@Override
public int metricIndex(final int codePoint) {
- // TODO Auto-generated method stub
- return 0;
+ final int metricIndex = this.charSet.getIndex(codePoint);
+ if (metricIndex < 0) {
+ throw new IllegalArgumentException("Character contains no index for codepoint: " + codePoint);
+ }
+ return metricIndex;
}
}
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 00:31:57 UTC (rev 12151)
+++ trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/FirstFitLbTests.java 2021-11-30 12:00:19 UTC (rev 12152)
@@ -46,6 +46,7 @@
* 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!");
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 00:31:57 UTC (rev 12151)
+++ trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/LbTestUtilities.java 2021-11-30 12:00:19 UTC (rev 12152)
@@ -28,9 +28,11 @@
package org.foray.linebreak;
-import org.foray.common.sequence.IntArrayBuilder;
import org.foray.font.util.MockFont;
+import org.foray.ps.encode.CharSetExtendedRoman;
+import org.axsl.ps.CharSet;
+
/**
* Utilities for Linebreaking tests.
*/
@@ -56,71 +58,71 @@
* listed in the article.
* Except where noted, the "Digital Typography" values agree with those of "The Monotype System". */
- final IntArrayBuilder builder = new IntArrayBuilder(128);
- builder.setLength(128);
- builder.setIntAt(' ', 6_000); // Unclear from the table in the Monotype manual what the width of a space is.
- builder.setIntAt('\'', 5_000);
- builder.setIntAt(',', 5_000);
- builder.setIntAt('-', 5_000);
- builder.setIntAt('.', 5_000);
- builder.setIntAt(';', 6_000); // Knuth-Plass shows ";" as 5. Unclear which value they actually used.
+ final CharSet charSet = CharSetExtendedRoman.getInstance();
+ final MockFont font = new MockFont();
+ font.setCharSet(charSet);
- builder.setIntAt('A', 13_000);
- builder.setIntAt('B', 13_000);
- builder.setIntAt('C', 13_000);
- builder.setIntAt('D', 14_000);
- builder.setIntAt('E', 13_000);
- builder.setIntAt('F', 12_000);
- builder.setIntAt('G', 14_000);
- builder.setIntAt('H', 15_000);
- builder.setIntAt('I', 8_000); // Knuth-Plass shows "I" as 6. Unclear which value they actually used.
- builder.setIntAt('J', 9_000);
- builder.setIntAt('K', 15_000);
- builder.setIntAt('L', 12_000);
- builder.setIntAt('M', 18_000);
- builder.setIntAt('N', 15_000);
- builder.setIntAt('O', 13_000);
- builder.setIntAt('P', 12_000);
- builder.setIntAt('Q', 13_000);
- builder.setIntAt('R', 14_000);
- builder.setIntAt('S', 10_000);
- builder.setIntAt('T', 13_000);
- builder.setIntAt('U', 14_000);
- builder.setIntAt('V', 13_000);
- builder.setIntAt('W', 18_000);
- builder.setIntAt('X', 15_000);
- builder.setIntAt('Y', 14_000);
- builder.setIntAt('Z', 11_000);
+ 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.
- builder.setIntAt('a', 9_000);
- builder.setIntAt('b', 10_000);
- builder.setIntAt('c', 8_000);
- builder.setIntAt('d', 10_000);
- builder.setIntAt('e', 8_000);
- builder.setIntAt('f', 6_000);
- builder.setIntAt('g', 9_000);
- builder.setIntAt('h', 10_000);
- builder.setIntAt('i', 5_000);
- builder.setIntAt('j', 6_000);
- builder.setIntAt('k', 10_000);
- builder.setIntAt('l', 5_000);
- builder.setIntAt('m', 15_000);
- builder.setIntAt('n', 10_000);
- builder.setIntAt('o', 9_000);
- builder.setIntAt('p', 10_000);
- builder.setIntAt('q', 10_000);
- builder.setIntAt('r', 7_000);
- builder.setIntAt('s', 7_000);
- builder.setIntAt('t', 7_000);
- builder.setIntAt('u', 10_000);
- builder.setIntAt('v', 10_000); // Knuth-Plass shows "v" as 9. Unclear which value they actually used.
- builder.setIntAt('w', 13_000);
- builder.setIntAt('x', 9_000); // Knuth-Plass shows "x" as 10. However, it is not used in their example.
- builder.setIntAt('y', 10_000);
- builder.setIntAt('z', 8_000);
+ 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);
- final MockFont font = new MockFont();
- font.setWidths(builder.toIntArray());
+ 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);
+
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 00:31:57 UTC (rev 12151)
+++ trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/LineBreaker4aTests.java 2021-11-30 12:00:19 UTC (rev 12152)
@@ -247,7 +247,7 @@
final MockFont font = LbTestUtilities.createMonotypeFont();
final MockFontUse fontUse = new MockFontUse();
fontUse.setFont(font);
- final ParaConfig4a paraConfig = new ParaConfig4a(fontUse, 10, null, 0, 0);
+ final ParaConfig4a paraConfig = new ParaConfig4a(fontUse, 10_000, null, 0, 0);
return paraConfig;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-11-30 00:31:59
|
Revision: 12151
http://sourceforge.net/p/foray/code/12151
Author: victormote
Date: 2021-11-30 00:31:57 +0000 (Tue, 30 Nov 2021)
Log Message:
-----------
1. Conform to aXSL change: Add method to set the length of each mutable sequence class. 2. Fix index checks against length to use the conceptual array length instead of the actual array length.
Modified Paths:
--------------
trunk/foray/foray-common/src/main/java/org/foray/common/data/PackedIntArray.java
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ByteArrayBuilder.java
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/CharArrayBuilder.java
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/IntArrayBuilder.java
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/LongArrayBuilder.java
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ShortArrayBuilder.java
trunk/foray/foray-font/src/main/java/org/foray/font/FontUse4a.java
trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/OtfLookupGsubx04x01.java
trunk/foray/foray-font/src/test/java/org/foray/font/format/ttf/OtfLookupGsubTests.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-common/src/main/java/org/foray/common/data/PackedIntArray.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/data/PackedIntArray.java 2021-11-29 21:24:13 UTC (rev 12150)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/data/PackedIntArray.java 2021-11-30 00:31:57 UTC (rev 12151)
@@ -67,7 +67,7 @@
if (startingBit + this.qtyBits < Long.SIZE) {
/* Everything fits in the starting element. */
final long newLong = BitUtils.replaceBits(oldInternal1, startingBit, this.qtyBits, value);
- internalArray.replace(startingElement, newLong);
+ internalArray.setLongAt(startingElement, newLong);
} else {
/* The virtual element straddles two physical elements. */
final long oldInternal2 = this.internalArray.longAt(startingElement + 1);
@@ -84,8 +84,8 @@
final long newValue2 = BitUtils.extractBits(value, length1, Long.SIZE - length1);
final long newInternal2 = BitUtils.replaceBits(oldInternal2, 0, length2, newValue2);
- internalArray.replace(startingElement, newInternal1);
- internalArray.replace(startingElement + 1, newInternal2);
+ internalArray.setLongAt(startingElement, newInternal1);
+ internalArray.setLongAt(startingElement + 1, newInternal2);
}
}
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ByteArrayBuilder.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ByteArrayBuilder.java 2021-11-29 21:24:13 UTC (rev 12150)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ByteArrayBuilder.java 2021-11-30 00:31:57 UTC (rev 12151)
@@ -358,17 +358,10 @@
return null;
}
- /**
- * Resets the length of this sequence to a specified length.
- * The <em>capacity</em> of the sequence remains unchanged unless it needs to increase to accommodate a bigger size.
- * <p>If {@code newLength} is greater than the current length, the existing bytes in the sequence are unchanged, and
- * the bytes that have effectively been appended to the sequence are filled with zero.</p>
- * @param newLength The new length of this sequence. Must be greater than or equal to {@code 0}.
- * @throws IndexOutOfBoundsException If {@code newLength} is negative.
- */
+ @Override
public void setLength(final int newLength) {
if (newLength < 0) {
- throw new StringIndexOutOfBoundsException(newLength);
+ throw new IndexOutOfBoundsException("Index out of bounds: " + newLength);
}
ensureCapacityInternal(newLength);
@@ -404,6 +397,10 @@
@Override
public void setByteAt(final int index, final byte newByte) {
+ if ((index < 0)
+ || (index >= this.length)) {
+ throw new ArrayIndexOutOfBoundsException(index);
+ }
this.backingArray[index] = newByte;
}
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/sequence/CharArrayBuilder.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/sequence/CharArrayBuilder.java 2021-11-29 21:24:13 UTC (rev 12150)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/CharArrayBuilder.java 2021-11-30 00:31:57 UTC (rev 12151)
@@ -208,17 +208,10 @@
}
}
- /**
- * Resets the length of this sequence to a specified length.
- * The <em>capacity</em> of the sequence remains unchanged unless it needs to increase to accommodate a bigger size.
- * <p>If {@code newLength} is greater than the current length, the existing elements in the sequence are unchanged,
- * and the chars that have effectively been appended to the sequence are filled with zero.</p>
- * @param newLength The new length of this sequence. Must be greater than or equal to {@code 0}.
- * @throws IndexOutOfBoundsException If {@code newLength} is negative.
- */
+ @Override
public void setLength(final int newLength) {
if (newLength < 0) {
- throw new StringIndexOutOfBoundsException(newLength);
+ throw new IndexOutOfBoundsException("Index out of bounds: " + newLength);
}
ensureCapacityInternal(newLength);
@@ -272,8 +265,9 @@
@Override
public void setCharAt(final int index, final char ch) {
- if ((index < 0) || (index >= this.length)) {
- throw new StringIndexOutOfBoundsException(index);
+ if ((index < 0)
+ || (index >= this.length)) {
+ throw new ArrayIndexOutOfBoundsException(index);
}
this.backingArray[index] = ch;
}
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/sequence/IntArrayBuilder.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/sequence/IntArrayBuilder.java 2021-11-29 21:24:13 UTC (rev 12150)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/IntArrayBuilder.java 2021-11-30 00:31:57 UTC (rev 12151)
@@ -174,7 +174,25 @@
}
@Override
+ public void setLength(final int newLength) {
+ if (newLength < 0) {
+ throw new IndexOutOfBoundsException("Index out of bounds: " + newLength);
+ }
+ ensureCapacity(newLength);
+ if (newLength > this.length) {
+ for (int index = this.length; index < newLength; index ++) {
+ this.backingArray[index] = 0;
+ }
+ }
+ this.length = newLength;
+ }
+
+ @Override
public void setIntAt(final int index, final int newInt) {
+ if ((index < 0)
+ || (index >= this.length)) {
+ throw new ArrayIndexOutOfBoundsException(index);
+ }
this.backingArray[index] = newInt;
}
@@ -246,22 +264,6 @@
}
/**
- * Replaces the value at a given index with a new value.
- * @param index The index whose value should be replaced.
- * @param newValue The new value to place at {@code index}.
- * @return This object.
- * @throws IndexOutOfBoundsException If the {@code index} is negative or greater than or equal to {@link #length()}.
- */
- public IntArrayBuilder replace(final int index, final int newValue) throws IndexOutOfBoundsException {
- ensureCapacity(index + 1);
- if ((index < 0) || (index >= this.backingArray.length)) {
- throw new IndexOutOfBoundsException("Index out of range: " + index);
- }
- this.backingArray[index] = newValue;
- return this;
- }
-
- /**
* Removes the value at a given index.
* @param index The index whose value should be deleted.
* @return This object.
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/sequence/LongArrayBuilder.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/sequence/LongArrayBuilder.java 2021-11-29 21:24:13 UTC (rev 12150)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/LongArrayBuilder.java 2021-11-30 00:31:57 UTC (rev 12151)
@@ -216,22 +216,6 @@
}
/**
- * Replaces the value at a given index with a new value.
- * @param index The index whose value should be replaced.
- * @param newValue The new value to place at {@code index}.
- * @return This object.
- * @throws IndexOutOfBoundsException If the {@code index} is negative or greater than or equal to {@link #length()}.
- */
- public LongArrayBuilder replace(final int index, final long newValue) throws IndexOutOfBoundsException {
- ensureCapacity(index + 1);
- if ((index < 0) || (index >= this.backingArray.length)) {
- throw new IndexOutOfBoundsException("Index out of range: " + index);
- }
- this.backingArray[index] = newValue;
- return this;
- }
-
- /**
* Removes the value at a given index.
* @param index The index whose value should be deleted.
* @return This object.
@@ -325,7 +309,25 @@
}
@Override
+ public void setLength(final int newLength) {
+ if (newLength < 0) {
+ throw new IndexOutOfBoundsException("Index out of bounds: " + newLength);
+ }
+ ensureCapacity(newLength);
+ if (newLength > this.length) {
+ for (int index = this.length; index < newLength; index ++) {
+ this.backingArray[index] = 0;
+ }
+ }
+ this.length = newLength;
+ }
+
+ @Override
public void setLongAt(final int index, final long newLong) {
+ if ((index < 0)
+ || (index >= this.length)) {
+ throw new ArrayIndexOutOfBoundsException(index);
+ }
this.backingArray[index] = newLong;
}
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ShortArrayBuilder.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ShortArrayBuilder.java 2021-11-29 21:24:13 UTC (rev 12150)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ShortArrayBuilder.java 2021-11-30 00:31:57 UTC (rev 12151)
@@ -197,21 +197,6 @@
}
/**
- * Replaces the value at a given index with a new value.
- * @param index The index whose value should be replaced.
- * @param newValue The new value to place at {@code index}.
- * @return This object.
- * @throws IndexOutOfBoundsException If the {@code index} is negative or greater than or equal to {@link #length()}.
- */
- public ShortArrayBuilder replace(final int index, final short newValue) throws IndexOutOfBoundsException {
- if ((index < 0) || (index >= this.backingArray.length)) {
- throw new IndexOutOfBoundsException("Index out of range: " + index);
- }
- this.backingArray[index] = newValue;
- return this;
- }
-
- /**
* Removes the value at a given index.
* @param index The index whose value should be deleted.
* @return This object.
@@ -290,7 +275,25 @@
}
@Override
+ public void setLength(final int newLength) {
+ if (newLength < 0) {
+ throw new IndexOutOfBoundsException("Index out of bounds: " + newLength);
+ }
+ ensureCapacity(newLength);
+ if (newLength > this.length) {
+ for (int index = this.length; index < newLength; index ++) {
+ this.backingArray[index] = 0;
+ }
+ }
+ this.length = newLength;
+ }
+
+ @Override
public void setShortAt(final int index, final short newShort) {
+ if ((index < 0)
+ || (index >= this.length)) {
+ throw new ArrayIndexOutOfBoundsException(index);
+ }
this.backingArray[index] = newShort;
}
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/FontUse4a.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/FontUse4a.java 2021-11-29 21:24:13 UTC (rev 12150)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/FontUse4a.java 2021-11-30 00:31:57 UTC (rev 12151)
@@ -156,7 +156,7 @@
index --;
} else {
final int glyphIndex = encode(codePoint);
- glyphIndexes.replace(index, glyphIndex);
+ glyphIndexes.setIntAt(index, glyphIndex);
}
}
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/OtfLookupGsubx04x01.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/OtfLookupGsubx04x01.java 2021-11-29 21:24:13 UTC (rev 12150)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/OtfLookupGsubx04x01.java 2021-11-30 00:31:57 UTC (rev 12151)
@@ -87,7 +87,7 @@
}
if (isMatch) {
/* Make the replacement. */
- glyphIndexes.replace(index, this.ligGlyph);
+ glyphIndexes.setIntAt(index, this.ligGlyph);
/* Delete the other glyph indexes. */
glyphIndexes.delete(index + 1, index + 1 + this.components.length);
/* Adjust the index. */
Modified: trunk/foray/foray-font/src/test/java/org/foray/font/format/ttf/OtfLookupGsubTests.java
===================================================================
--- trunk/foray/foray-font/src/test/java/org/foray/font/format/ttf/OtfLookupGsubTests.java 2021-11-29 21:24:13 UTC (rev 12150)
+++ trunk/foray/foray-font/src/test/java/org/foray/font/format/ttf/OtfLookupGsubTests.java 2021-11-30 00:31:57 UTC (rev 12151)
@@ -246,7 +246,7 @@
for (int index = 0; index < codePoints.length(); index ++) {
final int codePoint = codePoints.intAt(index);
final int glyphIndex = encoding.encode(codePoint);
- glyphIndexes.replace(index, glyphIndex);
+ glyphIndexes.setIntAt(index, glyphIndex);
}
return codePoints;
}
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-29 21:24:13 UTC (rev 12150)
+++ trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/LbTestUtilities.java 2021-11-30 00:31:57 UTC (rev 12151)
@@ -31,8 +31,6 @@
import org.foray.common.sequence.IntArrayBuilder;
import org.foray.font.util.MockFont;
-import org.axsl.font.Font;
-
/**
* Utilities for Linebreaking tests.
*/
@@ -51,7 +49,7 @@
* The Monotype System, Philadelphia, Lanston Monotype Machine Co.</a>
* @see "1999, Digital Typography, Chapter 3, page 75, table 1, for the values documented by Knuth-Plass."
*/
- public static Font createMonotypeFont() {
+ public static MockFont createMonotypeFont() {
/* The Knuth-Plass values listed were obtained from Chapter 3 of Digital Typography. They do not appear in the
* original 1981 article.
* By using the the referenced table in "The Monotype System", we have added the missing capitals that were not
@@ -59,66 +57,67 @@
* Except where noted, the "Digital Typography" values agree with those of "The Monotype System". */
final IntArrayBuilder builder = new IntArrayBuilder(128);
- builder.replace(' ', 6_000); // Unclear from the table in the Monotype manual what the width of a space is.
- builder.replace('\'', 5_000);
- builder.replace(',', 5_000);
- builder.replace('-', 5_000);
- builder.replace('.', 5_000);
- builder.replace(';', 6_000); // Knuth-Plass shows ";" as 5. Unclear which value they actually used.
+ builder.setLength(128);
+ builder.setIntAt(' ', 6_000); // Unclear from the table in the Monotype manual what the width of a space is.
+ builder.setIntAt('\'', 5_000);
+ builder.setIntAt(',', 5_000);
+ builder.setIntAt('-', 5_000);
+ builder.setIntAt('.', 5_000);
+ builder.setIntAt(';', 6_000); // Knuth-Plass shows ";" as 5. Unclear which value they actually used.
- builder.replace('A', 13_000);
- builder.replace('B', 13_000);
- builder.replace('C', 13_000);
- builder.replace('D', 14_000);
- builder.replace('E', 13_000);
- builder.replace('F', 12_000);
- builder.replace('G', 14_000);
- builder.replace('H', 15_000);
- builder.replace('I', 8_000); // Knuth-Plass shows "I" as 6. Unclear which value they actually used.
- builder.replace('J', 9_000);
- builder.replace('K', 15_000);
- builder.replace('L', 12_000);
- builder.replace('M', 18_000);
- builder.replace('N', 15_000);
- builder.replace('O', 13_000);
- builder.replace('P', 12_000);
- builder.replace('Q', 13_000);
- builder.replace('R', 14_000);
- builder.replace('S', 10_000);
- builder.replace('T', 13_000);
- builder.replace('U', 14_000);
- builder.replace('V', 13_000);
- builder.replace('W', 18_000);
- builder.replace('X', 15_000);
- builder.replace('Y', 14_000);
- builder.replace('Z', 11_000);
+ builder.setIntAt('A', 13_000);
+ builder.setIntAt('B', 13_000);
+ builder.setIntAt('C', 13_000);
+ builder.setIntAt('D', 14_000);
+ builder.setIntAt('E', 13_000);
+ builder.setIntAt('F', 12_000);
+ builder.setIntAt('G', 14_000);
+ builder.setIntAt('H', 15_000);
+ builder.setIntAt('I', 8_000); // Knuth-Plass shows "I" as 6. Unclear which value they actually used.
+ builder.setIntAt('J', 9_000);
+ builder.setIntAt('K', 15_000);
+ builder.setIntAt('L', 12_000);
+ builder.setIntAt('M', 18_000);
+ builder.setIntAt('N', 15_000);
+ builder.setIntAt('O', 13_000);
+ builder.setIntAt('P', 12_000);
+ builder.setIntAt('Q', 13_000);
+ builder.setIntAt('R', 14_000);
+ builder.setIntAt('S', 10_000);
+ builder.setIntAt('T', 13_000);
+ builder.setIntAt('U', 14_000);
+ builder.setIntAt('V', 13_000);
+ builder.setIntAt('W', 18_000);
+ builder.setIntAt('X', 15_000);
+ builder.setIntAt('Y', 14_000);
+ builder.setIntAt('Z', 11_000);
- builder.replace('a', 9_000);
- builder.replace('b', 10_000);
- builder.replace('c', 8_000);
- builder.replace('d', 10_000);
- builder.replace('e', 8_000);
- builder.replace('f', 6_000);
- builder.replace('g', 9_000);
- builder.replace('h', 10_000);
- builder.replace('i', 5_000);
- builder.replace('j', 6_000);
- builder.replace('k', 10_000);
- builder.replace('l', 5_000);
- builder.replace('m', 15_000);
- builder.replace('n', 10_000);
- builder.replace('o', 9_000);
- builder.replace('p', 10_000);
- builder.replace('q', 10_000);
- builder.replace('r', 7_000);
- builder.replace('s', 7_000);
- builder.replace('t', 7_000);
- builder.replace('u', 10_000);
- builder.replace('v', 10_000); // Knuth-Plass shows "v" as 9. Unclear which value they actually used.
- builder.replace('w', 13_000);
- builder.replace('x', 9_000); // Knuth-Plass shows "x" as 10. However, it is not used in their example.
- builder.replace('y', 10_000);
- builder.replace('z', 8_000);
+ builder.setIntAt('a', 9_000);
+ builder.setIntAt('b', 10_000);
+ builder.setIntAt('c', 8_000);
+ builder.setIntAt('d', 10_000);
+ builder.setIntAt('e', 8_000);
+ builder.setIntAt('f', 6_000);
+ builder.setIntAt('g', 9_000);
+ builder.setIntAt('h', 10_000);
+ builder.setIntAt('i', 5_000);
+ builder.setIntAt('j', 6_000);
+ builder.setIntAt('k', 10_000);
+ builder.setIntAt('l', 5_000);
+ builder.setIntAt('m', 15_000);
+ builder.setIntAt('n', 10_000);
+ builder.setIntAt('o', 9_000);
+ builder.setIntAt('p', 10_000);
+ builder.setIntAt('q', 10_000);
+ builder.setIntAt('r', 7_000);
+ builder.setIntAt('s', 7_000);
+ builder.setIntAt('t', 7_000);
+ builder.setIntAt('u', 10_000);
+ builder.setIntAt('v', 10_000); // Knuth-Plass shows "v" as 9. Unclear which value they actually used.
+ builder.setIntAt('w', 13_000);
+ builder.setIntAt('x', 9_000); // Knuth-Plass shows "x" as 10. However, it is not used in their example.
+ builder.setIntAt('y', 10_000);
+ builder.setIntAt('z', 8_000);
final MockFont font = new MockFont();
font.setWidths(builder.toIntArray());
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-29 21:24:13 UTC (rev 12150)
+++ trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/LineBreaker4aTests.java 2021-11-30 00:31:57 UTC (rev 12151)
@@ -33,12 +33,12 @@
import org.foray.common.para.ParaConfig4a;
import org.foray.common.para.ParaGlue4a;
import org.foray.common.para.ParaPenalty4a;
+import org.foray.font.util.MockFont;
+import org.foray.font.util.MockFontUse;
import org.foray.orthography.Punctuation4a;
import org.axsl.common.para.DiscretionaryHyphen;
import org.axsl.common.para.ParaControl;
-import org.axsl.font.Font;
-import org.axsl.font.FontUse;
import org.axsl.linebreak.LineBreakControl;
import org.axsl.linebreak.OutputLine;
@@ -244,9 +244,9 @@
* @return The Monotype paragraph configuration.
*/
public ParaConfig4a createMonotypeParaConfig() {
- final Font font = LbTestUtilities.createMonotypeFont();
- final FontUse fontUse = Mockito.mock(FontUse.class);
- Mockito.when(fontUse.getFont()).thenReturn(font);
+ final MockFont font = LbTestUtilities.createMonotypeFont();
+ final MockFontUse fontUse = new MockFontUse();
+ fontUse.setFont(font);
final ParaConfig4a paraConfig = new ParaConfig4a(fontUse, 10, null, 0, 0);
return paraConfig;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-11-29 21:24:16
|
Revision: 12150
http://sourceforge.net/p/foray/code/12150
Author: victormote
Date: 2021-11-29 21:24:13 +0000 (Mon, 29 Nov 2021)
Log Message:
-----------
Minor refinements to font & linebreaking testing tools.
Modified Paths:
--------------
trunk/foray/foray-font/src/main/java/org/foray/font/util/MockFont.java
trunk/foray/foray-linebreak/src/main/java/org/foray/linebreak/FirstFitLb.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
trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/TotalFitLbTests.java
Added Paths:
-----------
trunk/foray/foray-font/src/main/java/org/foray/font/util/MockFontUse.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-29 17:19:41 UTC (rev 12149)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/util/MockFont.java 2021-11-29 21:24:13 UTC (rev 12150)
@@ -30,23 +30,30 @@
import org.foray.common.WellKnownConstants;
import org.foray.common.sequence.IntArray;
+import org.foray.font.Font4a;
+import org.foray.font.format.Kerning;
import org.axsl.common.data.BoundingBox;
-import org.axsl.common.sequence.IntSequence;
import org.axsl.font.Font;
-import org.axsl.font.FontContext;
import org.axsl.font.Panose;
-import org.axsl.orthography.Orthography;
+import org.axsl.ps.CharSet;
import org.axsl.ps.Encoding;
/**
- * A mock implementation of Font, useful for tests.
+ * A mock implementation of {@link Font}, useful for tests.
*/
-public class MockFont implements Font {
+public class MockFont extends Font4a {
/** The array of glyph widths. */
private IntArray widths;
+ /**
+ * Constructor.
+ */
+ public MockFont() {
+ super(null);
+ }
+
@Override
public int getAscender(final int fontSize) {
// TODO Auto-generated method stub
@@ -76,14 +83,6 @@
return this.widths.intAt(metricIndex) * fontSize / WellKnownConstants.MILLIUNITS_PER_UNIT;
}
- @Override
- public int width(final IntSequence metricIndexes, final int offset, final int length, final int fontSize,
- final int letterSpacing, final int wordSpacing, final FontContext options,
- final Orthography orthography) {
- // TODO Auto-generated method stub
- return 0;
- }
-
/**
* Sets the widths to be used by this instance.
* @param widths The array of widths to be used.
@@ -93,12 +92,6 @@
}
@Override
- public int widthEstimate(final int codePoint, final int fontSize) {
- // TODO Auto-generated method stub
- return 0;
- }
-
- @Override
public boolean isEmbeddable() {
// TODO Auto-generated method stub
return false;
@@ -159,12 +152,6 @@
}
@Override
- public int kern(final int glyphIndex1, final int glyphIndex2) {
- // TODO Auto-generated method stub
- return 0;
- }
-
- @Override
public float getItalicAngle() {
// TODO Auto-generated method stub
return 0;
@@ -189,93 +176,123 @@
}
@Override
- public float normalLineHeightFactor(final LineHeightAlgorithm algorithm) {
+ public int underlineSize(final int fontSize) {
// TODO Auto-generated method stub
return 0;
}
@Override
- public int baselineOffset(final WritingMode writingMode, final Baseline baselineType, final int fontSize) {
+ public int underlinePosition(final int fontSize) {
// TODO Auto-generated method stub
return 0;
}
@Override
- public Baseline baseline(final String script) {
+ public int overlineSize(final int fontSize) {
// TODO Auto-generated method stub
- return null;
+ return 0;
}
@Override
- public int subscriptShift(final int fontSize) {
+ public int overlinePosition(final int fontSize) {
// TODO Auto-generated method stub
return 0;
}
@Override
- public int superscriptShift(final int fontSize) {
+ public int strikeoutSize(final int fontSize) {
// TODO Auto-generated method stub
return 0;
}
@Override
- public int underlineSize(final int fontSize) {
+ public int strikeoutPosition(final int fontSize) {
// TODO Auto-generated method stub
return 0;
}
@Override
- public int underlinePosition(final int fontSize) {
+ public Panose getPanose() {
// TODO Auto-generated method stub
- return 0;
+ return null;
}
@Override
- public int overlineSize(final int fontSize) {
+ public BoundingBox getBoundingBox() {
// TODO Auto-generated method stub
- return 0;
+ return null;
}
@Override
- public int overlinePosition(final int fontSize) {
+ public int getFlags() {
// TODO Auto-generated method stub
return 0;
}
@Override
- public int strikeoutSize(final int fontSize) {
+ public BoundingBox getGlyphBoundingBox(final int glyphIndex, final int fontSize) {
// TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ protected Kerning getKerning() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public boolean kerningActive() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public int widthUndefinedGlyph(final int fontSize) {
+ // TODO Auto-generated method stub
return 0;
}
@Override
- public int strikeoutPosition(final int fontSize) {
+ public boolean glyphAvailable(final int c) {
// TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public int getNumGlyphs() {
+ // TODO Auto-generated method stub
return 0;
}
@Override
- public Panose getPanose() {
+ public CharSet getCharSet() {
// TODO Auto-generated method stub
return null;
}
@Override
- public BoundingBox getBoundingBox() {
+ public int extractBaseline(final WritingMode writingMode, final Baseline baselineType, final int fontSize) {
// TODO Auto-generated method stub
- return null;
+ return 0;
}
@Override
- public int getFlags() {
+ public int getUnitsPerTextSpaceUnit() {
// TODO Auto-generated method stub
return 0;
}
@Override
- public BoundingBox getGlyphBoundingBox(final int glyphIndex, final int fontSize) {
+ public boolean supportsUnicode() {
// TODO Auto-generated method stub
- return null;
+ return false;
}
+ @Override
+ public int metricIndex(final int codePoint) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
}
Added: trunk/foray/foray-font/src/main/java/org/foray/font/util/MockFontUse.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/util/MockFontUse.java (rev 0)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/util/MockFontUse.java 2021-11-29 21:24:13 UTC (rev 12150)
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2021 The FOray Project.
+ * http://www.foray.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.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.font.util;
+
+import org.foray.font.Font4a;
+import org.foray.font.FontUse4a;
+
+import org.axsl.font.FontUse;
+
+/**
+ * A mock implementation of {@link FontUse}, useful for tests.
+ */
+public class MockFontUse extends FontUse4a {
+
+ /** The font. */
+ private Font4a font;
+
+ /**
+ * Constructor.
+ */
+ public MockFontUse() {
+ super(null, null, null);
+ }
+
+ @Override
+ public Font4a getFont() {
+ return this.font;
+ }
+
+ /**
+ * Set the font.
+ * @param font The new font.
+ */
+ public void setFont(final Font4a font) {
+ this.font = font;
+ }
+
+}
Property changes on: trunk/foray/foray-font/src/main/java/org/foray/font/util/MockFontUse.java
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Rev
\ No newline at end of property
Modified: trunk/foray/foray-linebreak/src/main/java/org/foray/linebreak/FirstFitLb.java
===================================================================
--- trunk/foray/foray-linebreak/src/main/java/org/foray/linebreak/FirstFitLb.java 2021-11-29 17:19:41 UTC (rev 12149)
+++ trunk/foray/foray-linebreak/src/main/java/org/foray/linebreak/FirstFitLb.java 2021-11-29 21:24:13 UTC (rev 12150)
@@ -135,7 +135,8 @@
private void addProvisionalNonGlue(final ParaLeaf leaf) {
provisionalNonGlue.add(leaf);
- provisionalNonGlueIdealWidth += leaf.getWidth(paraConfig);
+ final int leafWidth = leaf.getWidth(paraConfig);
+ provisionalNonGlueIdealWidth += leafWidth;
}
private void addProvisionalGlue(final ParaGlue glue) {
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-29 17:19:41 UTC (rev 12149)
+++ trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/FirstFitLbTests.java 2021-11-29 21:24:13 UTC (rev 12150)
@@ -51,7 +51,7 @@
para.addWordAndSpace("Hello World!");
para.setParaConfig(createMonotypeParaConfig());
final ParaControl paraControl = createParaControl();
- final LineBreakControl lbControl = createLineBreakControl();
+ final LineBreakControl lbControl = createLineBreakControl(-1);
final FirstFitLb out = new FirstFitLb();
final int[] actual = out.breakIntoLines(para, paraControl, lbControl);
final int[] expected = new int[] {1};
@@ -69,7 +69,8 @@
final ParaBranch4a para = this.createPara();
para.setParaConfig(createMonotypeParaConfig());
final ParaControl paraControl = createParaControl();
- final LineBreakControl lbControl = createLineBreakControl();
+ /* Line width obtained from "Digital Typography," p. 73.*/
+ final LineBreakControl lbControl = createLineBreakControl(390_000);
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-29 17:19:41 UTC (rev 12149)
+++ trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/LbTestUtilities.java 2021-11-29 21:24:13 UTC (rev 12150)
@@ -59,66 +59,66 @@
* Except where noted, the "Digital Typography" values agree with those of "The Monotype System". */
final IntArrayBuilder builder = new IntArrayBuilder(128);
- builder.replace(' ', 600); // Unclear from the table in the Monotype manual what the width of a space is.
- builder.replace('\'', 500);
- builder.replace(',', 500);
- builder.replace('-', 500);
- builder.replace('.', 500);
- builder.replace(';', 600); // Knuth-Plass shows ";" as 5. Unclear which value they actually used.
+ builder.replace(' ', 6_000); // Unclear from the table in the Monotype manual what the width of a space is.
+ builder.replace('\'', 5_000);
+ builder.replace(',', 5_000);
+ builder.replace('-', 5_000);
+ builder.replace('.', 5_000);
+ builder.replace(';', 6_000); // Knuth-Plass shows ";" as 5. Unclear which value they actually used.
- builder.replace('A', 1300);
- builder.replace('B', 1300);
- builder.replace('C', 1300);
- builder.replace('D', 1400);
- builder.replace('E', 1300);
- builder.replace('F', 1200);
- builder.replace('G', 1400);
- builder.replace('H', 1500);
- builder.replace('I', 800); // Knuth-Plass shows "I" as 6. Unclear which value they actually used.
- builder.replace('J', 900);
- builder.replace('K', 1500);
- builder.replace('L', 1200);
- builder.replace('M', 1800);
- builder.replace('N', 1500);
- builder.replace('O', 1300);
- builder.replace('P', 1200);
- builder.replace('Q', 1300);
- builder.replace('R', 1400);
- builder.replace('S', 1000);
- builder.replace('T', 1300);
- builder.replace('U', 1400);
- builder.replace('V', 1300);
- builder.replace('W', 1800);
- builder.replace('X', 1500);
- builder.replace('Y', 1400);
- builder.replace('Z', 1100);
+ builder.replace('A', 13_000);
+ builder.replace('B', 13_000);
+ builder.replace('C', 13_000);
+ builder.replace('D', 14_000);
+ builder.replace('E', 13_000);
+ builder.replace('F', 12_000);
+ builder.replace('G', 14_000);
+ builder.replace('H', 15_000);
+ builder.replace('I', 8_000); // Knuth-Plass shows "I" as 6. Unclear which value they actually used.
+ builder.replace('J', 9_000);
+ builder.replace('K', 15_000);
+ builder.replace('L', 12_000);
+ builder.replace('M', 18_000);
+ builder.replace('N', 15_000);
+ builder.replace('O', 13_000);
+ builder.replace('P', 12_000);
+ builder.replace('Q', 13_000);
+ builder.replace('R', 14_000);
+ builder.replace('S', 10_000);
+ builder.replace('T', 13_000);
+ builder.replace('U', 14_000);
+ builder.replace('V', 13_000);
+ builder.replace('W', 18_000);
+ builder.replace('X', 15_000);
+ builder.replace('Y', 14_000);
+ builder.replace('Z', 11_000);
- builder.replace('a', 900);
- builder.replace('b', 1000);
- builder.replace('c', 800);
- builder.replace('d', 1000);
- builder.replace('e', 800);
- builder.replace('f', 600);
- builder.replace('g', 900);
- builder.replace('h', 1000);
- builder.replace('i', 500);
- builder.replace('j', 600);
- builder.replace('k', 1000);
- builder.replace('l', 500);
- builder.replace('m', 1500);
- builder.replace('n', 1000);
- builder.replace('o', 900);
- builder.replace('p', 1000);
- builder.replace('q', 1000);
- builder.replace('r', 700);
- builder.replace('s', 700);
- builder.replace('t', 700);
- builder.replace('u', 1000);
- builder.replace('v', 1000); // Knuth-Plass shows "v" as 9. Unclear which value they actually used.
- builder.replace('w', 1300);
- builder.replace('x', 900); // Knuth-Plass shows "x" as 10. However, it is not used in their example.
- builder.replace('y', 1000);
- builder.replace('z', 800);
+ builder.replace('a', 9_000);
+ builder.replace('b', 10_000);
+ builder.replace('c', 8_000);
+ builder.replace('d', 10_000);
+ builder.replace('e', 8_000);
+ builder.replace('f', 6_000);
+ builder.replace('g', 9_000);
+ builder.replace('h', 10_000);
+ builder.replace('i', 5_000);
+ builder.replace('j', 6_000);
+ builder.replace('k', 10_000);
+ builder.replace('l', 5_000);
+ builder.replace('m', 15_000);
+ builder.replace('n', 10_000);
+ builder.replace('o', 9_000);
+ builder.replace('p', 10_000);
+ builder.replace('q', 10_000);
+ builder.replace('r', 7_000);
+ builder.replace('s', 7_000);
+ builder.replace('t', 7_000);
+ builder.replace('u', 10_000);
+ builder.replace('v', 10_000); // Knuth-Plass shows "v" as 9. Unclear which value they actually used.
+ builder.replace('w', 13_000);
+ builder.replace('x', 9_000); // Knuth-Plass shows "x" as 10. However, it is not used in their example.
+ builder.replace('y', 10_000);
+ builder.replace('z', 8_000);
final MockFont font = new MockFont();
font.setWidths(builder.toIntArray());
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-29 17:19:41 UTC (rev 12149)
+++ trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/LineBreaker4aTests.java 2021-11-29 21:24:13 UTC (rev 12150)
@@ -253,13 +253,19 @@
/**
* Creates a standard line break control, used for testing.
+ * @param lineWidth The line width that this control should use, in millipoints.
+ * If less than zero, a line width of 6.5 inches will be used.
* @return A link break control for testing.
*/
- public LineBreakControl createLineBreakControl() {
+ public LineBreakControl createLineBreakControl(final int lineWidth) {
final LineBreakControl lbControl = Mockito.mock(LineBreakControl.class);
final OutputLine lineOutput = Mockito.mock(OutputLine.class);
- /* Page is 8.5 inches wide, 1 inch margin on both ends, leaving 6.5 inches, or 468,000 millipoints. */
- Mockito.when(lineOutput.capacityTotal()).thenReturn(468000);
+ if (lineWidth < 0) {
+ /* Page is 8.5 inches wide, 1 inch margin on both ends, leaving 6.5 inches, or 468,000 millipoints. */
+ Mockito.when(lineOutput.capacityTotal()).thenReturn(468000);
+ } else {
+ Mockito.when(lineOutput.capacityTotal()).thenReturn(lineWidth);
+ }
Mockito.when(lbControl.getOutputLine(Mockito.anyInt())).thenReturn(lineOutput);
return lbControl;
}
Modified: trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/TotalFitLbTests.java
===================================================================
--- trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/TotalFitLbTests.java 2021-11-29 17:19:41 UTC (rev 12149)
+++ trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/TotalFitLbTests.java 2021-11-29 21:24:13 UTC (rev 12150)
@@ -51,7 +51,8 @@
final ParaBranch4a para = this.createPara();
para.setParaConfig(createMonotypeParaConfig());
final ParaControl paraControl = createParaControl();
- final LineBreakControl lbControl = createLineBreakControl();
+ /* Line width obtained from "Digital Typography," p. 73.*/
+ final LineBreakControl lbControl = createLineBreakControl(390_000);
final TotalFitLb out = new TotalFitLb();
final int[] actual = out.breakIntoLines(para, paraControl, lbControl);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-11-29 17:19:44
|
Revision: 12149
http://sourceforge.net/p/foray/code/12149
Author: victormote
Date: 2021-11-29 17:19:41 +0000 (Mon, 29 Nov 2021)
Log Message:
-----------
Rough-in an implementation of the "first-fit" algorithm.
Modified Paths:
--------------
trunk/foray/foray-linebreak/src/main/java/org/foray/linebreak/FirstFitLb.java
trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/FirstFitLbTests.java
Modified: trunk/foray/foray-linebreak/src/main/java/org/foray/linebreak/FirstFitLb.java
===================================================================
--- trunk/foray/foray-linebreak/src/main/java/org/foray/linebreak/FirstFitLb.java 2021-11-28 16:34:24 UTC (rev 12148)
+++ trunk/foray/foray-linebreak/src/main/java/org/foray/linebreak/FirstFitLb.java 2021-11-29 17:19:41 UTC (rev 12149)
@@ -28,20 +28,252 @@
package org.foray.linebreak;
+import org.foray.common.sequence.IntArrayBuilder;
+
import org.axsl.common.para.ParaBranch;
+import org.axsl.common.para.ParaConfig;
import org.axsl.common.para.ParaControl;
+import org.axsl.common.para.ParaGlue;
+import org.axsl.common.para.ParaLeaf;
+import org.axsl.common.para.ParaPenalty;
import org.axsl.linebreak.LineBreakControl;
+import org.axsl.linebreak.OutputLine;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.ListIterator;
+
/**
- * Implementation of the Knuth-Plass "first-fit" linebreaking algorithm.
- * @see "Knuth, Digital Typography, 1999, pp. 74, 78"
+ * <p>Implementation of the Knuth-Plass "first-fit" linebreaking algorithm, which is described as follows on pages
+ * 68-69:</p>
+ *
+ * <blockquote>Traditional practice has been to assign a minimum and maximum width to interword spaces, together with a
+ * normal width representing the ideal situation. The standard algorithm for line breaking ... then proceeds as follows:
+ * Keep appending words to the current line, assuming the normal spacing, until reaching a word that does not fit. Break
+ * after this word, if it is possible to do so without compressing the spaces to less than the given minimum; otherwise
+ * break before this word, if it is possible to do so without expanding the spaces to more than the given maximum.
+ * Otherwise hyphenate the offending word, putting as much of it on the current line as will fit; if no suitable
+ * hyphenation points can be found, accept a line whose spaces exceed the given maximum.</blockquote>
+ *
+ * @see "Knuth, Digital Typography, 1999, pp. 68, 74, 78"
*/
public class FirstFitLb extends LineBreaker4a {
+ /**
+ * Inner class storing the state of the line-breaking, to allow more concise methods without sacrificing thread
+ * safety.
+ */
+ private final class State {
+
+ /** Initial size for breakpoints, chosen as being unlikely to be exceeded. */
+ private static final int BREAKPOINTS_INIT_SIZE = 100;
+
+ /** Initial list size for line content items, chosen as being unlikely to be exceeded. */
+ private static final int LINE_CONTENT_INIT_SIZE = 200;
+
+ /** Initial list size for "provisional" items, chosen as being unlikely to be exceeded. */
+ private static final int PROVISIONAL_LIST_SIZE = 20;
+
+ /** The array of breakpoints for the paragraph. */
+ private IntArrayBuilder breakpoints = new IntArrayBuilder(BREAKPOINTS_INIT_SIZE);
+
+ /** The 1-based line number of the layout for this paragraphy. */
+ private int currentLineNumber;
+
+ /** The line onto which the next line of output from this line-breaker should be placed. */
+ private OutputLine currentLine;
+
+ /** The accepted content of the current line. */
+ private List<ParaLeaf> currentLineContent = new ArrayList<ParaLeaf>(LINE_CONTENT_INIT_SIZE);
+
+ /** The total ideal width of all items that have been accepted onto the current line. */
+ private int currentLineIdealWidth = 0;
+
+ /** The total shrinkability of all items that have been accepted onto the current line. */
+ private int currentLineShrinkability = 0;
+
+ /** The total stretchability of all items that have been accepted onto the current line. */
+ private int currentLineStretchability = 0;
+
+ /** The list of provisional glue items, i.e. the glue items marking the beginning of the current provisional
+ * word. */
+ private List<ParaGlue> provisionalGlue = new ArrayList<ParaGlue>(PROVISIONAL_LIST_SIZE);
+
+ /** The accumulated total of the ideal width of glue items at the beginning of the current provisional word. */
+ private int provisionalGlueIdealWidth = 0;
+
+ /** The accumulated total of the shrinkability of glue items at the beginning of the current provisional word.*/
+ private int provisionalGlueShrinkability = 0;
+
+ /** The accumulated total of the stretchability of glue items at the beginning of the current provisional
+ * word.*/
+ private int provisionalGlueStretchability = 0;
+
+ /** The list of provisional non-glue items for the current provisional word. */
+ private List<ParaLeaf> provisionalNonGlue = new ArrayList<ParaLeaf>(PROVISIONAL_LIST_SIZE);
+
+ /** The accumulated total of the ideal width of the non-glue items in the current provisional word. */
+ private int provisionalNonGlueIdealWidth = 0;
+
+ /** The configuration of the paragraph being processed. */
+ private ParaConfig paraConfig;
+
+ /** The line-break control. */
+ private LineBreakControl lbControl;
+
+ /**
+ * Constructor.
+ * @param paraConfig The configuration of the paragraph being processed.
+ * @param lbControl The linebreak control instance.
+ */
+ private State(final ParaConfig paraConfig, final LineBreakControl lbControl) {
+ this.paraConfig = paraConfig;
+ this.lbControl = lbControl;
+ this.currentLineNumber = 1;
+ this.currentLine = lbControl.getOutputLine(currentLineNumber);
+ }
+
+ private void addProvisionalNonGlue(final ParaLeaf leaf) {
+ provisionalNonGlue.add(leaf);
+ provisionalNonGlueIdealWidth += leaf.getWidth(paraConfig);
+ }
+
+ private void addProvisionalGlue(final ParaGlue glue) {
+ provisionalGlue.add(glue);
+ provisionalGlueShrinkability += glue.getShrinkability(paraConfig);
+ provisionalGlueStretchability += glue.getStretchability(paraConfig);
+ }
+
+ private void acceptProvisionalWord() {
+ currentLineIdealWidth += provisionalGlueIdealWidth;
+ currentLineIdealWidth += provisionalNonGlueIdealWidth;
+ currentLineShrinkability += provisionalGlueShrinkability;
+ currentLineStretchability += provisionalGlueStretchability;
+ currentLineContent.addAll(provisionalGlue);
+ currentLineContent.addAll(provisionalNonGlue);
+ provisionalGlue.clear();
+ provisionalNonGlue.clear();
+ }
+
+ private int idealProvisionalLineWidth() {
+ return currentLineIdealWidth + provisionalGlueIdealWidth + provisionalNonGlueIdealWidth;
+ }
+
+ private int minProvisionalLineWidth() {
+ return idealProvisionalLineWidth() - currentLineShrinkability - provisionalGlueShrinkability;
+ }
+
+ private void markBreakpointInternal() {
+ final int base = this.breakpoints.empty() ? 0 : this.breakpoints.peek();
+ final int newBreakpoint = base + this.currentLineContent.size();
+ this.breakpoints.append(newBreakpoint);
+ this.currentLineContent.clear();
+ }
+
+ private void markEndOfLine() {
+ markBreakpointInternal();
+ this.currentLineNumber ++;
+ this.currentLine = this.lbControl.getOutputLine(currentLineNumber);
+ }
+
+ private void markEndOfLine(final int provisionalIndex) {
+ final int base = this.breakpoints.empty() ? 0 : this.breakpoints.peek();
+ final int newBreakpoint = base + this.currentLineContent.size() + provisionalIndex;
+ this.breakpoints.append(newBreakpoint);
+
+ this.currentLineContent.clear();
+ /* Copy the portion of the provisional word that was pushed to the next line. */
+ for (int index = provisionalIndex; index < this.provisionalNonGlue.size(); index ++) {
+ final ParaLeaf leaf = this.provisionalNonGlue.get(index);
+ this.currentLineContent.add(leaf);
+ }
+ }
+
+ private void markEndOfParagraph() {
+ markBreakpointInternal();
+ }
+
+ }
+
@Override
public int[] breakIntoLines(final ParaBranch paragraph, final ParaControl paraControl,
final LineBreakControl lbControl) {
- return new int[0];
+ /* For purposes of this algorithm, "word" means the content between glue items, or, really, if (a) is non-glue,
+ * (b) is glue, (c) is non-glue, and (d) is glue, then (a) is the end of the previous word, and (b) and (c)
+ * together are the current word, and (d) is the beginning of the next word. */
+
+ final ParaConfig paraConfig = paragraph.getParaConfig();
+ final State state = new State(paraConfig, lbControl);
+
+ final ListIterator<ParaLeaf> leafIterator = paragraph.iterator();
+ while (leafIterator.hasNext()) {
+ final ParaLeaf leaf = leafIterator.next();
+ final ParaGlue glue = leaf.asParaGlue();
+ if (glue == null) {
+ /* This is word content. */
+ state.addProvisionalNonGlue(leaf);
+ } else {
+ if (state.provisionalNonGlue.size() < 1) {
+ /* This is glue at the beginning of a provisional "word." */
+ state.addProvisionalGlue(glue);
+ } else {
+ /* This is glue marking the end of a provisional "word" and the beginning of the next. We need to
+ * process the provisional word. */
+ if (state.idealProvisionalLineWidth() <= state.currentLine.capacityTotal()) {
+ /* Provisional word fits into the line using ideal widths. */
+ state.acceptProvisionalWord();
+ } else {
+ /* Provisional word does not fit into the line using ideal widths. */
+ processEndOfLine(state, state.currentLine);
+ }
+ }
+ }
+ }
+ state.markEndOfParagraph();
+ return state.breakpoints.toArray();
}
+ private void processEndOfLine(final State state, final OutputLine currentLine) {
+ /* Does the provisional word fit if we compress the word spacing? */
+ if (state.minProvisionalLineWidth() <= currentLine.capacityTotal()) {
+ /* Yes, it fits if we compress the word spacing. */
+ state.acceptProvisionalWord();
+ state.markEndOfLine();
+ return;
+ }
+ /* The provisional word does not fit, even if we compress the word spacing. */
+
+ /* If the word spacing is expanded to its maximum, is existing content (i.e. before the provisional word)
+ * long enough to fill the line? */
+ if (state.currentLineIdealWidth + state.currentLineStretchability >= currentLine.capacityTotal()) {
+ /* Yes, the current line can be expanded to fill the line. */
+ state.markEndOfLine();
+ return;
+ }
+ /* The word spacing expanded to its maximum does not fill the line. */
+
+ /* Is there an acceptable hyphenation point in the provisional word? */
+ /* Since we want as much of the word as possible to remain on the current line, iterate from the end of the
+ * provisional word. */
+ int idealWidthToNextLine = 0;
+ for (int index = state.provisionalNonGlue.size() - 1; index > 0; index --) {
+ final ParaLeaf leaf = state.provisionalNonGlue.get(index);
+ final ParaPenalty penalty = leaf.asParaPenalty();
+ if (penalty == null) {
+ idealWidthToNextLine += leaf.getWidth(state.paraConfig);
+ } else {
+ if (state.minProvisionalLineWidth() - idealWidthToNextLine + penalty.getWidth(state.paraConfig)
+ <= currentLine.capacityTotal()) {
+ /* This is the breakpoint we want. */
+ state.markEndOfLine(index);
+ return;
+ }
+ }
+ }
+ /* We did not find an acceptable hyphenation point in the provisional word. */
+
+ /* Accept the line without the provisional word, even though the spaces will exceed the given maximum. */
+ state.markEndOfLine();
+ }
+
}
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-28 16:34:24 UTC (rev 12148)
+++ trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/FirstFitLbTests.java 2021-11-29 17:19:41 UTC (rev 12149)
@@ -34,6 +34,7 @@
import org.axsl.linebreak.LineBreakControl;
import org.junit.Assert;
+import org.junit.Ignore;
import org.junit.Test;
/**
@@ -42,10 +43,27 @@
public class FirstFitLbTests extends LineBreaker4aTests {
/**
- * A test.
+ * Test of an extremely short line that should return no line breaks.
*/
@Test
- public void firstFitTest1() {
+ public void firstFitTestSingleLine() {
+ final ParaBranch4aTestFixture para = new ParaBranch4aTestFixture(null, '-');
+ para.addWordAndSpace("Hello World!");
+ para.setParaConfig(createMonotypeParaConfig());
+ final ParaControl paraControl = createParaControl();
+ final LineBreakControl lbControl = createLineBreakControl();
+ final FirstFitLb out = new FirstFitLb();
+ final int[] actual = out.breakIntoLines(para, paraControl, lbControl);
+ final int[] expected = new int[] {1};
+ Assert.assertArrayEquals(expected, actual);
+ }
+
+ /**
+ * A test of the Grimm paragraph.
+ */
+ @Test
+ @Ignore
+ public void firstFitTestGrimm() {
/* TODO: THE CLASS BEING TESTED IS VERY INCOMPLETE, AND SO IS THIS TEST !!!!!! */
final ParaBranch4a para = this.createPara();
@@ -56,7 +74,7 @@
final FirstFitLb out = new FirstFitLb();
final int[] actual = out.breakIntoLines(para, paraControl, lbControl);
- final int[] expected = new int[0];
+ final int[] expected = new int[] {19, 42, 68, 90, 113, 138, 164, 185, 209, 230, 254, 276};
Assert.assertArrayEquals(expected, actual);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-11-28 16:34:26
|
Revision: 12148
http://sourceforge.net/p/foray/code/12148
Author: victormote
Date: 2021-11-28 16:34:24 +0000 (Sun, 28 Nov 2021)
Log Message:
-----------
Add tests for attempts to read past either end of the iterator.
Modified Paths:
--------------
trunk/foray/foray-common/src/test/java/org/foray/common/para/ParaBranch4aIteratorTests.java
Modified: trunk/foray/foray-common/src/test/java/org/foray/common/para/ParaBranch4aIteratorTests.java
===================================================================
--- trunk/foray/foray-common/src/test/java/org/foray/common/para/ParaBranch4aIteratorTests.java 2021-11-28 16:19:58 UTC (rev 12147)
+++ trunk/foray/foray-common/src/test/java/org/foray/common/para/ParaBranch4aIteratorTests.java 2021-11-28 16:34:24 UTC (rev 12148)
@@ -54,6 +54,9 @@
Assert.assertEquals(expectedPreviousIndex, iterator.previousIndex());
}
+ /**
+ * Test iterating both forward and backward.
+ */
@Test
public void test_001() {
final ParaBranch4a para = ParaBranch4aTests.createTestPara();
@@ -139,4 +142,48 @@
}
}
+ /**
+ * Test trying to iterate backward when the iterator is first created.
+ */
+ @Test
+ public void test_002() {
+ final ParaBranch4a para = ParaBranch4aTests.createTestPara();
+ final ParaBranch4aIterator out = new ParaBranch4aIterator(para);
+ iteratorAssertions(out, true, false, 0, -1);
+
+ try {
+ out.previous();
+ Assert.fail("Exception expected here.");
+ } catch (final NoSuchElementException e) {
+ /* This is the expected case. */
+ Assert.assertEquals("There is no \"previous\" element.", e.getMessage());
+ }
+ }
+
+ /**
+ * Test trying to iterate forward past the end of the branch.
+ */
+ @Test
+ public void test_003() {
+ final ParaBranch4a para = ParaBranch4aTests.createTestPara();
+ final ParaBranch4aIterator out = new ParaBranch4aIterator(para);
+ iteratorAssertions(out, true, false, 0, -1);
+
+ /* Iterate to the end of the branch. */
+ for (int leafIndex = 0; leafIndex < para.paraLeafSize(); leafIndex ++) {
+ out.next();
+ }
+
+ /* Make sure we are where we think we are. */
+ iteratorAssertions(out, false, true, 50, 49);
+
+ try {
+ out.next();
+ Assert.fail("Exception expected here.");
+ } catch (final NoSuchElementException e) {
+ /* This is the expected case. */
+ Assert.assertEquals("There is no \"next\" element.", e.getMessage());
+ }
+ }
+
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-11-28 16:20:00
|
Revision: 12147
http://sourceforge.net/p/foray/code/12147
Author: victormote
Date: 2021-11-28 16:19:58 +0000 (Sun, 28 Nov 2021)
Log Message:
-----------
Conform to aXSL change: Add method empty() to stack-like primitive sequences.
Modified Paths:
--------------
trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaBranch4aIterator.java
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ByteArrayBuilder.java
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/CharArrayBuilder.java
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/IntArrayBuilder.java
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/LongArrayBuilder.java
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ShortArrayBuilder.java
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaBranch4aIterator.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaBranch4aIterator.java 2021-11-28 15:35:38 UTC (rev 12146)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaBranch4aIterator.java 2021-11-28 16:19:58 UTC (rev 12147)
@@ -169,7 +169,7 @@
* Increments the top item on the branch index stack.
*/
private void incrementBranchIndex() {
- if (this.branchIndexes.isEmpty()) {
+ if (this.branchIndexes.empty()) {
return;
}
int currentIndex = this.branchIndexes.pop();
@@ -181,7 +181,7 @@
* Decrements the top item on the branch index stack.
*/
private void decrementBranchIndex() {
- if (this.branchIndexes.isEmpty()) {
+ if (this.branchIndexes.empty()) {
return;
}
int currentIndex = this.branchIndexes.pop();
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ByteArrayBuilder.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ByteArrayBuilder.java 2021-11-28 15:35:38 UTC (rev 12146)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ByteArrayBuilder.java 2021-11-28 16:19:58 UTC (rev 12147)
@@ -33,7 +33,6 @@
package org.foray.common.sequence;
-import org.axsl.common.sequence.ByteSequence;
import org.axsl.common.sequence.ByteSequenceMutable;
import org.axsl.common.sequence.ByteSequencePlus;
@@ -47,10 +46,11 @@
import java.util.EmptyStackException;
/**
- * A mutable array of bytes.
- * Just as {@link ByteArray} is analogous to {@link java.lang.String}, and {@link ByteSequence} is analogous to
- * {@link CharSequence}, this class is analogous to {@link StringBuilder}.
- * Similar to {@link StringBuilder}, it will resize itself as necessary.
+ * <p>A mutable and automatically resizable collection of primitive {@link Byte#TYPE}, whose methods are analogous
+ * to, but a subset of, what is available in {@link StringBuilder}, using bytes instead of chars.</p>
+ *
+ * <p>This class can also operate as a stack of primitive bytes, the methods {@link #push(byte)}, {@link #pop()},
+ * {@link #peek()}, and {@link #empty()} being provided for that purpose.</p>
*/
public class ByteArrayBuilder extends AbstractByteSequence implements ByteSequenceMutable, Serializable {
@@ -435,4 +435,9 @@
return this.backingArray[this.length - 1];
}
+ @Override
+ public boolean empty() {
+ return this.length < 1;
+ }
+
}
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/sequence/CharArrayBuilder.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/sequence/CharArrayBuilder.java 2021-11-28 15:35:38 UTC (rev 12146)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/CharArrayBuilder.java 2021-11-28 16:19:58 UTC (rev 12147)
@@ -34,8 +34,11 @@
import java.util.EmptyStackException;
/**
- * A mutable array of chars that resizes itself as necessary.
- * This is a subsitute for {@link StringBuilder}.
+ * <p>A mutable and automatically resizable collection of primitive {@link Character#TYPE}, whose methods are analogous
+ * to, but a subset of, what is available in {@link StringBuilder}.</p>
+ *
+ * <p>This class can also operate as a stack of primitive chars, the methods {@link #push(char)}, {@link #pop()},
+ * {@link #peek()}, and {@link #empty()} being provided for that purpose.</p>
*/
public class CharArrayBuilder extends AbstractCharSequence implements CharSequenceMutable {
@@ -346,4 +349,9 @@
return this.backingArray[this.length - 1];
}
+ @Override
+ public boolean empty() {
+ return this.length < 1;
+ }
+
}
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/sequence/IntArrayBuilder.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/sequence/IntArrayBuilder.java 2021-11-28 15:35:38 UTC (rev 12146)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/IntArrayBuilder.java 2021-11-28 16:19:58 UTC (rev 12147)
@@ -35,12 +35,11 @@
import java.util.EmptyStackException;
/**
- * <p>A resizable collection of primitive {@link Integer#TYPE}, a subset of what is available in {@link StringBuilder},
- * but with ints instead of chars.</p>
+ * <p>A mutable and automatically resizable collection of primitive {@link Integer#TYPE}, whose methods are analogous
+ * to, but a subset of, what is available in {@link StringBuilder}, using ints instead of chars.</p>
*
- * <p>This class can also operate as a stack of primitive ints.
- * The {@link #push(int)}, {@link #pop()}, {@link #peek()}, and {@link #isEmpty()} methods exist to support that use
- * case.</p>
+ * <p>This class can also operate as a stack of primitive ints, the methods {@link #push(int)}, {@link #pop()},
+ * {@link #peek()}, and {@link #empty()} being provided for that purpose.</p>
*/
public class IntArrayBuilder extends AbstractIntSequence implements IntSequenceMutable {
@@ -330,7 +329,8 @@
return intAt(index);
}
- public boolean isEmpty() {
+ @Override
+ public boolean empty() {
return this.length < 1;
}
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/sequence/LongArrayBuilder.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/sequence/LongArrayBuilder.java 2021-11-28 15:35:38 UTC (rev 12146)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/LongArrayBuilder.java 2021-11-28 16:19:58 UTC (rev 12147)
@@ -37,11 +37,11 @@
import java.util.EmptyStackException;
/**
- * <p>A resizable collection of primitive {@link Long#TYPE}, a subset of what is available in {@link StringBuilder},
- * but with longs instead of chars.</p>
+ * <p>A mutable and automatically resizable collection of primitive {@link Long#TYPE}, whose methods are analogous
+ * to, but a subset of, what is available in {@link StringBuilder}, using longs instead of chars.</p>
*
- * <p>This class can also operate as a stack of primitive longs.
- * The {@link #push(long)}, {@link #pop()}, and {@link #peek()} methods exist to support that use case.</p>
+ * <p>This class can also operate as a stack of primitive longs, the methods {@link #push(long)}, {@link #pop()},
+ * {@link #peek()}, and {@link #empty()} being provided for that purpose.</p>
*/
public class LongArrayBuilder extends AbstractLongSequence implements LongSequenceMutable {
@@ -300,6 +300,11 @@
}
@Override
+ public boolean empty() {
+ return this.length < 1;
+ }
+
+ @Override
public LongSequencePlus asPlus() {
return this;
}
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ShortArrayBuilder.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ShortArrayBuilder.java 2021-11-28 15:35:38 UTC (rev 12146)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ShortArrayBuilder.java 2021-11-28 16:19:58 UTC (rev 12147)
@@ -35,11 +35,11 @@
import java.util.EmptyStackException;
/**
- * <p>A resizable collection of primitive {@link Short#TYPE}, a subset of what is available in {@link StringBuilder},
- * but with shorts instead of chars.</p>
+ * <p>A mutable and automatically resizable collection of primitive {@link Short#TYPE}, whose methods are analogous
+ * to, but a subset of, what is available in {@link StringBuilder}, using shorts instead of chars.</p>
*
- * <p>This class can also operate as a stack of primitive shorts.
- * The {@link #push(short)}, {@link #pop()}, and {@link #peek()} methods exist to support that use case.</p>
+ * <p>This class can also operate as a stack of primitive shorts, the methods {@link #push(short)}, {@link #pop()},
+ * {@link #peek()}, and {@link #empty()} being provided for that purpose.</p>
*/
public class ShortArrayBuilder extends AbstractShortSequence implements ShortSequenceMutable {
@@ -280,6 +280,11 @@
}
@Override
+ public boolean empty() {
+ return this.length < 1;
+ }
+
+ @Override
public ShortSequenceMutable asMutable() {
return this;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-11-28 15:35:40
|
Revision: 12146
http://sourceforge.net/p/foray/code/12146
Author: victormote
Date: 2021-11-28 15:35:38 +0000 (Sun, 28 Nov 2021)
Log Message:
-----------
Add iterator over the leaf nodes of a ParaBranch.
Modified Paths:
--------------
trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaBranch4a.java
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/IntArrayBuilder.java
trunk/foray/foray-common/src/test/java/org/foray/common/para/ParaBranch4aTests.java
Added Paths:
-----------
trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaBranch4aIterator.java
trunk/foray/foray-common/src/test/java/org/foray/common/para/ParaBranch4aIteratorTests.java
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaBranch4a.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaBranch4a.java 2021-11-28 01:37:07 UTC (rev 12145)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaBranch4a.java 2021-11-28 15:35:38 UTC (rev 12146)
@@ -190,8 +190,7 @@
@Override
public ListIterator<ParaLeaf> iterator() {
- // TODO Auto-generated method stub
- return null;
+ return new ParaBranch4aIterator(this);
}
@Override
Added: trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaBranch4aIterator.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaBranch4aIterator.java (rev 0)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaBranch4aIterator.java 2021-11-28 15:35:38 UTC (rev 12146)
@@ -0,0 +1,192 @@
+/*
+ * Copyright 2021 The FOray Project.
+ * http://www.foray.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.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.common.para;
+
+import org.foray.common.sequence.IntArrayBuilder;
+
+import org.axsl.common.para.ParaBranch;
+import org.axsl.common.para.ParaLeaf;
+import org.axsl.common.para.ParaNode;
+
+import java.util.ListIterator;
+import java.util.NoSuchElementException;
+import java.util.Stack;
+
+/**
+ * Depth-first bidirectional iterator over the Leaf nodes of a {@link ParaBranch} instance.
+ * Note that because this iterator is bidirectional, there is no concept of a "current" node, but rather "previous" and
+ * "next" which can be found at {@link #nextIndex()} and {@link #previousIndex()} respectively.
+ * This means that node "n" returned by next(), will also be returned again if the next call is to previous(), and vice
+ * versa.
+ */
+public class ParaBranch4aIterator implements ListIterator<ParaLeaf> {
+
+ /** The iterator conceptually sits immediately after (index - 1) and immediately before (index). */
+ private int leafIndex = 0;
+
+ /** The number of leaves in the branch. */
+ private int paraLeafSize;
+
+ /** The stack of branches being iterated. The root branch being iterated (i.e. the one passed in the constructor)
+ * is at the bottom of the stack, and the one currently being iterated is at the top. Each item on the stack must
+ * be a child of the item immediately below it in the stack. Together with {@link #branchIndexes}, which should
+ * always be of the same size, this defines the current location of the iterator as it traverses the content of
+ * the root. */
+ private Stack<ParaBranch> branchStack = new Stack<ParaBranch>();
+
+ /** The stack of descendant branch indexes. Together with {@link #branchStack}, which should always be of the same
+ * size, this defines the current location of the iterator as it traverses the content of the root. The index
+ * stored is conceptually the "next" index to be iterated. */
+ private IntArrayBuilder branchIndexes = new IntArrayBuilder();
+
+ public ParaBranch4aIterator(final ParaBranch branch) {
+ this.branchStack.push(branch);
+ this.paraLeafSize = branch.paraLeafSize();
+ branchIndexes.push(0);
+ }
+
+ @Override
+ public boolean hasNext() {
+ return this.leafIndex < this.paraLeafSize;
+ }
+
+ @Override
+ public ParaLeaf next() {
+ final ParaLeaf next = internalNext();
+ this.leafIndex ++;
+ return next;
+ }
+
+ private ParaLeaf internalNext() {
+ if (this.branchStack.isEmpty()) {
+ throw new NoSuchElementException("There is no \"next\" element.");
+ }
+ final ParaBranch currentBranch = this.branchStack.peek();
+ final int nextIndex = this.branchIndexes.peek();
+ if (nextIndex >= currentBranch.paraNodeSize()) {
+ this.branchStack.pop();
+ this.branchIndexes.pop();
+ incrementBranchIndex();
+ return internalNext();
+ }
+ final ParaNode node = currentBranch.paraNodeAt(nextIndex);
+ if (node.asParaLeaf() != null) {
+ incrementBranchIndex();
+ return node.asParaLeaf();
+ }
+ this.branchStack.push(node.asParaBranch());
+ this.branchIndexes.push(0);
+ return internalNext();
+ }
+
+ @Override
+ public boolean hasPrevious() {
+ return this.leafIndex > 0;
+ }
+
+ @Override
+ public ParaLeaf previous() {
+ final ParaLeaf previous = internalPrevious();
+ this.leafIndex --;
+ return previous;
+ }
+
+ private ParaLeaf internalPrevious() {
+ if (this.branchStack.isEmpty()) {
+ throw new NoSuchElementException("There is no \"previous\" element.");
+ }
+ final ParaBranch currentBranch = this.branchStack.peek();
+ final int previousIndex = this.branchIndexes.peek() - 1;
+ if (previousIndex < 0) {
+ this.branchStack.pop();
+ this.branchIndexes.pop();
+ decrementBranchIndex();
+ return internalPrevious();
+ }
+ final ParaNode node = currentBranch.paraNodeAt(previousIndex);
+ if (node.asParaLeaf() != null) {
+ decrementBranchIndex();
+ return node.asParaLeaf();
+ }
+ final ParaBranch branch = node.asParaBranch();
+ this.branchStack.push(branch);
+ this.branchIndexes.push(branch.paraNodeSize());
+ return internalPrevious();
+ }
+
+ @Override
+ public int nextIndex() {
+ return this.leafIndex;
+ }
+
+ @Override
+ public int previousIndex() {
+ return this.leafIndex - 1;
+ }
+
+ @Override
+ public void remove() {
+ throw new UnsupportedOperationException("This iterator is read-only.");
+ }
+
+ @Override
+ public void set(final ParaLeaf e) {
+ throw new UnsupportedOperationException("This iterator is read-only.");
+ }
+
+ @Override
+ public void add(final ParaLeaf e) {
+ throw new UnsupportedOperationException("This iterator is read-only.");
+ }
+
+ /**
+ * Increments the top item on the branch index stack.
+ */
+ private void incrementBranchIndex() {
+ if (this.branchIndexes.isEmpty()) {
+ return;
+ }
+ int currentIndex = this.branchIndexes.pop();
+ currentIndex ++;
+ this.branchIndexes.push(currentIndex);
+ }
+
+ /**
+ * Decrements the top item on the branch index stack.
+ */
+ private void decrementBranchIndex() {
+ if (this.branchIndexes.isEmpty()) {
+ return;
+ }
+ int currentIndex = this.branchIndexes.pop();
+ currentIndex --;
+ this.branchIndexes.push(currentIndex);
+ }
+
+}
Property changes on: trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaBranch4aIterator.java
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Rev
\ No newline at end of property
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/sequence/IntArrayBuilder.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/sequence/IntArrayBuilder.java 2021-11-28 01:37:07 UTC (rev 12145)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/IntArrayBuilder.java 2021-11-28 15:35:38 UTC (rev 12146)
@@ -39,7 +39,8 @@
* but with ints instead of chars.</p>
*
* <p>This class can also operate as a stack of primitive ints.
- * The {@link #push(int)}, {@link #pop()}, and {@link #peek()} methods exist to support that use case.</p>
+ * The {@link #push(int)}, {@link #pop()}, {@link #peek()}, and {@link #isEmpty()} methods exist to support that use
+ * case.</p>
*/
public class IntArrayBuilder extends AbstractIntSequence implements IntSequenceMutable {
@@ -329,6 +330,10 @@
return intAt(index);
}
+ public boolean isEmpty() {
+ return this.length < 1;
+ }
+
@Override
public IntSequenceMutable asMutable() {
return this;
Added: trunk/foray/foray-common/src/test/java/org/foray/common/para/ParaBranch4aIteratorTests.java
===================================================================
--- trunk/foray/foray-common/src/test/java/org/foray/common/para/ParaBranch4aIteratorTests.java (rev 0)
+++ trunk/foray/foray-common/src/test/java/org/foray/common/para/ParaBranch4aIteratorTests.java 2021-11-28 15:35:38 UTC (rev 12146)
@@ -0,0 +1,142 @@
+/*
+ * Copyright 2021 The FOray Project.
+ * http://www.foray.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.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.common.para;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.NoSuchElementException;
+
+/**
+ * Tests of {@link ParaBranch4aIterator}.
+ */
+public class ParaBranch4aIteratorTests {
+
+ /**
+ * Makes assertions about the state of the iterator.
+ * @param iterator The iterator about which the assertions are made.
+ * @param expectedHasNext The expected value for hasNext().
+ * @param expectedHasPrevious The expected value for hasPrevious().
+ * @param expectedNextIndex The expected value for nextIndex().
+ * @param expectedPreviousIndex The expected value for previousIndex().
+ */
+ private void iteratorAssertions(final ParaBranch4aIterator iterator, final boolean expectedHasNext,
+ final boolean expectedHasPrevious, final int expectedNextIndex, final int expectedPreviousIndex) {
+ Assert.assertEquals(expectedHasNext, iterator.hasNext());
+ Assert.assertEquals(expectedHasPrevious, iterator.hasPrevious());
+ Assert.assertEquals(expectedNextIndex, iterator.nextIndex());
+ Assert.assertEquals(expectedPreviousIndex, iterator.previousIndex());
+ }
+
+ @Test
+ public void test_001() {
+ final ParaBranch4a para = ParaBranch4aTests.createTestPara();
+ final ParaBranch4aIterator out = new ParaBranch4aIterator(para);
+ iteratorAssertions(out, true, false, 0, -1);
+
+ /* Iterate forward. */
+ Assert.assertEquals("B", out.next().getText());
+ iteratorAssertions(out, true, true, 1, 0);
+ Assert.assertEquals("e", out.next().getText());
+ iteratorAssertions(out, true, true, 2, 1);
+ Assert.assertEquals(" ", out.next().getText());
+ iteratorAssertions(out, true, true, 3, 2);
+ Assert.assertEquals("not", out.next().getText());
+ iteratorAssertions(out, true, true, 4, 3);
+ Assert.assertEquals(" ", out.next().getText());
+ iteratorAssertions(out, true, true, 5, 4);
+ Assert.assertEquals("afraid", out.next().getText());
+ iteratorAssertions(out, true, true, 6, 5);
+ Assert.assertEquals(" ", out.next().getText());
+ iteratorAssertions(out, true, true, 7, 6);
+ Assert.assertEquals("of", out.next().getText());
+ iteratorAssertions(out, true, true, 8, 7);
+ Assert.assertEquals(" ", out.next().getText());
+ iteratorAssertions(out, true, true, 9, 8);
+ Assert.assertEquals("great", out.next().getText());
+ iteratorAssertions(out, true, true, 10, 9);
+ Assert.assertEquals("-", out.next().getText());
+ iteratorAssertions(out, true, true, 11, 10);
+ Assert.assertEquals("ness", out.next().getText());
+ iteratorAssertions(out, true, true, 12, 11);
+ Assert.assertEquals(".", out.next().getText());
+ iteratorAssertions(out, true, true, 13, 12);
+
+ /* Now iterate backward for awhile. */
+ Assert.assertEquals(".", out.previous().getText());
+ iteratorAssertions(out, true, true, 12, 11);
+ Assert.assertEquals("ness", out.previous().getText());
+ iteratorAssertions(out, true, true, 11, 10);
+ Assert.assertEquals("-", out.previous().getText());
+ iteratorAssertions(out, true, true, 10, 9);
+ Assert.assertEquals("great", out.previous().getText());
+ iteratorAssertions(out, true, true, 9, 8);
+
+ /* Reverse direction to forward again. */
+ Assert.assertEquals("great", out.next().getText());
+ iteratorAssertions(out, true, true, 10, 9);
+ Assert.assertEquals("-", out.next().getText());
+ iteratorAssertions(out, true, true, 11, 10);
+
+ /* Reverse direction to backward again. Read back to the beginning. */
+ Assert.assertEquals("-", out.previous().getText());
+ iteratorAssertions(out, true, true, 10, 9);
+ Assert.assertEquals("great", out.previous().getText());
+ iteratorAssertions(out, true, true, 9, 8);
+ Assert.assertEquals(" ", out.previous().getText());
+ iteratorAssertions(out, true, true, 8, 7);
+ Assert.assertEquals("of", out.previous().getText());
+ iteratorAssertions(out, true, true, 7, 6);
+ Assert.assertEquals(" ", out.previous().getText());
+ iteratorAssertions(out, true, true, 6, 5);
+ Assert.assertEquals("afraid", out.previous().getText());
+ iteratorAssertions(out, true, true, 5, 4);
+ Assert.assertEquals(" ", out.previous().getText());
+ iteratorAssertions(out, true, true, 4, 3);
+ Assert.assertEquals("not", out.previous().getText());
+ iteratorAssertions(out, true, true, 3, 2);
+ Assert.assertEquals(" ", out.previous().getText());
+ iteratorAssertions(out, true, true, 2, 1);
+ Assert.assertEquals("e", out.previous().getText());
+ iteratorAssertions(out, true, true, 1, 0);
+ Assert.assertEquals("B", out.previous().getText());
+ iteratorAssertions(out, true, false, 0, -1);
+
+ /* We just retrieved the first node using previous(). The cursor is sitting before index 0. Another previous()
+ * should throw an exception. */
+ try {
+ out.previous();
+ Assert.fail("Exception expected here.");
+ } catch (final NoSuchElementException e) {
+ /* This is the expected case. */
+ Assert.assertEquals("There is no \"previous\" element.", e.getMessage());
+ }
+ }
+
+}
Property changes on: trunk/foray/foray-common/src/test/java/org/foray/common/para/ParaBranch4aIteratorTests.java
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Rev
\ No newline at end of property
Modified: trunk/foray/foray-common/src/test/java/org/foray/common/para/ParaBranch4aTests.java
===================================================================
--- trunk/foray/foray-common/src/test/java/org/foray/common/para/ParaBranch4aTests.java 2021-11-28 01:37:07 UTC (rev 12145)
+++ trunk/foray/foray-common/src/test/java/org/foray/common/para/ParaBranch4aTests.java 2021-11-28 15:35:38 UTC (rev 12146)
@@ -40,10 +40,10 @@
public class ParaBranch4aTests {
/**
- * Test of {@link ParaBranch4a#paraLeafAt(int)}.
+ * Creates a paragraph suitable for testing.
+ * @return A test paragraph.
*/
- @Test
- public void paraLeafAtTest_001() {
+ public static ParaBranch4a createTestPara() {
/*
* Be not afraid of greatness. Some are born great, some achieve greatness, and some have greatness thrust upon
* them.
@@ -108,7 +108,16 @@
nodeThem.add(new ParaBoxChars("m"));
nodeThem.add(new ParaBoxChars("."));
out.add(nodeThem); // Node 38, Leaf 45 - 49
+ return out;
+ }
+ /**
+ * Test of {@link ParaBranch4a#paraLeafAt(int)}.
+ */
+ @Test
+ public void paraLeafAtTest_001() {
+ final ParaBranch4a out = createTestPara();
+
/* Test the /node/ count. */
Assert.assertEquals(39, out.paraNodeSize());
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-11-28 01:37:08
|
Revision: 12145
http://sourceforge.net/p/foray/code/12145
Author: victormote
Date: 2021-11-28 01:37:07 +0000 (Sun, 28 Nov 2021)
Log Message:
-----------
Put branches at both ends of the test to make sure they are traversed correctly.
Modified Paths:
--------------
trunk/foray/foray-common/src/test/java/org/foray/common/para/ParaBranch4aTests.java
Modified: trunk/foray/foray-common/src/test/java/org/foray/common/para/ParaBranch4aTests.java
===================================================================
--- trunk/foray/foray-common/src/test/java/org/foray/common/para/ParaBranch4aTests.java 2021-11-28 01:19:17 UTC (rev 12144)
+++ trunk/foray/foray-common/src/test/java/org/foray/common/para/ParaBranch4aTests.java 2021-11-28 01:37:07 UTC (rev 12145)
@@ -52,74 +52,99 @@
final ParaConfig config = Mockito.mock(ParaConfig.class);
final ParaBranch4a out = new ParaBranch4a(config);
- final ParaBranch4a greatness = new ParaBranch4a(config);
- greatness.add(new ParaBoxChars("great"));
- greatness.add(DiscretionaryHyphen4a.GOOD);
- greatness.add(new ParaBoxChars("ness"));
+ final ParaBranch4a nodeGreatness = new ParaBranch4a(config);
+ nodeGreatness.add(new ParaBoxChars("great"));
+ nodeGreatness.add(DiscretionaryHyphen4a.GOOD);
+ nodeGreatness.add(new ParaBoxChars("ness"));
- out.add(new ParaBoxChars("Be")); // Node 0, Leaf 0
- out.add(ParaGlueChars.SPACE); // Node 1, Leaf 1
- out.add(new ParaBoxChars("not")); // Node 2, Leaf 2
- out.add(ParaGlueChars.SPACE); // Node 3, Leaf 3
- out.add(new ParaBoxChars("afraid")); // Node 4, Leaf 4
- out.add(ParaGlueChars.SPACE); // Node 5, Leaf 5
- out.add(new ParaBoxChars("of")); // Node 6, Leaf 6
- out.add(ParaGlueChars.SPACE); // Node 7, Leaf 7
- out.add(greatness); // Node 8, Leaf 8 - 10
- out.add(new ParaBoxChars(".")); // Node 9, Leaf 11
- out.add(ParaGlueChars.SPACE); // Node 10, Leaf 12
- out.add(new ParaBoxChars("Some")); // Node 11, Leaf 13
- out.add(ParaGlueChars.SPACE); // Node 12, Leaf 14
- out.add(new ParaBoxChars("are")); // Node 13, Leaf 15
- out.add(ParaGlueChars.SPACE); // Node 14, Leaf 16
- out.add(new ParaBoxChars("born")); // Node 15, Leaf 17
- out.add(ParaGlueChars.SPACE); // Node 16, Leaf 18
- out.add(new ParaBoxChars("great,")); // Node 17, Leaf 19
- out.add(ParaGlueChars.SPACE); // Node 18, Leaf 20
- out.add(new ParaBoxChars("some")); // Node 19, Leaf 21
- out.add(ParaGlueChars.SPACE); // Node 20, Leaf 22
- out.add(new ParaBoxChars("achieve")); // Node 21, Leaf 23
- out.add(ParaGlueChars.SPACE); // Node 22, Leaf 24
- out.add(greatness); // Node 23, Leaf 25 - 27
- out.add(new ParaBoxChars(",")); // Node 24, Leaf 28
- out.add(ParaGlueChars.SPACE); // Node 25, Leaf 29
- out.add(new ParaBoxChars("and")); // Node 26, Leaf 30
- out.add(ParaGlueChars.SPACE); // Node 27, Leaf 31
- out.add(new ParaBoxChars("some")); // Node 28, Leaf 32
- out.add(ParaGlueChars.SPACE); // Node 29, Leaf 33
- out.add(new ParaBoxChars("have")); // Node 30, Leaf 34
- out.add(ParaGlueChars.SPACE); // Node 31, Leaf 35
- out.add(greatness); // Node 32, Leaf 36 - 38
- out.add(ParaGlueChars.SPACE); // Node 33, Leaf 39
- out.add(new ParaBoxChars("thrust")); // Node 34, Leaf 40
- out.add(ParaGlueChars.SPACE); // Node 35, Leaf 41
- out.add(new ParaBoxChars("upon")); // Node 36, Leaf 42
- out.add(ParaGlueChars.SPACE); // Node 37, Leaf 43
- out.add(new ParaBoxChars("them.")); // Node 38, Leaf 44
+ /* Putting "Be" in a branch is unnecessary, but we with to test a branch as the first node. */
+ final ParaBranch4a nodeBe = new ParaBranch4a(config);
+ nodeBe.add(new ParaBoxChars("B"));
+ nodeBe.add(new ParaBoxChars("e"));
+ out.add(nodeBe); // Node 0, Leaf 0 - 1
+ out.add(ParaGlueChars.SPACE); // Node 1, Leaf 2
+ out.add(new ParaBoxChars("not")); // Node 2, Leaf 3
+ out.add(ParaGlueChars.SPACE); // Node 3, Leaf 4
+ out.add(new ParaBoxChars("afraid")); // Node 4, Leaf 5
+ out.add(ParaGlueChars.SPACE); // Node 5, Leaf 6
+ out.add(new ParaBoxChars("of")); // Node 6, Leaf 7
+ out.add(ParaGlueChars.SPACE); // Node 7, Leaf 8
+ out.add(nodeGreatness); // Node 8, Leaf 9 - 11
+ out.add(new ParaBoxChars(".")); // Node 9, Leaf 12
+ out.add(ParaGlueChars.SPACE); // Node 10, Leaf 13
+ out.add(new ParaBoxChars("Some")); // Node 11, Leaf 14
+ out.add(ParaGlueChars.SPACE); // Node 12, Leaf 15
+ out.add(new ParaBoxChars("are")); // Node 13, Leaf 16
+ out.add(ParaGlueChars.SPACE); // Node 14, Leaf 17
+ out.add(new ParaBoxChars("born")); // Node 15, Leaf 18
+ out.add(ParaGlueChars.SPACE); // Node 16, Leaf 19
+ out.add(new ParaBoxChars("great,")); // Node 17, Leaf 20
+ out.add(ParaGlueChars.SPACE); // Node 18, Leaf 21
+ out.add(new ParaBoxChars("some")); // Node 19, Leaf 22
+ out.add(ParaGlueChars.SPACE); // Node 20, Leaf 23
+ out.add(new ParaBoxChars("achieve")); // Node 21, Leaf 24
+ out.add(ParaGlueChars.SPACE); // Node 22, Leaf 25
+ out.add(nodeGreatness); // Node 23, Leaf 26 - 28
+ out.add(new ParaBoxChars(",")); // Node 24, Leaf 29
+ out.add(ParaGlueChars.SPACE); // Node 25, Leaf 30
+ out.add(new ParaBoxChars("and")); // Node 26, Leaf 31
+ out.add(ParaGlueChars.SPACE); // Node 27, Leaf 32
+ out.add(new ParaBoxChars("some")); // Node 28, Leaf 33
+ out.add(ParaGlueChars.SPACE); // Node 29, Leaf 34
+ out.add(new ParaBoxChars("have")); // Node 30, Leaf 35
+ out.add(ParaGlueChars.SPACE); // Node 31, Leaf 36
+ out.add(nodeGreatness); // Node 32, Leaf 37 - 39
+ out.add(ParaGlueChars.SPACE); // Node 33, Leaf 40
+ out.add(new ParaBoxChars("thrust")); // Node 34, Leaf 41
+ out.add(ParaGlueChars.SPACE); // Node 35, Leaf 42
+ out.add(new ParaBoxChars("upon")); // Node 36, Leaf 43
+ out.add(ParaGlueChars.SPACE); // Node 37, Leaf 44
- /* 39 lines, each adding one node. */
+ /* Putting "them." in a branch is unnecessary, but we with to test a branch as the last node. */
+ final ParaBranch4a nodeThem = new ParaBranch4a(config);
+ nodeThem.add(new ParaBoxChars("t"));
+ nodeThem.add(new ParaBoxChars("h"));
+ nodeThem.add(new ParaBoxChars("e"));
+ nodeThem.add(new ParaBoxChars("m"));
+ nodeThem.add(new ParaBoxChars("."));
+ out.add(nodeThem); // Node 38, Leaf 45 - 49
+
+ /* Test the /node/ count. */
Assert.assertEquals(39, out.paraNodeSize());
/* Test the /nodes/ at each end, and one in the middle. */
- Assert.assertEquals("Be", out.paraNodeAt(0).asParaLeaf().getText());
- Assert.assertEquals("them.", out.paraNodeAt(38).asParaLeaf().getText());
- Assert.assertEquals("born", out.paraNodeAt(15).asParaLeaf().getText());
+ Assert.assertEquals("Be", out.paraNodeAt(0).getText());
+ Assert.assertEquals("them.", out.paraNodeAt(38).getText());
+ Assert.assertEquals("born", out.paraNodeAt(15).getText());
/* Most nodes are exactly one leaf. 3 lines each add an additional 2 leaves each, adding 6 leaves. */
- Assert.assertEquals(45, out.paraLeafSize());
+ Assert.assertEquals(50, out.paraLeafSize());
/* Test the /leaves/ at each end. */
- Assert.assertEquals("Be", out.paraLeafAt(0).getText());
- Assert.assertEquals("them.", out.paraLeafAt(44).getText());
+ Assert.assertEquals("B", out.paraLeafAt(0).getText());
+ Assert.assertEquals("e", out.paraLeafAt(1).getText());
+ Assert.assertEquals(" ", out.paraLeafAt(2).getText());
+ Assert.assertEquals("not", out.paraLeafAt(3).getText());
+ Assert.assertEquals("upon", out.paraLeafAt(43).getText());
+ Assert.assertEquals(" ", out.paraLeafAt(44).getText());
+ Assert.assertEquals("t", out.paraLeafAt(45).getText());
+ Assert.assertEquals("h", out.paraLeafAt(46).getText());
+ Assert.assertEquals("e", out.paraLeafAt(47).getText());
+ Assert.assertEquals("m", out.paraLeafAt(48).getText());
+ Assert.assertEquals(".", out.paraLeafAt(49).getText());
- /* Make sure the nested branches can find their child nodes properly. */
- Assert.assertEquals("great", out.paraLeafAt(8).getText());
- Assert.assertEquals("-", out.paraLeafAt(9).getText());
- Assert.assertEquals("ness", out.paraLeafAt(10).getText());
+ /* Make sure other nested branches can find their child nodes properly. */
+ Assert.assertEquals("great", out.paraLeafAt(9).getText());
+ Assert.assertEquals("-", out.paraLeafAt(10).getText());
+ Assert.assertEquals("ness", out.paraLeafAt(11).getText());
- Assert.assertEquals("great", out.paraLeafAt(36).getText());
- Assert.assertEquals("-", out.paraLeafAt(37).getText());
- Assert.assertEquals("ness", out.paraLeafAt(38).getText());
+ Assert.assertEquals("great", out.paraLeafAt(37).getText());
+ Assert.assertEquals("-", out.paraLeafAt(38).getText());
+ Assert.assertEquals("ness", out.paraLeafAt(39).getText());
+
+ /* Test some internal leaves. */
+ Assert.assertEquals("afraid", out.paraLeafAt(5).getText());
+ Assert.assertEquals("achieve", out.paraLeafAt(24).getText());
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-11-28 01:19:20
|
Revision: 12144
http://sourceforge.net/p/foray/code/12144
Author: victormote
Date: 2021-11-28 01:19:17 +0000 (Sun, 28 Nov 2021)
Log Message:
-----------
Conform to aXSL change: Make all ParaNode implementations provide getText().
Modified Paths:
--------------
trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaBranch4a.java
trunk/foray/foray-common/src/test/java/org/foray/common/para/ParaBranch4aTests.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/SegmentDictionaryWord.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/StringWord.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/CapitalizedWord.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/ExactWord.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/LatinPlural1Word.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/LatinPlural2Word.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/LatinPossessive1Word.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/LatinPossessive2Word.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/SuffixedWord.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/UppercaseWord.java
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaBranch4a.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaBranch4a.java 2021-11-28 00:43:18 UTC (rev 12143)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaBranch4a.java 2021-11-28 01:19:17 UTC (rev 12144)
@@ -194,4 +194,14 @@
return null;
}
+ @Override
+ public CharSequence getText() {
+ final StringBuilder builder = new StringBuilder();
+ for (int leafIndex = 0; leafIndex < paraLeafSize(); leafIndex ++) {
+ final ParaLeaf leaf = paraLeafAt(leafIndex);
+ builder.append(leaf.getText());
+ }
+ return builder.toString();
+ }
+
}
Modified: trunk/foray/foray-common/src/test/java/org/foray/common/para/ParaBranch4aTests.java
===================================================================
--- trunk/foray/foray-common/src/test/java/org/foray/common/para/ParaBranch4aTests.java 2021-11-28 00:43:18 UTC (rev 12143)
+++ trunk/foray/foray-common/src/test/java/org/foray/common/para/ParaBranch4aTests.java 2021-11-28 01:19:17 UTC (rev 12144)
@@ -47,7 +47,7 @@
/*
* Be not afraid of greatness. Some are born great, some achieve greatness, and some have greatness thrust upon
* them.
- * -- William Shakespeare, "Twelfth Night"
+ * -- William Shakespeare, "Twelfth Night," Act II, Scene 5.
*/
final ParaConfig config = Mockito.mock(ParaConfig.class);
@@ -75,8 +75,8 @@
out.add(new ParaBoxChars("born")); // Node 15, Leaf 17
out.add(ParaGlueChars.SPACE); // Node 16, Leaf 18
out.add(new ParaBoxChars("great,")); // Node 17, Leaf 19
- out.add(ParaGlueChars.SPACE); // Node 28, Leaf 20
- out.add(new ParaBoxChars("some")); // Node 29, Leaf 21
+ out.add(ParaGlueChars.SPACE); // Node 18, Leaf 20
+ out.add(new ParaBoxChars("some")); // Node 19, Leaf 21
out.add(ParaGlueChars.SPACE); // Node 20, Leaf 22
out.add(new ParaBoxChars("achieve")); // Node 21, Leaf 23
out.add(ParaGlueChars.SPACE); // Node 22, Leaf 24
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/SegmentDictionaryWord.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/SegmentDictionaryWord.java 2021-11-28 00:43:18 UTC (rev 12143)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/SegmentDictionaryWord.java 2021-11-28 01:19:17 UTC (rev 12144)
@@ -133,4 +133,14 @@
return leafCount;
}
+ @Override
+ public CharSequence getText() {
+ final StringBuilder builder = new StringBuilder();
+ for (int index = 0; index < this.segments.length; index ++) {
+ final WordSegment segment = getWordSegment(index);
+ builder.append(segment.getText());
+ }
+ return builder.toString();
+ }
+
}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/StringWord.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/StringWord.java 2021-11-28 00:43:18 UTC (rev 12143)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/StringWord.java 2021-11-28 01:19:17 UTC (rev 12144)
@@ -159,4 +159,14 @@
return leafCount;
}
+ @Override
+ public CharSequence getText() {
+ final StringBuilder builder = new StringBuilder();
+ for (int index = 0; index < this.segments.length; index ++) {
+ final StringWordSegmentUtf16 segment = this.segments[index];
+ builder.append(segment.getText());
+ }
+ return builder.toString();
+ }
+
}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/CapitalizedWord.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/CapitalizedWord.java 2021-11-28 00:43:18 UTC (rev 12143)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/CapitalizedWord.java 2021-11-28 01:19:17 UTC (rev 12144)
@@ -116,4 +116,12 @@
return getWrappedWord().paraKpLeafSize();
}
+ @Override
+ public CharSequence getText() {
+ final StringBuilder builder = new StringBuilder();
+ builder.append(getWrappedWord().getActualContent());
+ builder.setCharAt(0, Character.toUpperCase(builder.charAt(0)));
+ return builder.toString();
+ }
+
}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/ExactWord.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/ExactWord.java 2021-11-28 00:43:18 UTC (rev 12143)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/ExactWord.java 2021-11-28 01:19:17 UTC (rev 12144)
@@ -99,4 +99,9 @@
return getWrappedWord().paraKpLeafSize();
}
+ @Override
+ public CharSequence getText() {
+ return getWrappedWord().getActualContent();
+ }
+
}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/LatinPlural1Word.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/LatinPlural1Word.java 2021-11-28 00:43:18 UTC (rev 12143)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/LatinPlural1Word.java 2021-11-28 01:19:17 UTC (rev 12144)
@@ -106,4 +106,9 @@
return getWrappedWord().paraKpLeafSize() + LatinPlural1Word.Segment.SIZE_DIFFERENCE;
}
+ @Override
+ public CharSequence getText() {
+ return this.getNormalizedContent() + Segment.WRAPPED_FORM;
+ }
+
}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/LatinPlural2Word.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/LatinPlural2Word.java 2021-11-28 00:43:18 UTC (rev 12143)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/LatinPlural2Word.java 2021-11-28 01:19:17 UTC (rev 12144)
@@ -109,4 +109,13 @@
return getWrappedWord().paraLeafSize() + LatinPlural2Word.Segment.SIZE_DIFFERENCE;
}
+ @Override
+ public CharSequence getText() {
+ final StringBuilder builder = new StringBuilder();
+ builder.append(getNormalizedContent());
+ builder.delete(builder.length() - 1, builder.length());
+ builder.append(Segment.WRAPPED_FORM);
+ return builder.toString();
+ }
+
}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/LatinPossessive1Word.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/LatinPossessive1Word.java 2021-11-28 00:43:18 UTC (rev 12143)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/LatinPossessive1Word.java 2021-11-28 01:19:17 UTC (rev 12144)
@@ -107,4 +107,9 @@
return getWrappedWord().paraKpLeafSize() + LatinPossessive1Word.Segment.SIZE_DIFFERENCE;
}
+ @Override
+ public CharSequence getText() {
+ return this.getNormalizedContent() + Segment.WRAPPED_FORM;
+ }
+
}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/LatinPossessive2Word.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/LatinPossessive2Word.java 2021-11-28 00:43:18 UTC (rev 12143)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/LatinPossessive2Word.java 2021-11-28 01:19:17 UTC (rev 12144)
@@ -107,4 +107,9 @@
return getWrappedWord().paraKpLeafSize() + LatinPossessive2Word.Segment.SIZE_DIFFERENCE;
}
+ @Override
+ public CharSequence getText() {
+ return this.getNormalizedContent() + Segment.WRAPPED_FORM;
+ }
+
}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/SuffixedWord.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/SuffixedWord.java 2021-11-28 00:43:18 UTC (rev 12143)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/SuffixedWord.java 2021-11-28 01:19:17 UTC (rev 12144)
@@ -73,4 +73,9 @@
*/
public abstract StringWordSegmentUtf16 getSuffix();
+ @Override
+ public CharSequence getText() {
+ return getWrappedWord().getText() + getSuffix().getText();
+ }
+
}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/UppercaseWord.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/UppercaseWord.java 2021-11-28 00:43:18 UTC (rev 12143)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/UppercaseWord.java 2021-11-28 01:19:17 UTC (rev 12144)
@@ -107,4 +107,9 @@
return getWrappedWord().paraKpLeafSize();
}
+ @Override
+ public CharSequence getText() {
+ return getWrappedWord().getActualContent().toString().toUpperCase();
+ }
+
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-11-28 00:43:21
|
Revision: 12143
http://sourceforge.net/p/foray/code/12143
Author: victormote
Date: 2021-11-28 00:43:18 +0000 (Sun, 28 Nov 2021)
Log Message:
-----------
Fix paraLeafAt(int). Enable related test assertions.
Modified Paths:
--------------
trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaBranch4a.java
trunk/foray/foray-common/src/test/java/org/foray/common/para/ParaBranch4aTests.java
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaBranch4a.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaBranch4a.java 2021-11-27 19:44:54 UTC (rev 12142)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaBranch4a.java 2021-11-28 00:43:18 UTC (rev 12143)
@@ -114,12 +114,15 @@
}
final int additionalLeaves = branch == null ? 1 : branch.paraLeafSize();
- runningLeafIndex += additionalLeaves;
+ final int newRunningLeafIndex = runningLeafIndex + additionalLeaves;
- if (runningLeafIndex > leafIndex) {
- final int relativeLeafIndex = runningLeafIndex - leafIndex;
+ if (newRunningLeafIndex > leafIndex) {
+ /* The leafIndex is a descendant of this node. */
+ final int relativeLeafIndex = leafIndex - runningLeafIndex;
return branch.paraLeafAt(relativeLeafIndex);
}
+
+ runningLeafIndex = newRunningLeafIndex;
}
throw new IndexOutOfBoundsException("Leaf index out of bounds: " + leafIndex);
}
Modified: trunk/foray/foray-common/src/test/java/org/foray/common/para/ParaBranch4aTests.java
===================================================================
--- trunk/foray/foray-common/src/test/java/org/foray/common/para/ParaBranch4aTests.java 2021-11-27 19:44:54 UTC (rev 12142)
+++ trunk/foray/foray-common/src/test/java/org/foray/common/para/ParaBranch4aTests.java 2021-11-28 00:43:18 UTC (rev 12143)
@@ -43,7 +43,7 @@
* Test of {@link ParaBranch4a#paraLeafAt(int)}.
*/
@Test
- public void test() {
+ public void paraLeafAtTest_001() {
/*
* Be not afraid of greatness. Some are born great, some achieve greatness, and some have greatness thrust upon
* them.
@@ -114,8 +114,12 @@
/* Make sure the nested branches can find their child nodes properly. */
Assert.assertEquals("great", out.paraLeafAt(8).getText());
-// Assert.assertEquals("-", out.paraLeafAt(9).getText());
-// Assert.assertEquals("ness", out.paraLeafAt(10).getText());
+ Assert.assertEquals("-", out.paraLeafAt(9).getText());
+ Assert.assertEquals("ness", out.paraLeafAt(10).getText());
+
+ Assert.assertEquals("great", out.paraLeafAt(36).getText());
+ Assert.assertEquals("-", out.paraLeafAt(37).getText());
+ Assert.assertEquals("ness", out.paraLeafAt(38).getText());
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-11-27 19:44:56
|
Revision: 12142
http://sourceforge.net/p/foray/code/12142
Author: victormote
Date: 2021-11-27 19:44:54 +0000 (Sat, 27 Nov 2021)
Log Message:
-----------
Add test class for "iteration" of ParaBranch4a.
Modified Paths:
--------------
trunk/foray/foray-common/build.gradle
trunk/foray/foray-common/src/main/java/org/foray/common/para/DiscretionaryHyphen4a.java
trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaGlueChars.java
Added Paths:
-----------
trunk/foray/foray-common/src/test/java/org/foray/common/para/
trunk/foray/foray-common/src/test/java/org/foray/common/para/ParaBranch4aTests.java
Modified: trunk/foray/foray-common/build.gradle
===================================================================
--- trunk/foray/foray-common/build.gradle 2021-11-27 14:56:10 UTC (rev 12141)
+++ trunk/foray/foray-common/build.gradle 2021-11-27 19:44:54 UTC (rev 12142)
@@ -15,6 +15,7 @@
implementation group: 'ch.qos.logback', name: 'logback-classic', version: logbackClassicVersion
testImplementation group: 'junit', name: 'junit', version: junitVersion
+ testImplementation group: 'org.mockito', name: 'mockito-core', version: mockitoVersion
}
javadoc {
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/para/DiscretionaryHyphen4a.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/para/DiscretionaryHyphen4a.java 2021-11-27 14:56:10 UTC (rev 12141)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/para/DiscretionaryHyphen4a.java 2021-11-27 19:44:54 UTC (rev 12142)
@@ -42,16 +42,25 @@
*/
public final class DiscretionaryHyphen4a extends ParaLeaf4a implements DiscretionaryHyphen {
+ /** Pre-built "acceptable" hyphenation point. */
+ public static final DiscretionaryHyphen4a ACCEPTABLE =
+ new DiscretionaryHyphen4a(DiscretionaryHyphen.Quality.ACCEPTABLE);
+
+ /** Pre-built "good" hyphenation point. */
+ public static final DiscretionaryHyphen4a GOOD =
+ new DiscretionaryHyphen4a(DiscretionaryHyphen.Quality.GOOD);
+
+ /** Pre-built "best" hyphenation point. */
+ public static final DiscretionaryHyphen4a BEST =
+ new DiscretionaryHyphen4a(DiscretionaryHyphen.Quality.BEST);
+
/** The array of pre-constructed instance, indexed by the numeric value of their quality minus 1. */
private static final DiscretionaryHyphen4a[] PRE_CONSTRUCTED_POINTS =
new DiscretionaryHyphen4a[DiscretionaryHyphen.Quality.values().length];
static {
- PRE_CONSTRUCTED_POINTS[DiscretionaryHyphen.Quality.ACCEPTABLE.getNumericValue() - 1] =
- new DiscretionaryHyphen4a(DiscretionaryHyphen.Quality.ACCEPTABLE);
- PRE_CONSTRUCTED_POINTS[DiscretionaryHyphen.Quality.GOOD.getNumericValue() - 1] =
- new DiscretionaryHyphen4a(DiscretionaryHyphen.Quality.GOOD);
- PRE_CONSTRUCTED_POINTS[DiscretionaryHyphen.Quality.BEST.getNumericValue() - 1] =
- new DiscretionaryHyphen4a(DiscretionaryHyphen.Quality.BEST);
+ PRE_CONSTRUCTED_POINTS[DiscretionaryHyphen.Quality.ACCEPTABLE.getNumericValue() - 1] = ACCEPTABLE;
+ PRE_CONSTRUCTED_POINTS[DiscretionaryHyphen.Quality.GOOD.getNumericValue() - 1] = GOOD;
+ PRE_CONSTRUCTED_POINTS[DiscretionaryHyphen.Quality.BEST.getNumericValue() - 1] = BEST;
}
/** The quality for this instance. */
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaGlueChars.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaGlueChars.java 2021-11-27 14:56:10 UTC (rev 12141)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaGlueChars.java 2021-11-27 19:44:54 UTC (rev 12142)
@@ -40,7 +40,10 @@
*/
public final class ParaGlueChars extends ParaLeaf4a implements ParaGlue {
- /** The char(s) for this penalty. */
+ /** Reusable glue item representing a single space character. */
+ public static final ParaGlueChars SPACE = new ParaGlueChars(" ");
+
+ /** The char(s) for this glue. */
private String chars;
/**
Added: trunk/foray/foray-common/src/test/java/org/foray/common/para/ParaBranch4aTests.java
===================================================================
--- trunk/foray/foray-common/src/test/java/org/foray/common/para/ParaBranch4aTests.java (rev 0)
+++ trunk/foray/foray-common/src/test/java/org/foray/common/para/ParaBranch4aTests.java 2021-11-27 19:44:54 UTC (rev 12142)
@@ -0,0 +1,121 @@
+/*
+ * Copyright 2021 The FOray Project.
+ * http://www.foray.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.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.common.para;
+
+import org.axsl.common.para.ParaConfig;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+/**
+ * Tests of {@Link ParaBranch4a}.
+ */
+public class ParaBranch4aTests {
+
+ /**
+ * Test of {@link ParaBranch4a#paraLeafAt(int)}.
+ */
+ @Test
+ public void test() {
+ /*
+ * Be not afraid of greatness. Some are born great, some achieve greatness, and some have greatness thrust upon
+ * them.
+ * -- William Shakespeare, "Twelfth Night"
+ */
+
+ final ParaConfig config = Mockito.mock(ParaConfig.class);
+ final ParaBranch4a out = new ParaBranch4a(config);
+ final ParaBranch4a greatness = new ParaBranch4a(config);
+ greatness.add(new ParaBoxChars("great"));
+ greatness.add(DiscretionaryHyphen4a.GOOD);
+ greatness.add(new ParaBoxChars("ness"));
+
+ out.add(new ParaBoxChars("Be")); // Node 0, Leaf 0
+ out.add(ParaGlueChars.SPACE); // Node 1, Leaf 1
+ out.add(new ParaBoxChars("not")); // Node 2, Leaf 2
+ out.add(ParaGlueChars.SPACE); // Node 3, Leaf 3
+ out.add(new ParaBoxChars("afraid")); // Node 4, Leaf 4
+ out.add(ParaGlueChars.SPACE); // Node 5, Leaf 5
+ out.add(new ParaBoxChars("of")); // Node 6, Leaf 6
+ out.add(ParaGlueChars.SPACE); // Node 7, Leaf 7
+ out.add(greatness); // Node 8, Leaf 8 - 10
+ out.add(new ParaBoxChars(".")); // Node 9, Leaf 11
+ out.add(ParaGlueChars.SPACE); // Node 10, Leaf 12
+ out.add(new ParaBoxChars("Some")); // Node 11, Leaf 13
+ out.add(ParaGlueChars.SPACE); // Node 12, Leaf 14
+ out.add(new ParaBoxChars("are")); // Node 13, Leaf 15
+ out.add(ParaGlueChars.SPACE); // Node 14, Leaf 16
+ out.add(new ParaBoxChars("born")); // Node 15, Leaf 17
+ out.add(ParaGlueChars.SPACE); // Node 16, Leaf 18
+ out.add(new ParaBoxChars("great,")); // Node 17, Leaf 19
+ out.add(ParaGlueChars.SPACE); // Node 28, Leaf 20
+ out.add(new ParaBoxChars("some")); // Node 29, Leaf 21
+ out.add(ParaGlueChars.SPACE); // Node 20, Leaf 22
+ out.add(new ParaBoxChars("achieve")); // Node 21, Leaf 23
+ out.add(ParaGlueChars.SPACE); // Node 22, Leaf 24
+ out.add(greatness); // Node 23, Leaf 25 - 27
+ out.add(new ParaBoxChars(",")); // Node 24, Leaf 28
+ out.add(ParaGlueChars.SPACE); // Node 25, Leaf 29
+ out.add(new ParaBoxChars("and")); // Node 26, Leaf 30
+ out.add(ParaGlueChars.SPACE); // Node 27, Leaf 31
+ out.add(new ParaBoxChars("some")); // Node 28, Leaf 32
+ out.add(ParaGlueChars.SPACE); // Node 29, Leaf 33
+ out.add(new ParaBoxChars("have")); // Node 30, Leaf 34
+ out.add(ParaGlueChars.SPACE); // Node 31, Leaf 35
+ out.add(greatness); // Node 32, Leaf 36 - 38
+ out.add(ParaGlueChars.SPACE); // Node 33, Leaf 39
+ out.add(new ParaBoxChars("thrust")); // Node 34, Leaf 40
+ out.add(ParaGlueChars.SPACE); // Node 35, Leaf 41
+ out.add(new ParaBoxChars("upon")); // Node 36, Leaf 42
+ out.add(ParaGlueChars.SPACE); // Node 37, Leaf 43
+ out.add(new ParaBoxChars("them.")); // Node 38, Leaf 44
+
+ /* 39 lines, each adding one node. */
+ Assert.assertEquals(39, out.paraNodeSize());
+
+ /* Test the /nodes/ at each end, and one in the middle. */
+ Assert.assertEquals("Be", out.paraNodeAt(0).asParaLeaf().getText());
+ Assert.assertEquals("them.", out.paraNodeAt(38).asParaLeaf().getText());
+ Assert.assertEquals("born", out.paraNodeAt(15).asParaLeaf().getText());
+
+ /* Most nodes are exactly one leaf. 3 lines each add an additional 2 leaves each, adding 6 leaves. */
+ Assert.assertEquals(45, out.paraLeafSize());
+
+ /* Test the /leaves/ at each end. */
+ Assert.assertEquals("Be", out.paraLeafAt(0).getText());
+ Assert.assertEquals("them.", out.paraLeafAt(44).getText());
+
+ /* Make sure the nested branches can find their child nodes properly. */
+ Assert.assertEquals("great", out.paraLeafAt(8).getText());
+// Assert.assertEquals("-", out.paraLeafAt(9).getText());
+// Assert.assertEquals("ness", out.paraLeafAt(10).getText());
+ }
+
+}
Property changes on: trunk/foray/foray-common/src/test/java/org/foray/common/para/ParaBranch4aTests.java
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Rev
\ No newline at end of property
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-11-27 14:56:13
|
Revision: 12141
http://sourceforge.net/p/foray/code/12141
Author: victormote
Date: 2021-11-27 14:56:10 +0000 (Sat, 27 Nov 2021)
Log Message:
-----------
Separate the building of the various test components.
Modified Paths:
--------------
trunk/foray/foray-linebreak/src/main/java/org/foray/linebreak/BestFitLb.java
trunk/foray/foray-linebreak/src/main/java/org/foray/linebreak/FirstFitLb.java
trunk/foray/foray-linebreak/src/main/java/org/foray/linebreak/TotalFitLb.java
trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/FirstFitLbTests.java
trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/LineBreaker4aTests.java
trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/TotalFitLbTests.java
Modified: trunk/foray/foray-linebreak/src/main/java/org/foray/linebreak/BestFitLb.java
===================================================================
--- trunk/foray/foray-linebreak/src/main/java/org/foray/linebreak/BestFitLb.java 2021-11-27 14:15:19 UTC (rev 12140)
+++ trunk/foray/foray-linebreak/src/main/java/org/foray/linebreak/BestFitLb.java 2021-11-27 14:56:10 UTC (rev 12141)
@@ -41,7 +41,7 @@
@Override
public int[] breakIntoLines(final ParaBranch paragraph, final ParaControl paraControl,
final LineBreakControl lbControl) {
- return null;
+ return new int[0];
}
}
Modified: trunk/foray/foray-linebreak/src/main/java/org/foray/linebreak/FirstFitLb.java
===================================================================
--- trunk/foray/foray-linebreak/src/main/java/org/foray/linebreak/FirstFitLb.java 2021-11-27 14:15:19 UTC (rev 12140)
+++ trunk/foray/foray-linebreak/src/main/java/org/foray/linebreak/FirstFitLb.java 2021-11-27 14:56:10 UTC (rev 12141)
@@ -33,7 +33,7 @@
import org.axsl.linebreak.LineBreakControl;
/**
- * Implementation of the Knuth-Plass first-fit linebreaking algorithm.
+ * Implementation of the Knuth-Plass "first-fit" linebreaking algorithm.
* @see "Knuth, Digital Typography, 1999, pp. 74, 78"
*/
public class FirstFitLb extends LineBreaker4a {
@@ -41,7 +41,7 @@
@Override
public int[] breakIntoLines(final ParaBranch paragraph, final ParaControl paraControl,
final LineBreakControl lbControl) {
- return null;
+ return new int[0];
}
}
Modified: trunk/foray/foray-linebreak/src/main/java/org/foray/linebreak/TotalFitLb.java
===================================================================
--- trunk/foray/foray-linebreak/src/main/java/org/foray/linebreak/TotalFitLb.java 2021-11-27 14:15:19 UTC (rev 12140)
+++ trunk/foray/foray-linebreak/src/main/java/org/foray/linebreak/TotalFitLb.java 2021-11-27 14:56:10 UTC (rev 12141)
@@ -51,7 +51,7 @@
import java.util.Stack;
/**
- * Implementation of the Knuth-Plass total-fit linebreaking algorithm.
+ * Implementation of the Knuth-Plass "total-fit" linebreaking algorithm.
* @see "Knuth, Digital Typography, 1999, p. 116"
*/
public class TotalFitLb extends LineBreaker4a {
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-27 14:15:19 UTC (rev 12140)
+++ trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/FirstFitLbTests.java 2021-11-27 14:56:10 UTC (rev 12141)
@@ -30,17 +30,14 @@
import org.foray.common.para.ParaBranch4a;
-import org.axsl.common.para.DiscretionaryHyphen;
import org.axsl.common.para.ParaControl;
import org.axsl.linebreak.LineBreakControl;
-import org.axsl.linebreak.OutputLine;
import org.junit.Assert;
import org.junit.Test;
-import org.mockito.Mockito;
/**
- * Tests of {@link TotalFitLb}.
+ * Tests of {@link FirstFitLb}.
*/
public class FirstFitLbTests extends LineBreaker4aTests {
@@ -48,24 +45,18 @@
* A test.
*/
@Test
- public void bestFitTest1() {
+ public void firstFitTest1() {
/* TODO: THE CLASS BEING TESTED IS VERY INCOMPLETE, AND SO IS THIS TEST !!!!!! */
- final ParaBranch4a content = this.createPara();
- final LineBreakControl lbControl = Mockito.mock(LineBreakControl.class);
- final OutputLine lineOutput = Mockito.mock(OutputLine.class);
- /* Page is 8.5 inches wide, 1 inch margin on both ends, leaving 6.5 inches, or 468,000 millipoints. */
- Mockito.when(lineOutput.capacityTotal()).thenReturn(468000);
- Mockito.when(lbControl.getOutputLine(Mockito.anyInt())).thenReturn(lineOutput);
- final ParaControl paraControl = Mockito.mock(ParaControl.class);
- Mockito.when(paraControl.getCost(Mockito.any(DiscretionaryHyphen.Quality.class))).thenReturn(50);
- final TotalFitLb out = new TotalFitLb();
- final int[] actual = out.breakIntoLines(content, paraControl, lbControl);
+ final ParaBranch4a para = this.createPara();
+ para.setParaConfig(createMonotypeParaConfig());
+ final ParaControl paraControl = createParaControl();
+ final LineBreakControl lbControl = createLineBreakControl();
+ final FirstFitLb out = new FirstFitLb();
+ final int[] actual = out.breakIntoLines(para, paraControl, lbControl);
final int[] expected = new int[0];
-//// final int[] expectedArray = {};
-//// expected.add(new OrderedTreePath4a(new IntArray(expectedArray)));
Assert.assertArrayEquals(expected, actual);
}
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-27 14:15:19 UTC (rev 12140)
+++ trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/LineBreaker4aTests.java 2021-11-27 14:56:10 UTC (rev 12141)
@@ -35,9 +35,12 @@
import org.foray.common.para.ParaPenalty4a;
import org.foray.orthography.Punctuation4a;
-import org.axsl.common.para.ParaConfig;
+import org.axsl.common.para.DiscretionaryHyphen;
+import org.axsl.common.para.ParaControl;
import org.axsl.font.Font;
import org.axsl.font.FontUse;
+import org.axsl.linebreak.LineBreakControl;
+import org.axsl.linebreak.OutputLine;
import org.junit.Assert;
import org.mockito.Mockito;
@@ -202,12 +205,6 @@
para.add(ParaGlue4a.FINISHING_GLUE); // 275 1
para.add(ParaPenalty4a.FORCED_BREAK); // 276 1
- final Font font = LbTestUtilities.createMonotypeFont();
- final FontUse fontUse = Mockito.mock(FontUse.class);
- Mockito.when(fontUse.getFont()).thenReturn(font);
- final ParaConfig paraConfig = new ParaConfig4a(fontUse, 10, null, 0, 0);
- para.setParaConfig(paraConfig);
-
/* The tokenized text treated "’s" as part of the attached word.
* The compound word "lime-tree" was treated as two words divided by punctuation.
* There are 131 lines of code creating the para.
@@ -242,4 +239,39 @@
return para;
}
+ /**
+ * Create a standard paragraph configuration using the Monotype pseudo-font.
+ * @return The Monotype paragraph configuration.
+ */
+ public ParaConfig4a createMonotypeParaConfig() {
+ final Font font = LbTestUtilities.createMonotypeFont();
+ final FontUse fontUse = Mockito.mock(FontUse.class);
+ Mockito.when(fontUse.getFont()).thenReturn(font);
+ final ParaConfig4a paraConfig = new ParaConfig4a(fontUse, 10, null, 0, 0);
+ return paraConfig;
+ }
+
+ /**
+ * Creates a standard line break control, used for testing.
+ * @return A link break control for testing.
+ */
+ public LineBreakControl createLineBreakControl() {
+ final LineBreakControl lbControl = Mockito.mock(LineBreakControl.class);
+ final OutputLine lineOutput = Mockito.mock(OutputLine.class);
+ /* Page is 8.5 inches wide, 1 inch margin on both ends, leaving 6.5 inches, or 468,000 millipoints. */
+ Mockito.when(lineOutput.capacityTotal()).thenReturn(468000);
+ Mockito.when(lbControl.getOutputLine(Mockito.anyInt())).thenReturn(lineOutput);
+ return lbControl;
+ }
+
+ /**
+ * Creates a standard paragraph control, used for testing.
+ * @return A paragraph control for testing.
+ */
+ public ParaControl createParaControl() {
+ final ParaControl paraControl = Mockito.mock(ParaControl.class);
+ Mockito.when(paraControl.getCost(Mockito.any(DiscretionaryHyphen.Quality.class))).thenReturn(50);
+ return paraControl;
+ }
+
}
Modified: trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/TotalFitLbTests.java
===================================================================
--- trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/TotalFitLbTests.java 2021-11-27 14:15:19 UTC (rev 12140)
+++ trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/TotalFitLbTests.java 2021-11-27 14:56:10 UTC (rev 12141)
@@ -30,14 +30,11 @@
import org.foray.common.para.ParaBranch4a;
-import org.axsl.common.para.DiscretionaryHyphen;
import org.axsl.common.para.ParaControl;
import org.axsl.linebreak.LineBreakControl;
-import org.axsl.linebreak.OutputLine;
import org.junit.Assert;
import org.junit.Test;
-import org.mockito.Mockito;
/**
* Tests of {@link TotalFitLb}.
@@ -48,24 +45,18 @@
* A test.
*/
@Test
- public void bestFitTest1() {
+ public void totalFitTest1() {
/* TODO: THE CLASS BEING TESTED IS VERY INCOMPLETE, AND SO IS THIS TEST !!!!!! */
- final ParaBranch4a content = this.createPara();
- final LineBreakControl lbControl = Mockito.mock(LineBreakControl.class);
- final OutputLine lineOutput = Mockito.mock(OutputLine.class);
- /* Page is 8.5 inches wide, 1 inch margin on both ends, leaving 6.5 inches, or 468,000 millipoints. */
- Mockito.when(lineOutput.capacityTotal()).thenReturn(468000);
- Mockito.when(lbControl.getOutputLine(Mockito.anyInt())).thenReturn(lineOutput);
- final ParaControl paraControl = Mockito.mock(ParaControl.class);
- Mockito.when(paraControl.getCost(Mockito.any(DiscretionaryHyphen.Quality.class))).thenReturn(50);
+ final ParaBranch4a para = this.createPara();
+ para.setParaConfig(createMonotypeParaConfig());
+ final ParaControl paraControl = createParaControl();
+ final LineBreakControl lbControl = createLineBreakControl();
+
final TotalFitLb out = new TotalFitLb();
- final int[] actual = out.breakIntoLines(content, paraControl, lbControl);
+ final int[] actual = out.breakIntoLines(para, paraControl, lbControl);
-
final int[] expected = new int[0];
-//// final int[] expectedArray = {};
-//// expected.add(new OrderedTreePath4a(new IntArray(expectedArray)));
Assert.assertArrayEquals(expected, actual);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-11-27 14:15:22
|
Revision: 12140
http://sourceforge.net/p/foray/code/12140
Author: victormote
Date: 2021-11-27 14:15:19 +0000 (Sat, 27 Nov 2021)
Log Message:
-----------
Add comments containing the leaf node index.
Modified Paths:
--------------
trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/LineBreaker4aTests.java
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-27 13:10:00 UTC (rev 12139)
+++ trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/LineBreaker4aTests.java 2021-11-27 14:15:19 UTC (rev 12140)
@@ -67,137 +67,140 @@
*/
public ParaBranch4a createPara() {
final ParaBranch4aTestFixture para = new ParaBranch4aTestFixture(null, '-');
- para.add(new ParaBox4a(18)); // Empty box for indentation
- para.addWordAndSpace("In");
- para.addWordAndSpace("olden");
- para.addWordAndSpace("times");
- para.addWordAndSpace("when");
- para.addWordAndSpace("wish-ing"); // 2 segments
- para.addWordAndSpace("still");
- para.addWordAndSpace("helped");
- para.addWord("one");
- para.addNodeAndSpace(Punctuation4a.COMMA);
- para.addWordAndSpace("there");
- para.addWordAndSpace("lived");
- para.addWordAndSpace("a");
- para.addWordAndSpace("king");
- para.addWordAndSpace("whose");
- para.addWordAndSpace("daugh-ters"); // 2 segments
- para.addWordAndSpace("were");
- para.addWordAndSpace("all");
- para.addWord("beau-ti-ful"); // 3 segments
- para.addNodeAndSpace(Punctuation4a.SEMICOLON);
- para.addWordAndSpace("and");
- para.addWordAndSpace("the");
- para.addWordAndSpace("young-est"); // 2 segments
- para.addWordAndSpace("was");
- para.addWordAndSpace("so");
- para.addWordAndSpace("beau-ti-ful"); // 3 segments
- para.addWordAndSpace("that");
- para.addWordAndSpace("the");
- para.addWordAndSpace("sun");
- para.addWord("it-self"); // 2 segments
- para.addNodeAndSpace(Punctuation4a.COMMA);
- para.addWordAndSpace("which");
- para.addWordAndSpace("has");
- para.addWordAndSpace("seen");
- para.addWordAndSpace("so");
- para.addWord("much");
- para.addNodeAndSpace(Punctuation4a.COMMA);
- para.addWordAndSpace("was");
- para.addWordAndSpace("aston-ished"); // 2 segments
- para.addWordAndSpace("when-ever"); // 2 segments
- para.addWordAndSpace("it");
- para.addWordAndSpace("shone");
- para.addWordAndSpace("in");
- para.addWordAndSpace("her");
- para.addWord("face");
- para.addNodeAndSpace(Punctuation4a.PERIOD);
- para.addWordAndSpace("Close");
- para.addWordAndSpace("by");
- para.addWordAndSpace("the");
- para.addWordAndSpace("king’s");
- para.addWordAndSpace("castle");
- para.addWordAndSpace("lay");
- para.addWordAndSpace("a");
- para.addWordAndSpace("great");
- para.addWordAndSpace("dark");
- para.addWord("for-est"); // 2 segments
- para.addNodeAndSpace(Punctuation4a.COMMA);
- para.addWordAndSpace("and");
- para.addWordAndSpace("un-der"); // 2 segments
- para.addWordAndSpace("an");
- para.addWordAndSpace("old");
- para.addWord("lime");
- para.add(Punctuation4a.MANDATORY_HYPHEN);
- para.add(new ParaPenalty4a(0, 50, true));
- para.addWordAndSpace("tree");
- para.addWordAndSpace("in");
- para.addWordAndSpace("the");
- para.addWordAndSpace("for-est"); // 2 segments
- para.addWordAndSpace("was");
- para.addWordAndSpace("a");
- para.addWord("well");
- para.addNodeAndSpace(Punctuation4a.COMMA);
- para.addWordAndSpace("and");
- para.addWordAndSpace("when");
- para.addWordAndSpace("the");
- para.addWordAndSpace("day");
- para.addWordAndSpace("was");
- para.addWordAndSpace("very");
- para.addWord("warm");
- para.addNodeAndSpace(Punctuation4a.COMMA);
- para.addWordAndSpace("the");
- para.addWordAndSpace("king’s");
- para.addWordAndSpace("child");
- para.addWordAndSpace("went");
- para.addWordAndSpace("out");
- para.addWordAndSpace("into");
- para.addWordAndSpace("the");
- para.addWordAndSpace("for-est"); // 2 segments
- para.addWordAndSpace("and");
- para.addWordAndSpace("sat");
- para.addWordAndSpace("down");
- para.addWordAndSpace("by");
- para.addWordAndSpace("the");
- para.addWordAndSpace("side");
- para.addWordAndSpace("of");
- para.addWordAndSpace("the");
- para.addWordAndSpace("cool");
- para.addWord("foun-tain"); // 2 segments
- para.addNodeAndSpace(Punctuation4a.SEMICOLON);
- para.addWordAndSpace("and");
- para.addWordAndSpace("when");
- para.addWordAndSpace("she");
- para.addWordAndSpace("was");
- para.addWordAndSpace("bored");
- para.addWordAndSpace("she");
- para.addWordAndSpace("took");
- para.addWordAndSpace("a");
- para.addWordAndSpace("golden");
- para.addWord("ball");
- para.addNodeAndSpace(Punctuation4a.COMMA);
- para.addWordAndSpace("and");
- para.addWordAndSpace("threw");
- para.addWordAndSpace("it");
- para.addWordAndSpace("up");
- para.addWordAndSpace("on");
- para.addWordAndSpace("high");
- para.addWordAndSpace("and");
- para.addWordAndSpace("caught");
- para.addWord("it");
- para.addNodeAndSpace(Punctuation4a.SEMICOLON);
- para.addWordAndSpace("and");
- para.addWordAndSpace("this");
- para.addWordAndSpace("ball");
- para.addWordAndSpace("was");
- para.addWordAndSpace("her");
- para.addWordAndSpace("favor-ite"); // 2 segments
- para.addWord("play-thing"); // 2 segments
- para.add(Punctuation4a.PERIOD);
- para.add(ParaPenalty4a.DISALLOWED_BREAK);
- para.add(ParaGlue4a.FINISHING_GLUE);
- para.add(ParaPenalty4a.FORCED_BREAK);
+// Leaf Qty
+// Index Leaves
+// ------ ------
+ para.add(new ParaBox4a(18)); // Empty box (indent) 0 1
+ para.addWordAndSpace("In"); // 1 2
+ para.addWordAndSpace("olden"); // 3 2
+ para.addWordAndSpace("times"); // 5 2
+ para.addWordAndSpace("when"); // 7 2
+ para.addWordAndSpace("wish-ing"); // 2 segments 9 4
+ para.addWordAndSpace("still"); // 13 2
+ para.addWordAndSpace("helped"); // 15 2
+ para.addWord("one"); // 17 1
+ para.addNodeAndSpace(Punctuation4a.COMMA); // 18 2
+ para.addWordAndSpace("there"); // 20 2
+ para.addWordAndSpace("lived"); // 22 2
+ para.addWordAndSpace("a"); // 24 2
+ para.addWordAndSpace("king"); // 26 2
+ para.addWordAndSpace("whose"); // 28 2
+ para.addWordAndSpace("daugh-ters"); // 2 segments 30 4
+ para.addWordAndSpace("were"); // 34 2
+ para.addWordAndSpace("all"); // 36 2
+ para.addWord("beau-ti-ful"); // 3 segments 38 5
+ para.addNodeAndSpace(Punctuation4a.SEMICOLON); // 43 2
+ para.addWordAndSpace("and"); // 45 2
+ para.addWordAndSpace("the"); // 47 2
+ para.addWordAndSpace("young-est"); // 2 segments 49 4
+ para.addWordAndSpace("was"); // 53 2
+ para.addWordAndSpace("so"); // 55 2
+ para.addWordAndSpace("beau-ti-ful"); // 3 segments 57 6
+ para.addWordAndSpace("that"); // 63 2
+ para.addWordAndSpace("the"); // 65 2
+ para.addWordAndSpace("sun"); // 67 2
+ para.addWord("it-self"); // 2 segments 69 3
+ para.addNodeAndSpace(Punctuation4a.COMMA); // 72 2
+ para.addWordAndSpace("which"); // 74 2
+ para.addWordAndSpace("has"); // 76 2
+ para.addWordAndSpace("seen"); // 78 2
+ para.addWordAndSpace("so"); // 80 2
+ para.addWord("much"); // 82 1
+ para.addNodeAndSpace(Punctuation4a.COMMA); // 83 2
+ para.addWordAndSpace("was"); // 85 2
+ para.addWordAndSpace("aston-ished"); // 2 segments 87 4
+ para.addWordAndSpace("when-ever"); // 2 segments 91 4
+ para.addWordAndSpace("it"); // 95 2
+ para.addWordAndSpace("shone"); // 97 2
+ para.addWordAndSpace("in"); // 99 2
+ para.addWordAndSpace("her"); // 101 2
+ para.addWord("face"); // 103 1
+ para.addNodeAndSpace(Punctuation4a.PERIOD); // 104 2
+ para.addWordAndSpace("Close"); // 106 2
+ para.addWordAndSpace("by"); // 108 2
+ para.addWordAndSpace("the"); // 110 2
+ para.addWordAndSpace("king’s"); // 112 2
+ para.addWordAndSpace("castle"); // 114 2
+ para.addWordAndSpace("lay"); // 116 2
+ para.addWordAndSpace("a"); // 118 2
+ para.addWordAndSpace("great"); // 120 2
+ para.addWordAndSpace("dark"); // 122 2
+ para.addWord("for-est"); // 2 segments 124 3
+ para.addNodeAndSpace(Punctuation4a.COMMA); // 127 2
+ para.addWordAndSpace("and"); // 129 2
+ para.addWordAndSpace("un-der"); // 2 segments 131 4
+ para.addWordAndSpace("an"); // 135 2
+ para.addWordAndSpace("old"); // 137 2
+ para.addWord("lime"); // 139 1
+ para.add(Punctuation4a.MANDATORY_HYPHEN); // 140 1
+ para.add(new ParaPenalty4a(0, 50, true)); // 141 1
+ para.addWordAndSpace("tree"); // 142 2
+ para.addWordAndSpace("in"); // 144 2
+ para.addWordAndSpace("the"); // 146 2
+ para.addWordAndSpace("for-est"); // 2 segments 148 4
+ para.addWordAndSpace("was"); // 152 2
+ para.addWordAndSpace("a"); // 154 2
+ para.addWord("well"); // 156 1
+ para.addNodeAndSpace(Punctuation4a.COMMA); // 157 2
+ para.addWordAndSpace("and"); // 159 2
+ para.addWordAndSpace("when"); // 161 2
+ para.addWordAndSpace("the"); // 163 2
+ para.addWordAndSpace("day"); // 165 2
+ para.addWordAndSpace("was"); // 167 2
+ para.addWordAndSpace("very"); // 169 2
+ para.addWord("warm"); // 171 1
+ para.addNodeAndSpace(Punctuation4a.COMMA); // 172 2
+ para.addWordAndSpace("the"); // 174 2
+ para.addWordAndSpace("king’s"); // 176 2
+ para.addWordAndSpace("child"); // 178 2
+ para.addWordAndSpace("went"); // 180 2
+ para.addWordAndSpace("out"); // 182 2
+ para.addWordAndSpace("into"); // 184 2
+ para.addWordAndSpace("the"); // 186 2
+ para.addWordAndSpace("for-est"); // 2 segments 188 4
+ para.addWordAndSpace("and"); // 192 2
+ para.addWordAndSpace("sat"); // 194 2
+ para.addWordAndSpace("down"); // 196 2
+ para.addWordAndSpace("by"); // 198 2
+ para.addWordAndSpace("the"); // 200 2
+ para.addWordAndSpace("side"); // 202 2
+ para.addWordAndSpace("of"); // 204 2
+ para.addWordAndSpace("the"); // 206 2
+ para.addWordAndSpace("cool"); // 208 2
+ para.addWord("foun-tain"); // 2 segments 210 3
+ para.addNodeAndSpace(Punctuation4a.SEMICOLON); // 213 2
+ para.addWordAndSpace("and"); // 215 2
+ para.addWordAndSpace("when"); // 217 2
+ para.addWordAndSpace("she"); // 219 2
+ para.addWordAndSpace("was"); // 221 2
+ para.addWordAndSpace("bored"); // 223 2
+ para.addWordAndSpace("she"); // 225 2
+ para.addWordAndSpace("took"); // 227 2
+ para.addWordAndSpace("a"); // 229 2
+ para.addWordAndSpace("golden"); // 231 2
+ para.addWord("ball"); // 233 1
+ para.addNodeAndSpace(Punctuation4a.COMMA); // 234 2
+ para.addWordAndSpace("and"); // 236 2
+ para.addWordAndSpace("threw"); // 238 2
+ para.addWordAndSpace("it"); // 240 2
+ para.addWordAndSpace("up"); // 242 2
+ para.addWordAndSpace("on"); // 244 2
+ para.addWordAndSpace("high"); // 246 2
+ para.addWordAndSpace("and"); // 248 2
+ para.addWordAndSpace("caught"); // 250 2
+ para.addWord("it"); // 252 1
+ para.addNodeAndSpace(Punctuation4a.SEMICOLON); // 253 2
+ para.addWordAndSpace("and"); // 255 2
+ para.addWordAndSpace("this"); // 257 2
+ para.addWordAndSpace("ball"); // 259 2
+ para.addWordAndSpace("was"); // 261 2
+ para.addWordAndSpace("her"); // 263 2
+ para.addWordAndSpace("favor-ite"); // 2 segments 265 4
+ para.addWord("play-thing"); // 2 segments 269 4
+ para.add(Punctuation4a.PERIOD); // 273 1
+ para.add(ParaPenalty4a.DISALLOWED_BREAK); // 274 1
+ para.add(ParaGlue4a.FINISHING_GLUE); // 275 1
+ para.add(ParaPenalty4a.FORCED_BREAK); // 276 1
final Font font = LbTestUtilities.createMonotypeFont();
final FontUse fontUse = Mockito.mock(FontUse.class);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-11-27 13:10:02
|
Revision: 12139
http://sourceforge.net/p/foray/code/12139
Author: victormote
Date: 2021-11-27 13:10:00 +0000 (Sat, 27 Nov 2021)
Log Message:
-----------
Rough-in logic for finding leaf descendants.
Modified Paths:
--------------
trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaBranch4a.java
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaBranch4a.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaBranch4a.java 2021-11-26 22:08:21 UTC (rev 12138)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaBranch4a.java 2021-11-27 13:10:00 UTC (rev 12139)
@@ -98,9 +98,30 @@
}
@Override
- public ParaLeaf paraLeafAt(final int index) {
- // TODO Auto-generated method stub
- return null;
+ public ParaLeaf paraLeafAt(final int leafIndex) {
+ int runningLeafIndex = 0;
+ for (int nodeIndex = 0; nodeIndex < this.nodes.size(); nodeIndex ++) {
+ final ParaNode node = this.nodes.get(nodeIndex);
+ final ParaBranch branch = node.asParaBranch();
+ final ParaLeaf leaf = node.asParaLeaf();
+
+ if (runningLeafIndex == leafIndex) {
+ if (leaf != null) {
+ return leaf;
+ } else {
+ return branch.paraLeafAt(0);
+ }
+ }
+
+ final int additionalLeaves = branch == null ? 1 : branch.paraLeafSize();
+ runningLeafIndex += additionalLeaves;
+
+ if (runningLeafIndex > leafIndex) {
+ final int relativeLeafIndex = runningLeafIndex - leafIndex;
+ return branch.paraLeafAt(relativeLeafIndex);
+ }
+ }
+ throw new IndexOutOfBoundsException("Leaf index out of bounds: " + leafIndex);
}
/**
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-11-26 22:08:24
|
Revision: 12138
http://sourceforge.net/p/foray/code/12138
Author: victormote
Date: 2021-11-26 22:08:21 +0000 (Fri, 26 Nov 2021)
Log Message:
-----------
Add class to dump laid-out paragraph content, to assist in visualizing the computed line breaks.
Modified Paths:
--------------
trunk/foray/foray-common/src/main/java/org/foray/common/primitive/NumberUtils.java
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/IntArray.java
Added Paths:
-----------
trunk/foray/foray-common/src/test/java/org/foray/common/primitive/NumberUtilsTests.java
trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/util/DumpLayout.java
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/primitive/NumberUtils.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/primitive/NumberUtils.java 2021-11-26 19:38:20 UTC (rev 12137)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/primitive/NumberUtils.java 2021-11-26 22:08:21 UTC (rev 12138)
@@ -28,11 +28,17 @@
package org.foray.common.primitive;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
/**
* Utility class for numeric computations not handled in standard classes.
*/
public final class NumberUtils {
+ /** Regex pattern for detecting and parsing string representation of an integer array. */
+ private static final Pattern INT_ARRAY_PATTERN = Pattern.compile("^\\[\\s*[0-9]+(\\s*,\\s*[0-9]+)*\\s*\\]$");
+
/**
* Private Constructor. This class is a utility class and should never be instantiated.
*/
@@ -72,4 +78,29 @@
return digitCount > 0;
}
+ /**
+ * Converts a string representation of an integer array into an int[].
+ * @param chars A string representation of an integer array.
+ * Example 1: "[3,13,39]".
+ * Example 2: "[ 3, 13, 39 ]".
+ * @return The integer array for the input chars, or null if that chars to do not match an int array pattern.
+ */
+ public static int[] intArrayFromString(final CharSequence chars) {
+ final Matcher matcher = INT_ARRAY_PATTERN.matcher(chars);
+ if (! matcher.matches()) {
+ return null;
+ }
+ final String[] strings = chars.toString()
+ .replace("[", StringUtils.EMPTY_STRING)
+ .replaceAll("]", StringUtils.EMPTY_STRING)
+ .replaceAll(" ", "")
+ .split(",");
+ final int[] returnValue = new int[strings.length];
+ for (int index = 0; index < strings.length; index ++) {
+ final int element = Integer.parseInt(strings[index]);
+ returnValue[index] = element;
+ }
+ return returnValue;
+ }
+
}
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/sequence/IntArray.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/sequence/IntArray.java 2021-11-26 19:38:20 UTC (rev 12137)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/IntArray.java 2021-11-26 22:08:21 UTC (rev 12138)
@@ -28,6 +28,8 @@
package org.foray.common.sequence;
+import org.foray.common.primitive.NumberUtils;
+
import org.axsl.common.sequence.IntSequence;
import org.axsl.common.sequence.IntSequenceMutable;
@@ -100,6 +102,14 @@
}
}
+ /**
+ * Constructor for a string-like representation of an array, for example: "[3, 13, 39]".
+ * @param arrayAsString The sequence of characters that should be parsed to create this array.
+ */
+ public IntArray(final CharSequence arrayAsString) {
+ this.array = NumberUtils.intArrayFromString(arrayAsString);
+ }
+
@Override
public int length() {
return this.array.length;
Added: trunk/foray/foray-common/src/test/java/org/foray/common/primitive/NumberUtilsTests.java
===================================================================
--- trunk/foray/foray-common/src/test/java/org/foray/common/primitive/NumberUtilsTests.java (rev 0)
+++ trunk/foray/foray-common/src/test/java/org/foray/common/primitive/NumberUtilsTests.java 2021-11-26 22:08:21 UTC (rev 12138)
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2021 The FOray Project.
+ * http://www.foray.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.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.common.primitive;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Tests of {@link NumberUtils}.
+ */
+public class NumberUtilsTests {
+
+
+ /**
+ * Test of {@link NumberUtils#intArrayFromString(CharSequence)}.
+ */
+ @Test
+ public void intArrayFromStringTests() {
+ final int[] expected = new int[] {3, 13, 39};
+
+ int[] actual = NumberUtils.intArrayFromString("[3,13,39]");
+ Assert.assertArrayEquals(expected, actual);
+
+ actual = NumberUtils.intArrayFromString("[ 3 , 13 , 39 ]");
+ Assert.assertArrayEquals(expected, actual);
+}
+
+}
Property changes on: trunk/foray/foray-common/src/test/java/org/foray/common/primitive/NumberUtilsTests.java
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Rev
\ No newline at end of property
Added: trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/util/DumpLayout.java
===================================================================
--- trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/util/DumpLayout.java (rev 0)
+++ trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/util/DumpLayout.java 2021-11-26 22:08:21 UTC (rev 12138)
@@ -0,0 +1,88 @@
+/*
+ * Copyright 2021 The FOray Project.
+ * http://www.foray.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.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.linebreak.util;
+
+import org.foray.common.para.ParaBranch4a;
+import org.foray.common.primitive.StringUtils;
+import org.foray.common.sequence.IntArray;
+import org.foray.linebreak.FirstFitLbTests;
+
+import org.axsl.common.para.ParaBranch;
+import org.axsl.common.para.ParaLeaf;
+
+import java.io.PrintStream;
+
+/**
+ * Dumps the content of a {@link ParaBranch} instance, along with a layout, to assist with visualizing the chosen
+ * line breaks.
+ */
+public class DumpLayout {
+
+ /** The output stream to which the output should be sent. */
+ private PrintStream output;
+
+ /**
+ * Constructor.
+ * @param branch The branch whose content should be dumped, with specified line breaks.
+ * @param layout The array of line breaks to be used during the dump.
+ */
+ public DumpLayout(final ParaBranch branch, final int[] layout) {
+ this.output = System.out;
+ final StringBuilder builder = new StringBuilder();
+ final int nextBreakIndex = 0;
+ for (int leafIndex = 0; leafIndex < branch.paraLeafSize(); leafIndex ++) {
+ if (nextBreakIndex < layout.length) {
+ final int nextBreakLeaf = layout[nextBreakIndex];
+ if (leafIndex == nextBreakLeaf) {
+ this.output.println(builder.toString());
+ StringUtils.clear(builder);
+ }
+ }
+ final ParaLeaf leaf = branch.paraLeafAt(leafIndex);
+ builder.append(leaf.getText());
+ }
+ if (builder.length() > 0) {
+ this.output.println(builder.toString());
+ }
+ }
+
+ /**
+ * Command-line interface.
+ * For now, adjust the code in this method to do your testing, or create an instance of this class.
+ * @param args None yet.
+ */
+ public static void main(final String[] args) {
+ final String arrayAsString = args[0];
+ final IntArray intArray = new IntArray(arrayAsString);
+ final FirstFitLbTests lb = new FirstFitLbTests();
+ final ParaBranch4a branch = lb.createPara();
+ new DumpLayout(branch, intArray.toArray());
+ }
+
+}
Property changes on: trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/util/DumpLayout.java
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Rev
\ No newline at end of property
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-11-26 19:38:23
|
Revision: 12137
http://sourceforge.net/p/foray/code/12137
Author: victormote
Date: 2021-11-26 19:38:20 +0000 (Fri, 26 Nov 2021)
Log Message:
-----------
Fix problems in test setup.
Modified Paths:
--------------
trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/LineBreaker4aTests.java
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-26 19:25:19 UTC (rev 12136)
+++ trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/LineBreaker4aTests.java 2021-11-26 19:38:20 UTC (rev 12137)
@@ -185,7 +185,7 @@
para.addWordAndSpace("high");
para.addWordAndSpace("and");
para.addWordAndSpace("caught");
- para.addWord("it;");
+ para.addWord("it");
para.addNodeAndSpace(Punctuation4a.SEMICOLON);
para.addWordAndSpace("and");
para.addWordAndSpace("this");
@@ -193,7 +193,7 @@
para.addWordAndSpace("was");
para.addWordAndSpace("her");
para.addWordAndSpace("favor-ite"); // 2 segments
- para.addWordAndSpace("play-thing"); // 2 segments
+ para.addWord("play-thing"); // 2 segments
para.add(Punctuation4a.PERIOD);
para.add(ParaPenalty4a.DISALLOWED_BREAK);
para.add(ParaGlue4a.FINISHING_GLUE);
@@ -209,14 +209,14 @@
* The compound word "lime-tree" was treated as two words divided by punctuation.
* There are 131 lines of code creating the para.
* Count Nodes
- * addWord 12 12
+ * addWord 13 13
* addNodeAndSpace 11 22
* add 7 7
- * addWordAndSpace (forced) 101 202
+ * addWordAndSpace (forced) 100 200
* ----- -----
- * totals 131 243
+ * totals 131 242
* ===== ===== */
- Assert.assertEquals(243, para.paraNodeSize());
+ Assert.assertEquals(242, para.paraNodeSize());
/* Of the words added, 13 are two-syllable, and 2 are three-syllable.
* If "n" is the number of syllables in a word, the total number of nodes in each word is ((2 * n) - 1).
@@ -230,11 +230,11 @@
* 34
* ====
*/
- Assert.assertEquals(277, para.paraLeafSize());
+ Assert.assertEquals(276, para.paraLeafSize());
/* Check the count of leaves using a strict Knuth-Plass notion of leaves, i.e. where each character in the word
* is a box. See Table 1 where the leaves are listed from 1 through 601. */
-// Assert.assertEquals(601, para.paraKpLeafSize());
+ Assert.assertEquals(601, para.paraKpLeafSize());
return para;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-11-26 19:25:21
|
Revision: 12136
http://sourceforge.net/p/foray/code/12136
Author: victormote
Date: 2021-11-26 19:25:19 +0000 (Fri, 26 Nov 2021)
Log Message:
-----------
Add class to dump a ParaBranch instance.
Modified Paths:
--------------
trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaBox4a.java
trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaGlue4a.java
trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaPenalty4a.java
trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/LineBreaker4aTests.java
Added Paths:
-----------
trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/util/
trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/util/DumpParaBranch.java
trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/util/package-info.java
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaBox4a.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaBox4a.java 2021-11-26 17:58:44 UTC (rev 12135)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaBox4a.java 2021-11-26 19:25:19 UTC (rev 12136)
@@ -40,6 +40,9 @@
*/
public final class ParaBox4a extends ParaLeaf4a implements ParaBox {
+ /** Format used in {@link #toString()}. */
+ private static final String TO_STRING_FORMAT = "Box (w = %1$d)";
+
/** The width of this box, in millipoints. */
private int width;
@@ -86,4 +89,9 @@
return 1;
}
+ @Override
+ public String toString() {
+ return String.format(TO_STRING_FORMAT, this.width);
+ }
+
}
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaGlue4a.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaGlue4a.java 2021-11-26 17:58:44 UTC (rev 12135)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaGlue4a.java 2021-11-26 19:25:19 UTC (rev 12136)
@@ -45,6 +45,9 @@
/** A glue instance used near the end of a paragraphy for finishing purposes. */
public static final ParaGlue4a FINISHING_GLUE = new ParaGlue4a(0, ParaGlue.INFINITE_STRETCHABILITY, 0);
+ /** Format used in {@link #toString()}. */
+ private static final String TO_STRING_FORMAT = "Box (w = %1$d, y = %2$d, z = %3$d)";
+
/** The ideal width of this glue, in millipoints. */
private int idealWidth;
@@ -111,4 +114,9 @@
return 1;
}
+ @Override
+ public String toString() {
+ return String.format(TO_STRING_FORMAT, this.idealWidth, this.stretchability, this.shrinkability);
+ }
+
}
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaPenalty4a.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaPenalty4a.java 2021-11-26 17:58:44 UTC (rev 12135)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaPenalty4a.java 2021-11-26 19:25:19 UTC (rev 12136)
@@ -49,6 +49,9 @@
/** A penalty instance indicating that a break must be taken here always. */
public static final ParaPenalty4a FORCED_BREAK = new ParaPenalty4a(0, ParaPenalty.FORCED_BREAK, true);
+ /** String format used in {@link #toString()}. */
+ private static final String TO_STRING_FORMAT = "Penalty (w = %1$d, p = %2$d, f = %3$b)";
+
/** The width of this penalty, in millipoints. */
private int width;
@@ -115,4 +118,9 @@
return 1;
}
+ @Override
+ public String toString() {
+ return String.format(TO_STRING_FORMAT, this.width, this.cost, this.flagged);
+ }
+
}
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-26 17:58:44 UTC (rev 12135)
+++ trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/LineBreaker4aTests.java 2021-11-26 19:25:19 UTC (rev 12136)
@@ -65,7 +65,7 @@
* manually build it in this method.
* @return The tokenized content of {@link #TEST_STRING_01}.
*/
- protected ParaBranch4a createPara() {
+ public ParaBranch4a createPara() {
final ParaBranch4aTestFixture para = new ParaBranch4aTestFixture(null, '-');
para.add(new ParaBox4a(18)); // Empty box for indentation
para.addWordAndSpace("In");
@@ -130,6 +130,7 @@
para.addWordAndSpace("old");
para.addWord("lime");
para.add(Punctuation4a.MANDATORY_HYPHEN);
+ para.add(new ParaPenalty4a(0, 50, true));
para.addWordAndSpace("tree");
para.addWordAndSpace("in");
para.addWordAndSpace("the");
@@ -206,16 +207,16 @@
/* The tokenized text treated "’s" as part of the attached word.
* The compound word "lime-tree" was treated as two words divided by punctuation.
- * There are 130 lines of code creating the para.
+ * There are 131 lines of code creating the para.
* Count Nodes
* addWord 12 12
* addNodeAndSpace 11 22
- * add 6 6
+ * add 7 7
* addWordAndSpace (forced) 101 202
* ----- -----
- * totals 130 242
+ * totals 131 243
* ===== ===== */
- Assert.assertEquals(242, para.paraNodeSize());
+ Assert.assertEquals(243, para.paraNodeSize());
/* Of the words added, 13 are two-syllable, and 2 are three-syllable.
* If "n" is the number of syllables in a word, the total number of nodes in each word is ((2 * n) - 1).
@@ -229,7 +230,7 @@
* 34
* ====
*/
- Assert.assertEquals(276, para.paraLeafSize());
+ Assert.assertEquals(277, para.paraLeafSize());
/* Check the count of leaves using a strict Knuth-Plass notion of leaves, i.e. where each character in the word
* is a box. See Table 1 where the leaves are listed from 1 through 601. */
Added: trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/util/DumpParaBranch.java
===================================================================
--- trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/util/DumpParaBranch.java (rev 0)
+++ trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/util/DumpParaBranch.java 2021-11-26 19:25:19 UTC (rev 12136)
@@ -0,0 +1,82 @@
+/*
+ * Copyright 2021 The FOray Project.
+ * http://www.foray.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.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.linebreak.util;
+
+import org.foray.common.para.ParaBranch4a;
+import org.foray.linebreak.FirstFitLbTests;
+
+import org.axsl.common.para.ParaBranch;
+import org.axsl.common.para.ParaNode;
+
+import java.io.PrintStream;
+
+/**
+ * Dumps the content of a {@link ParaBranch} instance, for debugging.
+ */
+public class DumpParaBranch {
+
+ /** Formatter for the output. */
+ private static final String FORMAT = "%6d %6d %6d %6d %6d %s";
+
+ /** The output stream to which the output should be sent. */
+ private PrintStream output;
+
+ public DumpParaBranch(final ParaBranch branch) {
+ this.output = System.out;
+ this.output.println(" Start");
+ this.output.println(" Start KP Qty");
+ this.output.println(" Node Leaf Qty Leaf KP");
+ this.output.println(" Index Index Leaves Index Leaves Node Content");
+ this.output.println("------ ------ ------ ------ ------ --------------------------------------");
+ int startLeafIndex = 0;
+ int startKpLeafIndex = 0;
+ for (int nodeIndex = 0; nodeIndex < branch.paraNodeSize(); nodeIndex ++) {
+ final ParaNode node = branch.paraNodeAt(nodeIndex);
+ final int qtyLeaves = node.asParaBranch() == null ? 1 : ((ParaBranch) node).paraLeafSize();
+ final int qtyKpLeaves = node.paraKpLeafSize();
+ final String line = String.format(FORMAT, nodeIndex, startLeafIndex, qtyLeaves, startKpLeafIndex,
+ qtyKpLeaves, node);
+ this.output.println(line);
+ startLeafIndex += qtyLeaves;
+ startKpLeafIndex += qtyKpLeaves;
+ }
+ }
+
+ /**
+ * Command-line interface.
+ * For now, adjust the code in this method to do your testing, or create an instance of this class.
+ * @param args None yet.
+ */
+ public static void main(final String[] args) {
+ final FirstFitLbTests lb = new FirstFitLbTests();
+ final ParaBranch4a branch = lb.createPara();
+ new DumpParaBranch(branch);
+ }
+
+}
Property changes on: trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/util/DumpParaBranch.java
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Rev
\ No newline at end of property
Added: trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/util/package-info.java
===================================================================
--- trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/util/package-info.java (rev 0)
+++ trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/util/package-info.java 2021-11-26 19:25:19 UTC (rev 12136)
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2021 The FOray Project.
+ * http://www.foray.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.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+/**
+ * Utility classes for foray-linebreak.
+ */
+package org.foray.linebreak.util;
Property changes on: trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/util/package-info.java
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Rev
\ No newline at end of property
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-11-26 17:58:47
|
Revision: 12135
http://sourceforge.net/p/foray/code/12135
Author: victormote
Date: 2021-11-26 17:58:44 +0000 (Fri, 26 Nov 2021)
Log Message:
-----------
Conform to aXSL change: Add method to get a strict Knuth-Plass leaf count.
Modified Paths:
--------------
trunk/foray/foray-common/src/main/java/org/foray/common/para/DiscretionaryHyphen4a.java
trunk/foray/foray-common/src/main/java/org/foray/common/para/DiscretionaryHyphenMutating4a.java
trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaBox4a.java
trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaBoxChars.java
trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaBranch4a.java
trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaGlue4a.java
trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaGlueChars.java
trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaPenalty4a.java
trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaPenaltyChars.java
trunk/foray/foray-linebreak/src/main/java/org/foray/linebreak/TotalFitLb.java
trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/LineBreaker4aTests.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/Punctuation4a.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/SegmentDictionaryWord.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/StringWord.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/StringWordSegmentLatin1.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/StringWordSegmentUtf16.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/Whitespace4a.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/WordSegment4a.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/CapitalizedWord.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/ExactWord.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/LatinPast1Word.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/LatinPlural1Word.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/LatinPlural2Word.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/LatinPossessive1Word.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/LatinPossessive2Word.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/UppercaseWord.java
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/para/DiscretionaryHyphen4a.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/para/DiscretionaryHyphen4a.java 2021-11-26 13:44:01 UTC (rev 12134)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/para/DiscretionaryHyphen4a.java 2021-11-26 17:58:44 UTC (rev 12135)
@@ -125,4 +125,9 @@
return "-";
}
+ @Override
+ public int paraKpLeafSize() {
+ return 1;
+ }
+
}
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/para/DiscretionaryHyphenMutating4a.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/para/DiscretionaryHyphenMutating4a.java 2021-11-26 13:44:01 UTC (rev 12134)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/para/DiscretionaryHyphenMutating4a.java 2021-11-26 17:58:44 UTC (rev 12135)
@@ -206,4 +206,9 @@
return "-";
}
+ @Override
+ public int paraKpLeafSize() {
+ return 1;
+ }
+
}
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaBox4a.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaBox4a.java 2021-11-26 13:44:01 UTC (rev 12134)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaBox4a.java 2021-11-26 17:58:44 UTC (rev 12135)
@@ -32,9 +32,7 @@
import org.axsl.common.para.ParaBox;
import org.axsl.common.para.ParaConfig;
-import org.axsl.common.para.ParaGlue;
import org.axsl.common.para.ParaLeaf;
-import org.axsl.common.para.ParaPenalty;
/**
* A hard-wired implementation of a Knuth-Plass box.
@@ -59,17 +57,17 @@
}
@Override
- public ParaBox asParaBox() {
+ public ParaBox4a asParaBox() {
return this;
}
@Override
- public ParaGlue asParaGlue() {
+ public ParaGlue4a asParaGlue() {
return null;
}
@Override
- public ParaPenalty asParaPenalty() {
+ public ParaPenalty4a asParaPenalty() {
return null;
}
@@ -83,4 +81,9 @@
return StringUtils.EMPTY_STRING;
}
+ @Override
+ public int paraKpLeafSize() {
+ return 1;
+ }
+
}
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaBoxChars.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaBoxChars.java 2021-11-26 13:44:01 UTC (rev 12134)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaBoxChars.java 2021-11-26 17:58:44 UTC (rev 12135)
@@ -86,4 +86,9 @@
return this.chars;
}
+ @Override
+ public int paraKpLeafSize() {
+ return this.chars.length();
+ }
+
}
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaBranch4a.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaBranch4a.java 2021-11-26 13:44:01 UTC (rev 12134)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaBranch4a.java 2021-11-26 17:58:44 UTC (rev 12135)
@@ -103,6 +103,34 @@
return null;
}
+ /**
+ * Returns the quantity of leaf nodes as computed by the Knuth-Plass model.
+ * In the FOray data model, syllables of words (aka word segments) are atoms, but the Knuth-Plass model treats
+ * each character as an atom.
+ * As a theoretical matter, the K-P count is correct, but the FOray model works as well as a practical matter.
+ * This method computes the count using the K-P method, which, within FOay at least, is probably useful only for
+ * testing.
+ * @return The number of descendant leaf nodes as compute by the Knuth-Plass model, i.e. each character in a word
+ * is treated as a box.
+ * @see ParaBranch#paraLeafSize()
+ */
+ public int paraKpLeafSize() {
+ int returnValue = 0;
+ for (int nodeIndex = 0; nodeIndex < paraNodeSize(); nodeIndex ++) {
+ final ParaNode node = paraNodeAt(nodeIndex);
+ final ParaBranch childBranch = node.asParaBranch();
+ if (childBranch == null) {
+ /* Child node is a leaf. */
+ final ParaLeaf leaf = node.asParaLeaf();
+ returnValue += leaf.paraKpLeafSize();
+ } else {
+ /* Child node is a branch. */
+ returnValue += childBranch.paraKpLeafSize();
+ }
+ }
+ return returnValue;
+ }
+
@Override
public ParaConfig getParaConfig() {
return this.config;
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaGlue4a.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaGlue4a.java 2021-11-26 13:44:01 UTC (rev 12134)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaGlue4a.java 2021-11-26 17:58:44 UTC (rev 12135)
@@ -42,6 +42,9 @@
*/
public final class ParaGlue4a extends ParaLeaf4a implements ParaGlue {
+ /** A glue instance used near the end of a paragraphy for finishing purposes. */
+ public static final ParaGlue4a FINISHING_GLUE = new ParaGlue4a(0, ParaGlue.INFINITE_STRETCHABILITY, 0);
+
/** The ideal width of this glue, in millipoints. */
private int idealWidth;
@@ -103,4 +106,9 @@
return StringUtils.EMPTY_STRING;
}
+ @Override
+ public int paraKpLeafSize() {
+ return 1;
+ }
+
}
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaGlueChars.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaGlueChars.java 2021-11-26 13:44:01 UTC (rev 12134)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaGlueChars.java 2021-11-26 17:58:44 UTC (rev 12135)
@@ -100,4 +100,9 @@
return config.getShrinkability(this);
}
+ @Override
+ public int paraKpLeafSize() {
+ return this.chars.length();
+ }
+
}
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaPenalty4a.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaPenalty4a.java 2021-11-26 13:44:01 UTC (rev 12134)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaPenalty4a.java 2021-11-26 17:58:44 UTC (rev 12135)
@@ -43,10 +43,12 @@
*/
public final class ParaPenalty4a extends ParaLeaf4a implements ParaPenalty {
- /** A penalty instance suitable for inclusion as the paragraph terminator in the Knuth-Plass line-breaking
- * algorithm. */
- public static final ParaPenalty4a PARAGRAPH_TERMINATOR = new ParaPenalty4a(0, ParaPenalty.FORCED_BREAK, false);
+ /** A penalty instance indicating that a break cannot be taken here under any circumstances. */
+ public static final ParaPenalty4a DISALLOWED_BREAK = new ParaPenalty4a(0, ParaPenalty.INFINITE_PENALTY, false);
+ /** A penalty instance indicating that a break must be taken here always. */
+ public static final ParaPenalty4a FORCED_BREAK = new ParaPenalty4a(0, ParaPenalty.FORCED_BREAK, true);
+
/** The width of this penalty, in millipoints. */
private int width;
@@ -108,4 +110,9 @@
return StringUtils.EMPTY_STRING;
}
+ @Override
+ public int paraKpLeafSize() {
+ return 1;
+ }
+
}
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaPenaltyChars.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaPenaltyChars.java 2021-11-26 13:44:01 UTC (rev 12134)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaPenaltyChars.java 2021-11-26 17:58:44 UTC (rev 12135)
@@ -102,4 +102,9 @@
return this.chars;
}
+ @Override
+ public int paraKpLeafSize() {
+ return this.chars.length();
+ }
+
}
Modified: trunk/foray/foray-linebreak/src/main/java/org/foray/linebreak/TotalFitLb.java
===================================================================
--- trunk/foray/foray-linebreak/src/main/java/org/foray/linebreak/TotalFitLb.java 2021-11-26 13:44:01 UTC (rev 12134)
+++ trunk/foray/foray-linebreak/src/main/java/org/foray/linebreak/TotalFitLb.java 2021-11-26 17:58:44 UTC (rev 12135)
@@ -123,7 +123,7 @@
currentPath.pop();
}
/* Add the paragraph terminator penalty item. */
- final LbNodeWrapper wrapper = new LbNodeWrapper(ParaPenalty4a.PARAGRAPH_TERMINATOR, paragraph.getParaConfig(),
+ final LbNodeWrapper wrapper = new LbNodeWrapper(ParaPenalty4a.FORCED_BREAK, paragraph.getParaConfig(),
this.contentNodes.size(), null);
this.contentNodes.add(wrapper);
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-26 13:44:01 UTC (rev 12134)
+++ trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/LineBreaker4aTests.java 2021-11-26 17:58:44 UTC (rev 12135)
@@ -28,8 +28,11 @@
package org.foray.linebreak;
+import org.foray.common.para.ParaBox4a;
import org.foray.common.para.ParaBranch4a;
import org.foray.common.para.ParaConfig4a;
+import org.foray.common.para.ParaGlue4a;
+import org.foray.common.para.ParaPenalty4a;
import org.foray.orthography.Punctuation4a;
import org.axsl.common.para.ParaConfig;
@@ -64,6 +67,7 @@
*/
protected ParaBranch4a createPara() {
final ParaBranch4aTestFixture para = new ParaBranch4aTestFixture(null, '-');
+ para.add(new ParaBox4a(18)); // Empty box for indentation
para.addWordAndSpace("In");
para.addWordAndSpace("olden");
para.addWordAndSpace("times");
@@ -190,6 +194,9 @@
para.addWordAndSpace("favor-ite"); // 2 segments
para.addWordAndSpace("play-thing"); // 2 segments
para.add(Punctuation4a.PERIOD);
+ para.add(ParaPenalty4a.DISALLOWED_BREAK);
+ para.add(ParaGlue4a.FINISHING_GLUE);
+ para.add(ParaPenalty4a.FORCED_BREAK);
final Font font = LbTestUtilities.createMonotypeFont();
final FontUse fontUse = Mockito.mock(FontUse.class);
@@ -199,16 +206,16 @@
/* The tokenized text treated "’s" as part of the attached word.
* The compound word "lime-tree" was treated as two words divided by punctuation.
- * There are 126 lines of code creating the para.
+ * There are 130 lines of code creating the para.
* Count Nodes
* addWord 12 12
* addNodeAndSpace 11 22
- * add 2 2
+ * add 6 6
* addWordAndSpace (forced) 101 202
* ----- -----
- * totals 126 238
+ * totals 130 242
* ===== ===== */
- Assert.assertEquals(238, para.paraNodeSize());
+ Assert.assertEquals(242, para.paraNodeSize());
/* Of the words added, 13 are two-syllable, and 2 are three-syllable.
* If "n" is the number of syllables in a word, the total number of nodes in each word is ((2 * n) - 1).
@@ -222,8 +229,12 @@
* 34
* ====
*/
- Assert.assertEquals(272, para.paraLeafSize());
+ Assert.assertEquals(276, para.paraLeafSize());
+ /* Check the count of leaves using a strict Knuth-Plass notion of leaves, i.e. where each character in the word
+ * is a box. See Table 1 where the leaves are listed from 1 through 601. */
+// Assert.assertEquals(601, para.paraKpLeafSize());
+
return para;
}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/Punctuation4a.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/Punctuation4a.java 2021-11-26 13:44:01 UTC (rev 12134)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/Punctuation4a.java 2021-11-26 17:58:44 UTC (rev 12135)
@@ -245,4 +245,9 @@
return this.content.subSequence(start, end);
}
+ @Override
+ public int paraKpLeafSize() {
+ return this.content.length();
+ }
+
}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/SegmentDictionaryWord.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/SegmentDictionaryWord.java 2021-11-26 13:44:01 UTC (rev 12134)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/SegmentDictionaryWord.java 2021-11-26 17:58:44 UTC (rev 12135)
@@ -110,7 +110,9 @@
@Override
public int paraLeafSize() {
- return this.segments.length;
+ /* Each syllable has a leaf for itself and one for the discretionary hyphen that follows it, except the last
+ * syllable, which is not followed by a hyphen. */
+ return (this.segments.length * 2) - 1;
}
@Override
@@ -119,4 +121,16 @@
return null;
}
+ @Override
+ public int paraKpLeafSize() {
+ /* First, count the discretionary hyphens. */
+ int leafCount = this.segments.length - 1;
+ /* Add the number of chars in each segment. */
+ for (int segmentIndex = 0; segmentIndex < this.segments.length; segmentIndex ++) {
+ final StringWordSegment segment = this.dictionary.getWordSegment(segmentIndex);
+ leafCount += segment.length();
+ }
+ return leafCount;
+ }
+
}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/StringWord.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/StringWord.java 2021-11-26 13:44:01 UTC (rev 12134)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/StringWord.java 2021-11-26 17:58:44 UTC (rev 12135)
@@ -147,4 +147,16 @@
return this.segments[segmentIndex];
}
+ @Override
+ public int paraKpLeafSize() {
+ /* First, count the discretionary hyphens. */
+ int leafCount = this.segments.length - 1;
+ /* Add the number of chars in each segment. */
+ for (int segmentIndex = 0; segmentIndex < this.segments.length; segmentIndex ++) {
+ final StringWordSegment segment = segments[segmentIndex];
+ leafCount += segment.length();
+ }
+ return leafCount;
+ }
+
}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/StringWordSegmentLatin1.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/StringWordSegmentLatin1.java 2021-11-26 13:44:01 UTC (rev 12134)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/StringWordSegmentLatin1.java 2021-11-26 17:58:44 UTC (rev 12135)
@@ -109,4 +109,9 @@
return toString();
}
+ @Override
+ public int paraKpLeafSize() {
+ return length();
+ }
+
}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/StringWordSegmentUtf16.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/StringWordSegmentUtf16.java 2021-11-26 13:44:01 UTC (rev 12134)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/StringWordSegmentUtf16.java 2021-11-26 17:58:44 UTC (rev 12135)
@@ -109,4 +109,9 @@
return toString();
}
+ @Override
+ public int paraKpLeafSize() {
+ return length();
+ }
+
}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/Whitespace4a.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/Whitespace4a.java 2021-11-26 13:44:01 UTC (rev 12134)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/Whitespace4a.java 2021-11-26 17:58:44 UTC (rev 12135)
@@ -183,4 +183,9 @@
return this.content.toString();
}
+ @Override
+ public int paraKpLeafSize() {
+ return this.content.length();
+ }
+
}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/WordSegment4a.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/WordSegment4a.java 2021-11-26 13:44:01 UTC (rev 12134)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/WordSegment4a.java 2021-11-26 17:58:44 UTC (rev 12135)
@@ -95,4 +95,9 @@
return getText();
}
+ @Override
+ public int paraKpLeafSize() {
+ return this.length();
+ }
+
}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/CapitalizedWord.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/CapitalizedWord.java 2021-11-26 13:44:01 UTC (rev 12134)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/CapitalizedWord.java 2021-11-26 17:58:44 UTC (rev 12135)
@@ -111,4 +111,9 @@
return this.getWrappedWord().paraLeafAt(index);
}
+ @Override
+ public int paraKpLeafSize() {
+ return getWrappedWord().paraKpLeafSize();
+ }
+
}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/ExactWord.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/ExactWord.java 2021-11-26 13:44:01 UTC (rev 12134)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/ExactWord.java 2021-11-26 17:58:44 UTC (rev 12135)
@@ -94,4 +94,9 @@
return this.getWrappedWord().paraLeafAt(index);
}
+ @Override
+ public int paraKpLeafSize() {
+ return getWrappedWord().paraKpLeafSize();
+ }
+
}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/LatinPast1Word.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/LatinPast1Word.java 2021-11-26 13:44:01 UTC (rev 12134)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/LatinPast1Word.java 2021-11-26 17:58:44 UTC (rev 12135)
@@ -75,4 +75,9 @@
throw new IndexOutOfBoundsException("Index out of bounds: " + index);
}
+ @Override
+ public int paraKpLeafSize() {
+ return getWrappedWord().paraKpLeafSize() + LatinPast1Word.SUFFIX.length();
+ }
+
}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/LatinPlural1Word.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/LatinPlural1Word.java 2021-11-26 13:44:01 UTC (rev 12134)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/LatinPlural1Word.java 2021-11-26 17:58:44 UTC (rev 12135)
@@ -51,6 +51,9 @@
/** The character(s) at the end of the wrapped word form. */
public static final String WRAPPED_FORM = "s";
+ /** The net number of additional characters in the wrapped word. */
+ public static final int SIZE_DIFFERENCE = 1;
+
/** Constant needed for serialization. */
private static final long serialVersionUID = -2217326535363608251L;
@@ -98,4 +101,9 @@
return getWrappedWord().paraLeafAt(index);
}
+ @Override
+ public int paraKpLeafSize() {
+ return getWrappedWord().paraKpLeafSize() + LatinPlural1Word.Segment.SIZE_DIFFERENCE;
+ }
+
}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/LatinPlural2Word.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/LatinPlural2Word.java 2021-11-26 13:44:01 UTC (rev 12134)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/LatinPlural2Word.java 2021-11-26 17:58:44 UTC (rev 12135)
@@ -54,6 +54,9 @@
/** The character(s) at the end of the wrapped word form. */
public static final String WRAPPED_FORM = "ies";
+ /** The net number of additional characters in the wrapped word. */
+ public static final int SIZE_DIFFERENCE = 2;
+
/** Constant needed for serialization. */
private static final long serialVersionUID = -2217326535363608251L;
@@ -101,4 +104,9 @@
return getWrappedWord().paraLeafAt(index);
}
+ @Override
+ public int paraKpLeafSize() {
+ return getWrappedWord().paraLeafSize() + LatinPlural2Word.Segment.SIZE_DIFFERENCE;
+ }
+
}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/LatinPossessive1Word.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/LatinPossessive1Word.java 2021-11-26 13:44:01 UTC (rev 12134)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/LatinPossessive1Word.java 2021-11-26 17:58:44 UTC (rev 12135)
@@ -52,6 +52,9 @@
/** The character(s) at the end of the wrapped word form. */
public static final String WRAPPED_FORM = "\u2019s";
+ /** The net number of additional characters in the wrapped word. */
+ public static final int SIZE_DIFFERENCE = 2;
+
/** Constant needed for serialization. */
private static final long serialVersionUID = 5259708128661560937L;
@@ -99,4 +102,9 @@
return getWrappedWord().paraLeafAt(index);
}
+ @Override
+ public int paraKpLeafSize() {
+ return getWrappedWord().paraKpLeafSize() + LatinPossessive1Word.Segment.SIZE_DIFFERENCE;
+ }
+
}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/LatinPossessive2Word.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/LatinPossessive2Word.java 2021-11-26 13:44:01 UTC (rev 12134)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/LatinPossessive2Word.java 2021-11-26 17:58:44 UTC (rev 12135)
@@ -52,6 +52,9 @@
/** The character(s) at the end of the wrapped word form. */
public static final String WRAPPED_FORM = "\'s";
+ /** The net number of additional characters in the wrapped word. */
+ public static final int SIZE_DIFFERENCE = 2;
+
/** Constant needed for serialization. */
private static final long serialVersionUID = 1420211154513295005L;
@@ -99,4 +102,9 @@
return getWrappedWord().paraLeafAt(index);
}
+ @Override
+ public int paraKpLeafSize() {
+ return getWrappedWord().paraKpLeafSize() + LatinPossessive2Word.Segment.SIZE_DIFFERENCE;
+ }
+
}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/UppercaseWord.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/UppercaseWord.java 2021-11-26 13:44:01 UTC (rev 12134)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/UppercaseWord.java 2021-11-26 17:58:44 UTC (rev 12135)
@@ -102,4 +102,9 @@
return getWrappedWord().paraLeafAt(index);
}
+ @Override
+ public int paraKpLeafSize() {
+ return getWrappedWord().paraKpLeafSize();
+ }
+
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-11-26 13:44:05
|
Revision: 12134
http://sourceforge.net/p/foray/code/12134
Author: victormote
Date: 2021-11-26 13:44:01 +0000 (Fri, 26 Nov 2021)
Log Message:
-----------
Conform to aXSL changes: Rename methods for consistency.
Modified Paths:
--------------
trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaBranch4a.java
trunk/foray/foray-fotree/src/main/java/org/foray/fotree/fo/obj/FoWordSequence.java
trunk/foray/foray-linebreak/src/main/java/org/foray/linebreak/ParaContentIterator.java
trunk/foray/foray-linebreak/src/main/java/org/foray/linebreak/TotalFitLb.java
trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/LineBreaker4aTests.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/SegmentDictionaryWord.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/StringWord.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/Word4a.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/CapitalizedWord.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/DecoratedWord.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/ExactWord.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/LatinPast1Word.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/LatinPlural1Word.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/LatinPlural2Word.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/LatinPossessive1Word.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/LatinPossessive2Word.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/UppercaseWord.java
trunk/foray/foray-orthography/src/test/java/org/foray/orthography/HyphenationConsumer4aTests.java
trunk/foray/foray-orthography/src/test/java/org/foray/orthography/SegmentDictionaryWordTests.java
trunk/foray/foray-orthography/src/test/java/org/foray/orthography/StringWordTests.java
trunk/foray/foray-orthography/src/test/java/org/foray/orthography/WordWrapperTests.java
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaBranch4a.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaBranch4a.java 2021-11-26 13:05:00 UTC (rev 12133)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaBranch4a.java 2021-11-26 13:44:01 UTC (rev 12134)
@@ -72,26 +72,26 @@
}
@Override
- public int getQtyParaNodeChildren() {
+ public int paraNodeSize() {
return this.nodes.size();
}
@Override
- public ParaNode getParaNodeChild(final int index) {
- return this.nodes.get(index);
+ public ParaNode paraNodeAt(final int nodeIndex) {
+ return this.nodes.get(nodeIndex);
}
@Override
- public int getQtyParaLeafDescendants() {
+ public int paraLeafSize() {
int returnValue = 0;
- for (int index = 0; index < getQtyParaNodeChildren(); index ++) {
- final ParaBranch childBranch = getParaNodeChild(index).asParaBranch();
+ for (int nodeIndex = 0; nodeIndex < paraNodeSize(); nodeIndex ++) {
+ final ParaBranch childBranch = paraNodeAt(nodeIndex).asParaBranch();
if (childBranch == null) {
/* Child node is a leaf. */
returnValue ++;
} else {
/* Child node is a branch. */
- returnValue += childBranch.getQtyParaLeafDescendants();
+ returnValue += childBranch.paraLeafSize();
}
}
return returnValue;
Modified: trunk/foray/foray-fotree/src/main/java/org/foray/fotree/fo/obj/FoWordSequence.java
===================================================================
--- trunk/foray/foray-fotree/src/main/java/org/foray/fotree/fo/obj/FoWordSequence.java 2021-11-26 13:05:00 UTC (rev 12133)
+++ trunk/foray/foray-fotree/src/main/java/org/foray/fotree/fo/obj/FoWordSequence.java 2021-11-26 13:44:01 UTC (rev 12134)
@@ -65,9 +65,9 @@
final ParaConfig4a config = new ParaConfig4a(getPrimaryFont(null), inlineFontSize(), inlineOrthography(),
parent.traitWordSpacingMax(null), parent.traitWordSpacingMin(null));
wordSequence.setParaConfig(config);
- this.content = new ArrayList<FoWordSequenceContent>(wordSequence.getQtyParaNodeChildren());
- for (int index = 0; index < wordSequence.getQtyParaNodeChildren(); index ++) {
- final ParaNode wordSequenceContent = wordSequence.getParaNodeChild(index);
+ this.content = new ArrayList<FoWordSequenceContent>(wordSequence.paraNodeSize());
+ for (int index = 0; index < wordSequence.paraNodeSize(); index ++) {
+ final ParaNode wordSequenceContent = wordSequence.paraNodeAt(index);
final FoWordSequenceContent contentElement = FoWordSequenceContent.create(wordSequenceContent);
this.content.add(contentElement);
}
Modified: trunk/foray/foray-linebreak/src/main/java/org/foray/linebreak/ParaContentIterator.java
===================================================================
--- trunk/foray/foray-linebreak/src/main/java/org/foray/linebreak/ParaContentIterator.java 2021-11-26 13:05:00 UTC (rev 12133)
+++ trunk/foray/foray-linebreak/src/main/java/org/foray/linebreak/ParaContentIterator.java 2021-11-26 13:44:01 UTC (rev 12134)
@@ -68,9 +68,9 @@
this.nodeStack.push(paraContent);
/* Push the first child of the root node, if any, on the stack. This is the first item to be returned.
* Push its index onto the currentPath. */
- if (paraContent.getQtyParaNodeChildren() > 0) {
+ if (paraContent.paraNodeSize() > 0) {
currentPath.push(0);
- this.nodeStack.push(paraContent.getParaNodeChild(0));
+ this.nodeStack.push(paraContent.paraNodeAt(0));
}
}
@@ -91,9 +91,9 @@
/* Set up the next item (if any) here. */
if (returnParaBranch != null
- && returnParaBranch.getQtyParaNodeChildren() > 0) {
+ && returnParaBranch.paraNodeSize() > 0) {
/* The return value has children. Put the first one on the stack. */
- this.nodeStack.push(returnParaBranch.getParaNodeChild(0));
+ this.nodeStack.push(returnParaBranch.paraNodeAt(0));
this.currentPath.push(0);
} else {
ParaNode nextNode = null;
@@ -112,8 +112,8 @@
final int nextIndex = this.currentPath.peek() + 1;
this.currentPath.pop();
if (topParaBranch != null
- && nextIndex < topParaBranch.getQtyParaNodeChildren()) {
- nextNode = topParaBranch.getParaNodeChild(nextIndex);
+ && nextIndex < topParaBranch.paraNodeSize()) {
+ nextNode = topParaBranch.paraNodeAt(nextIndex);
this.nodeStack.push(nextNode);
this.currentPath.push(nextIndex);
}
Modified: trunk/foray/foray-linebreak/src/main/java/org/foray/linebreak/TotalFitLb.java
===================================================================
--- trunk/foray/foray-linebreak/src/main/java/org/foray/linebreak/TotalFitLb.java 2021-11-26 13:05:00 UTC (rev 12133)
+++ trunk/foray/foray-linebreak/src/main/java/org/foray/linebreak/TotalFitLb.java 2021-11-26 13:44:01 UTC (rev 12134)
@@ -116,8 +116,8 @@
/* Flatten the tree structure. */
final IntArrayBuilder currentPath = new IntArrayBuilder();
- for (int index = 0; index < this.paragraph.getQtyParaNodeChildren(); index ++) {
- final ParaNode node = this.paragraph.getParaNodeChild(index);
+ for (int index = 0; index < this.paragraph.paraNodeSize(); index ++) {
+ final ParaNode node = this.paragraph.paraNodeAt(index);
currentPath.push(index);
flatten(node, currentPath);
currentPath.pop();
@@ -167,8 +167,8 @@
case BRANCH: {
final ParaBranch branch = node.asParaBranch();
this.branchStack.push(branch);
- for (int index = 0; index < branch.getQtyParaNodeChildren(); index ++) {
- final ParaNode childNode = branch.getParaNodeChild(index);
+ for (int index = 0; index < branch.paraNodeSize(); index ++) {
+ final ParaNode childNode = branch.paraNodeAt(index);
currentPath.push(index);
flatten(childNode, currentPath);
currentPath.pop();
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-26 13:05:00 UTC (rev 12133)
+++ trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/LineBreaker4aTests.java 2021-11-26 13:44:01 UTC (rev 12134)
@@ -208,7 +208,7 @@
* ----- -----
* totals 126 238
* ===== ===== */
- Assert.assertEquals(238, para.getQtyParaNodeChildren());
+ Assert.assertEquals(238, para.paraNodeSize());
/* Of the words added, 13 are two-syllable, and 2 are three-syllable.
* If "n" is the number of syllables in a word, the total number of nodes in each word is ((2 * n) - 1).
@@ -222,7 +222,7 @@
* 34
* ====
*/
- Assert.assertEquals(272, para.getQtyParaLeafDescendants());
+ Assert.assertEquals(272, para.paraLeafSize());
return para;
}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/SegmentDictionaryWord.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/SegmentDictionaryWord.java 2021-11-26 13:05:00 UTC (rev 12133)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/SegmentDictionaryWord.java 2021-11-26 13:44:01 UTC (rev 12134)
@@ -109,7 +109,7 @@
}
@Override
- public int getQtyParaLeafDescendants() {
+ public int paraLeafSize() {
return this.segments.length;
}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/StringWord.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/StringWord.java 2021-11-26 13:05:00 UTC (rev 12133)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/StringWord.java 2021-11-26 13:44:01 UTC (rev 12134)
@@ -125,7 +125,7 @@
}
@Override
- public int getQtyParaLeafDescendants() {
+ public int paraLeafSize() {
/* Each segment is 2 nodes, one for the segment, one for the discretionary hyphen that follows it, except that
* the last segment is not followed by a discretionary hyphen. */
return (2 * this.segments.length) - 1;
@@ -134,7 +134,7 @@
@Override
public ParaLeaf paraLeafAt(final int leafIndex) {
if (leafIndex < 0
- || leafIndex >= getQtyParaLeafDescendants()) {
+ || leafIndex >= paraLeafSize()) {
throw new IndexOutOfBoundsException("Index out of bounds: " + leafIndex);
}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/Word4a.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/Word4a.java 2021-11-26 13:05:00 UTC (rev 12133)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/Word4a.java 2021-11-26 13:44:01 UTC (rev 12134)
@@ -208,12 +208,12 @@
}
@Override
- public int getQtyParaNodeChildren() {
+ public int paraNodeSize() {
return this.getQtyWordComponents();
}
@Override
- public ParaNode getParaNodeChild(final int index) {
+ public ParaNode paraNodeAt(final int index) {
return this.getWordComponent(index);
}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/CapitalizedWord.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/CapitalizedWord.java 2021-11-26 13:05:00 UTC (rev 12133)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/CapitalizedWord.java 2021-11-26 13:44:01 UTC (rev 12134)
@@ -101,9 +101,9 @@
}
@Override
- public int getQtyParaLeafDescendants() {
+ public int paraLeafSize() {
/* Capitalizing the word does not change the number of leaf descendants. */
- return this.getWrappedWord().getQtyParaLeafDescendants();
+ return this.getWrappedWord().paraLeafSize();
}
@Override
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/DecoratedWord.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/DecoratedWord.java 2021-11-26 13:05:00 UTC (rev 12133)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/DecoratedWord.java 2021-11-26 13:44:01 UTC (rev 12134)
@@ -79,13 +79,13 @@
}
@Override
- public int getQtyParaNodeChildren() {
- return getWrappedWord().getQtyParaNodeChildren();
+ public int paraLeafSize() {
+ return getWrappedWord().paraLeafSize();
}
@Override
- public ParaNode getParaNodeChild(final int index) {
- return getWrappedWord().getParaNodeChild(index);
+ public ParaNode paraNodeAt(final int index) {
+ return getWrappedWord().paraNodeAt(index);
}
@Override
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/ExactWord.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/ExactWord.java 2021-11-26 13:05:00 UTC (rev 12133)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/ExactWord.java 2021-11-26 13:44:01 UTC (rev 12134)
@@ -84,9 +84,9 @@
}
@Override
- public int getQtyParaLeafDescendants() {
+ public int paraLeafSize() {
/* Changing the case of chars in the word does not change the number of leaf descendants. */
- return this.getWrappedWord().getQtyParaLeafDescendants();
+ return this.getWrappedWord().paraLeafSize();
}
@Override
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/LatinPast1Word.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/LatinPast1Word.java 2021-11-26 13:05:00 UTC (rev 12133)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/LatinPast1Word.java 2021-11-26 13:44:01 UTC (rev 12134)
@@ -59,17 +59,17 @@
}
@Override
- public int getQtyParaLeafDescendants() {
+ public int paraLeafSize() {
/* This wrapper should add one leaf descendant to the size of the wrapped word. */
- return this.getWrappedWord().getQtyParaLeafDescendants() + 1;
+ return this.getWrappedWord().paraLeafSize() + 1;
}
@Override
public ParaLeaf paraLeafAt(final int index) {
- if (index < getWrappedWord().getQtyParaLeafDescendants()) {
+ if (index < getWrappedWord().paraLeafSize()) {
return getWrappedWord().paraLeafAt(index);
}
- if (index == getWrappedWord().getQtyParaLeafDescendants()) {
+ if (index == getWrappedWord().paraLeafSize()) {
return SUFFIX;
}
throw new IndexOutOfBoundsException("Index out of bounds: " + index);
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/LatinPlural1Word.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/LatinPlural1Word.java 2021-11-26 13:05:00 UTC (rev 12133)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/LatinPlural1Word.java 2021-11-26 13:44:01 UTC (rev 12134)
@@ -88,9 +88,9 @@
}
@Override
- public int getQtyParaLeafDescendants() {
+ public int paraLeafSize() {
/* We think this wrapper should not change the number of leaf descendants. */
- return getWrappedWord().getQtyParaLeafDescendants();
+ return getWrappedWord().paraLeafSize();
}
@Override
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/LatinPlural2Word.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/LatinPlural2Word.java 2021-11-26 13:05:00 UTC (rev 12133)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/LatinPlural2Word.java 2021-11-26 13:44:01 UTC (rev 12134)
@@ -91,9 +91,9 @@
}
@Override
- public int getQtyParaLeafDescendants() {
+ public int paraLeafSize() {
/* We think this wrapper should not change the number of leaf descendants. */
- return getWrappedWord().getQtyParaLeafDescendants();
+ return getWrappedWord().paraLeafSize();
}
@Override
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/LatinPossessive1Word.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/LatinPossessive1Word.java 2021-11-26 13:05:00 UTC (rev 12133)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/LatinPossessive1Word.java 2021-11-26 13:44:01 UTC (rev 12134)
@@ -89,9 +89,9 @@
}
@Override
- public int getQtyParaLeafDescendants() {
+ public int paraLeafSize() {
/* We think this wrapper should not change the number of leaf descendants. */
- return getWrappedWord().getQtyParaLeafDescendants();
+ return getWrappedWord().paraLeafSize();
}
@Override
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/LatinPossessive2Word.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/LatinPossessive2Word.java 2021-11-26 13:05:00 UTC (rev 12133)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/LatinPossessive2Word.java 2021-11-26 13:44:01 UTC (rev 12134)
@@ -89,9 +89,9 @@
}
@Override
- public int getQtyParaLeafDescendants() {
+ public int paraLeafSize() {
/* We think this wrapper should not change the number of leaf descendants. */
- return this.getWrappedWord().getQtyParaLeafDescendants();
+ return this.getWrappedWord().paraLeafSize();
}
@Override
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/UppercaseWord.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/UppercaseWord.java 2021-11-26 13:05:00 UTC (rev 12133)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/UppercaseWord.java 2021-11-26 13:44:01 UTC (rev 12134)
@@ -92,9 +92,9 @@
}
@Override
- public int getQtyParaLeafDescendants() {
+ public int paraLeafSize() {
/* Converting the word to uppercase does not change the number of leaf descendants. */
- return getWrappedWord().getQtyParaLeafDescendants();
+ return getWrappedWord().paraLeafSize();
}
@Override
Modified: trunk/foray/foray-orthography/src/test/java/org/foray/orthography/HyphenationConsumer4aTests.java
===================================================================
--- trunk/foray/foray-orthography/src/test/java/org/foray/orthography/HyphenationConsumer4aTests.java 2021-11-26 13:05:00 UTC (rev 12133)
+++ trunk/foray/foray-orthography/src/test/java/org/foray/orthography/HyphenationConsumer4aTests.java 2021-11-26 13:44:01 UTC (rev 12134)
@@ -83,27 +83,27 @@
final String testString = "Once more unto the breach, dear friends, once more;";
final ParaBranch4a wordSequence =
this.consumer.tokenizeWordSequence(testString, 0, testString.length());
- Assert.assertEquals(20, wordSequence.getQtyParaNodeChildren());
- Assert.assertEquals("Once", wordSequence.getParaNodeChild(0).toString());
- Assert.assertEquals(" ", wordSequence.getParaNodeChild(1).toString());
- Assert.assertEquals("more", wordSequence.getParaNodeChild(2).toString());
- Assert.assertEquals(" ", wordSequence.getParaNodeChild(3).toString());
- Assert.assertEquals("un-to", wordSequence.getParaNodeChild(4).toString());
- Assert.assertEquals(" ", wordSequence.getParaNodeChild(5).toString());
- Assert.assertEquals("the", wordSequence.getParaNodeChild(6).toString());
- Assert.assertEquals(" ", wordSequence.getParaNodeChild(7).toString());
- Assert.assertEquals("breach", wordSequence.getParaNodeChild(8).toString());
- Assert.assertEquals(",", wordSequence.getParaNodeChild(9).toString());
- Assert.assertEquals(" ", wordSequence.getParaNodeChild(10).toString());
- Assert.assertEquals("dear", wordSequence.getParaNodeChild(11).toString());
- Assert.assertEquals(" ", wordSequence.getParaNodeChild(12).toString());
- Assert.assertEquals("friends", wordSequence.getParaNodeChild(13).toString());
- Assert.assertEquals(",", wordSequence.getParaNodeChild(14).toString());
- Assert.assertEquals(" ", wordSequence.getParaNodeChild(15).toString());
- Assert.assertEquals("once", wordSequence.getParaNodeChild(16).toString());
- Assert.assertEquals(" ", wordSequence.getParaNodeChild(17).toString());
- Assert.assertEquals("more", wordSequence.getParaNodeChild(18).toString());
- Assert.assertEquals(";", wordSequence.getParaNodeChild(19).toString());
+ Assert.assertEquals(20, wordSequence.paraNodeSize());
+ Assert.assertEquals("Once", wordSequence.paraNodeAt(0).toString());
+ Assert.assertEquals(" ", wordSequence.paraNodeAt(1).toString());
+ Assert.assertEquals("more", wordSequence.paraNodeAt(2).toString());
+ Assert.assertEquals(" ", wordSequence.paraNodeAt(3).toString());
+ Assert.assertEquals("un-to", wordSequence.paraNodeAt(4).toString());
+ Assert.assertEquals(" ", wordSequence.paraNodeAt(5).toString());
+ Assert.assertEquals("the", wordSequence.paraNodeAt(6).toString());
+ Assert.assertEquals(" ", wordSequence.paraNodeAt(7).toString());
+ Assert.assertEquals("breach", wordSequence.paraNodeAt(8).toString());
+ Assert.assertEquals(",", wordSequence.paraNodeAt(9).toString());
+ Assert.assertEquals(" ", wordSequence.paraNodeAt(10).toString());
+ Assert.assertEquals("dear", wordSequence.paraNodeAt(11).toString());
+ Assert.assertEquals(" ", wordSequence.paraNodeAt(12).toString());
+ Assert.assertEquals("friends", wordSequence.paraNodeAt(13).toString());
+ Assert.assertEquals(",", wordSequence.paraNodeAt(14).toString());
+ Assert.assertEquals(" ", wordSequence.paraNodeAt(15).toString());
+ Assert.assertEquals("once", wordSequence.paraNodeAt(16).toString());
+ Assert.assertEquals(" ", wordSequence.paraNodeAt(17).toString());
+ Assert.assertEquals("more", wordSequence.paraNodeAt(18).toString());
+ Assert.assertEquals(";", wordSequence.paraNodeAt(19).toString());
}
/**
Modified: trunk/foray/foray-orthography/src/test/java/org/foray/orthography/SegmentDictionaryWordTests.java
===================================================================
--- trunk/foray/foray-orthography/src/test/java/org/foray/orthography/SegmentDictionaryWordTests.java 2021-11-26 13:05:00 UTC (rev 12133)
+++ trunk/foray/foray-orthography/src/test/java/org/foray/orthography/SegmentDictionaryWordTests.java 2021-11-26 13:44:01 UTC (rev 12134)
@@ -82,7 +82,7 @@
*/
@Test
public void getQtyParaNodeChildrenTests() {
- Assert.assertEquals(5, dictionary.getWord("ambition", 0).getQtyParaNodeChildren());
+ Assert.assertEquals(5, dictionary.getWord("ambition", 0).paraNodeSize());
}
/**
@@ -91,13 +91,13 @@
@Test
public void getParaNodeChildTests() {
final SegmentDictionaryWord word = dictionary.getWord("ambition", 0);
- Assert.assertEquals("am", word.getParaNodeChild(0).toString());
- Assert.assertEquals("-", word.getParaNodeChild(1).toString());
- Assert.assertEquals("bi", word.getParaNodeChild(2).toString());
- Assert.assertEquals("-", word.getParaNodeChild(3).toString());
- Assert.assertEquals("tion", word.getParaNodeChild(4).toString());
+ Assert.assertEquals("am", word.paraNodeAt(0).toString());
+ Assert.assertEquals("-", word.paraNodeAt(1).toString());
+ Assert.assertEquals("bi", word.paraNodeAt(2).toString());
+ Assert.assertEquals("-", word.paraNodeAt(3).toString());
+ Assert.assertEquals("tion", word.paraNodeAt(4).toString());
try {
- word.getParaNodeChild(-1);
+ word.paraNodeAt(-1);
Assert.fail("Expected: " + IndexOutOfBoundsException.class.getName());
} catch (final IndexOutOfBoundsException e) {
/* This is the expected path. */
@@ -104,7 +104,7 @@
Assert.assertEquals("-1", e.getMessage());
}
try {
- word.getParaNodeChild(5);
+ word.paraNodeAt(5);
Assert.fail("Expected: " + IndexOutOfBoundsException.class.getName());
} catch (final IndexOutOfBoundsException e) {
/* This is the expected path. */
Modified: trunk/foray/foray-orthography/src/test/java/org/foray/orthography/StringWordTests.java
===================================================================
--- trunk/foray/foray-orthography/src/test/java/org/foray/orthography/StringWordTests.java 2021-11-26 13:05:00 UTC (rev 12133)
+++ trunk/foray/foray-orthography/src/test/java/org/foray/orthography/StringWordTests.java 2021-11-26 13:44:01 UTC (rev 12134)
@@ -115,23 +115,23 @@
@Test
public void paraBranchTest() {
- Assert.assertEquals(7, WORD_PHILOSOPHY.getQtyParaNodeChildren());
- Assert.assertEquals(StringWordSegmentUtf16.class, WORD_PHILOSOPHY.getParaNodeChild(0).getClass());
- Assert.assertEquals(DiscretionaryHyphen4a.class, WORD_PHILOSOPHY.getParaNodeChild(1).getClass());
- Assert.assertEquals(StringWordSegmentUtf16.class, WORD_PHILOSOPHY.getParaNodeChild(2).getClass());
- Assert.assertEquals(DiscretionaryHyphen4a.class, WORD_PHILOSOPHY.getParaNodeChild(3).getClass());
- Assert.assertEquals(StringWordSegmentUtf16.class, WORD_PHILOSOPHY.getParaNodeChild(4).getClass());
- Assert.assertEquals(DiscretionaryHyphen4a.class, WORD_PHILOSOPHY.getParaNodeChild(5).getClass());
- Assert.assertEquals(StringWordSegmentUtf16.class, WORD_PHILOSOPHY.getParaNodeChild(6).getClass());
+ Assert.assertEquals(7, WORD_PHILOSOPHY.paraNodeSize());
+ Assert.assertEquals(StringWordSegmentUtf16.class, WORD_PHILOSOPHY.paraNodeAt(0).getClass());
+ Assert.assertEquals(DiscretionaryHyphen4a.class, WORD_PHILOSOPHY.paraNodeAt(1).getClass());
+ Assert.assertEquals(StringWordSegmentUtf16.class, WORD_PHILOSOPHY.paraNodeAt(2).getClass());
+ Assert.assertEquals(DiscretionaryHyphen4a.class, WORD_PHILOSOPHY.paraNodeAt(3).getClass());
+ Assert.assertEquals(StringWordSegmentUtf16.class, WORD_PHILOSOPHY.paraNodeAt(4).getClass());
+ Assert.assertEquals(DiscretionaryHyphen4a.class, WORD_PHILOSOPHY.paraNodeAt(5).getClass());
+ Assert.assertEquals(StringWordSegmentUtf16.class, WORD_PHILOSOPHY.paraNodeAt(6).getClass());
- Assert.assertEquals("phi", WORD_PHILOSOPHY.getParaNodeChild(0).asParaLeaf().getText());
- Assert.assertEquals("los", WORD_PHILOSOPHY.getParaNodeChild(2).asParaLeaf().getText());
- Assert.assertEquals("o", WORD_PHILOSOPHY.getParaNodeChild(4).asParaLeaf().getText());
- Assert.assertEquals("phy", WORD_PHILOSOPHY.getParaNodeChild(6).asParaLeaf().getText());
+ Assert.assertEquals("phi", WORD_PHILOSOPHY.paraNodeAt(0).asParaLeaf().getText());
+ Assert.assertEquals("los", WORD_PHILOSOPHY.paraNodeAt(2).asParaLeaf().getText());
+ Assert.assertEquals("o", WORD_PHILOSOPHY.paraNodeAt(4).asParaLeaf().getText());
+ Assert.assertEquals("phy", WORD_PHILOSOPHY.paraNodeAt(6).asParaLeaf().getText());
/* Test an index that is too low. */
try {
- WORD_PHILOSOPHY.getParaNodeChild(-1);
+ WORD_PHILOSOPHY.paraNodeAt(-1);
Assert.fail("Should throw an IndexOutOfBoundsException.");
} catch (final IndexOutOfBoundsException e) {
/* This is the expected path. */
@@ -140,7 +140,7 @@
/* Test an index that is too high. */
try {
- WORD_PHILOSOPHY.getParaNodeChild(7);
+ WORD_PHILOSOPHY.paraNodeAt(7);
Assert.fail("Should throw an IndexOutOfBoundsException.");
} catch (final IndexOutOfBoundsException e) {
/* This is the expected path. */
Modified: trunk/foray/foray-orthography/src/test/java/org/foray/orthography/WordWrapperTests.java
===================================================================
--- trunk/foray/foray-orthography/src/test/java/org/foray/orthography/WordWrapperTests.java 2021-11-26 13:05:00 UTC (rev 12133)
+++ trunk/foray/foray-orthography/src/test/java/org/foray/orthography/WordWrapperTests.java 2021-11-26 13:44:01 UTC (rev 12134)
@@ -283,27 +283,27 @@
}
/**
- * Test method for {@link org.foray.orthography.WordWrapper#getQtyParaNodeChildren()}.
+ * Test method for {@link org.foray.orthography.WordWrapper#paraNodeSize()}.
*/
@Test
public void testGetQtyParaNodeChildren() {
- Assert.assertEquals(7, this.out.getQtyParaNodeChildren());
+ Assert.assertEquals(7, this.out.paraNodeSize());
}
/**
- * Test method for {@link org.foray.orthography.WordWrapper#getParaNodeChild(int)}.
+ * Test method for {@link org.foray.orthography.WordWrapper#paraNodeAt(int)}.
*/
@Test
- public void testGetParaNodeChild() {
- Assert.assertEquals("har", this.out.getParaNodeChild(0).toString());
- Assert.assertEquals("-", this.out.getParaNodeChild(1).toString());
- Assert.assertEquals("mo", this.out.getParaNodeChild(2).toString());
- Assert.assertEquals("-", this.out.getParaNodeChild(3).toString());
- Assert.assertEquals("ni", this.out.getParaNodeChild(4).toString());
- Assert.assertEquals("-", this.out.getParaNodeChild(5).toString());
- Assert.assertEquals("ous", this.out.getParaNodeChild(6).toString());
+ public void testParaNodeAt() {
+ Assert.assertEquals("har", this.out.paraNodeAt(0).toString());
+ Assert.assertEquals("-", this.out.paraNodeAt(1).toString());
+ Assert.assertEquals("mo", this.out.paraNodeAt(2).toString());
+ Assert.assertEquals("-", this.out.paraNodeAt(3).toString());
+ Assert.assertEquals("ni", this.out.paraNodeAt(4).toString());
+ Assert.assertEquals("-", this.out.paraNodeAt(5).toString());
+ Assert.assertEquals("ous", this.out.paraNodeAt(6).toString());
try {
- this.out.getParaNodeChild(-1);
+ this.out.paraNodeAt(-1);
Assert.fail("Expected: " + IndexOutOfBoundsException.class.getName());
} catch (final IndexOutOfBoundsException e) {
/* This is the expected path. */
@@ -310,7 +310,7 @@
Assert.assertEquals("-1", e.getMessage());
}
try {
- this.out.getParaNodeChild(7);
+ this.out.paraNodeAt(7);
Assert.fail("Expected: " + IndexOutOfBoundsException.class.getName());
} catch (final IndexOutOfBoundsException e) {
/* This is the expected path. */
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-11-26 13:05:02
|
Revision: 12133
http://sourceforge.net/p/foray/code/12133
Author: victormote
Date: 2021-11-26 13:05:00 +0000 (Fri, 26 Nov 2021)
Log Message:
-----------
Correct the leaf node computation for words.
Modified Paths:
--------------
trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/LineBreaker4aTests.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/StringWord.java
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-26 12:32:38 UTC (rev 12132)
+++ trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/LineBreaker4aTests.java 2021-11-26 13:05:00 UTC (rev 12133)
@@ -210,9 +210,19 @@
* ===== ===== */
Assert.assertEquals(238, para.getQtyParaNodeChildren());
- /* Of the words added, 12 are two-syllable, and 2 are three-syllable, which should add
- * (13 x 1) + (2 x 2) = 17 additional leaf nodes. */
- Assert.assertEquals(255, para.getQtyParaLeafDescendants());
+ /* Of the words added, 13 are two-syllable, and 2 are three-syllable.
+ * If "n" is the number of syllables in a word, the total number of nodes in each word is ((2 * n) - 1).
+ * In other words each syllable is a node for itself and a node for the discretionary hyphen that follows it.
+ * We subtract one because there is neither a discretionary hyphen at the beginning or end of a word.
+ * Therefore the two-syllable words have 3 nodes and the three-syllable words have 5.
+ * We already counted one of these nodes above for each case, so the number of additional nodes is:
+ * 13 * 2 = 26
+ * 2 * 4 = 8
+ * ----
+ * 34
+ * ====
+ */
+ Assert.assertEquals(272, para.getQtyParaLeafDescendants());
return para;
}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/StringWord.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/StringWord.java 2021-11-26 12:32:38 UTC (rev 12132)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/StringWord.java 2021-11-26 13:05:00 UTC (rev 12133)
@@ -28,8 +28,11 @@
package org.foray.orthography;
+import org.foray.common.para.DiscretionaryHyphen4a;
import org.foray.common.primitive.CharSequenceUtils;
+import org.foray.common.primitive.NumberUtils;
+import org.axsl.common.para.DiscretionaryHyphen;
import org.axsl.common.para.ParaLeaf;
/**
@@ -123,13 +126,25 @@
@Override
public int getQtyParaLeafDescendants() {
- return this.segments.length;
+ /* Each segment is 2 nodes, one for the segment, one for the discretionary hyphen that follows it, except that
+ * the last segment is not followed by a discretionary hyphen. */
+ return (2 * this.segments.length) - 1;
}
@Override
- public ParaLeaf paraLeafAt(final int index) {
- // TODO Auto-generated method stub
- return null;
+ public ParaLeaf paraLeafAt(final int leafIndex) {
+ if (leafIndex < 0
+ || leafIndex >= getQtyParaLeafDescendants()) {
+ throw new IndexOutOfBoundsException("Index out of bounds: " + leafIndex);
+ }
+
+ /* Every even-numbered index points to a segment of this word. Every odd-numbered index points to a
+ * discretionary hyphen. */
+ if (NumberUtils.isOdd(leafIndex)) {
+ return DiscretionaryHyphen4a.fromQuality(DiscretionaryHyphen.Quality.GOOD);
+ }
+ final int segmentIndex = leafIndex / 2;
+ return this.segments[segmentIndex];
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-11-26 12:32:40
|
Revision: 12132
http://sourceforge.net/p/foray/code/12132
Author: victormote
Date: 2021-11-26 12:32:38 +0000 (Fri, 26 Nov 2021)
Log Message:
-----------
Move some utility code not needed in LB tests over to Orthography.
Modified Paths:
--------------
trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/LbTestUtilities.java
Added Paths:
-----------
trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/FirstFitLbTests.java
trunk/foray/foray-orthography/src/test/java/org/foray/orthography/OrthographyTestUtilities.java
Added: trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/FirstFitLbTests.java
===================================================================
--- trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/FirstFitLbTests.java (rev 0)
+++ trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/FirstFitLbTests.java 2021-11-26 12:32:38 UTC (rev 12132)
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2019 The FOray Project.
+ * http://www.foray.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.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.linebreak;
+
+import org.foray.common.para.ParaBranch4a;
+
+import org.axsl.common.para.DiscretionaryHyphen;
+import org.axsl.common.para.ParaControl;
+import org.axsl.linebreak.LineBreakControl;
+import org.axsl.linebreak.OutputLine;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+/**
+ * Tests of {@link TotalFitLb}.
+ */
+public class FirstFitLbTests extends LineBreaker4aTests {
+
+ /**
+ * A test.
+ */
+ @Test
+ public void bestFitTest1() {
+ /* TODO: THE CLASS BEING TESTED IS VERY INCOMPLETE, AND SO IS THIS TEST !!!!!! */
+
+ final ParaBranch4a content = this.createPara();
+ final LineBreakControl lbControl = Mockito.mock(LineBreakControl.class);
+ final OutputLine lineOutput = Mockito.mock(OutputLine.class);
+ /* Page is 8.5 inches wide, 1 inch margin on both ends, leaving 6.5 inches, or 468,000 millipoints. */
+ Mockito.when(lineOutput.capacityTotal()).thenReturn(468000);
+ Mockito.when(lbControl.getOutputLine(Mockito.anyInt())).thenReturn(lineOutput);
+ final ParaControl paraControl = Mockito.mock(ParaControl.class);
+ Mockito.when(paraControl.getCost(Mockito.any(DiscretionaryHyphen.Quality.class))).thenReturn(50);
+ final TotalFitLb out = new TotalFitLb();
+ final int[] actual = out.breakIntoLines(content, paraControl, lbControl);
+
+
+ final int[] expected = new int[0];
+//// final int[] expectedArray = {};
+//// expected.add(new OrderedTreePath4a(new IntArray(expectedArray)));
+ Assert.assertArrayEquals(expected, actual);
+ }
+
+}
Property changes on: trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/FirstFitLbTests.java
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Rev
\ No newline at end of property
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-25 22:15:38 UTC (rev 12131)
+++ trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/LbTestUtilities.java 2021-11-26 12:32:38 UTC (rev 12132)
@@ -28,17 +28,11 @@
package org.foray.linebreak;
-import org.foray.common.Environment;
import org.foray.common.sequence.IntArrayBuilder;
import org.foray.font.util.MockFont;
-import org.foray.orthography.OrthographyServerConfig;
import org.axsl.font.Font;
-import java.io.IOException;
-import java.net.URL;
-import java.util.Properties;
-
/**
* Utilities for Linebreaking tests.
*/
@@ -131,39 +125,4 @@
return font;
}
- /**
- * Creates a hyphenation server configuration that can be used for tests.
- * @return the hyphenation server configuration.
- * @throws IOException For errors creating the URLs.
- */
- public static OrthographyServerConfig createHyphenationServerConfig() throws IOException {
- final Properties buildProperties = Environment.getBuildProperties();
- final String foraySandbox = buildProperties.getProperty("foray.sandbox");
-
- final String orthographyConfigPath =
- foraySandbox + "/foray-orthography/src/test/resources/orthography-config.xml";
- final String wordListDirString = foraySandbox + "/foray-orthography/src/main/data/word-lists/";
- final String dictionaryDirString =
- foraySandbox + "/foray-orthography/src/main/resources/resources/org/foray/orthography/dictionaries/";
- final String rawPatternsDirString = foraySandbox + "/foray-orthography/src/main/data/hyph-patterns/";
- final String serializedPatternsDirString =
- foraySandbox + "/foray-orthography/src/main/resources/resources/org/foray/orthography/dictionaries";
- final String naturalLanguageDirString = foraySandbox + "/foray-orthography/src/main/data/natural-languages/";
-
- final URL orthographyFile = new URL("file", null, orthographyConfigPath);
- final URL rawDictionary = new URL("file", null, wordListDirString);
- final URL parsedDictionary = new URL("file", null, dictionaryDirString);
- final URL rawPatterns = new URL("file", null, rawPatternsDirString);
- final URL parsedPatterns = new URL("file", null, serializedPatternsDirString);
- final URL naturalLanguageDir = new URL("file", null, naturalLanguageDirString);
-
- final OrthographyServerConfig config = new OrthographyServerConfig();
- config.setOrthographyConfigurationLocation(orthographyFile);
- config.setWordListsBaseDirectory(rawDictionary);
- config.setSerializedDictionariesBaseDirectory(parsedDictionary);
- config.setRawHyphenationPatternsBaseDirectory(rawPatterns);
- config.setSerializedHyphenationPatternsBaseDirectory(parsedPatterns);
- config.setNaturalLanguagesBaseDirectory(naturalLanguageDir);
- return config;
- }
}
Added: trunk/foray/foray-orthography/src/test/java/org/foray/orthography/OrthographyTestUtilities.java
===================================================================
--- trunk/foray/foray-orthography/src/test/java/org/foray/orthography/OrthographyTestUtilities.java (rev 0)
+++ trunk/foray/foray-orthography/src/test/java/org/foray/orthography/OrthographyTestUtilities.java 2021-11-26 12:32:38 UTC (rev 12132)
@@ -0,0 +1,85 @@
+/*
+ * Copyright 2021 The FOray Project.
+ * http://www.foray.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.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.orthography;
+
+import org.foray.common.Environment;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.Properties;
+
+/**
+ * Utilities classes related to using the orthography system in tests.
+ * These may be most useful in testing classes in other modules.
+ */
+public final class OrthographyTestUtilities {
+
+ /**
+ * Private constructor.
+ * This utility class should never be instantiated.
+ */
+ private OrthographyTestUtilities() { }
+
+ /**
+ * Creates an orthography server that can be used for tests.
+ * @return The orthography server.
+ * @throws IOException For errors creating the URLs.
+ */
+ public static OrthographyServerConfig createOrthographyServer() throws IOException {
+ final Properties buildProperties = Environment.getBuildProperties();
+ final String foraySandbox = buildProperties.getProperty("foray.sandbox");
+
+ final String orthographyConfigPath =
+ foraySandbox + "/foray-orthography/src/test/resources/orthography-config.xml";
+ final String wordListDirString = foraySandbox + "/foray-orthography/src/main/data/word-lists/";
+ final String dictionaryDirString =
+ foraySandbox + "/foray-orthography/src/main/resources/resources/org/foray/orthography/dictionaries/";
+ final String rawPatternsDirString = foraySandbox + "/foray-orthography/src/main/data/hyph-patterns/";
+ final String serializedPatternsDirString =
+ foraySandbox + "/foray-orthography/src/main/resources/resources/org/foray/orthography/dictionaries";
+ final String naturalLanguageDirString = foraySandbox + "/foray-orthography/src/main/data/natural-languages/";
+
+ final URL orthographyFile = new URL("file", null, orthographyConfigPath);
+ final URL rawDictionary = new URL("file", null, wordListDirString);
+ final URL parsedDictionary = new URL("file", null, dictionaryDirString);
+ final URL rawPatterns = new URL("file", null, rawPatternsDirString);
+ final URL parsedPatterns = new URL("file", null, serializedPatternsDirString);
+ final URL naturalLanguageDir = new URL("file", null, naturalLanguageDirString);
+
+ final OrthographyServerConfig config = new OrthographyServerConfig();
+ config.setOrthographyConfigurationLocation(orthographyFile);
+ config.setWordListsBaseDirectory(rawDictionary);
+ config.setSerializedDictionariesBaseDirectory(parsedDictionary);
+ config.setRawHyphenationPatternsBaseDirectory(rawPatterns);
+ config.setSerializedHyphenationPatternsBaseDirectory(parsedPatterns);
+ config.setNaturalLanguagesBaseDirectory(naturalLanguageDir);
+ return config;
+ }
+
+}
Property changes on: trunk/foray/foray-orthography/src/test/java/org/foray/orthography/OrthographyTestUtilities.java
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Rev
\ No newline at end of property
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-11-25 22:15:41
|
Revision: 12131
http://sourceforge.net/p/foray/code/12131
Author: victormote
Date: 2021-11-25 22:15:38 +0000 (Thu, 25 Nov 2021)
Log Message:
-----------
Conform to aXSL changes: Add methods paraLeafAt() an iterator() that provide a view of the ParaBranch as a sequence of leaves. Also, simplify the LineBreaker interface to use indexes to these leaf nodes.
Modified Paths:
--------------
trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaBranch4a.java
trunk/foray/foray-linebreak/src/main/java/org/foray/linebreak/BestFitLb.java
trunk/foray/foray-linebreak/src/main/java/org/foray/linebreak/FirstFitLb.java
trunk/foray/foray-linebreak/src/main/java/org/foray/linebreak/TotalFitLb.java
trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/TotalFitLbTests.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/Word4a.java
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaBranch4a.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaBranch4a.java 2021-11-25 17:06:58 UTC (rev 12130)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaBranch4a.java 2021-11-25 22:15:38 UTC (rev 12131)
@@ -35,6 +35,7 @@
import java.util.ArrayList;
import java.util.List;
+import java.util.ListIterator;
/**
* FOray implementation of {@link ParaBranch}.
@@ -135,4 +136,10 @@
this.config = config;
}
+ @Override
+ public ListIterator<ParaLeaf> iterator() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
}
Modified: trunk/foray/foray-linebreak/src/main/java/org/foray/linebreak/BestFitLb.java
===================================================================
--- trunk/foray/foray-linebreak/src/main/java/org/foray/linebreak/BestFitLb.java 2021-11-25 17:06:58 UTC (rev 12130)
+++ trunk/foray/foray-linebreak/src/main/java/org/foray/linebreak/BestFitLb.java 2021-11-25 22:15:38 UTC (rev 12131)
@@ -28,13 +28,10 @@
package org.foray.linebreak;
-import org.axsl.common.data.OrderedTreePath;
import org.axsl.common.para.ParaBranch;
import org.axsl.common.para.ParaControl;
import org.axsl.linebreak.LineBreakControl;
-import java.util.List;
-
/**
* Implementation of the Knuth-Plass "best-fit" linebreaking algorithm.
* @see "Knuth, Digital Typography, 1999, p. 8"
@@ -42,7 +39,7 @@
public class BestFitLb extends LineBreaker4a {
@Override
- public List<? extends OrderedTreePath> breakIntoLines(final ParaBranch paragraph, final ParaControl paraControl,
+ public int[] breakIntoLines(final ParaBranch paragraph, final ParaControl paraControl,
final LineBreakControl lbControl) {
return null;
}
Modified: trunk/foray/foray-linebreak/src/main/java/org/foray/linebreak/FirstFitLb.java
===================================================================
--- trunk/foray/foray-linebreak/src/main/java/org/foray/linebreak/FirstFitLb.java 2021-11-25 17:06:58 UTC (rev 12130)
+++ trunk/foray/foray-linebreak/src/main/java/org/foray/linebreak/FirstFitLb.java 2021-11-25 22:15:38 UTC (rev 12131)
@@ -28,13 +28,10 @@
package org.foray.linebreak;
-import org.axsl.common.data.OrderedTreePath;
import org.axsl.common.para.ParaBranch;
import org.axsl.common.para.ParaControl;
import org.axsl.linebreak.LineBreakControl;
-import java.util.List;
-
/**
* Implementation of the Knuth-Plass first-fit linebreaking algorithm.
* @see "Knuth, Digital Typography, 1999, pp. 74, 78"
@@ -42,7 +39,7 @@
public class FirstFitLb extends LineBreaker4a {
@Override
- public List<? extends OrderedTreePath> breakIntoLines(final ParaBranch paragraph, final ParaControl paraControl,
+ public int[] breakIntoLines(final ParaBranch paragraph, final ParaControl paraControl,
final LineBreakControl lbControl) {
return null;
}
Modified: trunk/foray/foray-linebreak/src/main/java/org/foray/linebreak/TotalFitLb.java
===================================================================
--- trunk/foray/foray-linebreak/src/main/java/org/foray/linebreak/TotalFitLb.java 2021-11-25 17:06:58 UTC (rev 12130)
+++ trunk/foray/foray-linebreak/src/main/java/org/foray/linebreak/TotalFitLb.java 2021-11-25 22:15:38 UTC (rev 12131)
@@ -99,14 +99,14 @@
private int cumulativeShrink;
@Override
- public List<OrderedTreePath4a> breakIntoLines(final ParaBranch paragraph, final ParaControl paraControl,
+ public int[] breakIntoLines(final ParaBranch paragraph, final ParaControl paraControl,
final LineBreakControl lbControl) {
this.paragraph = paragraph;
this.paraControl = paraControl;
this.lbControl = lbControl;
- final List<OrderedTreePath4a> returnValue = new ArrayList<OrderedTreePath4a>();
+ final IntArrayBuilder returnValue = new IntArrayBuilder();
if (paragraph == null) {
- return returnValue;
+ return returnValue.toArray();
}
/* Initialize the data structures. */
@@ -138,7 +138,7 @@
// for (LbBreakpoint bp : this.activeNodes) {
// returnValue.add(bp.getNodeWrapper().getPath());
// }
- return returnValue;
+ return returnValue.toArray();
}
/**
Modified: trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/TotalFitLbTests.java
===================================================================
--- trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/TotalFitLbTests.java 2021-11-25 17:06:58 UTC (rev 12130)
+++ trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/TotalFitLbTests.java 2021-11-25 22:15:38 UTC (rev 12131)
@@ -28,7 +28,6 @@
package org.foray.linebreak;
-import org.foray.common.data.OrderedTreePath4a;
import org.foray.common.para.ParaBranch4a;
import org.axsl.common.para.DiscretionaryHyphen;
@@ -40,9 +39,6 @@
import org.junit.Test;
import org.mockito.Mockito;
-import java.util.ArrayList;
-import java.util.List;
-
/**
* Tests of {@link TotalFitLb}.
*/
@@ -64,13 +60,13 @@
final ParaControl paraControl = Mockito.mock(ParaControl.class);
Mockito.when(paraControl.getCost(Mockito.any(DiscretionaryHyphen.Quality.class))).thenReturn(50);
final TotalFitLb out = new TotalFitLb();
- final List<OrderedTreePath4a> actual = out.breakIntoLines(content, paraControl, lbControl);
+ final int[] actual = out.breakIntoLines(content, paraControl, lbControl);
- final List<OrderedTreePath4a> expected = new ArrayList<OrderedTreePath4a>();
+ final int[] expected = new int[0];
//// final int[] expectedArray = {};
//// expected.add(new OrderedTreePath4a(new IntArray(expectedArray)));
- Assert.assertArrayEquals(expected.toArray(), actual.toArray());
+ Assert.assertArrayEquals(expected, actual);
}
}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/Word4a.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/Word4a.java 2021-11-25 17:06:58 UTC (rev 12130)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/Word4a.java 2021-11-25 22:15:38 UTC (rev 12131)
@@ -42,6 +42,7 @@
import org.axsl.orthography.WordSegment;
import java.io.Serializable;
+import java.util.ListIterator;
/**
* <p>Abstract superclass for FOray implementations of {@link Word}, providing some default implementation.</p>
@@ -268,4 +269,10 @@
return CharSequenceUtils.compare(this, o);
}
+ @Override
+ public ListIterator<ParaLeaf> iterator() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-11-25 17:07:01
|
Revision: 12130
http://sourceforge.net/p/foray/code/12130
Author: victormote
Date: 2021-11-25 17:06:58 +0000 (Thu, 25 Nov 2021)
Log Message:
-----------
Partially conform to aXSL change: Allow random access to individual leaf descendants in ParaBranch.
Modified Paths:
--------------
trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaBranch4a.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/SegmentDictionaryWord.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/StringWord.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/CapitalizedWord.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/ExactWord.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/LatinPast1Word.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/LatinPlural1Word.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/LatinPlural2Word.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/LatinPossessive1Word.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/LatinPossessive2Word.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/UppercaseWord.java
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaBranch4a.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaBranch4a.java 2021-11-25 16:15:08 UTC (rev 12129)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaBranch4a.java 2021-11-25 17:06:58 UTC (rev 12130)
@@ -97,6 +97,12 @@
}
@Override
+ public ParaLeaf paraLeafAt(final int index) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
public ParaConfig getParaConfig() {
return this.config;
}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/SegmentDictionaryWord.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/SegmentDictionaryWord.java 2021-11-25 16:15:08 UTC (rev 12129)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/SegmentDictionaryWord.java 2021-11-25 17:06:58 UTC (rev 12130)
@@ -28,6 +28,7 @@
package org.foray.orthography;
+import org.axsl.common.para.ParaLeaf;
import org.axsl.orthography.Word;
import org.axsl.orthography.WordSegment;
@@ -112,4 +113,10 @@
return this.segments.length;
}
+ @Override
+ public ParaLeaf paraLeafAt(final int index) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/StringWord.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/StringWord.java 2021-11-25 16:15:08 UTC (rev 12129)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/StringWord.java 2021-11-25 17:06:58 UTC (rev 12130)
@@ -30,6 +30,8 @@
import org.foray.common.primitive.CharSequenceUtils;
+import org.axsl.common.para.ParaLeaf;
+
/**
* A word implementation that wraps a set of {@link StringWordSegmentUtf16}, a thin wrapper around a {@link String}.
* Instances of this class are immutable.
@@ -124,4 +126,10 @@
return this.segments.length;
}
+ @Override
+ public ParaLeaf paraLeafAt(final int index) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/CapitalizedWord.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/CapitalizedWord.java 2021-11-25 16:15:08 UTC (rev 12129)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/CapitalizedWord.java 2021-11-25 17:06:58 UTC (rev 12130)
@@ -30,6 +30,7 @@
import org.foray.orthography.WordSegmentWrapper;
+import org.axsl.common.para.ParaLeaf;
import org.axsl.orthography.Word;
import org.axsl.orthography.WordSegment;
@@ -105,4 +106,9 @@
return this.getWrappedWord().getQtyParaLeafDescendants();
}
+ @Override
+ public ParaLeaf paraLeafAt(final int index) {
+ return this.getWrappedWord().paraLeafAt(index);
+ }
+
}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/ExactWord.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/ExactWord.java 2021-11-25 16:15:08 UTC (rev 12129)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/ExactWord.java 2021-11-25 17:06:58 UTC (rev 12130)
@@ -32,6 +32,7 @@
import org.foray.orthography.StringWord;
import org.foray.orthography.StringWordSegmentUtf16;
+import org.axsl.common.para.ParaLeaf;
import org.axsl.orthography.Word;
import org.axsl.orthography.WordSegment;
@@ -88,4 +89,9 @@
return this.getWrappedWord().getQtyParaLeafDescendants();
}
+ @Override
+ public ParaLeaf paraLeafAt(final int index) {
+ return this.getWrappedWord().paraLeafAt(index);
+ }
+
}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/LatinPast1Word.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/LatinPast1Word.java 2021-11-25 16:15:08 UTC (rev 12129)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/LatinPast1Word.java 2021-11-25 17:06:58 UTC (rev 12130)
@@ -30,6 +30,7 @@
import org.foray.orthography.StringWordSegmentUtf16;
+import org.axsl.common.para.ParaLeaf;
import org.axsl.orthography.Word;
/**
@@ -63,4 +64,15 @@
return this.getWrappedWord().getQtyParaLeafDescendants() + 1;
}
+ @Override
+ public ParaLeaf paraLeafAt(final int index) {
+ if (index < getWrappedWord().getQtyParaLeafDescendants()) {
+ return getWrappedWord().paraLeafAt(index);
+ }
+ if (index == getWrappedWord().getQtyParaLeafDescendants()) {
+ return SUFFIX;
+ }
+ throw new IndexOutOfBoundsException("Index out of bounds: " + index);
+ }
+
}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/LatinPlural1Word.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/LatinPlural1Word.java 2021-11-25 16:15:08 UTC (rev 12129)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/LatinPlural1Word.java 2021-11-25 17:06:58 UTC (rev 12130)
@@ -28,6 +28,7 @@
package org.foray.orthography.wrapper;
+import org.axsl.common.para.ParaLeaf;
import org.axsl.orthography.Word;
import org.axsl.orthography.WordSegment;
@@ -89,7 +90,12 @@
@Override
public int getQtyParaLeafDescendants() {
/* We think this wrapper should not change the number of leaf descendants. */
- return this.getWrappedWord().getQtyParaLeafDescendants();
+ return getWrappedWord().getQtyParaLeafDescendants();
}
+ @Override
+ public ParaLeaf paraLeafAt(final int index) {
+ return getWrappedWord().paraLeafAt(index);
+ }
+
}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/LatinPlural2Word.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/LatinPlural2Word.java 2021-11-25 16:15:08 UTC (rev 12129)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/LatinPlural2Word.java 2021-11-25 17:06:58 UTC (rev 12130)
@@ -28,6 +28,7 @@
package org.foray.orthography.wrapper;
+import org.axsl.common.para.ParaLeaf;
import org.axsl.orthography.Word;
import org.axsl.orthography.WordSegment;
@@ -92,7 +93,12 @@
@Override
public int getQtyParaLeafDescendants() {
/* We think this wrapper should not change the number of leaf descendants. */
- return this.getWrappedWord().getQtyParaLeafDescendants();
+ return getWrappedWord().getQtyParaLeafDescendants();
}
+ @Override
+ public ParaLeaf paraLeafAt(final int index) {
+ return getWrappedWord().paraLeafAt(index);
+ }
+
}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/LatinPossessive1Word.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/LatinPossessive1Word.java 2021-11-25 16:15:08 UTC (rev 12129)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/LatinPossessive1Word.java 2021-11-25 17:06:58 UTC (rev 12130)
@@ -28,6 +28,7 @@
package org.foray.orthography.wrapper;
+import org.axsl.common.para.ParaLeaf;
import org.axsl.orthography.Word;
import org.axsl.orthography.WordSegment;
@@ -90,7 +91,12 @@
@Override
public int getQtyParaLeafDescendants() {
/* We think this wrapper should not change the number of leaf descendants. */
- return this.getWrappedWord().getQtyParaLeafDescendants();
+ return getWrappedWord().getQtyParaLeafDescendants();
}
+ @Override
+ public ParaLeaf paraLeafAt(final int index) {
+ return getWrappedWord().paraLeafAt(index);
+ }
+
}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/LatinPossessive2Word.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/LatinPossessive2Word.java 2021-11-25 16:15:08 UTC (rev 12129)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/LatinPossessive2Word.java 2021-11-25 17:06:58 UTC (rev 12130)
@@ -28,6 +28,7 @@
package org.foray.orthography.wrapper;
+import org.axsl.common.para.ParaLeaf;
import org.axsl.orthography.Word;
import org.axsl.orthography.WordSegment;
@@ -93,4 +94,9 @@
return this.getWrappedWord().getQtyParaLeafDescendants();
}
+ @Override
+ public ParaLeaf paraLeafAt(final int index) {
+ return getWrappedWord().paraLeafAt(index);
+ }
+
}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/UppercaseWord.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/UppercaseWord.java 2021-11-25 16:15:08 UTC (rev 12129)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/UppercaseWord.java 2021-11-25 17:06:58 UTC (rev 12130)
@@ -30,6 +30,7 @@
import org.foray.orthography.WordSegmentWrapper;
+import org.axsl.common.para.ParaLeaf;
import org.axsl.orthography.Word;
import org.axsl.orthography.WordSegment;
@@ -93,7 +94,12 @@
@Override
public int getQtyParaLeafDescendants() {
/* Converting the word to uppercase does not change the number of leaf descendants. */
- return this.getWrappedWord().getQtyParaLeafDescendants();
+ return getWrappedWord().getQtyParaLeafDescendants();
}
+ @Override
+ public ParaLeaf paraLeafAt(final int index) {
+ return getWrappedWord().paraLeafAt(index);
+ }
+
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-11-25 16:15:11
|
Revision: 12129
http://sourceforge.net/p/foray/code/12129
Author: victormote
Date: 2021-11-25 16:15:08 +0000 (Thu, 25 Nov 2021)
Log Message:
-----------
Create classes for the first-fit and best-fit algorithms, a superclass for all three implementations, and a similar structure for tests.
Modified Paths:
--------------
trunk/foray/foray-linebreak/src/main/java/org/foray/linebreak/TotalFitLb.java
trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/TotalFitLbTests.java
trunk/foray/foray-orthography/src/main/data/dictionaries/eng-Latn-999.dict.xml
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/DictionaryResource.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/OrthographyResource.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/DictionaryParser.java
Added Paths:
-----------
trunk/foray/foray-linebreak/src/main/java/org/foray/linebreak/BestFitLb.java
trunk/foray/foray-linebreak/src/main/java/org/foray/linebreak/FirstFitLb.java
trunk/foray/foray-linebreak/src/main/java/org/foray/linebreak/LineBreaker4a.java
trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/LineBreaker4aTests.java
Added: trunk/foray/foray-linebreak/src/main/java/org/foray/linebreak/BestFitLb.java
===================================================================
--- trunk/foray/foray-linebreak/src/main/java/org/foray/linebreak/BestFitLb.java (rev 0)
+++ trunk/foray/foray-linebreak/src/main/java/org/foray/linebreak/BestFitLb.java 2021-11-25 16:15:08 UTC (rev 12129)
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2021 The FOray Project.
+ * http://www.foray.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.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.linebreak;
+
+import org.axsl.common.data.OrderedTreePath;
+import org.axsl.common.para.ParaBranch;
+import org.axsl.common.para.ParaControl;
+import org.axsl.linebreak.LineBreakControl;
+
+import java.util.List;
+
+/**
+ * Implementation of the Knuth-Plass "best-fit" linebreaking algorithm.
+ * @see "Knuth, Digital Typography, 1999, p. 8"
+ */
+public class BestFitLb extends LineBreaker4a {
+
+ @Override
+ public List<? extends OrderedTreePath> breakIntoLines(final ParaBranch paragraph, final ParaControl paraControl,
+ final LineBreakControl lbControl) {
+ return null;
+ }
+
+}
Property changes on: trunk/foray/foray-linebreak/src/main/java/org/foray/linebreak/BestFitLb.java
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Rev
\ No newline at end of property
Added: trunk/foray/foray-linebreak/src/main/java/org/foray/linebreak/FirstFitLb.java
===================================================================
--- trunk/foray/foray-linebreak/src/main/java/org/foray/linebreak/FirstFitLb.java (rev 0)
+++ trunk/foray/foray-linebreak/src/main/java/org/foray/linebreak/FirstFitLb.java 2021-11-25 16:15:08 UTC (rev 12129)
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2021 The FOray Project.
+ * http://www.foray.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.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.linebreak;
+
+import org.axsl.common.data.OrderedTreePath;
+import org.axsl.common.para.ParaBranch;
+import org.axsl.common.para.ParaControl;
+import org.axsl.linebreak.LineBreakControl;
+
+import java.util.List;
+
+/**
+ * Implementation of the Knuth-Plass first-fit linebreaking algorithm.
+ * @see "Knuth, Digital Typography, 1999, pp. 74, 78"
+ */
+public class FirstFitLb extends LineBreaker4a {
+
+ @Override
+ public List<? extends OrderedTreePath> breakIntoLines(final ParaBranch paragraph, final ParaControl paraControl,
+ final LineBreakControl lbControl) {
+ return null;
+ }
+
+}
Property changes on: trunk/foray/foray-linebreak/src/main/java/org/foray/linebreak/FirstFitLb.java
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Rev
\ No newline at end of property
Added: trunk/foray/foray-linebreak/src/main/java/org/foray/linebreak/LineBreaker4a.java
===================================================================
--- trunk/foray/foray-linebreak/src/main/java/org/foray/linebreak/LineBreaker4a.java (rev 0)
+++ trunk/foray/foray-linebreak/src/main/java/org/foray/linebreak/LineBreaker4a.java 2021-11-25 16:15:08 UTC (rev 12129)
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2021 The FOray Project.
+ * http://www.foray.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.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.linebreak;
+
+import org.axsl.linebreak.LineBreaker;
+
+public abstract class LineBreaker4a implements LineBreaker {
+
+ /** Magic number used in demerit computation to help normalize adjustment ratios and penalties. */
+ protected static final int DEMERIT_COMPUTATION_COEFFICIENT = 100;
+
+ /** The initial size for the feasible breaks list. */
+ protected static final int INITIAL_FEASIBLE_BREAKS_SIZE = 20;
+
+ /** The initial size for the content nodes list. */
+ protected static final int INITIAL_CONTENT_NODES_SIZE = 100;
+
+}
Property changes on: trunk/foray/foray-linebreak/src/main/java/org/foray/linebreak/LineBreaker4a.java
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Rev
\ No newline at end of property
Modified: trunk/foray/foray-linebreak/src/main/java/org/foray/linebreak/TotalFitLb.java
===================================================================
--- trunk/foray/foray-linebreak/src/main/java/org/foray/linebreak/TotalFitLb.java 2021-11-24 15:22:56 UTC (rev 12128)
+++ trunk/foray/foray-linebreak/src/main/java/org/foray/linebreak/TotalFitLb.java 2021-11-25 16:15:08 UTC (rev 12129)
@@ -44,7 +44,6 @@
import org.axsl.common.para.ParaPenalty;
import org.axsl.linebreak.KpFitnessClass;
import org.axsl.linebreak.LineBreakControl;
-import org.axsl.linebreak.LineBreaker;
import java.util.ArrayList;
import java.util.Arrays;
@@ -55,17 +54,8 @@
* Implementation of the Knuth-Plass total-fit linebreaking algorithm.
* @see "Knuth, Digital Typography, 1999, p. 116"
*/
-public class TotalFitLb implements LineBreaker {
+public class TotalFitLb extends LineBreaker4a {
- /** Magic number used in demerit computation to help normalize adjustment ratios and penalties. */
- private static final int DEMERIT_COMPUTATION_COEFFICIENT = 100;
-
- /** The initial size for the feasible breaks list. */
- private static final int INITIAL_FEASIBLE_BREAKS_SIZE = 20;
-
- /** The initial size for the content nodes list. */
- private static final int INITIAL_CONTENT_NODES_SIZE = 100;
-
/** The paragraph whose line-breaking is being computed. */
private ParaBranch paragraph;
Added: trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/LineBreaker4aTests.java
===================================================================
--- trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/LineBreaker4aTests.java (rev 0)
+++ trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/LineBreaker4aTests.java 2021-11-25 16:15:08 UTC (rev 12129)
@@ -0,0 +1,220 @@
+/*
+ * Copyright 2021 The FOray Project.
+ * http://www.foray.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.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.linebreak;
+
+import org.foray.common.para.ParaBranch4a;
+import org.foray.common.para.ParaConfig4a;
+import org.foray.orthography.Punctuation4a;
+
+import org.axsl.common.para.ParaConfig;
+import org.axsl.font.Font;
+import org.axsl.font.FontUse;
+
+import org.junit.Assert;
+import org.mockito.Mockito;
+
+/**
+ * Abstract superclass for classes testing subclasses of {@link LineBreaker4a}.
+ */
+public abstract class LineBreaker4aTests {
+
+ /** 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. */
+ public static final String TEST_STRING_01 =
+ "In olden times when wishing still helped one, there lived a king " +
+ "whose daughters were all beautiful; and the youngest was so beautiful that the sun itself, which has " +
+ "seen so much, was astonished whenever it shone in her face. Close by the king’s castle lay a great " +
+ "dark forest, and under an old lime-tree in the forest was a well, and when the day was very warm, the " +
+ "king’s child went out into the forest and sat down by the side of the cool fountain; and when she " +
+ "was bored she took a golden ball, and threw it up on high and caught it; and this ball was her favorite " +
+ "plaything.";
+
+ /**
+ * Creates the tokenized content of {@link #TEST_STRING_01}.
+ * We could use the orthography system to build this, but the line-breaking logic is independent of that, so we
+ * manually build it in this method.
+ * @return The tokenized content of {@link #TEST_STRING_01}.
+ */
+ protected ParaBranch4a createPara() {
+ final ParaBranch4aTestFixture para = new ParaBranch4aTestFixture(null, '-');
+ para.addWordAndSpace("In");
+ para.addWordAndSpace("olden");
+ para.addWordAndSpace("times");
+ para.addWordAndSpace("when");
+ para.addWordAndSpace("wish-ing"); // 2 segments
+ para.addWordAndSpace("still");
+ para.addWordAndSpace("helped");
+ para.addWord("one");
+ para.addNodeAndSpace(Punctuation4a.COMMA);
+ para.addWordAndSpace("there");
+ para.addWordAndSpace("lived");
+ para.addWordAndSpace("a");
+ para.addWordAndSpace("king");
+ para.addWordAndSpace("whose");
+ para.addWordAndSpace("daugh-ters"); // 2 segments
+ para.addWordAndSpace("were");
+ para.addWordAndSpace("all");
+ para.addWord("beau-ti-ful"); // 3 segments
+ para.addNodeAndSpace(Punctuation4a.SEMICOLON);
+ para.addWordAndSpace("and");
+ para.addWordAndSpace("the");
+ para.addWordAndSpace("young-est"); // 2 segments
+ para.addWordAndSpace("was");
+ para.addWordAndSpace("so");
+ para.addWordAndSpace("beau-ti-ful"); // 3 segments
+ para.addWordAndSpace("that");
+ para.addWordAndSpace("the");
+ para.addWordAndSpace("sun");
+ para.addWord("it-self"); // 2 segments
+ para.addNodeAndSpace(Punctuation4a.COMMA);
+ para.addWordAndSpace("which");
+ para.addWordAndSpace("has");
+ para.addWordAndSpace("seen");
+ para.addWordAndSpace("so");
+ para.addWord("much");
+ para.addNodeAndSpace(Punctuation4a.COMMA);
+ para.addWordAndSpace("was");
+ para.addWordAndSpace("aston-ished"); // 2 segments
+ para.addWordAndSpace("when-ever"); // 2 segments
+ para.addWordAndSpace("it");
+ para.addWordAndSpace("shone");
+ para.addWordAndSpace("in");
+ para.addWordAndSpace("her");
+ para.addWord("face");
+ para.addNodeAndSpace(Punctuation4a.PERIOD);
+ para.addWordAndSpace("Close");
+ para.addWordAndSpace("by");
+ para.addWordAndSpace("the");
+ para.addWordAndSpace("king’s");
+ para.addWordAndSpace("castle");
+ para.addWordAndSpace("lay");
+ para.addWordAndSpace("a");
+ para.addWordAndSpace("great");
+ para.addWordAndSpace("dark");
+ para.addWord("for-est"); // 2 segments
+ para.addNodeAndSpace(Punctuation4a.COMMA);
+ para.addWordAndSpace("and");
+ para.addWordAndSpace("un-der"); // 2 segments
+ para.addWordAndSpace("an");
+ para.addWordAndSpace("old");
+ para.addWord("lime");
+ para.add(Punctuation4a.MANDATORY_HYPHEN);
+ para.addWordAndSpace("tree");
+ para.addWordAndSpace("in");
+ para.addWordAndSpace("the");
+ para.addWordAndSpace("for-est"); // 2 segments
+ para.addWordAndSpace("was");
+ para.addWordAndSpace("a");
+ para.addWord("well");
+ para.addNodeAndSpace(Punctuation4a.COMMA);
+ para.addWordAndSpace("and");
+ para.addWordAndSpace("when");
+ para.addWordAndSpace("the");
+ para.addWordAndSpace("day");
+ para.addWordAndSpace("was");
+ para.addWordAndSpace("very");
+ para.addWord("warm");
+ para.addNodeAndSpace(Punctuation4a.COMMA);
+ para.addWordAndSpace("the");
+ para.addWordAndSpace("king’s");
+ para.addWordAndSpace("child");
+ para.addWordAndSpace("went");
+ para.addWordAndSpace("out");
+ para.addWordAndSpace("into");
+ para.addWordAndSpace("the");
+ para.addWordAndSpace("for-est"); // 2 segments
+ para.addWordAndSpace("and");
+ para.addWordAndSpace("sat");
+ para.addWordAndSpace("down");
+ para.addWordAndSpace("by");
+ para.addWordAndSpace("the");
+ para.addWordAndSpace("side");
+ para.addWordAndSpace("of");
+ para.addWordAndSpace("the");
+ para.addWordAndSpace("cool");
+ para.addWord("foun-tain"); // 2 segments
+ para.addNodeAndSpace(Punctuation4a.SEMICOLON);
+ para.addWordAndSpace("and");
+ para.addWordAndSpace("when");
+ para.addWordAndSpace("she");
+ para.addWordAndSpace("was");
+ para.addWordAndSpace("bored");
+ para.addWordAndSpace("she");
+ para.addWordAndSpace("took");
+ para.addWordAndSpace("a");
+ para.addWordAndSpace("golden");
+ para.addWord("ball");
+ para.addNodeAndSpace(Punctuation4a.COMMA);
+ para.addWordAndSpace("and");
+ para.addWordAndSpace("threw");
+ para.addWordAndSpace("it");
+ para.addWordAndSpace("up");
+ para.addWordAndSpace("on");
+ para.addWordAndSpace("high");
+ para.addWordAndSpace("and");
+ para.addWordAndSpace("caught");
+ para.addWord("it;");
+ para.addNodeAndSpace(Punctuation4a.SEMICOLON);
+ para.addWordAndSpace("and");
+ para.addWordAndSpace("this");
+ para.addWordAndSpace("ball");
+ para.addWordAndSpace("was");
+ para.addWordAndSpace("her");
+ para.addWordAndSpace("favor-ite"); // 2 segments
+ para.addWordAndSpace("play-thing"); // 2 segments
+ para.add(Punctuation4a.PERIOD);
+
+ final Font font = LbTestUtilities.createMonotypeFont();
+ final FontUse fontUse = Mockito.mock(FontUse.class);
+ Mockito.when(fontUse.getFont()).thenReturn(font);
+ final ParaConfig paraConfig = new ParaConfig4a(fontUse, 10, null, 0, 0);
+ para.setParaConfig(paraConfig);
+
+ /* The tokenized text treated "’s" as part of the attached word.
+ * The compound word "lime-tree" was treated as two words divided by punctuation.
+ * There are 126 lines of code creating the para.
+ * Count Nodes
+ * addWord 12 12
+ * addNodeAndSpace 11 22
+ * add 2 2
+ * addWordAndSpace (forced) 101 202
+ * ----- -----
+ * totals 126 238
+ * ===== ===== */
+ Assert.assertEquals(238, para.getQtyParaNodeChildren());
+
+ /* Of the words added, 12 are two-syllable, and 2 are three-syllable, which should add
+ * (13 x 1) + (2 x 2) = 17 additional leaf nodes. */
+ Assert.assertEquals(255, para.getQtyParaLeafDescendants());
+
+ return para;
+ }
+
+}
Property changes on: trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/LineBreaker4aTests.java
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Rev
\ No newline at end of property
Modified: trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/TotalFitLbTests.java
===================================================================
--- trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/TotalFitLbTests.java 2021-11-24 15:22:56 UTC (rev 12128)
+++ trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/TotalFitLbTests.java 2021-11-25 16:15:08 UTC (rev 12129)
@@ -30,14 +30,9 @@
import org.foray.common.data.OrderedTreePath4a;
import org.foray.common.para.ParaBranch4a;
-import org.foray.common.para.ParaConfig4a;
-import org.foray.orthography.Punctuation4a;
import org.axsl.common.para.DiscretionaryHyphen;
-import org.axsl.common.para.ParaConfig;
import org.axsl.common.para.ParaControl;
-import org.axsl.font.Font;
-import org.axsl.font.FontUse;
import org.axsl.linebreak.LineBreakControl;
import org.axsl.linebreak.OutputLine;
@@ -51,182 +46,9 @@
/**
* Tests of {@link TotalFitLb}.
*/
-public class TotalFitLbTests {
+public class TotalFitLbTests extends LineBreaker4aTests {
- /** 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. */
- public static final String TEST_STRING_01 =
- "In olden times when wishing still helped one, there lived a king " +
- "whose daughters were all beautiful; and the youngest was so beautiful that the sun itself, which has " +
- "seen so much, was astonished whenever it shone in her face. Close by the king’s castle lay a great " +
- "dark forest, and under an old lime-tree in the forest was a well, and when the day was very warm, the " +
- "king’s child went out into the forest and sat down by the side of the cool fountain; and when she " +
- "was bored she took a golden ball, and threw it up on high and caught it; and this ball was her favorite " +
- "plaything.";
-
/**
- * Creates the tokenized content of {@link #TEST_STRING_01}.
- * We could use the orthography system to build this, but the line-breaking logic is independent of that, so we
- * manually build it in this method.
- * @return The tokenized content of {@link #TEST_STRING_01}.
- */
- private ParaBranch4a createPara() {
- final ParaBranch4aTestFixture para = new ParaBranch4aTestFixture(null, '-');
- para.addWordAndSpace("In");
- para.addWordAndSpace("olden");
- para.addWordAndSpace("times");
- para.addWordAndSpace("when");
- para.addWordAndSpace("wish-ing"); // 2 segments
- para.addWordAndSpace("still");
- para.addWordAndSpace("helped");
- para.addWord("one");
- para.addNodeAndSpace(Punctuation4a.COMMA);
- para.addWordAndSpace("there");
- para.addWordAndSpace("lived");
- para.addWordAndSpace("a");
- para.addWordAndSpace("king");
- para.addWordAndSpace("whose");
- para.addWordAndSpace("daugh-ters"); // 2 segments
- para.addWordAndSpace("were");
- para.addWordAndSpace("all");
- para.addWord("beau-ti-ful"); // 3 segments
- para.addNodeAndSpace(Punctuation4a.SEMICOLON);
- para.addWordAndSpace("and");
- para.addWordAndSpace("the");
- para.addWordAndSpace("young-est"); // 2 segments
- para.addWordAndSpace("was");
- para.addWordAndSpace("so");
- para.addWordAndSpace("beau-ti-ful"); // 3 segments
- para.addWordAndSpace("that");
- para.addWordAndSpace("the");
- para.addWordAndSpace("sun");
- para.addWord("it-self"); // 2 segments
- para.addNodeAndSpace(Punctuation4a.COMMA);
- para.addWordAndSpace("which");
- para.addWordAndSpace("has");
- para.addWordAndSpace("seen");
- para.addWordAndSpace("so");
- para.addWord("much");
- para.addNodeAndSpace(Punctuation4a.COMMA);
- para.addWordAndSpace("was");
- para.addWordAndSpace("aston-ished"); // 2 segments
- para.addWordAndSpace("when-ever"); // 2 segments
- para.addWordAndSpace("it");
- para.addWordAndSpace("shone");
- para.addWordAndSpace("in");
- para.addWordAndSpace("her");
- para.addWord("face");
- para.addNodeAndSpace(Punctuation4a.PERIOD);
- para.addWordAndSpace("Close");
- para.addWordAndSpace("by");
- para.addWordAndSpace("the");
- para.addWordAndSpace("king’s");
- para.addWordAndSpace("castle");
- para.addWordAndSpace("lay");
- para.addWordAndSpace("a");
- para.addWordAndSpace("great");
- para.addWordAndSpace("dark");
- para.addWord("for-est"); // 2 segments
- para.addNodeAndSpace(Punctuation4a.COMMA);
- para.addWordAndSpace("and");
- para.addWordAndSpace("un-der"); // 2 segments
- para.addWordAndSpace("an");
- para.addWordAndSpace("old");
- para.addWord("lime");
- para.add(Punctuation4a.MANDATORY_HYPHEN);
- para.addWordAndSpace("tree");
- para.addWordAndSpace("in");
- para.addWordAndSpace("the");
- para.addWordAndSpace("for-est"); // 2 segments
- para.addWordAndSpace("was");
- para.addWordAndSpace("a");
- para.addWord("well");
- para.addNodeAndSpace(Punctuation4a.COMMA);
- para.addWordAndSpace("and");
- para.addWordAndSpace("when");
- para.addWordAndSpace("the");
- para.addWordAndSpace("day");
- para.addWordAndSpace("was");
- para.addWordAndSpace("very");
- para.addWord("warm");
- para.addNodeAndSpace(Punctuation4a.COMMA);
- para.addWordAndSpace("the");
- para.addWordAndSpace("king’s");
- para.addWordAndSpace("child");
- para.addWordAndSpace("went");
- para.addWordAndSpace("out");
- para.addWordAndSpace("into");
- para.addWordAndSpace("the");
- para.addWordAndSpace("for-est"); // 2 segments
- para.addWordAndSpace("and");
- para.addWordAndSpace("sat");
- para.addWordAndSpace("down");
- para.addWordAndSpace("by");
- para.addWordAndSpace("the");
- para.addWordAndSpace("side");
- para.addWordAndSpace("of");
- para.addWordAndSpace("the");
- para.addWordAndSpace("cool");
- para.addWord("foun-tain"); // 2 segments
- para.addNodeAndSpace(Punctuation4a.SEMICOLON);
- para.addWordAndSpace("and");
- para.addWordAndSpace("when");
- para.addWordAndSpace("she");
- para.addWordAndSpace("was");
- para.addWordAndSpace("bored");
- para.addWordAndSpace("she");
- para.addWordAndSpace("took");
- para.addWordAndSpace("a");
- para.addWordAndSpace("golden");
- para.addWord("ball");
- para.addNodeAndSpace(Punctuation4a.COMMA);
- para.addWordAndSpace("and");
- para.addWordAndSpace("threw");
- para.addWordAndSpace("it");
- para.addWordAndSpace("up");
- para.addWordAndSpace("on");
- para.addWordAndSpace("high");
- para.addWordAndSpace("and");
- para.addWordAndSpace("caught");
- para.addWord("it;");
- para.addNodeAndSpace(Punctuation4a.SEMICOLON);
- para.addWordAndSpace("and");
- para.addWordAndSpace("this");
- para.addWordAndSpace("ball");
- para.addWordAndSpace("was");
- para.addWordAndSpace("her");
- para.addWordAndSpace("favor-ite"); // 2 segments
- para.addWordAndSpace("play-thing"); // 2 segments
- para.add(Punctuation4a.PERIOD);
-
- final Font font = LbTestUtilities.createMonotypeFont();
- final FontUse fontUse = Mockito.mock(FontUse.class);
- Mockito.when(fontUse.getFont()).thenReturn(font);
- final ParaConfig paraConfig = new ParaConfig4a(fontUse, 10, null, 0, 0);
- para.setParaConfig(paraConfig);
-
- /* The tokenized text treated "’s" as part of the attached word.
- * The compound word "lime-tree" was treated as two words divided by punctuation.
- * There are 126 lines of code creating the para.
- * Count Nodes
- * addWord 12 12
- * addNodeAndSpace 11 22
- * add 2 2
- * addWordAndSpace (forced) 101 202
- * ----- -----
- * totals 126 238
- * ===== ===== */
- Assert.assertEquals(238, para.getQtyParaNodeChildren());
-
- /* Of the words added, 12 are two-syllable, and 2 are three-syllable, which should add
- * (13 x 1) + (2 x 2) = 17 additional leaf nodes. */
- Assert.assertEquals(255, para.getQtyParaLeafDescendants());
-
- return para;
- }
-
- /**
* A test.
*/
@Test
Modified: trunk/foray/foray-orthography/src/main/data/dictionaries/eng-Latn-999.dict.xml
===================================================================
--- trunk/foray/foray-orthography/src/main/data/dictionaries/eng-Latn-999.dict.xml 2021-11-24 15:22:56 UTC (rev 12128)
+++ trunk/foray/foray-orthography/src/main/data/dictionaries/eng-Latn-999.dict.xml 2021-11-25 16:15:08 UTC (rev 12129)
@@ -913,7 +913,7 @@
<w><t>ac-com-plish-er</t></w>
<w><t>ac-com-plish-ment</t></w>
<w><t>ac-compt</t></w>
-<w><t>ac-cord</t></w>
+<w><t>ac-cord</t><noun><pluralizable/><convertible-to-possessive/></noun><verb><regular-root/></verb></w>
<w><t>ac-cord-a-ble</t></w>
<w><t>ac-cord-ance</t></w>
<w><t>ac-cord-ant</t></w>
@@ -1510,7 +1510,7 @@
<w><t>ac-ry-lo-ni-trile</t></w>
<w><t>ac-ryl-yl</t></w>
<w><t>ac-ry-lyl</t></w>
-<w><t>act</t></w>
+<w><t>act</t><noun><pluralizable/><convertible-to-possessive/></noun><verb><regular-root/></verb></w>
<phrase><t>act of con-tri-tion</t></phrase>
<w><t>Ac-ta</t></w>
<w><t>act-a-bil-i-ty</t></w>
@@ -3257,7 +3257,7 @@
<w><t>ai-lu-ro-phobe</t></w>
<w><t>ai-lu-ro-pho-bi-a</t></w>
<w><t>ai-lu-ro-pho-bic</t></w>
-<w><t>aim</t></w>
+<w><t>aim</t><noun><pluralizable/></noun><verb><regular-root/></verb></w>
<w><t>ai-mak</t></w>
<w><t>Ai-mee</t></w>
<w><t>aim-er</t></w>
@@ -32930,7 +32930,7 @@
<w><t>con-vict-fish</t></w>
<w><t>con-vict-fish-es</t></w>
<w><t>con-vict-i-ble</t></w>
-<w><t>con-vic-tion</t></w>
+<w><t>con-vic-tion</t><noun><pluralizable/></noun></w>
<w><t>con-vic-tion-al</t></w>
<w><t>con-vic-tive</t></w>
<w><t>con-vic-tive-ly</t></w>
@@ -164106,7 +164106,7 @@
<w><t>train-sick</t></w>
<w><t>traipse</t></w>
<w><t>traips-ing</t></w>
-<w><t>trait</t></w>
+<w><t>trait</t><noun><pluralizable/></noun></w>
<w><t>trai-tor</t></w>
<w><t>trai-tor-ess</t></w>
<w><t>trai-tor-ous</t></w>
@@ -171654,6 +171654,7 @@
<w><t>un-feel-ing-ly</t></w>
<w><t>un-feel-ing-ness</t></w>
<w><t>un-feign-a-ble</t></w>
+<w><t>un-feigned</t><adjective/></w>
<w><t>un-feign-ing</t></w>
<w><t>un-fe-lic-i-tat-ed</t></w>
<w><t>un-fe-lic-i-tat-ing</t></w>
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/DictionaryResource.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/DictionaryResource.java 2021-11-24 15:22:56 UTC (rev 12128)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/DictionaryResource.java 2021-11-25 16:15:08 UTC (rev 12129)
@@ -130,7 +130,7 @@
inputStream = rawResource.openStream();
} catch (final IOException e) {
/* The word list file does not exist. Do not try to parse it. */
- getLogger().info("{} URL resource not found: {}", this.getTypeDescription(), rawResource.toExternalForm());
+ getLogger().debug("{} URL resource not found: {}", this.getTypeDescription(), rawResource.toExternalForm());
return null;
}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/OrthographyResource.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/OrthographyResource.java 2021-11-24 15:22:56 UTC (rev 12128)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/OrthographyResource.java 2021-11-25 16:15:08 UTC (rev 12129)
@@ -120,7 +120,7 @@
final ResourceLocation location = this.parsedResourceLocations.get(index);
final InputStream inputStream = location.getInputStream();
if (inputStream == null) {
- this.logger.info("Resource not found: {}", location.getLocationDescription());
+ this.logger.debug("Resource not found: {}", location.getLocationDescription());
continue;
}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/DictionaryParser.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/DictionaryParser.java 2021-11-24 15:22:56 UTC (rev 12128)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/DictionaryParser.java 2021-11-25 16:15:08 UTC (rev 12129)
@@ -139,7 +139,7 @@
*/
public List<SegmentDictionary> parse(final InputSource inputSource)
throws IOException, SAXException, ParserConfigurationException {
- getLogger().info("Begin dictionary word list parsing: " + inputSource.getSystemId());
+ getLogger().debug("Begin dictionary word list parsing: " + inputSource.getSystemId());
final XMLReader parser = this.createSax2Parser(true, true, true, AxslDtdUtil.getEntityResolver(), false);
if (parser != null) {
@@ -291,7 +291,7 @@
final String country = attributes.getValue(StringUtils.EMPTY_STRING, "country");
final String script = attributes.getValue(StringUtils.EMPTY_STRING, "script");
this.currentDictionary.orthography = WritingSystem4a.find(language, script, country);
- getLogger().info("Begin dictionary word list parsing: " + this.currentDictionary.orthography.toString());
+ getLogger().debug("Begin dictionary word list parsing: " + this.currentDictionary.orthography.toString());
final String soft = attributes.getValue(StringUtils.EMPTY_STRING, "soft-hyphen-char");
if (soft.length() != 1) {
throw new SAXException("Attribute soft-hyphen-char must have exactly one char.");
@@ -426,9 +426,9 @@
case "ordinal": break;
case "word-group": break;
case "axsl-dictionary": {
- getLogger().info("End parsing for dictionary: " + this.currentDictionary.orthography.toString());
- getLogger().info("Qty of unique word segments parsed: " + segmentSet.size());
- getLogger().info("Qty of words parsed: " + wordMap.size());
+ getLogger().debug("End parsing for dictionary: " + this.currentDictionary.orthography.toString());
+ getLogger().debug("Qty of unique word segments parsed: " + segmentSet.size());
+ getLogger().debug("Qty of words parsed: " + wordMap.size());
break;
}
case "axsl-dictionaries": break;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-11-24 15:22:59
|
Revision: 12128
http://sourceforge.net/p/foray/code/12128
Author: victormote
Date: 2021-11-24 15:22:56 +0000 (Wed, 24 Nov 2021)
Log Message:
-----------
Prevent StringWordSegmentLatin1Factory from trying to create a word that it cannot encode.
Modified Paths:
--------------
trunk/foray/foray-common/src/main/java/org/foray/common/primitive/StringLatin1.java
trunk/foray/foray-orthography/src/main/data/dictionaries/eng-Latn-999.dict.xml
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/StringWordSegment.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/StringWordSegmentLatin1Factory.java
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/primitive/StringLatin1.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/primitive/StringLatin1.java 2021-11-24 14:01:19 UTC (rev 12127)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/primitive/StringLatin1.java 2021-11-24 15:22:56 UTC (rev 12128)
@@ -36,12 +36,12 @@
*/
public class StringLatin1 extends StringBytes {
+ /** The encoding to use when encoding and decoding characters for this class. */
+ public static final Latin1Encoding ENCODING = new Latin1Encoding();
+
/** Constant needed for serialization. */
private static final long serialVersionUID = 7825461535101012668L;
- /** The encoding to use when encoding and decoding characters for this class. */
- private static final Latin1Encoding ENCODING = new Latin1Encoding();
-
/**
* Constructor.
* @param segment The chars in this segment.
Modified: trunk/foray/foray-orthography/src/main/data/dictionaries/eng-Latn-999.dict.xml
===================================================================
--- trunk/foray/foray-orthography/src/main/data/dictionaries/eng-Latn-999.dict.xml 2021-11-24 14:01:19 UTC (rev 12127)
+++ trunk/foray/foray-orthography/src/main/data/dictionaries/eng-Latn-999.dict.xml 2021-11-24 15:22:56 UTC (rev 12128)
@@ -8379,11 +8379,11 @@
<w><t>ap-par-i-tor</t></w>
<w><t>ap-pas-sio-na-to</t></w>
<w><t>ap-pau-mé</t></w>
-<w><t>ap-peal</t></w>
+<w><t>ap-peal</t><noun><pluralizable/><convertible-to-possessive/></noun><verb><regular-root/></verb></w>
<w><t>ap-peal-a-bil-i-ty</t></w>
<w><t>ap-peal-a-ble</t></w>
<w><t>ap-peal-er</t></w>
-<w><t>ap-peal-ing</t></w>
+<w><t>ap-peal-ing</t><adjective/></w>
<w><t>ap-peal-ing-ly</t></w>
<w><t>ap-peal-ing-ness</t></w>
<w><t>ap-pear</t></w>
@@ -10259,7 +10259,7 @@
<w><t>as-sen-tive-ness</t></w>
<w><t>as-sen-tor</t></w>
<w><t>As-ser</t></w>
-<w><t>as-sert</t></w>
+<w><t>as-sert</t><verb><regular-root/></verb></w>
<w><t>as-sert-ed</t></w>
<w><t>as-sert-ed-ly</t></w>
<w><t>as-sert-er</t></w>
@@ -32089,7 +32089,7 @@
<w><t>con-san-guin-e-ous-ly</t></w>
<w><t>con-san-guin-i-ty</t></w>
<w><t>con-sarned</t></w>
-<w><t>con-science</t></w>
+<w><t>con-science</t><noun><pluralizable/><convertible-to-possessive/></noun></w>
<phrase><t>con-science clause</t></phrase>
<phrase><t>con-science mon-ey</t></phrase>
<w><t>con-science=strick-en</t></w>
@@ -42699,11 +42699,9 @@
<w><t>dis-cour-ag-er</t></w>
<w><t>dis-cour-ag-ing</t></w>
<w><t>dis-cour-ag-ing-ly</t></w>
-<w><t>dis-course</t></w>
-<w><t>dis-coursed</t></w>
+<w><t>dis-course</t><noun><pluralizable/><convertible-to-possessive/></noun><verb><regular-root/></verb></w>
<w><t>dis-course-less</t></w>
<w><t>dis-cours-er</t></w>
-<w><t>dis-cours-ing</t></w>
<w><t>dis-cour-te-ous</t></w>
<w><t>dis-cour-te-ous-ly</t></w>
<w><t>dis-cour-te-ous-ness</t></w>
@@ -53501,7 +53499,7 @@
<w><t>fac-sim-i-le</t></w>
<w><t>fac-sim-i-led</t></w>
<w><t>fac-sim-i-le-ing</t></w>
-<w><t>fact</t></w>
+<w><t>fact</t><noun><pluralizable/><convertible-to-possessive/></noun></w>
<w><t>fact=find-ing</t></w>
<w><t>fact-ful</t></w>
<w><t>fac-tice</t></w>
@@ -88282,9 +88280,9 @@
<w><t>list-ed</t></w>
<phrase><t>list-ed build-ing</t></phrase>
<w><t>lis-tel</t></w>
-<w><t>lis-ten</t></w>
+<w><t>lis-ten</t><noun><singular/></noun><verb><regular-root/></verb></w>
<phrase><t>lis-ten in</t></phrase>
-<w><t>lis-ten-er</t></w>
+<w><t>lis-ten-er</t><noun><pluralizable/><convertible-to-possessive/></noun></w>
<phrase><t>lis-ten-ing post</t></phrase>
<w><t>list-er</t></w>
<w><t>Lis-ter</t></w>
@@ -109347,7 +109345,7 @@
<w><t>on-do-graph</t></w>
<w><t>on-dom-e-ter</t></w>
<w><t>on-do-scope</t></w>
-<w><t>one</t><cardinal/></w>
+<w><t>one</t><pronoun></pronoun><cardinal/></w>
<phrase><t>one an-oth-er</t></phrase>
<phrase><t>One Thou-sand Guin-eas</t></phrase>
<w><t>one=act-er</t></w>
@@ -109382,6 +109380,7 @@
<w><t>on-er-ous-ly</t></w>
<w><t>on-er-ous-ness</t></w>
<w><t>one-self</t></w>
+<w><t>one’s</t><adjective><possessive/></adjective></w>
<w><t>on-go-ing</t></w>
<w><t>on-i-cism</t></w>
<w><t>o-ni-o-ma-ni-a</t></w>
@@ -109689,7 +109688,7 @@
<w><t>op-ing</t></w>
<w><t>o-pin-i-cus</t></w>
<w><t>o-pin-i-cus-es</t></w>
-<w><t>o-pin-ion</t></w>
+<w><t>o-pin-ion</t><noun><pluralizable/><convertible-to-possessive/></noun></w>
<phrase><t>o-pin-ion poll</t></phrase>
<w><t>o-pin-ion-at-ed</t></w>
<w><t>o-pin-ion-at-ed-ly</t></w>
@@ -109735,10 +109734,12 @@
<phrase><t>op-por-tu-ni-ty cost</t></phrase>
<w><t>op-pos-a-bil-i-ty</t></w>
<w><t>op-pos-a-ble</t></w>
-<w><t>op-pose</t></w>
-<w><t>op-pos-er</t></w>
+<w><t>op-pose</t><verb><regular-root/></verb></w>
+<w><t>op-posed</t><adjective/></w>
+<w><t>op-pos-er</t><noun><pluralizable/><convertible-to-possessive/></noun></w>
+<w><t>op-pos-ing</t><adjective/></w>
<w><t>op-pos-ing-ly</t></w>
-<w><t>op-po-site</t></w>
+<w><t>op-po-site</t><noun><pluralizable/><convertible-to-possessive/></noun><adjective/><adverb/><preposition/></w>
<phrase><t>op-po-site num-ber</t></phrase>
<phrase><t>op-po-site prompt</t></phrase>
<phrase><t>op-po-site sex</t></phrase>
@@ -121489,7 +121490,7 @@
<w><t>po-lice-wom-an</t></w>
<w><t>po-lice-wom-en</t></w>
<w><t>pol-i-cli-nic</t></w>
-<w><t>pol-i-cy</t></w>
+<w><t>pol-i-cy</t><noun><pluralizable/><convertible-to-possessive/></noun></w>
<phrase><t>pol-i-cy sci-ence</t></phrase>
<w><t>pol-i-cy-hold-er</t></w>
<w><t>po-li-en-ceph-a-li-tis</t></w>
@@ -149730,7 +149731,6 @@
<phrase><t>soft shoul-der</t></phrase>
<w><t>soft=cen-tred</t></w>
<w><t>soft=cov-er</t></w>
-<w><t>soft-en</t><verb><regular-root/></verb></w>
<w><t>soft=fo-cus</t></w>
<w><t>soft=head-ed</t></w>
<w><t>soft=head-ed-ness</t></w>
@@ -149747,7 +149747,7 @@
<w><t>sof-ta</t></w>
<w><t>soft-ball</t></w>
<w><t>soft-board</t></w>
-<w><t>sof-ten</t></w>
+<w><t>soft-en</t><verb><regular-root/></verb></w>
<phrase><t>sof-ten up</t></phrase>
<w><t>sof-ten-er</t></w>
<w><t>soft-head</t></w>
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/StringWordSegment.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/StringWordSegment.java 2021-11-24 14:01:19 UTC (rev 12127)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/StringWordSegment.java 2021-11-24 15:22:56 UTC (rev 12128)
@@ -32,9 +32,9 @@
import org.axsl.orthography.WordSegment;
/**
- * Interface for classes that word segments made up of string or string-like entities.
- * This interface is needed for such classes because the tend to extend classes that are raw in nature and that should
- * not conform to this kind of interface.
+ * Word segments made up of string or string-like entities.
+ * This interface is needed for classes that extend classes that are raw in nature and that would not be expected to
+ * conform to this kind of interface.
*/
public interface StringWordSegment extends WordSegment, ParaLeaf {
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/StringWordSegmentLatin1Factory.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/StringWordSegmentLatin1Factory.java 2021-11-24 14:01:19 UTC (rev 12127)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/StringWordSegmentLatin1Factory.java 2021-11-24 15:22:56 UTC (rev 12128)
@@ -28,6 +28,8 @@
package org.foray.orthography;
+import org.foray.common.primitive.StringLatin1;
+
/**
* Factory class for {@link StringWordSegmentLatin1}.
*/
@@ -35,12 +37,18 @@
@Override
public StringWordSegmentLatin1 makeInstance(final CharSequence chars) {
- return new StringWordSegmentLatin1(chars);
+ if (StringLatin1.ENCODING.canEncode(chars)) {
+ return new StringWordSegmentLatin1(chars);
+ }
+ return null;
}
@Override
public StringWordSegmentLatin1 makeInstance(final char[] chars) {
- return new StringWordSegmentLatin1(chars);
+ if (StringLatin1.ENCODING.canEncode(chars)) {
+ return new StringWordSegmentLatin1(chars);
+ }
+ return null;
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|