foray-commit Mailing List for FOray (Page 73)
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-17 14:02:44
|
Revision: 12076
http://sourceforge.net/p/foray/code/12076
Author: victormote
Date: 2021-11-17 14:02:41 +0000 (Wed, 17 Nov 2021)
Log Message:
-----------
Get all tokenizer tests to pass. Much reorganization of code to follow.
Modified Paths:
--------------
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/Lexer4a.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/LexerJavaBreakIterator.java
trunk/foray/foray-orthography/src/test/java/org/foray/orthography/LexerLatin1Tests.java
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/Lexer4a.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/Lexer4a.java 2021-11-17 12:35:51 UTC (rev 12075)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/Lexer4a.java 2021-11-17 14:02:41 UTC (rev 12076)
@@ -47,7 +47,7 @@
WORD_CHAR,
/** Character is non-word break content. */
- NON_WORD_BREAK_CHAR,
+ BREAK_CHAR,
/** Character is a leading attached punctuation item such as (in English) an opening quotation mark or opening
* parenthesis. */
@@ -61,7 +61,7 @@
END,
/** Character is none of the above. */
- OTHER;
+ OTHER,
}
@@ -118,7 +118,7 @@
*/
public CharType computeCharType(final int c) {
if (isBreakChar(c)) {
- return CharType.NON_WORD_BREAK_CHAR;
+ return CharType.BREAK_CHAR;
}
if (isWordChar(c)) {
return CharType.WORD_CHAR;
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/LexerJavaBreakIterator.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/LexerJavaBreakIterator.java 2021-11-17 12:35:51 UTC (rev 12075)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/LexerJavaBreakIterator.java 2021-11-17 14:02:41 UTC (rev 12076)
@@ -50,7 +50,7 @@
* @param sequence The sequence whose breaks are needed.
* @return The sequence of breaks, indexes into {@code sequence}.
*/
- IntSequence findRawBreaks(final CharSequence sequence) {
+ protected IntSequence findRawBreaks(final CharSequence sequence) {
final IntArrayBuilder result = new IntArrayBuilder(sequence.length());
/* TODO: BreakIterators are reusable, not thread-safe, and expensive to create. Reuse this after figuring out
* how instances of this class are used/reused. */
@@ -72,7 +72,7 @@
* @return An array with a one-to-one correspondence with {@code rawBreaks}, containing the type of character at
* that break.
*/
- CharType[] findBreakTypes(final CharSequence sequence, final IntSequence rawBreaks) {
+ protected CharType[] findBreakTypes(final CharSequence sequence, final IntSequence rawBreaks) {
final CharType[] breakTypes = new CharType[rawBreaks.length()];
for (int breakIndex = 0; breakIndex < rawBreaks.length(); breakIndex ++) {
if (breakIndex >= rawBreaks.length() - 1) {
@@ -86,164 +86,119 @@
return breakTypes;
}
- @Override
- public List<CharSequence> tokenize(final CharSequence sequence) {
- if (sequence == null
- || sequence.length() < 1) {
- return Collections.emptyList();
+ /**
+ * Combine and eliminate the elements in the charTypes array.
+ * The touchstone here is the known word breaks which are always interword content.
+ * Anything between them must be either attached to the word break to become a part of the interword content, or
+ * must get coalesced into a "word" whether it is recognized as word content or not. If done properly, every element
+ * in the array, when finished, should be either {@link CharType#WORD_CHAR} or {@link CharType#BREAK_CHAR}.
+ * Anything not in those two categories will be treated in the final tokenization as {@link CharType#WORD_CHAR}.
+ * @param breakTypes The array of charTypes.
+ */
+ protected void filterBreakTypes(final CharType[] breakTypes) {
+ /* Convert attached trailing punctuation immediately after word content to interword. */
+ for (int breakIndex = 1; breakIndex < breakTypes.length; breakIndex ++) {
+ final CharType currentBreakType = breakTypes[breakIndex];
+ if (currentBreakType == CharType.ATTACHED_TRAILING_PUNCTUATION) {
+ final CharType previousBreakType = breakTypes[breakIndex - 1];
+ if (previousBreakType != CharType.BREAK_CHAR) {
+ breakTypes[breakIndex] = CharType.BREAK_CHAR;
+ }
+ }
}
+ /* Convert attached leading punctuation immediately before word content to interword. */
+ for (int breakIndex = 1; breakIndex < breakTypes.length; breakIndex ++) {
+ final CharType currentBreakType = breakTypes[breakIndex];
+ if (currentBreakType == CharType.ATTACHED_LEADING_PUNCTUATION) {
+ final CharType nextBreakType = breakTypes[breakIndex + 1];
+ if (nextBreakType != CharType.BREAK_CHAR) {
+ breakTypes[breakIndex] = CharType.BREAK_CHAR;
+ }
+ }
+ }
+ }
- /* First pass is to find all of the breaks that the BreakIterator can find. */
- final IntSequence rawBreaks = findRawBreaks(sequence);
-
- /* The BreakIterator is helpful, but for our purposes does not dig deeply enough.
- * Our purpose is to find where words start and end and to treat all other content as non-word or interword
- * content.
- * So our second pass is to find out the type of each character that is at a break. */
- final CharType[] breakTypes = findBreakTypes(sequence, rawBreaks);
-
- /* The third pass detects which of the breaks we care about based on their type and context. */
+ protected List<CharSequence> createTokens(final CharSequence sequence, final IntSequence rawBreaks,
+ final CharType[] breakTypes) {
final List<CharSequence> tokens = new ArrayList<CharSequence>();
+ boolean inWord = false;
+ int startNextToken = 0;
- /* Handle the case of only one break. It is either a single-token word, or non-word content that must be
- * preceded by an empty word. We will treat anything that is not a break char as part of a word. */
- if (breakTypes.length == 1) {
- if (breakTypes[0] == CharType.NON_WORD_BREAK_CHAR) {
- tokens.add(StringUtils.EMPTY_STRING);
- }
- tokens.add(sequence);
- return tokens;
- }
-
- /* There are at least two tokens. */
-
- /* Index 0 is special. */
- switch (breakTypes[0]) {
- case NON_WORD_BREAK_CHAR: {
+ /* First token. */
+ switch(breakTypes[0]) {
+ case BREAK_CHAR: {
+ /* Sequence starts with a break. Add the empty dummy word that signals that fact. */
tokens.add(StringUtils.EMPTY_STRING);
+ inWord = false;
break;
}
- case WORD_CHAR: {
- break;
+ default: {
+ /* Sequence starts with a word. */
+ inWord = true;
}
- case ATTACHED_LEADING_PUNCTUATION:
- case ATTACHED_TRAILING_PUNCTUATION:
- case OTHER: {
- if (breakTypes[1] == CharType.NON_WORD_BREAK_CHAR) {
- /* Treat this as a word. */
- } else {
- /* The next token starts a word. Threat this is non-word. */
- tokens.add(StringUtils.EMPTY_STRING);
- }
- break;
}
- case END:
- /* This shouldn't happen. */
- break;
- }
- /* Now iterate the remaining breaks. */
- int startNextToken = 0;
+ /* Iterate all remaining tokens. */
for (int breakIndex = 1; breakIndex < breakTypes.length; breakIndex ++) {
+ final CharType currentBreakType = breakTypes[breakIndex];
final int sequenceIndex = rawBreaks.intAt(breakIndex);
- final CharType currentBreakType = breakTypes[breakIndex];
- final CharType previousBreakType = breakTypes[breakIndex - 1];
- final CharType nextBreakType = currentBreakType == CharType.END ? null : breakTypes[breakIndex + 1];
- currentBreakType: {
- switch (currentBreakType) {
- case END: {
- tokens.add(sequence.subSequence(startNextToken, sequence.length()));
- break currentBreakType;
+ switch (currentBreakType) {
+ case END: {
+ tokens.add(sequence.subSequence(startNextToken, sequence.length()));
+ break;
+ }
+ case BREAK_CHAR: {
+ if (inWord) {
+ /* Write the word and roll forward. */
+ tokens.add(sequence.subSequence(startNextToken, sequenceIndex));
+ startNextToken = sequenceIndex;
+ inWord = false;
+ } else {
+ /* There is no state change. Nothing to do. */
}
- case NON_WORD_BREAK_CHAR: {
- previousBreakType: {
- switch (previousBreakType) {
- case WORD_CHAR: {
- tokens.add(sequence.subSequence(startNextToken, sequenceIndex));
- startNextToken = sequenceIndex;
- break previousBreakType;
- }
- case OTHER: {
-// nextBreakType: {
-//
-// }
-// tokens.add(sequence.subSequence(startNextToken, sequenceIndex));
-// startNextToken = sequenceIndex;
- break previousBreakType;
- }
- default: {
- break previousBreakType;
- }
- }
- }
- break currentBreakType;
+ break;
+ }
+ default: {
+ /* This is considered the start of word content. */
+ if (inWord) {
+ /* There is no state change. Nothing to do. */
+ } else {
+ /* Write the interword content and roll forward. */
+ tokens.add(sequence.subSequence(startNextToken, sequenceIndex));
+ startNextToken = sequenceIndex;
+ inWord = true;
}
- case WORD_CHAR: {
- if (previousBreakType == CharType.NON_WORD_BREAK_CHAR) {
- tokens.add(sequence.subSequence(startNextToken, sequenceIndex));
- startNextToken = sequenceIndex;
- }
- break currentBreakType;
- }
- case ATTACHED_LEADING_PUNCTUATION:
- case ATTACHED_TRAILING_PUNCTUATION:
- case OTHER: {
- previousBreakType: {
- switch (previousBreakType) {
- case WORD_CHAR: {
- /* The previous item is a word and this is not. Treat it as the beginning of a non-word
- * sequence. */
- tokens.add(sequence.subSequence(startNextToken, sequenceIndex));
- startNextToken = sequenceIndex;
- break previousBreakType;
- }
- case ATTACHED_LEADING_PUNCTUATION:
- case ATTACHED_TRAILING_PUNCTUATION:
- case OTHER: {
- /* There is no change. Nothing to do here. */
- break previousBreakType;
- }
- case NON_WORD_BREAK_CHAR: {
- nextBreakType:
- switch(nextBreakType) {
- case NON_WORD_BREAK_CHAR: {
- /* Sitting between two word breaks. Treat this as a word. */
- tokens.add(sequence.subSequence(startNextToken, sequenceIndex));
- startNextToken = sequenceIndex;
- break nextBreakType;
- }
- case ATTACHED_LEADING_PUNCTUATION:
- case ATTACHED_TRAILING_PUNCTUATION:
- case OTHER: {
- break nextBreakType;
- }
- case WORD_CHAR: {
- /* After a break and before a word. This is interword content. */
- break nextBreakType;
- }
- case END: {
- /* This can't happen. */
- break nextBreakType;
- }
- }
- break previousBreakType;
- }
- case END: {
- /* This shouldn't happen. */
- break previousBreakType;
- }
- }
- break currentBreakType;
- }
- }
- }
}
+ }
}
-
return tokens;
}
+ @Override
+ public List<CharSequence> tokenize(final CharSequence sequence) {
+ if (sequence == null
+ || sequence.length() < 1) {
+ return Collections.emptyList();
+ }
+
+ /* First pass is to find all of the breaks that the BreakIterator can find. */
+ final IntSequence rawBreaks = findRawBreaks(sequence);
+
+
+ /* The BreakIterator is helpful, but for our purposes does not dig deeply enough.
+ * Our purpose is to find where words start and end and to treat all other content as non-word or interword
+ * content.
+ * So our second pass is to find out the type of each character that is at a break. */
+ final CharType[] breakTypes = findBreakTypes(sequence, rawBreaks);
+
+ /* Third pass. Simplify the breakTypes array. */
+ filterBreakTypes(breakTypes);
+
+ /* The fourth step iterates over the resolved break types and turns them into tokens. */
+ return createTokens(sequence, rawBreaks, breakTypes);
+ }
+
}
Modified: trunk/foray/foray-orthography/src/test/java/org/foray/orthography/LexerLatin1Tests.java
===================================================================
--- trunk/foray/foray-orthography/src/test/java/org/foray/orthography/LexerLatin1Tests.java 2021-11-17 12:35:51 UTC (rev 12075)
+++ trunk/foray/foray-orthography/src/test/java/org/foray/orthography/LexerLatin1Tests.java 2021-11-17 14:02:41 UTC (rev 12076)
@@ -30,7 +30,6 @@
import org.junit.Assert;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
import java.util.List;
@@ -79,7 +78,7 @@
public void testMedium() {
final String testString = "39. It was the best of times. It was the worst of times. <----";
final List<CharSequence> actual = this.out.tokenize(testString);
- Assert.assertEquals(28, actual.size());
+ Assert.assertEquals(27, actual.size());
Assert.assertEquals("39", actual.get(0));
Assert.assertEquals(". ", actual.get(1));
Assert.assertEquals("It", actual.get(2));
@@ -106,8 +105,7 @@
Assert.assertEquals(" ", actual.get(23));
Assert.assertEquals("times", actual.get(24));
Assert.assertEquals(". ", actual.get(25));
- Assert.assertEquals("<", actual.get(26));
- Assert.assertEquals("----", actual.get(27));
+ Assert.assertEquals("<----", actual.get(26));
}
/**
@@ -156,7 +154,6 @@
* However, because each one is between hard word breaks, should be tokenized as words.
*/
@Test
- @Ignore
public void testWithSymbolsAsWords() {
final String testString = "! @ # $ %";
final List<CharSequence> actual = this.out.tokenize(testString);
@@ -178,7 +175,6 @@
* treated as a word.
*/
@Test
- @Ignore
public void testWithAttachedPunctuation() {
final String testString = "Parentheses (as I stated earlier) are a matching pair of ( and ) characters.";
final List<CharSequence> actual = this.out.tokenize(testString);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-11-17 12:35:54
|
Revision: 12075
http://sourceforge.net/p/foray/code/12075
Author: victormote
Date: 2021-11-17 12:35:51 +0000 (Wed, 17 Nov 2021)
Log Message:
-----------
Add method for search-and-replace in an array of Objects.
Added Paths:
-----------
trunk/foray/foray-common/src/main/java/org/foray/common/primitive/ArrayUtils.java
trunk/foray/foray-common/src/test/java/org/foray/common/primitive/ArrayUtilsTests.java
Added: trunk/foray/foray-common/src/main/java/org/foray/common/primitive/ArrayUtils.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/primitive/ArrayUtils.java (rev 0)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/primitive/ArrayUtils.java 2021-11-17 12:35:51 UTC (rev 12075)
@@ -0,0 +1,89 @@
+/*
+ * 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;
+
+public final class ArrayUtils {
+
+ private ArrayUtils() { }
+
+ /**
+ * Index-safe element retrieval from an array.
+ * If {@code index} is out of bounds, null is returned instead of throwing an {@link IndexOutOfBoundsException}.
+ * Useful mostly for making look-behind and look-ahead searches more readable.
+ * @param <T> The type of the array.
+ * @param array The array.
+ * @param index The index into {@code array} containing the element that should be returned.
+ * @return The element at {@code index} or null if the index is out of bounds.
+ */
+ public static <T extends Object> T elementAt(final T[] array, final int index) {
+ if (index < 0
+ || index >= array.length) {
+ return null;
+ }
+ return array[index];
+ }
+
+ /**
+ * Searches the elements of an array for all occurrences of a match pattern and performs an in-place replacement of
+ * those matching elements with those from a replacement pattern.
+ * For example, an array of Integers {1, 2, 3, 4, 1, 2, 3, 4}, a match pattern of {2, 3}, and a replace pattern of
+ * {3, 2}, change the original array to {1, 3, 2, 4, 1, 3, 2, 4}.
+ * If the length of {@code match} exceeds that of {@code replace}, the extra matching elements are left unchanged.
+ * @param <T> The type of the array being searched.
+ * @param array The array being searched.
+ * @param match The match pattern.
+ * @param replace The replacement pattern.
+ * @throws IllegalArgumentException If the lengths of {@code match} and {@code replace} are different.
+ */
+ public static <T extends Object> void matchAndReplace(final T[] array, final T[] match, final T[] replace) {
+ if (replace.length > match.length) {
+ throw new IllegalArgumentException("Length of \"replace\" cannot exceed length of \"match.\"");
+ }
+ for (int arrayIndex = 0; arrayIndex < array.length; arrayIndex ++) {
+ boolean matchFound = true;
+ for (int matchIndex = 0; matchIndex < match.length; matchIndex ++) {
+ final int arrayOffset = arrayIndex + matchIndex;
+ final T arrayElement = elementAt(array, arrayOffset);
+ final T matchElement = match[matchIndex];
+ if (! ObjectUtils.safeEquals(arrayElement, matchElement)) {
+ matchFound = false;
+ }
+ }
+ if (matchFound) {
+ for (int replaceIndex = 0; replaceIndex < replace.length; replaceIndex ++) {
+ final int arrayOffset = arrayIndex + replaceIndex;
+ array[arrayOffset] = replace[replaceIndex];
+ }
+ }
+
+ }
+
+ }
+
+}
Property changes on: trunk/foray/foray-common/src/main/java/org/foray/common/primitive/ArrayUtils.java
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Rev
\ No newline at end of property
Added: trunk/foray/foray-common/src/test/java/org/foray/common/primitive/ArrayUtilsTests.java
===================================================================
--- trunk/foray/foray-common/src/test/java/org/foray/common/primitive/ArrayUtilsTests.java (rev 0)
+++ trunk/foray/foray-common/src/test/java/org/foray/common/primitive/ArrayUtilsTests.java 2021-11-17 12:35:51 UTC (rev 12075)
@@ -0,0 +1,66 @@
+/*
+ * 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 ArrayUtils}.
+ */
+public class ArrayUtilsTests {
+
+ /**
+ * Tests of {@link ArrayUtils#elementAt(Object[], int)}.
+ */
+ @Test
+ public void elementAtTests() {
+ final Integer[] testArray = {1, 2, 3};
+ Assert.assertNull(ArrayUtils.elementAt(testArray, -1));
+ Assert.assertTrue(ArrayUtils.elementAt(testArray, 0).equals(1));
+ Assert.assertTrue(ArrayUtils.elementAt(testArray, 1).equals(2));
+ Assert.assertTrue(ArrayUtils.elementAt(testArray, 2).equals(3));
+ Assert.assertNull(ArrayUtils.elementAt(testArray, 3));
+ }
+
+ /**
+ * Tests of {@link ArrayUtils#matchAndReplace(Object[], Object[], Object[])}.
+ * Tests the example used in the javadocs.
+ */
+ @Test
+ public void matchAndReplaceTests() {
+ final Integer[] actual = {1, 2, 3, 4, 1, 2, 3, 4};
+ final Integer[] match = {2, 3};
+ final Integer[] replace = {3, 2};
+ ArrayUtils.matchAndReplace(actual, match, replace);
+ final Integer[] expected = {1, 3, 2, 4, 1, 3, 2, 4};
+ Assert.assertArrayEquals(expected, actual);
+ }
+
+}
Property changes on: trunk/foray/foray-common/src/test/java/org/foray/common/primitive/ArrayUtilsTests.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-17 00:08:46
|
Revision: 12074
http://sourceforge.net/p/foray/code/12074
Author: victormote
Date: 2021-11-17 00:08:43 +0000 (Wed, 17 Nov 2021)
Log Message:
-----------
Improvements on the edges of lexers.
Modified Paths:
--------------
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/Lexer4a.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/LexerJavaBreakIterator.java
trunk/foray/foray-orthography/src/test/java/org/foray/orthography/LexerLatin1Tests.java
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/Lexer4a.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/Lexer4a.java 2021-11-16 20:50:33 UTC (rev 12073)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/Lexer4a.java 2021-11-17 00:08:43 UTC (rev 12074)
@@ -28,6 +28,8 @@
package org.foray.orthography;
+import org.foray.common.primitive.CharacterUtils;
+
import org.axsl.orthography.optional.Lexer;
/**
@@ -47,10 +49,18 @@
/** Character is non-word break content. */
NON_WORD_BREAK_CHAR,
+ /** Character is a leading attached punctuation item such as (in English) an opening quotation mark or opening
+ * parenthesis. */
+ ATTACHED_LEADING_PUNCTUATION,
+
+ /** Character is a trailing attached punctuation mark such as (in English) a comma, semicolon, or closing
+ * parenthesis. */
+ ATTACHED_TRAILING_PUNCTUATION,
+
/** There is no character here -- this is the end of the character sequence. */
END,
- /** Character is neither a word chard nor a break char. */
+ /** Character is none of the above. */
OTHER;
}
@@ -113,6 +123,12 @@
if (isWordChar(c)) {
return CharType.WORD_CHAR;
}
+ if (CharacterUtils.isAttachedLeadingPunctuation(c)) {
+ return CharType.ATTACHED_LEADING_PUNCTUATION;
+ }
+ if (CharacterUtils.isAttachedTrailingPunctuation(c)) {
+ return CharType.ATTACHED_TRAILING_PUNCTUATION;
+ }
return CharType.OTHER;
}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/LexerJavaBreakIterator.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/LexerJavaBreakIterator.java 2021-11-16 20:50:33 UTC (rev 12073)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/LexerJavaBreakIterator.java 2021-11-17 00:08:43 UTC (rev 12074)
@@ -127,6 +127,8 @@
case WORD_CHAR: {
break;
}
+ case ATTACHED_LEADING_PUNCTUATION:
+ case ATTACHED_TRAILING_PUNCTUATION:
case OTHER: {
if (breakTypes[1] == CharType.NON_WORD_BREAK_CHAR) {
/* Treat this as a word. */
@@ -148,12 +150,14 @@
final int sequenceIndex = rawBreaks.intAt(breakIndex);
final CharType currentBreakType = breakTypes[breakIndex];
final CharType previousBreakType = breakTypes[breakIndex - 1];
+ final CharType nextBreakType = currentBreakType == CharType.END ? null : breakTypes[breakIndex + 1];
currentBreakType: {
switch (currentBreakType) {
- case END:
+ case END: {
tokens.add(sequence.subSequence(startNextToken, sequence.length()));
break currentBreakType;
+ }
case NON_WORD_BREAK_CHAR: {
previousBreakType: {
switch (previousBreakType) {
@@ -162,6 +166,14 @@
startNextToken = sequenceIndex;
break previousBreakType;
}
+ case OTHER: {
+// nextBreakType: {
+//
+// }
+// tokens.add(sequence.subSequence(startNextToken, sequenceIndex));
+// startNextToken = sequenceIndex;
+ break previousBreakType;
+ }
default: {
break previousBreakType;
}
@@ -176,6 +188,8 @@
}
break currentBreakType;
}
+ case ATTACHED_LEADING_PUNCTUATION:
+ case ATTACHED_TRAILING_PUNCTUATION:
case OTHER: {
previousBreakType: {
switch (previousBreakType) {
@@ -186,12 +200,13 @@
startNextToken = sequenceIndex;
break previousBreakType;
}
+ case ATTACHED_LEADING_PUNCTUATION:
+ case ATTACHED_TRAILING_PUNCTUATION:
case OTHER: {
/* There is no change. Nothing to do here. */
break previousBreakType;
}
case NON_WORD_BREAK_CHAR: {
- final CharType nextBreakType = breakTypes[breakIndex + 1];
nextBreakType:
switch(nextBreakType) {
case NON_WORD_BREAK_CHAR: {
@@ -200,6 +215,8 @@
startNextToken = sequenceIndex;
break nextBreakType;
}
+ case ATTACHED_LEADING_PUNCTUATION:
+ case ATTACHED_TRAILING_PUNCTUATION:
case OTHER: {
break nextBreakType;
}
Modified: trunk/foray/foray-orthography/src/test/java/org/foray/orthography/LexerLatin1Tests.java
===================================================================
--- trunk/foray/foray-orthography/src/test/java/org/foray/orthography/LexerLatin1Tests.java 2021-11-16 20:50:33 UTC (rev 12073)
+++ trunk/foray/foray-orthography/src/test/java/org/foray/orthography/LexerLatin1Tests.java 2021-11-17 00:08:43 UTC (rev 12074)
@@ -172,4 +172,45 @@
Assert.assertEquals("%", actual.get(8));
}
+ /**
+ * Test of {@link LexerLatin1#breakIntoWords(CharSequence)} with attached leading and trailing punctuation.
+ * That punctuation should be included in the interword text unless it is detached, in which case it should be
+ * treated as a word.
+ */
+ @Test
+ @Ignore
+ public void testWithAttachedPunctuation() {
+ final String testString = "Parentheses (as I stated earlier) are a matching pair of ( and ) characters.";
+ final List<CharSequence> actual = this.out.tokenize(testString);
+ Assert.assertEquals(28, actual.size());
+ Assert.assertEquals("Parentheses", actual.get(0));
+ Assert.assertEquals(" (", actual.get(1));
+ Assert.assertEquals("as", actual.get(2));
+ Assert.assertEquals(" ", actual.get(3));
+ Assert.assertEquals("I", actual.get(4));
+ Assert.assertEquals(" ", actual.get(5));
+ Assert.assertEquals("stated", actual.get(6));
+ Assert.assertEquals(" ", actual.get(7));
+ Assert.assertEquals("earlier", actual.get(8));
+ Assert.assertEquals(") ", actual.get(9));
+ Assert.assertEquals("are", actual.get(10));
+ Assert.assertEquals(" ", actual.get(11));
+ Assert.assertEquals("a", actual.get(12));
+ Assert.assertEquals(" ", actual.get(13));
+ Assert.assertEquals("matching", actual.get(14));
+ Assert.assertEquals(" ", actual.get(15));
+ Assert.assertEquals("pair", actual.get(16));
+ Assert.assertEquals(" ", actual.get(17));
+ Assert.assertEquals("of", actual.get(18));
+ Assert.assertEquals(" ", actual.get(19));
+ Assert.assertEquals("(", actual.get(20));
+ Assert.assertEquals(" ", actual.get(21));
+ Assert.assertEquals("and", actual.get(22));
+ Assert.assertEquals(" ", actual.get(23));
+ Assert.assertEquals(")", actual.get(24));
+ Assert.assertEquals(" ", actual.get(25));
+ Assert.assertEquals("characters", actual.get(26));
+ Assert.assertEquals(".", actual.get(27));
+ }
+
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-11-16 20:50:35
|
Revision: 12073
http://sourceforge.net/p/foray/code/12073
Author: victormote
Date: 2021-11-16 20:50:33 +0000 (Tue, 16 Nov 2021)
Log Message:
-----------
Progress on word-breaking rework.
Modified Paths:
--------------
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/LexerJavaBreakIterator.java
trunk/foray/foray-orthography/src/test/java/org/foray/orthography/LexerLatin1Tests.java
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/LexerJavaBreakIterator.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/LexerJavaBreakIterator.java 2021-11-16 19:29:31 UTC (rev 12072)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/LexerJavaBreakIterator.java 2021-11-16 20:50:33 UTC (rev 12073)
@@ -146,44 +146,84 @@
int startNextToken = 0;
for (int breakIndex = 1; breakIndex < breakTypes.length; breakIndex ++) {
final int sequenceIndex = rawBreaks.intAt(breakIndex);
+ final CharType currentBreakType = breakTypes[breakIndex];
final CharType previousBreakType = breakTypes[breakIndex - 1];
- switch (breakTypes[breakIndex]) {
- case END:
- tokens.add(sequence.subSequence(startNextToken, sequence.length()));
- break;
- case NON_WORD_BREAK_CHAR: {
- if (previousBreakType == CharType.WORD_CHAR) {
- tokens.add(sequence.subSequence(startNextToken, sequenceIndex));
- startNextToken = sequenceIndex;
+ currentBreakType: {
+ switch (currentBreakType) {
+ case END:
+ tokens.add(sequence.subSequence(startNextToken, sequence.length()));
+ break currentBreakType;
+ case NON_WORD_BREAK_CHAR: {
+ previousBreakType: {
+ switch (previousBreakType) {
+ case WORD_CHAR: {
+ tokens.add(sequence.subSequence(startNextToken, sequenceIndex));
+ startNextToken = sequenceIndex;
+ break previousBreakType;
+ }
+ default: {
+ break previousBreakType;
+ }
+ }
+ }
+ break currentBreakType;
}
- break;
- }
- case WORD_CHAR: {
- if (previousBreakType == CharType.NON_WORD_BREAK_CHAR) {
- tokens.add(sequence.subSequence(startNextToken, sequenceIndex));
- startNextToken = sequenceIndex;
+ case WORD_CHAR: {
+ if (previousBreakType == CharType.NON_WORD_BREAK_CHAR) {
+ tokens.add(sequence.subSequence(startNextToken, sequenceIndex));
+ startNextToken = sequenceIndex;
+ }
+ break currentBreakType;
}
- break;
- }
- case OTHER: {
- final CharType nextBreakType = breakTypes[breakIndex + 1];
- if (previousBreakType == CharType.WORD_CHAR) {
- /* The previous item is a word and this is not. Treat it as the beginning of a non-word sequence. */
- tokens.add(sequence.subSequence(startNextToken, sequenceIndex));
- startNextToken = sequenceIndex;
- break;
+ case OTHER: {
+ previousBreakType: {
+ switch (previousBreakType) {
+ case WORD_CHAR: {
+ /* The previous item is a word and this is not. Treat it as the beginning of a non-word
+ * sequence. */
+ tokens.add(sequence.subSequence(startNextToken, sequenceIndex));
+ startNextToken = sequenceIndex;
+ break previousBreakType;
+ }
+ case OTHER: {
+ /* There is no change. Nothing to do here. */
+ break previousBreakType;
+ }
+ case NON_WORD_BREAK_CHAR: {
+ final CharType nextBreakType = breakTypes[breakIndex + 1];
+ nextBreakType:
+ switch(nextBreakType) {
+ case NON_WORD_BREAK_CHAR: {
+ /* Sitting between two word breaks. Treat this as a word. */
+ tokens.add(sequence.subSequence(startNextToken, sequenceIndex));
+ startNextToken = sequenceIndex;
+ break nextBreakType;
+ }
+ case OTHER: {
+ break nextBreakType;
+ }
+ case WORD_CHAR: {
+ /* After a break and before a word. This is interword content. */
+ break nextBreakType;
+ }
+ case END: {
+ /* This can't happen. */
+ break nextBreakType;
+ }
+ }
+ break previousBreakType;
+ }
+ case END: {
+ /* This shouldn't happen. */
+ break previousBreakType;
+ }
+ }
+ break currentBreakType;
+ }
}
- if (nextBreakType == CharType.NON_WORD_BREAK_CHAR) {
- /* Treat this as a word. */
- tokens.add(sequence.subSequence(startNextToken, sequenceIndex));
- startNextToken = sequenceIndex;
- } else {
- /* The next token starts a word. Treat this is non-word. */
}
- break;
}
- }
}
return tokens;
Modified: trunk/foray/foray-orthography/src/test/java/org/foray/orthography/LexerLatin1Tests.java
===================================================================
--- trunk/foray/foray-orthography/src/test/java/org/foray/orthography/LexerLatin1Tests.java 2021-11-16 19:29:31 UTC (rev 12072)
+++ trunk/foray/foray-orthography/src/test/java/org/foray/orthography/LexerLatin1Tests.java 2021-11-16 20:50:33 UTC (rev 12073)
@@ -76,11 +76,10 @@
* A more complicated test of {@link LexerLatin1#breakIntoWords(CharSequence)}.
*/
@Test
- @Ignore
public void testMedium() {
final String testString = "39. It was the best of times. It was the worst of times. <----";
final List<CharSequence> actual = this.out.tokenize(testString);
- Assert.assertEquals(27, actual.size());
+ Assert.assertEquals(28, actual.size());
Assert.assertEquals("39", actual.get(0));
Assert.assertEquals(". ", actual.get(1));
Assert.assertEquals("It", actual.get(2));
@@ -107,7 +106,8 @@
Assert.assertEquals(" ", actual.get(23));
Assert.assertEquals("times", actual.get(24));
Assert.assertEquals(". ", actual.get(25));
- Assert.assertEquals("<----", actual.get(26));
+ Assert.assertEquals("<", actual.get(26));
+ Assert.assertEquals("----", actual.get(27));
}
/**
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-11-16 19:29:34
|
Revision: 12072
http://sourceforge.net/p/foray/code/12072
Author: victormote
Date: 2021-11-16 19:29:31 +0000 (Tue, 16 Nov 2021)
Log Message:
-----------
Rework the lexers. This work is incomplete.
Modified Paths:
--------------
trunk/foray/foray-common/src/main/java/org/foray/common/primitive/CharacterUtils.java
trunk/foray/foray-orthography/src/main/data/orthographies/foray-orthography-config.xml
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/Lexer4a.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/LexerDefault.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/LexerLatin1.java
trunk/foray/foray-orthography/src/test/java/org/foray/orthography/LexerLatin1Tests.java
trunk/foray/foray-orthography/src/test/resources/orthography-config.xml
Added Paths:
-----------
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/LexerJavaBreakIterator.java
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/primitive/CharacterUtils.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/primitive/CharacterUtils.java 2021-11-16 19:28:30 UTC (rev 12071)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/primitive/CharacterUtils.java 2021-11-16 19:29:31 UTC (rev 12072)
@@ -44,7 +44,7 @@
public final class CharacterUtils {
/** The maximum printable ASCII character, a tilde ~, 0x7E, 126. */
- public static final char MAX_PRINTABLE_ASCII_CHAR = '\u007E';
+ public static final char MAX_PRINTABLE_ASCII_CHAR = Basic_Latin_Block.TILDE;
/** The punctuation characters which, when they immediately precede a word, should not be separated from that word
* during line-breaking. TODO: This list is not comprehensive and should be improved. */
Modified: trunk/foray/foray-orthography/src/main/data/orthographies/foray-orthography-config.xml
===================================================================
--- trunk/foray/foray-orthography/src/main/data/orthographies/foray-orthography-config.xml 2021-11-16 19:28:30 UTC (rev 12071)
+++ trunk/foray/foray-orthography/src/main/data/orthographies/foray-orthography-config.xml 2021-11-16 19:29:31 UTC (rev 12072)
@@ -196,7 +196,7 @@
<dictionary reference="dictionary-eng-moby"/>
<hyphenation-patterns reference="hyph-patterns-eng"/>
<derivative-factories reference="eng-999-derivatives"/>
- <lexer class="org.foray.orthography.LexerLatin1"/>
+ <lexer class="org.foray.orthography.LexerJavaBreakIterator"/>
<orthography language-iso-3char="eng" country-iso-3char="USA" script-iso-4char="Latn"/>
<orthography language-iso-3char="eng" country-iso-3char="USA" script-iso-4char="Zyyy"/>
<orthography language-iso-3char="eng" country-iso-3char="999" script-iso-4char="Latn"/>
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/Lexer4a.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/Lexer4a.java 2021-11-16 19:28:30 UTC (rev 12071)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/Lexer4a.java 2021-11-16 19:29:31 UTC (rev 12072)
@@ -28,14 +28,8 @@
package org.foray.orthography;
-import org.foray.common.sequence.IntArray;
-import org.foray.common.sequence.IntArrayBuilder;
-
import org.axsl.orthography.optional.Lexer;
-import java.util.ArrayList;
-import java.util.List;
-
/**
* Implementations know how to break a character sequence into words and interword content.
*/
@@ -47,132 +41,28 @@
*/
public enum CharType {
- /** Character is always part of a word. */
- ALWAYS_WORD_CHAR,
+ /** Character is part of a word. */
+ WORD_CHAR,
- /** Character is never part of a word. */
- NEVER_WORD_CHAR,
+ /** Character is non-word break content. */
+ NON_WORD_BREAK_CHAR,
- /** Character may be part of a word, depending on context. */
- SOMETIMES_WORD_CHAR;
+ /** There is no character here -- this is the end of the character sequence. */
+ END,
- }
+ /** Character is neither a word chard nor a break char. */
+ OTHER;
- /**
- * Returns the word and interword content of a given character sequence.
- * Even-numbered indexes in the array always contain a word, and odd-numbered indexes always contain interword
- * content.
- * In the case that the sequence actually starts with interword content (instead of the more normal case of starting
- * with a word), element 0 will contain an empty string.
- * @param sequence The character sequence to be parsed.
- * @return The list of word and interword content parsed from {@code sequence}.
- */
- public List<CharSequence> tokenize(final CharSequence sequence) {
- final IntArray wordBreaks = findWordBreaks(sequence);
- final List<CharSequence> wordChunks = new ArrayList<CharSequence>(wordBreaks.length());
- if (wordBreaks.length() < 1) {
- return wordChunks;
- }
- for (int index = 0; index < wordBreaks.length() - 1; index ++) {
- final int start = Math.max(0, wordBreaks.intAt(index));
- final int end = wordBreaks.intAt(index + 1);
- final CharSequence wordChunk = sequence.subSequence(start, end);
- wordChunks.add(wordChunk);
- }
- final int finalStart = wordBreaks.lastInt();
- final int finalEnd = sequence.length();
- final CharSequence finalWordChunk = sequence.subSequence(finalStart, finalEnd);
- wordChunks.add(finalWordChunk);
- return wordChunks;
}
- /**
- * Records the index to the beginning of each word and interword area in an integer array.
- * Even-numbered indexes in the array always point to the beginning of a word, and odd-numbered indexes always point
- * to interword content.
- * In the normal case that the sequence starts with a word, element 0 will always be 0.
- * In the case that the sequence actually starts with interword content, element 0 will always be -1,
- * element 1 will always be 0 to mark the beginning of the leading interword content, and element 2 will always mark
- * the beginning of the first word.
- * The element at index n+1 will always be greater than the element at index n.
- * All content in the sequence is accounted for.
- * @param sequence The character sequence to be parsed.
- * @return An array of integers that marks the beginning of each word and interword item.
- */
- public IntArray findWordBreaks(final CharSequence sequence) {
- final IntArrayBuilder builder = new IntArrayBuilder();
- boolean inWord = false;
- for (int index = 0; index < sequence.length(); index++) {
- final boolean isWordChar = isWordChar(sequence, index);
- switch (index) {
- case 0: {
- if (isWordChar) {
- inWord = true;
- builder.append(index);
- } else {
- builder.append(-1);
- builder.append(index);
- }
- break;
- }
- default: {
- if (isWordChar) {
- if (! inWord) {
- inWord = true;
- builder.append(index);
- }
- } else {
- if (inWord) {
- inWord = false;
- builder.append(index);
- }
- }
-
- }
- }
- }
-
- return builder.toIntArray();
- }
-
/**
- * Indicates whether a given character in a sequence should be treated as a word character or not, taking the
- * context into consideration where necessary.
- * @param sequence The character sequence.
- * @param index The index to the item in {@code sequence} that is being tested.
- * @return True if and only if the char at {@code index} should be treated as a word character.
- */
- public boolean isWordChar(final CharSequence sequence, final int index) {
- if (index < 0
- || index >= sequence.length()) {
- return false;
- }
- final char c = sequence.charAt(index);
- final CharType charType = isWordChar(c);
- switch (charType) {
- case ALWAYS_WORD_CHAR: {
- return true;
- }
- case NEVER_WORD_CHAR: {
- return false;
- }
- case SOMETIMES_WORD_CHAR: {
- return resolveSometimesCase(sequence, index);
- }
- default: {
- throw new IllegalStateException("Unexpected isWordChar value: " + charType);
- }
- }
- }
-
- /**
- * Indicates whether a given character is a word character.
+ * Indicates whether a given Unicode code point is a word character.
* Subclasses should override this as needed.
* @param c The character being tested.
* @return Indication of whether {@code c} is always a word character, never one, or sometimes one.
*/
- public CharType isWordChar(final char c) {
+ public boolean isWordChar(final int c) {
final int type = Character.getType(c);
switch (type) {
@@ -188,81 +78,42 @@
case Character.LETTER_NUMBER:
case Character.OTHER_NUMBER:
case Character.OTHER_SYMBOL: {
- return CharType.ALWAYS_WORD_CHAR;
+ return true;
}
- /* Comment out the "false" values, for performance. */
-// case Character.COMBINING_SPACING_MARK:
-// case Character.CONNECTOR_PUNCTUATION:
-// case Character.CONTROL:
-// case Character.DASH_PUNCTUATION:
-// case Character.ENCLOSING_MARK:
-// case Character.END_PUNCTUATION:
-// case Character.FINAL_QUOTE_PUNCTUATION:
-// case Character.FORMAT:
-// case Character.INITIAL_QUOTE_PUNCTUATION:
-// case Character.LINE_SEPARATOR:
-// case Character.MODIFIER_SYMBOL:
-// case Character.NON_SPACING_MARK:
-// case Character.OTHER_PUNCTUATION:
-// case Character.PARAGRAPH_SEPARATOR:
-// case Character.PRIVATE_USE:
-// case Character.SPACE_SEPARATOR:
-// case Character.START_PUNCTUATION:
-// case Character.SURROGATE:
-// case Character.UNASSIGNED: {
-// return false;
-// }
default: {
- break;
+ return false;
}
}
-
- if (isSometimesWordChar(c)) {
- return CharType.SOMETIMES_WORD_CHAR;
- }
- return CharType.NEVER_WORD_CHAR;
}
/**
- * Indicates whether a char is a possible word character, depending on context.
- * For example, in English, a single quote or typographic apostrophe could be the end of a quotation (not a word
- * character), or mark a contraction or possession (is a word character).
- * @param c The character to be tested.
- * @return True if and only if {@code c} is sometimes (but not always) a word character.
+ * Indicates whether a given Unicode code point is a break character.
+ * @param c The codepoint to be tested.
+ * @return True if and only if {@code c} is a break character.
*/
- public abstract boolean isSometimesWordChar(char c);
+ public boolean isBreakChar(final int c) {
+ switch(c) {
+ case ' ': return true;
+ case '\r': return true;
+ case '\n': return true;
+ case '\t': return true;
+ }
+ return false;
+ }
/**
- * Indicates whether a given character, which should have already been identified as being
- * {@link CharType#SOMETIMES_WORD_CHAR} a word character, should be treated as a word character, taking context
- * into consideration.
- * @param sequence The entire sequence under examination.
- * @param index The index of the character being tested.
- * @return True if and only if the character at {@code index} should be considered a word character in this
- * context.
+ * Computes the word-breaking type of a char.
+ * @param c The char being tested.
+ * @return The word-breaking type of {@code c}.
*/
- public abstract boolean resolveSometimesCase(CharSequence sequence, int index);
-
- /**
- * Index-safe query into a specific char in a sequence, indicating whether it is always a word char or not.
- * A return value of false does <em>not</em> mean that the char should not be treated as a word char in this case,
- * only that it might not be.
- * This is a convenience method that helps subclasses see other characters in the context of the entire sequence.
- * For example, if the index "i" being tested in {@link #isWordChar(char)} contains a "sometimes" char, this method
- * can be used to easily determine if the previous char is always a word char: isAlwaysWordChar(sequence, n - 1).
- * @param sequence The sequence to be tested.
- * @param index The index to the char in {@code sequence} that is being tested.
- * If this index is an out-of-bounds value, this method will return false.
- * @return True if and only if the char at {@code index} is always a word char.
- */
- public boolean isAlwaysWordChar(final CharSequence sequence, final int index) {
- if (index < 0
- || index >= sequence.length()) {
- return false;
+ public CharType computeCharType(final int c) {
+ if (isBreakChar(c)) {
+ return CharType.NON_WORD_BREAK_CHAR;
}
- final char c = sequence.charAt(index);
- final CharType charType = isWordChar(c);
- return charType == CharType.ALWAYS_WORD_CHAR;
+ if (isWordChar(c)) {
+ return CharType.WORD_CHAR;
+ }
+ return CharType.OTHER;
}
}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/LexerDefault.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/LexerDefault.java 2021-11-16 19:28:30 UTC (rev 12071)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/LexerDefault.java 2021-11-16 19:29:31 UTC (rev 12072)
@@ -32,16 +32,6 @@
* A default Lexer implementation that uses only the Unicode character information to determine whether a given
* character in a sequence is part of a word or not.
*/
-public class LexerDefault extends Lexer4a {
+public class LexerDefault extends LexerJavaBreakIterator {
- @Override
- public boolean isSometimesWordChar(final char c) {
- return false;
- }
-
- @Override
- public boolean resolveSometimesCase(final CharSequence sequence, final int index) {
- return false;
- }
-
}
Added: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/LexerJavaBreakIterator.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/LexerJavaBreakIterator.java (rev 0)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/LexerJavaBreakIterator.java 2021-11-16 19:29:31 UTC (rev 12072)
@@ -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.orthography;
+
+import org.foray.common.primitive.StringUtils;
+import org.foray.common.sequence.IntArrayBuilder;
+
+import org.axsl.common.sequence.IntSequence;
+import org.axsl.orthography.optional.Lexer;
+
+import java.text.BreakIterator;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Locale;
+
+/**
+ * {@link Lexer} implementation that uses the Java {@link BreakIterator}.
+ */
+public class LexerJavaBreakIterator extends Lexer4a {
+
+ /**
+ * Uses the Java BreakIterator to find the breaks that it detects.
+ * @param sequence The sequence whose breaks are needed.
+ * @return The sequence of breaks, indexes into {@code sequence}.
+ */
+ IntSequence findRawBreaks(final CharSequence sequence) {
+ final IntArrayBuilder result = new IntArrayBuilder(sequence.length());
+ /* TODO: BreakIterators are reusable, not thread-safe, and expensive to create. Reuse this after figuring out
+ * how instances of this class are used/reused. */
+ final BreakIterator wordIterator = BreakIterator.getWordInstance(Locale.US);
+ wordIterator.setText(sequence.toString());
+ int boundary = wordIterator.first();
+
+ while (boundary != BreakIterator.DONE) {
+ result.append(boundary);
+ boundary = wordIterator.next();
+ }
+ return result;
+ }
+
+ /**
+ * Determines the type of character that triggered each raw break.
+ * @param sequence The characters being tokenized.
+ * @param rawBreaks The raw breaks.
+ * @return An array with a one-to-one correspondence with {@code rawBreaks}, containing the type of character at
+ * that break.
+ */
+ CharType[] findBreakTypes(final CharSequence sequence, final IntSequence rawBreaks) {
+ final CharType[] breakTypes = new CharType[rawBreaks.length()];
+ for (int breakIndex = 0; breakIndex < rawBreaks.length(); breakIndex ++) {
+ if (breakIndex >= rawBreaks.length() - 1) {
+ breakTypes[breakIndex] = CharType.END;
+ } else {
+ final int sequenceIndex = rawBreaks.intAt(breakIndex);
+ final int testChar = sequence.charAt(sequenceIndex);
+ breakTypes[breakIndex] = computeCharType(testChar);
+ }
+ }
+ return breakTypes;
+ }
+
+ @Override
+ public List<CharSequence> tokenize(final CharSequence sequence) {
+ if (sequence == null
+ || sequence.length() < 1) {
+ return Collections.emptyList();
+ }
+
+ /* First pass is to find all of the breaks that the BreakIterator can find. */
+ final IntSequence rawBreaks = findRawBreaks(sequence);
+
+
+ /* The BreakIterator is helpful, but for our purposes does not dig deeply enough.
+ * Our purpose is to find where words start and end and to treat all other content as non-word or interword
+ * content.
+ * So our second pass is to find out the type of each character that is at a break. */
+ final CharType[] breakTypes = findBreakTypes(sequence, rawBreaks);
+
+ /* The third pass detects which of the breaks we care about based on their type and context. */
+ final List<CharSequence> tokens = new ArrayList<CharSequence>();
+
+ /* Handle the case of only one break. It is either a single-token word, or non-word content that must be
+ * preceded by an empty word. We will treat anything that is not a break char as part of a word. */
+ if (breakTypes.length == 1) {
+ if (breakTypes[0] == CharType.NON_WORD_BREAK_CHAR) {
+ tokens.add(StringUtils.EMPTY_STRING);
+ }
+ tokens.add(sequence);
+ return tokens;
+ }
+
+ /* There are at least two tokens. */
+
+ /* Index 0 is special. */
+ switch (breakTypes[0]) {
+ case NON_WORD_BREAK_CHAR: {
+ tokens.add(StringUtils.EMPTY_STRING);
+ break;
+ }
+ case WORD_CHAR: {
+ break;
+ }
+ case OTHER: {
+ if (breakTypes[1] == CharType.NON_WORD_BREAK_CHAR) {
+ /* Treat this as a word. */
+ } else {
+ /* The next token starts a word. Threat this is non-word. */
+ tokens.add(StringUtils.EMPTY_STRING);
+ }
+ break;
+ }
+ case END:
+ /* This shouldn't happen. */
+ break;
+ }
+
+
+ /* Now iterate the remaining breaks. */
+ int startNextToken = 0;
+ for (int breakIndex = 1; breakIndex < breakTypes.length; breakIndex ++) {
+ final int sequenceIndex = rawBreaks.intAt(breakIndex);
+ final CharType previousBreakType = breakTypes[breakIndex - 1];
+
+ switch (breakTypes[breakIndex]) {
+ case END:
+ tokens.add(sequence.subSequence(startNextToken, sequence.length()));
+ break;
+ case NON_WORD_BREAK_CHAR: {
+ if (previousBreakType == CharType.WORD_CHAR) {
+ tokens.add(sequence.subSequence(startNextToken, sequenceIndex));
+ startNextToken = sequenceIndex;
+ }
+ break;
+ }
+ case WORD_CHAR: {
+ if (previousBreakType == CharType.NON_WORD_BREAK_CHAR) {
+ tokens.add(sequence.subSequence(startNextToken, sequenceIndex));
+ startNextToken = sequenceIndex;
+ }
+ break;
+ }
+ case OTHER: {
+ final CharType nextBreakType = breakTypes[breakIndex + 1];
+ if (previousBreakType == CharType.WORD_CHAR) {
+ /* The previous item is a word and this is not. Treat it as the beginning of a non-word sequence. */
+ tokens.add(sequence.subSequence(startNextToken, sequenceIndex));
+ startNextToken = sequenceIndex;
+ break;
+ }
+ if (nextBreakType == CharType.NON_WORD_BREAK_CHAR) {
+ /* Treat this as a word. */
+ tokens.add(sequence.subSequence(startNextToken, sequenceIndex));
+ startNextToken = sequenceIndex;
+ } else {
+ /* The next token starts a word. Treat this is non-word. */
+ }
+ break;
+ }
+ }
+ }
+
+ return tokens;
+ }
+
+}
Property changes on: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/LexerJavaBreakIterator.java
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Rev
\ No newline at end of property
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/LexerLatin1.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/LexerLatin1.java 2021-11-16 19:28:30 UTC (rev 12071)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/LexerLatin1.java 2021-11-16 19:29:31 UTC (rev 12072)
@@ -28,67 +28,9 @@
package org.foray.orthography;
-import org.axsl.unicode.block.Basic_Latin_Block;
-import org.axsl.unicode.block.General_Punctuation_Block;
-
/**
* A {@link Lexer4a} implementation that is intended for general use for Latin writing systems.
*/
-public class LexerLatin1 extends Lexer4a {
+public class LexerLatin1 extends LexerJavaBreakIterator {
- @Override
- public CharType isWordChar(final char c) {
- switch (c) {
- case '-': return CharType.ALWAYS_WORD_CHAR;
- case '&': return CharType.ALWAYS_WORD_CHAR;
- default: return super.isWordChar(c);
- }
- }
-
- @Override
- public boolean isSometimesWordChar(final char c) {
- switch (c) {
- /* Typographic apostrophe. */
- case General_Punctuation_Block.RIGHT_SINGLE_QUOTATION_MARK:
- case Basic_Latin_Block.APOSTROPHE: {
- return true;
- }
- default: {
- return false;
- }
- }
- }
-
- @Override
- public boolean resolveSometimesCase(final CharSequence sequence, final int index) {
- boolean returnValue = false;
- final char c = sequence.charAt(index);
-// final boolean previousIsAlwaysWordChar = isAlwaysWordChar(sequence, index - 1);
- final boolean nextIsAlwaysWordChar = isAlwaysWordChar(sequence, index + 1);
-
- switch (c) {
- case General_Punctuation_Block.RIGHT_SINGLE_QUOTATION_MARK: {
- if (nextIsAlwaysWordChar) {
- /* Looks like a contraction (like can't or 'tis) or possessive (like Harold's). */
- returnValue = true;
- }
- /* TODO: Add logic checking whether this is a closing single quotation mark. */
- break;
- }
- case Basic_Latin_Block.APOSTROPHE: {
- /* Similar to single quotation mark, but this character can also act as an opening quotation mark. */
- if (nextIsAlwaysWordChar) {
- /* Looks like a contraction (like can't or 'tis) or possessive (like Harold's). */
- returnValue = true;
- }
- /* TODO: Add logic checking whether this is a closing single quotation mark. */
- break;
- }
- default: {
- returnValue = false;
- }
- }
- return returnValue;
- }
-
}
Modified: trunk/foray/foray-orthography/src/test/java/org/foray/orthography/LexerLatin1Tests.java
===================================================================
--- trunk/foray/foray-orthography/src/test/java/org/foray/orthography/LexerLatin1Tests.java 2021-11-16 19:28:30 UTC (rev 12071)
+++ trunk/foray/foray-orthography/src/test/java/org/foray/orthography/LexerLatin1Tests.java 2021-11-16 19:29:31 UTC (rev 12072)
@@ -30,6 +30,7 @@
import org.junit.Assert;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
import java.util.List;
@@ -40,7 +41,8 @@
public class LexerLatin1Tests {
/** The object under test. */
- private LexerLatin1 out;
+ private LexerJavaBreakIterator out;
+ /* TODO: This is temporarily referencing the wrong type. */
/**
* Setup the test.
@@ -47,7 +49,7 @@
*/
@Before
public void setupTest() {
- this.out = new LexerLatin1();
+ this.out = new LexerJavaBreakIterator();
}
/**
@@ -74,6 +76,7 @@
* A more complicated test of {@link LexerLatin1#breakIntoWords(CharSequence)}.
*/
@Test
+ @Ignore
public void testMedium() {
final String testString = "39. It was the best of times. It was the worst of times. <----";
final List<CharSequence> actual = this.out.tokenize(testString);
@@ -148,4 +151,25 @@
Assert.assertEquals("thing", actual.get(6));
}
+ /**
+ * Test of {@link LexerLatin1#breakIntoWords(CharSequence)} with a bunch of symbols that are not really words.
+ * However, because each one is between hard word breaks, should be tokenized as words.
+ */
+ @Test
+ @Ignore
+ public void testWithSymbolsAsWords() {
+ final String testString = "! @ # $ %";
+ final List<CharSequence> actual = this.out.tokenize(testString);
+ Assert.assertEquals(9, actual.size());
+ Assert.assertEquals("!", actual.get(0));
+ Assert.assertEquals(" ", actual.get(1));
+ Assert.assertEquals("@", actual.get(2));
+ Assert.assertEquals(" ", actual.get(3));
+ Assert.assertEquals("#", actual.get(4));
+ Assert.assertEquals(" ", actual.get(5));
+ Assert.assertEquals("$", actual.get(6));
+ Assert.assertEquals(" ", actual.get(7));
+ Assert.assertEquals("%", actual.get(8));
+ }
+
}
Modified: trunk/foray/foray-orthography/src/test/resources/orthography-config.xml
===================================================================
--- trunk/foray/foray-orthography/src/test/resources/orthography-config.xml 2021-11-16 19:28:30 UTC (rev 12071)
+++ trunk/foray/foray-orthography/src/test/resources/orthography-config.xml 2021-11-16 19:29:31 UTC (rev 12072)
@@ -129,7 +129,7 @@
<dictionary reference="dictionary-eng-moby"/>
<hyphenation-patterns reference="hyph-patterns-eng"/>
<derivative-factories reference="derivatives-eng"/>
- <lexer class="org.foray.orthography.LexerLatin1"/>
+ <lexer class="org.foray.orthography.LexerJavaBreakIterator"/>
<orthography language-iso-3char="eng" country-iso-3char="USA" script-iso-4char="Latn"/>
<orthography language-iso-3char="eng" country-iso-3char="USA" script-iso-4char="Zyyy"/>
</configuration>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-11-16 19:28:32
|
Revision: 12071
http://sourceforge.net/p/foray/code/12071
Author: victormote
Date: 2021-11-16 19:28:30 +0000 (Tue, 16 Nov 2021)
Log Message:
-----------
Hard-code the location of the orthography file for the tests of record.
Modified Paths:
--------------
trunk/foray/foray-app/src/test/java/org/foray/app/fo/FoDocumentReader.java
Modified: trunk/foray/foray-app/src/test/java/org/foray/app/fo/FoDocumentReader.java
===================================================================
--- trunk/foray/foray-app/src/test/java/org/foray/app/fo/FoDocumentReader.java 2021-11-16 14:31:11 UTC (rev 12070)
+++ trunk/foray/foray-app/src/test/java/org/foray/app/fo/FoDocumentReader.java 2021-11-16 19:28:30 UTC (rev 12071)
@@ -57,7 +57,6 @@
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
-import java.util.Properties;
import javax.xml.parsers.ParserConfigurationException;
@@ -83,10 +82,7 @@
* objects.
*/
private FoDocumentReader() throws IOException, ForayException {
- 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 orthographyConfigPath = "../foray-orthography/src/test/resources/orthography-config.xml";
final URL orthographyFile = new URL("file", null, orthographyConfigPath);
final Logger logger = LoggerFactory.getLogger(FoDocumentReader.class);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-11-16 14:31:13
|
Revision: 12070
http://sourceforge.net/p/foray/code/12070
Author: victormote
Date: 2021-11-16 14:31:11 +0000 (Tue, 16 Nov 2021)
Log Message:
-----------
Move some uses of character definitions to the Unicode code blocks.
Modified Paths:
--------------
trunk/foray/foray-common/src/main/java/org/foray/common/primitive/CharacterUtils.java
trunk/foray/foray-linebreak/src/main/java/org/foray/text/line/solitary/SolitaryLineBreaker.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/LexerLatin1.java
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/primitive/CharacterUtils.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/primitive/CharacterUtils.java 2021-11-15 13:12:15 UTC (rev 12069)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/primitive/CharacterUtils.java 2021-11-16 14:31:11 UTC (rev 12070)
@@ -43,18 +43,6 @@
*/
public final class CharacterUtils {
- /** The typographical single open quotation mark: \u2018. */
- public static final char SINGLE_OPEN_QUOTATION_MARK = '\u2018';
-
- /** The typographical apostrophe or single close quotation mark: \u2019. */
- public static final char SINGLE_CLOSE_QUOTATION_MARK = '\u2019';
-
- /** The typographical double open quotation mark: \u201C. */
- public static final char DOUBLE_OPEN_QUOTATION_MARK = '\u201C';
-
- /** The typographical double close quotation mark: \u201D. */
- public static final char DOUBLE_CLOSE_QUOTATION_MARK = '\u201D';
-
/** The maximum printable ASCII character, a tilde ~, 0x7E, 126. */
public static final char MAX_PRINTABLE_ASCII_CHAR = '\u007E';
@@ -61,17 +49,27 @@
/** The punctuation characters which, when they immediately precede a word, should not be separated from that word
* during line-breaking. TODO: This list is not comprehensive and should be improved. */
private static final String ATTACHED_LEADING_PUNCTUATION = new String(new char[] {
- '(', '[',
- SINGLE_OPEN_QUOTATION_MARK,
- DOUBLE_OPEN_QUOTATION_MARK,
+ Basic_Latin_Block.LEFT_PARENTHESIS,
+ Basic_Latin_Block.LEFT_SQUARE_BRACKET,
+ General_Punctuation_Block.LEFT_SINGLE_QUOTATION_MARK,
+ General_Punctuation_Block.LEFT_DOUBLE_QUOTATION_MARK,
});
/** The punctuation characters which, when they immediately follow a word, should not be separated from that word
* during line-breaking. TODO: This list is not comprehensive and should be improved. */
private static final String ATTACHED_TRAILING_PUNCTUATION = new String(new char[] {
- '.', ',', ';', ':', '!', '?', '\'', '"', ')', ']',
- SINGLE_CLOSE_QUOTATION_MARK,
- DOUBLE_CLOSE_QUOTATION_MARK,
+ Basic_Latin_Block.FULL_STOP, // A period '.'
+ Basic_Latin_Block.COMMA,
+ Basic_Latin_Block.SEMICOLON,
+ Basic_Latin_Block.COLON,
+ Basic_Latin_Block.EXCLAMATION_MARK,
+ Basic_Latin_Block.QUESTION_MARK,
+ Basic_Latin_Block.APOSTROPHE,
+ Basic_Latin_Block.QUOTATION_MARK,
+ Basic_Latin_Block.RIGHT_PARENTHESIS,
+ Basic_Latin_Block.RIGHT_SQUARE_BRACKET,
+ General_Punctuation_Block.RIGHT_SINGLE_QUOTATION_MARK,
+ General_Punctuation_Block.RIGHT_DOUBLE_QUOTATION_MARK,
});
/** The punctuation characters which, when they immediately follow a word, can be separated from that word during
@@ -78,7 +76,7 @@
* line-breaking, but which preferably should not be separated. TODO: This list is not comprehensive and should be
* improved. */
private static final String DETACHABLE_PUNCTUATION = new String(new char[] {
- 0x2013, /* En-dash */
+ General_Punctuation_Block.EN_DASH,
});
/** The punctuation characters which, when they immediately follow a word, can be separated from that word during
@@ -85,7 +83,7 @@
* line-breaking, but which preferably should not be separated. TODO: This list is not comprehensive and should be
* improved.*/
private static final String DETACHED_PUNCTUATION = new String(new char[] {
- 0x2014, /* Em-dash */
+ General_Punctuation_Block.EM_DASH,
});
/**
Modified: trunk/foray/foray-linebreak/src/main/java/org/foray/text/line/solitary/SolitaryLineBreaker.java
===================================================================
--- trunk/foray/foray-linebreak/src/main/java/org/foray/text/line/solitary/SolitaryLineBreaker.java 2021-11-15 13:12:15 UTC (rev 12069)
+++ trunk/foray/foray-linebreak/src/main/java/org/foray/text/line/solitary/SolitaryLineBreaker.java 2021-11-16 14:31:11 UTC (rev 12070)
@@ -28,7 +28,6 @@
package org.foray.text.line.solitary;
-import org.foray.common.primitive.CharacterUtils;
import org.foray.text.TextServer4a;
import org.foray.text.line.EagerLineBreaker;
@@ -41,6 +40,7 @@
import org.axsl.text.TextException;
import org.axsl.text.line.LineBreakHandler;
import org.axsl.text.line.LineText;
+import org.axsl.unicode.block.General_Punctuation_Block;
/**
* An "eager" line-breaking implementaton which considers only the current line
@@ -578,7 +578,7 @@
private boolean isSometimesWordChar(final char c) {
switch (c) {
/* Typographic apostrophe. */
- case CharacterUtils.SINGLE_CLOSE_QUOTATION_MARK:
+ case General_Punctuation_Block.RIGHT_SINGLE_QUOTATION_MARK:
case '\'': {
return true;
}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/LexerLatin1.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/LexerLatin1.java 2021-11-15 13:12:15 UTC (rev 12069)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/LexerLatin1.java 2021-11-16 14:31:11 UTC (rev 12070)
@@ -28,7 +28,8 @@
package org.foray.orthography;
-import org.foray.common.primitive.CharacterUtils;
+import org.axsl.unicode.block.Basic_Latin_Block;
+import org.axsl.unicode.block.General_Punctuation_Block;
/**
* A {@link Lexer4a} implementation that is intended for general use for Latin writing systems.
@@ -48,8 +49,8 @@
public boolean isSometimesWordChar(final char c) {
switch (c) {
/* Typographic apostrophe. */
- case CharacterUtils.SINGLE_CLOSE_QUOTATION_MARK:
- case '\'': {
+ case General_Punctuation_Block.RIGHT_SINGLE_QUOTATION_MARK:
+ case Basic_Latin_Block.APOSTROPHE: {
return true;
}
default: {
@@ -66,7 +67,7 @@
final boolean nextIsAlwaysWordChar = isAlwaysWordChar(sequence, index + 1);
switch (c) {
- case CharacterUtils.SINGLE_CLOSE_QUOTATION_MARK: {
+ case General_Punctuation_Block.RIGHT_SINGLE_QUOTATION_MARK: {
if (nextIsAlwaysWordChar) {
/* Looks like a contraction (like can't or 'tis) or possessive (like Harold's). */
returnValue = true;
@@ -74,7 +75,7 @@
/* TODO: Add logic checking whether this is a closing single quotation mark. */
break;
}
- case '\'': {
+ case Basic_Latin_Block.APOSTROPHE: {
/* Similar to single quotation mark, but this character can also act as an opening quotation mark. */
if (nextIsAlwaysWordChar) {
/* Looks like a contraction (like can't or 'tis) or possessive (like Harold's). */
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-11-15 13:12:18
|
Revision: 12069
http://sourceforge.net/p/foray/code/12069
Author: victormote
Date: 2021-11-15 13:12:15 +0000 (Mon, 15 Nov 2021)
Log Message:
-----------
1. Conform to aXSL change: Require WritingSystem for graphics containing text. 2. Use same to remove remaining hard-coded instances of WritingSystem.
Modified Paths:
--------------
trunk/foray/foray-graphic/src/main/java/org/foray/graphic/batik/PdfTextPainter.java
trunk/foray/foray-graphic/src/main/java/org/foray/graphic/output/SvgPdf.java
trunk/foray/foray-linebreak/src/main/java/org/foray/text/line/LineBreaker.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXformMath.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXformSvg.java
Modified: trunk/foray/foray-graphic/src/main/java/org/foray/graphic/batik/PdfTextPainter.java
===================================================================
--- trunk/foray/foray-graphic/src/main/java/org/foray/graphic/batik/PdfTextPainter.java 2021-11-15 12:39:53 UTC (rev 12068)
+++ trunk/foray/foray-graphic/src/main/java/org/foray/graphic/batik/PdfTextPainter.java 2021-11-15 13:12:15 UTC (rev 12069)
@@ -34,8 +34,8 @@
package org.foray.graphic.batik;
import org.foray.common.WellKnownConstants;
-import org.foray.common.i18n.WritingSystem4a;
+import org.axsl.common.i18n.WritingSystem;
import org.axsl.font.Font;
import org.axsl.font.FontConsumer;
import org.axsl.font.FontException;
@@ -80,6 +80,9 @@
/** The FontConsumer that should be used for font resolution. */
private FontConsumer fontConsumer;
+ /** The writing system. */
+ private WritingSystem writingSystem;
+
/** The font family name used by this text. */
private String fontFamily = null;
@@ -89,9 +92,11 @@
/**
* Constructor.
* @param consumer The FontConsumer that should be used for font resolution.
+ * @param writingSystem The writing system.
*/
- public PdfTextPainter(final FontConsumer consumer) {
+ public PdfTextPainter(final FontConsumer consumer, final WritingSystem writingSystem) {
this.fontConsumer = consumer;
+ this.writingSystem = writingSystem;
}
@Override
@@ -277,10 +282,10 @@
fontToUse.registerCharsUsed(txt);
/* TODO: If letter-spacing is used, it needs to come from the SVG. */
final int letterSpacing = 0;
- /* TODO: Pass the font options and orthography below instead of hard-coding them. */
+ /* TODO: Pass the font options below instead of hard-coding them. */
final int width = fontToUse.width(txt, 0, txt.length(),
awtFontSize * WellKnownConstants.MILLIPOINTS_PER_POINT, letterSpacing, 0, FontOptions.DEFAULT,
- WritingSystem4a.USA);
+ this.writingSystem);
final float advance = WellKnownConstants.millipointsToPoints(width);
float tx = 0;
if (anchor != null) {
Modified: trunk/foray/foray-graphic/src/main/java/org/foray/graphic/output/SvgPdf.java
===================================================================
--- trunk/foray/foray-graphic/src/main/java/org/foray/graphic/output/SvgPdf.java 2021-11-15 12:39:53 UTC (rev 12068)
+++ trunk/foray/foray-graphic/src/main/java/org/foray/graphic/output/SvgPdf.java 2021-11-15 13:12:15 UTC (rev 12069)
@@ -34,6 +34,7 @@
import org.foray.graphic.batik.PdfTextPainter;
import org.foray.graphic.batik.PdfaElementBridge;
+import org.axsl.common.i18n.WritingSystem;
import org.axsl.font.FontConsumer;
import org.axsl.graphic.GraphicException;
@@ -69,7 +70,8 @@
}
@Override
- public void drawVectorContent(final Graphics2D graphic2d, final FontConsumer fontConsumer) throws GraphicException {
+ public void drawVectorContent(final Graphics2D graphic2d, final FontConsumer fontConsumer,
+ final WritingSystem writingSystem) throws GraphicException {
/* If not running in a graphical environment, log an error message
* and skip the SVG. */
if (! Environment.isGraphicalEnvironment()) {
@@ -87,7 +89,7 @@
if (fontConsumer == null) {
textPainter = new StrokingTextPainter();
} else {
- textPainter = new PdfTextPainter(fontConsumer);
+ textPainter = new PdfTextPainter(fontConsumer, writingSystem);
}
ctx.setTextPainter(textPainter);
Modified: trunk/foray/foray-linebreak/src/main/java/org/foray/text/line/LineBreaker.java
===================================================================
--- trunk/foray/foray-linebreak/src/main/java/org/foray/text/line/LineBreaker.java 2021-11-15 12:39:53 UTC (rev 12068)
+++ trunk/foray/foray-linebreak/src/main/java/org/foray/text/line/LineBreaker.java 2021-11-15 13:12:15 UTC (rev 12069)
@@ -28,7 +28,6 @@
package org.foray.text.line;
-import org.foray.common.i18n.WritingSystem4a;
import org.foray.text.TextServer4a;
import org.axsl.font.FontConsumer;
@@ -332,9 +331,8 @@
public int getWordWidth(final LineText lineText, final CharSequence word, final int offset, final int length) {
final FontUse fontUse = lineText.inlinePrimaryFont();
fontUse.registerCharsUsed(word);
- /* TODO: Pass the orthography below instead of hard-coding it. */
return fontUse.width(word, offset, length, lineText.inlineFontSize(), lineText.inlineLetterSpacingOptimum(), 0,
- lineText.inlineFontOptions(), WritingSystem4a.USA);
+ lineText.inlineFontOptions(), lineText.inlineWritingSystem());
}
/**
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXformMath.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXformMath.java 2021-11-15 12:39:53 UTC (rev 12068)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXformMath.java 2021-11-15 13:12:15 UTC (rev 12069)
@@ -86,7 +86,7 @@
final GraphicPdf graphicPdf = (GraphicPdf) graphicOutput;
// graphicPdf.drawVectorContent(outputStream, doc, this.fontConsumer, this.strokeText, false);
final Graphics2D graphic2D = new PdfGraphics2D(this.writingSystem, this.fontConsumer, doc, outputStream);
- graphicPdf.drawVectorContent(graphic2D, fontConsumer);
+ graphicPdf.drawVectorContent(graphic2D, this.fontConsumer, this.writingSystem);
return outputStream.toByteArray();
}
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXformSvg.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXformSvg.java 2021-11-15 12:39:53 UTC (rev 12068)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXformSvg.java 2021-11-15 13:12:15 UTC (rev 12069)
@@ -86,7 +86,7 @@
final GraphicPdf graphicPdf = (GraphicPdf) graphicOutput;
// graphicPdf.drawVectorContent(outputStream, doc, this.fontConsumer, this.strokeText, false);
final Graphics2D graphic2D = new PdfGraphics2D(this.writingSystem, this.fontConsumer, doc, outputStream);
- graphicPdf.drawVectorContent(graphic2D, fontConsumer);
+ graphicPdf.drawVectorContent(graphic2D, this.fontConsumer, this.writingSystem);
return outputStream.toByteArray();
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-11-15 12:39:55
|
Revision: 12068
http://sourceforge.net/p/foray/code/12068
Author: victormote
Date: 2021-11-15 12:39:53 +0000 (Mon, 15 Nov 2021)
Log Message:
-----------
Remove some instances of hard-coded WritingSystem.
Modified Paths:
--------------
trunk/foray/foray-areatree/src/main/java/org/foray/area/AbstractAncestralInlineArea.java
trunk/foray/foray-areatree/src/main/java/org/foray/area/ScalingValueCitationArea.java
trunk/foray/foray-render/src/main/java/org/foray/render/pdf/PdfRenderer.java
Modified: trunk/foray/foray-areatree/src/main/java/org/foray/area/AbstractAncestralInlineArea.java
===================================================================
--- trunk/foray/foray-areatree/src/main/java/org/foray/area/AbstractAncestralInlineArea.java 2021-11-15 12:25:19 UTC (rev 12067)
+++ trunk/foray/foray-areatree/src/main/java/org/foray/area/AbstractAncestralInlineArea.java 2021-11-15 12:39:53 UTC (rev 12068)
@@ -28,10 +28,7 @@
package org.foray.area;
-import org.foray.common.i18n.WritingSystem4a;
-
import org.axsl.area.AreaTreeException;
-import org.axsl.common.i18n.WritingSystem;
import org.axsl.fo.fo.BasicLink;
import org.axsl.fo.fo.BidiOverride;
import org.axsl.fo.fo.CharacterSequence;
@@ -219,13 +216,4 @@
return FontOptions.DEFAULT;
}
- /**
- * Returns the orthography.
- * @return The orthography.
- */
- public WritingSystem writingSystem() {
- /* TODO: Get this from the FOTree. */
- return WritingSystem4a.USA;
- }
-
}
Modified: trunk/foray/foray-areatree/src/main/java/org/foray/area/ScalingValueCitationArea.java
===================================================================
--- trunk/foray/foray-areatree/src/main/java/org/foray/area/ScalingValueCitationArea.java 2021-11-15 12:25:19 UTC (rev 12067)
+++ trunk/foray/foray-areatree/src/main/java/org/foray/area/ScalingValueCitationArea.java 2021-11-15 12:39:53 UTC (rev 12068)
@@ -28,10 +28,7 @@
package org.foray.area;
-import org.foray.common.i18n.WritingSystem4a;
-
import org.axsl.area.AreaTreeException;
-import org.axsl.common.i18n.WritingSystem;
import org.axsl.fo.Fo;
import org.axsl.fo.fo.GraftingPoint;
import org.axsl.fo.fo.ScalingValueCitation;
@@ -321,13 +318,4 @@
return FontOptions.DEFAULT;
}
- /**
- * Returns the orthography.
- * @return The orthography.
- */
- public WritingSystem writingSystem() {
- /* TODO: Get this from the FOTree. */
- return WritingSystem4a.USA;
- }
-
}
Modified: trunk/foray/foray-render/src/main/java/org/foray/render/pdf/PdfRenderer.java
===================================================================
--- trunk/foray/foray-render/src/main/java/org/foray/render/pdf/PdfRenderer.java 2021-11-15 12:25:19 UTC (rev 12067)
+++ trunk/foray/foray-render/src/main/java/org/foray/render/pdf/PdfRenderer.java 2021-11-15 12:39:53 UTC (rev 12068)
@@ -34,7 +34,6 @@
package org.foray.render.pdf;
import org.foray.common.WellKnownConstants;
-import org.foray.common.i18n.WritingSystem4a;
import org.foray.render.PrintRenderer;
import org.axsl.common.FormattedIntegerType;
@@ -305,7 +304,7 @@
final Rectangle2D.Float pdfClipRectangle = convertMillipointRectangle(
clipRectangle);
try {
- final PdfXobject xObject = this.pdfDoc.createXobject(image, WritingSystem4a.USA, getFontConsumer());
+ final PdfXobject xObject = this.pdfDoc.createXobject(image, area.writingSystem(), getFontConsumer());
getContentStream().drawXobject(xObject, pdfContentRectangle, pdfClipRectangle);
} catch (final PdfException e) {
throw new GalleyVisitorException(e);
@@ -321,7 +320,8 @@
toPoints(foreign.referenceBpd()));
final SvgGraphic svgGraphic = area.getGraphic();
try {
- final PdfXobject xObject = this.pdfDoc.createXobject(svgGraphic, WritingSystem4a.USA, getFontConsumer());
+ final PdfXobject xObject = this.pdfDoc.createXobject(svgGraphic, area.getParent().writingSystem(),
+ getFontConsumer());
getContentStream().drawXobject(xObject, contentRectangle, null);
} catch (final PdfException e) {
throw new GalleyVisitorException(e);
@@ -338,7 +338,8 @@
toPoints(foreign.referenceBpd()));
final MathGraphic mathGraphic = area.getGraphic();
try {
- final PdfXobject xObject = this.pdfDoc.createXobject(mathGraphic, WritingSystem4a.USA, getFontConsumer());
+ final PdfXobject xObject = this.pdfDoc.createXobject(mathGraphic, area.getParent().writingSystem(),
+ getFontConsumer());
getContentStream().drawXobject(xObject, contentRectangle, null);
} catch (final PdfException e) {
throw new GalleyVisitorException(e);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-11-15 12:25:23
|
Revision: 12067
http://sourceforge.net/p/foray/code/12067
Author: victormote
Date: 2021-11-15 12:25:19 +0000 (Mon, 15 Nov 2021)
Log Message:
-----------
Conform to aXSL changes: Add methods in both axsl-fo and axsl-galley to get the WritingSystem and Orthography for all nodes.
Modified Paths:
--------------
trunk/foray/foray-areatree/src/main/java/org/foray/area/AreaNode4a.java
trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoObj.java
Modified: trunk/foray/foray-areatree/src/main/java/org/foray/area/AreaNode4a.java
===================================================================
--- trunk/foray/foray-areatree/src/main/java/org/foray/area/AreaNode4a.java 2021-11-15 00:21:54 UTC (rev 12066)
+++ trunk/foray/foray-areatree/src/main/java/org/foray/area/AreaNode4a.java 2021-11-15 12:25:19 UTC (rev 12067)
@@ -34,11 +34,13 @@
import org.axsl.area.AreaNode;
import org.axsl.area.AreaTreeException;
import org.axsl.area.BlockContentFactory;
+import org.axsl.common.i18n.WritingSystem;
import org.axsl.fo.Fo;
import org.axsl.fo.fo.GraftingPoint;
import org.axsl.fo.fo.Table;
import org.axsl.fo.fo.prop.ColorPa;
import org.axsl.galley.Galley;
+import org.axsl.orthography.Orthography;
import org.slf4j.Logger;
@@ -768,4 +770,22 @@
return this.getParent().getColor();
}
+ @Override
+ public WritingSystem writingSystem() {
+ final Fo generatedBy = this.traitGeneratedBy();
+ if (generatedBy != null) {
+ return generatedBy.getWritingSystem();
+ }
+ return null;
+ }
+
+ @Override
+ public Orthography orthography() {
+ final Fo generatedBy = this.traitGeneratedBy();
+ if (generatedBy != null) {
+ return generatedBy.getOrthography();
+ }
+ return null;
+ }
+
}
Modified: trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoObj.java
===================================================================
--- trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoObj.java 2021-11-15 00:21:54 UTC (rev 12066)
+++ trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoObj.java 2021-11-15 12:25:19 UTC (rev 12067)
@@ -120,7 +120,6 @@
import org.axsl.common.value.WhiteSpaceTreatment;
import org.axsl.common.value.WrapOption;
import org.axsl.fo.Fo;
-import org.axsl.fo.FoAllProperties;
import org.axsl.fo.FoContext;
import org.axsl.fo.FoInlineContext;
import org.axsl.fo.FoTreeException;
@@ -134,6 +133,7 @@
import org.axsl.font.FontUse;
import org.axsl.graphic.Graphic;
import org.axsl.graphic.GraphicServer;
+import org.axsl.orthography.Orthography;
import org.axsl.orthography.OrthographyServer;
import org.axsl.speech.SpeechException;
import org.axsl.speech.SpeechServer;
@@ -155,7 +155,7 @@
/**
* Base class for formatting objects.
*/
-public abstract class FoObj extends AbstractOrderedTreeNode implements Fo, FoAllProperties, ParaConfig {
+public abstract class FoObj extends AbstractOrderedTreeNode implements Fo, ParaConfig {
/** A static empty and immutable list of children, suitable for return by
* objects that have no children. */
@@ -3930,4 +3930,10 @@
return WritingSystem4a.find(language, country, script);
}
+ public Orthography getOrthography() {
+ final OrthographyServer server = getOrthographyServer();
+ final WritingSystem writingSystem = getWritingSystem();
+ return server.getOrthography(writingSystem);
+ }
+
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-11-15 00:21:56
|
Revision: 12066
http://sourceforge.net/p/foray/code/12066
Author: victormote
Date: 2021-11-15 00:21:54 +0000 (Mon, 15 Nov 2021)
Log Message:
-----------
Conform to aXSL changes: Start process of making axsl-area extend axsl-galley.
Modified Paths:
--------------
trunk/foray/foray-areatree/src/main/java/org/foray/area/Area4a.java
trunk/foray/foray-areatree/src/main/java/org/foray/area/AreaNode4a.java
trunk/foray/foray-areatree/src/main/java/org/foray/area/AreaTree4a.java
Modified: trunk/foray/foray-areatree/src/main/java/org/foray/area/Area4a.java
===================================================================
--- trunk/foray/foray-areatree/src/main/java/org/foray/area/Area4a.java 2021-11-14 23:19:35 UTC (rev 12065)
+++ trunk/foray/foray-areatree/src/main/java/org/foray/area/Area4a.java 2021-11-15 00:21:54 UTC (rev 12066)
@@ -30,6 +30,7 @@
import org.foray.common.WellKnownConstants;
+import org.axsl.area.Area;
import org.axsl.area.AreaTreeException;
import org.axsl.area.BlockContainerRefArea;
import org.axsl.common.value.AbsoluteAxis;
@@ -52,8 +53,7 @@
/**
* Abstract superclass for all Areas in the AreaTree.
*/
-public abstract class Area4a extends AreaNode4a implements org.axsl.galley.Area,
- org.axsl.area.Area {
+public abstract class Area4a extends AreaNode4a implements Area {
/**
* Constructor.
Modified: trunk/foray/foray-areatree/src/main/java/org/foray/area/AreaNode4a.java
===================================================================
--- trunk/foray/foray-areatree/src/main/java/org/foray/area/AreaNode4a.java 2021-11-14 23:19:35 UTC (rev 12065)
+++ trunk/foray/foray-areatree/src/main/java/org/foray/area/AreaNode4a.java 2021-11-15 00:21:54 UTC (rev 12066)
@@ -31,6 +31,7 @@
import org.foray.common.data.AbstractOrderedTreeNode;
import org.foray.common.data.OrderedTreeNode;
+import org.axsl.area.AreaNode;
import org.axsl.area.AreaTreeException;
import org.axsl.area.BlockContentFactory;
import org.axsl.fo.Fo;
@@ -49,8 +50,7 @@
/**
* Abstract superclass for all nodes in the AreaTree.
*/
-public abstract class AreaNode4a extends AbstractOrderedTreeNode
- implements org.axsl.galley.AreaNode, org.axsl.area.AreaNode {
+public abstract class AreaNode4a extends AbstractOrderedTreeNode implements AreaNode {
/**
* Constructor.
Modified: trunk/foray/foray-areatree/src/main/java/org/foray/area/AreaTree4a.java
===================================================================
--- trunk/foray/foray-areatree/src/main/java/org/foray/area/AreaTree4a.java 2021-11-14 23:19:35 UTC (rev 12065)
+++ trunk/foray/foray-areatree/src/main/java/org/foray/area/AreaTree4a.java 2021-11-15 00:21:54 UTC (rev 12066)
@@ -28,6 +28,7 @@
package org.foray.area;
+import org.axsl.area.AreaTree;
import org.axsl.area.AreaTreeEvent;
import org.axsl.area.AreaTreeException;
import org.axsl.area.AreaTreeListener;
@@ -52,8 +53,7 @@
/**
* The root of the AreaTree.
*/
-public final class AreaTree4a extends NonArea implements org.axsl.galley.Galley,
- org.axsl.area.AreaTree {
+public final class AreaTree4a extends NonArea implements AreaTree {
/** The initial size at which the linkage map should be created. */
private static final short INITIAL_LINKAGE_MAP_SIZE = 200;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-11-14 23:19:39
|
Revision: 12065
http://sourceforge.net/p/foray/code/12065
Author: victormote
Date: 2021-11-14 23:19:35 +0000 (Sun, 14 Nov 2021)
Log Message:
-----------
Rename some Foray implementation classes to help distinguish them from the aXSL interface names.
Modified Paths:
--------------
trunk/foray/foray-app/src/test/java/org/foray/app/area/AbstractAreaTreeTest.java
trunk/foray/foray-app/src/test/java/org/foray/app/area/AreaTreeCreator.java
trunk/foray/foray-app/src/test/java/org/foray/app/area/TestBlock.java
trunk/foray/foray-app/src/test/java/org/foray/app/area/TestBorder.java
trunk/foray/foray-app/src/test/java/org/foray/app/area/TestGraphicArea.java
trunk/foray/foray-app/src/test/java/org/foray/app/area/TestInline.java
trunk/foray/foray-app/src/test/java/org/foray/app/area/TestMetadata.java
trunk/foray/foray-app/src/test/java/org/foray/app/area/TestVertical.java
trunk/foray/foray-areatree/src/main/java/org/foray/area/AbstractInlineArea.java
trunk/foray/foray-areatree/src/main/java/org/foray/area/AbstractListItemContent.java
trunk/foray/foray-areatree/src/main/java/org/foray/area/AbstractTablePartContainer.java
trunk/foray/foray-areatree/src/main/java/org/foray/area/AreaFixed.java
trunk/foray/foray-areatree/src/main/java/org/foray/area/AreaFlexible.java
trunk/foray/foray-areatree/src/main/java/org/foray/area/AreaTreeFactory4a.java
trunk/foray/foray-areatree/src/main/java/org/foray/area/BasicLinkArea.java
trunk/foray/foray-areatree/src/main/java/org/foray/area/BeforeFloatRa.java
trunk/foray/foray-areatree/src/main/java/org/foray/area/BidiOverrideArea.java
trunk/foray/foray-areatree/src/main/java/org/foray/area/BlockArea.java
trunk/foray/foray-areatree/src/main/java/org/foray/area/BlockContainerRa.java
trunk/foray/foray-areatree/src/main/java/org/foray/area/BookmarkTreeArea.java
trunk/foray/foray-areatree/src/main/java/org/foray/area/ExternalGraphicArea.java
trunk/foray/foray-areatree/src/main/java/org/foray/area/FoLinkage.java
trunk/foray/foray-areatree/src/main/java/org/foray/area/FoLinkageMarker.java
trunk/foray/foray-areatree/src/main/java/org/foray/area/FoLinkageNormal.java
trunk/foray/foray-areatree/src/main/java/org/foray/area/FootnoteRa.java
trunk/foray/foray-areatree/src/main/java/org/foray/area/ForeignObjectArea.java
trunk/foray/foray-areatree/src/main/java/org/foray/area/IndexPageCitationListArea.java
trunk/foray/foray-areatree/src/main/java/org/foray/area/InlineArea.java
trunk/foray/foray-areatree/src/main/java/org/foray/area/InlineContainerArea.java
trunk/foray/foray-areatree/src/main/java/org/foray/area/LeaderArea.java
trunk/foray/foray-areatree/src/main/java/org/foray/area/LineArea.java
trunk/foray/foray-areatree/src/main/java/org/foray/area/ListBlockArea.java
trunk/foray/foray-areatree/src/main/java/org/foray/area/ListItemArea.java
trunk/foray/foray-areatree/src/main/java/org/foray/area/MainRa.java
trunk/foray/foray-areatree/src/main/java/org/foray/area/NonArea.java
trunk/foray/foray-areatree/src/main/java/org/foray/area/NormalBlockArea.java
trunk/foray/foray-areatree/src/main/java/org/foray/area/NormalFlowRa.java
trunk/foray/foray-areatree/src/main/java/org/foray/area/PageCollection.java
trunk/foray/foray-areatree/src/main/java/org/foray/area/PageNumberArea.java
trunk/foray/foray-areatree/src/main/java/org/foray/area/PageNumberCitationArea.java
trunk/foray/foray-areatree/src/main/java/org/foray/area/PageNumberCitationLastArea.java
trunk/foray/foray-areatree/src/main/java/org/foray/area/PageRa.java
trunk/foray/foray-areatree/src/main/java/org/foray/area/RegionRa.java
trunk/foray/foray-areatree/src/main/java/org/foray/area/RegionRaBody.java
trunk/foray/foray-areatree/src/main/java/org/foray/area/ScalingValueCitationArea.java
trunk/foray/foray-areatree/src/main/java/org/foray/area/SpanRa.java
trunk/foray/foray-areatree/src/main/java/org/foray/area/TableBodyContainer.java
trunk/foray/foray-areatree/src/main/java/org/foray/area/TableCellRa.java
trunk/foray/foray-areatree/src/main/java/org/foray/area/TableFooterContainer.java
trunk/foray/foray-areatree/src/main/java/org/foray/area/TableHeaderContainer.java
trunk/foray/foray-areatree/src/main/java/org/foray/area/TableRa.java
trunk/foray/foray-areatree/src/main/java/org/foray/area/TableRowContainer.java
trunk/foray/foray-areatree/src/main/java/org/foray/area/TextArea.java
Added Paths:
-----------
trunk/foray/foray-areatree/src/main/java/org/foray/area/Area4a.java
trunk/foray/foray-areatree/src/main/java/org/foray/area/AreaNode4a.java
trunk/foray/foray-areatree/src/main/java/org/foray/area/AreaTree4a.java
Removed Paths:
-------------
trunk/foray/foray-areatree/src/main/java/org/foray/area/Area.java
trunk/foray/foray-areatree/src/main/java/org/foray/area/AreaNode.java
trunk/foray/foray-areatree/src/main/java/org/foray/area/AreaTree.java
Modified: trunk/foray/foray-app/src/test/java/org/foray/app/area/AbstractAreaTreeTest.java
===================================================================
--- trunk/foray/foray-app/src/test/java/org/foray/app/area/AbstractAreaTreeTest.java 2021-11-14 22:36:02 UTC (rev 12064)
+++ trunk/foray/foray-app/src/test/java/org/foray/app/area/AbstractAreaTreeTest.java 2021-11-14 23:19:35 UTC (rev 12065)
@@ -28,8 +28,8 @@
package org.foray.app.area;
-import org.foray.area.AreaNode;
-import org.foray.area.AreaTree;
+import org.foray.area.AreaNode4a;
+import org.foray.area.AreaTree4a;
import org.foray.area.MainRa;
import org.foray.area.NormalFlowRa;
import org.foray.area.PageCollection;
@@ -92,13 +92,13 @@
* @param areaTree The area tree being tested.
* @return The first normal-flow reference area in {@code areaTree}.
*/
- protected NormalFlowRa getFirstNormalFlowArea(final AreaTree areaTree) {
+ protected NormalFlowRa getFirstNormalFlowArea(final AreaTree4a areaTree) {
final PageCollection pageCollection = getPageCollection(areaTree, 1);
final PageRa firstPage = getPage(pageCollection, 1);
final RegionRaBody regionBody = firstPage.getRegionBody(
"xsl-region-body");
final MainRa main = regionBody.getMainRefArea();
- AreaNode node = main.getChildAt(0);
+ AreaNode4a node = main.getChildAt(0);
Assert.assertTrue(node instanceof SpanRa);
final SpanRa span = (SpanRa) node;
node = span.getChildAt(0);
@@ -115,9 +115,9 @@
* etc.
* @return The requested page collection, or null if it does not exist.
*/
- protected PageCollection getPageCollection(final AreaTree areaTree,
+ protected PageCollection getPageCollection(final AreaTree4a areaTree,
final int collectionNum) {
- final AreaNode node = areaTree.getChildAt(0);
+ final AreaNode4a node = areaTree.getChildAt(0);
Assert.assertTrue(node instanceof PageCollection);
final PageCollection pageCollection = (PageCollection) node;
return pageCollection;
@@ -138,7 +138,7 @@
final int index = pageNum - 1;
Assert.assertTrue(index >= 0);
Assert.assertTrue(index < pageCollection.getChildCount());
- final AreaNode node = pageCollection.getChildAt(index);
+ final AreaNode4a node = pageCollection.getChildAt(index);
Assert.assertTrue(node instanceof PageRa);
final PageRa page = (PageRa) node;
return page;
@@ -153,7 +153,7 @@
* @param node The node whose descendant text should be returned.
* @return The String concatenating all descendant text items.
*/
- protected String getText(final AreaNode node) {
+ protected String getText(final AreaNode4a node) {
final StringBuilder builder = new StringBuilder();
final Iterator<OrderedTreeNode> iterator =
node.postOrderDescendantIterator();
Modified: trunk/foray/foray-app/src/test/java/org/foray/app/area/AreaTreeCreator.java
===================================================================
--- trunk/foray/foray-app/src/test/java/org/foray/app/area/AreaTreeCreator.java 2021-11-14 22:36:02 UTC (rev 12064)
+++ trunk/foray/foray-app/src/test/java/org/foray/app/area/AreaTreeCreator.java 2021-11-14 23:19:35 UTC (rev 12065)
@@ -30,7 +30,7 @@
import org.foray.app.ForaySpecific;
import org.foray.app.fo.FoDocumentReader;
-import org.foray.area.AreaTree;
+import org.foray.area.AreaTree4a;
import org.foray.area.AreaTreeFactory4a;
import org.foray.area.PageCollection;
import org.foray.core.ForayException;
@@ -100,11 +100,11 @@
* @return The parsed FO Tree instance.
* @throws ForayException For errors building the FO Tree.
*/
- public AreaTree buildAreaTree(final String file) throws ForayException {
+ public AreaTree4a buildAreaTree(final String file) throws ForayException {
final FoDocumentReader foReader = FoDocumentReader.getInstance();
final FoTreeBuilder foTree = foReader.buildFoTree(file);
final Root root = foTree.getRootFo();
- final AreaTree areaTree = this.areaTreeFactory.makeAreaTree(root);
+ final AreaTree4a areaTree = this.areaTreeFactory.makeAreaTree(root);
final PioneerLayoutStrategy layout = this.layoutFactory.makeLayout();
final Iterator<PageSequence> iterator = root.getPageSequenceIterator();
while (iterator.hasNext()) {
Modified: trunk/foray/foray-app/src/test/java/org/foray/app/area/TestBlock.java
===================================================================
--- trunk/foray/foray-app/src/test/java/org/foray/app/area/TestBlock.java 2021-11-14 22:36:02 UTC (rev 12064)
+++ trunk/foray/foray-app/src/test/java/org/foray/app/area/TestBlock.java 2021-11-14 23:19:35 UTC (rev 12065)
@@ -29,8 +29,8 @@
package org.foray.app.area;
-import org.foray.area.AreaNode;
-import org.foray.area.AreaTree;
+import org.foray.area.AreaNode4a;
+import org.foray.area.AreaTree4a;
import org.foray.area.LineArea;
import org.foray.area.NormalBlockArea;
import org.foray.area.NormalFlowRa;
@@ -73,13 +73,13 @@
@Ignore
public void testBlock001() throws ForayException {
final AreaTreeCreator creator = AreaTreeCreator.getInstance();
- final AreaTree areaTree = creator.buildAreaTree(
+ final AreaTree4a areaTree = creator.buildAreaTree(
"fo/block-001.fo");
final NormalFlowRa firstNormalFlowArea = this.getFirstNormalFlowArea(
areaTree);
/* The outer block area. */
- AreaNode node = firstNormalFlowArea.getChildAt(0);
+ AreaNode4a node = firstNormalFlowArea.getChildAt(0);
Assert.assertTrue(node instanceof NormalBlockArea);
final NormalBlockArea outerBlockArea = (NormalBlockArea) node;
/* 1 inch left margin. */
@@ -172,7 +172,7 @@
@Ignore
public void testBlock002() throws ForayException {
final AreaTreeCreator creator = AreaTreeCreator.getInstance();
- final AreaTree areaTree = creator.buildAreaTree(
+ final AreaTree4a areaTree = creator.buildAreaTree(
"fo/block-002.fo");
final PageCollection pageCollection = this.getPageCollection(areaTree,
1);
@@ -254,13 +254,13 @@
public void testBlock003() throws ForayException, FontException {
final AreaTreeCreator creator = AreaTreeCreator.getInstance();
- final AreaTree areaTree = creator.buildAreaTree(
+ final AreaTree4a areaTree = creator.buildAreaTree(
"fo/block-003.fo");
final NormalFlowRa firstNormalFlowArea = this.getFirstNormalFlowArea(
areaTree);
/* Test location and dimensions of the block area. */
- AreaNode node = firstNormalFlowArea.getChildAt(0);
+ AreaNode4a node = firstNormalFlowArea.getChildAt(0);
Assert.assertTrue(node instanceof NormalBlockArea);
final NormalBlockArea blockArea = (NormalBlockArea) node;
/* 1 inch left margin. */
@@ -318,13 +318,13 @@
@Ignore
public void testBlock004() throws ForayException, FontException {
final AreaTreeCreator creator = AreaTreeCreator.getInstance();
- final AreaTree areaTree = creator.buildAreaTree(
+ final AreaTree4a areaTree = creator.buildAreaTree(
"fo/block-004.fo");
final NormalFlowRa firstNormalFlowArea = this.getFirstNormalFlowArea(
areaTree);
/* Test location and dimensions of the block area. */
- AreaNode node = firstNormalFlowArea.getChildAt(0);
+ AreaNode4a node = firstNormalFlowArea.getChildAt(0);
Assert.assertTrue(node instanceof NormalBlockArea);
final NormalBlockArea blockArea = (NormalBlockArea) node;
/* 1 inch left margin. */
Modified: trunk/foray/foray-app/src/test/java/org/foray/app/area/TestBorder.java
===================================================================
--- trunk/foray/foray-app/src/test/java/org/foray/app/area/TestBorder.java 2021-11-14 22:36:02 UTC (rev 12064)
+++ trunk/foray/foray-app/src/test/java/org/foray/app/area/TestBorder.java 2021-11-14 23:19:35 UTC (rev 12065)
@@ -28,8 +28,8 @@
package org.foray.app.area;
-import org.foray.area.AreaNode;
-import org.foray.area.AreaTree;
+import org.foray.area.AreaNode4a;
+import org.foray.area.AreaTree4a;
import org.foray.area.NormalBlockArea;
import org.foray.area.NormalFlowRa;
import org.foray.core.ForayException;
@@ -51,12 +51,12 @@
@Ignore
public void testBorderStyle001() throws ForayException {
final AreaTreeCreator creator = AreaTreeCreator.getInstance();
- final AreaTree areaTree = creator.buildAreaTree(
+ final AreaTree4a areaTree = creator.buildAreaTree(
"fo/border-style-001.fo");
final NormalFlowRa firstNormalFlowArea = this.getFirstNormalFlowArea(
areaTree);
- final AreaNode node = firstNormalFlowArea.getChildAt(0);
+ final AreaNode4a node = firstNormalFlowArea.getChildAt(0);
Assert.assertTrue(node instanceof NormalBlockArea);
final NormalBlockArea blockArea = (NormalBlockArea) node;
Assert.assertEquals(72000, blockArea.brOriginX());
Modified: trunk/foray/foray-app/src/test/java/org/foray/app/area/TestGraphicArea.java
===================================================================
--- trunk/foray/foray-app/src/test/java/org/foray/app/area/TestGraphicArea.java 2021-11-14 22:36:02 UTC (rev 12064)
+++ trunk/foray/foray-app/src/test/java/org/foray/app/area/TestGraphicArea.java 2021-11-14 23:19:35 UTC (rev 12065)
@@ -28,8 +28,8 @@
package org.foray.app.area;
-import org.foray.area.AreaNode;
-import org.foray.area.AreaTree;
+import org.foray.area.AreaNode4a;
+import org.foray.area.AreaTree4a;
import org.foray.area.ExternalGraphicArea;
import org.foray.area.LineArea;
import org.foray.area.NormalBlockArea;
@@ -55,7 +55,7 @@
@Ignore
public void testGraphic002() throws ForayException {
final AreaTreeCreator creator = AreaTreeCreator.getInstance();
- final AreaTree areaTree = creator.buildAreaTree(
+ final AreaTree4a areaTree = creator.buildAreaTree(
"fo/graphic-002.fo");
final NormalFlowRa firstNormalFlowArea = this.getFirstNormalFlowArea(
areaTree);
@@ -64,7 +64,7 @@
Assert.assertEquals(2, firstNormalFlowArea.getChildCount());
/* The second one contains the graphic. */
- AreaNode node = firstNormalFlowArea.getChildAt(1);
+ AreaNode4a node = firstNormalFlowArea.getChildAt(1);
Assert.assertTrue(node instanceof NormalBlockArea);
/* It has one child, a LineArea ... */
Modified: trunk/foray/foray-app/src/test/java/org/foray/app/area/TestInline.java
===================================================================
--- trunk/foray/foray-app/src/test/java/org/foray/app/area/TestInline.java 2021-11-14 22:36:02 UTC (rev 12064)
+++ trunk/foray/foray-app/src/test/java/org/foray/app/area/TestInline.java 2021-11-14 23:19:35 UTC (rev 12065)
@@ -28,8 +28,8 @@
package org.foray.app.area;
-import org.foray.area.AreaNode;
-import org.foray.area.AreaTree;
+import org.foray.area.AreaNode4a;
+import org.foray.area.AreaTree4a;
import org.foray.area.InlineArea;
import org.foray.area.LineArea;
import org.foray.area.NormalBlockArea;
@@ -56,7 +56,7 @@
@Ignore
public void testInline001() throws ForayException {
final AreaTreeCreator creator = AreaTreeCreator.getInstance();
- final AreaTree areaTree = creator.buildAreaTree(
+ final AreaTree4a areaTree = creator.buildAreaTree(
"fo/inline-001.fo");
final NormalFlowRa firstNormalFlowArea = this.getFirstNormalFlowArea(
areaTree);
@@ -63,7 +63,7 @@
Assert.assertEquals(1, firstNormalFlowArea.getChildCount());
/* The block area. */
- AreaNode node = firstNormalFlowArea.getChildAt(0);
+ AreaNode4a node = firstNormalFlowArea.getChildAt(0);
Assert.assertTrue(node instanceof NormalBlockArea);
final NormalBlockArea blockArea = (NormalBlockArea) node;
Assert.assertEquals(1, blockArea.getChildCount());
Modified: trunk/foray/foray-app/src/test/java/org/foray/app/area/TestMetadata.java
===================================================================
--- trunk/foray/foray-app/src/test/java/org/foray/app/area/TestMetadata.java 2021-11-14 22:36:02 UTC (rev 12064)
+++ trunk/foray/foray-app/src/test/java/org/foray/app/area/TestMetadata.java 2021-11-14 23:19:35 UTC (rev 12065)
@@ -28,7 +28,7 @@
package org.foray.app.area;
-import org.foray.area.AreaTree;
+import org.foray.area.AreaTree4a;
import org.foray.core.ForayException;
import org.junit.Assert;
@@ -48,7 +48,7 @@
@Ignore
public void testMetadata001() throws ForayException {
final AreaTreeCreator creator = AreaTreeCreator.getInstance();
- final AreaTree areaTree = creator.buildAreaTree(
+ final AreaTree4a areaTree = creator.buildAreaTree(
"fo/metadata-001.fo");
Assert.assertNotNull(areaTree);
Assert.assertEquals("Test Title", areaTree.getTitle());
Modified: trunk/foray/foray-app/src/test/java/org/foray/app/area/TestVertical.java
===================================================================
--- trunk/foray/foray-app/src/test/java/org/foray/app/area/TestVertical.java 2021-11-14 22:36:02 UTC (rev 12064)
+++ trunk/foray/foray-app/src/test/java/org/foray/app/area/TestVertical.java 2021-11-14 23:19:35 UTC (rev 12065)
@@ -28,8 +28,8 @@
package org.foray.app.area;
-import org.foray.area.AreaNode;
-import org.foray.area.AreaTree;
+import org.foray.area.AreaNode4a;
+import org.foray.area.AreaTree4a;
import org.foray.area.InlineArea;
import org.foray.area.LineArea;
import org.foray.area.NormalBlockArea;
@@ -56,12 +56,12 @@
@Ignore
public void testVertical001() throws ForayException {
final AreaTreeCreator creator = AreaTreeCreator.getInstance();
- final AreaTree areaTree = creator.buildAreaTree("fo/vertical-001.fo");
+ final AreaTree4a areaTree = creator.buildAreaTree("fo/vertical-001.fo");
final NormalFlowRa firstNormalFlowArea = this.getFirstNormalFlowArea(
areaTree);
/* The block area. */
- AreaNode node = firstNormalFlowArea.getChildAt(0);
+ AreaNode4a node = firstNormalFlowArea.getChildAt(0);
Assert.assertTrue(node instanceof NormalBlockArea);
final NormalBlockArea blockArea = (NormalBlockArea) node;
final FontUse font = blockArea.getPrimaryFont();
Modified: trunk/foray/foray-areatree/src/main/java/org/foray/area/AbstractInlineArea.java
===================================================================
--- trunk/foray/foray-areatree/src/main/java/org/foray/area/AbstractInlineArea.java 2021-11-14 22:36:02 UTC (rev 12064)
+++ trunk/foray/foray-areatree/src/main/java/org/foray/area/AbstractInlineArea.java 2021-11-14 23:19:35 UTC (rev 12065)
@@ -65,7 +65,7 @@
}
@Override
- public Area getOverflowArea(final Area childRequesting)
+ public Area4a getOverflowArea(final Area4a childRequesting)
throws AreaTreeException {
return ancestorArea().getOverflowArea(this);
}
@@ -95,7 +95,7 @@
@Override
public int baselineY() {
int dominantBaselinePosition = 0;
- final Area ancestorArea = this.ancestorArea();
+ final Area4a ancestorArea = this.ancestorArea();
if (ancestorArea instanceof LineArea) {
dominantBaselinePosition = ((LineArea) ancestorArea).alignmentPointY();
} else if (ancestorArea instanceof AbstractAncestralInlineArea) {
@@ -177,7 +177,7 @@
* @throws AreaTreeException If the node is not either a {@link LineArea} or
* an {@link AbstractInlineArea}.
*/
- protected Area validateNewParent(final AreaNode node)
+ protected Area4a validateNewParent(final AreaNode4a node)
throws AreaTreeException {
if (node instanceof LineArea) {
return (LineArea) node;
Modified: trunk/foray/foray-areatree/src/main/java/org/foray/area/AbstractListItemContent.java
===================================================================
--- trunk/foray/foray-areatree/src/main/java/org/foray/area/AbstractListItemContent.java 2021-11-14 22:36:02 UTC (rev 12064)
+++ trunk/foray/foray-areatree/src/main/java/org/foray/area/AbstractListItemContent.java 2021-11-14 23:19:35 UTC (rev 12065)
@@ -55,7 +55,7 @@
private ListItemArea parent;
/** The children of this node. */
- private List<Area> children = new ArrayList<Area>();
+ private List<Area4a> children = new ArrayList<Area4a>();
/**
* Private Constructor.
@@ -76,7 +76,7 @@
}
@Override
- public void setParent(final AreaNode node) throws AreaTreeException {
+ public void setParent(final AreaNode4a node) throws AreaTreeException {
if (node instanceof ListItemArea) {
this.parent = (ListItemArea) node;
} else {
@@ -87,7 +87,7 @@
}
@Override
- public List<Area> getChildren() {
+ public List<Area4a> getChildren() {
return this.children;
}
@@ -154,7 +154,7 @@
*/
public int getProgressionDimension() {
int pd = 0;
- for (Area area : this.children) {
+ for (Area4a area : this.children) {
/* TODO: This is not right. We need the space-before, etc.
* considered also. */
pd += area.brBpd();
Modified: trunk/foray/foray-areatree/src/main/java/org/foray/area/AbstractTablePartContainer.java
===================================================================
--- trunk/foray/foray-areatree/src/main/java/org/foray/area/AbstractTablePartContainer.java 2021-11-14 22:36:02 UTC (rev 12064)
+++ trunk/foray/foray-areatree/src/main/java/org/foray/area/AbstractTablePartContainer.java 2021-11-14 23:19:35 UTC (rev 12065)
@@ -90,7 +90,7 @@
}
@Override
- public void setParent(final AreaNode node) throws AreaTreeException {
+ public void setParent(final AreaNode4a node) throws AreaTreeException {
if (node instanceof TableRa) {
this.parent = (TableRa) node;
} else {
Deleted: trunk/foray/foray-areatree/src/main/java/org/foray/area/Area.java
===================================================================
--- trunk/foray/foray-areatree/src/main/java/org/foray/area/Area.java 2021-11-14 22:36:02 UTC (rev 12064)
+++ trunk/foray/foray-areatree/src/main/java/org/foray/area/Area.java 2021-11-14 23:19:35 UTC (rev 12065)
@@ -1,1019 +0,0 @@
-/*
- * Copyright 2004 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.area;
-
-import org.foray.common.WellKnownConstants;
-
-import org.axsl.area.AreaTreeException;
-import org.axsl.area.BlockContainerRefArea;
-import org.axsl.common.value.AbsoluteAxis;
-import org.axsl.common.value.AbsoluteDirection;
-import org.axsl.common.value.LinkType;
-import org.axsl.common.value.RelativeAxis;
-import org.axsl.common.value.WhiteSpaceTreatment;
-import org.axsl.common.value.WritingMode;
-import org.axsl.fo.Fo;
-import org.axsl.fo.fo.BasicLink;
-import org.axsl.fo.fo.Block;
-import org.axsl.fo.fo.prop.IdPa;
-import org.axsl.fo.fo.prop.WritingModePa;
-import org.axsl.font.Font;
-import org.axsl.galley.BackgroundArea;
-
-import java.awt.geom.Rectangle2D;
-import java.util.List;
-
-/**
- * Abstract superclass for all Areas in the AreaTree.
- */
-public abstract class Area extends AreaNode implements org.axsl.galley.Area,
- org.axsl.area.Area {
-
- /**
- * Constructor.
- */
- protected Area() {
- }
-
- /**
- * Returns the nearest ancestor area that is a block container.
- * @return The nearest ancestor area that is a block container.
- */
- public BlockContainerRefArea getNearestAncestorAreaContainer() {
- AreaNode areaNode = this.getParent();
- while (areaNode != null
- && !(areaNode instanceof BlockContainerRefArea)) {
- areaNode = areaNode.getParent();
- }
- return (BlockContainerRefArea) areaNode;
- }
-
- @Override
- public boolean generatedByExists() {
- return getLinkage() != null;
- }
-
- @Override
- public String generatedByName() {
- return traitGeneratedBy().getName();
- }
-
- /**
- * Returns the end-indent trait.
- * @return The end-indent trait.
- */
- public abstract int traitEndIndent();
-
- /**
- * Returns the start-indent trait.
- * @return The start-indent trait.
- */
- public abstract int traitStartIndent();
-
- /**
- * Returns the allocation width of this area's parent.
- * @return The allocation width of this area's parent.
- */
- public int parentAllocationWidth() {
- if (! (getParent() instanceof Area)) {
- return 0;
- }
- return ((Area) getParent()).narIPD();
- }
-
- /**
- * Indicates whether this area is its parent's first child.
- * @return True iff this area is its parent's first child.
- */
- protected boolean isFirstChildOfParent() {
- if (getParent() == null) {
- return true;
- }
- final List<? extends AreaNode> siblings = getParent().getChildren();
- if (siblings == null
- || siblings.size() < 1) {
- return true;
- }
- if (siblings.get(0) == this) {
- return true;
- }
- return false;
- }
-
- /**
- * Indicates whether this area is its parent's last child.
- * @return True iff this area is its parent's last child.
- */
- protected boolean isLastChildOfParent() {
- if (getParent() == null) {
- return true;
- }
- final List<? extends AreaNode> siblings = getParent().getChildren();
- if (siblings == null) {
- return true;
- }
- /*
- * This loop is necessary because the children include DisplaySpace
- * instances which are not considered for this test.
- */
- for (int i = siblings.size() - 1; i >= 0; i--) {
- if (siblings.get(i) instanceof Area) {
- if (siblings.get(i) == this) {
- return true;
- }
- return false;
- }
- }
- return false;
- }
-
- /**
- * Returns the parent Area.
- * @return The parent if it is an Area, or null if it is not.
- */
- public Area getAreaParent() {
- if (getParent() == null) {
- return null;
- }
- if (getParent() instanceof Area) {
- return (Area) getParent();
- }
- return null;
- }
-
- /**
- * Returns the total amount of the progression-dimension that has been
- * used by siblings.
- * @return The total amount of the progression-dimension that has been
- * used by siblings.
- */
- public abstract int pdUsedBySiblings();
-
- @Override
- public int brIpd() {
- return prIpd() + traitBorderStartWidth() + traitBorderEndWidth();
- }
-
- @Override
- public int brBpd() {
- return prBpd() + traitBorderBeforeWidth() + traitBorderAfterWidth();
- }
-
- /**
- * The difference, in millipoints, between the page-viewport-area's
- * start-edge and this Area's border-rectangle start-edge.
- * This assumes for now that the IP Direction is the same for all areas.
- * @return The IPD offset of the border rectangle.
- */
- public int brOriginIPDOffset() {
- // Start with this Area's content-rectangle offset.
- int offset = crOriginIPDOffset();
- offset -= traitPaddingStart();
- return offset;
- }
-
- /**
- * The difference, in millipoints, between the page-viewport-area's
- * before-edge and this Area's border-rectangle before-edge.
- * This assumes for now that the BP Direction is the same for all areas.
- * @return The BPD offset of the border rectangle.
- */
- public int brOriginBPDOffset() {
- // Start with this Area's content-rectangle offset.
- int offset = crOriginBPDOffset();
- offset -= traitPaddingBefore();
- return offset;
- }
-
- @Override
- public int brOriginX() {
- // Start at the padding-rectangle origin.
- int x = prOriginX();
- final WritingMode writingMode = this.getWritingMode();
- if (this.getBPAxis() == AbsoluteAxis.VERTICAL) {
- // Our BP Axis is vertical
- final boolean goingRight = writingMode.getIpDirectionOdd()
- == AbsoluteDirection.LEFT_TO_RIGHT;
- if (goingRight) {
- x -= this.traitBorderStartWidth();
- } else {
- x += this.traitBorderStartWidth();
- }
- } else {
- // Our BP Axis is horizontal
- final boolean goingRight = writingMode.getBpDirection()
- == AbsoluteDirection.LEFT_TO_RIGHT;
- if (goingRight) {
- x -= this.traitBorderBeforeWidth();
- } else {
- x += this.traitBorderBeforeWidth();
- }
- }
- return x;
- }
-
- @Override
- public int brOriginY() {
- // Start at the padding-rectangle origin.
- int y = prOriginY();
- final WritingMode writingMode = this.getWritingMode();
- if (this.getBPAxis() == AbsoluteAxis.VERTICAL) {
- // Our BP Axis is vertical
- final boolean goingDown = writingMode.getBpDirection()
- == AbsoluteDirection.TOP_TO_BOTTOM;
- if (goingDown) {
- y += this.traitBorderBeforeWidth();
- } else {
- y -= this.traitBorderBeforeWidth();
- }
- } else {
- // Our BP Axis is horizontal
- final boolean goingUp = writingMode.getIpDirectionOdd()
- == AbsoluteDirection.BOTTOM_TO_TOP;
- if (goingUp) {
- y -= this.traitBorderStartWidth();
- } else {
- y += this.traitBorderStartWidth();
- }
- }
- return y;
- }
-
- /**
- * Returns the IPD of the PR.
- * @return The inline-progression-dimension of the padding-rectangle for
- * this Area.
- */
- public int prIpd() {
- return crIpd() + traitPaddingStart() + traitPaddingEnd();
- }
-
- /**
- * Returns the BPD of the PR.
- * @return The block-progression-dimension of the padding-rectangle for
- * this Area.
- */
- public int prBpd() {
- return crBpd() + traitPaddingBefore() + traitPaddingAfter();
- }
-
- /**
- * The difference, in millipoints, between the page-viewport-area's
- * start-edge and this Area's padding-rectangle start-edge.
- * This assumes for now that the IP Direction is the same for all areas.
- * @return The IPD offset of the padding rectangle.
- */
- public int prOriginIPDOffset() {
- // Start with this Area's content-rectangle offset.
- int offset = crOriginIPDOffset();
- offset -= traitPaddingStart();
- return offset;
- }
-
- /**
- * The difference, in millipoints, between the page-viewport-area's
- * before-edge and this Area's padding-rectangle before-edge.
- * This assumes for now that the BP Direction is the same for all areas.
- * @return The BPD offset of the padding rectangle.
- */
- public int prOriginBPDOffset() {
- // Start with this Area's content-rectangle offset.
- int offset = crOriginBPDOffset();
- offset -= traitPaddingBefore();
- return offset;
- }
-
- /**
- * Implementation of {@link BackgroundArea#prOriginX}.
- * @return The padding-rectangle point-of-origin x coordinate.
- */
- public int prOriginX() {
- // Start at the content-rectangle origin.
- int x = crOriginX();
- final WritingMode writingMode = this.getWritingMode();
- if (this.getBPAxis() == AbsoluteAxis.VERTICAL) {
- // Our BP Axis is vertical
- final boolean goingRight = writingMode.getIpDirectionOdd()
- == AbsoluteDirection.LEFT_TO_RIGHT;
- if (goingRight) {
- x -= this.traitPaddingStart();
- } else {
- x += this.traitPaddingStart();
- }
- } else {
- // Our BP Axis is horizontal
- final boolean goingRight = writingMode.getBpDirection()
- == AbsoluteDirection.LEFT_TO_RIGHT;
- if (goingRight) {
- x -= this.traitPaddingBefore();
- } else {
- x += this.traitPaddingBefore();
- }
- }
- return x;
- }
-
- /**
- * Implementation of {@link BackgroundArea#prOriginY}.
- * @return The padding-rectangle point-of-origin y coordinate.
- */
- public int prOriginY() {
- // Start at the content-rectangle origin.
- int y = crOriginY();
- final WritingMode writingMode = this.getWritingMode();
- if (this.getBPAxis() == AbsoluteAxis.VERTICAL) {
- final boolean goingDown = writingMode.getBpDirection()
- == AbsoluteDirection.TOP_TO_BOTTOM;
- if (goingDown) {
- y += this.traitPaddingBefore();
- } else {
- y -= this.traitPaddingBefore();
- }
- } else {
- // Our BP Axis is horizontal
- final boolean goingRight = writingMode.getBpDirection()
- == AbsoluteDirection.LEFT_TO_RIGHT;
- if (goingRight) {
- y -= this.traitPaddingBefore();
- } else {
- y += this.traitPaddingBefore();
- }
- }
- return y;
- }
-
- @Override
- public abstract int crIpd();
-
- @Override
- public abstract int crBpd();
-
- /**
- * The difference, in millipoints, between the page-viewport-area's
- * start-edge and this Area's content-rectangle start-edge.
- * This assumes for now that the IP Direction is the same for all areas.
- * @return The IPD offset of the content rectangle.
- */
- public abstract int crOriginIPDOffset();
-
- /**
- * The difference, in millipoints, between the page-viewport-area's
- * before-edge and this Area's content-rectangle before-edge.
- * This assumes for now that the BP Direction is the same for all areas.
- * @return The BPD offset of the content rectangle.
- */
- public abstract int crOriginBPDOffset();
-
- @Override
- public int crOriginX() {
- return computeCrOriginX();
- }
-
- /**
- * Computes the x coordinate of the point of origin of this area's content
- * rectangle.
- * @return The computed x coordinate of the content rectangle.
- */
- private int computeCrOriginX() {
- // Start at the parent's content origin.
- int x = crReferenceX();
- final AbsoluteDirection ipOdd = getWritingMode().getIpDirectionOdd();
- if (ipOdd == AbsoluteDirection.LEFT_TO_RIGHT) {
- x += this.crOriginIPDOffset();
- return x;
- }
- if (ipOdd == AbsoluteDirection.RIGHT_TO_LEFT) {
- x -= this.crOriginIPDOffset();
- return x;
- }
- final AbsoluteDirection bpd = getWritingMode().getBpDirection();
- if (bpd == AbsoluteDirection.LEFT_TO_RIGHT) {
- x += this.crOriginBPDOffset();
- return x;
- }
- if (bpd == AbsoluteDirection.RIGHT_TO_LEFT) {
- x -= this.crOriginBPDOffset();
- return x;
- }
- return x;
- }
-
- /**
- * Returns the reference X value.
- * @return The x value (from an appropriate parent) from which this Area's
- * content-rectangle is computed, that is, the starting point.
- */
- int crReferenceX() {
- return getContainingReferenceArea().crOriginX();
- }
-
- @Override
- public int crOriginY() {
- return computeCrOriginY();
- }
-
- /**
- * Computes the y coordinate of the point of origin of this area's content
- * rectangle.
- * @return The computed y coordinate of the content rectangle.
- */
- private int computeCrOriginY() {
- // Start at the parent's content origin.
- int y = ancestorArea().crOriginY();
- final AbsoluteDirection bpd = getWritingMode().getBpDirection();
- if (bpd == AbsoluteDirection.TOP_TO_BOTTOM) {
- y -= this.crOriginBPDOffset();
- return y;
- }
- if (bpd == AbsoluteDirection.BOTTOM_TO_TOP) {
- y += this.crOriginBPDOffset();
- return y;
- }
- final AbsoluteDirection ipOdd = getWritingMode().getIpDirectionOdd();
- if (ipOdd == AbsoluteDirection.TOP_TO_BOTTOM) {
- y -= this.crOriginIPDOffset();
- return y;
- }
- if (ipOdd == AbsoluteDirection.RIGHT_TO_LEFT) {
- y += this.crOriginIPDOffset();
- return y;
- }
- return y;
- }
-
- /**
- * Returns the IPD of the NAR.
- * @return The inline-progression-dimension of the
- * normal-allocation-rectangle for this Area.
- */
- public int narIPD() {
- if (isBlockArea()) {
- return crIpd() + traitStartIndent() + traitEndIndent();
- }
- return brIpd();
- }
-
- /**
- * Retursn the BPD of the NAR.
- * @return The block-progression-dimension of the
- * normal-allocation-rectangle for this Area.
- */
- public int narBPD() {
- if (isBlockArea()) {
- return brBpd();
- }
- return crBpd();
- }
-
- /**
- * See {@link #brOriginX()} where point-of-origin is defined.
- * @return The absolute cartesian X value, on the page, of the point of
- * origin of the normal-allocation-rectangle.
- */
- public int narOriginX() {
- return 0;
- }
-
- /**
- * See {@link #brOriginX()} where point-of-origin is defined.
- * @return The absolute cartesian Y value, on the page, of the point of
- * origin of the normal-allocation-rectangle.
- */
- public int narOriginY() {
- return 0;
- }
-
- /**
- * Returns the IPD of the LAR.
- * @return The inline-progression-dimension of the
- * large-allocation-rectangle for this Area.
- */
- public int larIPD() {
- // LAR is the same as the BR
- return brIpd();
- }
-
- /**
- * Returns the BPD of the LAR.
- * @return The block-progression-dimension of the large-allocation-rectangle
- * for this Area.
- */
- public int larBPD() {
- // LAR is the same as the BR
- return brBpd();
- }
-
- /**
- * See {@link #brOriginX()} where point-of-origin is defined.
- * @return The absolute cartesian X value, on the page, of the point of
- * origin of the large-allocation-rectangle.
- */
- public int larOriginX() {
- // LAR is the same as the BR
- return brOriginX();
- }
-
- /**
- * See {@link #brOriginX()} where point-of-origin is defined.
- * @return The absolute cartesian Y value, on the page, of the point of
- * origin of the large-allocation-rectangle.
- */
- public int larOriginY() {
- // LAR is the same as the BR
- return brOriginY();
- }
-
- /**
- * Indicates whether this Area is a block area.
- * @return True if this Area is a block-area, false if it is an inline-area.
- * Defaults to true. Inline areas should override this method.
- */
- public boolean isBlockArea() {
- return true;
- }
-
- /**
- * Returns the space-before optimum trait for this area.
- * @return The space-before optimum trait for this area.
- */
- public abstract int traitSpaceBeforeOptimum();
-
- /**
- * Returns the space-after optimum trait for this area.
- * @return The space-after optimum trait for this area.
- */
- public abstract int traitSpaceAfterOptimum();
-
- /**
- * Returns the space-start optimum trait for this area.
- * @return The space-start optimum trait for this area.
- */
- public abstract int traitSpaceStartOptimum();
-
- /**
- * Returns the space-end optimum trait for this area.
- * @return The space-end optimum trait for this area.
- */
- public abstract int traitSpaceEndOptimum();
-
- /**
- * Tells which axis (horizontal or vertical) is the block-progression axis.
- * @return Either {@link AbsoluteAxis#HORIZONTAL} or
- * {@link AbsoluteAxis#VERTICAL}, or null if writing-mode is invalid.
- */
- public AbsoluteAxis getBPAxis() {
- return getWritingMode().getBpAxis();
- }
-
- /**
- * Tells which axis (horizontal or vertical) is the inline-progression axis.
- * @return Either {@link AbsoluteAxis#HORIZONTAL} or
- * {@link AbsoluteAxis#VERTICAL}, or null if writing-mode is invalid.
- */
- public AbsoluteAxis getIPAxis() {
- return getWritingMode().getIpAxis();
- }
-
- /**
- * Returns the writing-mode for this area.
- * @return The writing-mode for this area.
- */
- public WritingMode getWritingMode() {
- final Fo generatedBy = traitGeneratedBy();
- if (generatedBy instanceof WritingModePa) {
- return ((WritingModePa) generatedBy).traitWritingMode(this);
- }
- return this.ancestorArea().getWritingMode();
- }
-
- /**
- * Returns the content stacking axis for this area.
- * @return Either {@link RelativeAxis#BLOCK_PROGRESSION} or
- * {@link RelativeAxis#INLINE_PROGRESSION}, depending on whether the
- * contents of this area stack in the block-progression-direction or the
- * inline-progression-direction.
- * The default value is that contents stack in the BPD. Classes that
- * stack in the IPD should override this method.
- */
- public abstract RelativeAxis contentStackingAxis();
-
- /**
- * Return the absolute axis for this area.
- * @return Either {@link AbsoluteAxis#HORIZONTAL} or
- * {@link AbsoluteAxis#VERTICAL}, depending on the relative content stacking
- * axis and the writing-mode.
- * @see #contentStackingAxis()
- */
- public AbsoluteAxis contentStackingAxisAbsolute() {
- return getWritingMode().getAbsoluteAxis(contentStackingAxis());
- }
-
- /**
- * Return the absolute direction for this area.
- * @return One of {@link AbsoluteDirection#TOP_TO_BOTTOM},
- * {@link AbsoluteDirection#BOTTOM_TO_TOP},
- * {@link AbsoluteDirection#LEFT_TO_RIGHT},
- * or {@link AbsoluteDirection#RIGHT_TO_LEFT}, depending on the
- * writing-mode.
- */
- public AbsoluteDirection contentStackingDirectionAbsolute() {
- final RelativeAxis relative = contentStackingAxis();
- return getWritingMode().getAbsoluteDirFromRelativeAxis(relative);
- }
-
- @Override
- public abstract int pdAvailable();
-
- /**
- * <p>Returns the actual total value, in millipoints, of the size of this
- * area (not counting space-before, etc.) in its progression direction.
- * This value does <em>not</em> include space-before, etc., but
- * <em>does</em> include borders and padding.
- * For block areas, the progression dimension is the
- * block-progression-dimension.
- * For inline areas, it is the inline-progression-dimension.</p>
- * @return The progressionDimension.
- */
- public abstract int getProgressionDimension();
-
- /**
- * Sets the progression-dimension used by this Area.
- * @param progressionDimension The new progression-dimension value for this
- * Area.
- */
- public abstract void setProgressionDimension(int progressionDimension);
-
- /**
- * Set the minimum progression dimension for this Area. If the current
- * progression dimension value is less than this value, it will be
- * increased to this minimum. Otherwise, it is ignored.
- * @param minimumPD The minimum progression dimension to set.
- */
- public abstract void setMinimumProgressionDimension(int minimumPD);
-
- /**
- * Change the progression-dimension used by this Area.
- * @param incrementAmount The amount by which the progression-dimension
- * should be changed for this area.
- * Positive values increase the progression-dimension, negative values
- * decrease it.
- */
- public abstract void incrementProgressionDimension(int incrementAmount);
-
- /**
- * This method is used by child Areas to ask the parent Area into which
- * Area the child Area's overflow should be placed.
- * Overflows start when a new LineArea cannot be create for the current
- * BlockArea.
- * General strategy for overflow is to recursively go up the tree until
- * getting to any Area that knows how to solve the overflow. One general
- * case is the page-reference-area, which should know how to create a
- * new page.
- * @param childRequesting Child Areas ask
- * @return The younger sister Area that should be used to handle the
- * overflow condition.
- * @throws AreaTreeException If the Area is unable to find or create the
- * overflow area.
- */
- public abstract Area getOverflowArea(Area childRequesting)
- throws AreaTreeException;
-
- /**
- * Indicates whether this area is a reference area.
- * @return True iff this area is a reference area.
- */
- public boolean traitIsReferenceArea() {
- return traitGeneratedBy().traitIsReferenceArea();
- }
-
- /**
- * Returns the cumulative reference orientation for this area.
- * @return The cumulative reference orientation for this area, in degrees.
- */
- public short referenceOrientationCumulative() {
- /* TODO: This needs to be rewritten. There is a mismatch between the
- * FoValue items returned and the "degrees" concept that needs to be
- * resolved. */
- return 0;
-// final Area containingRA = this.getContainingReferenceArea();
-// short cumulative = containingRA.traitReferenceOrientation();
- /*
- * The FObj method from which the following line is derived returns
- * a 0 for FOs that do not generate reference-areas.
- */
-// cumulative += this.traitReferenceOrientation();
-// if (cumulative < 0) {
-// cumulative += WellKnownConstants.DEGREES_PER_CIRCLE;
-// }
-// return (short) (cumulative % WellKnownConstants.DEGREES_PER_CIRCLE);
- }
-
- /**
- * Returns the whitespace-treatment trait for this area.
- * @return The whitespace-treatment trait for this area.
- */
- public WhiteSpaceTreatment traitWhiteSpaceTreatment() {
- final NormalBlockArea nearestBlockArea = this.nearestNormalBlockArea();
- final Block block = nearestBlockArea.traitGeneratedBy();
- return block.traitWhiteSpaceTreatment(nearestBlockArea);
- }
-
- /**
- * Indicates whether this is the first child of the "generated by".
- * @return True iff this is the first child of the "generated by".
- */
- public boolean traitIsFirst() {
- return this.isFirstChildOfGeneratedBy();
- }
-
- /**
- * Indicates whether this is the last child of the "generated by".
- * @return True iff this is the last child of the "generated by".
- */
- public boolean traitIsLast() {
- return this.isLastChildOfGeneratedBy();
- }
-
- @Override
- public String destinationName() {
- final String id = traitId();
- if (id == null || id.equals("")) {
- return null;
- }
- /*
- * Only one Area should be used to create the destination, and it must
- * be the first. For example, if an fo:block starts at the bottom of
- * page N, and continues at the top of Page N+1, the destination should
- * point to the bottom of N.
- */
- if (! (this.isFirstChildOfGeneratedBy())) {
- return null;
- }
- return id;
- }
-
- @Override
- public boolean isLinkRoot() {
- if (linkType() == null) {
- return false;
- }
- if (this.ancestorArea() != null
- && this.ancestorArea().linkType() != null) {
- return false;
- }
- return true;
- }
-
- @Override
- public LinkType linkType() {
- final BasicLink link = this.traitGeneratedBy().ancestorBasicLink(this);
- if (link == null) {
- return null;
- }
- return link.getLinkType();
- }
-
- @Override
- public String linkDestination() {
- final BasicLink link = this.traitGeneratedBy().ancestorBasicLink(this);
- if (link == null) {
- return null;
- }
- return link.getDestination();
- }
-
- /**
- * Returns the content rectangle measured in points (1/72 of an inch).
- * @return The content rectangle in points.
- */
- public Rectangle2D.Float crPoints() {
- return new Rectangle2D.Float(
- crOriginX() / WellKnownConstants.MILLIPOINTS_PER_POINT,
- crOriginY() / WellKnownConstants.MILLIPOINTS_PER_POINT,
- crIpd() / WellKnownConstants.MILLIPOINTS_PER_POINT,
- crBpd() / WellKnownConstants.MILLIPOINTS_PER_POINT);
- }
-
- /**
- * Returns the border rectangle measured in points (1/72 of an inch).
- * @return The border rectangle in points.
- */
- public Rectangle2D.Float brPoints() {
- return new Rectangle2D.Float(
- brOriginX() / WellKnownConstants.MILLIPOINTS_PER_POINT,
- brOriginY() / WellKnownConstants.MILLIPOINTS_PER_POINT,
- brIpd() / WellKnownConstants.MILLIPOINTS_PER_POINT,
- brBpd() / WellKnownConstants.MILLIPOINTS_PER_POINT);
- }
-
- /**
- * Indicates whether this Area is positioned absolutely or relatively.
- * @return True iff this Area is absolutely positioned.
- */
- public abstract boolean isAbsolutelyPositioned();
-
- /**
- * Indicates whether this Area is part of the normal flow.
- * See XSL-FO 1.0, Section 7.5, where absolutely-positioned Areas are
- * excluded from the normal flow, and do not affect the positioning of later
- * siblings.
- * @return True iff this Area is part of the normal flow and affects the
- * positioning of later siblings.
- */
- public boolean isInNormalFlow() {
- if (this.isAbsolutelyPositioned()) {
- return false;
- }
- return true;
- }
-
- /**
- * Indicates whether the parent progression dimension should be adjusted.
- * @return True iff the parent progression dimension should be adjusted.
- */
- public boolean shouldAdjustParentPD() {
- /* If not in the normal flow, the parent's dimensions are not used up
- * as this grows. */
- if (! this.isInNormalFlow()) {
- return false;
- }
- final Area parent = ancestorArea();
- if (parent instanceof LineArea) {
- /* LineArea children grow in the IPD, LineArea grows in the BPD. */
- return false;
- }
- if (parent instanceof TableRowContainer) {
- /* TableRowContainer children grow in the IPD, LineArea grows in the
- * BPD. */
- return false;
- }
- return true;
- }
-
- /**
- * Returns the area-class trait for this Area.
- * @return The area-class trait for this Area.
- * @see "XSL-FO 1.1, Section 4.2.5."
- */
- public AreaClass traitAreaClass() {
- /* TODO: This method is incomplete. */
- final FootnoteRa footnoteArea = this.nearestFootnoteArea();
- if (footnoteArea != null) {
- return AreaClass.XSL_FOOTNOTE;
- }
- final BeforeFloatRa beforeFloatArea = this.nearestBeforeFloatArea();
- if (beforeFloatArea != null) {
- return AreaClass.XSL_BEFORE_FLOAT;
- }
- return AreaClass.XSL_NORMAL;
- }
-
- /**
- * Indicates whether there is an absolute fence preceding this Area for
- * purposes of stacking constraints.
- * This method is only relevant for block-areas as inline-areas have a more
- * complicated fencing procedure.
- * @return True iff this Area has a fence preceding it.
- * @see "XSL-FO 1.1, Section 4.2.5, under 'Block-stacking constraints'."
- */
- public boolean hasFencePreceding() {
- if (this.isBlockArea()) {
- if (this.traitIsReferenceArea()) {
- return true;
- }
- if (this.traitBorderBeforeWidth() != 0) {
- return true;
- }
- if (this.traitPaddingBefore() != 0) {
- return true;
- }
- }
- return false;
- }
-
- /**
- * Indicates whether there is an absolute fence following this Area for
- * purposes of stacking constraints.
- * This method is only relevant for block-areas as inline-areas have a more
- * complicated fencing procedure.
- * @return True iff this Area has a fence following it.
- * @see "XSL-FO 1.1, Section 4.2.5, under 'Block-stacking constraints'."
- */
- public boolean hasFenceFollowing() {
- if (this.isBlockArea()) {
- if (this.traitIsReferenceArea()) {
- return true;
- }
- if (this.traitBorderAfterWidth() != 0) {
- return true;
- }
- if (this.traitPaddingAfter() != 0) {
- return true;
- }
- }
- return false;
- }
-
- @Override
- public Area nearestArea() {
- /* Overrides the AreaNode implementation, because this is the nearest
- * Area. */
- return this;
- }
-
- @Override
- public String traitId() {
- final Fo generatedBy = this.traitGeneratedBy();
- if (generatedBy instanceof IdPa) {
- return ((IdPa) generatedBy).traitId();
- }
- return null;
- }
-
- /**
- * Returns the border-start-width trait for this area.
- * @return The border-start-width trait for this area.
- */
- public abstract int traitBorderStartWidth();
-
- /**
- * Returns the border-end-width trait for this area.
- * @return The border-end-width trait for this area.
- */
- public abstract int traitBorderEndWidth();
-
- /**
- * Returns the border-before-width trait for this area.
- * @return The border-before-width trait for this area.
- */
- public abstract int traitBorderBeforeWidth();
-
- /**
- * Returns the border-after-width trait for this area.
- * @return The border-after-width trait for this area.
- */
- public abstract int traitBorderAfterWidth();
-
- /**
- * Returns the padding-start trait for this area.
- * @return The padding-start trait for this area.
- */
- public abstract int traitPaddingStart();
-
- /**
- * Returns the padding-end trait for this area.
- * @return The padding-end trait for this area.
- */
- public abstract int traitPaddingEnd();
-
- /**
- * Returns the padding-before trait for this area.
- * @return The padding-before trait for this area.
- */
- public abstract int traitPaddingBefore();
-
- /**
- * Returns the padding-after trait for this area.
- * @return The padding-after trait for this area.
- */
- public abstract int traitPaddingAfter();
-
- /**
- * Returns the writing mode associated with this Area.
- * @return The writing mode (vertical or horizontal) that is associated with this Area.
- */
- public Font.WritingMode getFontWritingMode() {
- final AbsoluteAxis axis = this.getWritingMode().getIpAxis();
- if (axis == AbsoluteAxis.VERTICAL) {
- return Font.WritingMode.VERTICAL;
- }
- return Font.WritingMode.HORIZONTAL;
- }
-
-}
Copied: trunk/foray/foray-areatree/src/main/java/org/foray/area/Area4a.java (from rev 12032, trunk/foray/foray-areatree/src/main/java/org/foray/area/Area.java)
===================================================================
--- trunk/foray/foray-areatree/src/main/java/org/foray/area/Area4a.java (rev 0)
+++ trunk/foray/foray-areatree/src/main/java/org/foray/area/Area4a.java 2021-11-14 23:19:35 UTC (rev 12065)
@@ -0,0 +1,1019 @@
+/*
+ * Copyright 2004 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.area;
+
+import org.foray.common.WellKnownConstants;
+
+import org.axsl.area.AreaTreeException;
+import org.axsl.area.BlockContainerRefArea;
+import org.axsl.common.value.AbsoluteAxis;
+import org.axsl.common.value.AbsoluteDirection;
+import org.axsl.common.value.LinkType;
+import org.axsl.common.value.RelativeAxis;
+import org.axsl.common.value.WhiteSpaceTreatment;
+import org.axsl.common.value.WritingMode;
+import org.axsl.fo.Fo;
+import org.axsl.fo.fo.BasicLink;
+import org.axsl.fo.fo.Block;
+import org.axsl.fo.fo.prop.IdPa;
+import org.axsl.fo.fo.prop.WritingModePa;
+import org.axsl.font.Font;
+import org.axsl.galley.BackgroundArea;
+
+import java.awt.geom.Rectangle2D;
+import java.util.List;
+
+/**
+ * Abstract superclass for all Areas in the AreaTree.
+ */
+public abstract class Area4a extends AreaNode4a implements org.axsl.galley.Area,
+ org.axsl.area.Area {
+
+ ...
[truncated message content] |
|
From: <vic...@us...> - 2021-11-14 22:36:04
|
Revision: 12064
http://sourceforge.net/p/foray/code/12064
Author: victormote
Date: 2021-11-14 22:36:02 +0000 (Sun, 14 Nov 2021)
Log Message:
-----------
Conform to aXSL change: Require WritingSystem. This effectively pushes the hard-coded WritingSystem arguments upstream.
Modified Paths:
--------------
trunk/foray/foray-areatree/src/main/java/org/foray/area/TextArea.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfDocument4a.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXformMath.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXformSvg.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXobject4a.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/util/PdfGraphics2D.java
trunk/foray/foray-render/src/main/java/org/foray/render/pdf/PdfRenderer.java
Modified: trunk/foray/foray-areatree/src/main/java/org/foray/area/TextArea.java
===================================================================
--- trunk/foray/foray-areatree/src/main/java/org/foray/area/TextArea.java 2021-11-14 20:40:14 UTC (rev 12063)
+++ trunk/foray/foray-areatree/src/main/java/org/foray/area/TextArea.java 2021-11-14 22:36:02 UTC (rev 12064)
@@ -65,7 +65,7 @@
* Please note that a given FOText node may have more than one TextArea that
* springs from it (they would have to be in different LineAreas or use
* different Fonts due to overriding).
- * However , a TextSegment always springs from exactly one FOText node.
+ * However, a TextSegment always springs from exactly one FOText node.
*/
public final class TextArea extends AbstractInlineArea
implements org.axsl.galley.TextArea, org.axsl.area.GlyphAreaSequence {
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfDocument4a.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfDocument4a.java 2021-11-14 20:40:14 UTC (rev 12063)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfDocument4a.java 2021-11-14 22:36:02 UTC (rev 12064)
@@ -45,6 +45,7 @@
import org.foray.pdf.PdfParser;
import org.axsl.common.Gradient;
+import org.axsl.common.i18n.WritingSystem;
import org.axsl.common.sequence.IntPrimitiveIterator;
import org.axsl.font.Font;
import org.axsl.font.FontConsumer;
@@ -766,10 +767,11 @@
}
@Override
- public PdfXobject createXobject(final Graphic graphic, final FontConsumer fontConsumer) throws PdfException {
+ public PdfXobject createXobject(final Graphic graphic, final WritingSystem writingSystem,
+ final FontConsumer fontConsumer) throws PdfException {
final PdfXobject4a xObject;
try {
- xObject = PdfXobject4a.makeXObject(this, graphic, fontConsumer);
+ xObject = PdfXobject4a.makeXObject(this, graphic, writingSystem, fontConsumer);
} catch (final GraphicException e) {
throw new PdfException(e);
}
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXformMath.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXformMath.java 2021-11-14 20:40:14 UTC (rev 12063)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXformMath.java 2021-11-14 22:36:02 UTC (rev 12064)
@@ -33,6 +33,7 @@
import org.foray.pdf.util.PdfGraphics2D;
import org.axsl.common.data.BoundingBox;
+import org.axsl.common.i18n.WritingSystem;
import org.axsl.font.FontConsumer;
import org.axsl.graphic.GraphicException;
import org.axsl.graphic.MathGraphic;
@@ -55,15 +56,21 @@
/** The FontConsumer to use for resolving fonts in the MathML document. */
private FontConsumer fontConsumer;
+ /** The writing system. */
+ private WritingSystem writingSystem;
+
/**
* Constructor.
* @param doc The parent PDF document.
* @param graphic The form to be encapsulated.
+ * @param writingSystem The writing system.
* @param fontConsumer The font consumer to use for resolving fonts in the SVG.
*/
- public PdfXformMath(final PdfDocument4a doc, final MathGraphic graphic, final FontConsumer fontConsumer) {
+ public PdfXformMath(final PdfDocument4a doc, final MathGraphic graphic, final WritingSystem writingSystem,
+ final FontConsumer fontConsumer) {
super(doc, graphic);
this.graphic = graphic;
+ this.writingSystem = writingSystem;
this.fontConsumer = fontConsumer;
}
@@ -78,7 +85,7 @@
}
final GraphicPdf graphicPdf = (GraphicPdf) graphicOutput;
// graphicPdf.drawVectorContent(outputStream, doc, this.fontConsumer, this.strokeText, false);
- final Graphics2D graphic2D = new PdfGraphics2D(fontConsumer, doc, outputStream);
+ final Graphics2D graphic2D = new PdfGraphics2D(this.writingSystem, this.fontConsumer, doc, outputStream);
graphicPdf.drawVectorContent(graphic2D, fontConsumer);
return outputStream.toByteArray();
}
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXformSvg.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXformSvg.java 2021-11-14 20:40:14 UTC (rev 12063)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXformSvg.java 2021-11-14 22:36:02 UTC (rev 12064)
@@ -33,6 +33,7 @@
import org.foray.pdf.util.PdfGraphics2D;
import org.axsl.common.data.BoundingBox;
+import org.axsl.common.i18n.WritingSystem;
import org.axsl.font.FontConsumer;
import org.axsl.graphic.GraphicException;
import org.axsl.graphic.SvgGraphic;
@@ -55,16 +56,22 @@
/** The FontConsumer to use for resolving fonts in the SVG. */
private FontConsumer fontConsumer;
+ /** The writing system. */
+ private WritingSystem writingSystem;
+
/**
* Constructor.
* @param doc The parent PDF document.
* @param graphic The form to be encapsulated.
+ * @param writingSystem The writing system.
* @param fontConsumer The font consumer to use for resolving fonts in the SVG.
*/
- public PdfXformSvg(final PdfDocument4a doc, final SvgGraphic graphic, final FontConsumer fontConsumer) {
+ public PdfXformSvg(final PdfDocument4a doc, final SvgGraphic graphic, final WritingSystem writingSystem,
+ final FontConsumer fontConsumer) {
super(doc, graphic);
this.graphic = graphic;
this.fontConsumer = fontConsumer;
+ this.writingSystem = writingSystem;
}
@Override
@@ -78,7 +85,7 @@
}
final GraphicPdf graphicPdf = (GraphicPdf) graphicOutput;
// graphicPdf.drawVectorContent(outputStream, doc, this.fontConsumer, this.strokeText, false);
- final Graphics2D graphic2D = new PdfGraphics2D(fontConsumer, doc, outputStream);
+ final Graphics2D graphic2D = new PdfGraphics2D(this.writingSystem, this.fontConsumer, doc, outputStream);
graphicPdf.drawVectorContent(graphic2D, fontConsumer);
return outputStream.toByteArray();
}
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXobject4a.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXobject4a.java 2021-11-14 20:40:14 UTC (rev 12063)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXobject4a.java 2021-11-14 22:36:02 UTC (rev 12064)
@@ -34,6 +34,7 @@
package org.foray.pdf.object;
+import org.axsl.common.i18n.WritingSystem;
import org.axsl.font.FontConsumer;
import org.axsl.graphic.EpsGraphic;
import org.axsl.graphic.Graphic;
@@ -85,12 +86,13 @@
* PdfXobject instance.
* @param pdfDoc The parent PDF document.
* @param img The graphic to be encapsulated.
+ * @param writingSystem The writing system.
* @param fontConsumer The font consumer to use for resolving fonts in the SVG.
* @return An appropriate PdfXobject instance that encapsulates the input.
* @throws GraphicException For errors getting the appropriate filter.
*/
public static PdfXobject4a makeXObject(final PdfDocument4a pdfDoc, final Graphic img,
- final FontConsumer fontConsumer) throws GraphicException {
+ final WritingSystem writingSystem, final FontConsumer fontConsumer) throws GraphicException {
/* If it has already been created, reuse it ... */
PdfXobject4a xObject = pdfDoc.findXObject(img);
if (xObject != null) {
@@ -103,10 +105,10 @@
xObject = new PdfXformEps(pdfDoc, epsGraphic);
} else if (img instanceof SvgGraphic) {
final SvgGraphic svgGraphic = (SvgGraphic) img;
- xObject = new PdfXformSvg(pdfDoc, svgGraphic, fontConsumer);
+ xObject = new PdfXformSvg(pdfDoc, svgGraphic, writingSystem, fontConsumer);
} else if (img instanceof MathGraphic) {
final MathGraphic mathGraphic = (MathGraphic) img;
- xObject = new PdfXformMath(pdfDoc, mathGraphic, fontConsumer);
+ xObject = new PdfXformMath(pdfDoc, mathGraphic, writingSystem, fontConsumer);
} else if (img.getGraphicType() == Graphic.Type.PDF) {
xObject = new PdfXreference(pdfDoc, img);
} else {
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/util/PdfGraphics2D.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/util/PdfGraphics2D.java 2021-11-14 20:40:14 UTC (rev 12063)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/util/PdfGraphics2D.java 2021-11-14 22:36:02 UTC (rev 12064)
@@ -36,12 +36,12 @@
import org.foray.common.CharacterOutputStream;
import org.foray.common.Gradient4a;
import org.foray.common.WellKnownConstants;
-import org.foray.common.i18n.WritingSystem4a;
import org.foray.common.ps.PsColor;
import org.foray.common.ps.PsUtil;
import org.foray.pdf.PdfConstants;
import org.foray.pdf.object.PdfColor4a;
+import org.axsl.common.i18n.WritingSystem;
import org.axsl.font.FontConsumer;
import org.axsl.font.FontOptions;
import org.axsl.font.FontUse;
@@ -158,6 +158,9 @@
* the next "restore". */
private Stack<PdfGraphics2D.PdfGraphicsState> graphicsStateStack = new Stack<PdfGraphics2D.PdfGraphicsState>();
+ /** The current writing system. */
+ private WritingSystem writingSystem;
+
/** Lazily-loaded logger. Use {@link getLogger()} to obtain the instance. */
private Logger logger;
@@ -164,11 +167,12 @@
/**
* Create a new PdfGraphics2D with the given pdf document info.
* This is used to create a Graphics object for use inside an already existing document.
+ * @param writingSystem The writing system in use.
* @param fontConsumer The font consumer for this document.
* @param pdfContext The PDF context in which this content is being written.
* @param outputStream The output stream to which this processor writes its PDF output.
*/
- public PdfGraphics2D(final FontConsumer fontConsumer,
+ public PdfGraphics2D(final WritingSystem writingSystem, final FontConsumer fontConsumer,
final GraphicOutputContext pdfContext, final OutputStream outputStream) {
super(fontConsumer == null);
this.gc = new GraphicContext();
@@ -179,6 +183,7 @@
this.fontConsumer = fontConsumer;
this.pdfContext = pdfContext;
this.graphicsStateStack.push(new PdfGraphicsState(null));
+ this.writingSystem = writingSystem;
}
/**
@@ -675,7 +680,7 @@
this.write(matrixString + "cm");
this.write("1 0 0 -1 0 0 Tm ");
- final CharSequence outputString = font.textToPdf(s, FontOptions.DEFAULT, WritingSystem4a.USA);
+ final CharSequence outputString = font.textToPdf(s, FontOptions.DEFAULT, this.writingSystem);
this.write(outputString);
this.write("ET");
Modified: trunk/foray/foray-render/src/main/java/org/foray/render/pdf/PdfRenderer.java
===================================================================
--- trunk/foray/foray-render/src/main/java/org/foray/render/pdf/PdfRenderer.java 2021-11-14 20:40:14 UTC (rev 12063)
+++ trunk/foray/foray-render/src/main/java/org/foray/render/pdf/PdfRenderer.java 2021-11-14 22:36:02 UTC (rev 12064)
@@ -34,6 +34,7 @@
package org.foray.render.pdf;
import org.foray.common.WellKnownConstants;
+import org.foray.common.i18n.WritingSystem4a;
import org.foray.render.PrintRenderer;
import org.axsl.common.FormattedIntegerType;
@@ -304,7 +305,7 @@
final Rectangle2D.Float pdfClipRectangle = convertMillipointRectangle(
clipRectangle);
try {
- final PdfXobject xObject = this.pdfDoc.createXobject(image, getFontConsumer());
+ final PdfXobject xObject = this.pdfDoc.createXobject(image, WritingSystem4a.USA, getFontConsumer());
getContentStream().drawXobject(xObject, pdfContentRectangle, pdfClipRectangle);
} catch (final PdfException e) {
throw new GalleyVisitorException(e);
@@ -320,7 +321,7 @@
toPoints(foreign.referenceBpd()));
final SvgGraphic svgGraphic = area.getGraphic();
try {
- final PdfXobject xObject = this.pdfDoc.createXobject(svgGraphic, getFontConsumer());
+ final PdfXobject xObject = this.pdfDoc.createXobject(svgGraphic, WritingSystem4a.USA, getFontConsumer());
getContentStream().drawXobject(xObject, contentRectangle, null);
} catch (final PdfException e) {
throw new GalleyVisitorException(e);
@@ -337,7 +338,7 @@
toPoints(foreign.referenceBpd()));
final MathGraphic mathGraphic = area.getGraphic();
try {
- final PdfXobject xObject = this.pdfDoc.createXobject(mathGraphic, getFontConsumer());
+ final PdfXobject xObject = this.pdfDoc.createXobject(mathGraphic, WritingSystem4a.USA, getFontConsumer());
getContentStream().drawXobject(xObject, contentRectangle, null);
} catch (final PdfException e) {
throw new GalleyVisitorException(e);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-11-14 20:40:17
|
Revision: 12063
http://sourceforge.net/p/foray/code/12063
Author: victormote
Date: 2021-11-14 20:40:14 +0000 (Sun, 14 Nov 2021)
Log Message:
-----------
Add method that retrieves the WritingSystem from the FO tree. Use that to remove a hard-coded instance.
Modified Paths:
--------------
trunk/foray/foray-areatree/src/main/java/org/foray/area/FoLinkage.java
trunk/foray/foray-areatree/src/main/java/org/foray/area/TextArea.java
Modified: trunk/foray/foray-areatree/src/main/java/org/foray/area/FoLinkage.java
===================================================================
--- trunk/foray/foray-areatree/src/main/java/org/foray/area/FoLinkage.java 2021-11-14 20:38:39 UTC (rev 12062)
+++ trunk/foray/foray-areatree/src/main/java/org/foray/area/FoLinkage.java 2021-11-14 20:40:14 UTC (rev 12063)
@@ -28,7 +28,9 @@
package org.foray.area;
+import org.axsl.common.i18n.WritingSystem;
import org.axsl.fo.Fo;
+import org.axsl.fo.FoLineText;
import org.axsl.fo.fo.GraftingPoint;
/**
@@ -63,4 +65,16 @@
*/
public abstract GraftingPoint getRetrieveMarker(AreaNode areaNode);
+ /**
+ * Retrieves the writing system, if any, for the wrapped FO.
+ * @return The writing system for the wrapped FO, of null if the FO does not have one.
+ */
+ public WritingSystem getWritingSystem() {
+ if (this.foGenerator instanceof FoLineText) {
+ final FoLineText lt = (FoLineText) this.foGenerator;
+ return lt.inlineWritingSystem();
+ }
+ return null;
+ }
+
}
Modified: trunk/foray/foray-areatree/src/main/java/org/foray/area/TextArea.java
===================================================================
--- trunk/foray/foray-areatree/src/main/java/org/foray/area/TextArea.java 2021-11-14 20:38:39 UTC (rev 12062)
+++ trunk/foray/foray-areatree/src/main/java/org/foray/area/TextArea.java 2021-11-14 20:40:14 UTC (rev 12063)
@@ -29,7 +29,6 @@
package org.foray.area;
import org.foray.common.CharSequenceSubset;
-import org.foray.common.i18n.WritingSystem4a;
import org.foray.common.primitive.XmlCharacterUtils;
import org.axsl.area.AreaTreeException;
@@ -679,8 +678,7 @@
@Override
public WritingSystem writingSystem() {
- /* TODO: Get this from the FOTree. */
- return WritingSystem4a.USA;
+ return this.generatedBy.getWritingSystem();
}
@Override
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-11-14 20:38:41
|
Revision: 12062
http://sourceforge.net/p/foray/code/12062
Author: victormote
Date: 2021-11-14 20:38:39 +0000 (Sun, 14 Nov 2021)
Log Message:
-----------
Remove dependency on hard-coded writing system
Modified Paths:
--------------
trunk/foray/foray-render/src/main/java/org/foray/render/pdf/PdfRenderer.java
Modified: trunk/foray/foray-render/src/main/java/org/foray/render/pdf/PdfRenderer.java
===================================================================
--- trunk/foray/foray-render/src/main/java/org/foray/render/pdf/PdfRenderer.java 2021-11-14 19:46:18 UTC (rev 12061)
+++ trunk/foray/foray-render/src/main/java/org/foray/render/pdf/PdfRenderer.java 2021-11-14 20:38:39 UTC (rev 12062)
@@ -34,7 +34,6 @@
package org.foray.render.pdf;
import org.foray.common.WellKnownConstants;
-import org.foray.common.i18n.WritingSystem4a;
import org.foray.render.PrintRenderer;
import org.axsl.common.FormattedIntegerType;
@@ -481,7 +480,7 @@
/* Paint the text. */
final CharSequence textToWrite = text.subSequence(startIndex, startIndex + size);
- getContentStream().drawText(textToWrite, fontOptions, WritingSystem4a.USA);
+ getContentStream().drawText(textToWrite, fontOptions, orthography);
}
@Override
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-11-14 19:46:20
|
Revision: 12061
http://sourceforge.net/p/foray/code/12061
Author: victormote
Date: 2021-11-14 19:46:18 +0000 (Sun, 14 Nov 2021)
Log Message:
-----------
Allow Punctuation4a to silently return a null. Fix some minor side-effects of that.
Modified Paths:
--------------
trunk/foray/foray-orthography/src/main/data/dictionaries/eng-999-Latn.dict.xml
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/LexerLatin1.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/Punctuation4a.java
Modified: trunk/foray/foray-orthography/src/main/data/dictionaries/eng-999-Latn.dict.xml
===================================================================
--- trunk/foray/foray-orthography/src/main/data/dictionaries/eng-999-Latn.dict.xml 2021-11-14 16:56:39 UTC (rev 12060)
+++ trunk/foray/foray-orthography/src/main/data/dictionaries/eng-999-Latn.dict.xml 2021-11-14 19:46:18 UTC (rev 12061)
@@ -53,6 +53,7 @@
# web site, or submit a patch request.
-->
+<w><t>&</t></w>
<w><t>a</t></w>
<phrase><t>a cap-pel-la</t></phrase>
<phrase><t>a for-ti-o-ri</t></phrase>
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/LexerLatin1.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/LexerLatin1.java 2021-11-14 16:56:39 UTC (rev 12060)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/LexerLatin1.java 2021-11-14 19:46:18 UTC (rev 12061)
@@ -39,6 +39,7 @@
public CharType isWordChar(final char c) {
switch (c) {
case '-': return CharType.ALWAYS_WORD_CHAR;
+ case '&': return CharType.ALWAYS_WORD_CHAR;
default: return super.isWordChar(c);
}
}
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-14 16:56:39 UTC (rev 12060)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/Punctuation4a.java 2021-11-14 19:46:18 UTC (rev 12061)
@@ -39,8 +39,6 @@
import org.axsl.common.para.ParaPenalty;
import org.axsl.orthography.Punctuation;
-import org.slf4j.LoggerFactory;
-
import java.util.ArrayList;
import java.util.List;
@@ -108,8 +106,17 @@
public static final Punctuation4a CLOSE_SQUARE_BRACKET = new Punctuation4a("]");
/** Common punctuation item. */
+ public static final Punctuation4a FORWARD_SLASH = new Punctuation4a("/");
+
+ /** Common punctuation item. */
+ public static final Punctuation4a ELLIPSIS = new Punctuation4a("\u2026");
+
+ /** Common punctuation item. */
public static final Punctuation4a ZERO_WIDTH_SPACE = new Punctuation4a("\u200B");
+ /** Common punctuation item. */
+ public static final Punctuation4a ZERO_WIDTH_NO_BREAK_SPACE = new Punctuation4a("\uFEFF");
+
/** The list of common interword items. */
private static final List<Punctuation4a> COMMON_PUNCTUATION = new ArrayList<Punctuation4a>(25);
static {
@@ -133,7 +140,10 @@
COMMON_PUNCTUATION.add(CLOSE_PAREN);
COMMON_PUNCTUATION.add(OPEN_SQUARE_BRACKET);
COMMON_PUNCTUATION.add(CLOSE_SQUARE_BRACKET);
+ COMMON_PUNCTUATION.add(FORWARD_SLASH);
+ COMMON_PUNCTUATION.add(ELLIPSIS);
COMMON_PUNCTUATION.add(ZERO_WIDTH_SPACE);
+ COMMON_PUNCTUATION.add(ZERO_WIDTH_NO_BREAK_SPACE);
}
@@ -153,7 +163,7 @@
* Using this method instead of a constructor allows this class to reduce unnecessary object creation be reusing
* existing instances of this class instead of creating identical ones.
* @param content The content of the interword item.
- * @return An instance of this class wrapping the given content.
+ * @return An instance of this class wrapping the given content, or null if no instance is found.
*/
public static Punctuation4a findInstance(final CharSequence content) {
for (int index = 0; index < COMMON_PUNCTUATION.size(); index ++) {
@@ -162,8 +172,7 @@
return punctuation;
}
}
- LoggerFactory.getLogger(Punctuation4a.class).warn("Standard punctuation not found: [" + content + "]");
- return new Punctuation4a(content);
+ return null;
}
@Override
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-11-14 16:56:41
|
Revision: 12060
http://sourceforge.net/p/foray/code/12060
Author: victormote
Date: 2021-11-14 16:56:39 +0000 (Sun, 14 Nov 2021)
Log Message:
-----------
1. Conform to aXSL change: Add method to ParaBranch that returns the count of its descendant leaf nodes. 2. Add assertion for this count in TotalFitLbTests.
Modified Paths:
--------------
trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaBranch4a.java
trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/TotalFitLbTests.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-14 15:04:23 UTC (rev 12059)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaBranch4a.java 2021-11-14 16:56:39 UTC (rev 12060)
@@ -81,6 +81,22 @@
}
@Override
+ public int getQtyParaLeafDescendants() {
+ int returnValue = 0;
+ for (int index = 0; index < getQtyParaNodeChildren(); index ++) {
+ final ParaBranch childBranch = getParaNodeChild(index).asParaBranch();
+ if (childBranch == null) {
+ /* Child node is a leaf. */
+ returnValue ++;
+ } else {
+ /* Child node is a branch. */
+ returnValue += childBranch.getQtyParaLeafDescendants();
+ }
+ }
+ return returnValue;
+ }
+
+ @Override
public ParaConfig getParaConfig() {
return this.config;
}
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-14 15:04:23 UTC (rev 12059)
+++ trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/TotalFitLbTests.java 2021-11-14 16:56:39 UTC (rev 12060)
@@ -112,7 +112,7 @@
para.addNodeAndSpace(Punctuation4a.COMMA);
para.addWordAndSpace("was");
para.addWordAndSpace("aston-ished"); // 2 segments
- para.addWordAndSpace("when-ever");
+ para.addWordAndSpace("when-ever"); // 2 segments
para.addWordAndSpace("it");
para.addWordAndSpace("shone");
para.addWordAndSpace("in");
@@ -218,8 +218,12 @@
* ----- -----
* totals 126 238
* ===== ===== */
+ Assert.assertEquals(238, para.getQtyParaNodeChildren());
- 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;
}
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-14 15:04:23 UTC (rev 12059)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/SegmentDictionaryWord.java 2021-11-14 16:56:39 UTC (rev 12060)
@@ -107,4 +107,9 @@
return PosUtils.isOfQualifiedType(this.partsOfSpeech, pos, qualifier);
}
+ @Override
+ public int getQtyParaLeafDescendants() {
+ 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-14 15:04:23 UTC (rev 12059)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/StringWord.java 2021-11-14 16:56:39 UTC (rev 12060)
@@ -119,4 +119,9 @@
return this.partsOfSpeech;
}
+ @Override
+ public int getQtyParaLeafDescendants() {
+ return this.segments.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-14 15:04:23 UTC (rev 12059)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/CapitalizedWord.java 2021-11-14 16:56:39 UTC (rev 12060)
@@ -99,4 +99,10 @@
}
}
+ @Override
+ public int getQtyParaLeafDescendants() {
+ /* Capitalizing the word does not change the number of leaf descendants. */
+ return this.getWrappedWord().getQtyParaLeafDescendants();
+ }
+
}
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-14 15:04:23 UTC (rev 12059)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/ExactWord.java 2021-11-14 16:56:39 UTC (rev 12060)
@@ -82,4 +82,10 @@
return this.exact;
}
+ @Override
+ public int getQtyParaLeafDescendants() {
+ /* Changing the case of chars in the word does not change the number of leaf descendants. */
+ return this.getWrappedWord().getQtyParaLeafDescendants();
+ }
+
}
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-14 15:04:23 UTC (rev 12059)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/LatinPast1Word.java 2021-11-14 16:56:39 UTC (rev 12060)
@@ -57,4 +57,10 @@
return LatinPast1Word.SUFFIX;
}
+ @Override
+ public int getQtyParaLeafDescendants() {
+ /* This wrapper should add one leaf descendant to the size of the wrapped word. */
+ return this.getWrappedWord().getQtyParaLeafDescendants() + 1;
+ }
+
}
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-14 15:04:23 UTC (rev 12059)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/LatinPlural1Word.java 2021-11-14 16:56:39 UTC (rev 12060)
@@ -86,4 +86,10 @@
return new Segment(unmodifiedSegment);
}
+ @Override
+ public int getQtyParaLeafDescendants() {
+ /* We think this wrapper should not change the number of leaf descendants. */
+ return this.getWrappedWord().getQtyParaLeafDescendants();
+ }
+
}
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-14 15:04:23 UTC (rev 12059)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/LatinPlural2Word.java 2021-11-14 16:56:39 UTC (rev 12060)
@@ -89,4 +89,10 @@
return new Segment(unmodifiedSegment);
}
+ @Override
+ public int getQtyParaLeafDescendants() {
+ /* We think this wrapper should not change the number of leaf descendants. */
+ return this.getWrappedWord().getQtyParaLeafDescendants();
+ }
+
}
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-14 15:04:23 UTC (rev 12059)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/LatinPossessive1Word.java 2021-11-14 16:56:39 UTC (rev 12060)
@@ -87,4 +87,10 @@
return new Segment(unmodifiedSegment);
}
+ @Override
+ public int getQtyParaLeafDescendants() {
+ /* We think this wrapper should not change the number of leaf descendants. */
+ return this.getWrappedWord().getQtyParaLeafDescendants();
+ }
+
}
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-14 15:04:23 UTC (rev 12059)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/LatinPossessive2Word.java 2021-11-14 16:56:39 UTC (rev 12060)
@@ -87,4 +87,10 @@
return new Segment(unmodifiedSegment);
}
+ @Override
+ public int getQtyParaLeafDescendants() {
+ /* We think this wrapper should not change the number of leaf descendants. */
+ return this.getWrappedWord().getQtyParaLeafDescendants();
+ }
+
}
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-14 15:04:23 UTC (rev 12059)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/wrapper/UppercaseWord.java 2021-11-14 16:56:39 UTC (rev 12060)
@@ -90,4 +90,10 @@
return new Segment(segment);
}
+ @Override
+ public int getQtyParaLeafDescendants() {
+ /* Converting the word to uppercase does not change the number of leaf descendants. */
+ return this.getWrappedWord().getQtyParaLeafDescendants();
+ }
+
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-11-14 15:04:26
|
Revision: 12059
http://sourceforge.net/p/foray/code/12059
Author: victormote
Date: 2021-11-14 15:04:23 +0000 (Sun, 14 Nov 2021)
Log Message:
-----------
Push decision about whether punctuation or not over to Punctuation4a.
Modified Paths:
--------------
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/Orthography4a.java
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/Orthography4a.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/Orthography4a.java 2021-11-14 14:37:28 UTC (rev 12058)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/Orthography4a.java 2021-11-14 15:04:23 UTC (rev 12059)
@@ -31,7 +31,6 @@
import org.foray.common.para.ParaBranch4a;
import org.foray.common.primitive.BooleanUtils;
import org.foray.common.primitive.CharSequenceUtils;
-import org.foray.common.primitive.CharacterUtils;
import org.foray.common.primitive.NumberUtils;
import org.foray.orthography.wrapper.CapitalizedWord;
import org.foray.orthography.wrapper.ExactWord;
@@ -438,18 +437,17 @@
private void parseInterwordContent(final ParaBranch4a wordSequence, final CharSequence interword) {
int index = 0;
while (index < interword.length()) {
- if (CharacterUtils.isPunctuation(interword.charAt(index))) {
- final Punctuation4a punctuation = Punctuation4a.findInstance(interword.subSequence(index, index + 1));
+ final char contentChar = interword.charAt(index);
+ final Punctuation4a punctuation = Punctuation4a.findInstance(interword.subSequence(index, index + 1));
+ if (punctuation != null) {
wordSequence.add(punctuation);
index ++;
- } else if (Character.isWhitespace(interword.charAt(index))) {
+ } else if (Character.isWhitespace(contentChar)) {
final Whitespace4a whitespace = Whitespace4a.findInstance(interword.subSequence(index, index + 1));
wordSequence.add(whitespace);
index ++;
} else {
- final Interword4a unknown = Interword4a.findInstance(interword.subSequence(index, index + 1));
- wordSequence.add(unknown);
- index ++;
+ throw new IllegalStateException("Don't know how to handle interword content: " + contentChar);
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-11-14 14:37:30
|
Revision: 12058
http://sourceforge.net/p/foray/code/12058
Author: victormote
Date: 2021-11-14 14:37:28 +0000 (Sun, 14 Nov 2021)
Log Message:
-----------
1. Conform to aXSL change: Change the notion of interword content from a ParaBranch to ParaLeaf. 2. Remove no-longer-needed Whitespace4a class and related test class.
Modified Paths:
--------------
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/Punctuation4a.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/Whitespace4a.java
Removed Paths:
-------------
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/Interword4a.java
trunk/foray/foray-orthography/src/test/java/org/foray/orthography/Interword4aTests.java
Deleted: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/Interword4a.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/Interword4a.java 2021-11-13 20:37:22 UTC (rev 12057)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/Interword4a.java 2021-11-14 14:37:28 UTC (rev 12058)
@@ -1,325 +0,0 @@
-/*
- * Copyright 2017 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.para.ParaBoxChars;
-import org.foray.common.para.ParaGlueChars;
-import org.foray.common.primitive.CharSequenceUtils;
-import org.foray.common.primitive.CharacterUtils;
-import org.foray.common.primitive.StringUtils;
-
-import org.axsl.common.para.ParaBranch;
-import org.axsl.common.para.ParaConfig;
-import org.axsl.common.para.ParaLeaf;
-import org.axsl.common.para.ParaNode;
-import org.axsl.orthography.Interword;
-
-import org.slf4j.LoggerFactory;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * FOray implementation of {link Interword}.
- * Instances of this class are immutable.
- */
-public final class Interword4a implements Interword {
-
- /** The glue for an interword space. */
- private static final ParaGlueChars SPACE_GLUE = new ParaGlueChars(" ");
-
- /** Common interword item. */
- private static final Interword4a SPACE = new Interword4a(new ParaLeaf[] {
- SPACE_GLUE
- });
-
- /** Common interword item. */
- private static final Interword4a COMMA = new Interword4a(new ParaLeaf[] {
- new ParaBoxChars(",")
- });
-
- /** Common interword item. */
- private static final Interword4a COLON = new Interword4a(new ParaLeaf[] {
- new ParaBoxChars(":")
- });
-
- /** Common interword item. */
- private static final Interword4a SEMICOLON = new Interword4a(new ParaLeaf[] {
- new ParaBoxChars(";")
- });
-
- /** Common interword item. */
- private static final Interword4a PERIOD = new Interword4a(new ParaLeaf[] {
- new ParaBoxChars(".")
- });
-
- /** Common interword item. */
- private static final Interword4a QUESTION = new Interword4a(new ParaLeaf[] {
- new ParaBoxChars("?")
- });
-
- /** Common interword item. */
- private static final Interword4a EXCLAMATION = new Interword4a(new ParaLeaf[] {
- new ParaBoxChars("!")
- });
-
- /** Common interword item. */
- private static final Interword4a COMMA_AND_SPACE = new Interword4a(new ParaLeaf[] {
- new ParaBoxChars(","),
- SPACE_GLUE
- });
-
- /** Common interword item. */
- private static final Interword4a SEMICOLON_AND_SPACE = new Interword4a(new ParaLeaf[] {
- new ParaBoxChars(";"),
- SPACE_GLUE
- });
-
- /** Common interword item. */
- private static final Interword4a COLON_AND_SPACE = new Interword4a(new ParaLeaf[] {
- new ParaBoxChars(":"),
- SPACE_GLUE
- });
-
- /** Common interword item. */
- private static final Interword4a PERIOD_AND_SPACE = new Interword4a(new ParaLeaf[] {
- new ParaBoxChars("."),
- SPACE_GLUE
- });
-
- /** Common interword item. */
- private static final Interword4a QUESTION_AND_SPACE = new Interword4a(new ParaLeaf[] {
- new ParaBoxChars("?"),
- SPACE_GLUE
- });
-
- /** Common interword item. */
- private static final Interword4a EXCLAMATION_AND_SPACE = new Interword4a(new ParaLeaf[] {
- new ParaBoxChars("!"),
- SPACE_GLUE
- });
-
- /** Common interword item. */
- private static final Interword4a LINE_FEED = new Interword4a(new ParaLeaf[] {
- new ParaBoxChars("\n")
- });
-
- /** Common interword item. */
- private static final Interword4a CARRIAGE_RETURN_AND_LINE_FEED = new Interword4a(new ParaLeaf[] {
- new ParaBoxChars("\r\n")
- });
-
- /** Common interword item. */
- private static final Interword4a CARRIAGE_RETURN = new Interword4a(new ParaLeaf[] {
- new ParaBoxChars("\r")
- });
-
- /** Common interword item. TODO: This needs to be treated differently. */
- private static final Interword4a APOSTROPHE = new Interword4a(new ParaLeaf[] {
- new ParaBoxChars(StringUtils.EMPTY_STRING + CharacterUtils.SINGLE_CLOSE_QUOTATION_MARK)
- });
-
- /** Common interword item. */
- private static final Interword4a MANDATORY_HYPHEN = new Interword4a(new ParaLeaf[] {
- new ParaBoxChars("-")
- });
-
- /** Common interword item. */
- private static final Interword4a SPACE_AND_DOUBLE_QUOTE = new Interword4a(new ParaLeaf[] {
- new ParaBoxChars(" \"")
- });
-
- /** Common interword item. */
- private static final Interword4a DOUBLE_QUOTE_AND_SPACE = new Interword4a(new ParaLeaf[] {
- new ParaBoxChars("\" ")
- });
-
- /** Common interword item. */
- private static final Interword4a DOUBLE_QUOTE_COMMA_AND_SPACE = new Interword4a(new ParaLeaf[] {
- new ParaBoxChars("\", ")
- });
-
- /** Common interword item. */
- private static final Interword4a LF_TWO_SPACES = new Interword4a(new ParaLeaf[] {
- new ParaBoxChars("\n ")
- });
-
- /** Common interword item. */
- private static final Interword4a CR_TWO_SPACES = new Interword4a(new ParaLeaf[] {
- new ParaBoxChars("\r ")
- });
-
- /** Common interword item. */
- private static final Interword4a CR_LF_TWO_SPACES = new Interword4a(new ParaLeaf[] {
- new ParaBoxChars("\r\n ")
- });
-
- /** The list of common interword items. */
- private static final List<Interword4a> COMMON_INTERWORDS = new ArrayList<Interword4a>(20);
- static {
- COMMON_INTERWORDS.add(SPACE);
-
- COMMON_INTERWORDS.add(COMMA);
- COMMON_INTERWORDS.add(SEMICOLON);
- COMMON_INTERWORDS.add(COLON);
- COMMON_INTERWORDS.add(PERIOD);
- COMMON_INTERWORDS.add(QUESTION);
- COMMON_INTERWORDS.add(EXCLAMATION);
-
- COMMON_INTERWORDS.add(COMMA_AND_SPACE);
- COMMON_INTERWORDS.add(SEMICOLON_AND_SPACE);
- COMMON_INTERWORDS.add(COLON_AND_SPACE);
- COMMON_INTERWORDS.add(PERIOD_AND_SPACE);
- COMMON_INTERWORDS.add(QUESTION_AND_SPACE);
- COMMON_INTERWORDS.add(EXCLAMATION_AND_SPACE);
-
- COMMON_INTERWORDS.add(LINE_FEED);
- COMMON_INTERWORDS.add(CARRIAGE_RETURN_AND_LINE_FEED);
- COMMON_INTERWORDS.add(CARRIAGE_RETURN);
-
- COMMON_INTERWORDS.add(APOSTROPHE);
- COMMON_INTERWORDS.add(MANDATORY_HYPHEN);
- COMMON_INTERWORDS.add(SPACE_AND_DOUBLE_QUOTE);
- COMMON_INTERWORDS.add(DOUBLE_QUOTE_AND_SPACE);
- COMMON_INTERWORDS.add(DOUBLE_QUOTE_COMMA_AND_SPACE);
- COMMON_INTERWORDS.add(LF_TWO_SPACES);
- COMMON_INTERWORDS.add(CR_TWO_SPACES);
- COMMON_INTERWORDS.add(CR_LF_TWO_SPACES);
- }
-
- /** The list of discovered interword items. */
- private static final List<Interword4a> DISCOVERED_INTERWORDS = new ArrayList<Interword4a>(20);
-
- /** The content of this interword item. */
- private ParaLeaf[] content;
-
- /**
- * Private constructor. Use {@link #findInterword4a(CharSequence)} to obtain an instance of this class.
- * @param content The content of this interword item.
- */
- private Interword4a(final ParaLeaf[] content) {
- this.content = content;
- }
-
- /**
- * Finds or creates an Interword4a instance for given content.
- * Using this method instead of a constructor allows this class to reduce unnecessary object creation be reusing
- * existing instances of this class instead of creating identical ones.
- * @param content The content of the interword item.
- * @return An instance of this class wrapping the given content.
- */
- public static Interword4a findInstance(final CharSequence content) {
- for (int index = 0; index < COMMON_INTERWORDS.size(); index ++) {
- final Interword4a interword = COMMON_INTERWORDS.get(index);
- if (CharSequenceUtils.areEquivalent(interword, content)) {
- return interword;
- }
- }
- for (int index = 0; index < DISCOVERED_INTERWORDS.size(); index ++) {
- final Interword4a interword = DISCOVERED_INTERWORDS.get(index);
- if (CharSequenceUtils.areEquivalent(interword, content)) {
- return interword;
- }
- }
- LoggerFactory.getLogger(Interword4a.class).warn("Standard interword not found: [" + content + "]");
- final Interword4a newInterword = new Interword4a(new ParaLeaf[] {new ParaBoxChars(content)});
- DISCOVERED_INTERWORDS.add(newInterword);
- return newInterword;
- }
-
- @Override
- public CharSequence getContent() {
- /* Performance not considered here as it seems unlikely this will be used much. */
- final StringBuilder builder = new StringBuilder();
- for (int index = 0; index < this.content.length; index ++) {
- builder.append(this.content[index].getText());
- }
- /* Avoid the cost of converting to String. */
- return builder;
- }
-
- @Override
- public int length() {
- /* Performance not considered here as it seems unlikely this will be used much. */
- return getContent().length();
- }
-
- @Override
- public char charAt(final int index) {
- /* Performance not considered here as it seems unlikely this will be used much. */
- return getContent().charAt(index);
- }
-
- @Override
- /* Performance not considered here as it seems unlikely this will be used much. */
- public CharSequence subSequence(final int start, final int end) {
- return getContent().subSequence(start, end);
- }
-
- @Override
- public String toString() {
- return getContent().toString();
- }
-
- @Override
- public int getQtyParaNodeChildren() {
- return this.content.length;
- }
-
- @Override
- public ParaNode getParaNodeChild(final int index) {
- return this.content[index];
- }
-
- @Override
- public ParaConfig getParaConfig() {
- return null;
- }
-
- @Override
- public void setParaConfig(final ParaConfig config) {
- /* Nothing to do here. */
- }
-
- @Override
- public Type getParaNodeType() {
- return ParaNode.Type.BRANCH;
- }
-
- @Override
- public ParaLeaf asParaLeaf() {
- return null;
- }
-
- @Override
- public ParaBranch asParaBranch() {
- return this;
- }
-
-}
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-13 20:37:22 UTC (rev 12057)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/Punctuation4a.java 2021-11-14 14:37:28 UTC (rev 12058)
@@ -107,9 +107,11 @@
/** Common punctuation item. */
public static final Punctuation4a CLOSE_SQUARE_BRACKET = new Punctuation4a("]");
+ /** Common punctuation item. */
+ public static final Punctuation4a ZERO_WIDTH_SPACE = new Punctuation4a("\u200B");
/** The list of common interword items. */
- private static final List<Punctuation4a> COMMON_PUNCTUATION = new ArrayList<Punctuation4a>(20);
+ private static final List<Punctuation4a> COMMON_PUNCTUATION = new ArrayList<Punctuation4a>(25);
static {
COMMON_PUNCTUATION.add(COMMA);
@@ -131,6 +133,7 @@
COMMON_PUNCTUATION.add(CLOSE_PAREN);
COMMON_PUNCTUATION.add(OPEN_SQUARE_BRACKET);
COMMON_PUNCTUATION.add(CLOSE_SQUARE_BRACKET);
+ COMMON_PUNCTUATION.add(ZERO_WIDTH_SPACE);
}
@@ -219,26 +222,6 @@
}
@Override
- public int getQtyParaNodeChildren() {
- return 0;
- }
-
- @Override
- public ParaNode getParaNodeChild(final int index) {
- return null;
- }
-
- @Override
- public ParaConfig getParaConfig() {
- return null;
- }
-
- @Override
- public void setParaConfig(final ParaConfig config) {
- /* Nothing to do here. */
- }
-
- @Override
public int length() {
return this.content.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-13 20:37:22 UTC (rev 12057)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/Whitespace4a.java 2021-11-14 14:37:28 UTC (rev 12058)
@@ -35,7 +35,6 @@
import org.axsl.common.para.ParaConfig;
import org.axsl.common.para.ParaGlue;
import org.axsl.common.para.ParaLeaf;
-import org.axsl.common.para.ParaNode;
import org.axsl.common.para.ParaPenalty;
import org.axsl.orthography.Whitespace;
@@ -165,26 +164,6 @@
}
@Override
- public int getQtyParaNodeChildren() {
- return 0;
- }
-
- @Override
- public ParaNode getParaNodeChild(final int index) {
- return null;
- }
-
- @Override
- public ParaConfig getParaConfig() {
- return null;
- }
-
- @Override
- public void setParaConfig(final ParaConfig config) {
- /* Nothing to do here. */
- }
-
- @Override
public int length() {
return this.content.length();
}
Deleted: trunk/foray/foray-orthography/src/test/java/org/foray/orthography/Interword4aTests.java
===================================================================
--- trunk/foray/foray-orthography/src/test/java/org/foray/orthography/Interword4aTests.java 2021-11-13 20:37:22 UTC (rev 12057)
+++ trunk/foray/foray-orthography/src/test/java/org/foray/orthography/Interword4aTests.java 2021-11-14 14:37:28 UTC (rev 12058)
@@ -1,49 +0,0 @@
-/*
- * 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.orthography;
-
-import org.junit.Assert;
-import org.junit.Test;
-
-/**
- * Tests of {@link Interword4a}.
- */
-public class Interword4aTests {
-
-
- /**
- * Test of {@link Interword4a#findInstance(CharSequence)}.
- */
- @Test
- public void findInstanceTest() {
- final Interword4a instance = Interword4a.findInstance(" ");
- Assert.assertEquals(" ", instance.getContent().toString());
- }
-
-}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-11-13 20:37:24
|
Revision: 12057
http://sourceforge.net/p/foray/code/12057
Author: victormote
Date: 2021-11-13 20:37:22 +0000 (Sat, 13 Nov 2021)
Log Message:
-----------
Add codepoint range to class javadocs.
Modified Paths:
--------------
trunk/foray/foray-unicode/src/main/java/org/foray/unicode/UnicodeParser.java
Modified: trunk/foray/foray-unicode/src/main/java/org/foray/unicode/UnicodeParser.java
===================================================================
--- trunk/foray/foray-unicode/src/main/java/org/foray/unicode/UnicodeParser.java 2021-11-13 18:00:37 UTC (rev 12056)
+++ trunk/foray/foray-unicode/src/main/java/org/foray/unicode/UnicodeParser.java 2021-11-13 20:37:22 UTC (rev 12057)
@@ -43,6 +43,10 @@
/**
* Parser that reads the raw Unicode files that we care about and generates Java source code files.
+ * Since the Unicode source files are stored as data in this project, the following command-line example may be
+ * helpful:
+ * java -cp ... UnicodeParser ./src/main/data/Unicode_13_0/UCD_zip "c:/Users/Victor Mote/desktop" "General Punctuation"
+ *
*/
public class UnicodeParser {
@@ -120,7 +124,11 @@
writer.write(eol);
writer.write(" * Unicode(r) code points for the \"");
writer.write(block.getName());
- writer.write("\" block.");
+ writer.write("\" block (0x");
+ writer.write(Integer.toHexString(block.getStart()));
+ writer.write(" thru 0x");
+ writer.write(Integer.toHexString(block.getEnd()));
+ writer.write(").");
writer.write(eol);
writer.write(" * See package documentation for links to the Unicode(r) license and terms of use.");
writer.write(eol);
@@ -315,6 +323,8 @@
* <ol>
* <li>The directory containing the raw Unicode files.</li>
* <li>The directory into which the generated source code should be written.</li>
+ * <li>Comma-delimited list of the code blocks to be generated. These code blocks must match those listed in
+ * Blocks.txt in the Unicode distribution.
* </ol>
*/
public static void main(final String[] args) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-11-13 18:00:39
|
Revision: 12056
http://sourceforge.net/p/foray/code/12056
Author: victormote
Date: 2021-11-13 18:00:37 +0000 (Sat, 13 Nov 2021)
Log Message:
-----------
Add simple dictionary implementation, primarily for testing, but perhaps useful other places.
Added Paths:
-----------
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/SimpleDictionary.java
Added: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/SimpleDictionary.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/SimpleDictionary.java (rev 0)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/SimpleDictionary.java 2021-11-13 18:00:37 UTC (rev 12056)
@@ -0,0 +1,107 @@
+/*
+ * 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.axsl.orthography.Word;
+import org.axsl.orthography.Word.PartOfSpeech;
+import org.axsl.orthography.Word.PosQualifier;
+import org.axsl.orthography.optional.Dictionary;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.regex.Pattern;
+
+/**
+ * A simple dictionary implementation, possibly useful only for testing.
+ */
+public class SimpleDictionary implements Dictionary {
+
+ /** Constant needed for serialization. */
+ private static final long serialVersionUID = 1797657088308334420L;
+
+ /** Regex pattern used to break compound words into their components. */
+ private Pattern wordBreaker;
+
+ /** The map of words. */
+ private Map<String, Word> words = new HashMap<String, Word>();
+
+ public SimpleDictionary(final char softHyphenChar) {
+ this.wordBreaker = Pattern.compile(Character.toString(softHyphenChar));
+ }
+
+ /**
+ * Add a word to this dictionary.
+ * @param wordChars The characters in the word, e.g. "running", "apple", etc.
+ * @param word The word.
+ */
+ public void addWord(final CharSequence wordChars, final Word word) {
+ final String wordString = wordChars.toString();
+ if (this.words.containsKey(wordString)) {
+ throw new IllegalArgumentException("Word already exists in dictionary: " + wordString);
+ }
+ this.words.put(wordString, word);
+ }
+
+ /**
+ * Add a word to this dictionary.
+ * @param wordChars The characters in the word, including raw hyphenation points, e.g. "run-ning", "ap-ple", etc.
+ */
+ public void addWord(final CharSequence wordChars) {
+ final char partsOfSpeech = 0;
+ final String[] components = this.wordBreaker.split(wordChars);
+ final StringWord word = new StringWord(partsOfSpeech, components);
+ final String wordString = word.getActualContent().toString();
+ if (this.words.containsKey(wordString)) {
+ throw new IllegalArgumentException("Word already exists in dictionary: " + wordString);
+ }
+ this.words.put(wordString, word);
+ }
+
+ @Override
+ public int qtyAlternatives(final CharSequence wordChars) {
+ if (this.words.containsKey(wordChars.toString())) {
+ return 1;
+ }
+ return 0;
+ }
+
+ @Override
+ public Word getWord(final CharSequence wordChars, final int index) {
+ if (index != 0) {
+ throw new IndexOutOfBoundsException("Index must be zero.");
+ }
+ return this.words.get(wordChars.toString());
+ }
+
+ @Override
+ public boolean supportsQualifiedType(final PartOfSpeech arg0, final PosQualifier arg1) {
+ return false;
+ }
+
+}
Property changes on: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/SimpleDictionary.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-13 17:58:07
|
Revision: 12055
http://sourceforge.net/p/foray/code/12055
Author: victormote
Date: 2021-11-13 17:58:04 +0000 (Sat, 13 Nov 2021)
Log Message:
-----------
Simplify line-break testing by removing dependency on orthography tokenizing.
Modified Paths:
--------------
trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/TotalFitLbTests.java
Added Paths:
-----------
trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/ParaBranch4aTestFixture.java
Added: trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/ParaBranch4aTestFixture.java
===================================================================
--- trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/ParaBranch4aTestFixture.java (rev 0)
+++ trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/ParaBranch4aTestFixture.java 2021-11-13 17:58:04 UTC (rev 12055)
@@ -0,0 +1,83 @@
+/*
+ * 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.orthography.StringWord;
+import org.foray.orthography.Whitespace4a;
+
+import org.axsl.common.para.ParaConfig;
+import org.axsl.common.para.ParaNode;
+
+import java.util.regex.Pattern;
+
+/**
+ * Adds some methods that simplify and clarify some tests.
+ */
+public class ParaBranch4aTestFixture extends ParaBranch4a {
+
+ /** Regex pattern used to break compound words into their components. */
+ private Pattern wordBreaker;
+
+ /**
+ * Constructor.
+ * @param config The configuration information for this branch.
+ * @param softHyphenChar The character used to mark syllable breaks.
+ */
+ public ParaBranch4aTestFixture(final ParaConfig config, final char softHyphenChar) {
+ super(config);
+ this.wordBreaker = Pattern.compile(Character.toString(softHyphenChar));
+ }
+
+ /**
+ * Add a word and space to this dictionary.
+ * @param wordChars The characters in the word, including raw hyphenation points, e.g. "run-ning", "ap-ple", etc.
+ */
+ public void addWordAndSpace(final CharSequence wordChars) {
+ addWord(wordChars);
+ this.add(Whitespace4a.SPACE);
+ }
+
+ /**
+ * Add a word and space to this dictionary.
+ * @param wordChars The characters in the word, including raw hyphenation points, e.g. "run-ning", "ap-ple", etc.
+ */
+ public void addWord(final CharSequence wordChars) {
+ final char partsOfSpeech = 0;
+ final String[] components = this.wordBreaker.split(wordChars);
+ final StringWord word = new StringWord(partsOfSpeech, components);
+ this.add(word);
+ }
+
+ public void addNodeAndSpace(final ParaNode node) {
+ this.add(node);
+ this.add(Whitespace4a.SPACE);
+ }
+
+}
Property changes on: trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/ParaBranch4aTestFixture.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-13 17:50:31 UTC (rev 12054)
+++ trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/TotalFitLbTests.java 2021-11-13 17:58:04 UTC (rev 12055)
@@ -32,10 +32,7 @@
import org.foray.common.i18n.WritingSystem4a;
import org.foray.common.para.ParaBranch4a;
import org.foray.common.para.ParaConfig4a;
-import org.foray.orthography.Orthography4a;
-import org.foray.orthography.OrthographyServer4a;
-import org.foray.orthography.OrthographyServerConfig;
-import org.foray.orthography.StringWord;
+import org.foray.orthography.Punctuation4a;
import org.axsl.common.para.DiscretionaryHyphen;
import org.axsl.common.para.ParaConfig;
@@ -44,14 +41,11 @@
import org.axsl.font.FontUse;
import org.axsl.linebreak.LineBreakControl;
import org.axsl.linebreak.OutputLine;
-import org.axsl.orthography.OrthographyException;
import org.junit.Assert;
-import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
-import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@@ -66,32 +60,167 @@
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\u2019s castle lay a great " +
+ "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\u2019s child went out into the forest and sat down by the side of the cool fountain; and when she " +
+ "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.";
- /** The orthography server doing the basic parsing. */
- private OrthographyServer4a orthographyServer;
-
- /** The paragraph configuration to be used for these tests. */
- private ParaConfig paraConfig;
-
/**
- * Setup the test.
- * @throws IOException For errors creating the URLs to the various resources.
- * @throws OrthographyException For errors creating a hyphenation server.
+ * 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}.
*/
- @Before
- public void setup() throws IOException, OrthographyException {
- final OrthographyServerConfig config = LbTestUtilities.createHyphenationServerConfig();
- this.orthographyServer = new OrthographyServer4a(config);
+ 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");
+ 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);
- this.paraConfig = new ParaConfig4a(fontUse, 10, WritingSystem4a.USA, 0, 0);
+ final ParaConfig paraConfig = new ParaConfig4a(fontUse, 10, WritingSystem4a.USA, 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());
+ return para;
}
/**
@@ -100,24 +229,8 @@
@Test
public void bestFitTest1() {
/* TODO: THE CLASS BEING TESTED IS VERY INCOMPLETE, AND SO IS THIS TEST !!!!!! */
- final Orthography4a orthography = this.orthographyServer.getOrthography(WritingSystem4a.USA);
- final ParaBranch4a paragraph =
- orthography.tokenizeWordSequence(TEST_STRING_01, 0, TEST_STRING_01.length());
- paragraph.setParaConfig(paraConfig);
-
- /* Make manual changes to get the paragraph features identical to our baseline paragraph, as documented
- * in the Knuth-Plass article. These are all cases where the native hyphenation opportunies violate the
- * "leave at least 2, and push at least 3" general rule. */
- paragraph.setParaNodeChild(2, new StringWord(0, "olden")); // Native = old-en
- paragraph.setParaNodeChild(66, new StringWord(0, "aston", "ished")); // Native = as-ton-ish-ed
- paragraph.setParaNodeChild(68, new StringWord(0, "when", "ever")); // Native = when-ev-er
- paragraph.setParaNodeChild(88, new StringWord(0, "castle")); // Native = cas-tle
- paragraph.setParaNodeChild(134, new StringWord(0, "very")); // Native = ver-y
- paragraph.setParaNodeChild(148, new StringWord(0, "into")); // Native = in-to
- paragraph.setParaNodeChild(190, new StringWord(0, "golden")); // Native = gold-en
- paragraph.setParaNodeChild(222, new StringWord(0, "favor", "ite")); // Native = fa-vor-ite
-
+ 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. */
@@ -126,19 +239,12 @@
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(paragraph, paraControl, lbControl);
+ final List<OrderedTreePath4a> actual = out.breakIntoLines(content, paraControl, lbControl);
- /* For now, treat "’s" as interword content of an apostrophe, followed by a 1-syllable word. */
- /* Words: 98 1-syllable, 13 2-syllable, 2 3-syllable, total of 114 words
- * 98 x 2 = 196, 13 x 4 = 52, 2 x 6 = 12, subtotal of 260 nodes.
- * Special Interword: 11 normal, 2 "’s", 1 ="-", 1 terminating period (no space after).
- * 11 x 2 = 22, 2 x 3 = 6, 1 x 1 = 1, 1 x 1 = 1, subtotal of 30 nodes.
- * Grand total of 290 nodes. */
-// Assert.assertEquals(290, out.getContentNodes().size());
final List<OrderedTreePath4a> expected = new ArrayList<OrderedTreePath4a>();
-// final int[] expectedArray = {};
-// expected.add(new OrderedTreePath4a(new IntArray(expectedArray)));
+//// final int[] expectedArray = {};
+//// expected.add(new OrderedTreePath4a(new IntArray(expectedArray)));
Assert.assertArrayEquals(expected.toArray(), actual.toArray());
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-11-13 17:50:33
|
Revision: 12054
http://sourceforge.net/p/foray/code/12054
Author: victormote
Date: 2021-11-13 17:50:31 +0000 (Sat, 13 Nov 2021)
Log Message:
-----------
Make interword constants public.
Modified Paths:
--------------
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/Punctuation4a.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/Whitespace4a.java
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-13 13:41:48 UTC (rev 12053)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/Punctuation4a.java 2021-11-13 17:50:31 UTC (rev 12054)
@@ -51,61 +51,61 @@
public final class Punctuation4a implements Punctuation, ParaLeaf, ParaBox {
/** Common punctuation item, a comma. */
- private static final Punctuation4a COMMA = new Punctuation4a(",");
+ public static final Punctuation4a COMMA = new Punctuation4a(",");
/** Common punctuation item, semicolon. */
- private static final Punctuation4a SEMICOLON = new Punctuation4a(";");
+ public static final Punctuation4a SEMICOLON = new Punctuation4a(";");
/** Common punctuation item, a colon. */
- private static final Punctuation4a COLON = new Punctuation4a(":");
+ public static final Punctuation4a COLON = new Punctuation4a(":");
/** Common punctuation item, period. */
- private static final Punctuation4a PERIOD = new Punctuation4a(".");
+ public static final Punctuation4a PERIOD = new Punctuation4a(".");
/** Common punctuation item, a question mark. */
- private static final Punctuation4a QUESTION = new Punctuation4a("?");
+ public static final Punctuation4a QUESTION = new Punctuation4a("?");
/** Common punctuation item, an exclamation point. */
- private static final Punctuation4a EXCLAMATION = new Punctuation4a("!");
+ public static final Punctuation4a EXCLAMATION = new Punctuation4a("!");
/** Common punctuation item, a closing single quote or apostrophe. TODO: This needs to be treated differently. */
- private static final Punctuation4a SINGLE_QUOTE = new Punctuation4a("\'");
+ public static final Punctuation4a SINGLE_QUOTE = new Punctuation4a("\'");
/** Common punctuation item, a closing single quote or apostrophe. TODO: This needs to be treated differently. */
- private static final Punctuation4a DOUBLE_QUOTE = new Punctuation4a("\"");
+ public static final Punctuation4a DOUBLE_QUOTE = new Punctuation4a("\"");
/** Common punctuation item, an opening typographical single quote or apostrophe. */
- private static final Punctuation4a OPEN_TYPO_SINGLE_QUOTE = new Punctuation4a("\u2018");
+ public static final Punctuation4a OPEN_TYPO_SINGLE_QUOTE = new Punctuation4a("\u2018");
/** Common punctuation item, a closing typographical single quote. */
- private static final Punctuation4a CLOSE_TYPO_SINGLE_QUOTE = new Punctuation4a("\u2019");
+ public static final Punctuation4a CLOSE_TYPO_SINGLE_QUOTE = new Punctuation4a("\u2019");
/** Common punctuation item, an opening typographical double quote. */
- private static final Punctuation4a OPEN_TYPO_DOUBLE_QUOTE = new Punctuation4a("\u201C");
+ public static final Punctuation4a OPEN_TYPO_DOUBLE_QUOTE = new Punctuation4a("\u201C");
/** Common punctuation item, a closing typographical double quote. */
- private static final Punctuation4a CLOSE_TYPO_DOUBLE_QUOTE = new Punctuation4a("\u201D");
+ public static final Punctuation4a CLOSE_TYPO_DOUBLE_QUOTE = new Punctuation4a("\u201D");
/** Common punctuation item. */
- private static final Punctuation4a MANDATORY_HYPHEN = new Punctuation4a("-");
+ public static final Punctuation4a MANDATORY_HYPHEN = new Punctuation4a("-");
/** Common punctuation item. */
- private static final Punctuation4a EN_DASH = new Punctuation4a("\u2013");
+ public static final Punctuation4a EN_DASH = new Punctuation4a("\u2013");
/** Common punctuation item. */
- private static final Punctuation4a EM_DASH = new Punctuation4a("\u2014");
+ public static final Punctuation4a EM_DASH = new Punctuation4a("\u2014");
/** Common punctuation item. */
- private static final Punctuation4a OPEN_PAREN = new Punctuation4a("(");
+ public static final Punctuation4a OPEN_PAREN = new Punctuation4a("(");
/** Common punctuation item. */
- private static final Punctuation4a CLOSE_PAREN = new Punctuation4a(")");
+ public static final Punctuation4a CLOSE_PAREN = new Punctuation4a(")");
/** Common punctuation item. */
- private static final Punctuation4a OPEN_SQUARE_BRACKET = new Punctuation4a("[");
+ public static final Punctuation4a OPEN_SQUARE_BRACKET = new Punctuation4a("[");
/** Common punctuation item. */
- private static final Punctuation4a CLOSE_SQUARE_BRACKET = new Punctuation4a("]");
+ public static final Punctuation4a CLOSE_SQUARE_BRACKET = new Punctuation4a("]");
/** The list of common interword items. */
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-13 13:41:48 UTC (rev 12053)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/Whitespace4a.java 2021-11-13 17:50:31 UTC (rev 12054)
@@ -51,19 +51,19 @@
public final class Whitespace4a implements Whitespace, ParaLeaf, ParaGlue {
/** Common whitespace item. */
- private static final Whitespace4a SPACE = new Whitespace4a(" ");
+ public static final Whitespace4a SPACE = new Whitespace4a(" ");
/** Common whitespace item. */
- private static final Whitespace4a LINE_FEED = new Whitespace4a("\n");
+ public static final Whitespace4a LINE_FEED = new Whitespace4a("\n");
/** Common whitespace item. */
- private static final Whitespace4a CARRIAGE_RETURN_AND_LINE_FEED = new Whitespace4a("\r\n");
+ public static final Whitespace4a CARRIAGE_RETURN_AND_LINE_FEED = new Whitespace4a("\r\n");
/** Common whitespace item. */
- private static final Whitespace4a CARRIAGE_RETURN = new Whitespace4a("\r");
+ public static final Whitespace4a CARRIAGE_RETURN = new Whitespace4a("\r");
/** Common whitespace item. */
- private static final Whitespace4a TAB = new Whitespace4a("\t");
+ public static final Whitespace4a TAB = new Whitespace4a("\t");
/** The list of common whitespace items. */
private static final List<Whitespace4a> COMMON_WHITESPACE = new ArrayList<Whitespace4a>(20);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-11-13 13:41:51
|
Revision: 12053
http://sourceforge.net/p/foray/code/12053
Author: victormote
Date: 2021-11-13 13:41:48 +0000 (Sat, 13 Nov 2021)
Log Message:
-----------
Conform to aXSL changes: Move management of the paragraph config, a layout issue, out of Orthography.
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/test/java/org/foray/linebreak/TotalFitLbTests.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/Interword4a.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/Orthography4a.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/Punctuation4a.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/Whitespace4a.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/Word4a.java
trunk/foray/foray-orthography/src/test/java/org/foray/orthography/HyphenationConsumer4aTests.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-13 12:37:41 UTC (rev 12052)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaBranch4a.java 2021-11-13 13:41:48 UTC (rev 12053)
@@ -108,4 +108,9 @@
this.nodes.set(index, newNode);
}
+ @Override
+ public void setParaConfig(final ParaConfig config) {
+ this.config = config;
+ }
+
}
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-13 12:37:41 UTC (rev 12052)
+++ trunk/foray/foray-fotree/src/main/java/org/foray/fotree/fo/obj/FoWordSequence.java 2021-11-13 13:41:48 UTC (rev 12053)
@@ -59,11 +59,12 @@
public FoWordSequence(final FoObj parent, final CharSequence content) {
super(parent);
final OrthographyServer orthographyServer = getOrthographyServer();
+ final Orthography orthography = orthographyServer.getOrthography(getWritingSystem());
+ final ParaBranch wordSequence =
+ orthography.tokenizeWordSequence(content, 0, content.length());
final ParaConfig4a config = new ParaConfig4a(getPrimaryFont(null), inlineFontSize(), inlineWritingSystem(),
parent.traitWordSpacingMax(null), parent.traitWordSpacingMin(null));
- final Orthography orthography = orthographyServer.getOrthography(getWritingSystem());
- final ParaBranch wordSequence =
- orthography.parseWordSequence(content, 0, content.length(), config);
+ wordSequence.setParaConfig(config);
this.content = new ArrayList<FoWordSequenceContent>(wordSequence.getQtyParaNodeChildren());
for (int index = 0; index < wordSequence.getQtyParaNodeChildren(); index ++) {
final ParaNode wordSequenceContent = wordSequence.getParaNodeChild(index);
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-13 12:37:41 UTC (rev 12052)
+++ trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/TotalFitLbTests.java 2021-11-13 13:41:48 UTC (rev 12053)
@@ -60,7 +60,9 @@
*/
public class TotalFitLbTests {
- /** A string used for testing line-breaking. */
+ /** 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 " +
@@ -101,7 +103,8 @@
final Orthography4a orthography = this.orthographyServer.getOrthography(WritingSystem4a.USA);
final ParaBranch4a paragraph =
- orthography.parseWordSequence(TEST_STRING_01, 0, TEST_STRING_01.length(), paraConfig);
+ orthography.tokenizeWordSequence(TEST_STRING_01, 0, TEST_STRING_01.length());
+ paragraph.setParaConfig(paraConfig);
/* Make manual changes to get the paragraph features identical to our baseline paragraph, as documented
* in the Knuth-Plass article. These are all cases where the native hyphenation opportunies violate the
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/Interword4a.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/Interword4a.java 2021-11-13 12:37:41 UTC (rev 12052)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/Interword4a.java 2021-11-13 13:41:48 UTC (rev 12053)
@@ -303,6 +303,11 @@
}
@Override
+ public void setParaConfig(final ParaConfig config) {
+ /* Nothing to do here. */
+ }
+
+ @Override
public Type getParaNodeType() {
return ParaNode.Type.BRANCH;
}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/Orthography4a.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/Orthography4a.java 2021-11-13 12:37:41 UTC (rev 12052)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/Orthography4a.java 2021-11-13 13:41:48 UTC (rev 12053)
@@ -37,7 +37,6 @@
import org.foray.orthography.wrapper.ExactWord;
import org.foray.orthography.wrapper.UppercaseWord;
-import org.axsl.common.para.ParaConfig;
import org.axsl.orthography.Orthography;
import org.axsl.orthography.Word;
import org.axsl.orthography.optional.Dictionary;
@@ -407,9 +406,8 @@
}
@Override
- public ParaBranch4a parseWordSequence(final CharSequence characters, final int startIndex, final int length,
- final ParaConfig paraConfig) {
- final ParaBranch4a wordSequence = new ParaBranch4a(paraConfig);
+ public ParaBranch4a tokenizeWordSequence(final CharSequence characters, final int startIndex, final int length) {
+ final ParaBranch4a wordSequence = new ParaBranch4a(null);
final CharSequence sequence = characters.subSequence(startIndex, startIndex + length);
final List<CharSequence> chunks = this.lexer.tokenize(sequence);
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-13 12:37:41 UTC (rev 12052)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/Punctuation4a.java 2021-11-13 13:41:48 UTC (rev 12053)
@@ -234,6 +234,11 @@
}
@Override
+ public void setParaConfig(final ParaConfig config) {
+ /* Nothing to do here. */
+ }
+
+ @Override
public int length() {
return this.content.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-13 12:37:41 UTC (rev 12052)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/Whitespace4a.java 2021-11-13 13:41:48 UTC (rev 12053)
@@ -180,6 +180,11 @@
}
@Override
+ public void setParaConfig(final ParaConfig config) {
+ /* Nothing to do here. */
+ }
+
+ @Override
public int length() {
return this.content.length();
}
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-13 12:37:41 UTC (rev 12052)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/Word4a.java 2021-11-13 13:41:48 UTC (rev 12053)
@@ -221,6 +221,11 @@
return null;
}
+ @Override
+ public void setParaConfig(final ParaConfig config) {
+ /* Nothing to do here. */
+ }
+
/**
* Returns the index (from a {@link CharSequence} standpoint) to the first character of a given segment.
* For example, for the word phi-los-o-phy, getSegmentStart(1) should return the index to the second segment
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-13 12:37:41 UTC (rev 12052)
+++ trunk/foray/foray-orthography/src/test/java/org/foray/orthography/HyphenationConsumer4aTests.java 2021-11-13 13:41:48 UTC (rev 12053)
@@ -30,7 +30,6 @@
import org.foray.common.i18n.WritingSystem4a;
import org.foray.common.para.ParaBranch4a;
-import org.foray.common.para.ParaConfig4a;
import org.axsl.common.para.ParaConfig;
import org.axsl.orthography.OrthographyException;
@@ -51,9 +50,6 @@
/** The hyphenation server used in these tests. */
private static OrthographyServer4a server;
- /** The paragraph configuration that should be used in these tests. */
- private static ParaConfig paraConfig = new ParaConfig4a(null, 0, WritingSystem4a.USA, 0, 0);
-
/** The object under test. */
private Orthography4a consumer;
@@ -86,7 +82,7 @@
/* Spoken by Henry, Henry V, Act III Scene 1. */
final String testString = "Once more unto the breach, dear friends, once more;";
final ParaBranch4a wordSequence =
- this.consumer.parseWordSequence(testString, 0, testString.length(), paraConfig);
+ 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());
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-11-13 12:37:44
|
Revision: 12052
http://sourceforge.net/p/foray/code/12052
Author: victormote
Date: 2021-11-13 12:37:41 +0000 (Sat, 13 Nov 2021)
Log Message:
-----------
Conform to aXSL change: Remove writing system info from ParaConfig. Writing system and orthography issues have all been resolved prior to paragraph layout.
Modified Paths:
--------------
trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaConfig4a.java
trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoObj.java
trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/TotalFitLbTests.java
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaConfig4a.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaConfig4a.java 2021-11-12 18:37:54 UTC (rev 12051)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaConfig4a.java 2021-11-13 12:37:41 UTC (rev 12052)
@@ -95,11 +95,6 @@
}
@Override
- public WritingSystem getWritingSystem() {
- return this.orthography;
- }
-
- @Override
public int getHyphenCharacterWidth() {
return this.fontUse.width(this.hyphenationCharacter, this.fontSize);
}
Modified: trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoObj.java
===================================================================
--- trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoObj.java 2021-11-12 18:37:54 UTC (rev 12051)
+++ trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoObj.java 2021-11-13 12:37:41 UTC (rev 12052)
@@ -3919,7 +3919,10 @@
return fontUse.width(hyphenationCodePoint, traitFontSize(null));
}
- @Override
+ /**
+ * Returns the writing system for this FO.
+ * @return The writing system for this FO.
+ */
public WritingSystem getWritingSystem() {
final Language4a language = this.traitLanguage(null);
final Country4a country = this.traitCountry(null);
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-12 18:37:54 UTC (rev 12051)
+++ trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/TotalFitLbTests.java 2021-11-13 12:37:41 UTC (rev 12052)
@@ -98,7 +98,7 @@
@Test
public void bestFitTest1() {
/* TODO: THE CLASS BEING TESTED IS VERY INCOMPLETE, AND SO IS THIS TEST !!!!!! */
- final Orthography4a orthography = this.orthographyServer.getOrthography(this.paraConfig.getWritingSystem());
+ final Orthography4a orthography = this.orthographyServer.getOrthography(WritingSystem4a.USA);
final ParaBranch4a paragraph =
orthography.parseWordSequence(TEST_STRING_01, 0, TEST_STRING_01.length(), paraConfig);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|