Made performance improvements, doc improvements, and code cleanup to
DuffCode.
This commit is contained in:
parent
08d2ea3e2d
commit
a4bc23a9ab
3 changed files with 42 additions and 53 deletions
|
@ -10,7 +10,7 @@ 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-2003 THDL.
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
Contributor(s): ______________________________________.
|
Contributor(s): ______________________________________.
|
||||||
|
@ -31,24 +31,23 @@ import org.thdl.util.ThdlDebug;
|
||||||
* a character number. A font identification and a character
|
* a character number. A font identification and a character
|
||||||
* (or character number) are sufficient to uniquely identify
|
* (or character number) are sufficient to uniquely identify
|
||||||
* any TibetanMachineWeb glyph.
|
* 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
|
* @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,
|
* the font number in which this glyph can be found,
|
||||||
* from 1 (TibetanMachineWeb) to 10 (TibetanMachineWeb9).
|
* 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;
|
private int charNum;
|
||||||
/**
|
|
||||||
* the character value of this glyph, as an integer
|
|
||||||
*/
|
|
||||||
public int charNum;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called by {@link TibetanMachineWeb} to generate
|
* Called by {@link TibetanMachineWeb} to generate
|
||||||
|
@ -75,12 +74,10 @@ public class DuffCode {
|
||||||
if (leftToRight) {
|
if (leftToRight) {
|
||||||
setFontNum(num1.intValue());
|
setFontNum(num1.intValue());
|
||||||
charNum = num2.intValue();
|
charNum = num2.intValue();
|
||||||
character = (char)charNum;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
setFontNum(num2.intValue());
|
setFontNum(num2.intValue());
|
||||||
charNum = num1.intValue();
|
charNum = num1.intValue();
|
||||||
character = (char)charNum;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (NumberFormatException e) {
|
catch (NumberFormatException e) {
|
||||||
|
@ -97,7 +94,6 @@ public class DuffCode {
|
||||||
*/
|
*/
|
||||||
public DuffCode(int font, char ch) {
|
public DuffCode(int font, char ch) {
|
||||||
setFontNum(font);
|
setFontNum(font);
|
||||||
character = ch;
|
|
||||||
charNum = (int)ch;
|
charNum = (int)ch;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,23 +124,16 @@ public class DuffCode {
|
||||||
* @return the identifying character for this DuffCode
|
* @return the identifying character for this DuffCode
|
||||||
*/
|
*/
|
||||||
public char getCharacter() {
|
public char getCharacter() {
|
||||||
return character;
|
return (char)charNum;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Assigns a hashcode based on the font number and character for this glyph.
|
* Assigns a hashcode based on the font number and character for this
|
||||||
* The hashcode for a DuffCode with font=1 and character='c'
|
* glyph.
|
||||||
* is defined as the hash code of the string '1-c'.
|
|
||||||
*
|
*
|
||||||
* @return the hash code for this object
|
* @return the hash code for this object */
|
||||||
*/
|
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
StringBuffer sb = new StringBuffer();
|
return fontNum*256 + charNum;
|
||||||
sb.append(new Integer(fontNum).toString());
|
|
||||||
sb.append('-');
|
|
||||||
sb.append(character);
|
|
||||||
String s = sb.toString();
|
|
||||||
return s.hashCode();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -170,6 +159,6 @@ public class DuffCode {
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "<duffcode font=" + TibetanMachineWeb.tmwFontNames[fontNum]
|
return "<duffcode font=" + TibetanMachineWeb.tmwFontNames[fontNum]
|
||||||
+ " charNum=" + charNum + " character="
|
+ " charNum=" + charNum + " character="
|
||||||
+ new Character(character).toString() + "/>";
|
+ new Character(getCharacter()).toString() + "/>";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,18 +62,18 @@ public class TibTextUtils implements THDLWylieConstants {
|
||||||
StringBuffer sb = new StringBuffer();
|
StringBuffer sb = new StringBuffer();
|
||||||
Iterator iter = glyphs.iterator();
|
Iterator iter = glyphs.iterator();
|
||||||
DuffCode dc = (DuffCode)iter.next();
|
DuffCode dc = (DuffCode)iter.next();
|
||||||
int lastfont = dc.fontNum;
|
int lastfont = dc.getFontNum();
|
||||||
sb.append(dc.character);
|
sb.append(dc.getCharacter());
|
||||||
|
|
||||||
while (iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
dc = (DuffCode)iter.next();
|
dc = (DuffCode)iter.next();
|
||||||
if (dc.fontNum == lastfont)
|
if (dc.getFontNum() == lastfont)
|
||||||
sb.append(dc.character);
|
sb.append(dc.getCharacter());
|
||||||
else {
|
else {
|
||||||
data.add(new DuffData(sb.toString(), lastfont));
|
data.add(new DuffData(sb.toString(), lastfont));
|
||||||
lastfont = dc.fontNum;
|
lastfont = dc.getFontNum();
|
||||||
sb = new StringBuffer();
|
sb = new StringBuffer();
|
||||||
sb.append(dc.character);
|
sb.append(dc.getCharacter());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1096,9 +1096,9 @@ public class TibTextUtils implements THDLWylieConstants {
|
||||||
StringBuffer wylieBuffer = new StringBuffer();
|
StringBuffer wylieBuffer = new StringBuffer();
|
||||||
|
|
||||||
for (int i=start; i<dcs.length; i++) {
|
for (int i=start; i<dcs.length; i++) {
|
||||||
ch = dcs[i].character;
|
ch = dcs[i].getCharacter();
|
||||||
int k = dcs[i].charNum;
|
int k = dcs[i].getCharNum();
|
||||||
// int fontNum = dcs[i].fontNum;
|
// int fontNum = dcs[i].getFontNum();
|
||||||
|
|
||||||
if (k < 32) {
|
if (k < 32) {
|
||||||
if (wylieBuffer.length() > 0 || !glyphList.isEmpty()) {
|
if (wylieBuffer.length() > 0 || !glyphList.isEmpty()) {
|
||||||
|
|
|
@ -390,7 +390,7 @@ public class TibetanMachineWeb implements THDLWylieConstants {
|
||||||
// TM(dos) equivalent), so we must
|
// TM(dos) equivalent), so we must
|
||||||
// test for null here:
|
// test for null here:
|
||||||
if (null != duffCodes[TM]) {
|
if (null != duffCodes[TM]) {
|
||||||
TMtoTMW[duffCodes[TM].fontNum-1][duffCodes[TM].charNum-32]
|
TMtoTMW[duffCodes[TM].getFontNum()-1][duffCodes[TM].getCharNum()-32]
|
||||||
= duffCodes[TMW];
|
= duffCodes[TMW];
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -421,8 +421,8 @@ public class TibetanMachineWeb implements THDLWylieConstants {
|
||||||
if (hashOn)
|
if (hashOn)
|
||||||
tibHash.put(wylie,duffCodes);
|
tibHash.put(wylie,duffCodes);
|
||||||
|
|
||||||
int font = duffCodes[2].fontNum;
|
int font = duffCodes[2].getFontNum();
|
||||||
int code = duffCodes[2].charNum-32;
|
int code = duffCodes[2].getCharNum()-32;
|
||||||
toHashKey[font][code] = wylie;
|
toHashKey[font][code] = wylie;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -790,6 +790,9 @@ public static boolean hasGlyph(String hashKey) {
|
||||||
*/
|
*/
|
||||||
public static DuffCode getGlyph(String hashKey) {
|
public static DuffCode getGlyph(String hashKey) {
|
||||||
DuffCode[] dc = (DuffCode[])tibHash.get(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];
|
return dc[TMW];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -871,7 +874,7 @@ public static int getTMWFontNumber(String name) {
|
||||||
/**
|
/**
|
||||||
* Gets the hash key associated with this glyph.
|
* Gets the hash key associated with this glyph.
|
||||||
* @param font a TibetanMachineWeb font number
|
* @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
|
* @return the hashKey corresponding to the character
|
||||||
* at font, code
|
* at font, code
|
||||||
*/
|
*/
|
||||||
|
@ -886,8 +889,8 @@ public static String getHashKeyForGlyph(int font, int code) {
|
||||||
* @return the hashKey corresponding to the character at dc
|
* @return the hashKey corresponding to the character at dc
|
||||||
*/
|
*/
|
||||||
public static String getHashKeyForGlyph(DuffCode dc) {
|
public static String getHashKeyForGlyph(DuffCode dc) {
|
||||||
int font = dc.fontNum;
|
int font = dc.getFontNum();
|
||||||
int code = dc.charNum-32;
|
int code = dc.getCharNum()-32;
|
||||||
return toHashKey[font][code];
|
return toHashKey[font][code];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -921,7 +924,7 @@ public static String wylieForGlyph(String hashKey) {
|
||||||
* Gets the Extended Wylie value for this glyph.
|
* Gets the Extended Wylie value for this glyph.
|
||||||
* @param font the font of the TibetanMachineWeb
|
* @param font the font of the TibetanMachineWeb
|
||||||
* glyph you want the Wylie of
|
* 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
|
* you want the Wylie of
|
||||||
* @return the Wylie value corresponding to the
|
* @return the Wylie value corresponding to the
|
||||||
* glyph denoted by font, code
|
* 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.
|
* Says whether or not this glyph involves a Sanskrit stack.
|
||||||
* @param font the font of a TibetanMachineWeb glyph
|
* @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,
|
* @return true if this glyph is a Sanskrit stack,
|
||||||
* false if not
|
* false if not
|
||||||
*/
|
*/
|
||||||
|
@ -987,8 +990,8 @@ public static boolean isSanskritStack(int font, int code) {
|
||||||
* false if not
|
* false if not
|
||||||
*/
|
*/
|
||||||
public static boolean isSanskritStack(DuffCode dc) {
|
public static boolean isSanskritStack(DuffCode dc) {
|
||||||
int font = dc.fontNum;
|
int font = dc.getFontNum();
|
||||||
int code = dc.charNum-32;
|
int code = dc.getCharNum()-32;
|
||||||
|
|
||||||
if (isSanskritStack(font, code))
|
if (isSanskritStack(font, code))
|
||||||
return true;
|
return true;
|
||||||
|
@ -999,7 +1002,7 @@ public static boolean isSanskritStack(DuffCode dc) {
|
||||||
/**
|
/**
|
||||||
* Says whether or not this glyph involves a Tibetan stack.
|
* Says whether or not this glyph involves a Tibetan stack.
|
||||||
* @param font the font of a TibetanMachineWeb glyph
|
* @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,
|
* @return true if this glyph is a Tibetan stack,
|
||||||
* false if not
|
* false if not
|
||||||
*/
|
*/
|
||||||
|
@ -1018,13 +1021,10 @@ public static boolean isStack(int font, int code) {
|
||||||
* false if not
|
* false if not
|
||||||
*/
|
*/
|
||||||
public static boolean isStack(DuffCode dc) {
|
public static boolean isStack(DuffCode dc) {
|
||||||
int font = dc.fontNum;
|
int font = dc.getFontNum();
|
||||||
int code = dc.charNum-32;
|
int code = dc.getCharNum()-32;
|
||||||
|
|
||||||
if (isStack(font, code))
|
return isStack(font, code);
|
||||||
return true;
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue