Added Than's converter GUI code; adapted it to work with Jskad's
converters. TMW->Unicode now uses Ximalaya by default.
This commit is contained in:
parent
19d7cabfe6
commit
f547734043
8 changed files with 830 additions and 74 deletions
46
build.xml
46
build.xml
|
@ -51,6 +51,7 @@
|
||||||
subdirectories of ${bin}. -->
|
subdirectories of ${bin}. -->
|
||||||
<property name="bin" location="bin"/>
|
<property name="bin" location="bin"/>
|
||||||
<property name="jskadbin" location="bin/jskad"/>
|
<property name="jskadbin" location="bin/jskad"/>
|
||||||
|
<property name="converterguibin" location="bin/convertergui"/>
|
||||||
<property name="tibbiblbin" location="bin/tibbibl"/>
|
<property name="tibbiblbin" location="bin/tibbibl"/>
|
||||||
<property name="junitbin" location="bin/for-junit"/>
|
<property name="junitbin" location="bin/for-junit"/>
|
||||||
<property name="ttstandalonebin" location="bin/tt-standalone"/>
|
<property name="ttstandalonebin" location="bin/tt-standalone"/>
|
||||||
|
@ -272,11 +273,11 @@
|
||||||
description="JARs up everything into self-contained JARs for double-click, classpath-worry-free joy" />
|
description="JARs up everything into self-contained JARs for double-click, classpath-worry-free joy" />
|
||||||
|
|
||||||
<target name="dist"
|
<target name="dist"
|
||||||
depends="jskad-dist,tt-handheld-dist,tt-standalone-dist,tt-applet-plus-jws-dist,tt-servlet-dist,tibbibl-dist"
|
depends="jskad-dist,tt-handheld-dist,tt-standalone-dist,tt-applet-plus-jws-dist,tt-servlet-dist,tibbibl-dist,convertergui-dist"
|
||||||
description="JARs up everything" />
|
description="JARs up everything" />
|
||||||
|
|
||||||
<target name="compile"
|
<target name="compile"
|
||||||
depends="jskad-compile,tt-standalone-compile,tt-handheld-compile,tt-applet-plus-jws-compile,tt-servlet-compile,tibbibl-compile"
|
depends="jskad-compile,tt-standalone-compile,tt-handheld-compile,tt-applet-plus-jws-compile,tt-servlet-compile,tibbibl-compile,convertergui-compile"
|
||||||
description="compiles all programs" />
|
description="compiles all programs" />
|
||||||
|
|
||||||
|
|
||||||
|
@ -309,6 +310,11 @@
|
||||||
<param name="my.included.source.file"
|
<param name="my.included.source.file"
|
||||||
value="org/thdl/tib/input/TibetanConverter.java"/>
|
value="org/thdl/tib/input/TibetanConverter.java"/>
|
||||||
</antcall>
|
</antcall>
|
||||||
|
<antcall target="our-internal-javac-task">
|
||||||
|
<param name="mybin" value="${jskadbin}"/>
|
||||||
|
<param name="my.included.source.file"
|
||||||
|
value="org/thdl/tib/input/ConverterGUI.java"/>
|
||||||
|
</antcall>
|
||||||
<antcall target="copy-ini-files-to-bin-dir-for-jarring">
|
<antcall target="copy-ini-files-to-bin-dir-for-jarring">
|
||||||
<param name="mybin" value="${jskadbin}"/>
|
<param name="mybin" value="${jskadbin}"/>
|
||||||
</antcall>
|
</antcall>
|
||||||
|
@ -331,6 +337,30 @@
|
||||||
</copy>
|
</copy>
|
||||||
</target>
|
</target>
|
||||||
|
|
||||||
|
<target name="convertergui-compile" depends="init"
|
||||||
|
description="compiles Convertergui" >
|
||||||
|
<mkdir dir="${converterguibin}"/>
|
||||||
|
<antcall target="create-timestamp-source-code"/> <!-- DLC NOW! The -run targets are mucking with this! It isn't fatal, but it should be fixed. -->
|
||||||
|
<antcall target="our-internal-javac-task">
|
||||||
|
<param name="mybin" value="${converterguibin}"/>
|
||||||
|
<param name="my.included.source.file"
|
||||||
|
value="org/thdl/tib/input/ConverterGUI.java"/>
|
||||||
|
</antcall>
|
||||||
|
<!-- Put TibetanConverter in this jar for those who want
|
||||||
|
to use it. -->
|
||||||
|
<antcall target="our-internal-javac-task">
|
||||||
|
<param name="mybin" value="${converterguibin}"/>
|
||||||
|
<param name="my.included.source.file"
|
||||||
|
value="org/thdl/tib/input/TibetanConverter.java"/>
|
||||||
|
</antcall>
|
||||||
|
<antcall target="copy-ini-files-to-bin-dir-for-jarring">
|
||||||
|
<param name="mybin" value="${converterguibin}"/>
|
||||||
|
</antcall>
|
||||||
|
<antcall target="copy-license-etc-to-bin-dir-for-jarring">
|
||||||
|
<param name="mybin" value="${converterguibin}"/>
|
||||||
|
</antcall>
|
||||||
|
</target>
|
||||||
|
|
||||||
<target name="tibbibl-compile" depends="init"
|
<target name="tibbibl-compile" depends="init"
|
||||||
description="compiles Tibbibl" >
|
description="compiles Tibbibl" >
|
||||||
<mkdir dir="${tibbiblbin}"/>
|
<mkdir dir="${tibbiblbin}"/>
|
||||||
|
@ -603,6 +633,18 @@
|
||||||
</target>
|
</target>
|
||||||
|
|
||||||
|
|
||||||
|
<target name="convertergui-dist" depends="convertergui-compile"
|
||||||
|
description="generates the bare ConverterGUI binary distribution" >
|
||||||
|
<!-- Put everything in ${converterguibin} into the JAR file -->
|
||||||
|
<jar jarfile="${lib}/TibetanConverterGUI${my.jar.suffix}.jar"
|
||||||
|
basedir="${converterguibin}">
|
||||||
|
<manifest>
|
||||||
|
<attribute name="Main-Class" value="org.thdl.tib.input.ConverterGUI"/>
|
||||||
|
</manifest>
|
||||||
|
</jar>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
|
||||||
<target name="tibbibl-dist" depends="tibbibl-compile"
|
<target name="tibbibl-dist" depends="tibbibl-compile"
|
||||||
description="generates the bare Tibbibl binary distribution" >
|
description="generates the bare Tibbibl binary distribution" >
|
||||||
<!-- Put everything in ${tibbiblbin} into the JAR file -->
|
<!-- Put everything in ${tibbiblbin} into the JAR file -->
|
||||||
|
|
412
source/org/thdl/tib/input/ConvertDialog.java
Normal file
412
source/org/thdl/tib/input/ConvertDialog.java
Normal file
|
@ -0,0 +1,412 @@
|
||||||
|
/*
|
||||||
|
The contents of this file are subject to the THDL Open Community License
|
||||||
|
Version 1.0 (the "License"); you may not use this file except in compliance
|
||||||
|
with the License. You may obtain a copy of the License on the THDL web site
|
||||||
|
(http://www.thdl.org/).
|
||||||
|
|
||||||
|
Software distributed under the License is distributed on an "AS IS" basis,
|
||||||
|
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
||||||
|
License for the specific terms governing rights and limitations under the
|
||||||
|
License.
|
||||||
|
|
||||||
|
The Initial Developer of this software is the Tibetan and Himalayan Digital
|
||||||
|
Library (THDL). Portions created by the THDL are Copyright 2003 THDL.
|
||||||
|
All Rights Reserved.
|
||||||
|
|
||||||
|
Contributor(s): ______________________________________.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.thdl.tib.input;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.*;
|
||||||
|
import java.io.*;
|
||||||
|
import java.util.*;
|
||||||
|
import javax.swing.*;
|
||||||
|
import javax.swing.event.*;
|
||||||
|
import javax.swing.filechooser.*;
|
||||||
|
|
||||||
|
import org.thdl.util.*;
|
||||||
|
|
||||||
|
/** A GUI widget used to convert Tibetan documents from one encoding
|
||||||
|
to another.
|
||||||
|
|
||||||
|
@author Nathaniel Garson, Tibetan and Himalayan Digital Library */
|
||||||
|
class ConvertDialog extends JDialog
|
||||||
|
implements FontConverterConstants
|
||||||
|
{
|
||||||
|
private static final boolean debug = false;
|
||||||
|
|
||||||
|
// Attributes
|
||||||
|
FontConversion controller;
|
||||||
|
|
||||||
|
Box fileBox, buttonBox;
|
||||||
|
|
||||||
|
JPanel content, choicePanel;
|
||||||
|
|
||||||
|
JComboBox choices;
|
||||||
|
|
||||||
|
JTextField oldTextField, newTextField;
|
||||||
|
|
||||||
|
JButton browseOld, browseNew, convert, cancel, openDoc;
|
||||||
|
|
||||||
|
JLabel type, oldLabel, newLabel;
|
||||||
|
|
||||||
|
String[] choiceNames;
|
||||||
|
|
||||||
|
boolean oldFieldChanged, newFieldChanged;
|
||||||
|
|
||||||
|
JFileChooser jfc;
|
||||||
|
File oldFile, newFile;
|
||||||
|
String default_directory;
|
||||||
|
|
||||||
|
final String BROWSENEW = "Browse";
|
||||||
|
final String BROWSEOLD = BROWSENEW;
|
||||||
|
final String CONVERT = "Convert";
|
||||||
|
final String CANCEL = "Cancel";
|
||||||
|
|
||||||
|
private final ThdlActionListener tal = new ThdlActionListener() {
|
||||||
|
public void theRealActionPerformed(ActionEvent e) {
|
||||||
|
ConvertDialog.this.theRealActionPerformed(e);
|
||||||
|
}};
|
||||||
|
public void init()
|
||||||
|
{
|
||||||
|
default_directory = controller.getDefaultDirectory();
|
||||||
|
jfc = new JFileChooser(default_directory);
|
||||||
|
jfc.setFileFilter(new RTFFileFilter());
|
||||||
|
|
||||||
|
content = new JPanel(new GridLayout(0,1));
|
||||||
|
JPanel temp = new JPanel(new FlowLayout(FlowLayout.CENTER,5,5));
|
||||||
|
type = new JLabel("Type of Conversion: ");
|
||||||
|
temp.add(type);
|
||||||
|
temp.add(choices);
|
||||||
|
content.add(temp);
|
||||||
|
|
||||||
|
temp = new JPanel(new FlowLayout(FlowLayout.CENTER,5,5));
|
||||||
|
oldLabel = new JLabel("Original File: ");
|
||||||
|
temp.add(oldLabel);
|
||||||
|
|
||||||
|
oldTextField = new JTextField(25);
|
||||||
|
oldFieldChanged = false;
|
||||||
|
oldTextField.addCaretListener(new CaretListener() {
|
||||||
|
public void caretUpdate(CaretEvent ce) {
|
||||||
|
oldFieldChanged = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
JPanel tfTemp = new JPanel();
|
||||||
|
tfTemp.add(oldTextField);
|
||||||
|
temp.add(tfTemp);
|
||||||
|
|
||||||
|
browseOld = new JButton(BROWSEOLD);
|
||||||
|
browseOld.addActionListener(tal);
|
||||||
|
temp.add(browseOld);
|
||||||
|
content.add(temp);
|
||||||
|
|
||||||
|
temp = new JPanel(new FlowLayout(FlowLayout.CENTER,5,5));
|
||||||
|
newLabel = new JLabel("Converted File: ");
|
||||||
|
temp.add(newLabel);
|
||||||
|
|
||||||
|
newTextField = new JTextField(25);
|
||||||
|
newFieldChanged = false;
|
||||||
|
newTextField.addCaretListener(new CaretListener() {
|
||||||
|
public void caretUpdate(CaretEvent ce) {
|
||||||
|
newFieldChanged = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
tfTemp = new JPanel();
|
||||||
|
tfTemp.add(newTextField);
|
||||||
|
temp.add(tfTemp);
|
||||||
|
|
||||||
|
if (true) { // DLC
|
||||||
|
browseNew = new JButton(BROWSENEW);
|
||||||
|
browseNew.addActionListener(tal);
|
||||||
|
}
|
||||||
|
temp.add(browseNew);
|
||||||
|
// DLC temp.add(new JLabel(" "));
|
||||||
|
content.add(temp);
|
||||||
|
|
||||||
|
buttonBox = Box.createHorizontalBox();
|
||||||
|
buttonBox.add(Box.createHorizontalGlue());
|
||||||
|
convert = new JButton(CONVERT);
|
||||||
|
convert.addActionListener(tal);
|
||||||
|
buttonBox.add(convert);
|
||||||
|
buttonBox.add(Box.createHorizontalGlue());
|
||||||
|
|
||||||
|
cancel = new JButton(CANCEL);
|
||||||
|
cancel.addActionListener(tal);
|
||||||
|
buttonBox.add(cancel);
|
||||||
|
buttonBox.add(Box.createHorizontalGlue());
|
||||||
|
|
||||||
|
openDoc = new JButton("Open Document");
|
||||||
|
openDoc.addActionListener(tal);
|
||||||
|
buttonBox.add(openDoc);
|
||||||
|
buttonBox.add(Box.createHorizontalGlue());
|
||||||
|
openDoc.setVisible(false);
|
||||||
|
|
||||||
|
content.add(buttonBox);
|
||||||
|
setContentPane(content);
|
||||||
|
pack();
|
||||||
|
setSize(new Dimension(500,200));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setChoices(String[] choices)
|
||||||
|
{
|
||||||
|
choiceNames = choices;
|
||||||
|
this.choices = new JComboBox(choiceNames);
|
||||||
|
this.choices.addActionListener(tal);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Accessors
|
||||||
|
public void setController(FontConversion fc)
|
||||||
|
{
|
||||||
|
controller = fc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FontConversion getController()
|
||||||
|
{
|
||||||
|
return controller;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getType()
|
||||||
|
{
|
||||||
|
return (String)choices.getSelectedItem();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCurrentDirectory(String dir)
|
||||||
|
{
|
||||||
|
jfc.setCurrentDirectory(new File(dir));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOldFile(File f)
|
||||||
|
{
|
||||||
|
oldFile = f;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNewFile(File f)
|
||||||
|
{
|
||||||
|
newFile = f;
|
||||||
|
}
|
||||||
|
|
||||||
|
public File getOldFile()
|
||||||
|
{
|
||||||
|
if(debug && oldFile == null) {System.out.println("Old file is null!");}
|
||||||
|
return oldFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
public File getNewFile()
|
||||||
|
{
|
||||||
|
if(debug && newFile == null) {System.out.println("New file is null!");}
|
||||||
|
return newFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConvertDialog(FontConversion controller, String[] choices, boolean modal)
|
||||||
|
{
|
||||||
|
super(new JDialog(),PROGRAM_TITLE,modal);
|
||||||
|
setController(controller);
|
||||||
|
setChoices(choices);
|
||||||
|
init();
|
||||||
|
if (debug)
|
||||||
|
System.out.println("Default close operation: "
|
||||||
|
+ getDefaultCloseOperation());
|
||||||
|
}
|
||||||
|
|
||||||
|
void theRealActionPerformed(ActionEvent ae)
|
||||||
|
{
|
||||||
|
String cmd = ae.getActionCommand();
|
||||||
|
if (cmd.equals(BROWSEOLD)
|
||||||
|
|| cmd.equals(BROWSENEW))
|
||||||
|
{
|
||||||
|
JButton src = (JButton)ae.getSource();
|
||||||
|
jfc.showOpenDialog(this);
|
||||||
|
File chosenFile = jfc.getSelectedFile();
|
||||||
|
if(chosenFile == null) { return; }
|
||||||
|
if(src.equals(browseOld)) {
|
||||||
|
String fileName = chosenFile.getPath();
|
||||||
|
oldTextField.setText(fileName);
|
||||||
|
updateNewFileGuess();
|
||||||
|
oldFieldChanged = false;
|
||||||
|
oldFile = jfc.getSelectedFile();
|
||||||
|
} else if(src.equals(browseNew)) {
|
||||||
|
newTextField.setText(chosenFile.getPath());
|
||||||
|
newFieldChanged = false;
|
||||||
|
newFile = jfc.getSelectedFile();
|
||||||
|
openDoc.setVisible(false);
|
||||||
|
}
|
||||||
|
} else if(cmd.equals(CONVERT)) {
|
||||||
|
if (debug)
|
||||||
|
System.out.println("Need to write checks for complete info...");
|
||||||
|
|
||||||
|
if(oldFieldChanged || getOldFile() == null) {
|
||||||
|
if (debug)
|
||||||
|
System.out.println("DLC: old field changed");
|
||||||
|
setOldFile(updateFile(oldFile,oldTextField));
|
||||||
|
}
|
||||||
|
if(newFieldChanged || getNewFile() == null) {
|
||||||
|
if (debug)
|
||||||
|
System.out.println("DLC: new field changed");
|
||||||
|
setNewFile(updateFile(newFile,newTextField));
|
||||||
|
}
|
||||||
|
|
||||||
|
if(null == oldFile || !oldFile.exists()) {
|
||||||
|
JOptionPane.showMessageDialog(this,
|
||||||
|
"The original file does not exist. Choose again.",
|
||||||
|
"No such file",
|
||||||
|
JOptionPane.ERROR_MESSAGE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(null == newFile) {
|
||||||
|
JOptionPane.showMessageDialog(this,
|
||||||
|
"Please name the new file before proceeding.",
|
||||||
|
"No output file named",
|
||||||
|
JOptionPane.ERROR_MESSAGE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
if(getNewFile().getCanonicalPath().equals(getOldFile().getCanonicalPath())) {
|
||||||
|
JOptionPane.showMessageDialog(this,
|
||||||
|
"Please name the new file something different from the old file.",
|
||||||
|
"Input and output are the same",
|
||||||
|
JOptionPane.ERROR_MESSAGE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
// allow it.
|
||||||
|
}
|
||||||
|
|
||||||
|
// Success or failure is immaterial; we still want to bust
|
||||||
|
// out the "Open Document" button.
|
||||||
|
controller.doConversion(this,
|
||||||
|
getOldFile(),
|
||||||
|
getNewFile(),
|
||||||
|
(String)choices.getSelectedItem());
|
||||||
|
oldFieldChanged = false;
|
||||||
|
newFieldChanged = false;
|
||||||
|
openDoc.setVisible(true);
|
||||||
|
} else if(cmd.equals("Open Document")) {
|
||||||
|
try {
|
||||||
|
if(newFile == null) {return;}
|
||||||
|
boolean done = false;
|
||||||
|
File prog = new File(ThdlOptions.getStringOption("thdl.external.rtf.reader", "C:\\Program Files\\Microsoft Office\\Office\\WINWORD.EXE"));
|
||||||
|
while (!done) {
|
||||||
|
String[] cmdArray = {prog.getPath(),newFile.getPath()};
|
||||||
|
Runtime rtime = Runtime.getRuntime();
|
||||||
|
try {
|
||||||
|
Process proc = rtime.exec(cmdArray);
|
||||||
|
proc = null;
|
||||||
|
done = true;
|
||||||
|
} catch (IOException ioe) {
|
||||||
|
JFileChooser jfc = new JFileChooser("C:\\Program Files\\");
|
||||||
|
jfc.setDialogTitle("Locate Program to Read RTF");
|
||||||
|
int returnValue = jfc.showOpenDialog(this);
|
||||||
|
if(returnValue != jfc.CANCEL_OPTION) {
|
||||||
|
prog = jfc.getSelectedFile();
|
||||||
|
ThdlOptions.setUserPreference("thdl.external.rtf.reader",
|
||||||
|
prog.getAbsolutePath());
|
||||||
|
} else {
|
||||||
|
done = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (SecurityException se) {
|
||||||
|
JOptionPane.showMessageDialog(this,
|
||||||
|
"Cannot proceed because your security policy interfered.",
|
||||||
|
"Access denied",
|
||||||
|
JOptionPane.ERROR_MESSAGE);
|
||||||
|
}
|
||||||
|
} else if(cmd.equals(CANCEL)) {
|
||||||
|
System.runFinalization();
|
||||||
|
this.dispose();
|
||||||
|
System.exit(0);
|
||||||
|
} else if (cmd.equals("comboBoxChanged")) {
|
||||||
|
updateNewFileGuess();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void updateNewFileGuess() {
|
||||||
|
String oldFileName = oldTextField.getText();
|
||||||
|
if (oldFileName == null || oldFileName.equals(""))
|
||||||
|
return;
|
||||||
|
|
||||||
|
String newFileNamePrefix;
|
||||||
|
|
||||||
|
|
||||||
|
File of = new File(oldFileName);
|
||||||
|
String oldFileDirName = of.getParent();
|
||||||
|
if (oldFileDirName == null)
|
||||||
|
oldFileDirName = "";
|
||||||
|
else
|
||||||
|
oldFileDirName = oldFileDirName + File.separator;
|
||||||
|
String oldFileNameSansThingy = of.getName();
|
||||||
|
if (oldFileNameSansThingy.startsWith("TMW_")) {
|
||||||
|
oldFileNameSansThingy
|
||||||
|
= oldFileNameSansThingy.substring("TMW_".length(),
|
||||||
|
oldFileNameSansThingy.length());
|
||||||
|
} else if (oldFileNameSansThingy.startsWith("TM_")) {
|
||||||
|
oldFileNameSansThingy
|
||||||
|
= oldFileNameSansThingy.substring("TM_".length(),
|
||||||
|
oldFileNameSansThingy.length());
|
||||||
|
} else if (oldFileNameSansThingy.startsWith("TMW")) {
|
||||||
|
oldFileNameSansThingy
|
||||||
|
= oldFileNameSansThingy.substring("TMW".length(),
|
||||||
|
oldFileNameSansThingy.length());
|
||||||
|
} else if (oldFileNameSansThingy.startsWith("TM")) {
|
||||||
|
oldFileNameSansThingy
|
||||||
|
= oldFileNameSansThingy.substring("TM".length(),
|
||||||
|
oldFileNameSansThingy.length());
|
||||||
|
}
|
||||||
|
|
||||||
|
String ct = (String)choices.getSelectedItem();
|
||||||
|
if ("Find all non-TMW" == ct) {
|
||||||
|
newFileNamePrefix = "FindAllNonTMW__";
|
||||||
|
} else if ("Find some non-TMW" == ct) {
|
||||||
|
newFileNamePrefix = "FindSomeNonTMW__";
|
||||||
|
} else if ("Find some non-TM" == ct) {
|
||||||
|
newFileNamePrefix = "FindSomeNonTM__";
|
||||||
|
} else if ("Find all non-TM" == ct) {
|
||||||
|
newFileNamePrefix = "FindAllNonTM__";
|
||||||
|
} else { // conversion {to Wylie or TM} mode
|
||||||
|
if ("TMW to Wylie" == ct) {
|
||||||
|
newFileNamePrefix = "THDL_Wylie_";
|
||||||
|
} else if ("TMW to Unicode" == ct) {
|
||||||
|
newFileNamePrefix = "Uni_";
|
||||||
|
} else if ("TM to TMW" == ct) {
|
||||||
|
newFileNamePrefix = "TMW_";
|
||||||
|
} else {
|
||||||
|
ThdlDebug.verify("TMW to TM" == ct);
|
||||||
|
newFileNamePrefix = "TM_";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
newTextField.setText(oldFileDirName
|
||||||
|
+ newFileNamePrefix
|
||||||
|
+ oldFileNameSansThingy);
|
||||||
|
}
|
||||||
|
|
||||||
|
public File updateFile(File setFile, JTextField textField)
|
||||||
|
{
|
||||||
|
if(textField.equals(newTextField)) {openDoc.setVisible(false);}
|
||||||
|
String txt = textField.getText();
|
||||||
|
if (txt.equals(""))
|
||||||
|
return null;
|
||||||
|
if(txt.indexOf(".rtf")==-1) { txt += ".rtf"; }
|
||||||
|
if(setFile == null) {return new File(txt); }
|
||||||
|
String fileName = setFile.getPath();
|
||||||
|
String filePath = setFile.getPath();
|
||||||
|
if(txt.equals(fileName) || txt.equals(filePath)) { return setFile; }
|
||||||
|
if(txt.indexOf("\\")>-1) { return new File(txt); }
|
||||||
|
return new File(setFile.getParent() + "\\" + txt);
|
||||||
|
}
|
||||||
|
|
||||||
|
public class RTFFileFilter extends javax.swing.filechooser.FileFilter
|
||||||
|
{
|
||||||
|
public boolean accept(File f)
|
||||||
|
{
|
||||||
|
if(f.isDirectory() || f.getName().indexOf(".rtf")>-1) { return true; }
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription()
|
||||||
|
{
|
||||||
|
return "RTF files only";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
138
source/org/thdl/tib/input/ConverterGUI.java
Normal file
138
source/org/thdl/tib/input/ConverterGUI.java
Normal file
|
@ -0,0 +1,138 @@
|
||||||
|
/*
|
||||||
|
The contents of this file are subject to the THDL Open Community License
|
||||||
|
Version 1.0 (the "License"); you may not use this file except in compliance
|
||||||
|
with the License. You may obtain a copy of the License on the THDL web site
|
||||||
|
(http://www.thdl.org/).
|
||||||
|
|
||||||
|
Software distributed under the License is distributed on an "AS IS" basis,
|
||||||
|
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
||||||
|
License for the specific terms governing rights and limitations under the
|
||||||
|
License.
|
||||||
|
|
||||||
|
The Initial Developer of this software is the Tibetan and Himalayan Digital
|
||||||
|
Library (THDL). Portions created by the THDL are Copyright 2003 THDL.
|
||||||
|
All Rights Reserved.
|
||||||
|
|
||||||
|
Contributor(s): ______________________________________.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.thdl.tib.input;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
|
||||||
|
import org.thdl.util.*;
|
||||||
|
import org.thdl.tib.text.*;
|
||||||
|
import javax.swing.JOptionPane;
|
||||||
|
|
||||||
|
/** DLC FIXMEDOC
|
||||||
|
* @author David Chandler */
|
||||||
|
public class ConverterGUI implements FontConversion {
|
||||||
|
/** Default constructor; does nothing */
|
||||||
|
ConverterGUI() { }
|
||||||
|
|
||||||
|
static {
|
||||||
|
// No need for the TM or TMW fonts.
|
||||||
|
System.setProperty("thdl.rely.on.system.tmw.fonts", "true");
|
||||||
|
System.setProperty("thdl.do.not.rely.on.system.tmw.fonts", "false");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Runs the converter. */
|
||||||
|
public static void main(String[] args) {
|
||||||
|
System.exit(realMain(args, System.out));
|
||||||
|
}
|
||||||
|
|
||||||
|
// DLC FIXMEDOC returns true on success
|
||||||
|
public boolean doConversion(ConvertDialog cd, File oldFile, File newFile,
|
||||||
|
String whichConversion) {
|
||||||
|
System.err.println("DLC NOW " + oldFile + " " + newFile + " " + whichConversion);
|
||||||
|
PrintStream ps;
|
||||||
|
try {
|
||||||
|
returnCode
|
||||||
|
= TibetanConverter.reallyConvert(new FileInputStream(oldFile),
|
||||||
|
ps = new PrintStream(new FileOutputStream(newFile),
|
||||||
|
false),
|
||||||
|
whichConversion);
|
||||||
|
ps.close();
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
returnCode = 39;
|
||||||
|
}
|
||||||
|
if (0 != returnCode) {
|
||||||
|
JOptionPane.showMessageDialog(cd,
|
||||||
|
"The conversion failed with code " + returnCode + "; please e-mail\ndchandler@users.sourceforge.net to learn what that means if\nyou can't find out from the output.",
|
||||||
|
"Conversion failed",
|
||||||
|
JOptionPane.ERROR_MESSAGE);
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
if (!ThdlOptions.getBooleanOption("thdl.skip.conversion.success.message"))
|
||||||
|
JOptionPane.showMessageDialog(cd,
|
||||||
|
"The conversion went perfectly.",
|
||||||
|
"Conversion succeeded",
|
||||||
|
JOptionPane.PLAIN_MESSAGE);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DLC FIXMEDOC
|
||||||
|
public String getDefaultDirectory() {
|
||||||
|
return ThdlOptions.getStringOption("thdl.Jskad.working.directory",
|
||||||
|
null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int returnCode = 0;
|
||||||
|
|
||||||
|
/** Runs the converter without exiting the program.
|
||||||
|
* @return the exit code. */
|
||||||
|
public static int realMain(String[] args, PrintStream out) {
|
||||||
|
try {
|
||||||
|
|
||||||
|
final ConvertDialog convDialog
|
||||||
|
= new ConvertDialog(new ConverterGUI(),
|
||||||
|
new String[]{
|
||||||
|
// DLC FIXME: use variables
|
||||||
|
// for these, because they're
|
||||||
|
// used in
|
||||||
|
// TibetanConverter.java too.
|
||||||
|
"TM to TMW",
|
||||||
|
"TMW to Unicode",
|
||||||
|
"TMW to Wylie",
|
||||||
|
"TMW to TM",
|
||||||
|
"Find some non-TMW",
|
||||||
|
"Find some non-TM",
|
||||||
|
"Find all non-TMW",
|
||||||
|
"Find all non-TM"
|
||||||
|
},
|
||||||
|
true);
|
||||||
|
|
||||||
|
/* Make it so that any time the user exits this program by
|
||||||
|
* (almost) any means, the user's preferences are saved if
|
||||||
|
* the SecurityManager allows it and the path is correct.
|
||||||
|
* This means that the program used to "Open Document"
|
||||||
|
* will be remembered. */
|
||||||
|
Runtime.getRuntime().addShutdownHook(new Thread() {
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
if (!ThdlOptions.saveUserPreferences()) {
|
||||||
|
JOptionPane.showMessageDialog(convDialog,
|
||||||
|
"You previously cleared preferences,\nso you cannot now save them.",
|
||||||
|
"Cannot Save User Preferences",
|
||||||
|
JOptionPane.PLAIN_MESSAGE);
|
||||||
|
}
|
||||||
|
} catch (IOException ioe) {
|
||||||
|
System.out.println("IO Exception saving user preferences to " + ThdlOptions.getUserPreferencesPath());
|
||||||
|
ioe.printStackTrace();
|
||||||
|
ThdlDebug.noteIffyCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
convDialog.setVisible(true);
|
||||||
|
return returnCode;
|
||||||
|
} catch (ThdlLazyException e) {
|
||||||
|
out.println("ConverterGUI has a BUG:");
|
||||||
|
e.getRealException().printStackTrace(out);
|
||||||
|
return 7;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
29
source/org/thdl/tib/input/FontConversion.java
Normal file
29
source/org/thdl/tib/input/FontConversion.java
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
/*
|
||||||
|
The contents of this file are subject to the THDL Open Community License
|
||||||
|
Version 1.0 (the "License"); you may not use this file except in compliance
|
||||||
|
with the License. You may obtain a copy of the License on the THDL web site
|
||||||
|
(http://www.thdl.org/).
|
||||||
|
|
||||||
|
Software distributed under the License is distributed on an "AS IS" basis,
|
||||||
|
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
||||||
|
License for the specific terms governing rights and limitations under the
|
||||||
|
License.
|
||||||
|
|
||||||
|
The Initial Developer of this software is the Tibetan and Himalayan Digital
|
||||||
|
Library (THDL). Portions created by the THDL are Copyright 2003 THDL.
|
||||||
|
All Rights Reserved.
|
||||||
|
|
||||||
|
Contributor(s): ______________________________________.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.thdl.tib.input;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
// DLC FIXMEDOC
|
||||||
|
interface FontConversion
|
||||||
|
{
|
||||||
|
String getDefaultDirectory();
|
||||||
|
boolean doConversion(ConvertDialog cd, File oldFile,
|
||||||
|
File newFile, String whichConversion);
|
||||||
|
}
|
62
source/org/thdl/tib/input/FontConverterConstants.java
Normal file
62
source/org/thdl/tib/input/FontConverterConstants.java
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
/*
|
||||||
|
The contents of this file are subject to the THDL Open Community License
|
||||||
|
Version 1.0 (the "License"); you may not use this file except in compliance
|
||||||
|
with the License. You may obtain a copy of the License on the THDL web site
|
||||||
|
(http://www.thdl.org/).
|
||||||
|
|
||||||
|
Software distributed under the License is distributed on an "AS IS" basis,
|
||||||
|
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
||||||
|
License for the specific terms governing rights and limitations under the
|
||||||
|
License.
|
||||||
|
|
||||||
|
The Initial Developer of this software is the Tibetan and Himalayan Digital
|
||||||
|
Library (THDL). Portions created by the THDL are Copyright 2003 THDL.
|
||||||
|
All Rights Reserved.
|
||||||
|
|
||||||
|
Contributor(s): ______________________________________.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.thdl.tib.input;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
/** Constants used by ConvertDialog.
|
||||||
|
|
||||||
|
@author Nathaniel Garson, Tibetan and Himalayan Digital Library */
|
||||||
|
interface FontConverterConstants
|
||||||
|
{
|
||||||
|
// DLC prune
|
||||||
|
|
||||||
|
// File Constants
|
||||||
|
String HOME_PATH = System.getProperties().getProperty("user.dir");
|
||||||
|
File HOME_FOLDER = new File(HOME_PATH);
|
||||||
|
|
||||||
|
// GUI Constants
|
||||||
|
// Sizes
|
||||||
|
Dimension WIN_SIZE = new Dimension(600,400);
|
||||||
|
|
||||||
|
|
||||||
|
// Colors
|
||||||
|
Color BG_COLOR = Color.white;
|
||||||
|
|
||||||
|
// Data Delimiters
|
||||||
|
String COMMENT_DELIM = "////";
|
||||||
|
String HEADER_DELIM = "<?";
|
||||||
|
String DATA_DELIM = "=";
|
||||||
|
String FONT_NUM_DELIM = ",";
|
||||||
|
|
||||||
|
// Data File Headers
|
||||||
|
String OLD_FONT_HEADER = "old_fonts";
|
||||||
|
String NEW_FONT_HEADER = "new_fonts";
|
||||||
|
String CORRESP_HEADER = "correspondences";
|
||||||
|
String END_OF_SECTION = "EOS";
|
||||||
|
|
||||||
|
// Type Constants
|
||||||
|
public final int TIB_TO_TIB = 0;
|
||||||
|
public final int DIA_TO_UNICODE = 1;
|
||||||
|
|
||||||
|
// String Constants
|
||||||
|
public final String PROGRAM_TITLE = "THDL Font Conversion (with Jskad Technology)";
|
||||||
|
|
||||||
|
}
|
|
@ -33,12 +33,16 @@ import org.thdl.tib.text.*;
|
||||||
* it with no parameters for usage information.
|
* it with no parameters for usage information.
|
||||||
* @author David Chandler */
|
* @author David Chandler */
|
||||||
public class TibetanConverter {
|
public class TibetanConverter {
|
||||||
|
/** Default constructor; does nothing */
|
||||||
|
TibetanConverter() { }
|
||||||
|
|
||||||
static final String rtfErrorMessage
|
static final String rtfErrorMessage
|
||||||
= "The Rich Text Format (RTF) file selected contains constructs that\nJskad cannot handle. If you got the RTF file from saving a Word\ndocument as RTF, try saving that same document as RTF in\nWord 2000 instead of Word XP or in Word 97 instead of\nWord 2000. Older versions of Word produce RTF that Jskad\ncan more easily deal with. OpenOffice and StarOffice may also\nproduce better-behaved RTF.";
|
= "The Rich Text Format (RTF) file selected contains constructs that\nJskad cannot handle. If you got the RTF file from saving a Word\ndocument as RTF, try saving that same document as RTF in\nWord 2000 instead of Word XP or in Word 97 instead of\nWord 2000. Older versions of Word produce RTF that Jskad\ncan more easily deal with. OpenOffice and StarOffice may also\nproduce better-behaved RTF.";
|
||||||
|
|
||||||
static {
|
static {
|
||||||
// No need for the TMW fonts.
|
// No need for the TM or TMW fonts.
|
||||||
System.setProperty("thdl.rely.on.system.tmw.fonts", "true");
|
System.setProperty("thdl.rely.on.system.tmw.fonts", "true");
|
||||||
|
System.setProperty("thdl.do.not.rely.on.system.tmw.fonts", "false");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -128,84 +132,34 @@ public class TibetanConverter {
|
||||||
}
|
}
|
||||||
String inputRtfPath = args[args.length - 1];
|
String inputRtfPath = args[args.length - 1];
|
||||||
|
|
||||||
DuffPane dp = new DuffPane();
|
InputStream in;
|
||||||
// Read in the rtf file.
|
if (inputRtfPath.equals("-"))
|
||||||
{
|
in = System.in;
|
||||||
InputStream in;
|
else
|
||||||
if (inputRtfPath.equals("-"))
|
in = new FileInputStream(inputRtfPath);
|
||||||
in = System.in;
|
|
||||||
else
|
String conversionTag = null;
|
||||||
in = new FileInputStream(inputRtfPath);
|
|
||||||
try {
|
|
||||||
dp.rtfEd.read(in, dp.getDocument(), 0);
|
|
||||||
} catch (Exception e) {
|
|
||||||
out.println("TibetanConverter:\n"
|
|
||||||
+ rtfErrorMessage);
|
|
||||||
return 3;
|
|
||||||
}
|
|
||||||
in.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (findAllNonTMWMode) {
|
if (findAllNonTMWMode) {
|
||||||
// 0, -1 is the entire document.
|
conversionTag = "Find all non-TMW";
|
||||||
return ((TibetanDocument)dp.getDocument()).findAllNonTMWCharacters(0, -1, out);
|
|
||||||
} else if (findSomeNonTMWMode) {
|
} else if (findSomeNonTMWMode) {
|
||||||
// 0, -1 is the entire document.
|
conversionTag = "Find some non-TMW";
|
||||||
return ((TibetanDocument)dp.getDocument()).findSomeNonTMWCharacters(0, -1, out);
|
|
||||||
} else if (findSomeNonTMMode) {
|
} else if (findSomeNonTMMode) {
|
||||||
// 0, -1 is the entire document.
|
conversionTag = "Find some non-TM";
|
||||||
return ((TibetanDocument)dp.getDocument()).findSomeNonTMCharacters(0, -1, out);
|
|
||||||
} else if (findAllNonTMMode) {
|
} else if (findAllNonTMMode) {
|
||||||
// 0, -1 is the entire document.
|
conversionTag = "Find all non-TM";
|
||||||
return ((TibetanDocument)dp.getDocument()).findAllNonTMCharacters(0, -1, out);
|
|
||||||
} else { // conversion {to Wylie or TM} mode
|
} else { // conversion {to Wylie or TM} mode
|
||||||
// Fix curly braces in the entire document if the input is TMW:
|
|
||||||
if (!convertToTMWMode) {
|
|
||||||
// DLC make me optional
|
|
||||||
((TibetanDocument)dp.getDocument()).replaceTahomaCurlyBracesAndBackslashes(0, -1);
|
|
||||||
}
|
|
||||||
|
|
||||||
int exitCode = 0;
|
|
||||||
ThdlDebug.verify((convertToTMMode ? 1 : 0)
|
|
||||||
+ (convertToUnicodeMode ? 1 : 0)
|
|
||||||
+ (convertToTMWMode ? 1 : 0)
|
|
||||||
+ (convertToWylieMode ? 1 : 0)
|
|
||||||
== 1);
|
|
||||||
if (convertToWylieMode) {
|
if (convertToWylieMode) {
|
||||||
// Convert to THDL Wylie:
|
conversionTag = "TMW to Wylie";
|
||||||
dp.toWylie(0, dp.getDocument().getLength());
|
|
||||||
} else if (convertToUnicodeMode) {
|
} else if (convertToUnicodeMode) {
|
||||||
StringBuffer errors = new StringBuffer();
|
conversionTag = "TMW to Unicode";
|
||||||
// Convert to Unicode:
|
|
||||||
if (((TibetanDocument)dp.getDocument()).convertToUnicode(0,
|
|
||||||
dp.getDocument().getLength(),
|
|
||||||
errors,
|
|
||||||
ThdlOptions.getStringOption("thdl.tmw.to.unicode.font").intern())) {
|
|
||||||
System.err.println(errors);
|
|
||||||
exitCode = 42;
|
|
||||||
}
|
|
||||||
} else if (convertToTMWMode) {
|
} else if (convertToTMWMode) {
|
||||||
StringBuffer errors = new StringBuffer();
|
conversionTag = "TM to TMW";
|
||||||
// Convert to TibetanMachineWeb:
|
|
||||||
if (((TibetanDocument)dp.getDocument()).convertToTMW(0, dp.getDocument().getLength(), errors)) {
|
|
||||||
System.err.println(errors);
|
|
||||||
exitCode = 42;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
ThdlDebug.verify(convertToTMMode);
|
ThdlDebug.verify(convertToTMMode);
|
||||||
StringBuffer errors = new StringBuffer();
|
conversionTag = "TMW to TM";
|
||||||
// Convert to TibetanMachine:
|
|
||||||
if (((TibetanDocument)dp.getDocument()).convertToTM(0, dp.getDocument().getLength(), errors)) {
|
|
||||||
System.err.println(errors);
|
|
||||||
exitCode = 42;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write to standard output the result:
|
|
||||||
((TibetanDocument)dp.getDocument()).writeRTFOutputStream(out);
|
|
||||||
|
|
||||||
return exitCode;
|
|
||||||
}
|
}
|
||||||
|
return reallyConvert(in, out, conversionTag);
|
||||||
} catch (ThdlLazyException e) {
|
} catch (ThdlLazyException e) {
|
||||||
out.println("TibetanConverter has a BUG:");
|
out.println("TibetanConverter has a BUG:");
|
||||||
e.getRealException().printStackTrace(out);
|
e.getRealException().printStackTrace(out);
|
||||||
|
@ -215,4 +169,113 @@ public class TibetanConverter {
|
||||||
return 4;
|
return 4;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Reads from in, closes in, converts (or finds some/all
|
||||||
|
non-TM/TMW), writes the result to out, does not close out.
|
||||||
|
The action taken depends on ct, which must be one of a set
|
||||||
|
number of strings -- see the code. Returns an appropriate
|
||||||
|
return code so that TibetanConverter's usage message is
|
||||||
|
honored. */
|
||||||
|
static int reallyConvert(InputStream in, PrintStream out, String ct) {
|
||||||
|
DuffPane dp = new DuffPane();
|
||||||
|
try {
|
||||||
|
// Read in the rtf file.
|
||||||
|
dp.rtfEd.read(in, dp.getDocument(), 0);
|
||||||
|
} catch (Exception e) {
|
||||||
|
out.println("TibetanConverter:\n"
|
||||||
|
+ rtfErrorMessage);
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
in.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
// silently ignore; we don't care about the input so much...
|
||||||
|
ThdlDebug.noteIffyCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if ("Find all non-TMW" == ct) {
|
||||||
|
// 0, -1 is the entire document.
|
||||||
|
int exitCode
|
||||||
|
= ((TibetanDocument)dp.getDocument()).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);
|
||||||
|
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);
|
||||||
|
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);
|
||||||
|
if (out.checkError())
|
||||||
|
exitCode = 41;
|
||||||
|
return exitCode;
|
||||||
|
} else { // conversion {to Wylie or TM} mode
|
||||||
|
// Fix curly braces in the entire document if the input is TMW:
|
||||||
|
if ("TMW to TM" != ct) {
|
||||||
|
// DLC make me optional
|
||||||
|
((TibetanDocument)dp.getDocument()).replaceTahomaCurlyBracesAndBackslashes(0, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int exitCode = 0;
|
||||||
|
ThdlDebug.verify((("TMW to TM" == ct) ? 1 : 0)
|
||||||
|
+ (("TMW to Unicode" == ct) ? 1 : 0)
|
||||||
|
+ (("TM to TMW" == ct) ? 1 : 0)
|
||||||
|
+ (("TMW to Wylie" == ct) ? 1 : 0)
|
||||||
|
== 1);
|
||||||
|
if ("TMW to Wylie" == ct) {
|
||||||
|
// Convert to THDL Wylie:
|
||||||
|
dp.toWylie(0, dp.getDocument().getLength());
|
||||||
|
} else if ("TMW to Unicode" == 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())) {
|
||||||
|
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)) {
|
||||||
|
System.err.println(errors);
|
||||||
|
exitCode = 42;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ThdlDebug.verify("TMW to TM" == ct);
|
||||||
|
StringBuffer errors = new StringBuffer();
|
||||||
|
// Convert to TibetanMachine:
|
||||||
|
if (((TibetanDocument)dp.getDocument()).convertToTM(0, dp.getDocument().getLength(), errors)) {
|
||||||
|
System.err.println(errors);
|
||||||
|
exitCode = 42;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write to standard output the result:
|
||||||
|
try {
|
||||||
|
((TibetanDocument)dp.getDocument()).writeRTFOutputStream(out);
|
||||||
|
} catch (IOException e) {
|
||||||
|
exitCode = 40;
|
||||||
|
}
|
||||||
|
if (out.checkError())
|
||||||
|
exitCode = 41;
|
||||||
|
|
||||||
|
return exitCode;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -213,6 +213,16 @@ public class TibetanDocument extends DefaultStyledDocument {
|
||||||
throw new Error("TMW->Unicode failed because the following constitute a bad position: startOffset " + startOffset + ", endOffset " + endOffset);
|
throw new Error("TMW->Unicode failed because the following constitute a bad position: startOffset " + startOffset + ", endOffset " + endOffset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// DLC NOW do I stick to these rules in TMW->Unicode mappings?
|
||||||
|
// Chris Fynn wrote:
|
||||||
|
//
|
||||||
|
// 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)
|
||||||
|
|
||||||
|
|
||||||
private int insertDuff(int fontSize, int pos, DuffData[] glyphs, boolean asTMW) {
|
private int insertDuff(int fontSize, int pos, DuffData[] glyphs, boolean asTMW) {
|
||||||
if (glyphs == null)
|
if (glyphs == null)
|
||||||
|
@ -544,7 +554,7 @@ public class TibetanDocument extends DefaultStyledDocument {
|
||||||
@param errors if non-null, then notes about all exceptional
|
@param errors if non-null, then notes about all exceptional
|
||||||
cases will be appended to this StringBuffer
|
cases will be appended to this StringBuffer
|
||||||
@param unicodeFont the name of the Unicode font to use;
|
@param unicodeFont the name of the Unicode font to use;
|
||||||
defaults to Arial Unicode MS if null
|
defaults to Ximalaya if null
|
||||||
*/
|
*/
|
||||||
public boolean convertToUnicode(int begin, int end, StringBuffer errors,
|
public boolean convertToUnicode(int begin, int end, StringBuffer errors,
|
||||||
String unicodeFont) {
|
String unicodeFont) {
|
||||||
|
@ -974,7 +984,7 @@ public class TibetanDocument extends DefaultStyledDocument {
|
||||||
/** 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
|
||||||
* end < 0 is treated as the document's length. Note that roman,
|
* end < 0 is treated as the document's length. Note that roman,
|
||||||
* TM, Arial Unicode MS, and TMW text can all be intermingled
|
* TM, Ximalaya, and TMW text can all be intermingled
|
||||||
* within a paragraph. It's the correct level of abstraction to
|
* within a paragraph. It's the correct level of abstraction to
|
||||||
* use, however, because the next finer grain is roughly one
|
* use, however, because the next finer grain is roughly one
|
||||||
* Element per glyph. */
|
* Element per glyph. */
|
||||||
|
|
|
@ -285,7 +285,7 @@ public class TibetanMachineWeb implements THDLWylieConstants {
|
||||||
|
|
||||||
defaultUnicodeFontAttributeSet = new SimpleAttributeSet();
|
defaultUnicodeFontAttributeSet = new SimpleAttributeSet();
|
||||||
StyleConstants.setFontFamily(defaultUnicodeFontAttributeSet,
|
StyleConstants.setFontFamily(defaultUnicodeFontAttributeSet,
|
||||||
"Arial Unicode MS");
|
"Ximalaya");
|
||||||
|
|
||||||
webFontAttributeSet[0] = null;
|
webFontAttributeSet[0] = null;
|
||||||
for (int i=1; i<webFontAttributeSet.length; i++) {
|
for (int i=1; i<webFontAttributeSet.length; i++) {
|
||||||
|
@ -665,12 +665,12 @@ public static SimpleAttributeSet getAttributeSet(int font) {
|
||||||
* order to be able to put styled text into {@link TibetanDocument
|
* order to be able to put styled text into {@link TibetanDocument
|
||||||
* TibetanDocument}.
|
* TibetanDocument}.
|
||||||
* @param unicodeFont the interned name of the Unicode font to use;
|
* @param unicodeFont the interned name of the Unicode font to use;
|
||||||
* defaults to Arial Unicode MS if null
|
* defaults to Ximalaya if null
|
||||||
* @return a SimpleAttributeSet for the Unicode font - that is, a way
|
* @return a SimpleAttributeSet for the Unicode font - that is, a way
|
||||||
* of encoding the font itself */
|
* of encoding the font itself */
|
||||||
public static SimpleAttributeSet getUnicodeAttributeSet(String unicodeFont) {
|
public static SimpleAttributeSet getUnicodeAttributeSet(String unicodeFont) {
|
||||||
if (null == unicodeFont
|
if (null == unicodeFont
|
||||||
|| "Arial Unicode MS" == unicodeFont)
|
|| "Ximalaya" == unicodeFont)
|
||||||
return defaultUnicodeFontAttributeSet;
|
return defaultUnicodeFontAttributeSet;
|
||||||
else {
|
else {
|
||||||
SimpleAttributeSet cached
|
SimpleAttributeSet cached
|
||||||
|
|
Loading…
Reference in a new issue