001: /*
002: *******************************************************************************
003: * Copyright (C) 1997-2006, International Business Machines Corporation and *
004: * others. All Rights Reserved. *
005: *******************************************************************************
006: */
007:
008: package com.ibm.icu.dev.demo.chart;
009:
010: import java.io.*;
011: import java.util.ArrayList;
012: import java.util.Iterator;
013: import java.util.List;
014: import java.util.Map;
015: import java.util.TreeMap;
016:
017: import com.ibm.icu.dev.test.util.*;
018: import com.ibm.icu.lang.*;
019: import com.ibm.icu.util.VersionInfo;
020:
021: public class UnicodeChart {
022: static int surrogateType = UCharacter.getType('\ud800');
023: static int privateUseType = UCharacter.getType('\ue000');
024:
025: public static void main(String[] args) throws IOException {
026: //int rowWidth = 256;
027: VersionInfo vi = UCharacter.getUnicodeVersion();
028: String version = vi.getMajor() + "." + vi.getMinor() + "."
029: + vi.getMilli();
030: PrintWriter pw = BagFormatter.openUTF8Writer("C:\\DATA\\GEN\\",
031: "UnicodeChart.html");
032: pw
033: .println("<html><head><meta http-equiv='Content-Type' content='text/html; charset=utf-8'>");
034: pw
035: .println("<script type='text/javascript' src='UnicodeChart.js'></script>");
036: pw
037: .println("<link rel='stylesheet' type='text/css' href='UnicodeChart.css'>");
038: pw.println("<title>Unicode " + version + " Chart</title>");
039: pw.println("</head><body bgcolor='#FFFFFF'>");
040: pw
041: .println("<table border='1' cellspacing='0'><caption><h1>Unicode "
042: + version + " Chart</h1></caption>");
043:
044: /*pw.println("<tr><th></th>");
045: for (int j = 0; j < rowWidth; ++j) {
046: pw.print("<th>" + hex(j,2) + "</th>");
047: }
048: pw.println("</tr>");
049: */
050: // TODO: fix Utility to take ints
051: System.out.println("//Surrogate Type: Java="
052: + Character.SURROGATE + ", ICU=" + surrogateType);
053: System.out.println("//Private-Use Type: Java="
054: + Character.PRIVATE_USE + ", ICU=" + privateUseType);
055:
056: //boolean gotOne = true;
057: int columns = 0;
058: int limit = 0x110000 / 16;
059: pw.println("<script>");
060: pw.print("top();");
061: // an array that maps String (containing column information) to UnicodeSet (containing column numbers)
062: Map info_number = new TreeMap();
063: List number_info = new ArrayList();
064: StringBuffer sb = new StringBuffer();
065: int lastInfo = -1;
066: int sameCount = 0;
067: System.out.println("var charRanges = [");
068: for (int i = 0; i < limit; ++i) {
069: // get the string of info, and get its number
070: sb.setLength(0);
071: for (int j = 0; j < 16; ++j) {
072: int cp = i * 16 + j;
073: char type = getType(cp);
074: sb.append(type);
075: }
076: String info = sb.toString();
077: Integer s = (Integer) info_number.get(info);
078: if (s == null) {
079: info_number.put(info, s = new Integer(number_info
080: .size()));
081: number_info.add(info);
082: }
083:
084: // write a line whenever the value changes
085: if (lastInfo == s.intValue()) {
086: sameCount++;
087: } else {
088: if (lastInfo != -1)
089: System.out
090: .println(sameCount + "," + lastInfo + ",");
091: sameCount = 1;
092: lastInfo = s.intValue();
093: }
094: }
095: // write last line
096: System.out.println(sameCount + "," + lastInfo);
097: System.out.println("];");
098:
099: // now write out array
100: System.out.println("var charInfo = [");
101: for (Iterator it = number_info.iterator(); it.hasNext();) {
102: String info = (String) it.next();
103: System.out.println("'" + info + "',");
104: }
105: System.out.println("];");
106:
107: // write out blocks
108: Map blockMap = new TreeMap();
109: int startValue = -1;
110: int lastEnum = -1;
111: for (int i = 0; i <= 0x10FFFF; ++i) {
112: int prop = UCharacter.getIntPropertyValue(i,
113: UProperty.BLOCK);
114: if (prop == lastEnum)
115: continue;
116: if (lastEnum != -1) {
117: String s = UCharacter.getPropertyValueName(
118: UProperty.BLOCK, lastEnum,
119: UProperty.NameChoice.LONG);
120: blockMap.put(s, hex(startValue, 0) + "/"
121: + hex(i - startValue, 0));
122: System.out.println(s + ": " + blockMap.get(s));
123: }
124: lastEnum = prop;
125: startValue = i;
126: }
127: String s = UCharacter.getPropertyValueName(UProperty.BLOCK,
128: lastEnum, UProperty.NameChoice.LONG);
129: blockMap.put(s, hex(startValue, 0) + "/"
130: + hex(0x110000 - startValue, 0));
131: blockMap.remove("No_Block");
132: for (Iterator it = blockMap.keySet().iterator(); it.hasNext();) {
133: String blockName = (String) it.next();
134: String val = (String) blockMap.get(blockName);
135: System.out.println("<option value='" + val + "'>"
136: + blockName + "</option>");
137: }
138:
139: // <option value="4DC0">Yijing Hexagram Symbols</option>
140:
141: pw.println("</script></tr></table><p></p>");
142: pw.println("<table><caption>Key</caption>");
143: pw
144: .println("<tr><td>X</td><td class='left'>Graphic characters</td></tr>");
145: pw
146: .println("<tr><td>\u00A0</td><td class='left'>Whitespace</td></tr>");
147: pw
148: .println("<tr><td class='i'>\u00A0</td><td class='left'>Other Default Ignorable</td></tr>");
149: pw
150: .println("<tr><td class='u'>\u00A0</td><td class='left'>Undefined, Private Use, or Surrogates</td></tr>");
151: pw
152: .println("<tr><td class='n'>\u00A0</td><td class='left'>Noncharacter</td></tr>");
153: pw.println("</table>");
154: pw
155: .println("<p>Copyright \u00A9 2003, Mark Davis. All Rights Reserved.</body></html>");
156: pw.close();
157: System.out.println("//columns: " + columns);
158: }
159:
160: private static char getType(int i) {
161: char type = 'v';
162: int cat = UCharacter.getType(i);
163: if (UCharacter.hasBinaryProperty(i,
164: UProperty.NONCHARACTER_CODE_POINT)) {
165: type = 'n';
166: } else if (cat == Character.UNASSIGNED || cat == surrogateType
167: || cat == privateUseType) {
168: type = 'u';
169: } else if (UCharacter.isUWhiteSpace(i)) {
170: type = 'w';
171: } else if (UCharacter.hasBinaryProperty(i,
172: UProperty.DEFAULT_IGNORABLE_CODE_POINT)) {
173: type = 'i';
174: } else {
175: type = 'v';
176: }
177: return type;
178: }
179:
180: static String hex(int i, int padTo) {
181: String result = Integer.toHexString(i).toUpperCase(
182: java.util.Locale.ENGLISH);
183: while (result.length() < padTo)
184: result = "0" + result;
185: return result;
186: }
187: }
|