ACIP->Unicode crash fixed.
5% of the code for support of ACIP->Unicode.rtf is here.
This commit is contained in:
parent
5aab4acc93
commit
3aa3859354
3 changed files with 48 additions and 34 deletions
|
@ -267,9 +267,10 @@ 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,
|
||||||
embeddedWarnings,
|
warnings,
|
||||||
warningLevel))
|
embeddedWarnings,
|
||||||
|
warningLevel))
|
||||||
return 46;
|
return 46;
|
||||||
} else {
|
} else {
|
||||||
if (ct != ACIP_TO_TMW) throw new Error("badness");
|
if (ct != ACIP_TO_TMW) throw new Error("badness");
|
||||||
|
|
|
@ -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,18 +181,18 @@ 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,
|
||||||
String warningLevel) {
|
String warningLevel) {
|
||||||
ByteArrayOutputStream sw = new ByteArrayOutputStream();
|
ByteArrayOutputStream sw = new ByteArrayOutputStream();
|
||||||
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");
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
|
@ -219,15 +220,15 @@ 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,
|
||||||
boolean writeWarningsToOut,
|
boolean writeWarningsToOut,
|
||||||
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)
|
||||||
|
tdoc.enableColors();
|
||||||
|
else
|
||||||
|
tdoc.disableColors();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (colors)
|
|
||||||
tdoc.enableColors();
|
|
||||||
else
|
|
||||||
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,10 +558,13 @@ 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")) {
|
||||||
DuffCode tshegDuff = TibetanMachineWeb.getGlyph(" ");
|
if (null != writer) unicode = ACIPRules.getUnicodeFor(" ", false);
|
||||||
if (null == tshegDuff) throw new Error("tsheg duff");
|
if (null != tdoc) {
|
||||||
tdoc.appendDuffCode(tdocstart++,
|
DuffCode tshegDuff = TibetanMachineWeb.getGlyph(" ");
|
||||||
tshegDuff, lastColor);
|
if (null == tshegDuff) throw new Error("tsheg duff");
|
||||||
|
tdoc.appendDuffCode(tdocstart++,
|
||||||
|
tshegDuff, lastColor);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!done) {
|
if (!done) {
|
||||||
|
@ -627,8 +640,8 @@ public class ACIPConverter {
|
||||||
if (isCleanDoc && null != tdoc && tdocstart != tdoc.getLength())
|
if (isCleanDoc && null != tdoc && tdocstart != tdoc.getLength())
|
||||||
throw new Error("Oops -- we dropped something from the output! tdocstart++; and tdocstart+=xyz; are not being used correctly.");
|
throw new Error("Oops -- we dropped something from the output! tdocstart++; and tdocstart+=xyz; are not being used correctly.");
|
||||||
return !hasErrors;
|
return !hasErrors;
|
||||||
} catch (javax.swing.text.BadLocationException e) {
|
} catch (javax.swing.text.BadLocationException e) {
|
||||||
throw new IllegalArgumentException("tdocstart is no good: " + tdocstart);
|
throw new IllegalArgumentException("tdocstart is no good: " + tdocstart);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue