Bad RTF now causes an error message to appear in the transcription
instead of causing a fatal exception. The error allows you to look up the DuffCode that caused the trouble.
This commit is contained in:
parent
8275afeb41
commit
8958366a07
2 changed files with 182 additions and 175 deletions
|
@ -1,165 +1,175 @@
|
||||||
/*
|
/*
|
||||||
The contents of this file are subject to the THDL Open Community License
|
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
|
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
|
with the License. You may obtain a copy of the License on the THDL web site
|
||||||
(http://www.thdl.org/).
|
(http://www.thdl.org/).
|
||||||
|
|
||||||
Software distributed under the License is distributed on an "AS IS" basis,
|
Software distributed under the License is distributed on an "AS IS" basis,
|
||||||
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
||||||
License for the specific terms governing rights and limitations under the
|
License for the specific terms governing rights and limitations under the
|
||||||
License.
|
License.
|
||||||
|
|
||||||
The Initial Developer of this software is the Tibetan and Himalayan Digital
|
The Initial Developer of this software is the Tibetan and Himalayan Digital
|
||||||
Library (THDL). Portions created by the THDL are Copyright 2001 THDL.
|
Library (THDL). Portions created by the THDL are Copyright 2001 THDL.
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
Contributor(s): ______________________________________.
|
Contributor(s): ______________________________________.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.thdl.tib.text;
|
package org.thdl.tib.text;
|
||||||
|
|
||||||
import java.util.StringTokenizer;
|
import java.util.StringTokenizer;
|
||||||
|
|
||||||
/**
|
import org.thdl.util.ThdlDebug;
|
||||||
* A wrapper for the primitive data types
|
|
||||||
* that combine to represent a Tibetan glyph in the
|
/**
|
||||||
* TibetanMachineWeb family of fonts.
|
* A wrapper for the primitive data types
|
||||||
*
|
* that combine to represent a Tibetan glyph in the
|
||||||
* A DuffCode consists of a font number, a character, and
|
* TibetanMachineWeb family of fonts.
|
||||||
* a character number. A font identification and a character
|
*
|
||||||
* (or character number) are sufficient to uniquely identify
|
* A DuffCode consists of a font number, a character, and
|
||||||
* any TibetanMachineWeb glyph.
|
* a character number. A font identification and a character
|
||||||
* @author Edward Garrett, Tibetan and Himalayan Digital Library
|
* (or character number) are sufficient to uniquely identify
|
||||||
* @version 1.0
|
* any TibetanMachineWeb glyph.
|
||||||
*/
|
* @author Edward Garrett, Tibetan and Himalayan Digital Library
|
||||||
|
* @version 1.0
|
||||||
public class DuffCode {
|
*/
|
||||||
/**
|
|
||||||
* the font number in which this glyph can be found,
|
public class DuffCode {
|
||||||
* from 1 (TibetanMachineWeb) to 10 (TibetanMachineWeb9).
|
/**
|
||||||
*/
|
* the font number in which this glyph can be found,
|
||||||
public int fontNum;
|
* from 1 (TibetanMachineWeb) to 10 (TibetanMachineWeb9).
|
||||||
/**
|
*/
|
||||||
* the character value of this glyph
|
public int fontNum;
|
||||||
*/
|
/**
|
||||||
public char character;
|
* the character value of this glyph
|
||||||
/**
|
*/
|
||||||
* the character value of this glyph, as an integer
|
public char character;
|
||||||
*/
|
/**
|
||||||
public int charNum;
|
* the character value of this glyph, as an integer
|
||||||
|
*/
|
||||||
/**
|
public int charNum;
|
||||||
* Called by {@link TibetanMachineWeb} to generate
|
|
||||||
* DuffCodes from the 'tibwn.ini' initialization file.
|
/**
|
||||||
* This constructor expects to receive a string such as "1,33" or "33,1",
|
* Called by {@link TibetanMachineWeb} to generate
|
||||||
* i.e. a sequence of two numbers separated by a comma. These numbers
|
* DuffCodes from the 'tibwn.ini' initialization file.
|
||||||
* represent a character: one number is its identifying font number,
|
* This constructor expects to receive a string such as "1,33" or "33,1",
|
||||||
* and the other is the ASCII code of the character.
|
* i.e. a sequence of two numbers separated by a comma. These numbers
|
||||||
*
|
* represent a character: one number is its identifying font number,
|
||||||
* @param s the string to parse
|
* and the other is the ASCII code of the character.
|
||||||
* @param leftToRight should be true if the first number is the font number,
|
*
|
||||||
* false if the second number is the font number
|
* @param s the string to parse
|
||||||
*/
|
* @param leftToRight should be true if the first number is the font number,
|
||||||
public DuffCode(String s, boolean leftToRight) {
|
* false if the second number is the font number
|
||||||
StringTokenizer st = new StringTokenizer(s,",");
|
*/
|
||||||
|
public DuffCode(String s, boolean leftToRight) {
|
||||||
try {
|
StringTokenizer st = new StringTokenizer(s,",");
|
||||||
String val1 = st.nextToken();
|
|
||||||
String val2 = st.nextToken();
|
try {
|
||||||
|
String val1 = st.nextToken();
|
||||||
Integer num1 = new Integer(val1);
|
String val2 = st.nextToken();
|
||||||
Integer num2 = new Integer(val2);
|
|
||||||
|
Integer num1 = new Integer(val1);
|
||||||
if (leftToRight) {
|
Integer num2 = new Integer(val2);
|
||||||
fontNum = num1.intValue();
|
|
||||||
charNum = num2.intValue();
|
if (leftToRight) {
|
||||||
character = (char)charNum;
|
setFontNum(num1.intValue());
|
||||||
}
|
charNum = num2.intValue();
|
||||||
else {
|
character = (char)charNum;
|
||||||
fontNum = num2.intValue();
|
}
|
||||||
charNum = num1.intValue();
|
else {
|
||||||
character = (char)charNum;
|
setFontNum(num2.intValue());
|
||||||
}
|
charNum = num1.intValue();
|
||||||
}
|
character = (char)charNum;
|
||||||
catch (NumberFormatException e) {
|
}
|
||||||
}
|
}
|
||||||
}
|
catch (NumberFormatException e) {
|
||||||
|
ThdlDebug.noteIffyCode();
|
||||||
/**
|
}
|
||||||
* Called to create DuffCodes on the fly
|
}
|
||||||
* from an identifying font number and an ASCII character.
|
|
||||||
*
|
/**
|
||||||
* @param font the identifying number of the font
|
* Called to create DuffCodes on the fly
|
||||||
* @param ch a character
|
* from an identifying font number and an ASCII character.
|
||||||
*/
|
*
|
||||||
public DuffCode(int font, char ch) {
|
* @param font the identifying number of the font
|
||||||
fontNum = font;
|
* @param ch a character
|
||||||
character = ch;
|
*/
|
||||||
charNum = (int)ch;
|
public DuffCode(int font, char ch) {
|
||||||
}
|
setFontNum(font);
|
||||||
|
character = ch;
|
||||||
/**
|
charNum = (int)ch;
|
||||||
* Gets the font number of this glyph.
|
}
|
||||||
* @return the identifying font number for this DuffCode
|
|
||||||
*/
|
private void setFontNum(int font) {
|
||||||
public int getFontNum() {
|
ThdlDebug.verify(font >= 1 && font <= 10);
|
||||||
return fontNum;
|
fontNum = font;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the character for this glyph, as an integer.
|
* Gets the font number of this glyph.
|
||||||
* @return the identifying character, converted to an
|
* @return the identifying font number for this DuffCode
|
||||||
* integer, for this DuffCode
|
*/
|
||||||
*/
|
public int getFontNum() {
|
||||||
public int getCharNum() {
|
return fontNum;
|
||||||
return charNum;
|
}
|
||||||
}
|
|
||||||
|
/**
|
||||||
/**
|
* Gets the character for this glyph, as an integer.
|
||||||
* Gets the character for this glyph.
|
* @return the identifying character, converted to an
|
||||||
* @return the identifying character for this DuffCode
|
* integer, for this DuffCode
|
||||||
*/
|
*/
|
||||||
public char getCharacter() {
|
public int getCharNum() {
|
||||||
return character;
|
return charNum;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Assigns a hashcode based on the font number and character for this glyph.
|
* Gets the character for this glyph.
|
||||||
* The hashcode for a DuffCode with font=1 and character='c'
|
* @return the identifying character for this DuffCode
|
||||||
* is defined as the hash code of the string '1-c'.
|
*/
|
||||||
*
|
public char getCharacter() {
|
||||||
* @return the hash code for this object
|
return character;
|
||||||
*/
|
}
|
||||||
public int hashCode() {
|
|
||||||
StringBuffer sb = new StringBuffer();
|
/**
|
||||||
sb.append(new Integer(fontNum).toString());
|
* Assigns a hashcode based on the font number and character for this glyph.
|
||||||
sb.append('-');
|
* The hashcode for a DuffCode with font=1 and character='c'
|
||||||
sb.append(character);
|
* is defined as the hash code of the string '1-c'.
|
||||||
String s = sb.toString();
|
*
|
||||||
return s.hashCode();
|
* @return the hash code for this object
|
||||||
}
|
*/
|
||||||
|
public int hashCode() {
|
||||||
/**
|
StringBuffer sb = new StringBuffer();
|
||||||
* Evaluates two DuffCodes as equal iff their
|
sb.append(new Integer(fontNum).toString());
|
||||||
* font numbers and characters are identical.
|
sb.append('-');
|
||||||
*
|
sb.append(character);
|
||||||
* @param o the object (DuffCode) you want to compare
|
String s = sb.toString();
|
||||||
* @return true if this object is equal to o, false if not
|
return s.hashCode();
|
||||||
*/
|
}
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (o instanceof DuffCode) {
|
/**
|
||||||
DuffCode dc = (DuffCode)o;
|
* Evaluates two DuffCodes as equal iff their
|
||||||
|
* font numbers and characters are identical.
|
||||||
if (fontNum == dc.fontNum && charNum == dc.charNum)
|
*
|
||||||
return true;
|
* @param o the object (DuffCode) you want to compare
|
||||||
}
|
* @return true if this object is equal to o, false if not
|
||||||
return false;
|
*/
|
||||||
}
|
public boolean equals(Object o) {
|
||||||
|
if (o instanceof DuffCode) {
|
||||||
/**
|
DuffCode dc = (DuffCode)o;
|
||||||
* @return a string representation of this object
|
|
||||||
*/
|
if (fontNum == dc.fontNum && charNum == dc.charNum)
|
||||||
public String toString() {
|
return true;
|
||||||
return "fontNum="+fontNum+";charNum="+charNum+";character="+new Character(character).toString();
|
}
|
||||||
}
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return a string representation of this object
|
||||||
|
*/
|
||||||
|
public String toString() {
|
||||||
|
return "<duffcode font=" + TibetanMachineWeb.tmwFontNames[fontNum]
|
||||||
|
+ " charNum=" + charNum + " character="
|
||||||
|
+ new Character(character).toString() + "/>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@ import javax.swing.text.*;
|
||||||
import java.awt.font.*;
|
import java.awt.font.*;
|
||||||
|
|
||||||
import org.thdl.util.ThdlDebug;
|
import org.thdl.util.ThdlDebug;
|
||||||
|
import org.thdl.util.ThdlLazyException;
|
||||||
import org.thdl.util.Trie;
|
import org.thdl.util.Trie;
|
||||||
import org.thdl.util.ThdlOptions;
|
import org.thdl.util.ThdlOptions;
|
||||||
|
|
||||||
|
@ -537,17 +538,10 @@ public static boolean isFormatting(char c) {
|
||||||
* false if not
|
* false if not
|
||||||
*/
|
*/
|
||||||
public static boolean isChar(String s) {
|
public static boolean isChar(String s) {
|
||||||
if (currentKeyboardIsExtendedWylie()) {
|
if (currentKeyboardIsExtendedWylie())
|
||||||
if (charSet.contains(s))
|
return charSet.contains(s);
|
||||||
return true;
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
if (keyboard.isChar(s))
|
return keyboard.isChar(s);
|
||||||
return true;
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -934,6 +928,9 @@ public static String getWylieForGlyph(int font, int code) {
|
||||||
*/
|
*/
|
||||||
public static String getWylieForGlyph(DuffCode dc) {
|
public static String getWylieForGlyph(DuffCode dc) {
|
||||||
String hashKey = getHashKeyForGlyph(dc);
|
String hashKey = getHashKeyForGlyph(dc);
|
||||||
|
if (hashKey == null) {
|
||||||
|
return "<<[[JSKAD_TMW_TO_WYLIE_ERROR_NO_SUCH_WYLIE: Cannot convert DuffCode " + dc + " to THDL Extended Wylie. Please see the documentation for the TMW font and transcribe this yourself.]]>>";
|
||||||
|
}
|
||||||
return wylieForGlyph(hashKey);
|
return wylieForGlyph(hashKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue