Jskad has a new menu item, 'Copy as Unicode', which does a

TMW->Unicode conversion.
This commit is contained in:
dchandler 2005-02-26 22:57:38 +00:00
parent 25f5440218
commit 9cfedadab7
4 changed files with 183 additions and 58 deletions

View File

@ -949,8 +949,13 @@ public class DuffPane extends TibetanPane implements FocusListener {
appendStatus(" (because the window focus was lost)");
}
/** Copies the current selection to the system clipboard, unless
cut-and-paste operations are disabled. */
/** Converts the current selection to Unicode and then copies that
Unicode to the system clipboard. */
public void copyAsUnicode() {
copyOrCutToUnicode(getSelectionStart(), getSelectionEnd(), false);
}
/** Copies the current selection to the system clipboard. */
public void copy() {
copy(getSelectionStart(), getSelectionEnd(), false);
}
@ -991,29 +996,98 @@ public class DuffPane extends TibetanPane implements FocusListener {
* false if it is 'copy'
*/
private void copy(int start, int end, boolean remove) {
int p1 = start;
int p2 = end;
if (p1 != p2) {
if (start != end) {
ThdlDebug.verify(getDocument() == getTibDoc());
RTFSelection rtfSelection = new RTFSelection((StyledDocument)getDocument(), p1, p2-p1);
RTFSelection rtfSelection
= new RTFSelection((StyledDocument)getDocument(),
start, end-start);
try {
rtfBoard.setContents(rtfSelection, rtfSelection);
updateStatus("Copied to clipboard");
} catch (IllegalStateException ise) {
// TODO(dchandler): let's show a dialog box. The user
// should know that another app is monopolizing the
// clipboard.
ise.printStackTrace();
ThdlDebug.noteIffyCode();
}
} else
updateStatus("Nothing to copy/cut");
if (remove) {
// Respect setEditable(boolean):
if (!this.isEditable())
return;
if (remove && this.isEditable()) {
try {
ThdlDebug.verify(getDocument() == getTibDoc());
getDocument().remove(p1, p2-p1);
getDocument().remove(start, end-start);
updateStatus("Cut to clipboard");
} catch (BadLocationException ble) {
ble.printStackTrace();
ThdlDebug.noteIffyCode();
}
}
}
/** Adds to the clipboard the Unicode you'd get if you used a
TMW->Unicode conversion on the specified portion of the
document. This is plain-text Unicode, not RTF. We lose info
about font size, formatting like centering etc. */
private void copyOrCutToUnicode(int start, int end, boolean remove) {
if (start != end) {
ThdlDebug.verify(getDocument() == getTibDoc());
// construct new document that contains only portion of
// text you want to copy/cut so that we can use
// TibetanDocument.convertToUnicode(..).
TibetanDocument newDoc = new TibetanDocument();
boolean warn_about_tm = false;
for (int i = start; i < end; i++) {
try {
String s = getTibDoc().getText(i,1);
AttributeSet as
= getTibDoc().getCharacterElement(i).getAttributes();
String fontName = StyleConstants.getFontFamily(as);
if (0 != TibetanMachineWeb.getTMFontNumber(fontName))
warn_about_tm = true;
newDoc.insertString(i - start, s, as);
} catch (BadLocationException ble) {
ble.printStackTrace();
ThdlDebug.noteIffyCode();
}
}
String unicode = "[Jskad: Converting to Unicode failed.]";
if (newDoc.convertToUnicode(0, newDoc.getLength(), null, null,
new long[] { 0 })) {
// TODO(dchandler): better error handling!
} else {
try {
unicode = newDoc.getText(0, newDoc.getLength());
if (warn_about_tm)
unicode
= ("[Jskad: Warning while copying as Unicode: We convert TibetanMachineWeb to Unicode but not TibetanMachine during this operation, but there was some TibetanMachine text present. This will appear as garbage! Convert your TibetanMachine to TibetanMachineWeb and try again if you want perfect results.]"
+ unicode);
if (start != end && unicode.length() == 0)
unicode = "[Jskad: Converting to Unicode shouldn't have produced the empty string! This is a bug in Jskad.]";
} catch (BadLocationException ble) {
// This should never happen.
unicode = "[Jskad: Oops! bigtime bug 13412412kjlwe32]";
}
}
StringSelection uSelection = new StringSelection(unicode);
try {
rtfBoard.setContents(uSelection, uSelection);
updateStatus("Copied to clipboard");
} catch (IllegalStateException ise) {
// TODO(dchandler): let's show a dialog box. The user
// should know that another app is monopolizing the
// clipboard.
ise.printStackTrace();
ThdlDebug.noteIffyCode();
}
} else
updateStatus("Nothing to copy/cut");
if (remove && this.isEditable()) {
try {
ThdlDebug.verify(getDocument() == getTibDoc());
getDocument().remove(start, end-start);
updateStatus("Cut to clipboard");
} catch (BadLocationException ble) {
ble.printStackTrace();
@ -1634,18 +1708,17 @@ public void paste(int offset)
/** The JDK contains StringSelection, but we want to copy and paste
RTF sometimes. Enter RTFSelection. */
class RTFSelection implements ClipboardOwner, Transferable {
private DataFlavor[] supportedFlavors;
private final DataFlavor[] supportedFlavors
= new DataFlavor[] { rtfFlavor, DataFlavor.stringFlavor };
private ByteArrayOutputStream rtfOut;
private String plainText;
RTFSelection(StyledDocument sdoc, int offset, int length) {
supportedFlavors = new DataFlavor[2];
supportedFlavors[0] = rtfFlavor;
supportedFlavors[1] = DataFlavor.stringFlavor;
try {
//construct new document that contains only portion of text you want to copy
//this workaround is due to bug 4129911, which will not be fixed
// construct new document that contains only portion of
// text you want to copy this workaround is due to bug
// 4129911, which will not be fixed
//
// TODO(dchandler): Is this where we lose formatting like
// centering and indention?
StyledDocument newDoc = new DefaultStyledDocument();
@ -1659,12 +1732,11 @@ class RTFSelection implements ClipboardOwner, Transferable {
ThdlDebug.noteIffyCode();
}
}
plainText = getText(offset, length);
rtfOut = new ByteArrayOutputStream();
//last two parameters ignored (bug 4129911?):
rtfEd.write(rtfOut, newDoc, 0, newDoc.getLength());
plainText = getText(offset, length);
} catch (BadLocationException ble) {
ble.printStackTrace();
ThdlDebug.noteIffyCode();
@ -1683,9 +1755,7 @@ class RTFSelection implements ClipboardOwner, Transferable {
return null;
}
public DataFlavor[] getTransferDataFlavors() {
// TODO(dchandler): Can't the caller modify our array? Let's
// return a new array that's a copy, for safety.
return supportedFlavors;
return (DataFlavor[])supportedFlavors.clone();
}
public boolean isDataFlavorSupported(DataFlavor flavor) {
for (int i=0; i<supportedFlavors.length; i++)
@ -1693,6 +1763,6 @@ class RTFSelection implements ClipboardOwner, Transferable {
return true;
return false;
}
} // class RTFSelection
} // inner class DuffPane.RTFSelection
}
} // class DuffPane

View File

@ -365,6 +365,14 @@ public class Jskad extends JPanel implements DocumentListener {
});
editMenu.add(copyItem);
JMenuItem copyAsUnicodeItem = new JMenuItem("Copy as Unicode");
copyAsUnicodeItem.addActionListener(new ThdlActionListener() {
public void theRealActionPerformed(ActionEvent e) {
copyAsUnicodeSelection();
}
});
editMenu.add(copyAsUnicodeItem);
JMenuItem pasteItem = new JMenuItem("Paste");
pasteItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V,
java.awt.Event.CTRL_MASK)); //Ctrl-v
@ -1147,6 +1155,10 @@ public class Jskad extends JPanel implements DocumentListener {
dp.copy();
}
private void copyAsUnicodeSelection() {
dp.copyAsUnicode();
}
private void pasteSelection() {
dp.paste(dp.getCaret().getDot());
}

View File

@ -14,7 +14,8 @@
<li><a href="#start">Getting Started</a></li>
<li><a href="#tibetan">Typing Tibetan</a></li>
<li><a href="#english">Typing English</a></li>
<li><a href="#copypaste">Copying and Pasting</a></li>
<li><a href="#copypaste">Copying and Pasting TM/TMW</a></li>
<li><a href="#copyasunicode">Copying as Unicode</a></li>
<li><a href="#wylietotmw">Converting Wylie to Tibetan</a></li>
<li><a href="#tmwtowylie">Converting Tibetan to Wylie</a></li>
<li><a href="#ttot">Converting Tibetan to Tibetan</a></li>
@ -50,8 +51,8 @@ produce a document without the warning messages.
<p>
Jskad now has first-class support for converting entire
documents.&nbsp; You can convert ACIP to Unicode, ACIP to Tibetan
Machine Web (or TMW, or simply "Tibetan" in the menus), Tibetan
Machine to TMW and vice versa, TMW to ACIP, TMW to Unicode, and TMW to
Machine Web ("TMW", or simply "Tibetan" in the menus), Tibetan Machine
("TM") to TMW and vice versa, TMW to ACIP, TMW to Unicode, and TMW to
Wylie (i.e., EWTS).&nbsp; Try it from the Tools menu.&nbsp; Full
documentation is <a
href="http://thdltools.sourceforge.net/TMW_RTF_TO_THDL_WYLIE.html">online</a>.
@ -59,8 +60,11 @@ href="http://thdltools.sourceforge.net/TMW_RTF_TO_THDL_WYLIE.html">online</a>.
<p>
Be on the lookout for formatting changes; Java's RTF support is
currently poor.<!-- DLC FIXME: do this correctly, not in a "Latest
Changes" section. -->
currently poor and it's hard to fix Java because (as of February
2005) Java is not available under an OSI-approved open-source
license.&nbsp; You will lose some formatting like centering and some
indention when to convert from RTF to RTF.<!-- DLC FIXME: do this
correctly, not in a "Latest Changes" section. -->
</p>
<p>
@ -96,7 +100,8 @@ Machine Web</a> family of fonts installed; they are now embedded in
Jskad itself along with the <a
href="http://iris.lib.virginia.edu/tibet/tools/tm.html">Tibetan
Machine</a> family of fonts.&nbsp; But if you wish to copy and paste
into another application, then you do need the <a
into another application as Tibetan Machine Web (rather than as
Unicode), then you do need the <a
href="http://iris.lib.virginia.edu/tibet/tools/tmw.html">Tibetan
Machine Web</a> family of fonts installed.
</p>
@ -150,9 +155,10 @@ As...' lets you save under a new name.
<p>
The 'Edit' menu lets you cut, copy, and paste Tibetan text and set
document preferences.&nbsp; These topics are covered elsewhere, in <a
href="#copypaste">Copying and Pasting</a>, <a href="#tibetan">Typing
Tibetan</a>, <a href="#english">Typing English</a>, and <a
href="#preferences">Preferences</a>.
href="#copypaste">Copying and Pasting TM/TMW</a>, <a
href="#copyasunicode">Copying as Unicode</a>, <a
href="#tibetan">Typing Tibetan</a>, <a href="#english">Typing
English</a>, and <a href="#preferences">Preferences</a>.
</p>
<p>
@ -174,19 +180,19 @@ href="#tmwtowylie">Converting Tibetan to Wylie</a>. -->
<p>
Jskad lets you input Tibetan text according to several popular
keyboard input methods.&nbsp; The default keyboard is the <a
keyboard input methods.&nbsp; The default keyboard is the <!-- <a
href="http://iris.lib.virginia.edu/tibet/tools/jskad_docs/Wylie_keyboard.rtf"
target="_blank">Extended Wylie</a> keyboard.&nbsp; Other supported
keyboards include <a
target="_blank"> -->Extended Wylie<!-- </a> --> keyboard.&nbsp; Other
supported keyboards include <!-- <a
href="http://iris.lib.virginia.edu/tibet/tools/jskad_docs/TCC_keyboard_1.rtf"
target="_blank">Tibetan Computer Company Keyboard #1</a>, <a
target="_blank"> -->Tibetan Computer Company Keyboard #1<!-- </a> -->,
<!-- <a
href="http://iris.lib.virginia.edu/tibet/tools/jskad_docs/TCC_keyboard_2.rtf"
target="_blank">Tibetan Computer Company Keyboard #2</a> , and
Nitharta's <a
target="_blank"> -->Tibetan Computer Company Keyboard #2<!-- </a> -->
, and Nitharta's <!-- <a
href="http://iris.lib.virginia.edu/tibet/tools/jskad_docs/Sambhota_keymap_one.rtf"
target="_blank">Sambhota Keymap One</a>.&nbsp; There is an ACIP
keyboard also, but it is pre-alpha; there are various known bugs with
it.
target="_blank"> -->Sambhota Keymap One<!-- </a> -->.&nbsp; For
documentation of these keyboards, see Jskad's 'Help' menu.
</p>
<p>
@ -226,15 +232,48 @@ selecting 'Preferences' from the 'Edit' menu.
<center><font size="-1"><a href="#top">Back to top</a></font></center>
</p>
<a name="copyasunicode"></a>
<h3>Copying as Unicode</h3>
<p>
In addition to supporting <a href="#copypaste">copying and pasting TM
and TMW</a>, Jskad supports copying Tibetan Machine Web as Unicode.
</p>
<p>
This effectively does a <a
href="http://thdltools.sourceforge.net/TMW_RTF_TO_THDL_WYLIE.html">TMW-&gt;Unicode</a>
conversion and then copies the output to the system clipboard, ready
to be pasted into MS Word, OpenOffice, Notepad, or wherever.
Depending on how smart the target application is, you may have to
explicitly tell it to use a Tibetan Unicode font such as THDL's own
Tibetan Machine Uni.
</p>
<p>
<font color="red">NOTE WELL</font> that OpenOffice 1.1.4 has a bug
whereby the parts of your selection that were not Tibetan Machine Web
are silently dropped if you paste into a section of Tibetan Unicode.
If this affects you, you should paste into a section of English text.
</p>
<a name="copypaste"></a>
<h3>Copying and Pasting</h3>
<h3>Copying and Pasting TM/TMW</h3>
<p>
In addition to supporting <a href="#copyasunicode">copying to Unicode
text</a>, Jskad supports copying and pasting Tibetan Machine Web.
</p>
<p>
Jskad supports RTF copy and paste.&nbsp; That means, among other
things, that you can copy Tibetan back and forth between Microsoft
Word and Jskad.&nbsp; To do so, you can use standard keyboard
shortcuts (Ctrl-A for select all, Ctrl-X for cut, Ctrl-C for copy, and
Ctrl-V for paste).&nbsp; Note that you must have the <a
things, that you can copy Tibetan Machine and Tibetan Machine Web back
and forth between Jskad and Microsoft Word or OpenOffice.&nbsp; To do
so, you can use standard keyboard shortcuts (Ctrl-A for select all,
Ctrl-X for cut, Ctrl-C for copy, and Ctrl-V for paste).&nbsp; Note
that you must have the <a
href="http://iris.lib.virginia.edu/tibet/tools/tmw.html">Tibetan
Machine Web</a> family of fonts installed on your computer for
applications besides Jskad to be aware of them.
@ -465,21 +504,21 @@ As already mentioned, Jskad supports four different keyboard input methods:
</p>
<ol>
<li><a
<li><!-- <a
href="http://iris.lib.virginia.edu/tibet/tools/jskad_docs/Wylie_keyboard.rtf"
target="_blank">Extended Wylie</a></li>
target="_blank"> -->Extended Wylie<!-- </a> --></li>
<li><a
<li><!-- <a
href="http://iris.lib.virginia.edu/tibet/tools/jskad_docs/TCC_keyboard_1.rtf"
target="_blank">Tibetan Computer Company Keyboard #1</a></li>
target="_blank"> -->Tibetan Computer Company Keyboard #1<!-- </a> --></li>
<li><a
<li><!-- <a
href="http://iris.lib.virginia.edu/tibet/tools/jskad_docs/TCC_keyboard_2.rtf"
target="_blank">Tibetan Computer Company Keyboard #2</a></li>
target="_blank"> -->Tibetan Computer Company Keyboard #2<!-- </a> --></li>
<li><a
<li><!-- <a
href="http://iris.lib.virginia.edu/tibet/tools/jskad_docs/Sambhota_keymap_one.rtf"
target="_blank">Sambhota Keymap One</a></li>
target="_blank"> -->Sambhota Keymap One<!-- </a> --></li>
</ol>
<p>

View File

@ -1081,13 +1081,17 @@ private int insertDuff(int fontSize, int pos, DuffData[] glyphs, boolean asTMW,
// FIXME: are we doing the right thing here? I
// think so -- I think we're just not replacing
// the current character, but I'm not at all sure.
if (debug > 0) System.out.println("non-tm/tmw found at offset " + i + "; font=" + fontName + " ord " + (int)getText(i,1).charAt(0));
if (debug > 0) System.out.println("some font we're not converting found at offset " + i + "; font=" + fontName + " ord " + (int)getText(i,1).charAt(0));
if (replacementQueue.length() > 0) {
if (!mustReplace) {
mustReplaceUntil = i;
mustReplace = true;
}
}
// TODO(dchandler): If this is a TMW->*
// conversion, generate a warning if TM is found.
// If this is a TM->* conversion, generate a
// warning if TMW is found.
}
i++;
}