Fixed the line feeds, which were botched DOS line feeds.

Added copyright boilerplate.
This commit is contained in:
dchandler 2002-09-28 14:35:09 +00:00
parent 3c82f0a24c
commit 1b47e7c268
2 changed files with 378 additions and 342 deletions

View file

@ -1,171 +1,189 @@
package org.thdl.tib.text; /*
The contents of this file are subject to the THDL Open Community License
import java.util.*; Version 1.0 (the "License"); you may not use this file except in compliance
import org.w3c.dom.*; with the License. You may obtain a copy of the License on the THDL web site
(http://www.thdl.org/).
public class TibetanQTText {
private static String tibFontSize = "28"; Software distributed under the License is distributed on an "AS IS" basis,
private Map lines; WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
private Map times; License for the specific terms governing rights and limitations under the
int id; License.
public TibetanQTText() { The Initial Developer of this software is the Tibetan and Himalayan Digital
lines = new HashMap(); Library (THDL). Portions created by the THDL are Copyright 2001 THDL.
times = new TreeMap(); All Rights Reserved.
id = 0;
} Contributor(s): ______________________________________.
*/
public void addLine(String wylie, String t1, String t2) {
id++; package org.thdl.tib.text;
String lineID = String.valueOf(id);
lines.put(lineID, wylie); import java.util.*;
import org.w3c.dom.*;
try {
Float startTime = new Float(t1); public class TibetanQTText {
if (!times.containsKey(startTime)) private static String tibFontSize = "28";
times.put(startTime, lineID+","); private Map lines;
else { private Map times;
String val = (String)times.get(startTime); int id;
val += lineID+",";
times.put(startTime, val); public TibetanQTText() {
} lines = new HashMap();
times = new TreeMap();
Float stopTime = new Float(t2); id = 0;
if (!times.containsKey(stopTime)) }
times.put(stopTime, lineID+",");
else { public void addLine(String wylie, String t1, String t2) {
String val = (String)times.get(stopTime); id++;
val += lineID+","; String lineID = String.valueOf(id);
times.put(stopTime, val); lines.put(lineID, wylie);
}
} try {
catch (NumberFormatException nfe) { Float startTime = new Float(t1);
} if (!times.containsKey(startTime))
times.put(startTime, lineID+",");
} else {
String val = (String)times.get(startTime);
public void organizeLines() { val += lineID+",";
List line_list = new ArrayList(); times.put(startTime, val);
}
Iterator iter = times.keySet().iterator();
while (iter.hasNext()) { Float stopTime = new Float(t2);
Float this_time = (Float)iter.next(); if (!times.containsKey(stopTime))
String these_lines = (String)times.get(this_time); times.put(stopTime, lineID+",");
else {
StringTokenizer sTok = new StringTokenizer(these_lines,","); String val = (String)times.get(stopTime);
while (sTok.hasMoreTokens()) { val += lineID+",";
String lineID = sTok.nextToken(); times.put(stopTime, val);
if (line_list.contains(lineID)) }
line_list.remove(lineID); }
else catch (NumberFormatException nfe) {
line_list.add(lineID); }
}
}
StringBuffer sb = new StringBuffer();
Iterator line_list_iter = line_list.iterator(); public void organizeLines() {
while (line_list_iter.hasNext()) { List line_list = new ArrayList();
String lineID = (String)line_list_iter.next();
sb.append(lineID); Iterator iter = times.keySet().iterator();
sb.append(','); while (iter.hasNext()) {
} Float this_time = (Float)iter.next();
String these_lines = (String)times.get(this_time);
times.put(this_time, sb.toString());
} StringTokenizer sTok = new StringTokenizer(these_lines,",");
} while (sTok.hasMoreTokens()) {
String lineID = sTok.nextToken();
public String getQTTextForLines() { if (line_list.contains(lineID))
StringBuffer sb = new StringBuffer(); line_list.remove(lineID);
else
Iterator iter = times.keySet().iterator(); line_list.add(lineID);
while (iter.hasNext()) { }
Float this_time = (Float)iter.next();
sb.append(getQTTimeTag(String.valueOf(this_time))); StringBuffer sb = new StringBuffer();
String these_lines = (String)times.get(this_time); Iterator line_list_iter = line_list.iterator();
while (line_list_iter.hasNext()) {
StringTokenizer sTok = new StringTokenizer(these_lines,","); String lineID = (String)line_list_iter.next();
while (sTok.hasMoreTokens()) { sb.append(lineID);
String lineID = sTok.nextToken(); sb.append(',');
String wylie = (String)lines.get(lineID); }
sb.append(getQTText(wylie));
sb.append('\n'); times.put(this_time, sb.toString());
} }
} }
return sb.toString(); public String getQTTextForLines() {
} StringBuffer sb = new StringBuffer();
public static String getQTHeader() { Iterator iter = times.keySet().iterator();
return "{QTtext}{plain}{anti-alias:off}{size:28}{justify:left}{timeScale:1000}{width:320}{height:120}{timeStamps:absolute}{language:0}{textEncoding:0}\n"; while (iter.hasNext()) {
} Float this_time = (Float)iter.next();
sb.append(getQTTimeTag(String.valueOf(this_time)));
public static String getQTTimeTag(String t) { String these_lines = (String)times.get(this_time);
StringBuffer sb = new StringBuffer();
sb.append('['); StringTokenizer sTok = new StringTokenizer(these_lines,",");
sb.append(t); while (sTok.hasMoreTokens()) {
sb.append(']'); String lineID = sTok.nextToken();
return sb.toString(); String wylie = (String)lines.get(lineID);
} sb.append(getQTText(wylie));
sb.append('\n');
public static String getQTText(String wylie) { }
try { }
return getQTText(TibetanDocument.getTibetanMachineWeb(wylie));
} return sb.toString();
catch (InvalidWylieException ive) { }
return null;
} public static String getQTHeader() {
} return "{QTtext}{plain}{anti-alias:off}{size:28}{justify:left}{timeScale:1000}{width:320}{height:120}{timeStamps:absolute}{language:0}{textEncoding:0}\n";
}
public static String getQTText(TibetanDocument.DuffData[] duffData) {
StringBuffer qtBuffer = new StringBuffer(); public static String getQTTimeTag(String t) {
qtBuffer.append("{size:" + tibFontSize + "}"); StringBuffer sb = new StringBuffer();
sb.append('[');
for (int i=0; i<duffData.length; i++) { sb.append(t);
qtBuffer.append("{font:" + TibetanMachineWeb.tmwFontNames[duffData[i].font] + "}"); sb.append(']');
qtBuffer.append(duffData[i].text); return sb.toString();
} }
return qtBuffer.toString(); public static String getQTText(String wylie) {
} try {
} return getQTText(TibetanDocument.getTibetanMachineWeb(wylie));
}
/* catch (InvalidWylieException ive) {
public void addLine(NodeList nodes) { return null;
}
}
Element line = (Element)nodes.item(0);
Node wylie_node = line.getFirstChild(); public static String getQTText(TibetanDocument.DuffData[] duffData) {
// NodeList wylie_nodes = line.getElementsByTagName("wylie"); StringBuffer qtBuffer = new StringBuffer();
qtBuffer.append("{size:" + tibFontSize + "}");
// Node wylie_node = wylie_nodes.item(0);
Node wylie_text = wylie_node.getFirstChild(); for (int i=0; i<duffData.length; i++) {
System.out.println(wylie_text.getNodeName()); qtBuffer.append("{font:" + TibetanMachineWeb.tmwFontNames[duffData[i].font] + "}");
// String wylie = wylie_text.getNodeValue(); qtBuffer.append(duffData[i].text);
id++; }
String lineID = String.valueOf(id);
lines.put(lineID, wylie); return qtBuffer.toString();
}
NodeList audio_nodes = line.getElementsByTagName("AUDIO"); }
Element audio_element = (Element)audio_nodes.item(0);
try { /*
Integer startTime = Integer.valueOf(audio_element.getAttribute("begin")); public void addLine(NodeList nodes) {
if (!times.containsKey(startTime))
times.put(startTime, lineID+",");
else { Element line = (Element)nodes.item(0);
String val = (String)times.get(startTime); Node wylie_node = line.getFirstChild();
val += lineID+","; // NodeList wylie_nodes = line.getElementsByTagName("wylie");
times.put(startTime, val);
} // Node wylie_node = wylie_nodes.item(0);
Node wylie_text = wylie_node.getFirstChild();
Integer stopTime = Integer.valueOf(audio_element.getAttribute("end")); System.out.println(wylie_text.getNodeName());
if (!times.containsKey(stopTime)) // String wylie = wylie_text.getNodeValue();
times.put(stopTime, lineID+","); id++;
else { String lineID = String.valueOf(id);
String val = (String)times.get(stopTime); lines.put(lineID, wylie);
val += lineID+",";
times.put(stopTime, val); NodeList audio_nodes = line.getElementsByTagName("AUDIO");
} Element audio_element = (Element)audio_nodes.item(0);
} try {
catch (NumberFormatException nfe) { Integer startTime = Integer.valueOf(audio_element.getAttribute("begin"));
} if (!times.containsKey(startTime))
} times.put(startTime, lineID+",");
*/ else {
String val = (String)times.get(startTime);
val += lineID+",";
times.put(startTime, val);
}
Integer stopTime = Integer.valueOf(audio_element.getAttribute("end"));
if (!times.containsKey(stopTime))
times.put(stopTime, lineID+",");
else {
String val = (String)times.get(stopTime);
val += lineID+",";
times.put(stopTime, val);
}
}
catch (NumberFormatException nfe) {
}
}
*/

View file

@ -1,171 +1,189 @@
package org.thdl.tib.text; /*
The contents of this file are subject to the THDL Open Community License
import java.util.*; Version 1.0 (the "License"); you may not use this file except in compliance
import org.w3c.dom.*; with the License. You may obtain a copy of the License on the THDL web site
(http://www.thdl.org/).
public class TibetanQTText2 {
private static String tibFontSize = "28"; Software distributed under the License is distributed on an "AS IS" basis,
private Map lines; WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
private Map times; License for the specific terms governing rights and limitations under the
int id; License.
public TibetanQTText2() { The Initial Developer of this software is the Tibetan and Himalayan Digital
lines = new HashMap(); Library (THDL). Portions created by the THDL are Copyright 2001 THDL.
times = new TreeMap(); All Rights Reserved.
id = 0;
} Contributor(s): ______________________________________.
*/
public void addLine(String wylie, String t1, String t2) {
id++; package org.thdl.tib.text;
String lineID = String.valueOf(id);
lines.put(lineID, wylie); import java.util.*;
import org.w3c.dom.*;
try {
Float startTime = new Float(t1); public class TibetanQTText2 {
if (!times.containsKey(startTime)) private static String tibFontSize = "28";
times.put(startTime, lineID+","); private Map lines;
else { private Map times;
String val = (String)times.get(startTime); int id;
val += lineID+",";
times.put(startTime, val); public TibetanQTText2() {
} lines = new HashMap();
times = new TreeMap();
Float stopTime = new Float(t2); id = 0;
if (!times.containsKey(stopTime)) }
times.put(stopTime, lineID+",");
else { public void addLine(String wylie, String t1, String t2) {
String val = (String)times.get(stopTime); id++;
val += lineID+","; String lineID = String.valueOf(id);
times.put(stopTime, val); lines.put(lineID, wylie);
}
} try {
catch (NumberFormatException nfe) { Float startTime = new Float(t1);
} if (!times.containsKey(startTime))
times.put(startTime, lineID+",");
} else {
String val = (String)times.get(startTime);
public void organizeLines() { val += lineID+",";
List line_list = new ArrayList(); times.put(startTime, val);
}
Iterator iter = times.keySet().iterator();
while (iter.hasNext()) { Float stopTime = new Float(t2);
Float this_time = (Float)iter.next(); if (!times.containsKey(stopTime))
String these_lines = (String)times.get(this_time); times.put(stopTime, lineID+",");
else {
StringTokenizer sTok = new StringTokenizer(these_lines,","); String val = (String)times.get(stopTime);
while (sTok.hasMoreTokens()) { val += lineID+",";
String lineID = sTok.nextToken(); times.put(stopTime, val);
if (line_list.contains(lineID)) }
line_list.remove(lineID); }
else catch (NumberFormatException nfe) {
line_list.add(lineID); }
}
}
StringBuffer sb = new StringBuffer();
Iterator line_list_iter = line_list.iterator(); public void organizeLines() {
while (line_list_iter.hasNext()) { List line_list = new ArrayList();
String lineID = (String)line_list_iter.next();
sb.append(lineID); Iterator iter = times.keySet().iterator();
sb.append(','); while (iter.hasNext()) {
} Float this_time = (Float)iter.next();
String these_lines = (String)times.get(this_time);
times.put(this_time, sb.toString());
} StringTokenizer sTok = new StringTokenizer(these_lines,",");
} while (sTok.hasMoreTokens()) {
String lineID = sTok.nextToken();
public String getQTTextForLines() { if (line_list.contains(lineID))
StringBuffer sb = new StringBuffer(); line_list.remove(lineID);
else
Iterator iter = times.keySet().iterator(); line_list.add(lineID);
while (iter.hasNext()) { }
Float this_time = (Float)iter.next();
sb.append(getQTTimeTag(String.valueOf(this_time))); StringBuffer sb = new StringBuffer();
String these_lines = (String)times.get(this_time); Iterator line_list_iter = line_list.iterator();
while (line_list_iter.hasNext()) {
StringTokenizer sTok = new StringTokenizer(these_lines,","); String lineID = (String)line_list_iter.next();
while (sTok.hasMoreTokens()) { sb.append(lineID);
String lineID = sTok.nextToken(); sb.append(',');
String wylie = (String)lines.get(lineID); }
sb.append(getQTText(wylie));
sb.append('\n'); times.put(this_time, sb.toString());
} }
} }
return sb.toString(); public String getQTTextForLines() {
} StringBuffer sb = new StringBuffer();
public static String getQTHeader() { Iterator iter = times.keySet().iterator();
return "{QTtext}{plain}{anti-alias:off}{size:28}{justify:left}{timeScale:1000}{width:320}{height:120}{timeStamps:absolute}{language:0}{textEncoding:0}\n"; while (iter.hasNext()) {
} Float this_time = (Float)iter.next();
sb.append(getQTTimeTag(String.valueOf(this_time)));
public static String getQTTimeTag(String t) { String these_lines = (String)times.get(this_time);
StringBuffer sb = new StringBuffer();
sb.append('['); StringTokenizer sTok = new StringTokenizer(these_lines,",");
sb.append(t); while (sTok.hasMoreTokens()) {
sb.append(']'); String lineID = sTok.nextToken();
return sb.toString(); String wylie = (String)lines.get(lineID);
} sb.append(getQTText(wylie));
sb.append('\n');
public static String getQTText(String wylie) { }
try { }
return getQTText(TibetanDocument.getTibetanMachineWeb(wylie));
} return sb.toString();
catch (InvalidWylieException ive) { }
return null;
} public static String getQTHeader() {
} return "{QTtext}{plain}{anti-alias:off}{size:28}{justify:left}{timeScale:1000}{width:320}{height:120}{timeStamps:absolute}{language:0}{textEncoding:0}\n";
}
public static String getQTText(TibetanDocument.DuffData[] duffData) {
StringBuffer qtBuffer = new StringBuffer(); public static String getQTTimeTag(String t) {
qtBuffer.append("{size:" + tibFontSize + "}"); StringBuffer sb = new StringBuffer();
sb.append('[');
for (int i=0; i<duffData.length; i++) { sb.append(t);
qtBuffer.append("{font:" + TibetanMachineWeb.tmwFontNames[duffData[i].font] + "}"); sb.append(']');
qtBuffer.append(duffData[i].text); return sb.toString();
} }
return qtBuffer.toString(); public static String getQTText(String wylie) {
} try {
} return getQTText(TibetanDocument.getTibetanMachineWeb(wylie));
}
/* catch (InvalidWylieException ive) {
public void addLine(NodeList nodes) { return null;
}
}
Element line = (Element)nodes.item(0);
Node wylie_node = line.getFirstChild(); public static String getQTText(TibetanDocument.DuffData[] duffData) {
// NodeList wylie_nodes = line.getElementsByTagName("wylie"); StringBuffer qtBuffer = new StringBuffer();
qtBuffer.append("{size:" + tibFontSize + "}");
// Node wylie_node = wylie_nodes.item(0);
Node wylie_text = wylie_node.getFirstChild(); for (int i=0; i<duffData.length; i++) {
System.out.println(wylie_text.getNodeName()); qtBuffer.append("{font:" + TibetanMachineWeb.tmwFontNames[duffData[i].font] + "}");
// String wylie = wylie_text.getNodeValue(); qtBuffer.append(duffData[i].text);
id++; }
String lineID = String.valueOf(id);
lines.put(lineID, wylie); return qtBuffer.toString();
}
NodeList audio_nodes = line.getElementsByTagName("AUDIO"); }
Element audio_element = (Element)audio_nodes.item(0);
try { /*
Integer startTime = Integer.valueOf(audio_element.getAttribute("begin")); public void addLine(NodeList nodes) {
if (!times.containsKey(startTime))
times.put(startTime, lineID+",");
else { Element line = (Element)nodes.item(0);
String val = (String)times.get(startTime); Node wylie_node = line.getFirstChild();
val += lineID+","; // NodeList wylie_nodes = line.getElementsByTagName("wylie");
times.put(startTime, val);
} // Node wylie_node = wylie_nodes.item(0);
Node wylie_text = wylie_node.getFirstChild();
Integer stopTime = Integer.valueOf(audio_element.getAttribute("end")); System.out.println(wylie_text.getNodeName());
if (!times.containsKey(stopTime)) // String wylie = wylie_text.getNodeValue();
times.put(stopTime, lineID+","); id++;
else { String lineID = String.valueOf(id);
String val = (String)times.get(stopTime); lines.put(lineID, wylie);
val += lineID+",";
times.put(stopTime, val); NodeList audio_nodes = line.getElementsByTagName("AUDIO");
} Element audio_element = (Element)audio_nodes.item(0);
} try {
catch (NumberFormatException nfe) { Integer startTime = Integer.valueOf(audio_element.getAttribute("begin"));
} if (!times.containsKey(startTime))
} times.put(startTime, lineID+",");
*/ else {
String val = (String)times.get(startTime);
val += lineID+",";
times.put(startTime, val);
}
Integer stopTime = Integer.valueOf(audio_element.getAttribute("end"));
if (!times.containsKey(stopTime))
times.put(stopTime, lineID+",");
else {
String val = (String)times.get(stopTime);
val += lineID+",";
times.put(stopTime, val);
}
}
catch (NumberFormatException nfe) {
}
}
*/