-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrintText.java
More file actions
executable file
·71 lines (60 loc) · 1.84 KB
/
PrintText.java
File metadata and controls
executable file
·71 lines (60 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
* PrintText.java
*
* Created on August 1, 2006, 4:05 PM
*/
/**
*
* @author Chen-Fu Liao
*/
import java.util.regex.*;
public class PrintText {
/** Creates a new instance of PrintText */
public PrintText() {
}
/**
* Print the string.
*/
public void print(String s) throws GDSPrintException {
//first prep the string for the printing
String toPrint = prepareString(s);
//now send the prep'ed string to the print preview
PrintPreview.print(toPrint);
}
/**
* Internally all text is converted to HTML
*/
private String prepareString(String s) {
String retval = s;
//replace all < and > with < and > symbols
Pattern pat1 = Pattern.compile("<");
Matcher mat1 = pat1.matcher(retval);
retval = mat1.replaceAll("<");
Pattern pat2 = Pattern.compile(">");
Matcher mat2 = pat1.matcher(retval);
retval = mat2.replaceAll(">");
//Add <font size="0"> to the beginning and </font> to the ending
return ("<body bgcolor=\"#f0f0f0\"><pre><font size=\"+0\">"
+ "<font color=\"blue\">" + retval + "</font></font></pre></body>");
}
public static String StrFormat(int flag, String str, int length) {
int len = str.length() ;
String ret_str ;
if (len>length) {
ret_str = str ;
} else {
String space = "" ;
for (int i=0; i<length-len; i++) {
space += " " ;
}
if (flag==0) {
// left align
ret_str = str+space ;
} else {
// right align
ret_str = space+str ;
}
} // if len > length ?
return ret_str ;
} // StrFormat
}