diff --git a/source/org/thdl/tib/input/DuffPane.java b/source/org/thdl/tib/input/DuffPane.java index 3d943ca..4f7cf1d 100644 --- a/source/org/thdl/tib/input/DuffPane.java +++ b/source/org/thdl/tib/input/DuffPane.java @@ -190,7 +190,6 @@ public class DuffPane extends TibetanPane implements FocusListener { private String romanFontFamily; private int romanFontSize; - private MutableAttributeSet romanAttributeSet; private Clipboard rtfBoard; @@ -337,7 +336,7 @@ public class DuffPane extends TibetanPane implements FocusListener { if (isTibetan) { processTibetanChar(key.charAt(0)); } else { - processRomanChar(key, romanAttributeSet); + processRomanChar(key, getTibDoc().getRomanAttributeSet()); } if (manageCaret) { caret.setDot(getTibDoc().getLength()); @@ -549,7 +548,7 @@ public class DuffPane extends TibetanPane implements FocusListener { * @param attr the attributes for the text to insert * @param s the string of text to insert */ - public void append(String s, MutableAttributeSet attr) { + public void append(String s, AttributeSet attr) { append(caret.getDot(), s, attr); } @@ -559,7 +558,7 @@ public class DuffPane extends TibetanPane implements FocusListener { * @param attr the attributes for the text to insert * @param s the string of text to insert */ - public void append(int offset, String s, MutableAttributeSet attr) { + public void append(int offset, String s, AttributeSet attr) { try { getTibDoc().insertString(offset, s, attr); } @@ -617,9 +616,12 @@ public class DuffPane extends TibetanPane implements FocusListener { * @param size a point size */ public void setRomanAttributeSet(String font, int size) { - romanAttributeSet = new SimpleAttributeSet(); - StyleConstants.setFontFamily(romanAttributeSet, font); - StyleConstants.setFontSize(romanAttributeSet, size); + if (getTibDoc() != null) { + SimpleAttributeSet ras = new SimpleAttributeSet(); + StyleConstants.setFontFamily(ras, romanFontFamily = font); + StyleConstants.setFontSize(ras, romanFontSize = size); + getTibDoc().setRomanAttributeSet(ras); + } } /** Like {@link #setRomanAttributeSet}, but allows for noting the @@ -1120,7 +1122,7 @@ public void paste(int offset) { isCutAndPasteEnabled = false; } - private void processRomanChar(String key, MutableAttributeSet attSet) { + private void processRomanChar(String key, AttributeSet attSet) { switch (key.charAt(0)) { case KeyEvent.VK_TAB: case KeyEvent.VK_ENTER: @@ -1483,66 +1485,6 @@ public void paste(int offset) { } } -/** -* Converts the entire document to Extended Wylie. -*/ - public void toWylie() { - int start = getSelectionStart(); - int end = getSelectionEnd(); - long n[] = new long[] { 0 }; - toWylie(start, end, n); - } - -/** -* Converts the specified portion -* of this object's document to Extended Wylie. -* -* @param start the point from which to begin converting to Wylie -* @param end the point at which to stop converting to Wylie -* @param numAttemptedReplacements an array that contains one element; -* this first element will be, upon exit, incremented by the number of -* TMW glyphs that we encountered and attempted to convert to Wylie */ - public void toWylie(int start, int end, - long numAttemptedReplacements[]) { - if (start == end) - return; - - - try { - DuffCode[] any_dc_array = new DuffCode[0]; - DuffCode[] dc_array; - Position endPos = getTibDoc().createPosition(end); - int i = start; - java.util.List dcs = new ArrayList(); - - while (i < endPos.getOffset()+1) { - AttributeSet attr - = getTibDoc().getCharacterElement(i).getAttributes(); - String fontName = StyleConstants.getFontFamily(attr); - int fontNum; - - if ((0 == (fontNum = TibetanMachineWeb.getTMWFontNumber(fontName))) || i==endPos.getOffset()) { - if (i != start) { - dc_array = (DuffCode[])dcs.toArray(any_dc_array); - getTibDoc().remove(start, i-start); - append(start, TibTextUtils.getWylie(dc_array), romanAttributeSet); - dcs.clear(); - } - start = i+1; - } else { - char ch = getTibDoc().getText(i,1).charAt(0); - dcs.add(new DuffCode(fontNum, ch)); - ++numAttemptedReplacements[0]; - } - - i++; - } - } catch (BadLocationException ble) { - ble.printStackTrace(); - ThdlDebug.noteIffyCode(); - } - } - /** * Converts a string of Extended Wylie to TibetanMachineWeb, and * inserts it at the specified position. diff --git a/source/org/thdl/tib/input/Jskad.java b/source/org/thdl/tib/input/Jskad.java index 14704d8..2127934 100644 --- a/source/org/thdl/tib/input/Jskad.java +++ b/source/org/thdl/tib/input/Jskad.java @@ -1076,8 +1076,9 @@ public class Jskad extends JPanel implements DocumentListener { private void toWylie() { Jskad.this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); - long n[] = new long[] { 0 }; - dp.toWylie(dp.getSelectionStart(), dp.getSelectionEnd(), n); + ((TibetanDocument)dp.getDocument()).toWylie(dp.getSelectionStart(), + dp.getSelectionEnd(), + new long[] { 0 }); Jskad.this.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); } diff --git a/source/org/thdl/tib/input/TibetanConverter.java b/source/org/thdl/tib/input/TibetanConverter.java index cc75d54..62867a2 100644 --- a/source/org/thdl/tib/input/TibetanConverter.java +++ b/source/org/thdl/tib/input/TibetanConverter.java @@ -19,6 +19,7 @@ Contributor(s): ______________________________________. package org.thdl.tib.input; import java.io.*; +import javax.swing.text.rtf.RTFEditorKit; import org.thdl.util.*; import org.thdl.tib.text.*; @@ -180,13 +181,13 @@ public class TibetanConverter implements FontConverterConstants { return code so that TibetanConverter's usage message is honored. */ static int reallyConvert(InputStream in, PrintStream out, String ct) { - DuffPane dp = new DuffPane(); + TibetanDocument tdoc = new TibetanDocument(); try { // Read in the rtf file. if (debug) System.err.println("Start: reading in old RTF file"); if (!ThdlOptions.getBooleanOption("thdl.do.not.fix.rtf.hex.escapes")) in = new RTFFixerInputStream(in); - dp.rtfEd.read(in, dp.getDocument(), 0); + (new RTFEditorKit()).read(in, tdoc, 0); if (debug) System.err.println("End : reading in old RTF file"); } catch (Exception e) { out.println("TibetanConverter:\n" @@ -205,28 +206,28 @@ public class TibetanConverter implements FontConverterConstants { if (FIND_ALL_NON_TMW == ct) { // 0, -1 is the entire document. int exitCode - = ((TibetanDocument)dp.getDocument()).findAllNonTMWCharacters(0, -1, out); + = tdoc.findAllNonTMWCharacters(0, -1, out); if (out.checkError()) exitCode = 41; return exitCode; } else if (FIND_SOME_NON_TMW == ct) { // 0, -1 is the entire document. int exitCode - = ((TibetanDocument)dp.getDocument()).findSomeNonTMWCharacters(0, -1, out); + = tdoc.findSomeNonTMWCharacters(0, -1, out); if (out.checkError()) exitCode = 41; return exitCode; } else if (FIND_SOME_NON_TM == ct) { // 0, -1 is the entire document. int exitCode - = ((TibetanDocument)dp.getDocument()).findSomeNonTMCharacters(0, -1, out); + = tdoc.findSomeNonTMCharacters(0, -1, out); if (out.checkError()) exitCode = 41; return exitCode; } else if (FIND_ALL_NON_TM == ct) { // 0, -1 is the entire document. int exitCode - = ((TibetanDocument)dp.getDocument()).findAllNonTMCharacters(0, -1, out); + = tdoc.findAllNonTMCharacters(0, -1, out); if (out.checkError()) exitCode = 41; return exitCode; @@ -235,7 +236,7 @@ public class TibetanConverter implements FontConverterConstants { if (TM_TO_TMW != ct) { // DLC make me optional if (debug) System.err.println("Start: solving curly brace problem"); - ((TibetanDocument)dp.getDocument()).replaceTahomaCurlyBracesAndBackslashes(0, -1); + tdoc.replaceTahomaCurlyBracesAndBackslashes(0, -1); if (debug) System.err.println("End : solving curly brace problem"); } @@ -248,24 +249,25 @@ public class TibetanConverter implements FontConverterConstants { long numAttemptedReplacements[] = new long[] { 0 }; if (TMW_TO_WYLIE == ct) { // Convert to THDL Wylie: - dp.toWylie(0, dp.getDocument().getLength(), - numAttemptedReplacements); + tdoc.toWylie(0, + tdoc.getLength(), + numAttemptedReplacements); } else if (TMW_TO_UNI == ct) { StringBuffer errors = new StringBuffer(); // Convert to Unicode: - if (((TibetanDocument)dp.getDocument()).convertToUnicode(0, - dp.getDocument().getLength(), - errors, - ThdlOptions.getStringOption("thdl.tmw.to.unicode.font").intern(), - numAttemptedReplacements)) { + if (tdoc.convertToUnicode(0, + tdoc.getLength(), + errors, + ThdlOptions.getStringOption("thdl.tmw.to.unicode.font").intern(), + numAttemptedReplacements)) { System.err.println(errors); exitCode = 42; } } else if (TM_TO_TMW == ct) { StringBuffer errors = new StringBuffer(); // Convert to TibetanMachineWeb: - if (((TibetanDocument)dp.getDocument()).convertToTMW(0, dp.getDocument().getLength(), errors, - numAttemptedReplacements)) { + if (tdoc.convertToTMW(0, tdoc.getLength(), errors, + numAttemptedReplacements)) { System.err.println(errors); exitCode = 42; } @@ -273,8 +275,8 @@ public class TibetanConverter implements FontConverterConstants { ThdlDebug.verify(TMW_TO_TM == ct); StringBuffer errors = new StringBuffer(); // Convert to TibetanMachine: - if (((TibetanDocument)dp.getDocument()).convertToTM(0, dp.getDocument().getLength(), errors, - numAttemptedReplacements)) { + if (tdoc.convertToTM(0, tdoc.getLength(), errors, + numAttemptedReplacements)) { System.err.println(errors); exitCode = 42; } @@ -282,7 +284,7 @@ public class TibetanConverter implements FontConverterConstants { // Write to standard output the result: try { - ((TibetanDocument)dp.getDocument()).writeRTFOutputStream(out); + tdoc.writeRTFOutputStream(out); } catch (IOException e) { exitCode = 40; } diff --git a/source/org/thdl/tib/text/TibetanDocument.java b/source/org/thdl/tib/text/TibetanDocument.java index 224ad0a..53f3ee0 100644 --- a/source/org/thdl/tib/text/TibetanDocument.java +++ b/source/org/thdl/tib/text/TibetanDocument.java @@ -1076,6 +1076,73 @@ public class TibetanDocument extends DefaultStyledDocument { ThdlDebug.noteIffyCode(); } } + + /** the attribute set applied to Roman text in this + document */ + private AttributeSet romanAttributeSet = null; + + /** Gets the attribute set applied to Roman text in this + document. */ + public AttributeSet getRomanAttributeSet() { + return romanAttributeSet; + } + + /** Sets the attribute set applied to Roman text in this + document. */ + public void setRomanAttributeSet(AttributeSet ras) { + romanAttributeSet = ras; + } + +/** +* Converts the specified portion of this document to THDL Extended +* Wylie. +* +* @param start the point from which to begin converting to Wylie +* @param end the point at which to stop converting to Wylie +* @param numAttemptedReplacements an array that contains one element; +* this first element will be, upon exit, incremented by the number of +* TMW glyphs that we encountered and attempted to convert to Wylie */ + public void toWylie(int start, int end, + long numAttemptedReplacements[]) { + if (start >= end) + return; + + try { + DuffCode[] any_dc_array = new DuffCode[0]; + DuffCode[] dc_array; + Position endPos = createPosition(end); + int i = start; + java.util.List dcs = new ArrayList(); + + while (i < endPos.getOffset()+1) { + AttributeSet attr + = getCharacterElement(i).getAttributes(); + String fontName = StyleConstants.getFontFamily(attr); + int fontNum; + + if ((0 == (fontNum = TibetanMachineWeb.getTMWFontNumber(fontName))) || i==endPos.getOffset()) { + if (i != start) { + dc_array = (DuffCode[])dcs.toArray(any_dc_array); + remove(start, i-start); + insertString(start, + TibTextUtils.getWylie(dc_array), + getRomanAttributeSet()); + dcs.clear(); + } + start = i+1; + } else { + char ch = getText(i,1).charAt(0); + dcs.add(new DuffCode(fontNum, ch)); + ++numAttemptedReplacements[0]; + } + + i++; + } + } catch (BadLocationException ble) { + ble.printStackTrace(); + ThdlDebug.noteIffyCode(); + } + } /** Returns all the paragraph elements in this document that * contain glyphs with offsets in the range [start, end) where