Fixed bug 830332, "Convert selected ACIP=>Tibetan busted".
This commit is contained in:
parent
e74547d743
commit
5c36dd81d3
3 changed files with 63 additions and 48 deletions
|
@ -1609,12 +1609,12 @@ public void paste(int offset) {
|
||||||
DuffData[] duffdata = null;
|
DuffData[] duffdata = null;
|
||||||
if (fromACIP) {
|
if (fromACIP) {
|
||||||
getTibDoc().remove(start, i-start);
|
getTibDoc().remove(start, i-start);
|
||||||
TibTextUtils.insertTibetanMachineWebForACIP(sb.toString(),
|
i += -1 /* because i++ will occur */
|
||||||
getTibDoc(),
|
+ TibTextUtils.insertTibetanMachineWebForACIP(sb.toString(),
|
||||||
start,
|
getTibDoc(),
|
||||||
withWarnings);
|
start,
|
||||||
}
|
withWarnings);
|
||||||
else
|
} else
|
||||||
duffdata = TibTextUtils.getTibetanMachineWebForEWTS(sb.toString());
|
duffdata = TibTextUtils.getTibetanMachineWebForEWTS(sb.toString());
|
||||||
if (!fromACIP) {
|
if (!fromACIP) {
|
||||||
getTibDoc().remove(start, i-start);
|
getTibDoc().remove(start, i-start);
|
||||||
|
|
|
@ -324,11 +324,12 @@ public class TibTextUtils implements THDLWylieConstants {
|
||||||
* it does not conform to the ACIP transcription rules (those in the
|
* it does not conform to the ACIP transcription rules (those in the
|
||||||
* official document and the subtler rules pieced together by David
|
* official document and the subtler rules pieced together by David
|
||||||
* Chandler through study and private correspondence with Robert
|
* Chandler through study and private correspondence with Robert
|
||||||
* Chilton) */
|
* Chilton)
|
||||||
public static void insertTibetanMachineWebForACIP(String acip,
|
* @return the number of characters inserted into tdoc */
|
||||||
TibetanDocument tdoc,
|
public static int insertTibetanMachineWebForACIP(String acip,
|
||||||
int loc,
|
TibetanDocument tdoc,
|
||||||
boolean withWarnings)
|
int loc,
|
||||||
|
boolean withWarnings)
|
||||||
throws InvalidACIPException
|
throws InvalidACIPException
|
||||||
{
|
{
|
||||||
StringBuffer errors = new StringBuffer();
|
StringBuffer errors = new StringBuffer();
|
||||||
|
@ -346,8 +347,11 @@ public class TibTextUtils implements THDLWylieConstants {
|
||||||
putWarningsInOutput = true;
|
putWarningsInOutput = true;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
int tloc[] = new int[] { loc };
|
||||||
ACIPConverter.convertToTMW(al, tdoc, null, null,
|
ACIPConverter.convertToTMW(al, tdoc, null, null,
|
||||||
putWarningsInOutput, warningLevel, colors, loc);
|
putWarningsInOutput, warningLevel,
|
||||||
|
colors, tloc);
|
||||||
|
return tloc[0] - loc;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new Error("Can't happen: " + e);
|
throw new Error("Can't happen: " + e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,8 +38,6 @@ import org.thdl.tib.text.DuffCode;
|
||||||
public class ACIPConverter {
|
public class ACIPConverter {
|
||||||
// DLC NOW: (KA)'s info is lost when you convert to Unicode text instead of Unicode RTF. Give an ERROR.
|
// DLC NOW: (KA)'s info is lost when you convert to Unicode text instead of Unicode RTF. Give an ERROR.
|
||||||
|
|
||||||
// DLC NOW: IMPLEMENT (KA) font shrinking
|
|
||||||
|
|
||||||
// DLC NOW: BAo isn't converting.
|
// DLC NOW: BAo isn't converting.
|
||||||
|
|
||||||
/** Command-line converter. Gives error messages on standard
|
/** Command-line converter. Gives error messages on standard
|
||||||
|
@ -142,12 +140,20 @@ public class ACIPConverter {
|
||||||
boolean rv
|
boolean rv
|
||||||
= convertToTMW(scan, tdoc, errors, warnings,
|
= convertToTMW(scan, tdoc, errors, warnings,
|
||||||
writeWarningsToResult, warningLevel, colors,
|
writeWarningsToResult, warningLevel, colors,
|
||||||
tdoc.getLength());
|
new int[] { tdoc.getLength() });
|
||||||
tdoc.writeRTFOutputStream(out);
|
tdoc.writeRTFOutputStream(out);
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** DLC DOC */
|
|
||||||
|
/** Turns the list of TStrings scan into TibetanMachineWeb and
|
||||||
|
Roman warnings and error messages that are inserted at
|
||||||
|
position loc in tdoc. DLC DOC better
|
||||||
|
|
||||||
|
@param loc an input-output parameter. On input, loc[0] is the
|
||||||
|
offset from zero inside tdoc at which conversion results will
|
||||||
|
be placed. On output, loc[0] is one past the offset of the
|
||||||
|
last of the conversion results. */
|
||||||
public static boolean convertToTMW(ArrayList scan,
|
public static boolean convertToTMW(ArrayList scan,
|
||||||
TibetanDocument tdoc,
|
TibetanDocument tdoc,
|
||||||
StringBuffer errors,
|
StringBuffer errors,
|
||||||
|
@ -155,12 +161,12 @@ public class ACIPConverter {
|
||||||
boolean writeWarningsToResult,
|
boolean writeWarningsToResult,
|
||||||
String warningLevel,
|
String warningLevel,
|
||||||
boolean colors,
|
boolean colors,
|
||||||
int loc)
|
int[] loc)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
return convertTo(false, true, 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[0] == tdoc.getLength());
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns UTF-8 encoded Unicode. A bit indirect, so use this
|
/** Returns UTF-8 encoded Unicode. A bit indirect, so use this
|
||||||
|
@ -222,7 +228,7 @@ public class ACIPConverter {
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
return convertTo(true, false, scan, out, null, errors, warnings,
|
return convertTo(true, false, scan, out, null, errors, warnings,
|
||||||
writeWarningsToOut, warningLevel, false, -1, true);
|
writeWarningsToOut, warningLevel, false, new int[] { -1 } , true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean peekaheadFindsSpacesAndComma(ArrayList /* of TString */ scan,
|
private static boolean peekaheadFindsSpacesAndComma(ArrayList /* of TString */ scan,
|
||||||
|
@ -253,7 +259,12 @@ public class ACIPConverter {
|
||||||
boolean writeWarningsToOut,
|
boolean writeWarningsToOut,
|
||||||
String warningLevel,
|
String warningLevel,
|
||||||
boolean colors,
|
boolean colors,
|
||||||
int tdocstart,
|
// tdocLocation[0] is an
|
||||||
|
// input-output parameter. It's
|
||||||
|
// the starting location on input
|
||||||
|
// and the location just past the
|
||||||
|
// end on output.
|
||||||
|
int[] tdocLocation,
|
||||||
boolean isCleanDoc)
|
boolean isCleanDoc)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
|
@ -307,8 +318,8 @@ public class ACIPConverter {
|
||||||
String text = "[#ERROR CONVERTING ACIP DOCUMENT: Lexical error: " + s.getText() + "]";
|
String text = "[#ERROR CONVERTING ACIP DOCUMENT: Lexical error: " + s.getText() + "]";
|
||||||
if (null != writer) writer.write(text);
|
if (null != writer) writer.write(text);
|
||||||
if (null != tdoc) {
|
if (null != tdoc) {
|
||||||
tdoc.appendRoman(tdocstart, text, Color.RED);
|
tdoc.appendRoman(tdocLocation[0], text, Color.RED);
|
||||||
tdocstart += text.length();
|
tdocLocation[0] += text.length();
|
||||||
}
|
}
|
||||||
} else if (stype == TString.TSHEG_BAR_ADORNMENT) {
|
} else if (stype == TString.TSHEG_BAR_ADORNMENT) {
|
||||||
if (lastGuyWasNonPunct) {
|
if (lastGuyWasNonPunct) {
|
||||||
|
@ -326,10 +337,10 @@ public class ACIPConverter {
|
||||||
= ACIPRules.getWylieForACIPOther(s.getText());
|
= ACIPRules.getWylieForACIPOther(s.getText());
|
||||||
if (null == wylie) {
|
if (null == wylie) {
|
||||||
hasErrors = true;
|
hasErrors = true;
|
||||||
tdoc.appendRoman(tdocstart, err, Color.RED);
|
tdoc.appendRoman(tdocLocation[0], err, Color.RED);
|
||||||
tdocstart += err.length();
|
tdocLocation[0] += err.length();
|
||||||
} else {
|
} else {
|
||||||
tdoc.appendDuffCode(tdocstart++,
|
tdoc.appendDuffCode(tdocLocation[0]++,
|
||||||
TibetanMachineWeb.getGlyph(wylie),
|
TibetanMachineWeb.getGlyph(wylie),
|
||||||
Color.BLACK);
|
Color.BLACK);
|
||||||
}
|
}
|
||||||
|
@ -346,8 +357,8 @@ public class ACIPConverter {
|
||||||
String text = "[#WARNING CONVERTING ACIP DOCUMENT: Lexical warning: " + s.getText() + "]";
|
String text = "[#WARNING CONVERTING ACIP DOCUMENT: Lexical warning: " + s.getText() + "]";
|
||||||
if (null != writer) writer.write(text);
|
if (null != writer) writer.write(text);
|
||||||
if (null != tdoc) {
|
if (null != tdoc) {
|
||||||
tdoc.appendRoman(tdocstart, text, Color.RED);
|
tdoc.appendRoman(tdocLocation[0], text, Color.RED);
|
||||||
tdocstart += text.length();
|
tdocLocation[0] += text.length();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -366,8 +377,8 @@ public class ACIPConverter {
|
||||||
+ ((stype == TString.FOLIO_MARKER) ? "}" : ""));
|
+ ((stype == TString.FOLIO_MARKER) ? "}" : ""));
|
||||||
if (null != writer) writer.write(text);
|
if (null != writer) writer.write(text);
|
||||||
if (null != tdoc) {
|
if (null != tdoc) {
|
||||||
tdoc.appendRoman(tdocstart, text, Color.BLACK);
|
tdoc.appendRoman(tdocLocation[0], text, Color.BLACK);
|
||||||
tdocstart += text.length();
|
tdocLocation[0] += text.length();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
String unicode = null;
|
String unicode = null;
|
||||||
|
@ -383,9 +394,9 @@ public class ACIPConverter {
|
||||||
String errorMessage = "[#ERROR CONVERTING ACIP DOCUMENT: THE TSHEG BAR (\"SYLLABLE\") " + s.getText() + " HAS THESE ERRORS: " + acipError + "]";
|
String errorMessage = "[#ERROR CONVERTING ACIP DOCUMENT: THE TSHEG BAR (\"SYLLABLE\") " + s.getText() + " HAS THESE ERRORS: " + acipError + "]";
|
||||||
if (null != writer) writer.write(errorMessage);
|
if (null != writer) writer.write(errorMessage);
|
||||||
if (null != tdoc) {
|
if (null != tdoc) {
|
||||||
tdoc.appendRoman(tdocstart, errorMessage,
|
tdoc.appendRoman(tdocLocation[0], errorMessage,
|
||||||
Color.RED);
|
Color.RED);
|
||||||
tdocstart += errorMessage.length();
|
tdocLocation[0] += errorMessage.length();
|
||||||
}
|
}
|
||||||
if (null != errors)
|
if (null != errors)
|
||||||
errors.append(errorMessage + "\n");
|
errors.append(errorMessage + "\n");
|
||||||
|
@ -398,9 +409,9 @@ public class ACIPConverter {
|
||||||
String errorMessage = "[#ERROR CONVERTING ACIP DOCUMENT: THE TSHEG BAR (\"SYLLABLE\") " + s.getText() + " IS ESSENTIALLY NOTHING.]";
|
String errorMessage = "[#ERROR CONVERTING ACIP DOCUMENT: THE TSHEG BAR (\"SYLLABLE\") " + s.getText() + " IS ESSENTIALLY NOTHING.]";
|
||||||
if (null != writer) writer.write(errorMessage);
|
if (null != writer) writer.write(errorMessage);
|
||||||
if (null != tdoc) {
|
if (null != tdoc) {
|
||||||
tdoc.appendRoman(tdocstart, errorMessage,
|
tdoc.appendRoman(tdocLocation[0], errorMessage,
|
||||||
Color.RED);
|
Color.RED);
|
||||||
tdocstart += errorMessage.length();
|
tdocLocation[0] += errorMessage.length();
|
||||||
}
|
}
|
||||||
if (null != errors)
|
if (null != errors)
|
||||||
errors.append(errorMessage + "\n");
|
errors.append(errorMessage + "\n");
|
||||||
|
@ -413,10 +424,10 @@ public class ACIPConverter {
|
||||||
String errorMessage = "[#ERROR CONVERTING ACIP DOCUMENT: THE TSHEG BAR (\"SYLLABLE\") " + s.getText() + " HAS NO LEGAL PARSES.]";
|
String errorMessage = "[#ERROR CONVERTING ACIP DOCUMENT: THE TSHEG BAR (\"SYLLABLE\") " + s.getText() + " HAS NO LEGAL PARSES.]";
|
||||||
if (null != writer) writer.write(errorMessage);
|
if (null != writer) writer.write(errorMessage);
|
||||||
if (null != tdoc) {
|
if (null != tdoc) {
|
||||||
tdoc.appendRoman(tdocstart,
|
tdoc.appendRoman(tdocLocation[0],
|
||||||
errorMessage,
|
errorMessage,
|
||||||
Color.RED);
|
Color.RED);
|
||||||
tdocstart += errorMessage.length();
|
tdocLocation[0] += errorMessage.length();
|
||||||
}
|
}
|
||||||
if (null != errors)
|
if (null != errors)
|
||||||
errors.append(errorMessage + "\n");
|
errors.append(errorMessage + "\n");
|
||||||
|
@ -454,10 +465,10 @@ public class ACIPConverter {
|
||||||
+ warning + "]");
|
+ warning + "]");
|
||||||
if (null != writer) writer.write(text);
|
if (null != writer) writer.write(text);
|
||||||
if (null != tdoc) {
|
if (null != tdoc) {
|
||||||
tdoc.appendRoman(tdocstart,
|
tdoc.appendRoman(tdocLocation[0],
|
||||||
text,
|
text,
|
||||||
Color.RED);
|
Color.RED);
|
||||||
tdocstart += text.length();
|
tdocLocation[0] += text.length();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (null != warnings) {
|
if (null != warnings) {
|
||||||
|
@ -533,10 +544,10 @@ public class ACIPConverter {
|
||||||
}
|
}
|
||||||
if (null != tdoc) {
|
if (null != tdoc) {
|
||||||
String x = " ";
|
String x = " ";
|
||||||
tdoc.appendRoman(tdocstart,
|
tdoc.appendRoman(tdocLocation[0],
|
||||||
x,
|
x,
|
||||||
Color.BLACK);
|
Color.BLACK);
|
||||||
tdocstart += x.length();
|
tdocLocation[0] += x.length();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// DLC AM I DOING THIS? By normal Tibetan & Dzongkha spelling, writing, and input rules
|
// DLC AM I DOING THIS? By normal Tibetan & Dzongkha spelling, writing, and input rules
|
||||||
|
@ -555,7 +566,7 @@ public class ACIPConverter {
|
||||||
if (null != tdoc) {
|
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(tdocLocation[0]++,
|
||||||
tshegDuff, lastColor);
|
tshegDuff, lastColor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -567,9 +578,9 @@ public class ACIPConverter {
|
||||||
|| s.getText().equals("\t")
|
|| s.getText().equals("\t")
|
||||||
|| s.getText().equals("\n")
|
|| s.getText().equals("\n")
|
||||||
|| s.getText().equals("\r\n")) {
|
|| s.getText().equals("\r\n")) {
|
||||||
tdoc.appendRoman(tdocstart, s.getText(),
|
tdoc.appendRoman(tdocLocation[0], s.getText(),
|
||||||
Color.BLACK);
|
Color.BLACK);
|
||||||
tdocstart += s.getText().length();
|
tdocLocation[0] += s.getText().length();
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
String wy = ACIPRules.getWylieForACIPOther(s.getText());
|
String wy = ACIPRules.getWylieForACIPOther(s.getText());
|
||||||
|
@ -603,17 +614,17 @@ public class ACIPConverter {
|
||||||
if (null != duff && 0 != duff.length) {
|
if (null != duff && 0 != duff.length) {
|
||||||
for (int j = 0; j < duff.length; j++) {
|
for (int j = 0; j < duff.length; j++) {
|
||||||
if (duff[j] instanceof DuffCode)
|
if (duff[j] instanceof DuffCode)
|
||||||
tdoc.appendDuffCode(tdocstart++,
|
tdoc.appendDuffCode(tdocLocation[0]++,
|
||||||
(DuffCode)duff[j],
|
(DuffCode)duff[j],
|
||||||
color);
|
color);
|
||||||
else {
|
else {
|
||||||
hasErrors = true;
|
hasErrors = true;
|
||||||
if (null != errors)
|
if (null != errors)
|
||||||
errors.append((String)duff[j] + "\n");
|
errors.append((String)duff[j] + "\n");
|
||||||
tdoc.appendRoman(tdocstart,
|
tdoc.appendRoman(tdocLocation[0],
|
||||||
(String)duff[j],
|
(String)duff[j],
|
||||||
Color.RED);
|
Color.RED);
|
||||||
tdocstart += ((String)duff[j]).length();
|
tdocLocation[0] += ((String)duff[j]).length();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -630,11 +641,11 @@ public class ACIPConverter {
|
||||||
if (null != writer) {
|
if (null != writer) {
|
||||||
writer.close();
|
writer.close();
|
||||||
}
|
}
|
||||||
if (isCleanDoc && null != tdoc && tdocstart != tdoc.getLength())
|
if (isCleanDoc && null != tdoc && tdocLocation[0] != 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! tdocLocation[0]++; and tdocLocation[0]+=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("tdocLocation[0] is no good: " + tdocLocation[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue