class Printer
extends java.lang.Object
Layouter
class, this
decides where to insert line breaks. It tries to break as few
blocks as possible.Modifier and Type | Field and Description |
---|---|
private Backend |
back
Back-end for the pretty-printed output
|
private static int |
BREAK_MASK
Mask for break type flags.
|
private static int |
CONSISTENT
Flag to indicate this block will be broken consistently
|
private static int |
FITS
Flag to indicate this block fits into the current line
|
private static int |
INCONSISTENT
Flag to indicate this block will be broken inconsistently
|
private int |
lineWidth
total line length available
|
private java.util.ArrayList<java.lang.Integer> |
marginStack
stack to remember value of
pos in nested blocks |
private int |
pos
position in current line.
|
private static java.lang.String |
spaces
a String containing
SPACES spaces |
private static int |
SPACES
how many spaces
|
Constructor and Description |
---|
Printer(Backend back)
Create a printer.
|
Modifier and Type | Method and Description |
---|---|
(package private) void |
close()
Close the output stream.
|
(package private) void |
closeBlock()
end a block
|
(package private) void |
flush()
Flush the output stream.
|
(package private) void |
indent(int width,
int offset) |
(package private) int |
lineWidth()
Return the line width of this Printer.
|
(package private) void |
mark(java.lang.Object o) |
private void |
newLine()
Start a new line and indent according to
pos |
(package private) void |
openBlock(boolean consistent,
int indent,
int followingLength)
begin a block
|
private void |
pop()
Pop one element from the space stack.
|
(package private) void |
print(java.lang.String s)
write the String
s to out |
(package private) void |
printBreak(int width,
int offset,
int followingLength)
write a break.
|
private void |
push(int n,
int breaks) |
(package private) int |
space()
Return the amount of space currently left on this line.
|
private int |
top()
return the topmost element of the space stack without popping it.
|
private int |
topBreak() |
private int |
topMargin() |
private void |
writeSpaces(int n) |
private static final int BREAK_MASK
private static final int FITS
private static final int CONSISTENT
private static final int INCONSISTENT
private final int lineWidth
private int pos
private Backend back
private java.util.ArrayList<java.lang.Integer> marginStack
pos
in nested blocksprivate static final int SPACES
private static final java.lang.String spaces
SPACES
spacesPrinter(Backend back)
writer
.
Lines have a maximum width of lineWidth
.void print(java.lang.String s) throws java.io.IOException
s
to out
java.io.IOException
void openBlock(boolean consistent, int indent, int followingLength)
void closeBlock()
void printBreak(int width, int offset, int followingLength) throws java.io.IOException
followingLength
should be the
space needed by the material up to the next corresponding
closeBlock() or printBreak(), and is used to decide whether the
current line is continues, or a new (indented) line is begun.java.io.IOException
void mark(java.lang.Object o)
void indent(int width, int offset) throws java.io.IOException
java.io.IOException
void close() throws java.io.IOException
java.io.IOException
void flush() throws java.io.IOException
java.io.IOException
int space()
int lineWidth()
private void push(int n, int breaks)
private void pop()
private int top()
private int topMargin()
private int topBreak()
private void newLine() throws java.io.IOException
pos
java.io.IOException
private void writeSpaces(int n) throws java.io.IOException
java.io.IOException