diff --git a/source/org/thdl/tib/text/TibetanDocument.java b/source/org/thdl/tib/text/TibetanDocument.java index c967197..186d778 100644 --- a/source/org/thdl/tib/text/TibetanDocument.java +++ b/source/org/thdl/tib/text/TibetanDocument.java @@ -23,6 +23,7 @@ import javax.swing.*; import javax.swing.text.*; import javax.swing.text.rtf.RTFEditorKit; import java.io.*; +import java.awt.Color; import org.thdl.util.ThdlDebug; import org.thdl.util.ThdlOptions; @@ -144,6 +145,10 @@ public class TibetanDocument extends DefaultStyledDocument { } } + private static boolean allowColors = true; // DLC FIXME: make me configurable + public static void enableColors() { allowColors = true; } + public static void disableColors() { allowColors = false; } + /** * Inserts Tibetan text into the document. The font size is applied automatically, @@ -154,7 +159,7 @@ public class TibetanDocument extends DefaultStyledDocument { * @see #setTibetanFontSize(int size) */ public void appendDuff(int offset, String s, MutableAttributeSet attr) { - appendDuff(tibetanFontSize, offset, s, attr); + appendDuff(tibetanFontSize, offset, s, attr, Color.BLACK); } /** @@ -164,8 +169,10 @@ public class TibetanDocument extends DefaultStyledDocument { * @param s the string you want to insert * @see #setRomanAttributeSet(AttributeSet) */ - public void appendRoman(int offset, String s) throws BadLocationException { + public void appendRoman(int offset, String s, Color color) throws BadLocationException { ThdlDebug.verify(getRomanAttributeSet() != null); + if (allowColors) + StyleConstants.setForeground(getRomanAttributeSet(), color); insertString(offset, s, getRomanAttributeSet()); } @@ -175,17 +182,18 @@ public class TibetanDocument extends DefaultStyledDocument { * @param s the string you want to insert * @see #setRomanAttributeSet(AttributeSet) */ - public void appendRoman(String s) { + public void appendRoman(String s, Color color) { try { - appendRoman(getLength(), s); + appendRoman(getLength(), s, color); } catch (BadLocationException e) { throw new Error("can't happen"); } } - private void appendDuff(int fontSize, int offset, String s, MutableAttributeSet attr) { + private void appendDuff(int fontSize, int offset, String s, MutableAttributeSet attr, Color color) { try { StyleConstants.setFontSize(attr, fontSize); + if (allowColors) StyleConstants.setForeground(attr, color); insertString(offset, s, attr); } catch (BadLocationException ble) { @@ -198,20 +206,25 @@ public class TibetanDocument extends DefaultStyledDocument { * @param glyphs the array of Tibetan data you want to insert * @param pos the position at which you want to insert text */ + public int insertDuff(int pos, DuffData[] glyphs, Color color) { + return insertDuff(tibetanFontSize, pos, glyphs, true, color); + } + public int insertDuff(int pos, DuffData[] glyphs) { - return insertDuff(tibetanFontSize, pos, glyphs, true); + return insertDuff(tibetanFontSize, pos, glyphs, true, Color.BLACK); } /** * Appends all DuffCodes in glyphs to the end of this document. */ - public void appendDuffCodes(DuffCode[] glyphs) { + public void appendDuffCodes(DuffCode[] glyphs, Color color) { // PERFORMANCE FIXME: this isn't so speedy, but it reuses // existing code. for (int i = 0; i < glyphs.length; i++) { insertDuff(getLength(), new DuffData[] { new DuffData(new String(new char[] { glyphs[i].getCharacter() }), - glyphs[i].getFontNum()) }); + glyphs[i].getFontNum()) }, + color); } } @@ -280,6 +293,9 @@ public class TibetanDocument extends DefaultStyledDocument { private int insertDuff(int fontSize, int pos, DuffData[] glyphs, boolean asTMW) { + return insertDuff(fontSize, pos, glyphs, asTMW, Color.BLACK); + } + private int insertDuff(int fontSize, int pos, DuffData[] glyphs, boolean asTMW, Color color) { if (glyphs == null) return pos; @@ -290,7 +306,7 @@ public class TibetanDocument extends DefaultStyledDocument { : TibetanMachineWeb.getAttributeSetTM(glyphs[i].font)); if (null == mas) throw new Error("Cannot insert that DuffData; the font number is too low or too high; perhaps the programmer has asTMW set incorrectly?"); - appendDuff(fontSize, pos, glyphs[i].text, mas); + appendDuff(fontSize, pos, glyphs[i].text, mas, color); pos += glyphs[i].text.length(); } return pos; @@ -1110,17 +1126,17 @@ public class TibetanDocument extends DefaultStyledDocument { /** the attribute set applied to Roman text in this document */ - private AttributeSet romanAttributeSet = null; + private MutableAttributeSet romanAttributeSet = null; /** Gets the attribute set applied to Roman text in this document. */ - public AttributeSet getRomanAttributeSet() { + public MutableAttributeSet getRomanAttributeSet() { return romanAttributeSet; } /** Sets the attribute set applied to Roman text in this document. */ - public void setRomanAttributeSet(AttributeSet ras) { + public void setRomanAttributeSet(MutableAttributeSet ras) { romanAttributeSet = ras; } diff --git a/source/org/thdl/tib/text/ttt/ACIPConverter.java b/source/org/thdl/tib/text/ttt/ACIPConverter.java index 7e11bd6..9755f8a 100644 --- a/source/org/thdl/tib/text/ttt/ACIPConverter.java +++ b/source/org/thdl/tib/text/ttt/ACIPConverter.java @@ -21,6 +21,7 @@ package org.thdl.tib.text.ttt; import java.io.*; import java.util.ArrayList; import java.util.Stack; +import java.awt.Color; import org.thdl.util.ThdlDebug; import org.thdl.util.ThdlOptions; @@ -50,6 +51,8 @@ public class ACIPConverter { ThdlOptions.setUserPreference("thdl.rely.on.system.tm.fonts", true); ThdlOptions.setUserPreference("thdl.debug", true); + TibetanDocument.enableColors(); + boolean verbose = true; if (args.length != 1) { System.out.println("Bad args! Need just the name of the ACIP text file."); @@ -253,6 +256,8 @@ public class ACIPConverter { = new BufferedWriter(new OutputStreamWriter(out, "UTF-8")); boolean lastGuyWasNonPunct = false; TStackList lastGuy = null; + Color lastColor = Color.BLACK; + Color color = Color.BLACK; for (int i = 0; i < sz; i++) { ACIPString s = (ACIPString)scan.get(i); int stype = s.getType(); @@ -262,14 +267,14 @@ public class ACIPConverter { hasErrors = true; String text = "[#ERROR CONVERTING ACIP DOCUMENT: Lexical error: " + s.getText() + "]"; if (null != writer) writer.write(text); - if (null != tdoc) tdoc.appendRoman(text); + if (null != tdoc) tdoc.appendRoman(text, Color.RED); } else if (stype == ACIPString.WARNING) { lastGuyWasNonPunct = false; lastGuy = null; if (writeWarningsToOut) { String text = "[#WARNING CONVERTING ACIP DOCUMENT: Lexical warning: " + s.getText() + "]"; if (null != writer) writer.write(text); - if (null != tdoc) tdoc.appendRoman(text); + if (null != tdoc) tdoc.appendRoman(text, Color.RED); } // DLC NOW: Warning: We're going with {'}{R}{DA}, but only because our knowledge of prefix rules says that {'}{R+DA} is not a legal Tibetan tsheg bar ("syllable") @@ -287,7 +292,7 @@ public class ACIPConverter { + s.getText() + ((stype == ACIPString.FOLIO_MARKER) ? "}" : "")); if (null != writer) writer.write(text); - if (null != tdoc) tdoc.appendRoman(text); + if (null != tdoc) tdoc.appendRoman(text, Color.BLACK); } else { String unicode = null; DuffCode[] duff = null; @@ -300,7 +305,7 @@ public class ACIPConverter { hasErrors = true; String errorMessage = "[#ERROR CONVERTING ACIP DOCUMENT: THE TSHEG BAR (\"SYLLABLE\") " + s.getText() + " HAS THESE ERRORS: " + acipError + "]"; if (null != writer) writer.write(errorMessage); - if (null != tdoc) tdoc.appendRoman(errorMessage); + if (null != tdoc) tdoc.appendRoman(errorMessage, Color.RED); if (null != errors) errors.append(errorMessage + "\n"); } else { @@ -309,7 +314,7 @@ public class ACIPConverter { hasErrors = true; String errorMessage = "[#ERROR CONVERTING ACIP DOCUMENT: THE TSHEG BAR (\"SYLLABLE\") " + s.getText() + " IS ESSENTIALLY NOTHING.]"; if (null != writer) writer.write(errorMessage); - if (null != tdoc) tdoc.appendRoman(errorMessage); + if (null != tdoc) tdoc.appendRoman(errorMessage, Color.RED); if (null != errors) errors.append(errorMessage + "\n"); } else { @@ -318,7 +323,7 @@ public class ACIPConverter { hasErrors = true; String errorMessage = "[#ERROR CONVERTING ACIP DOCUMENT: THE TSHEG BAR (\"SYLLABLE\") " + s.getText() + " HAS NO LEGAL PARSES.]"; if (null != writer) writer.write(errorMessage); - if (null != tdoc) tdoc.appendRoman(errorMessage); + if (null != tdoc) tdoc.appendRoman(errorMessage, Color.RED); if (null != errors) errors.append(errorMessage + "\n"); } else { @@ -333,7 +338,7 @@ public class ACIPConverter { = ("[#WARNING CONVERTING ACIP DOCUMENT: " + warning + "]"); if (null != writer) writer.write(text); - if (null != tdoc) tdoc.appendRoman(text); + if (null != tdoc) tdoc.appendRoman(text, Color.RED); } if (null != warnings) { warnings.append(warning); @@ -346,6 +351,14 @@ public class ACIPConverter { } if (null != tdoc) { duff = sl.getDuff(); + if (sl.isLegalTshegBar(true).isLegal && !sl.isLegalTshegBar(false).isLegal) { + color = Color.GRAY; + } else if (sl.isLegalTshegBar(false).isLegal) { + color = Color.BLACK; + } else { + color = Color.YELLOW; + } + if (0 == duff.length) { throw new Error("No DuffCodes for stack list " + sl); // FIXME: make this an assertion } @@ -354,6 +367,7 @@ public class ACIPConverter { } } } else { + color = Color.BLACK; if (stype == ACIPString.START_SLASH) { if (null != writer) unicode = "\u0F3C"; if (null != tdoc) duff = new DuffCode[] { TibetanMachineWeb.getGlyph("(") }; @@ -388,9 +402,15 @@ public class ACIPConverter { done = true; } if (null != tdoc) { - tdoc.appendRoman(" "); + tdoc.appendRoman(" ", Color.BLACK); continue; } +// DLC AM I DOING THIS? By normal Tibetan & Dzongkha spelling, writing, and input rules +// Tibetan script stacks should be entered and written: 1 headline +// consonant (0F40->0F6A), any subjoined consonant(s) (0F90-> +// 0F9C), achung (0F71), shabkyu (0F74), any above headline +// vowel(s) (0F72 0F7A 0F7B 0F7C 0F7D and 0F80) ; any ngaro (0F7E, +// 0F82 and 0F83) } } else if (s.getText().equals(",") && lastGuyWasNonPunct @@ -399,7 +419,7 @@ public class ACIPConverter { && lpl.get(0).getLeft().equals("NG")) { DuffCode tshegDuff = TibetanMachineWeb.getGlyph(" "); if (null == tshegDuff) throw new Error("tsheg duff"); - tdoc.appendDuffCodes(new DuffCode[] { tshegDuff }); + tdoc.appendDuffCodes(new DuffCode[] { tshegDuff }, lastColor); } if (!done) { @@ -409,7 +429,7 @@ public class ACIPConverter { || s.getText().equals("\t") || s.getText().equals("\n") || s.getText().equals("\r\n")) { - tdoc.appendRoman(s.getText()); + tdoc.appendRoman(s.getText(), Color.BLACK); continue; } else { String wy = ACIPRules.getWylieForACIPOther(s.getText()); @@ -431,7 +451,7 @@ public class ACIPConverter { if (null != writer && null != unicode) writer.write(unicode); if (null != tdoc) { if (null != duff && 0 != duff.length) { - tdoc.appendDuffCodes(duff); + tdoc.appendDuffCodes(duff, color); // DLC NOW FIXME: use TibTextUtils.getVowel logic to make the output beautiful. } else { // this happens when you have an @@ -442,6 +462,7 @@ public class ACIPConverter { } } } + lastColor = color; } if (null != writer) { writer.close();