diff --git a/source/org/thdl/tib/text/DuffCode.java b/source/org/thdl/tib/text/DuffCode.java
index 0794296..bbc9a5d 100644
--- a/source/org/thdl/tib/text/DuffCode.java
+++ b/source/org/thdl/tib/text/DuffCode.java
@@ -10,7 +10,7 @@ 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 2001 THDL.
+Library (THDL). Portions created by the THDL are Copyright 2001-2003 THDL.
All Rights Reserved.
Contributor(s): ______________________________________.
@@ -31,24 +31,23 @@ import org.thdl.util.ThdlDebug;
* a character number. A font identification and a character
* (or character number) are sufficient to uniquely identify
* any TibetanMachineWeb glyph.
+*
+* Note that DuffCodes are sometimes used, internally, to represent
+* glyphs in other fonts, e.g. the TibetanMachine font. But mainly
+* they represent TibetanMachineWeb glyphs.
* @author Edward Garrett, Tibetan and Himalayan Digital Library
-* @version 1.0
-*/
+* @version 1.0 */
-public class DuffCode {
+public final class DuffCode {
/**
* the font number in which this glyph can be found,
* from 1 (TibetanMachineWeb) to 10 (TibetanMachineWeb9).
*/
- public int fontNum;
+ private int fontNum;
/**
-* the character value of this glyph
+* the character value of this glyph, as an integer (that is, ordinal)
*/
- public char character;
-/**
-* the character value of this glyph, as an integer
-*/
- public int charNum;
+ private int charNum;
/**
* Called by {@link TibetanMachineWeb} to generate
@@ -75,12 +74,10 @@ public class DuffCode {
if (leftToRight) {
setFontNum(num1.intValue());
charNum = num2.intValue();
- character = (char)charNum;
}
else {
setFontNum(num2.intValue());
charNum = num1.intValue();
- character = (char)charNum;
}
}
catch (NumberFormatException e) {
@@ -97,7 +94,6 @@ public class DuffCode {
*/
public DuffCode(int font, char ch) {
setFontNum(font);
- character = ch;
charNum = (int)ch;
}
@@ -128,23 +124,16 @@ public class DuffCode {
* @return the identifying character for this DuffCode
*/
public char getCharacter() {
- return character;
+ return (char)charNum;
}
/**
-* Assigns a hashcode based on the font number and character for this glyph.
-* The hashcode for a DuffCode with font=1 and character='c'
-* is defined as the hash code of the string '1-c'.
+* Assigns a hashcode based on the font number and character for this
+* glyph.
*
-* @return the hash code for this object
-*/
+* @return the hash code for this object */
public int hashCode() {
- StringBuffer sb = new StringBuffer();
- sb.append(new Integer(fontNum).toString());
- sb.append('-');
- sb.append(character);
- String s = sb.toString();
- return s.hashCode();
+ return fontNum*256 + charNum;
}
/**
@@ -170,6 +159,6 @@ public class DuffCode {
public String toString() {
return "";
+ + new Character(getCharacter()).toString() + "/>";
}
}
diff --git a/source/org/thdl/tib/text/TibTextUtils.java b/source/org/thdl/tib/text/TibTextUtils.java
index 81a3f9a..4ad6b09 100644
--- a/source/org/thdl/tib/text/TibTextUtils.java
+++ b/source/org/thdl/tib/text/TibTextUtils.java
@@ -62,18 +62,18 @@ public class TibTextUtils implements THDLWylieConstants {
StringBuffer sb = new StringBuffer();
Iterator iter = glyphs.iterator();
DuffCode dc = (DuffCode)iter.next();
- int lastfont = dc.fontNum;
- sb.append(dc.character);
+ int lastfont = dc.getFontNum();
+ sb.append(dc.getCharacter());
while (iter.hasNext()) {
dc = (DuffCode)iter.next();
- if (dc.fontNum == lastfont)
- sb.append(dc.character);
+ if (dc.getFontNum() == lastfont)
+ sb.append(dc.getCharacter());
else {
data.add(new DuffData(sb.toString(), lastfont));
- lastfont = dc.fontNum;
+ lastfont = dc.getFontNum();
sb = new StringBuffer();
- sb.append(dc.character);
+ sb.append(dc.getCharacter());
}
}
@@ -1096,9 +1096,9 @@ public class TibTextUtils implements THDLWylieConstants {
StringBuffer wylieBuffer = new StringBuffer();
for (int i=start; i 0 || !glyphList.isEmpty()) {
diff --git a/source/org/thdl/tib/text/TibetanMachineWeb.java b/source/org/thdl/tib/text/TibetanMachineWeb.java
index f4239a8..5d4af05 100644
--- a/source/org/thdl/tib/text/TibetanMachineWeb.java
+++ b/source/org/thdl/tib/text/TibetanMachineWeb.java
@@ -390,7 +390,7 @@ public class TibetanMachineWeb implements THDLWylieConstants {
// TM(dos) equivalent), so we must
// test for null here:
if (null != duffCodes[TM]) {
- TMtoTMW[duffCodes[TM].fontNum-1][duffCodes[TM].charNum-32]
+ TMtoTMW[duffCodes[TM].getFontNum()-1][duffCodes[TM].getCharNum()-32]
= duffCodes[TMW];
}
break;
@@ -421,8 +421,8 @@ public class TibetanMachineWeb implements THDLWylieConstants {
if (hashOn)
tibHash.put(wylie,duffCodes);
- int font = duffCodes[2].fontNum;
- int code = duffCodes[2].charNum-32;
+ int font = duffCodes[2].getFontNum();
+ int code = duffCodes[2].getCharNum()-32;
toHashKey[font][code] = wylie;
}
}
@@ -790,6 +790,9 @@ public static boolean hasGlyph(String hashKey) {
*/
public static DuffCode getGlyph(String hashKey) {
DuffCode[] dc = (DuffCode[])tibHash.get(hashKey);
+ // If dc is null, then likely you misconfigured tibwn.ini such
+ // that, say, M is expected (i.e., it is listed as,
+ // e.g. punctuation), but no 'M~...' line appears.
return dc[TMW];
}
@@ -871,7 +874,7 @@ public static int getTMWFontNumber(String name) {
/**
* Gets the hash key associated with this glyph.
* @param font a TibetanMachineWeb font number
-* @param code an ASCII character code
+* @param code an ASCII character code minus 32
* @return the hashKey corresponding to the character
* at font, code
*/
@@ -886,8 +889,8 @@ public static String getHashKeyForGlyph(int font, int code) {
* @return the hashKey corresponding to the character at dc
*/
public static String getHashKeyForGlyph(DuffCode dc) {
- int font = dc.fontNum;
- int code = dc.charNum-32;
+ int font = dc.getFontNum();
+ int code = dc.getCharNum()-32;
return toHashKey[font][code];
}
@@ -921,7 +924,7 @@ public static String wylieForGlyph(String hashKey) {
* Gets the Extended Wylie value for this glyph.
* @param font the font of the TibetanMachineWeb
* glyph you want the Wylie of
-* @param code the TibetanMachineWeb glyph
+* @param code the ordinal, minus 32, of the TibetanMachineWeb glyph
* you want the Wylie of
* @return the Wylie value corresponding to the
* glyph denoted by font, code
@@ -968,7 +971,7 @@ public static String getWylieForGlyph(DuffCode dc) {
/**
* Says whether or not this glyph involves a Sanskrit stack.
* @param font the font of a TibetanMachineWeb glyph
-* @param code the ASCII value of a TibetanMachineWeb glyph
+* @param code the ASCII value of a TibetanMachineWeb glyph minus 32
* @return true if this glyph is a Sanskrit stack,
* false if not
*/
@@ -987,8 +990,8 @@ public static boolean isSanskritStack(int font, int code) {
* false if not
*/
public static boolean isSanskritStack(DuffCode dc) {
- int font = dc.fontNum;
- int code = dc.charNum-32;
+ int font = dc.getFontNum();
+ int code = dc.getCharNum()-32;
if (isSanskritStack(font, code))
return true;
@@ -999,7 +1002,7 @@ public static boolean isSanskritStack(DuffCode dc) {
/**
* Says whether or not this glyph involves a Tibetan stack.
* @param font the font of a TibetanMachineWeb glyph
-* @param code the ASCII value of a TibetanMachineWeb glyph
+* @param code the ASCII value of a TibetanMachineWeb glyph minus 32
* @return true if this glyph is a Tibetan stack,
* false if not
*/
@@ -1018,13 +1021,10 @@ public static boolean isStack(int font, int code) {
* false if not
*/
public static boolean isStack(DuffCode dc) {
- int font = dc.fontNum;
- int code = dc.charNum-32;
+ int font = dc.getFontNum();
+ int code = dc.getCharNum()-32;
- if (isStack(font, code))
- return true;
- else
- return false;
+ return isStack(font, code);
}
/**