Revision: 7555
Author: victormote
Date: 2006-06-12 21:22:14 -0700 (Mon, 12 Jun 2006)
ViewCVS: http://svn.sourceforge.net/foray/?rev=7555&view=rev
Log Message:
-----------
1. Push RetrieveMarker instance through the line-breaking system.
2. Conform to axsl changes regarding the same.
Modified Paths:
--------------
trunk/foray/foray-text/src/java/org/foray/text/line/EagerLineBreaker.java
trunk/foray/foray-text/src/java/org/foray/text/line/LineBreaker.java
trunk/foray/foray-text/src/java/org/foray/text/line/solitary/SolitaryLineBreaker.java
Modified: trunk/foray/foray-text/src/java/org/foray/text/line/EagerLineBreaker.java
===================================================================
--- trunk/foray/foray-text/src/java/org/foray/text/line/EagerLineBreaker.java 2006-06-13 04:21:50 UTC (rev 7554)
+++ trunk/foray/foray-text/src/java/org/foray/text/line/EagerLineBreaker.java 2006-06-13 04:22:14 UTC (rev 7555)
@@ -52,21 +52,11 @@
super(server, control, handler, fontConsumer);
}
- protected int findLineBreaks() throws TextException {
- int status = 0;
- for (int i = 0; i < content.size(); i++) {
- this.currentLineContent = (LineContent) content.get(i);
- int end = content.size() - 1;
- status = processInput(this.currentLineContent, status, end);
- }
- return status;
- }
-
/**
* @throws TextException
*/
- protected int processInput(LineContent lineContent, int start, int end)
- throws TextException {
+ protected int processInput(LineContent lineContent, int start, int end,
+ Object context) throws TextException {
int status = 0;
if (lineContent instanceof LineText) {
LineText lineText = (LineText) lineContent;
@@ -90,7 +80,8 @@
}
if (shouldSwitch) {
// Process this chunk.
- status = processLineText(lineText, subsetStart, i - 1);
+ status = processLineText(lineText, subsetStart, i - 1,
+ context);
// If it can't process the whole chunk, we need to exit.
if (status != i) {
return status;
@@ -99,11 +90,11 @@
}
inLowerCase = isLowerCase(c);
}
- return processLineText(lineText, subsetStart, end);
+ return processLineText(lineText, subsetStart, end, context);
}
- status = processLineText(lineText, start, end);
+ status = processLineText(lineText, start, end, context);
} else if (lineContent instanceof LineNonText) {
- status = processLineNonText((LineNonText) lineContent);
+ status = processLineNonText((LineNonText) lineContent, context);
} else {
throw new TextException("Invalid LineContent.");
}
@@ -118,7 +109,7 @@
* if there is not enough room on the line for it.
* @throws TextException
*/
- protected int processLineNonText(LineNonText nonTextItem)
+ protected int processLineNonText(LineNonText nonTextItem, Object context)
throws TextException {
int lineLength = getCurrentLine().capacityTotal();
int itemSize = nonTextItem.inlineSizeOptimum(lineLength);
@@ -128,7 +119,7 @@
// There is nothing on the line. Therefore it won't fit any
// better on the next line. Put it on this one.
handler.handleLineBreakNonText(getCurrentLine(), nonTextItem,
- itemSize);
+ itemSize, context);
getLogger().error("Content too large for any line.");
return 1;
}
@@ -136,12 +127,13 @@
return 0;
}
// It fits on the line. Add it.
- handler.handleLineBreakNonText(getCurrentLine(), nonTextItem, itemSize);
+ handler.handleLineBreakNonText(getCurrentLine(), nonTextItem, itemSize,
+ context);
return 1;
}
protected abstract int processLineText(LineText lineText, int start,
- int end) throws TextException;
+ int end, Object context) throws TextException;
protected int currentLineWidthRemaining() throws TextException {
return getCurrentLine().capacityTotal()
@@ -149,9 +141,9 @@
}
public int addLineContent(LineContent content, int start, int end,
- LineOutput output) throws TextException {
+ LineOutput output, Object context) throws TextException {
this.currentOutput = output;
- return processInput(content, start, end);
+ return processInput(content, start, end, context);
}
protected LineOutput getCurrentLine() {
Modified: trunk/foray/foray-text/src/java/org/foray/text/line/LineBreaker.java
===================================================================
--- trunk/foray/foray-text/src/java/org/foray/text/line/LineBreaker.java 2006-06-13 04:21:50 UTC (rev 7554)
+++ trunk/foray/foray-text/src/java/org/foray/text/line/LineBreaker.java 2006-06-13 04:22:14 UTC (rev 7555)
@@ -41,33 +41,6 @@
import java.util.ArrayList;
-/**
- * LineBreaker subclasses provide line-breaking logic to clients.
- * <p>To use a LineBreaker, first get an instance from the appropriate
- * LineBreakServer. This is usually done through the
- * {@link TextServer#provideLineBreaker(LineBreakControl, LineBreakHandler,
- * FontConsumer)}
- * method, but could
- * conceivably be accomplished directly from the
- * {@link LineBreakServer#provideLineBreaker(LineBreakControl, LineBreakHandler,
- * FontConsumer)} method.</p>
- *
- * <p>After obtaining an instance, recursively access the addLineContent,
- * providing the instance with each item that should be included in the block
- * of content to be broken into lines. After this is complete, run
- * {@link #getResults()}, which performs the computations needed to
- * determine the line breaks and returns the results.</p>
- *
- * <p>Note that LineBreaker subclasses are not expected to normalize or
- * otherwise modify the text that is presented to them. For example, some
- * typesetting systems have provisions to normalize linefeed characters a
- * certain way, or to condense contiguous whitespace into one space.
- * Although a LineBreaker subclass could perform these services, it is not
- * part of the general contract. Also, LineBreaker subclasses do not provide
- * any special treatment for the tab character. If tab characters are presented
- * to it, it will treat them like any other character, which is likely not the
- * intent of the author.</p>
- */
public abstract class LineBreaker implements org.axsl.text.line.LineBreaker {
/** The "parent" LineBreakServer. */
@@ -146,7 +119,7 @@
* send all of their input to the text-processing system before processing
* actually starts.
* ("Eager" clients should use {@link #processLineContent(LineContent, int,
- * int, LineOutput)}.)
+ * int, LineOutput, Object)}.)
* @param contentItem The LineContent implementation that should be laid
* out.
*/
@@ -176,12 +149,12 @@
* successfully added to the line.
*/
public int processLineContent(LineContent contentItem, int start, int end,
- LineOutput output) throws TextException {
+ LineOutput output, Object context) throws TextException {
validateEagerContent(contentItem, output);
content.add(contentItem);
this.currentOutput = output;
this.currentLineContent = contentItem;
- return addLineContent(contentItem, start, end, output);
+ return addLineContent(contentItem, start, end, output, context);
}
/**
@@ -205,20 +178,9 @@
}
protected abstract int addLineContent(LineContent contentItem, int start,
- int end, LineOutput output) throws TextException;
+ int end, LineOutput output, Object context) throws TextException;
- public int getResults() throws TextException {
- return findLineBreaks();
- }
-
/**
- * The actual computation of the line-breaks. In this method, implementing
- * classes should compute line contents and then send them to a
- * {@link LineBreakHandler}.
- */
- protected abstract int findLineBreaks() throws TextException;
-
- /**
* {@inheritDoc}
*/
public int getCharWidth(LineText lineText, int codePoint) {
Modified: trunk/foray/foray-text/src/java/org/foray/text/line/solitary/SolitaryLineBreaker.java
===================================================================
--- trunk/foray/foray-text/src/java/org/foray/text/line/solitary/SolitaryLineBreaker.java 2006-06-13 04:21:50 UTC (rev 7554)
+++ trunk/foray/foray-text/src/java/org/foray/text/line/solitary/SolitaryLineBreaker.java 2006-06-13 04:22:14 UTC (rev 7555)
@@ -102,8 +102,8 @@
super(server, control, handler, fontConsumer);
}
- protected int processLineText(LineText lineText, int start, int end)
- throws TextException {
+ protected int processLineText(LineText lineText, int start, int end,
+ Object context) throws TextException {
this.currentLineText = lineText;
this.currentChars = currentLineText.inlineText();
String language = lineText.inlineLanguage();
@@ -141,7 +141,7 @@
charCount++;
}
if (forcesLineBreak(codePoint)) {
- createLineContent(start, i, finalWidth, false);
+ createLineContent(start, i, finalWidth, false, context);
return i + 1;
}
if (allowsLineBreak(codePoint)) {
@@ -170,7 +170,8 @@
finalWidth += spaceWidth;
finalWidth += wordWidth;
finalWidth += getHyphenWidth(lineText);
- createLineContent(start, ret - 1, finalWidth, true);
+ createLineContent(start, ret - 1, finalWidth, true,
+ context);
return ret;
}
}
@@ -180,26 +181,28 @@
finalWidth += spaceWidth;
finalWidth += wordWidth;
finalWidth -= charWidth;
- createLineContent(start, i - charCount, finalWidth, false);
+ createLineContent(start, i - charCount, finalWidth, false,
+ context);
/* Return the index at the start of this character*/
return i - charCount + 1;
}
// Break the line at the end of the previous word.
- createLineContent(start, wordStart - 1, finalWidth, false);
+ createLineContent(start, wordStart - 1, finalWidth, false,
+ context);
return wordStart;
}
/* We have now read through each character. */
/* If this ends with white space, place remaining contents on this
* line. */
if (previousCharacter == CONNECTOR) {
- return remainingContentOnThisLine(startIndex, endIndex);
+ return remainingContentOnThisLine(startIndex, endIndex, context);
}
/* Otherwise the word may continue into the next text. See if the
* entire word fits. */
if (finalWidth + spaceWidth + wordWidth
+ sizeFirstWordNextText(lineText, startIndex, endIndex)
<= currentLineWidthRemaining()) {
- return remainingContentOnThisLine(startIndex, endIndex);
+ return remainingContentOnThisLine(startIndex, endIndex, context);
}
/* TODO: If the entire words doesn't fit, see if it can be
@@ -207,7 +210,7 @@
/* If nothing else works, the content doesn't fit on this line.
* Break the line at the end of the previous word. */
- createLineContent(start, wordStart - 1, finalWidth, false);
+ createLineContent(start, wordStart - 1, finalWidth, false, context);
return wordStart;
}
@@ -218,11 +221,11 @@
* it is one past endIndex, indicating that all has been laid out.
* @throws TextException
*/
- private int remainingContentOnThisLine(int startIndex, int endIndex)
- throws TextException {
+ private int remainingContentOnThisLine(int startIndex, int endIndex,
+ Object context) throws TextException {
finalWidth += spaceWidth;
finalWidth += wordWidth;
- createLineContent(startIndex, endIndex, finalWidth, false);
+ createLineContent(startIndex, endIndex, finalWidth, false, context);
return endIndex + 1;
}
@@ -322,7 +325,7 @@
* @param sizeInline The size, in millipoints, of the content being created.
*/
private void createLineContent(int startIndex, int endIndex, int sizeInline,
- boolean isHyphenated) throws TextException {
+ boolean isHyphenated, Object context) throws TextException {
LineText lineText = (LineText) this.currentLineContent;
boolean everythingWritten = endIndex >= lineText.inlineText().length;
boolean isLastItemOnLine = true;
@@ -335,7 +338,7 @@
}
handler.handleLineBreakText(this.currentOutput, lineText, startIndex,
endIndex - startIndex + 1, sizeInline, isHyphenated,
- inLowerCase, isLastItemOnLine);
+ inLowerCase, isLastItemOnLine, context);
}
/**
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|