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();
boolean embeddedWarnings = (warningLevel != "None");
if (ACIP_TO_UNI_TEXT == ct) {
if (!ACIPConverter.convertToUnicode(al, out, null, warnings,
if (!ACIPConverter.convertToUnicodeText(al, out, null,
warnings,
embeddedWarnings,
warningLevel))
return 46;

View file

@ -154,6 +154,7 @@ public class ACIPConverter {
return rv;
}
/** DLC DOC */
public static boolean convertToTMW(ArrayList scan,
TibetanDocument tdoc,
StringBuffer errors,
@ -164,7 +165,7 @@ public class ACIPConverter {
int loc)
throws IOException
{
return convertTo(false, scan, null, tdoc, errors, warnings,
return convertTo(false, true, scan, null, tdoc, errors, warnings,
writeWarningsToResult, warningLevel, colors,
loc, loc == tdoc.getLength());
}
@ -180,7 +181,7 @@ public class ACIPConverter {
* conversion upon perfect success or if there were merely
* warnings, null if errors occurred.
*/
public static String convertToUnicode(String acip,
public static String convertToUnicodeText(String acip,
StringBuffer errors,
StringBuffer warnings,
boolean writeWarningsToResult,
@ -189,7 +190,7 @@ public class ACIPConverter {
ArrayList al = ACIPTshegBarScanner.scan(acip, errors, -1);
try {
if (null != al) {
convertToUnicode(al, sw, errors,
convertToUnicodeText(al, sw, errors,
warnings, writeWarningsToResult,
warningLevel);
return sw.toString("UTF-8");
@ -219,7 +220,7 @@ public class ACIPConverter {
* are written to out in the appropriate places
* @throws IOException if we cannot write to out
*/
public static boolean convertToUnicode(ArrayList scan,
public static boolean convertToUnicodeText(ArrayList scan,
OutputStream out,
StringBuffer errors,
StringBuffer warnings,
@ -227,7 +228,7 @@ public class ACIPConverter {
String warningLevel)
throws IOException
{
return convertTo(true, scan, out, null, errors, warnings,
return convertTo(true, false, scan, out, null, errors, warnings,
writeWarningsToOut, warningLevel, false, -1, true);
}
@ -250,9 +251,10 @@ public class ACIPConverter {
}
private static boolean convertTo(boolean toUnicode, // else to TMW
boolean toRTF, // else to UTF-8-encoded text
ArrayList scan,
OutputStream out, // for toUnicode mode
TibetanDocument tdoc, // for !toUnicode mode
OutputStream out, // for (toUnicode && !toRTF) mode
TibetanDocument tdoc, // for !toUnicode mode or (toUnicode && toRTF) mode
StringBuffer errors,
StringBuffer warnings,
boolean writeWarningsToOut,
@ -263,6 +265,14 @@ public class ACIPConverter {
throws IOException
{
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 regularFontSize = -1;
if (null != tdoc) {
@ -278,16 +288,16 @@ public class ACIPConverter {
smallFontSize = (int)(0.75*regularFontSize);
if (smallFontSize >= regularFontSize)
smallFontSize = regularFontSize - 1;
}
if (colors)
tdoc.enableColors();
else
tdoc.disableColors();
}
int sz = scan.size();
boolean hasErrors = false;
BufferedWriter writer = null;
if (toUnicode)
if (toUnicode && !toRTF)
writer
= new BufferedWriter(new OutputStreamWriter(out, "UTF-8"));
boolean lastGuyWasNonPunct = false;
@ -548,11 +558,14 @@ public class ACIPConverter {
&& null != lastGuy
&& (lpl = lastGuy.get(lastGuy.size() - 1)).size() == 1
&& lpl.get(0).getLeft().equals("NG")) {
if (null != writer) unicode = ACIPRules.getUnicodeFor(" ", false);
if (null != tdoc) {
DuffCode tshegDuff = TibetanMachineWeb.getGlyph(" ");
if (null == tshegDuff) throw new Error("tsheg duff");
tdoc.appendDuffCode(tdocstart++,
tshegDuff, lastColor);
}
}
if (!done) {
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) {
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 != expectedUnicode && "none" != expectedUnicode) {
System.out.println("No unicode exists for " + acip + " but you expected " + org.thdl.tib.text.tshegbar.UnicodeUtils.unicodeStringToPrettyString(expectedUnicode));