Merge changes from 1.0 final + more config ui work

git-svn-id: svn://svn.code.sf.net/p/writer2latex/code/trunk@34 f0f2a975-2e09-46c8-9428-3b39399b9f3c
This commit is contained in:
henrikjust 2009-09-21 06:12:18 +00:00
parent e8bba32302
commit a0384669cc
46 changed files with 1671 additions and 90 deletions

View file

@ -16,11 +16,11 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
* Copyright: 2002-2008 by Henrik Just
* Copyright: 2002-2009 by Henrik Just
*
* All Rights Reserved.
*
* Version 1.0 (2008-11-23)
* Version 1.2 (2009-09-20)
*
*/
@ -31,6 +31,8 @@ import java.io.InputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.lang.IllegalArgumentException;
import java.util.Map;
import java.util.Set;
/** This is an interface for configuration of a {@link Converter}.
* A configuration always supports simple name/value options.
@ -94,6 +96,28 @@ public interface Config {
* not exist or the given name is null
*/
public String getOption(String sName);
/** Set a complex option
*
* @param sGroup the group to which this option belongs
* @param sName the name of this option
* @param attributes the attributes defining the values of this option
*/
public void setComplexOption(String sGroup, String sName, Map<String,String> attributes);
/** Get a complex option
*
* @param sGroup the group to which this option belongs
* @param sName the name of this option
* @return the attributes defining the values of this option
*/
public Map<String,String> getComplexOption(String sGroup, String sName);
/** Get the collection of complex options in a specific groups
*
* @param sGroup the name of the group of options
* @return the names of the currently defined options in this group
*/
public Set<String> getComplexOptions(String sGroup);
}

View file

@ -20,7 +20,7 @@
*
* All Rights Reserved.
*
* Version 1.2 (2009-08-23)
* Version 1.2 (2009-09-17)
*
*/
@ -33,7 +33,7 @@ public class ConverterFactory {
// Version information
private static final String VERSION = "1.1.1";
private static final String DATE = "2008-09-07";
private static final String DATE = "2008-09-17";
/** Return version information
* @return the Writer2LaTeX version in the form

View file

@ -20,7 +20,7 @@
*
* All Rights Reserved.
*
* Version 1.2 (2009-05-31)
* Version 1.2 (2009-09-20)
*
*/
@ -28,7 +28,10 @@ package writer2latex.latex;
import java.util.LinkedList;
import java.util.Hashtable;
import java.util.HashMap;
import java.util.Enumeration;
import java.util.Map;
import java.util.Set;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
@ -40,6 +43,7 @@ import writer2latex.base.Option;
import writer2latex.latex.util.HeadingMap;
import writer2latex.latex.i18n.ClassicI18n;
import writer2latex.latex.i18n.ReplacementTrie;
import writer2latex.latex.i18n.ReplacementTrieNode;
import writer2latex.latex.util.StyleMap;
import writer2latex.util.Misc;
@ -69,6 +73,8 @@ public class LaTeXConfig extends writer2latex.base.ConfigBase {
public static final int CONVERT_ALL = 4;
// Page formatting
public static final int CONVERT_HEADER_FOOTER = 5;
public static final int CONVERT_GEOMETRY = 6;
// Handling of other formatting
public static final int IGNORE = 0;
public static final int ACCEPT = 1;
@ -224,6 +230,7 @@ public class LaTeXConfig extends writer2latex.base.ConfigBase {
super.setString(sValue);
if ("convert_all".equals(sValue)) nValue = CONVERT_ALL;
else if ("convert_header_footer".equals(sValue)) nValue = CONVERT_HEADER_FOOTER;
else if ("convert_geometry".equals(sValue)) nValue = CONVERT_GEOMETRY;
else if ("ignore_all".equals(sValue)) nValue = IGNORE_ALL;
}
};
@ -295,6 +302,36 @@ public class LaTeXConfig extends writer2latex.base.ConfigBase {
//stringReplace.put("\u00AB\u00A0","\u00AB ",I18n.readFontencs("any"));
//stringReplace.put("\u00A0\u00BB"," \u00BB",I18n.readFontencs("any"));
}
public void setComplexOption(String sGroup, String sName, Map<String,String> attributes) {
if ("string-replace".equals(sGroup)) {
String sLaTeXCode = attributes.get("latex-code");
String sFontencs = attributes.get("fontencs");
if (sLaTeXCode!=null) {
int nFontencs = ClassicI18n.readFontencs(sFontencs!=null && sFontencs.length()>0 ? sFontencs : "any");
stringReplace.put(sName,sLaTeXCode,nFontencs);
}
}
}
public Map<String,String> getComplexOption(String sGroup, String sName) {
if ("string-replace".equals(sGroup)) {
ReplacementTrieNode node = stringReplace.get(sName);
if (node!=null) {
HashMap<String,String> attributes = new HashMap<String,String>();
attributes.put("latex-code", node.getLaTeXCode());
attributes.put("fontencs", "(todo)");
}
}
return null;
}
public Set<String> getComplexOptions(String sGroup) {
if ("string-replace".equals(sGroup)) {
return stringReplace.getInputStrings();
}
return new java.util.HashSet<String>();
}
protected void readInner(Element elm) {
if (elm.getTagName().equals("style-map")) {
@ -400,24 +437,21 @@ public class LaTeXConfig extends writer2latex.base.ConfigBase {
hlmNode.setAttribute("level",Integer.toString(headingMap.getLevel(i)));
hmNode.appendChild(hlmNode);
}
// TODO: Export string replacements
//String[] sInputStrings = stringReplace.getInputStrings();
/*
int nSize = sInputStrings.size();
for (int i=0; i<nSize; i++) {
String sInput = sInputStrings[i];
Set<String> inputStrings = stringReplace.getInputStrings();
for (String sInput : inputStrings) {
System.out.println("Writing input "+sInput);
ReplacementTrieNode node = stringReplace.get(sInput);
Element srNode = dom.createElement("string-replace");
srNode.setAttribute("input",sInput);
srNode.setAttribute("latex-code",node.getLaTeXCode());
srNode.setAttribute("fontenc",I18n.writeFontencs(node.getFontencs()));
hmNode.appendChild(srNode);
srNode.setAttribute("fontenc","(todo)");
//srNode.setAttribute("fontenc",ClassicI18n.writeFontencs(node.getFontencs()));
dom.getDocumentElement().appendChild(srNode);
}
*/
writeContent(dom,customPreamble,"custom-preamble");
}
private void writeStyleMap(Document dom, StyleMap sm, String sFamily) {

View file

@ -16,11 +16,11 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
* Copyright: 2002-2008 by Henrik Just
* Copyright: 2002-2009 by Henrik Just
*
* All Rights Reserved.
*
* Version 1.0 (2008-11-22)
* Version 1.2 (2009-09-20)
*
*/
@ -171,6 +171,9 @@ public final class MathmlConverter extends ConverterHelper {
else if (XMLString.TEXT_TAB_STOP.equals(sName)) { // old
// Tab stops are allowed
}
else if (XMLString.TEXT_SOFT_PAGE_BREAK.equals(sName)) { // since ODF 1.1
// Soft page breaks are allowed
}
else {
// Other elements -> not a display
return false;

View file

@ -16,11 +16,11 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
* Copyright: 2002-2008 by Henrik Just
* Copyright: 2002-2009 by Henrik Just
*
* All Rights Reserved.
*
* Version 1.0 (2008-11-23)
* Version 1.2 (2009-09-17)
*
*/
@ -130,7 +130,7 @@ public class PageStyleConverter extends StyleConverter {
* @param ba the <code>BeforeAfter</code> to add code to.
*/
private void applyMasterPage(String sName, BeforeAfter ba) {
if (config.pageFormatting()==LaTeXConfig.IGNORE_ALL) return;
if (config.pageFormatting()==LaTeXConfig.IGNORE_ALL || config.pageFormatting()==LaTeXConfig.CONVERT_GEOMETRY) return;
MasterPage style = ofr.getMasterPage(sName);
if (style==null) { return; }
String sNextName = style.getProperty(XMLString.STYLE_NEXT_STYLE_NAME);
@ -150,7 +150,7 @@ public class PageStyleConverter extends StyleConverter {
* Process header or footer contents
*/
private void convertMasterPages(LaTeXDocumentPortion ldp) {
if (config.pageFormatting()==LaTeXConfig.IGNORE_ALL) { return; }
if (config.pageFormatting()==LaTeXConfig.IGNORE_ALL || config.pageFormatting()==LaTeXConfig.CONVERT_GEOMETRY) { return; }
Context context = new Context();
context.resetFormattingFromStyle(ofr.getDefaultParStyle());
@ -357,7 +357,7 @@ public class PageStyleConverter extends StyleConverter {
// TODO: Reenable several geometries per document??
private void convertPageMasterGeometry(LaTeXDocumentPortion pack, LaTeXDocumentPortion ldp) {
if (config.pageFormatting()!=LaTeXConfig.CONVERT_ALL) { return; }
if (config.pageFormatting()!=LaTeXConfig.CONVERT_ALL && config.pageFormatting()!=LaTeXConfig.CONVERT_GEOMETRY) { return; }
if (mainPageLayout==null) { return; }
// Set global document options

View file

@ -313,6 +313,10 @@ public class ClassicI18n extends I18n {
pack.append("\\usepackage[")
.append(babelopt.toString())
.append("]{babel}").nl();
// For Polish we must undefine \lll which is later defined by ams
if (languages.contains("pl")) {
pack.append("\\let\\lll\\undefined").nl();
}
}
// usepackage tipa

View file

@ -16,16 +16,19 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
* Copyright: 2002-2006 by Henrik Just
* Copyright: 2002-2009 by Henrik Just
*
* All Rights Reserved.
*
* Version 0.5 (2006-11-02)
* Version 1.2 (2009-09-20)
*
*/
package writer2latex.latex.i18n;
import java.util.HashSet;
import java.util.Set;
/** This class contains a trie of string -> LaTeX code replacements
*/
public class ReplacementTrie extends ReplacementTrieNode {
@ -48,8 +51,10 @@ public class ReplacementTrie extends ReplacementTrieNode {
else { super.put(sInput,sLaTeXCode,nFontencs); }
}
public String[] getInputStrings() {
return null; //TODO
public Set<String> getInputStrings() {
HashSet<String> strings = new HashSet<String>();
collectStrings(strings,"");
return strings;
}

View file

@ -16,16 +16,18 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
* Copyright: 2002-2006 by Henrik Just
* Copyright: 2002-2009 by Henrik Just
*
* All Rights Reserved.
*
* Version 0.5 (2006-11-02)
* Version 1.2 (2009-09-20)
*
*/
package writer2latex.latex.i18n;
import java.util.Set;
/** This class contains a node in a trie of string -> LaTeX code replacements
*/
public class ReplacementTrieNode {
@ -114,6 +116,18 @@ public class ReplacementTrieNode {
child.setFontencs(nFontencs);
}
}
protected void collectStrings(Set<String> strings, String sPrefix) {
ReplacementTrieNode child = this.getFirstChild();
while (child!=null) {
if (child.getLaTeXCode()!=null) {
strings.add(sPrefix+child.getLetter());
System.out.println("Found "+sPrefix+child.getLetter());
}
child.collectStrings(strings, sPrefix+child.getLetter());
child = child.getNextSibling();
}
}
public String toString() {
String s = Character.toString(cLetter);

View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- This is a datafile used by Writer2LaTeX
Version 1.0 (2008-12-03)
Version 1.0 (2009-09-07)
The definitions for greek characters are contributed by interzone, info@interzone.gr
and extended by Johannis Likos. Additional bugfixes by Alexej Kryukov
@ -1273,8 +1273,8 @@ PART I: Common symbols, ascii only
<symbol char="227D" math="{\succcurlyeq}"/>
<symbol char="227E" math="{\precsim}"/>
<symbol char="227F" math="{\succsim}"/>
<symbol char="2280" math="{\nsucc}"/>
<symbol char="2281" math="{\nprec}"/>
<symbol char="2280" math="{\nprec}"/>
<symbol char="2281" math="{\nsucc}"/>
<symbol char="2282" math="{\subset}"/>
<symbol char="2283" math="{\supset}"/>
<symbol char="2284" math="{\not\subset}"/>

View file

@ -16,13 +16,13 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
* Copyright: 2002-2008 by Henrik Just
* Copyright: 2002-2009 by Henrik Just
*
* Version 1.0 (2009-09-14)
*
* All Rights Reserved.
*/
// Version 1.0 (2008-11-22)
package writer2latex.office;
import java.util.LinkedList;
@ -52,6 +52,9 @@ public class TableReader {
private String sTableWidth;
private String sRelTableWidth;
private Vector<TableRange> printRanges;
private int nRowCount;
private int nEmptyRowCount;
/**
* <p> The constructor reads a table from a table:table or table:sub-table
@ -63,6 +66,10 @@ public class TableReader {
//this.ofr = ofr;
this.tableNode = tableNode;
if (!tableNode.hasChildNodes()) { return; } // empty table!
// Count the actual number of rows (trailing repeated rows are ignored)
countTableRows(tableNode);
NodeList nl = tableNode.getChildNodes();
int nLen = nl.getLength();
for (int i = 0; i < nLen; i++) {
@ -224,7 +231,7 @@ public class TableReader {
private void readTableRow(Node node, boolean bHeader, boolean bDisplay) {
int nRepeat = Misc.getPosInteger(Misc.getAttribute(node,
XMLString.TABLE_NUMBER_ROWS_REPEATED),1);
while (nRepeat-->0) {
while (nRepeat-->0 && rows.size()<nRowCount) {
rows.add(new TableLine(node,bHeader,bDisplay));
// Read the cells in the row
@ -303,6 +310,98 @@ public class TableReader {
private void readTableHeaderRows(Node node, boolean bHeader, boolean bDisplay) {
readTableRows(node,true,bDisplay);
}
private void countTableRows(Element table) {
nRowCount = 0;
nEmptyRowCount = 0;
Node child = table.getFirstChild();
while (child!=null) {
if (child.getNodeType() == Node.ELEMENT_NODE) {
String sName = child.getNodeName();
if (sName.equals(XMLString.TABLE_TABLE_ROW)) {
countTableRow(child);
}
else if (sName.equals(XMLString.TABLE_TABLE_ROWS)) {
countTableRows(child);
}
else if (sName.equals(XMLString.TABLE_TABLE_ROW_GROUP)) {
countTableRowGroup(child);
}
else if (sName.equals(XMLString.TABLE_TABLE_HEADER_ROWS)) {
countTableHeaderRows(child);
}
}
child = child.getNextSibling();
}
// We will accept only one trailing empty row
if (nEmptyRowCount>1) { nRowCount-=nEmptyRowCount-1; }
}
private void countTableRow(Node node) {
int nRepeat = Misc.getPosInteger(Misc.getAttribute(node,
XMLString.TABLE_NUMBER_ROWS_REPEATED),1);
nRowCount += nRepeat;
if (isEmptyRow(node)) {
nEmptyRowCount+=nRepeat;
}
else {
nEmptyRowCount = 0;
}
}
private boolean isEmptyRow(Node node) {
Node child = node.getFirstChild();
while (child!=null) {
if (child.getNodeType() == Node.ELEMENT_NODE) {
Element cell = (Element) child;
String sName = cell.getTagName();
if (sName.equals(XMLString.TABLE_TABLE_CELL)) {
if (cell.hasChildNodes()) { return false; }
}
}
child = child.getNextSibling();
}
return true;
}
private void countTableRows(Node node) {
Node child = node.getFirstChild();
while (child!=null) {
if (child.getNodeType() == Node.ELEMENT_NODE) {
String sName = child.getNodeName();
if (sName.equals(XMLString.TABLE_TABLE_ROW)) {
countTableRow(child);
}
else if (sName.equals(XMLString.TABLE_TABLE_ROW_GROUP)) {
countTableRowGroup(child);
}
}
child = child.getNextSibling();
}
}
private void countTableRowGroup(Node node) {
Node child = node.getFirstChild();
while (child!=null) {
if (child.getNodeType() == Node.ELEMENT_NODE) {
String sName = child.getNodeName();
if (sName.equals(XMLString.TABLE_TABLE_HEADER_ROWS)) {
countTableHeaderRows(child);
}
else if (sName.equals(XMLString.TABLE_TABLE_ROW)) {
countTableRow(child);
}
else if (sName.equals(XMLString.TABLE_TABLE_ROW_GROUP)) {
countTableRowGroup(child);
}
}
child = child.getNextSibling();
}
}
private void countTableHeaderRows(Node node) {
countTableRows(node);
}
public String getTableName() {
return tableNode.getAttribute(XMLString.TABLE_NAME);

View file

@ -20,7 +20,7 @@
*
* All Rights Reserved.
*
* Version 1.2 (2009-09-07)
* Version 1.2 (2009-09-20)
*
*/
@ -321,6 +321,8 @@ public class XMLString {
public static final String TEXT_FOOTNOTE_REF="text:footnote-ref";
public static final String TEXT_ENDNOTE_REF="text:endnote-ref";
public static final String TEXT_NOTE_REF="text:note-ref"; // oasis
public static final String TEXT_SOFT_PAGE_BREAK="text:soft-page-break"; // ODF 1.1
// text namespace - attributes
public static final String TEXT_USE_OUTLINE_LEVEL="text:use-outline-level";
public static final String TEXT_USE_INDEX_SOURCE_STYLES="text:use-index-source-styles";

View file

@ -20,7 +20,7 @@
*
* All Rights Reserved.
*
* Version 1.2 (2009-05-29)
* Version 1.2 (2009-09-15)
*
*/
@ -109,6 +109,48 @@ public class L10n {
case DOCUMENT: return "Documento";
}
}
if (sLocale.startsWith("pt")) { // (brazilian) portuguese
switch (nString) {
case UP: return "Acima";
case FIRST : return "Primeiro";
case PREVIOUS : return "Anterior";
case NEXT : return "Pr\u00f3ximo";
case LAST : return "\u00daltimo";
case CONTENTS : return "Conte\u00fado";
case INDEX : return "\u00cdndice";
case HOME : return "Home";
case DIRECTORY: return "Diret\u00f3rio";
case DOCUMENT: return "Documento";
}
}
if (sLocale.startsWith("cs")) { // czech
switch (nString) {
case UP: return "Nahoru";
case FIRST : return "Prvn\u00ed";
case PREVIOUS : return "P\u0159edchoz\u00ed";
case NEXT : return "Dal\u0161\u00ed";
case LAST : return "Posledn\u00ed";
case CONTENTS : return "Obsah";
case INDEX : return "Rejst\u0159\u00edk";
case HOME : return "Dom\u016f";
case DIRECTORY: return "Adres\u00e1\u0159 (slo\u017eka)";
case DOCUMENT: return "Dokument";
}
}
if (sLocale.startsWith("nl")) { // dutch
switch (nString) {
case UP: return "Omhoog";
case FIRST : return "Eerste";
case PREVIOUS : return "Vorige";
case NEXT : return "Volgende";
case LAST : return "Laatste";
case CONTENTS : return "Inhoud";
case INDEX : return "Index";
case HOME : return "Hoofdpagina";
case DIRECTORY: return "Directory";
case DOCUMENT: return "Document";
}
}
if (sLocale.startsWith("da")) { // danish
switch (nString) {
case UP: return "Op";

View file

@ -20,13 +20,15 @@
*
* All Rights Reserved.
*
* Version 1.2 (2009-09-05)
* Version 1.2 (2009-09-20)
*
*/
package writer2latex.xhtml;
import java.util.Enumeration;
import java.util.Map;
import java.util.Set;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@ -152,8 +154,23 @@ public class XhtmlConfig extends writer2latex.base.ConfigBase {
options[DIRECTORY_ICON] = new Option("directory_icon","");
options[DOCUMENT_ICON] = new Option("document_icon","");
}
// Dummy implementation of complex options
public void setComplexOption(String sGroup, String sName, Map<String,String> attributes) {
// do nothing
}
public Map<String,String> getComplexOption(String sGroup, String sName) {
// no options are defined, return null in all cases
return null;
}
protected void readInner(Element elm) {
public Set<String> getComplexOptions(String sGroup) {
// Always an empty set
return new java.util.HashSet<String>();
}
protected void readInner(Element elm) {
if (elm.getTagName().equals("xhtml-style-map")) {
String sName = elm.getAttribute("name");
String sFamily = elm.getAttribute("family");