ACIP->Unicode crash fixed.

5% of the code for support of ACIP->Unicode.rtf is here.
This commit is contained in:
dchandler 2003-10-19 22:19:16 +00:00
parent 5aab4acc93
commit 3aa3859354
3 changed files with 48 additions and 34 deletions

View file

@ -267,7 +267,8 @@ public class TibetanConverter implements FontConverterConstants {
StringBuffer warnings = new StringBuffer(); StringBuffer warnings = new StringBuffer();
boolean embeddedWarnings = (warningLevel != "None"); boolean embeddedWarnings = (warningLevel != "None");
if (ACIP_TO_UNI_TEXT == ct) { if (ACIP_TO_UNI_TEXT == ct) {
if (!ACIPConverter.convertToUnicode(al, out, null, warnings, if (!ACIPConverter.convertToUnicodeText(al, out, null,
warnings,
embeddedWarnings, embeddedWarnings,
warningLevel)) warningLevel))
return 46; return 46;

View file

@ -154,6 +154,7 @@ public class ACIPConverter {
return rv; return rv;
} }
/** DLC DOC */
public static boolean convertToTMW(ArrayList scan, public static boolean convertToTMW(ArrayList scan,
TibetanDocument tdoc, TibetanDocument tdoc,
StringBuffer errors, StringBuffer errors,
@ -164,7 +165,7 @@ public class ACIPConverter {
int loc) int loc)
throws IOException throws IOException
{ {
return convertTo(false, scan, null, tdoc, errors, warnings, return convertTo(false, true, scan, null, tdoc, errors, warnings,
writeWarningsToResult, warningLevel, colors, writeWarningsToResult, warningLevel, colors,
loc, loc == tdoc.getLength()); loc, loc == tdoc.getLength());
} }
@ -180,7 +181,7 @@ public class ACIPConverter {
* conversion upon perfect success or if there were merely * conversion upon perfect success or if there were merely
* warnings, null if errors occurred. * warnings, null if errors occurred.
*/ */
public static String convertToUnicode(String acip, public static String convertToUnicodeText(String acip,
StringBuffer errors, StringBuffer errors,
StringBuffer warnings, StringBuffer warnings,
boolean writeWarningsToResult, boolean writeWarningsToResult,
@ -189,7 +190,7 @@ public class ACIPConverter {
ArrayList al = ACIPTshegBarScanner.scan(acip, errors, -1); ArrayList al = ACIPTshegBarScanner.scan(acip, errors, -1);
try { try {
if (null != al) { if (null != al) {
convertToUnicode(al, sw, errors, convertToUnicodeText(al, sw, errors,
warnings, writeWarningsToResult, warnings, writeWarningsToResult,
warningLevel); warningLevel);
return sw.toString("UTF-8"); return sw.toString("UTF-8");
@ -219,7 +220,7 @@ public class ACIPConverter {
* are written to out in the appropriate places * are written to out in the appropriate places
* @throws IOException if we cannot write to out * @throws IOException if we cannot write to out
*/ */
public static boolean convertToUnicode(ArrayList scan, public static boolean convertToUnicodeText(ArrayList scan,
OutputStream out, OutputStream out,
StringBuffer errors, StringBuffer errors,
StringBuffer warnings, StringBuffer warnings,
@ -227,7 +228,7 @@ public class ACIPConverter {
String warningLevel) String warningLevel)
throws IOException throws IOException
{ {
return convertTo(true, scan, out, null, errors, warnings, return convertTo(true, false, scan, out, null, errors, warnings,
writeWarningsToOut, warningLevel, false, -1, true); writeWarningsToOut, warningLevel, false, -1, true);
} }
@ -250,9 +251,10 @@ public class ACIPConverter {
} }
private static boolean convertTo(boolean toUnicode, // else to TMW private static boolean convertTo(boolean toUnicode, // else to TMW
boolean toRTF, // else to UTF-8-encoded text
ArrayList scan, ArrayList scan,
OutputStream out, // for toUnicode mode OutputStream out, // for (toUnicode && !toRTF) mode
TibetanDocument tdoc, // for !toUnicode mode TibetanDocument tdoc, // for !toUnicode mode or (toUnicode && toRTF) mode
StringBuffer errors, StringBuffer errors,
StringBuffer warnings, StringBuffer warnings,
boolean writeWarningsToOut, boolean writeWarningsToOut,
@ -263,6 +265,14 @@ public class ACIPConverter {
throws IOException throws IOException
{ {
try { try {
if (toUnicode && toRTF)
throw new Error("DLC NOW FIXME: support this ACIP->Unicode.rtf mode so that KA (GA) shows up in two different font sizes.");
if (!toUnicode && !toRTF)
throw new IllegalArgumentException("ACIP->Uni.rtf, ACIP->Uni.txt, and ACIP->TMW.rtf are supported, but not ACIP->TMW.txt");
if (toUnicode && toRTF && null == tdoc)
throw new IllegalArgumentException("ACIP->Uni.rtf requires a TibetanDocument");
if (null != out && !(toUnicode && !toRTF))
throw new IllegalArgumentException("That stream is only used in ACIP->Uni.txt mode");
int smallFontSize = -1; int smallFontSize = -1;
int regularFontSize = -1; int regularFontSize = -1;
if (null != tdoc) { if (null != tdoc) {
@ -278,16 +288,16 @@ public class ACIPConverter {
smallFontSize = (int)(0.75*regularFontSize); smallFontSize = (int)(0.75*regularFontSize);
if (smallFontSize >= regularFontSize) if (smallFontSize >= regularFontSize)
smallFontSize = regularFontSize - 1; smallFontSize = regularFontSize - 1;
}
if (colors) if (colors)
tdoc.enableColors(); tdoc.enableColors();
else else
tdoc.disableColors(); tdoc.disableColors();
}
int sz = scan.size(); int sz = scan.size();
boolean hasErrors = false; boolean hasErrors = false;
BufferedWriter writer = null; BufferedWriter writer = null;
if (toUnicode) if (toUnicode && !toRTF)
writer writer
= new BufferedWriter(new OutputStreamWriter(out, "UTF-8")); = new BufferedWriter(new OutputStreamWriter(out, "UTF-8"));
boolean lastGuyWasNonPunct = false; boolean lastGuyWasNonPunct = false;
@ -548,11 +558,14 @@ public class ACIPConverter {
&& null != lastGuy && null != lastGuy
&& (lpl = lastGuy.get(lastGuy.size() - 1)).size() == 1 && (lpl = lastGuy.get(lastGuy.size() - 1)).size() == 1
&& lpl.get(0).getLeft().equals("NG")) { && lpl.get(0).getLeft().equals("NG")) {
if (null != writer) unicode = ACIPRules.getUnicodeFor(" ", false);
if (null != tdoc) {
DuffCode tshegDuff = TibetanMachineWeb.getGlyph(" "); DuffCode tshegDuff = TibetanMachineWeb.getGlyph(" ");
if (null == tshegDuff) throw new Error("tsheg duff"); if (null == tshegDuff) throw new Error("tsheg duff");
tdoc.appendDuffCode(tdocstart++, tdoc.appendDuffCode(tdocstart++,
tshegDuff, lastColor); tshegDuff, lastColor);
} }
}
if (!done) { if (!done) {
if (null != writer) unicode = ACIPRules.getUnicodeFor(s.getText(), false); if (null != writer) unicode = ACIPRules.getUnicodeFor(s.getText(), false);

View file

@ -7348,7 +7348,7 @@ tstHelper("ZUR");
} }
private static void uhelp(String acip, String expectedUnicode) { private static void uhelp(String acip, String expectedUnicode) {
StringBuffer errors = new StringBuffer(); StringBuffer errors = new StringBuffer();
String unicode = ACIPConverter.convertToUnicode(acip, errors, null, true, "Most"); String unicode = ACIPConverter.convertToUnicodeText(acip, errors, null, true, "Most");
if (null == unicode) { if (null == unicode) {
if (null != expectedUnicode && "none" != expectedUnicode) { if (null != expectedUnicode && "none" != expectedUnicode) {
System.out.println("No unicode exists for " + acip + " but you expected " + org.thdl.tib.text.tshegbar.UnicodeUtils.unicodeStringToPrettyString(expectedUnicode)); System.out.println("No unicode exists for " + acip + " but you expected " + org.thdl.tib.text.tshegbar.UnicodeUtils.unicodeStringToPrettyString(expectedUnicode));