Java Reference
In-Depth Information
keeping track of the current position on the page. The output of this program can be sent dir-
ectly to a PostScript printer.
Example 10-14. src/main/java/textproc/PSFormatter.java
public
public class
PSFormatter
{
/** The current input source */
protected
class
PSFormatter
protected
BufferedReader br
;
/** The current page number */
protected
protected
int
int
pageNum
;
/** The current X and Y on the page */
protected
protected
int
int
curX
,
curY
;
/** The current line number on page */
protected
protected
int
int
lineNum
;
/** The current tab setting */
protected
protected
int
int
tabPos
=
0
;
public
public static
static final
final
int
int
INCH
=
72
;
// PS constant: 72 pts/inch
// Page parameters
/** The left margin indent */
protected
protected
int
int
leftMargin
=
50
;
/** The top of page indent */
protected
protected
int
int
topMargin
=
750
;
/** The bottom of page indent */
protected
protected
int
int
botMargin
=
50
;
// FORMATTING PARAMETERS
protected
protected
int
int
points
=
12
;
protected
protected
int
int
leading
=
14
;
public
public static
static
void
void
main
(
String
[]
av
)
throws
throws
IOException
{
iif
(
av
.
length
==
0
)
new
new
PSFormatter
(
new
new
InputStreamReader
(
System
.
in
)).
process
();
else
else
for
(
int
int
i
=
0
;
i
<
av
.
length
;
i
++) {
new
new
PSFormatter
(
av
[
i
]).
process
();
}
}
public
public
PSFormatter
(
String fileName
)
throws
throws
IOException
{
br
=
new
new
BufferedReader
(
new
new
FileReader
(
fileName
));
}
public
public
PSFormatter
(
Reader in
)
throws
throws
IOException
{
iif
(
in
instanceof
instanceof
BufferedReader
)
br
= (
BufferedReader
)
in
;