Factored TibetanDocument into two classes, one that is a

DefaultStyledDocument, and another consisting entirely of static utility
methods for processing Tibetan text.  Moved TibetanDocument.DuffData
into its own class.

I think this makes things a bit more transparent, and gets us a little closer to
making clean use of Swing.
This commit is contained in:
dchandler 2002-11-02 03:38:59 +00:00
parent 5249c48807
commit abcf8f19b3
25 changed files with 1490 additions and 1337 deletions

View file

@ -225,18 +225,6 @@ public RTFEditorKit rtfEd = null;
// this(new StyledEditorKit(), keyboardURL);
}
// DLC
private Action getActionByName(String name) {
Action[] actions = this.getActions();
for (int i = 0; i < actions.length; i++) {
if (actions[i].getValue(Action.NAME).equals(name)) {
return actions[i];
}
}
return null;
}
/** Creates a new DuffPane that updates sb, if sb is not null,
with messages about how the users' keypresses are being
interpreted. */
@ -640,7 +628,7 @@ public RTFEditorKit rtfEd = null;
backSpace(oldGlyphCount - beginDifference);
java.util.List sublist = newGlyphList.subList(k, newGlyphCount);
TibetanDocument.DuffData[] dd = TibetanDocument.convertGlyphs(sublist);
DuffData[] dd = TibTextUtils.convertGlyphs(sublist);
doc.insertDuff(caret.getDot(), dd);
return newGlyphList;
}
@ -705,7 +693,7 @@ public RTFEditorKit rtfEd = null;
before_vowel.add(dc_1);
before_vowel.add(dc_2);
java.util.List after_vowel = TibetanDocument.getVowel(dc_1, dc_2, v);
java.util.List after_vowel = TibTextUtils.getVowel(dc_1, dc_2, v);
redrawGlyphs(before_vowel, after_vowel);
}
catch(BadLocationException ble) {
@ -728,8 +716,8 @@ public RTFEditorKit rtfEd = null;
private void printAChenWithVowel(String v) {
DuffCode[] dc_array = (DuffCode[])TibetanMachineWeb.getTibHash().get(TibetanMachineWeb.ACHEN);
DuffCode dc = dc_array[TibetanMachineWeb.TMW];
java.util.List achenlist = TibetanDocument.getVowel(dc,v);
TibetanDocument.DuffData[] dd = TibetanDocument.convertGlyphs(achenlist);
java.util.List achenlist = TibTextUtils.getVowel(dc,v);
DuffData[] dd = TibTextUtils.convertGlyphs(achenlist);
doc.insertDuff(caret.getDot(), dd);
}
@ -765,7 +753,7 @@ public RTFEditorKit rtfEd = null;
DuffCode dc = new DuffCode(fontNum, c2);
java.util.List beforecaret = new ArrayList();
beforecaret.add(dc);
java.util.List bindulist = TibetanDocument.getBindu(dc);
java.util.List bindulist = TibTextUtils.getBindu(dc);
redrawGlyphs(beforecaret, bindulist);
initKeyboard();
return;
@ -775,7 +763,7 @@ public RTFEditorKit rtfEd = null;
}
}
TibetanDocument.DuffData[] dd = TibetanDocument.convertGlyphs(TibetanDocument.getBindu(null));
DuffData[] dd = TibTextUtils.convertGlyphs(TibTextUtils.getBindu(null));
doc.insertDuff(caret.getDot(), dd);
initKeyboard();
}
@ -1162,7 +1150,7 @@ public void paste(int offset) {
* type s-g-r, you see a single glyph, a three-letter stack, but if you
* type s-d-r, you see two glyphs. If you examine the status bar,
* you'll see that the thing determining that is
* TibetanDocument.getGlyphs, which in turn relies on 'tibwn.ini'.
* TibTextUtils.getGlyphs, which in turn relies on 'tibwn.ini'.
*
* @param e a KeyEvent */
public void processTibetan(KeyEvent e) {
@ -1214,11 +1202,11 @@ public void paste(int offset) {
appendStatus(" (because you pressed the stacking key with nothing to stack on)");
} else if (size > 1 && isStackingRightToLeft) {
String s = (String)charList.remove(charList.size() - 1);
newGlyphList = TibetanDocument.getGlyphs(charList, isStackingRightToLeft, isDefinitelyTibetan, isDefinitelySanskrit);
newGlyphList = TibTextUtils.getGlyphs(charList, isStackingRightToLeft, isDefinitelyTibetan, isDefinitelySanskrit);
oldGlyphList = redrawGlyphs(oldGlyphList, newGlyphList);
initKeyboard();
charList.add(s);
newGlyphList = TibetanDocument.getGlyphs(charList, isStackingRightToLeft, isDefinitelyTibetan, isDefinitelySanskrit);
newGlyphList = TibTextUtils.getGlyphs(charList, isStackingRightToLeft, isDefinitelyTibetan, isDefinitelySanskrit);
oldGlyphList = redrawGlyphs(oldGlyphList, newGlyphList);
holdCurrent = new StringBuffer();
isTopHypothesis = false;
@ -1355,7 +1343,7 @@ public void paste(int offset) {
s = TibetanMachineWeb.getWylieForChar(s);
charList.add(s);
isTopHypothesis = true;
newGlyphList = TibetanDocument.getGlyphs(charList, isStackingRightToLeft, isDefinitelyTibetan, isDefinitelySanskrit);
newGlyphList = TibTextUtils.getGlyphs(charList, isStackingRightToLeft, isDefinitelyTibetan, isDefinitelySanskrit);
oldGlyphList = redrawGlyphs(oldGlyphList, newGlyphList);
changedStatus = true;
updateStatus("You typed a non-vowel, Tibetan character.");
@ -1379,7 +1367,7 @@ public void paste(int offset) {
if (isTopHypothesis) {
if (TibetanMachineWeb.isAChungConsonant() && isStackingOn && charList.size()>1 && s2.equals(TibetanMachineWeb.ACHUNG)) {
charList.remove(charList.size() - 1);
newGlyphList = TibetanDocument.getGlyphs(charList, isStackingRightToLeft, isDefinitelyTibetan, isDefinitelySanskrit);
newGlyphList = TibTextUtils.getGlyphs(charList, isStackingRightToLeft, isDefinitelyTibetan, isDefinitelySanskrit);
oldGlyphList = redrawGlyphs(oldGlyphList, newGlyphList);
putVowel(TibetanMachineWeb.A_VOWEL);
initKeyboard();
@ -1388,7 +1376,7 @@ public void paste(int offset) {
break key_block;
}
charList.set(charList.size()-1, s2);
newGlyphList = TibetanDocument.getGlyphs(charList, isStackingRightToLeft, isDefinitelyTibetan, isDefinitelySanskrit);
newGlyphList = TibTextUtils.getGlyphs(charList, isStackingRightToLeft, isDefinitelyTibetan, isDefinitelySanskrit);
oldGlyphList = redrawGlyphs(oldGlyphList, newGlyphList);
} else {
if (!isStackingOn) {
@ -1406,7 +1394,7 @@ public void paste(int offset) {
charList.add(s2);
isTopHypothesis = true;
newGlyphList = TibetanDocument.getGlyphs(charList, isStackingRightToLeft, isDefinitelyTibetan, isDefinitelySanskrit);
newGlyphList = TibTextUtils.getGlyphs(charList, isStackingRightToLeft, isDefinitelyTibetan, isDefinitelySanskrit);
oldGlyphList = redrawGlyphs(oldGlyphList, newGlyphList);
}
} else { //the holding string is not a character
@ -1441,7 +1429,7 @@ public void paste(int offset) {
}
charList.add(s2);
newGlyphList = TibetanDocument.getGlyphs(charList, isStackingRightToLeft, isDefinitelyTibetan, isDefinitelySanskrit);
newGlyphList = TibTextUtils.getGlyphs(charList, isStackingRightToLeft, isDefinitelyTibetan, isDefinitelySanskrit);
oldGlyphList = redrawGlyphs(oldGlyphList, newGlyphList);
changedStatus = true;
updateStatus("added character to charList");
@ -1511,7 +1499,7 @@ public void paste(int offset) {
dc_array = new DuffCode[0];
dc_array = (DuffCode[])dcs.toArray(dc_array);
doc.remove(start, i-start);
append(start, TibetanDocument.getWylie(dc_array), romanAttributeSet);
append(start, TibTextUtils.getWylie(dc_array), romanAttributeSet);
dcs.clear();
}
start = i+1;
@ -1552,7 +1540,7 @@ public void paste(int offset) {
ThdlDebug.noteIffyCode();
}
} else {
TibetanDocument.DuffData[] dd = TibetanDocument.getTibetanMachineWeb(next);
DuffData[] dd = TibTextUtils.getTibetanMachineWeb(next);
offset = doc.insertDuff(offset, dd);
}
}
@ -1603,7 +1591,7 @@ public void paste(int offset) {
if ((0 != (fontNum = TibetanMachineWeb.getTMWFontNumber(fontName))) || i==endPos.getOffset()) {
if (i != start) {
try {
TibetanDocument.DuffData[] duffdata = TibetanDocument.getTibetanMachineWeb(sb.toString());
DuffData[] duffdata = TibTextUtils.getTibetanMachineWeb(sb.toString());
doc.remove(start, i-start);
doc.insertDuff(start, duffdata);
}
@ -1630,4 +1618,14 @@ public void paste(int offset) {
}
}
/**
* Converts the entire associated document into Extended Wylie. If the
* document consists of both Tibetan and non-Tibetan fonts, however,
* the conversion stops at the first non-Tibetan font.
* @return the string of Wylie corresponding to the associated document
* @see org.thdl.tib.text.TibetanDocument.getWylie() */
public String getWylie() {
return doc.getWylie();
}
}

View file

@ -47,6 +47,7 @@ public class Jskad2JavaScript extends JApplet {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch (Exception e) {
ThdlDebug.noteIffyCode();
}
setContentPane(makeContentPane());
}
@ -61,11 +62,10 @@ public class Jskad2JavaScript extends JApplet {
public void theRealActionPerformed(ActionEvent e)
{
try {
TibetanDocument t_doc = (TibetanDocument)jskad.dp.getDocument();
String wylie = t_doc.getWylie();
Object[] args = {wylie};
Object[] args = { jskad.dp.getWylie() };
JSObject.getWindow(Jskad2JavaScript.this).call("settext", args);
} catch (Exception ex) {
ThdlDebug.noteIffyCode();
}
}
});

View file

@ -68,11 +68,11 @@ public class Jskad4JavaScript extends JApplet {
public void setWylie(String wylie) {
try {
TibetanDocument.DuffData[] dd = TibetanDocument.getTibetanMachineWeb(wylie);
DuffData[] dd = TibTextUtils.getTibetanMachineWeb(wylie);
TibetanDocument t_doc = (TibetanDocument)jskad.dp.getDocument();
if (t_doc.getLength() > 0)
jskad.dp.newDocument();
TibetanDocument.DuffData[] duffdata = TibetanDocument.getTibetanMachineWeb(wylie);
jskad.dp.newDocument(); // DLC FIXME: is it intended that t_doc is the new document? Because it is the old document at present.
DuffData[] duffdata = TibTextUtils.getTibetanMachineWeb(wylie);
t_doc.insertDuff(0, duffdata);
}
catch (InvalidWylieException iwe) {
@ -84,7 +84,6 @@ public class Jskad4JavaScript extends JApplet {
}
public String getWylie() {
TibetanDocument t_doc = (TibetanDocument)jskad.dp.getDocument();
return t_doc.getWylie();
return jskad.dp.getWylie();
}
}

View file

@ -61,8 +61,7 @@ public class JskadConversionTool extends JApplet {
public void theRealActionPerformed(ActionEvent e)
{
try {
TibetanDocument t_doc = (TibetanDocument)jskad.dp.getDocument();
String wylie = t_doc.getWylie();
String wylie = jskad.dp.getWylie();
String html = "<HTML>\n<HEAD>\n<STYLE>\n";
html += TibetanHTML.getStyles("28");
html += "</STYLE>\n</HEAD>\n<BODY>\n";

View file

@ -25,7 +25,6 @@ import javax.swing.text.JTextComponent;
import java.awt.event.*;
import java.awt.datatransfer.*;
import org.thdl.tib.input.DuffPane;
import org.thdl.tib.text.TibetanDocument;
/** Inputs a Tibetan text and displays the words with
their definitions through through a graphical interfase using a
@ -244,7 +243,7 @@ public class AppletScannerFilter extends JApplet implements ActionListener, Focu
{
try
{
((TibetanDocument)t.getDocument()).remove(t.getSelectionStart(), t.getSelectionEnd());
t.getDocument().remove(t.getSelectionStart(), t.getSelectionEnd());
}
catch (Exception ex)
{

View file

@ -19,8 +19,8 @@ package org.thdl.tib.scanner;
import javax.swing.*;
import javax.swing.table.*;
import org.thdl.tib.text.TibetanDocument;
import org.thdl.tib.text.TibetanDocument.DuffData;
import org.thdl.tib.text.TibTextUtils;
import org.thdl.tib.text.DuffData;
/** Stores the words being displayed in a DictionaryTable.
@ -114,7 +114,7 @@ public class DictionaryTableModel extends AbstractTableModel
try
{
for (i=0; i<array.length; i++)
arrayTibetan[i]=TibetanDocument.getTibetanMachineWeb(array[i].getWylie());
arrayTibetan[i]=TibTextUtils.getTibetanMachineWeb(array[i].getWylie());
}
catch (Exception e)
{
@ -122,4 +122,4 @@ public class DictionaryTableModel extends AbstractTableModel
}
}
}
}
}

View file

@ -24,7 +24,7 @@ import javax.swing.border.*;
import javax.swing.text.*;
import org.thdl.tib.input.DuffPane;
import org.thdl.tib.text.*;
import org.thdl.tib.text.TibetanDocument.DuffData;
import org.thdl.tib.text.DuffData;
import java.io.Serializable;
/** Used by DictionaryTable to display a Tibetan word or phrase
@ -133,7 +133,8 @@ public class DuffCellRenderer extends DuffPane implements TableCellRenderer, Ser
catch (Exception e)
{
System.out.println(e);
ThdlDebug.noteIffyCode();
}
doc.insertDuff(0, (DuffData []) value);
}
}
}

View file

@ -23,7 +23,6 @@ import javax.swing.*;
import javax.swing.event.*;
import javax.swing.table.*;
import org.thdl.tib.input.DuffPane;
import org.thdl.tib.text.TibetanDocument;
/** Graphical interfase to be used by applications and applets
to input a Tibetan text (in Roman or Tibetan script) and
@ -142,7 +141,7 @@ public class DuffScannerPanel extends ScannerPanel
in = "";
if (showingTibetan)
in = ((TibetanDocument)duffInput.getDocument()).getWylie();
in = duffInput.getWylie();
else
in = txtInput.getText();
@ -192,7 +191,7 @@ public class DuffScannerPanel extends ScannerPanel
}
if (!enabled && showingTibetan)
{
txtInput.setText(((TibetanDocument)duffInput.getDocument()).getWylie());
txtInput.setText(duffInput.getWylie());
table.activateTibetan(false);
cl.last(inputPanel);
showingTibetan = false;

View file

@ -27,7 +27,6 @@ import java.awt.*;
import java.awt.datatransfer.*;
import javax.swing.text.JTextComponent;
import org.thdl.tib.input.DuffPane;
import org.thdl.tib.text.TibetanDocument;
public class WindowScannerFilter implements WindowListener, FocusListener, ActionListener, ItemListener
{
@ -339,7 +338,7 @@ public class WindowScannerFilter implements WindowListener, FocusListener, Actio
{
try
{
((TibetanDocument)t.getDocument()).remove(t.getSelectionStart(), t.getSelectionEnd());
t.getDocument().remove(t.getSelectionStart(), t.getSelectionEnd());
}
catch (Exception ex)
{

View file

@ -25,7 +25,9 @@ import javax.swing.border.*;
import javax.swing.text.*;
import org.thdl.tib.input.DuffPane;
import org.thdl.tib.text.*;
import org.thdl.tib.text.TibetanDocument.DuffData;
import org.thdl.tib.text.DuffData;
import org.thdl.util.ThdlDebug;
import java.io.Serializable;
/** Used by DictionaryTable to display a Tibetan word or phrase
@ -135,6 +137,7 @@ public class DuffCellRenderer extends DuffPane implements TableCellRenderer, Ser
catch (Exception e)
{
System.out.println(e);
org.thdl.util.ThdlDebug.noteIffyCode();
}
doc.insertDuff(0, (DuffData []) value);
}

View file

@ -0,0 +1,53 @@
/*
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 2001 THDL.
All Rights Reserved.
Contributor(s): ______________________________________.
*/
package org.thdl.tib.text;
/**
* A wrapper object for a stretch of TibetanMachineWeb data that shares the same font.
* A piece of DuffData consists of a font number and a string.
* The font number is a number from one to ten, corresponding
* to the ten TibetanMachineWeb fonts, as follows:
* <p>
* 1 - TibetanMachineWeb<br>
* 2 - TibetanMachineWeb1<br>
* ...<br>
* 10 - TibetanMachineWeb9<br>
* <p>
* The string represents a contiguous stretch of data in that
* font, i.e. a stretch of TibetanMachineWeb that doesn't require a font change.
*/
public class DuffData {
/**
* a string of text
*/
public String text;
/**
* the font number for this text (see class description)
*/
public int font;
/**
* @param s a string of TibetanMachineWeb text
* @param i a TibetanMachineWeb font number
*/
public DuffData(String s, int i) {
text = s;
font = i;
}
}

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1,144 +1,225 @@
package org.thdl.tib.text;
public class TibetanHTML {
static String[] styleNames =
{"tmw","tmw1","tmw2","tmw3","tmw4","tmw5","tmw6","tmw7","tmw8","tmw9"};
public static String getStyles(String fontSize) {
return ".tmw {font: "+fontSize+"pt TibetanMachineWeb}\n"+
".tmw1 {font: "+fontSize+"pt TibetanMachineWeb1}\n"+
".tmw2 {font: "+fontSize+"pt TibetanMachineWeb2}\n"+
".tmw3 {font: "+fontSize+"pt TibetanMachineWeb3}\n"+
".tmw4 {font: "+fontSize+"pt TibetanMachineWeb4}\n"+
".tmw5 {font: "+fontSize+"pt TibetanMachineWeb5}\n"+
".tmw6 {font: "+fontSize+"pt TibetanMachineWeb6}\n"+
".tmw7 {font: "+fontSize+"pt TibetanMachineWeb7}\n"+
".tmw8 {font: "+fontSize+"pt TibetanMachineWeb8}\n"+
".tmw9 {font: "+fontSize+"pt TibetanMachineWeb9}\n";
}
public static String getHTML(String wylie) {
try {
return getHTML(TibetanDocument.getTibetanMachineWeb(wylie));
}
catch (InvalidWylieException ive) {
return null;
}
}
public static String getHTML(TibetanDocument.DuffData[] duffData) {
String[] styleNames =
{"tmw","tmw1","tmw2","tmw3","tmw4","tmw5","tmw6","tmw7","tmw8","tmw9"};
StringBuffer htmlBuffer = new StringBuffer();
htmlBuffer.append("<nobr>");
for (int i=0; i<duffData.length; i++) {
char[] c = duffData[i].text.toCharArray();
for (int k=0; k<c.length; k++) {
htmlBuffer.append("<span class=\"");
htmlBuffer.append(styleNames[duffData[i].font-1]);
htmlBuffer.append("\">");
switch (c[k]) {
case '"':
htmlBuffer.append("&quot");
break;
case '<':
htmlBuffer.append("&lt");
break;
case '>':
htmlBuffer.append("&gt");
break;
case '&':
htmlBuffer.append("&amp");
break;
default:
htmlBuffer.append(c[k]);
break;
}
htmlBuffer.append("</span>");
if (c[k] < 32) //must be formatting, like carriage return or tab
htmlBuffer.append("<br>");
else {
String wylie = TibetanMachineWeb.getWylieForGlyph(duffData[i].font, c[k]);
if (TibetanMachineWeb.isWyliePunc(wylie))
htmlBuffer.append("<wbr>");
}
}
}
htmlBuffer.append("</nobr>");
return htmlBuffer.toString();
}
}
//import org.apache.xerces.dom.DOMImplementationImpl;
//import org.w3c.dom.*;
/*
public static Node getHTML(String wylie) {
try {
return getHTML(TibetanDocument.getTibetanMachineWeb(wylie));
}
catch (InvalidWylieException ive) {
return null;
}
}
public static Node getHTML(TibetanDocument.DuffData[] duffData) {
try {
DOMImplementationImpl impl = new DOMImplementationImpl();
Document doc = impl.createDocument(null, "root", null);
// DocumentFragment frag = doc.createDocumentFragment()
Element nobr = doc.createElement("nobr");
// frag.appendChild(nobr);
for (int i=0; i<duffData.length; i++) {
char[] c = duffData[i].text.toCharArray();
for (int k=0; k<c.length; k++) {
Element span = doc.createElement("span");
span.setAttribute("class", styleNames[duffData[i].font-1]);
// Text tib = doc.createTextNode(String.valueOf(c[k]));
// span.appendChild(tib);
nobr.appendChild(span);
String wylie = TibetanMachineWeb.getWylieForGlyph(duffData[i].font, c[k]);
if (TibetanMachineWeb.isWyliePunc(wylie)) {
Element wbr = doc.createElement("wbr");
nobr.appendChild(wbr);
}
}
}
//doc.appendChild(nobr);
return nobr;
// return frag;
}
catch (DOMException dome) {
switch (dome.code) {
case DOMException.HIERARCHY_REQUEST_ERR:
System.out.println("hierarchy error!!");
break;
case DOMException.WRONG_DOCUMENT_ERR:
System.out.println("wrong doc error!!");
break;
case DOMException.NO_MODIFICATION_ALLOWED_ERR:
System.out.println("no mod allowed error!!");
break;
}
return null;
}
}
*/
package org.thdl.tib.text;
import java.util.StringTokenizer;
public class TibetanHTML {
static String[] styleNames =
{"tmw","tmw1","tmw2","tmw3","tmw4","tmw5","tmw6","tmw7","tmw8","tmw9"};
public static String getStyles(String fontSize) {
return ".tmw {font: "+fontSize+"pt TibetanMachineWeb}\n"+
".tmw1 {font: "+fontSize+"pt TibetanMachineWeb1}\n"+
".tmw2 {font: "+fontSize+"pt TibetanMachineWeb2}\n"+
".tmw3 {font: "+fontSize+"pt TibetanMachineWeb3}\n"+
".tmw4 {font: "+fontSize+"pt TibetanMachineWeb4}\n"+
".tmw5 {font: "+fontSize+"pt TibetanMachineWeb5}\n"+
".tmw6 {font: "+fontSize+"pt TibetanMachineWeb6}\n"+
".tmw7 {font: "+fontSize+"pt TibetanMachineWeb7}\n"+
".tmw8 {font: "+fontSize+"pt TibetanMachineWeb8}\n"+
".tmw9 {font: "+fontSize+"pt TibetanMachineWeb9}\n";
}
public static String getHTMLX(String wylie) {
try {
StringBuffer buffer = new StringBuffer();
for (StringTokenizer tokenizer = new StringTokenizer(wylie, " \t\n", true); tokenizer.hasMoreElements();) {
String next = tokenizer.nextToken();
if (next.equals("\t") || next.equals("\n")) {
buffer.append("<wbr/>");
buffer.append(getHTML(TibTextUtils.getTibetanMachineWeb("_")));
buffer.append("<wbr/>");
}
else
buffer.append(getHTML(TibTextUtils.getTibetanMachineWeb(next)));
}
return buffer.toString();
} catch (InvalidWylieException ive) {
return "";
}
}
public static String getHTMLX(DuffData[] duffData) {
String[] styleNames =
{"tmw","tmw1","tmw2","tmw3","tmw4","tmw5","tmw6","tmw7","tmw8","tmw9"};
StringBuffer htmlBuffer = new StringBuffer();
htmlBuffer.append("<nobr>");
for (int i=0; i<duffData.length; i++) {
char[] c = duffData[i].text.toCharArray();
for (int k=0; k<c.length; k++) {
htmlBuffer.append("<span class=\"");
htmlBuffer.append(styleNames[duffData[i].font-1]);
htmlBuffer.append("\">");
if (c[k] > 32 && c[k] < 127) { //ie if it's not formatting
switch (c[k]) {
case '"':
htmlBuffer.append("&quot;");
break;
case '<':
htmlBuffer.append("&lt;");
break;
case '>':
htmlBuffer.append("&gt;");
break;
case '&':
htmlBuffer.append("&amp;");
break;
default:
htmlBuffer.append(c[k]);
break;
}
htmlBuffer.append("</span>");
String wylie = TibetanMachineWeb.getWylieForGlyph(duffData[i].font, c[k]);
if (TibetanMachineWeb.isWyliePunc(wylie))
htmlBuffer.append("<wbr/>");
} else {
htmlBuffer.append("</span><br/>");
}
}
}
htmlBuffer.append("</nobr>");
return htmlBuffer.toString();
}
public static String getIndentedHTML(String wylie) {
return getHTML("_" + wylie);
}
public static String getHTML(String wylie) {
try {
StringBuffer buffer = new StringBuffer();
for (StringTokenizer tokenizer = new StringTokenizer(wylie, " \t\n", true); tokenizer.hasMoreElements();) {
String next = tokenizer.nextToken();
if (next.equals("\t") || next.equals("\n")) {
buffer.append("<wbr/>");
buffer.append(getHTML(TibTextUtils.getTibetanMachineWeb("_")));
buffer.append("<wbr/>");
}
else
buffer.append(getHTML(TibTextUtils.getTibetanMachineWeb(next)));
}
return buffer.toString();
} catch (InvalidWylieException ive) {
return "";
}
}
public static String getHTML(DuffData[] duffData) {
String[] styleNames =
{"tmw","tmw1","tmw2","tmw3","tmw4","tmw5","tmw6","tmw7","tmw8","tmw9"};
StringBuffer htmlBuffer = new StringBuffer();
htmlBuffer.append("<nobr>");
for (int i=0; i<duffData.length; i++) {
htmlBuffer.append("<span class=\"");
htmlBuffer.append(styleNames[duffData[i].font-1]);
htmlBuffer.append("\">");
char[] c = duffData[i].text.toCharArray();
for (int k=0; k<c.length; k++) {
if (c[k] > 31 && c[k] < 127) { //ie if it's not formatting
switch (c[k]) {
case '"':
htmlBuffer.append("&quot;");
break;
case '<':
htmlBuffer.append("&lt;");
break;
case '>':
htmlBuffer.append("&gt;");
break;
case '&':
htmlBuffer.append("&amp;");
break;
default:
htmlBuffer.append(c[k]);
break;
}
String wylie = TibetanMachineWeb.getWylieForGlyph(duffData[i].font, c[k]);
if (TibetanMachineWeb.isWyliePunc(wylie))
htmlBuffer.append("<wbr/>");
} else {
htmlBuffer.append("<br/>");
}
}
htmlBuffer.append("</span>");
}
htmlBuffer.append("</nobr>");
return htmlBuffer.toString();
}
public static String getHTMLforJava(String wylie) {
//differences:
// as of 1.4.1, anyway, browser built into java does not accept <wbr/> and <br/>,
// only <wbr> and <br>
try {
StringBuffer buffer = new StringBuffer();
for (StringTokenizer tokenizer = new StringTokenizer(wylie, " \t\n", true); tokenizer.hasMoreElements();) {
String next = tokenizer.nextToken();
if (next.equals("\t") || next.equals("\n")) {
buffer.append("<wbr>");
buffer.append(getHTML(TibTextUtils.getTibetanMachineWeb("_")));
buffer.append("<wbr>");
}
else
buffer.append(getHTML(TibTextUtils.getTibetanMachineWeb(next)));
}
return buffer.toString();
} catch (InvalidWylieException ive) {
return "";
}
}
public static String getHTMLforJava(DuffData[] duffData) {
String[] fontNames = {
"TibetanMachineWeb","TibetanMachineWeb1", "TibetanMachineWeb2",
"TibetanMachineWeb3","TibetanMachineWeb4","TibetanMachineWeb5",
"TibetanMachineWeb6","TibetanMachineWeb7","TibetanMachineWeb8",
"TibetanMachineWeb9"};
StringBuffer htmlBuffer = new StringBuffer();
htmlBuffer.append("<nobr>");
for (int i=0; i<duffData.length; i++) {
htmlBuffer.append("<font size=\"36\" face=\"");
htmlBuffer.append(fontNames[duffData[i].font-1]);
htmlBuffer.append("\">");
char[] c = duffData[i].text.toCharArray();
for (int k=0; k<c.length; k++) {
if (c[k] > 31 && c[k] < 127) { //ie if it's not formatting
switch (c[k]) {
case '"':
htmlBuffer.append("&quot;");
break;
case '<':
htmlBuffer.append("&lt;");
break;
case '>':
htmlBuffer.append("&gt;");
break;
case '&':
htmlBuffer.append("&amp;");
break;
default:
htmlBuffer.append(c[k]);
break;
}
String wylie = TibetanMachineWeb.getWylieForGlyph(duffData[i].font, c[k]);
if (TibetanMachineWeb.isWyliePunc(wylie))
htmlBuffer.append("<wbr>");
} else {
htmlBuffer.append("<br>");
}
}
htmlBuffer.append("</font>");
}
htmlBuffer.append("</nobr>");
return htmlBuffer.toString();
}
}

View file

@ -126,14 +126,14 @@ public class TibetanQTText {
public static String getQTText(String wylie) {
try {
return getQTText(TibetanDocument.getTibetanMachineWeb(wylie));
return getQTText(TibTextUtils.getTibetanMachineWeb(wylie));
}
catch (InvalidWylieException ive) {
return null;
}
}
public static String getQTText(TibetanDocument.DuffData[] duffData) {
public static String getQTText(DuffData[] duffData) {
StringBuffer qtBuffer = new StringBuffer();
qtBuffer.append("{size:" + tibFontSize + "}");

View file

@ -126,14 +126,14 @@ public class TibetanQTText2 {
public static String getQTText(String wylie) {
try {
return getQTText(TibetanDocument.getTibetanMachineWeb(wylie));
return getQTText(TibTextUtils.getTibetanMachineWeb(wylie));
}
catch (InvalidWylieException ive) {
return null;
}
}
public static String getQTText(TibetanDocument.DuffData[] duffData) {
public static String getQTText(DuffData[] duffData) {
StringBuffer qtBuffer = new StringBuffer();
qtBuffer.append("{size:" + tibFontSize + "}");