diff --git a/source/options.txt b/source/options.txt index ea452fa..86ea267 100644 --- a/source/options.txt +++ b/source/options.txt @@ -122,3 +122,8 @@ thdl.add.developer.options.to.menu = false # you about the messy details of how Jskad decides when and where to # break lines for display. thdl.log.line.breaking.algorithm = false + +# Java Swing's RTF support is buggy. The hex escape sequence \'97 +# disappears from the input. We turn these guys into Unicode escapes +# when this is false. We leave it buggy when this is true. +thdl.do.not.fix.rtf.hex.escapes = false diff --git a/source/org/thdl/tib/input/DuffPane.java b/source/org/thdl/tib/input/DuffPane.java index 12170c9..d02fc1e 100644 --- a/source/org/thdl/tib/input/DuffPane.java +++ b/source/org/thdl/tib/input/DuffPane.java @@ -33,6 +33,7 @@ import org.thdl.tib.text.*; import org.thdl.util.ThdlDebug; import org.thdl.util.ThdlOptions; import org.thdl.util.StatusBar; +import org.thdl.util.RTFFixerInputStream; /** * Enables input of Tibetan text @@ -1036,6 +1037,8 @@ public void paste(int offset) { boolean errorReading = false; try { + if (!ThdlOptions.getBooleanOption("thdl.do.not.fix.rtf.hex.escapes")) + in = new RTFFixerInputStream(in); rtfEd.read(in, sd, 0); } catch (Exception e) { errorReading = true; @@ -1047,7 +1050,7 @@ public void paste(int offset) { /** Added by AM, to fix copy-paste issues for Translation Tool. Assumes that if roman is disabled and you are pasting something in RTF but - is not TibetanMachineWeb it most be wylie. */ + it is not TibetanMachineWeb then it must be wylie. */ if (!sd.getFont((sd.getCharacterElement(0).getAttributes())).getFamily().startsWith("TibetanMachineWeb") && !isRomanEnabled && contents.isDataFlavorSupported(DataFlavor.stringFlavor)) diff --git a/source/org/thdl/tib/input/Jskad.java b/source/org/thdl/tib/input/Jskad.java index a52fff0..6f90fcb 100644 --- a/source/org/thdl/tib/input/Jskad.java +++ b/source/org/thdl/tib/input/Jskad.java @@ -35,6 +35,7 @@ import java.util.Vector; import org.thdl.tib.text.*; import org.thdl.util.ThdlDebug; +import org.thdl.util.RTFFixerInputStream; import org.thdl.util.ThdlOptions; import org.thdl.util.ThdlVersion; import org.thdl.util.StatusBar; @@ -435,6 +436,19 @@ public class Jskad extends JPanel implements DocumentListener { toolsMenu.add(DevelItem); } + if (ThdlOptions.getBooleanOption("thdl.add.developer.options.to.menu")) { + toolsMenu.addSeparator(); + JMenuItem DevelItem = new JMenuItem("Debug dump to standard output"); + DevelItem.addActionListener(new ThdlActionListener() { + public void theRealActionPerformed(ActionEvent e) { + StringBuffer buf = new StringBuffer(); + ((TibetanDocument)dp.getDocument()).getTextRepresentation(0, -1, buf); + System.out.println("The text representation of the document, for debugging, is this:\n" + buf); + } + }); + toolsMenu.add(DevelItem); + } + if (ThdlOptions.getBooleanOption("thdl.add.developer.options.to.menu")) { toolsMenu.addSeparator(); JMenuItem DevelItem = new JMenuItem("Check for non-TMW characters"); // FIXME: do it just in the selection? @@ -764,6 +778,8 @@ public class Jskad extends JPanel implements DocumentListener { if (dp.getDocument().getLength()>0 && parentObject instanceof JFrame) { JFrame parentFrame = (JFrame)parentObject; InputStream in = new FileInputStream(fileChosen); + if (!ThdlOptions.getBooleanOption("thdl.do.not.fix.rtf.hex.escapes")) + in = new RTFFixerInputStream(in); ThdlOptions.setUserPreference("thdl.Jskad.working.directory", fileChosen.getParentFile().getAbsolutePath()); JFrame newFrame = new JFrame(f_name); @@ -798,6 +814,8 @@ public class Jskad extends JPanel implements DocumentListener { } } else { InputStream in = new FileInputStream(fileChosen); + if (!ThdlOptions.getBooleanOption("thdl.do.not.fix.rtf.hex.escapes")) + in = new RTFFixerInputStream(in); ThdlOptions.setUserPreference("thdl.Jskad.working.directory", fileChosen.getParentFile().getAbsolutePath()); dp.newDocument(); @@ -1229,9 +1247,11 @@ public class Jskad extends JPanel implements DocumentListener { /** Stores all open Jskad sessions. */ private static Vector jskads = new Vector(); - /** Closes all Jskad windows after asking "Do you want to save?" - for the modified windows. If you don't cancel for any unsaved - session, then all sessions are closed. */ + /** Closes all Jskad windows if user confirms. After asking "Do + you want to save?" for the modified windows, this closes them + all. If you don't cancel for any unsaved session, then all + sessions are closed. If you do cancel for any one, even the + last one, then all sessions remain open. */ private static void exitAction() { int sz = jskads.size(); for (int i = 0; i < sz; i++) { diff --git a/source/org/thdl/tib/input/TibetanConverter.java b/source/org/thdl/tib/input/TibetanConverter.java index e7358ef..8084435 100644 --- a/source/org/thdl/tib/input/TibetanConverter.java +++ b/source/org/thdl/tib/input/TibetanConverter.java @@ -183,6 +183,8 @@ public class TibetanConverter implements FontConverterConstants { 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); if (debug) System.err.println("End : reading in old RTF file"); } catch (Exception e) { diff --git a/source/org/thdl/tib/text/TibetanMachineWeb.java b/source/org/thdl/tib/text/TibetanMachineWeb.java index 5c259a3..0e9b88b 100644 --- a/source/org/thdl/tib/text/TibetanMachineWeb.java +++ b/source/org/thdl/tib/text/TibetanMachineWeb.java @@ -1015,8 +1015,12 @@ private static final DuffCode TMW_tab = new DuffCode(1, '\t'); public static DuffCode mapTMtoTMW(int font, int ordinal, int suggestedFont) { if (font < 0 || font > 4) return null; - if (ordinal >= 255) - return getUnusualTMtoTMW(font, ordinal); + if (ordinal >= 255) { + DuffCode rv = getUnusualTMtoTMW(font, ordinal); + if (null != rv && !ThdlOptions.getBooleanOption("thdl.do.not.fix.rtf.hex.escapes")) + throw new Error("oddballs still found after fixing RTF hex escapes"); + return rv; + } if (ordinal < 32) { if (ordinal == (int)'\r') { if (0 == suggestedFont)