Package com.io7m.jpita.core
Class JPJustifierBasic
java.lang.Object
com.io7m.jpita.core.JPJustifierBasic
- All Implemented Interfaces:
JPAlignerType
An basic aligner that fully justifies text. The algorithm used is a simple
greedy formatter that avoids the
O(n²) performance of a full dynamic
programming approach.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceA function that, when evaluated, yieldstrueiff a line with the given number of space and text characters should be justified. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final JPJustifierBasic.SpaceTextDecisionTypeAn instance of theJPJustifierBasic.SpaceTextDecisionTypethat always justifies lines.static final JPJustifierBasic.SpaceTextDecisionTypeAn instance of theJPJustifierBasic.SpaceTextDecisionTypethat avoids justifying lines if more than half of the line would be space. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd a word to the current layout.voidInsert a hard line break.static JPAlignerTypecreate(JPOverflowBehaviour in_overflow, JPJustifierBasic.SpaceTextDecisionType in_decider, int in_width) Construct a new justifier.finish()Finish the current layout, effectively resetting it to a blank canvas.
-
Field Details
-
JUSTIFY_UNDER_HALF
An instance of theJPJustifierBasic.SpaceTextDecisionTypethat avoids justifying lines if more than half of the line would be space. -
JUSTIFY_ALWAYS
An instance of theJPJustifierBasic.SpaceTextDecisionTypethat always justifies lines.
-
-
Method Details
-
create
public static JPAlignerType create(JPOverflowBehaviour in_overflow, JPJustifierBasic.SpaceTextDecisionType in_decider, int in_width) Construct a new justifier.- Parameters:
in_overflow- The behaviour for words that are of a greater length than the maximum width and therefore cannot fit even when placed on an otherwise blank linein_decider- A function that decides whether or not lines should be justifiedin_width- The maximum width in characters- Returns:
- A new justifier
-
addWord
Description copied from interface:JPAlignerTypeAdd a word to the current layout.- Specified by:
addWordin interfaceJPAlignerType- Parameters:
w- A word
-
breakLine
public void breakLine()Description copied from interface:JPAlignerTypeInsert a hard line break.- Specified by:
breakLinein interfaceJPAlignerType
-
finish
Description copied from interface:JPAlignerTypeFinish the current layout, effectively resetting it to a blank canvas.- Specified by:
finishin interfaceJPAlignerType- Returns:
- A list of formatted lines
-