Class PageSplitter
- java.lang.Object
-
- ch.sahits.game.openpatrician.javafx.control.PageSplitter
-
public class PageSplitter extends java.lang.Object
Utility class to help separate the spliting up of a text into lines and pages.- Author:
- Andi Hotz, (c) Sahits GmbH, 2013 Created on Aug 7, 2013
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
CENTERED_STYLE
private javafx.scene.text.Font
font
static java.lang.String
HEADING_STYLE
private double
initialHeigth
private double
lineSpacing
private double
pageHeigth
private double
pageWidth
static java.lang.String
PARAGRAPH_STYLE
private TextSizingUtility
sizing
private IWordSplitter
splitter
static java.lang.String[]
STYLES
-
Constructor Summary
Constructors Constructor Description PageSplitter(double pageHeigth, double pageWidth, double lineSpacing, double initialHeigth, javafx.scene.text.Font font)
Initialize the page splitter.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private boolean
isLineTooLong(double lineWidth)
(package private) void
overrideTextSizingUtility(TextSizingUtility sizing)
Override the sizing utility for test purposes.void
setWordSplitter(IWordSplitter splitter)
java.util.List<Page>
splitIntoPages(Text text)
Splitting up the text onto pages.private java.util.List<Page>
splitIntoPages(Text text, boolean eliminateWhiteSpaces)
Splitting up the text onto pages.private double
updatePageHeight(java.lang.String line, double currentPageHeight)
Compute the line height and add it to the page height.
-
-
-
Field Detail
-
CENTERED_STYLE
public static final java.lang.String CENTERED_STYLE
- See Also:
- Constant Field Values
-
PARAGRAPH_STYLE
public static final java.lang.String PARAGRAPH_STYLE
- See Also:
- Constant Field Values
-
HEADING_STYLE
public static final java.lang.String HEADING_STYLE
- See Also:
- Constant Field Values
-
STYLES
public static final java.lang.String[] STYLES
-
pageHeigth
private final double pageHeigth
-
pageWidth
private final double pageWidth
-
lineSpacing
private final double lineSpacing
-
initialHeigth
private final double initialHeigth
-
font
private final javafx.scene.text.Font font
-
sizing
private TextSizingUtility sizing
-
splitter
private IWordSplitter splitter
-
-
Constructor Detail
-
PageSplitter
public PageSplitter(double pageHeigth, double pageWidth, double lineSpacing, double initialHeigth, javafx.scene.text.Font font)
Initialize the page splitter.- Parameters:
pageHeigth
- height of a pagepageWidth
- width of a pagelineSpacing
- spacing between two linesinitialHeigth
- initial height of the pagefont
- to be used.
-
-
Method Detail
-
overrideTextSizingUtility
void overrideTextSizingUtility(TextSizingUtility sizing)
Override the sizing utility for test purposes.- Parameters:
sizing
- service to calculate line length based on fonts.
-
setWordSplitter
public void setWordSplitter(IWordSplitter splitter)
-
splitIntoPages
public java.util.List<Page> splitIntoPages(Text text)
Splitting up the text onto pages.- Parameters:
text
- to be split- Returns:
- list of Pages.
-
splitIntoPages
private java.util.List<Page> splitIntoPages(Text text, boolean eliminateWhiteSpaces)
Splitting up the text onto pages. Using the additional flag you can control the behavior on line setup. This becomes important on recursive calls, where a word was splitt and should be reassambled on a single line.- Parameters:
text
- to be spliteliminateWhiteSpaces
- flag indicating if the words on a line should be concatenated (remove spaces)- Returns:
- list of Pages.
-
isLineTooLong
private boolean isLineTooLong(double lineWidth)
-
updatePageHeight
private double updatePageHeight(java.lang.String line, double currentPageHeight)
Compute the line height and add it to the page height.- Parameters:
line
- to be checkedcurrentPageHeight
- current page height withoutline
- Returns:
- new page height
-
-