Package org.daisy.dotify.common.text
Class BreakPointHandler
- java.lang.Object
-
- org.daisy.dotify.common.text.BreakPointHandler
-
public class BreakPointHandler extends Object
Breaks a paragraph of text into rows. It is assumed that all preferred break points are supplied with the input string.Soft hyphen (0x00ad) and zero width space (0x200b) characters can also be used for non-standard hyphenation.
Soft hyphen (0x00ad), zero width space (0x200b), dash (0x002d) and space are used to determine an appropriate break point. Soft hyphens are removed in the result.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
BreakPointHandler.Builder
Provides a builder for break point handlers.
-
Constructor Summary
Constructors Constructor Description BreakPointHandler(String str)
Create a new BreakPointHandler.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description BreakPointHandler
copy()
Creates a new copy of this object in its current state.int
countRemaining()
Counts the remaining characters, excluding unused breakpoints.String
getRemaining()
Gets the remaining characters, removing unused breakpoint characters.boolean
hasNext()
Does this BreakPointHandler has any text left to break into rows.void
mark()
Marks the current state for later use withreset()
.BreakPoint
nextRow(int breakPoint, boolean force)
Gets the next row from this BreakPointHandler.BreakPoint
nextRow(int breakPoint, boolean force, boolean ignoreHyphens)
Gets the next row from this BreakPointHandler.void
reset()
Resets the state to the last call tomark()
, or the initial state, if no call to mark has been made.
-
-
-
Constructor Detail
-
BreakPointHandler
public BreakPointHandler(String str)
Create a new BreakPointHandler. All preferred break points must be in supplied with the input String, represented by hyphen 0x2d, soft hyphen 0xad or space 0x20.- Parameters:
str
- the paragraph to break into rows.
-
-
Method Detail
-
copy
public BreakPointHandler copy()
Creates a new copy of this object in its current state.- Returns:
- returns a new instance
-
mark
public void mark()
Marks the current state for later use withreset()
.
-
reset
public void reset()
Resets the state to the last call tomark()
, or the initial state, if no call to mark has been made.
-
nextRow
public BreakPoint nextRow(int breakPoint, boolean force)
Gets the next row from this BreakPointHandler.- Parameters:
breakPoint
- the desired breakpoint for this rowforce
- if force is allowed if no breakpoint is found- Returns:
- returns the next BreakPoint
-
nextRow
public BreakPoint nextRow(int breakPoint, boolean force, boolean ignoreHyphens)
Gets the next row from this BreakPointHandler.- Parameters:
breakPoint
- the desired breakpoint for this rowforce
- if force is allowed if no breakpoint is foundignoreHyphens
- ignore hyphenation points inside words- Returns:
- returns the next break point
-
countRemaining
public int countRemaining()
Counts the remaining characters, excluding unused breakpoints.- Returns:
- returns the number of remaining characters
-
getRemaining
public String getRemaining()
Gets the remaining characters, removing unused breakpoint characters.- Returns:
- returns the remaining characters
-
hasNext
public boolean hasNext()
Does this BreakPointHandler has any text left to break into rows.- Returns:
- returns true if this BreakPointHandler has any text left to break into rows
-
-