001: /**
002: * CPCompiler.java
003: *
004: Copyright (c) 2007, Innovatics Inc.
005:
006: All rights reserved.
007:
008: Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
009:
010: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
011: * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
012:
013: THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
014: "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
015: LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
016: A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
017: CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
018: EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
019: PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
020: PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
021: LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
022: NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
023: SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
024: */package util;
025:
026: import java.lang.*;
027: import java.io.*;
028: import java.util.*;
029:
030: /**
031: * CPCompiler.java
032: * Creates the code page .java and .cs files
033: */
034: public class CPCompiler {
035:
036: public CPCompiler(String fileName, String lang) {
037:
038: try {
039: BufferedReader in = new BufferedReader(new FileReader(
040: "code-pages/" + fileName));
041: String className = fileName.substring(0, fileName
042: .lastIndexOf('.'));
043: BufferedWriter out = null;
044: if (lang.equals("Java")) {
045: out = new BufferedWriter(new FileWriter("com/pdfjet/CP"
046: + className + ".java"));
047: out.write("package com.pdfjet;\n\n");
048: out.write("import java.lang.*;\n\n");
049: } else {
050: out = new BufferedWriter(new FileWriter("net/pdfjet/CP"
051: + className + ".cs"));
052: out.write("using System;\n\n");
053: out.write("namespace PDFjet.NET {\n");
054: }
055: out.write("public class CP" + className + " {\n");
056:
057: out.write("protected static int[] codes = {\n");
058: out.write("0x0020,\n");
059: List<String> list = new ArrayList<String>();
060: List<String> unicodes = new ArrayList<String>();
061: int count = 0x80;
062: String line = null;
063: while ((line = in.readLine()) != null) {
064: if (line.startsWith("#"))
065: continue;
066: list.clear();
067: StringTokenizer st = new StringTokenizer(line, " =:");
068: while (st.hasMoreTokens())
069: list.add(st.nextToken());
070: int code = Integer.parseInt(list.get(0), 16);
071: if (code < 0x80)
072: continue;
073: while (count < code) {
074: unicodes.add("0020");
075: out.write("0x0020,\n");
076: count++;
077: }
078: String unicode = (list.get(1)).substring(2);
079: unicodes.add(unicode);
080: out.write("0x" + unicode + ",\n");
081: count++;
082: }
083: out.write("};\n");
084:
085: in.close();
086: in = new BufferedReader(new FileReader(
087: "code-pages/aglfn.txt"));
088: Map<String, String> map = new HashMap<String, String>();
089: while ((line = in.readLine()) != null) {
090: if (line.startsWith("#"))
091: continue;
092: list.clear();
093: StringTokenizer st = new StringTokenizer(line, ";");
094: while (st.hasMoreTokens())
095: list.add(st.nextToken());
096: map.put(list.get(0), list.get(1));
097: }
098:
099: out.write("protected static String[] names = {\n");
100: out.write("\"/space\",\n");
101: for (int i = 0; i < unicodes.size(); i++) {
102: if (unicodes.get(i) == null)
103: continue;
104: out.write("\"/");
105: if (unicodes.get(i).equals("00A0")) {
106: out.write("space");
107: } else if (unicodes.get(i).equals("00AD")) {
108: out.write("hyphen");
109: } else if (unicodes.get(i).equals("00B2")) {
110: out.write("twosuperior");
111: } else if (unicodes.get(i).equals("00B3")) {
112: out.write("threesuperior");
113: } else if (unicodes.get(i).equals("00B9")) {
114: out.write("onesuperior");
115: } else if (unicodes.get(i).equals("00B5")) {
116: out.write("mu");
117: } else if (unicodes.get(i).equals("2015")) {
118: out.write("endash");
119: } else {
120: out.write(map.get(unicodes.get(i)));
121: }
122: out.write("\",\n");
123: }
124: out.write("};\n");
125: out.write("}\n");
126:
127: if (lang.equals("C#")) {
128: out.write("}\n");
129: }
130: out.close();
131: in.close();
132: } catch (Exception e) {
133: System.err.println(e);
134: }
135: }
136:
137: public static void main(String[] args) {
138: new CPCompiler("1250.txt", "Java"); // Central Europe
139: new CPCompiler("1251.txt", "Java"); // Cyrillic
140: new CPCompiler("1252.txt", "Java"); // Latin I
141: new CPCompiler("1253.txt", "Java"); // Greek
142: new CPCompiler("1254.txt", "Java"); // Turkish
143: new CPCompiler("1257.txt", "Java"); // Baltic
144:
145: new CPCompiler("1250.txt", "C#"); // Central Europe
146: new CPCompiler("1251.txt", "C#"); // Cyrillic
147: new CPCompiler("1252.txt", "C#"); // Latin I
148: new CPCompiler("1253.txt", "C#"); // Greek
149: new CPCompiler("1254.txt", "C#"); // Turkish
150: new CPCompiler("1257.txt", "C#"); // Baltic
151: }
152:
153: } // End of CPCompiler.java
|