1 /* $Id: chartab-lite.java,v 1.4 2006/09/28 13:31:21 tm Exp $
2  *
3  * PDFlib client: character table
4  */
5 
6 import java.io.*;
7 import com.pdflib.pdflib;
8 import com.pdflib.PDFlibException;
9 
10 public class chartab
11 {
12     /* change these as required */
13     static final String fontname = "LuciduxSans-Oblique";
14 
15     /* This is where font/image/PDF input files live. Adjust as necessary. */
16     static final String searchpath = "../data";
17 
18     /* list of encodings to use */
19     static final String encodings[] = {"iso8859-1", "iso8859-2", "iso8859-15"};
20     static final int ENCODINGS = 3;
21     static final double FONTSIZE	= 16;
22     static final double TOP		= 700;
23     static final double LEFT		= 50;
24     static final double YINCR	= 2*FONTSIZE;
25     static final double XINCR	= 2*FONTSIZE;
26 
main(String argv[])27     public static void main (String argv[])
28     {
29 	/* whether or not to embed the font */
30 	int embed = 1;
31 
32 	String buf;
33 	String optlist;
34 	double x, y;
35 	int row, col, font, page;
36 
37 	pdflib p = null ;
38 
39 	try{
40 	    p = new pdflib();
41 
42 	    /* This means we must check return values of load_font() etc. */
43 	    p.set_parameter("errorpolicy", "return");
44 
45 	    if (p.begin_document("chartab.pdf",
46 	    	"destination {type fitwindow page 1}") == -1)
47 	    {
48 		throw new Exception("Error: " + p.get_errmsg());
49 	    }
50 
51 	    p.set_parameter("SearchPath", searchpath);
52 
53 	    p.set_info("Creator", "chartab.java");
54 	    p.set_info("Author", "Thomas Merz");
55 	    p.set_info("Title", "Character table (Java)");
56 
57 	    /* loop over all encodings */
58 	    for (page = 0; page < ENCODINGS; page++)
59 	    {
60 		p.begin_page_ext(595, 842, "");  /* start a new page */
61 
62 		/* print the heading and generate the bookmark */
63 		font = p.load_font("Helvetica", "winansi", "");
64 		if (font == -1)
65 		    throw new Exception("Error: " + p.get_errmsg());
66 
67 		p.setfont(font, FONTSIZE);
68 		if (embed == 1) {
69 		    buf = fontname + " (" + encodings[page] + ") embedded";
70 		} else{
71 		    buf = fontname + " (" + encodings[page] + ") not  embedded";
72 		}
73 
74 		p.show_xy(buf, LEFT - XINCR, TOP + 3 * YINCR);
75 		p.create_bookmark(buf, "");
76 
77 		/* print the row and column captions */
78 		p.setfont(font, 2 * FONTSIZE/3);
79 
80 		for (row = 0; row < 16; row++)
81 		{
82 		    buf ="x" + (Integer.toHexString(row)).toUpperCase();
83 		    p.show_xy(buf, LEFT + row*XINCR, TOP + YINCR);
84 
85 		    buf = (Integer.toHexString(row)).toUpperCase() + "x";
86 		    p.show_xy(buf, LEFT - XINCR, TOP - row * YINCR);
87 		}
88 
89 		/* print the character table */
90 		if (embed == 1) {
91 		    optlist = "embedding";
92 		} else{
93 		    optlist = "";
94 		}
95 		font = p.load_font(fontname, encodings[page], optlist);
96 		if (font == -1)
97 		    throw new Exception("Error: " + p.get_errmsg());
98 
99 		p.setfont(font, FONTSIZE);
100 
101 		y = TOP;
102 		x = LEFT;
103 
104 		for (row = 0; row < 16; row++)
105 		{
106 		    for (col = 0; col < 16; col++) {
107 			buf = String.valueOf((char)(16*row + col));
108 			p.show_xy(buf, x, y);
109 			x += XINCR;
110 		    }
111 		    x = LEFT;
112 		    y -= YINCR;
113 		}
114 
115 		p.end_page_ext("");
116 	    }
117 	    p.end_document("");
118 
119         } catch (PDFlibException e) {
120 	    System.err.print("PDFlib exception occurred in chartab sample:\n");
121 	    System.err.print("[" + e.get_errnum() + "] " + e.get_apiname() +
122 			    ": " + e.get_errmsg() + "\n");
123         } catch (Exception e) {
124             System.err.println(e.getMessage());
125         } finally {
126             if (p != null) {
127 		p.delete();
128             }
129         }
130     }
131 }
132