TMW->Wylie now occurs in the TibetanDocument, not in DuffPane,
which means that the command-line tool can finally function with a headless graphics device. Hopefully it will speed things up, too. It also means that entering Roman text into the TMW->Unicode conversion and TMW->TM conversion will be easy.
This commit is contained in:
parent
61d29fc355
commit
6151a7bc94
4 changed files with 101 additions and 89 deletions
|
@ -190,7 +190,6 @@ public class DuffPane extends TibetanPane implements FocusListener {
|
||||||
|
|
||||||
private String romanFontFamily;
|
private String romanFontFamily;
|
||||||
private int romanFontSize;
|
private int romanFontSize;
|
||||||
private MutableAttributeSet romanAttributeSet;
|
|
||||||
|
|
||||||
private Clipboard rtfBoard;
|
private Clipboard rtfBoard;
|
||||||
|
|
||||||
|
@ -337,7 +336,7 @@ public class DuffPane extends TibetanPane implements FocusListener {
|
||||||
if (isTibetan) {
|
if (isTibetan) {
|
||||||
processTibetanChar(key.charAt(0));
|
processTibetanChar(key.charAt(0));
|
||||||
} else {
|
} else {
|
||||||
processRomanChar(key, romanAttributeSet);
|
processRomanChar(key, getTibDoc().getRomanAttributeSet());
|
||||||
}
|
}
|
||||||
if (manageCaret) {
|
if (manageCaret) {
|
||||||
caret.setDot(getTibDoc().getLength());
|
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 attr the attributes for the text to insert
|
||||||
* @param s the string of 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);
|
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 attr the attributes for the text to insert
|
||||||
* @param s the string of 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 {
|
try {
|
||||||
getTibDoc().insertString(offset, s, attr);
|
getTibDoc().insertString(offset, s, attr);
|
||||||
}
|
}
|
||||||
|
@ -617,9 +616,12 @@ public class DuffPane extends TibetanPane implements FocusListener {
|
||||||
* @param size a point size
|
* @param size a point size
|
||||||
*/
|
*/
|
||||||
public void setRomanAttributeSet(String font, int size) {
|
public void setRomanAttributeSet(String font, int size) {
|
||||||
romanAttributeSet = new SimpleAttributeSet();
|
if (getTibDoc() != null) {
|
||||||
StyleConstants.setFontFamily(romanAttributeSet, font);
|
SimpleAttributeSet ras = new SimpleAttributeSet();
|
||||||
StyleConstants.setFontSize(romanAttributeSet, size);
|
StyleConstants.setFontFamily(ras, romanFontFamily = font);
|
||||||
|
StyleConstants.setFontSize(ras, romanFontSize = size);
|
||||||
|
getTibDoc().setRomanAttributeSet(ras);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Like {@link #setRomanAttributeSet}, but allows for noting the
|
/** Like {@link #setRomanAttributeSet}, but allows for noting the
|
||||||
|
@ -1120,7 +1122,7 @@ public void paste(int offset) {
|
||||||
isCutAndPasteEnabled = false;
|
isCutAndPasteEnabled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processRomanChar(String key, MutableAttributeSet attSet) {
|
private void processRomanChar(String key, AttributeSet attSet) {
|
||||||
switch (key.charAt(0)) {
|
switch (key.charAt(0)) {
|
||||||
case KeyEvent.VK_TAB:
|
case KeyEvent.VK_TAB:
|
||||||
case KeyEvent.VK_ENTER:
|
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
|
* Converts a string of Extended Wylie to TibetanMachineWeb, and
|
||||||
* inserts it at the specified position.
|
* inserts it at the specified position.
|
||||||
|
|
|
@ -1076,8 +1076,9 @@ public class Jskad extends JPanel implements DocumentListener {
|
||||||
|
|
||||||
private void toWylie() {
|
private void toWylie() {
|
||||||
Jskad.this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
|
Jskad.this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
|
||||||
long n[] = new long[] { 0 };
|
((TibetanDocument)dp.getDocument()).toWylie(dp.getSelectionStart(),
|
||||||
dp.toWylie(dp.getSelectionStart(), dp.getSelectionEnd(), n);
|
dp.getSelectionEnd(),
|
||||||
|
new long[] { 0 });
|
||||||
Jskad.this.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
|
Jskad.this.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@ Contributor(s): ______________________________________.
|
||||||
package org.thdl.tib.input;
|
package org.thdl.tib.input;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
import javax.swing.text.rtf.RTFEditorKit;
|
||||||
|
|
||||||
import org.thdl.util.*;
|
import org.thdl.util.*;
|
||||||
import org.thdl.tib.text.*;
|
import org.thdl.tib.text.*;
|
||||||
|
@ -180,13 +181,13 @@ public class TibetanConverter implements FontConverterConstants {
|
||||||
return code so that TibetanConverter's usage message is
|
return code so that TibetanConverter's usage message is
|
||||||
honored. */
|
honored. */
|
||||||
static int reallyConvert(InputStream in, PrintStream out, String ct) {
|
static int reallyConvert(InputStream in, PrintStream out, String ct) {
|
||||||
DuffPane dp = new DuffPane();
|
TibetanDocument tdoc = new TibetanDocument();
|
||||||
try {
|
try {
|
||||||
// Read in the rtf file.
|
// Read in the rtf file.
|
||||||
if (debug) System.err.println("Start: reading in old RTF file");
|
if (debug) System.err.println("Start: reading in old RTF file");
|
||||||
if (!ThdlOptions.getBooleanOption("thdl.do.not.fix.rtf.hex.escapes"))
|
if (!ThdlOptions.getBooleanOption("thdl.do.not.fix.rtf.hex.escapes"))
|
||||||
in = new RTFFixerInputStream(in);
|
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");
|
if (debug) System.err.println("End : reading in old RTF file");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
out.println("TibetanConverter:\n"
|
out.println("TibetanConverter:\n"
|
||||||
|
@ -205,28 +206,28 @@ public class TibetanConverter implements FontConverterConstants {
|
||||||
if (FIND_ALL_NON_TMW == ct) {
|
if (FIND_ALL_NON_TMW == ct) {
|
||||||
// 0, -1 is the entire document.
|
// 0, -1 is the entire document.
|
||||||
int exitCode
|
int exitCode
|
||||||
= ((TibetanDocument)dp.getDocument()).findAllNonTMWCharacters(0, -1, out);
|
= tdoc.findAllNonTMWCharacters(0, -1, out);
|
||||||
if (out.checkError())
|
if (out.checkError())
|
||||||
exitCode = 41;
|
exitCode = 41;
|
||||||
return exitCode;
|
return exitCode;
|
||||||
} else if (FIND_SOME_NON_TMW == ct) {
|
} else if (FIND_SOME_NON_TMW == ct) {
|
||||||
// 0, -1 is the entire document.
|
// 0, -1 is the entire document.
|
||||||
int exitCode
|
int exitCode
|
||||||
= ((TibetanDocument)dp.getDocument()).findSomeNonTMWCharacters(0, -1, out);
|
= tdoc.findSomeNonTMWCharacters(0, -1, out);
|
||||||
if (out.checkError())
|
if (out.checkError())
|
||||||
exitCode = 41;
|
exitCode = 41;
|
||||||
return exitCode;
|
return exitCode;
|
||||||
} else if (FIND_SOME_NON_TM == ct) {
|
} else if (FIND_SOME_NON_TM == ct) {
|
||||||
// 0, -1 is the entire document.
|
// 0, -1 is the entire document.
|
||||||
int exitCode
|
int exitCode
|
||||||
= ((TibetanDocument)dp.getDocument()).findSomeNonTMCharacters(0, -1, out);
|
= tdoc.findSomeNonTMCharacters(0, -1, out);
|
||||||
if (out.checkError())
|
if (out.checkError())
|
||||||
exitCode = 41;
|
exitCode = 41;
|
||||||
return exitCode;
|
return exitCode;
|
||||||
} else if (FIND_ALL_NON_TM == ct) {
|
} else if (FIND_ALL_NON_TM == ct) {
|
||||||
// 0, -1 is the entire document.
|
// 0, -1 is the entire document.
|
||||||
int exitCode
|
int exitCode
|
||||||
= ((TibetanDocument)dp.getDocument()).findAllNonTMCharacters(0, -1, out);
|
= tdoc.findAllNonTMCharacters(0, -1, out);
|
||||||
if (out.checkError())
|
if (out.checkError())
|
||||||
exitCode = 41;
|
exitCode = 41;
|
||||||
return exitCode;
|
return exitCode;
|
||||||
|
@ -235,7 +236,7 @@ public class TibetanConverter implements FontConverterConstants {
|
||||||
if (TM_TO_TMW != ct) {
|
if (TM_TO_TMW != ct) {
|
||||||
// DLC make me optional
|
// DLC make me optional
|
||||||
if (debug) System.err.println("Start: solving curly brace problem");
|
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");
|
if (debug) System.err.println("End : solving curly brace problem");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -248,24 +249,25 @@ public class TibetanConverter implements FontConverterConstants {
|
||||||
long numAttemptedReplacements[] = new long[] { 0 };
|
long numAttemptedReplacements[] = new long[] { 0 };
|
||||||
if (TMW_TO_WYLIE == ct) {
|
if (TMW_TO_WYLIE == ct) {
|
||||||
// Convert to THDL Wylie:
|
// Convert to THDL Wylie:
|
||||||
dp.toWylie(0, dp.getDocument().getLength(),
|
tdoc.toWylie(0,
|
||||||
numAttemptedReplacements);
|
tdoc.getLength(),
|
||||||
|
numAttemptedReplacements);
|
||||||
} else if (TMW_TO_UNI == ct) {
|
} else if (TMW_TO_UNI == ct) {
|
||||||
StringBuffer errors = new StringBuffer();
|
StringBuffer errors = new StringBuffer();
|
||||||
// Convert to Unicode:
|
// Convert to Unicode:
|
||||||
if (((TibetanDocument)dp.getDocument()).convertToUnicode(0,
|
if (tdoc.convertToUnicode(0,
|
||||||
dp.getDocument().getLength(),
|
tdoc.getLength(),
|
||||||
errors,
|
errors,
|
||||||
ThdlOptions.getStringOption("thdl.tmw.to.unicode.font").intern(),
|
ThdlOptions.getStringOption("thdl.tmw.to.unicode.font").intern(),
|
||||||
numAttemptedReplacements)) {
|
numAttemptedReplacements)) {
|
||||||
System.err.println(errors);
|
System.err.println(errors);
|
||||||
exitCode = 42;
|
exitCode = 42;
|
||||||
}
|
}
|
||||||
} else if (TM_TO_TMW == ct) {
|
} else if (TM_TO_TMW == ct) {
|
||||||
StringBuffer errors = new StringBuffer();
|
StringBuffer errors = new StringBuffer();
|
||||||
// Convert to TibetanMachineWeb:
|
// Convert to TibetanMachineWeb:
|
||||||
if (((TibetanDocument)dp.getDocument()).convertToTMW(0, dp.getDocument().getLength(), errors,
|
if (tdoc.convertToTMW(0, tdoc.getLength(), errors,
|
||||||
numAttemptedReplacements)) {
|
numAttemptedReplacements)) {
|
||||||
System.err.println(errors);
|
System.err.println(errors);
|
||||||
exitCode = 42;
|
exitCode = 42;
|
||||||
}
|
}
|
||||||
|
@ -273,8 +275,8 @@ public class TibetanConverter implements FontConverterConstants {
|
||||||
ThdlDebug.verify(TMW_TO_TM == ct);
|
ThdlDebug.verify(TMW_TO_TM == ct);
|
||||||
StringBuffer errors = new StringBuffer();
|
StringBuffer errors = new StringBuffer();
|
||||||
// Convert to TibetanMachine:
|
// Convert to TibetanMachine:
|
||||||
if (((TibetanDocument)dp.getDocument()).convertToTM(0, dp.getDocument().getLength(), errors,
|
if (tdoc.convertToTM(0, tdoc.getLength(), errors,
|
||||||
numAttemptedReplacements)) {
|
numAttemptedReplacements)) {
|
||||||
System.err.println(errors);
|
System.err.println(errors);
|
||||||
exitCode = 42;
|
exitCode = 42;
|
||||||
}
|
}
|
||||||
|
@ -282,7 +284,7 @@ public class TibetanConverter implements FontConverterConstants {
|
||||||
|
|
||||||
// Write to standard output the result:
|
// Write to standard output the result:
|
||||||
try {
|
try {
|
||||||
((TibetanDocument)dp.getDocument()).writeRTFOutputStream(out);
|
tdoc.writeRTFOutputStream(out);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
exitCode = 40;
|
exitCode = 40;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1076,6 +1076,73 @@ public class TibetanDocument extends DefaultStyledDocument {
|
||||||
ThdlDebug.noteIffyCode();
|
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
|
/** Returns all the paragraph elements in this document that
|
||||||
* contain glyphs with offsets in the range [start, end) where
|
* contain glyphs with offsets in the range [start, end) where
|
||||||
|
|
Loading…
Reference in a new issue