main code
This commit is contained in:
parent
4123c61fd6
commit
966b49dc9c
8 changed files with 1001 additions and 12 deletions
|
@ -305,6 +305,7 @@ public class OfficeReader {
|
|||
private OfficeStyleFamily list = new OfficeStyleFamily(ListStyle.class);
|
||||
private OfficeStyleFamily pageLayout = new OfficeStyleFamily(PageLayout.class);
|
||||
private OfficeStyleFamily masterPage = new OfficeStyleFamily(MasterPage.class);
|
||||
private Map<String,MasterPage> masterPages = new HashMap<String, MasterPage>();
|
||||
|
||||
// Document-wide styles
|
||||
private ListStyle outline = new ListStyle();
|
||||
|
@ -500,7 +501,12 @@ public class OfficeReader {
|
|||
public MasterPage getMasterPage(String sName) {
|
||||
return (MasterPage) masterPage.getStyle(sName);
|
||||
}
|
||||
|
||||
public Map<String,MasterPage> getAllMasterPages() {
|
||||
return (masterPages);
|
||||
}
|
||||
public MasterPage getFullMasterPage(String sName) {
|
||||
return masterPages.get(sName);
|
||||
}
|
||||
public ListStyle getOutlineStyle() { return outline; }
|
||||
|
||||
public PropertySet getFootnotesConfiguration() { return footnotes; }
|
||||
|
@ -904,6 +910,7 @@ public class OfficeReader {
|
|||
}
|
||||
else if (child.getNodeName().equals(XMLString.STYLE_MASTER_PAGE)) {
|
||||
masterPage.loadStyleFromDOM(child,bAutomatic);
|
||||
masterPages.put(Misc.getAttribute(child,XMLString.STYLE_NAME), (MasterPage) masterPage.getStyle(Misc.getAttribute(child,XMLString.STYLE_NAME)) );
|
||||
if (firstMasterPage==null) {
|
||||
firstMasterPage = (MasterPage) masterPage.getStyle(Misc.getAttribute(child,XMLString.STYLE_NAME));
|
||||
}
|
||||
|
|
|
@ -311,6 +311,7 @@ public class XMLString {
|
|||
public static final String TEXT_LINE_BREAK="text:line-break";
|
||||
public static final String TEXT_PAGE_NUMBER="text:page-number";
|
||||
public static final String TEXT_PAGE_COUNT="text:page-count";
|
||||
public static final String TEXT_PAGE_ADJUST="text:page-adjust";
|
||||
public static final String TEXT_CHAPTER="text:chapter";
|
||||
public static final String TEXT_SEQUENCE="text:sequence";
|
||||
public static final String TEXT_SEQUENCE_REF="text:sequence-ref";
|
||||
|
|
|
@ -630,7 +630,15 @@ public class Converter extends ConverterBase {
|
|||
public Element getPanelNode() {
|
||||
return htmlDoc.getPanelNode();
|
||||
}
|
||||
public String getTitle(){
|
||||
String title = metaData.getTitle();
|
||||
if (title==null) {
|
||||
// use filename as fallback
|
||||
title = htmlDoc.getFileName();
|
||||
}
|
||||
return title;
|
||||
|
||||
}
|
||||
// Prepare next output file
|
||||
public Element nextOutFile() {
|
||||
htmlDoc = new XhtmlDocument(getOutFileName(++nOutFileIndex,false),nType);
|
||||
|
|
148
source/java/writer2latex/xhtml/GreenstoneTags.java
Normal file
148
source/java/writer2latex/xhtml/GreenstoneTags.java
Normal file
|
@ -0,0 +1,148 @@
|
|||
package writer2latex.xhtml;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
import javax.swing.text.Element;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
import writer2latex.office.XMLString;
|
||||
import writer2latex.util.Misc;
|
||||
|
||||
|
||||
//LinkedList<String> stringList = new LinkedList<String>();
|
||||
public class GreenstoneTags {
|
||||
|
||||
private static LinkedList<Integer> headerStack = new LinkedList<Integer>();
|
||||
private static boolean pageSection = false;
|
||||
|
||||
protected static boolean processHeading(Node currentNode, Node hnode, int pageNum) {
|
||||
|
||||
String sLevel = Misc.getAttribute(currentNode, XMLString.TEXT_OUTLINE_LEVEL);
|
||||
//If this heading contain outline-level
|
||||
if (sLevel != null && !sLevel.isEmpty()) {
|
||||
int nLevel = Integer.parseInt(sLevel);
|
||||
// Close page section if opened
|
||||
if (pageSection) {
|
||||
closeSection(hnode);
|
||||
pageSection = false;
|
||||
}
|
||||
|
||||
//If stack not empty
|
||||
//Close all sections with level less than current
|
||||
if (!headerStack.isEmpty()) {
|
||||
while (nLevel <= headerStack.peek()){
|
||||
closeSection(hnode);
|
||||
headerStack.poll();
|
||||
if (headerStack.isEmpty()){ break;}
|
||||
|
||||
}
|
||||
}
|
||||
//System.out.println(sLevel +">" +headerStack.peek() );
|
||||
Node nextNode = currentNode.getNextSibling();
|
||||
//Useless to open section if we are at end of the document
|
||||
if (nextNode != null){
|
||||
//Open Heading section
|
||||
String title = getTitle(currentNode);
|
||||
|
||||
openSection(hnode, title);
|
||||
headerStack.offerFirst(Integer.parseInt(sLevel));
|
||||
//System.out.println("Current " + sLevel + " stack " + headerStack.peek() + "SUM" + headerStack.size());
|
||||
|
||||
if (!(nextNode.getNodeType() == Node.ELEMENT_NODE
|
||||
&& nextNode.getNodeName().equals(XMLString.TEXT_H)
|
||||
&& Misc.getAttribute(nextNode, XMLString.TEXT_OUTLINE_LEVEL) != null
|
||||
&& !Misc.getAttribute(nextNode, XMLString.TEXT_OUTLINE_LEVEL).isEmpty())) {
|
||||
openSection(hnode, pageNum);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
private static String getTitle(Node currentNode) {
|
||||
Node content = currentNode.cloneNode(true);
|
||||
NodeList contentNodes = content.getChildNodes();
|
||||
String title = null;
|
||||
|
||||
int i = 0;
|
||||
while (i < contentNodes.getLength()) {
|
||||
Node child = contentNodes.item(i);
|
||||
if (child.getNodeType() == Node.ELEMENT_NODE){
|
||||
if (child.getNodeName().equals(XMLString.TEXT_TAB) ||
|
||||
child.getNodeName().equals(XMLString.TEXT_LINE_BREAK) ){
|
||||
Document doc = child.getOwnerDocument();
|
||||
Node testSpace = doc.createTextNode(" ");
|
||||
content.insertBefore(testSpace, child);
|
||||
content.removeChild(child);
|
||||
}
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
title = content.getTextContent();
|
||||
|
||||
return title;
|
||||
}
|
||||
static void processPageBreak(Node currentNode, Node hnode, Integer pageNum){
|
||||
|
||||
|
||||
if ( !( currentNode.getNodeType() == Node.ELEMENT_NODE
|
||||
&& currentNode.getNodeName().equals(XMLString.TEXT_H)
|
||||
&& Misc.getAttribute(currentNode, XMLString.TEXT_OUTLINE_LEVEL) != null
|
||||
&& !Misc.getAttribute(currentNode, XMLString.TEXT_OUTLINE_LEVEL).isEmpty()
|
||||
)
|
||||
&& !headerStack.isEmpty()
|
||||
) {
|
||||
if (pageSection) {
|
||||
closeSection(hnode);
|
||||
pageSection = false;
|
||||
|
||||
}
|
||||
if (pageNum != null) {
|
||||
openSection(hnode, pageNum);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
//Method to open main document tag
|
||||
static void StartDocument(Node hnode, String title){
|
||||
openSection(hnode, title);
|
||||
}
|
||||
//Method to close open tags at the end of the document
|
||||
static void endDocument(Node hnode){
|
||||
if (pageSection){
|
||||
closeSection(hnode);
|
||||
pageSection = false;
|
||||
}
|
||||
closeSection(hnode);
|
||||
}
|
||||
private static void openSection(Node hnode, Integer pageNum){
|
||||
Document doc = hnode.getOwnerDocument();
|
||||
String commentText = "<Section>\n<Description>\n<Metadata name=\"Title\">" + pageNum
|
||||
+ "</Metadata>\n<Metadata name=\"Page\">" + pageNum + "</Metadata>\n</Description>";
|
||||
Node openSection = doc.createComment(commentText);
|
||||
//Node openSection = doc.createTextNode(commentText);
|
||||
// insert open section comment before header node
|
||||
hnode.appendChild(openSection);
|
||||
pageSection = true;
|
||||
}
|
||||
private static void openSection(Node hnode, String title){
|
||||
Document doc = hnode.getOwnerDocument();
|
||||
String commentText = "<Section>\n<Description>\n<Metadata name=\"Title\">" + title
|
||||
+ "</Metadata>\n</Description>";
|
||||
Node openSection = doc.createComment(commentText);
|
||||
// insert open section comment before header node
|
||||
hnode.appendChild(openSection);
|
||||
}
|
||||
|
||||
private static void closeSection(Node hnode){
|
||||
Document doc = hnode.getOwnerDocument();
|
||||
String commentText = "</Section>";
|
||||
Node closeSection = doc.createComment(commentText);
|
||||
//insert open section comment before header node
|
||||
hnode.appendChild(closeSection);
|
||||
}
|
||||
}
|
607
source/java/writer2latex/xhtml/PageSplitter.java
Normal file
607
source/java/writer2latex/xhtml/PageSplitter.java
Normal file
|
@ -0,0 +1,607 @@
|
|||
package writer2latex.xhtml;
|
||||
|
||||
import javax.print.Doc;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
import writer2latex.office.OfficeReader;
|
||||
import writer2latex.office.StyleWithProperties;
|
||||
import writer2latex.office.XMLString;
|
||||
import writer2latex.util.Misc;
|
||||
|
||||
public class PageSplitter {
|
||||
static Node truncatedListItemNodeContent = null;
|
||||
|
||||
protected static Node splitSoftPageBreak(Node onode,OfficeReader ofr){
|
||||
//Find par node with soft page break inside and split it
|
||||
Document document = onode.getOwnerDocument();
|
||||
Element softPageBreak = document.createElement(XMLString.TEXT_SOFT_PAGE_BREAK);
|
||||
NodeList nodes = onode.getChildNodes();
|
||||
|
||||
int i = 0;
|
||||
//Loop through the content nodes and split paragraph nodes with soft page break
|
||||
while (i < nodes.getLength()){
|
||||
Node child = nodes.item(i);
|
||||
|
||||
//Necessary check if node is an Element
|
||||
if ((child.getNodeType() == Node.ELEMENT_NODE) && checkSoftPageBreak(child, false)){
|
||||
String nodeName = child.getNodeName();
|
||||
//DEBUG
|
||||
//System.out.println("----------CURRENT NODE IS-------" + nodeName);
|
||||
//Create Duplicate Node!
|
||||
Element childFirstPart = (Element) child.cloneNode(false);
|
||||
StyleWithProperties style = null;
|
||||
if ((nodeName.equals(XMLString.TEXT_P) || nodeName.equals(XMLString.TEXT_H))) {
|
||||
//If SPB not the first node
|
||||
if (handleParagraph(childFirstPart, child)){
|
||||
onode.insertBefore(childFirstPart, child);
|
||||
style = ofr.getTableStyle(Misc.getAttribute(child, XMLString.TEXT_STYLE_NAME));
|
||||
}
|
||||
} else if (nodeName.equals(XMLString.TABLE_TABLE)) {
|
||||
if (handleTableTable(childFirstPart, child)){
|
||||
onode.insertBefore(childFirstPart, child);
|
||||
style = ofr.getTableStyle(Misc.getAttribute(child, XMLString.TABLE_STYLE_NAME));
|
||||
|
||||
}
|
||||
} else if (nodeName.equals(XMLString.TEXT_LIST)) {
|
||||
if (handleList(childFirstPart, child)){
|
||||
onode.insertBefore(childFirstPart, child);
|
||||
style = ofr.getTableStyle(Misc.getAttribute(child, XMLString.TEXT_LIST_STYLE));
|
||||
}
|
||||
} else if (nodeName.equals(XMLString.TEXT_SECTION)) {
|
||||
if (handleSection(childFirstPart, child)){
|
||||
onode.insertBefore(childFirstPart, child);
|
||||
style = ofr.getTableStyle(Misc.getAttribute(child, XMLString.TEXT_SECTION));
|
||||
}
|
||||
} else if (nodeName.equals(XMLString.TEXT_TABLE_OF_CONTENT)){
|
||||
//HACK
|
||||
checkSoftPageBreak(childFirstPart, false);
|
||||
i++;
|
||||
continue;
|
||||
} else if (nodeName.equals(XMLString.TEXT_SOFT_PAGE_BREAK)){
|
||||
//HACK
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
//TODO: IF fo:break before in original table - don't create SPB
|
||||
|
||||
if (style == null || !"page".equals(style.getProperty(XMLString.FO_BREAK_BEFORE))){
|
||||
onode.insertBefore(softPageBreak.cloneNode(false), child);
|
||||
}
|
||||
//HACK!
|
||||
if (truncatedListItemNodeContent != null){
|
||||
NodeList itemNodeList= truncatedListItemNodeContent.getChildNodes();
|
||||
while (itemNodeList.getLength() > 0){
|
||||
onode.insertBefore(itemNodeList.item(0), child);
|
||||
}
|
||||
truncatedListItemNodeContent.getParentNode().removeChild(truncatedListItemNodeContent);
|
||||
truncatedListItemNodeContent = null;
|
||||
}
|
||||
if (!child.hasChildNodes()){
|
||||
onode.removeChild(child);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
return onode;
|
||||
}
|
||||
private static boolean handleList(Node listFirstPart, Node list){
|
||||
|
||||
NodeList listNodes = list.getChildNodes();
|
||||
int i = 0;
|
||||
boolean dataMoved = false;
|
||||
while (listNodes.getLength() > i) {
|
||||
Node listChild = listNodes.item(i);
|
||||
if(listChild.getNodeType() == Node.ELEMENT_NODE){
|
||||
String nodeName = listChild.getNodeName();
|
||||
if (nodeName.equals(XMLString.TEXT_LIST_HEADER)) {
|
||||
if(checkSoftPageBreak(listChild, true)){
|
||||
//Remove inner SPB
|
||||
//HACK :(
|
||||
break;
|
||||
}
|
||||
listFirstPart.appendChild(listChild.cloneNode(true));
|
||||
//Get next element
|
||||
i++;
|
||||
|
||||
|
||||
} else if (nodeName.equals(XMLString.TEXT_LIST_ITEM)) {
|
||||
if (checkSoftPageBreak(listChild, false)){
|
||||
Node listItemFirstPart = listChild.cloneNode(false);
|
||||
//remove SPB, move previous nodes to firstPart.
|
||||
if (handleListItem(listItemFirstPart,listChild)){
|
||||
dataMoved = true;
|
||||
//Add first part of list item to previous list item
|
||||
listFirstPart.appendChild(listItemFirstPart);
|
||||
//Get list parent node and move cutted node
|
||||
//After First Part and SPB but before this list;
|
||||
//TODO!!!!!!!!!!
|
||||
truncatedListItemNodeContent = listChild;
|
||||
listFirstPart.getParentNode();
|
||||
//If List item is empty - remove it
|
||||
if (!listChild.hasChildNodes()){
|
||||
list.removeChild(listChild);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
//Add text:continue-numbering="true"
|
||||
if (dataMoved){
|
||||
((Element) list).setAttribute(XMLString.TEXT_CONTINUE_NUMBERING, "true");
|
||||
}
|
||||
break;
|
||||
} else {
|
||||
// Not with SPB yet, move node, set dataMoved=true
|
||||
listFirstPart.appendChild(listChild);
|
||||
dataMoved = true;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
return dataMoved;
|
||||
}
|
||||
//If SPB before first item - return false, remove SPB
|
||||
//Otherwise add childNodes before SPB to firstPart, return true
|
||||
private static boolean handleListItem(Node listItemFirstPart, Node listItem){
|
||||
int i = 0;
|
||||
boolean dataMoved = false;
|
||||
NodeList listItemNodes = listItem.getChildNodes();
|
||||
while(listItemNodes.getLength() > i){
|
||||
Node listItemChild = listItemNodes.item(i);
|
||||
if(listItemChild.getNodeType() == Node.ELEMENT_NODE){
|
||||
//Node name
|
||||
String nodeName = listItemChild.getNodeName();
|
||||
if (checkSoftPageBreak(listItemChild, false)){
|
||||
Node listItemChildFirstPart = listItemChild.cloneNode(false);
|
||||
//Break if SPB
|
||||
if (nodeName.equals(XMLString.TEXT_SOFT_PAGE_BREAK)) {
|
||||
//Remove SPB.Return result
|
||||
listItem.removeChild(listItemChild);
|
||||
} else if (nodeName.equals(XMLString.TEXT_LIST)) {
|
||||
if (handleList(listItemChildFirstPart, listItemChild)){
|
||||
listItemFirstPart.appendChild(listItemChildFirstPart);
|
||||
dataMoved=true;
|
||||
}
|
||||
|
||||
} else if (nodeName.equals(XMLString.TEXT_H) || nodeName.equals(XMLString.TEXT_P)) {
|
||||
|
||||
if (handleParagraph(listItemChildFirstPart, listItemChild)){
|
||||
listItemFirstPart.appendChild(listItemChildFirstPart);
|
||||
dataMoved=true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
//Move to first part
|
||||
} else {
|
||||
|
||||
listItemFirstPart.appendChild(listItemChild);
|
||||
dataMoved = true;
|
||||
}
|
||||
} else {
|
||||
listItemFirstPart.appendChild(listItemChild);
|
||||
dataMoved = true;
|
||||
}
|
||||
//check internal nodes
|
||||
}
|
||||
return dataMoved;
|
||||
}
|
||||
//Needs finish
|
||||
private static boolean handleTableTable(Node tableFirstPart, Node table) {
|
||||
|
||||
/*
|
||||
* // TODO: 0.Test if soft-page-break not at start of table // - in that
|
||||
* case just remove it and insert before table // 1.Create new table //
|
||||
* 2.Copy to it table:table-column's and // table:table-header-rows //
|
||||
* 3.Move nodes before soft-page-break to new table //4. IF in one
|
||||
* table:row exist more one Algorithm IF SPB at start - just move it
|
||||
* higher IF SPB between rows - just copy table move row and put SPB
|
||||
* between tables IF SPB inside row, inside cell - copy table, copy
|
||||
* empty row, copy each empty cell and in each cell move every node up
|
||||
* to the first SPB
|
||||
*
|
||||
*
|
||||
*/
|
||||
NodeList tableChildNodes = table.getChildNodes();
|
||||
// Node counter
|
||||
int i = 0;
|
||||
boolean dataMoved = false;
|
||||
// Loop through the TABLE:TABLE child nodes
|
||||
while (tableChildNodes.getLength() > i) {
|
||||
Node tableChildNode = tableChildNodes.item(i);
|
||||
|
||||
if (tableChildNode.getNodeType() == Node.ELEMENT_NODE) {
|
||||
//Node name
|
||||
String tableChildNodeName = tableChildNode.getNodeName();
|
||||
//System.out.println("Table child node " + tableChildNodeName);
|
||||
if (checkSoftPageBreak(tableChildNode, false)){
|
||||
Node tableChildFirstPart = tableChildNode.cloneNode(false);
|
||||
if (tableChildNodeName.equals(XMLString.TEXT_SOFT_PAGE_BREAK)) {
|
||||
// remove inner soft page break node
|
||||
table.removeChild(tableChildNode);
|
||||
|
||||
} else if (tableChildNodeName.equals(XMLString.TABLE_TABLE_ROW_GROUP)) {
|
||||
if (handleTableRowGroup(tableChildFirstPart, tableChildNode)){
|
||||
dataMoved = true;
|
||||
tableFirstPart.appendChild(tableChildFirstPart);
|
||||
}
|
||||
} else if ( tableChildNodeName.equals(XMLString.TABLE_TABLE_ROWS)) {
|
||||
if (handleTableRows(tableChildFirstPart, tableChildNode)){
|
||||
dataMoved = true;
|
||||
tableFirstPart.appendChild(tableChildFirstPart);
|
||||
}
|
||||
} else if ( tableChildNodeName.equals(XMLString.TABLE_TABLE_ROW)) {
|
||||
if (handleTableRow(tableChildFirstPart, tableChildNode)){
|
||||
dataMoved = true;
|
||||
tableFirstPart.appendChild(tableChildFirstPart);
|
||||
}
|
||||
} else if (tableChildNodeName.equals(XMLString.TABLE_TABLE_COLUMN)
|
||||
|| tableChildNodeName.equals(XMLString.TABLE_TABLE_COLUMN_GROUP)
|
||||
|| tableChildNodeName.equals(XMLString.TABLE_TABLE_HEADER_ROWS)
|
||||
|| tableChildNodeName.equals(XMLString.TABLE_TABLE_HEADER_COLUMNS)) {
|
||||
//Remove Soft Page Break
|
||||
checkSoftPageBreak(tableChildNode, true);
|
||||
}
|
||||
break;
|
||||
|
||||
} else {
|
||||
//Before SPB
|
||||
//Description nodes
|
||||
if (tableChildNodeName.equals(XMLString.TABLE_TABLE_COLUMN)
|
||||
|| tableChildNodeName.equals(XMLString.TABLE_TABLE_COLUMN_GROUP)
|
||||
|| tableChildNodeName.equals(XMLString.TABLE_TABLE_HEADER_ROWS)
|
||||
|| tableChildNodeName.equals(XMLString.TABLE_TABLE_HEADER_COLUMNS)) {
|
||||
//Append to clone table
|
||||
tableFirstPart.appendChild(tableChildNode.cloneNode(true));
|
||||
//increment counter
|
||||
i++;
|
||||
} else {
|
||||
//Append to clone table
|
||||
tableFirstPart.appendChild(tableChildNode);
|
||||
dataMoved = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return dataMoved;
|
||||
}
|
||||
|
||||
private static boolean handleTableRowGroup(Node tableRowGroupFistPart, Node tableRowGroup) {
|
||||
boolean dataMoved = false;
|
||||
// Node counter
|
||||
int i = 0;
|
||||
NodeList tableRowGroupChildNodes = tableRowGroup.getChildNodes();
|
||||
while (tableRowGroupChildNodes.getLength() > i) {
|
||||
Node tableRowGroupChildNode = tableRowGroupChildNodes.item(0);
|
||||
if ((tableRowGroupChildNode.getNodeType() == Node.ELEMENT_NODE)) {
|
||||
|
||||
String nodeName = tableRowGroupChildNode.getNodeName();
|
||||
|
||||
if (checkSoftPageBreak(tableRowGroupChildNode, false)){
|
||||
Node tableRowGroupChildFirstPart = tableRowGroupChildNode.cloneNode(false);
|
||||
if (nodeName.equals(XMLString.TEXT_SOFT_PAGE_BREAK)){
|
||||
// remove inner soft page break node
|
||||
tableRowGroup.removeChild(tableRowGroupChildNode);
|
||||
|
||||
} else if (nodeName.equals(XMLString.TABLE_TABLE_HEADER_ROWS)){
|
||||
//Nothing IF table-header-rows found - it is description node,
|
||||
//Not needed to set dataMoved = true, not needed to append First part
|
||||
|
||||
} else if (nodeName.equals(XMLString.TABLE_TABLE_ROW)){
|
||||
if (handleTableRow(tableRowGroupChildFirstPart, tableRowGroupChildNode)){
|
||||
dataMoved = true;
|
||||
tableRowGroupFistPart.appendChild(tableRowGroupChildFirstPart);
|
||||
}
|
||||
} else if (nodeName.equals(XMLString.TABLE_TABLE_ROW_GROUP)){
|
||||
if (handleTableRowGroup(tableRowGroupChildFirstPart, tableRowGroupChildNode)){
|
||||
dataMoved = true;
|
||||
tableRowGroupFistPart.appendChild(tableRowGroupChildFirstPart);
|
||||
}
|
||||
} else if (nodeName.equals(XMLString.TABLE_TABLE_ROWS)){
|
||||
if (handleTableRows(tableRowGroupChildFirstPart, tableRowGroupChildNode)){
|
||||
dataMoved = true;
|
||||
tableRowGroupFistPart.appendChild(tableRowGroupChildFirstPart);
|
||||
}
|
||||
}
|
||||
break;
|
||||
} else {
|
||||
if (nodeName.equals(XMLString.TABLE_TABLE_HEADER_ROWS)){
|
||||
tableRowGroupFistPart.appendChild(tableRowGroupChildNode.cloneNode(true));
|
||||
//increment counter
|
||||
i++;
|
||||
|
||||
} else {
|
||||
tableRowGroupFistPart.appendChild(tableRowGroupChildNode);
|
||||
dataMoved = true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//Append text nodes
|
||||
tableRowGroupFistPart.appendChild(tableRowGroupChildNode);
|
||||
dataMoved = true;
|
||||
}
|
||||
|
||||
}
|
||||
return dataMoved;
|
||||
}
|
||||
private static boolean handleTableRows(Node tableRowsFistPart, Node tableRows) {
|
||||
boolean dataMoved = false;
|
||||
// Node counter
|
||||
int i = 0;
|
||||
NodeList tableRowsChildNodes = tableRows.getChildNodes();
|
||||
while (tableRowsChildNodes.getLength() > i) {
|
||||
Node tableRowsChildNode = tableRowsChildNodes.item(0);
|
||||
if ((tableRowsChildNode.getNodeType() == Node.ELEMENT_NODE)) {
|
||||
|
||||
String nodeName = tableRowsChildNode.getNodeName();
|
||||
|
||||
if (checkSoftPageBreak(tableRowsChildNode, false)){
|
||||
Node tableRowGroupChildFirstPart = tableRowsChildNode.cloneNode(false);
|
||||
if (nodeName.equals(XMLString.TEXT_SOFT_PAGE_BREAK)){
|
||||
// remove inner soft page break node
|
||||
tableRows.removeChild(tableRowsChildNode);
|
||||
|
||||
} else if (nodeName.equals(XMLString.TABLE_TABLE_ROW)){
|
||||
if (handleTableRow(tableRowGroupChildFirstPart, tableRowsChildNode)){
|
||||
dataMoved = true;
|
||||
tableRowsFistPart.appendChild(tableRowGroupChildFirstPart);
|
||||
}
|
||||
}
|
||||
break;
|
||||
} else {
|
||||
tableRowsFistPart.appendChild(tableRowsChildNode);
|
||||
dataMoved = true;
|
||||
}
|
||||
} else {
|
||||
System.out.println("ERROR: TEXT NODE FOUND INSIDE tabl:table-rows");
|
||||
//Append text nodes
|
||||
//tableRowsFistPart.appendChild(tableRowsChildNode);
|
||||
//dataMoved = true;
|
||||
}
|
||||
|
||||
}
|
||||
return dataMoved;
|
||||
}
|
||||
private static boolean handleTableRow(Node tableRowFistPart, Node tableRow) {
|
||||
boolean dataMoved = false;
|
||||
// Node counter
|
||||
int i = 0;
|
||||
NodeList tableRowChildNodes = tableRow.getChildNodes();
|
||||
while (tableRowChildNodes.getLength() > i) {
|
||||
Node tableRowChildNode = tableRowChildNodes.item(i);
|
||||
if ((tableRowChildNode.getNodeType() == Node.ELEMENT_NODE)) {
|
||||
|
||||
String nodeName = tableRowChildNode.getNodeName();
|
||||
|
||||
if (checkSoftPageBreak(tableRowChildNode, false)){
|
||||
Node tableRowGroupChildFirstPart = tableRowChildNode.cloneNode(false);
|
||||
if (nodeName.equals(XMLString.TABLE_TABLE_CELL)){
|
||||
if (handleCell(tableRowGroupChildFirstPart, tableRowChildNode)){
|
||||
dataMoved = true;
|
||||
tableRowFistPart.appendChild(tableRowGroupChildFirstPart);
|
||||
}
|
||||
|
||||
} else if (nodeName.equals(XMLString.TABLE_COVERED_TABLE_CELL)){
|
||||
//Implement handleCoveredCell in future
|
||||
if (handleCell(tableRowGroupChildFirstPart, tableRowChildNode)){
|
||||
dataMoved = true;
|
||||
tableRowFistPart.appendChild(tableRowGroupChildFirstPart);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//System.out.println("HERE " + nodeName);
|
||||
//Move node without SPB above
|
||||
tableRowFistPart.appendChild(tableRowChildNode.cloneNode(true));
|
||||
Node emptyCell = tableRowChildNode.cloneNode(false);
|
||||
Document document = tableRow.getOwnerDocument();
|
||||
Element textP = document.createElement(XMLString.TEXT_P);
|
||||
emptyCell.appendChild(textP);
|
||||
tableRow.insertBefore(emptyCell, tableRowChildNode);
|
||||
tableRow.removeChild(tableRowChildNode);
|
||||
|
||||
|
||||
dataMoved = true;
|
||||
}
|
||||
i++;
|
||||
} else {
|
||||
System.out.println("ERROR: TEXT NODE FOUND INSIDE tabl:table-row");
|
||||
//Append text nodes
|
||||
//tableRowsFistPart.appendChild(tableRowsChildNode);
|
||||
//dataMoved = true;
|
||||
}
|
||||
|
||||
}
|
||||
return dataMoved;
|
||||
}
|
||||
private static boolean handleCell(Node cellFirstPart, Node cellNode) {
|
||||
boolean dataMoved = false;
|
||||
// Node counter
|
||||
int i = 0;
|
||||
NodeList cellChildNodes = cellNode.getChildNodes();
|
||||
while (cellChildNodes.getLength() > i) {
|
||||
Node cellChildNode = cellChildNodes.item(0);
|
||||
if ((cellChildNode.getNodeType() == Node.ELEMENT_NODE)) {
|
||||
String nodeName = cellChildNode.getNodeName();
|
||||
if (checkSoftPageBreak(cellChildNode, false)){
|
||||
Node cellChildFirstPart = cellChildNode.cloneNode(false);
|
||||
if (nodeName.equals(XMLString.TEXT_SOFT_PAGE_BREAK)){
|
||||
// remove inner soft page break node
|
||||
cellNode.removeChild(cellChildNode);
|
||||
|
||||
} else if (nodeName.equals(XMLString.TEXT_H) || nodeName.equals(XMLString.TEXT_P)) {
|
||||
|
||||
if (handleParagraph(cellChildFirstPart, cellChildNode)){
|
||||
cellFirstPart.appendChild(cellChildFirstPart);
|
||||
dataMoved=true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
} else {
|
||||
cellFirstPart.appendChild(cellChildNode);
|
||||
dataMoved = true;
|
||||
}
|
||||
} else {
|
||||
//Append text nodes
|
||||
cellFirstPart.appendChild(cellChildNode);
|
||||
dataMoved = true;
|
||||
}
|
||||
|
||||
}
|
||||
return dataMoved;
|
||||
}
|
||||
private static boolean handleSection(Node sectionFirstPart, Node sectionNode) {
|
||||
boolean dataMoved = false;
|
||||
// Node counter
|
||||
int i = 0;
|
||||
NodeList sectionChildNodes = sectionNode.getChildNodes();
|
||||
while (sectionChildNodes.getLength() > i) {
|
||||
Node sectionChildNode = sectionChildNodes.item(0);
|
||||
if ((sectionChildNode.getNodeType() == Node.ELEMENT_NODE)) {
|
||||
String nodeName = sectionChildNode.getNodeName();
|
||||
if (checkSoftPageBreak(sectionChildNode, false)){
|
||||
Node sectionChildFirstPart = sectionChildNode.cloneNode(false);
|
||||
if (nodeName.equals(XMLString.TEXT_SOFT_PAGE_BREAK)){
|
||||
// remove inner soft page break node
|
||||
sectionNode.removeChild(sectionChildNode);
|
||||
|
||||
} else if (nodeName.equals(XMLString.TEXT_H) || nodeName.equals(XMLString.TEXT_P)) {
|
||||
|
||||
if (handleParagraph(sectionChildFirstPart, sectionChildNode)){
|
||||
sectionFirstPart.appendChild(sectionChildFirstPart);
|
||||
dataMoved=true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
} else {
|
||||
sectionFirstPart.appendChild(sectionChildNode);
|
||||
dataMoved = true;
|
||||
}
|
||||
} else {
|
||||
//Append text nodes
|
||||
sectionFirstPart.appendChild(sectionChildNode);
|
||||
dataMoved = true;
|
||||
}
|
||||
|
||||
}
|
||||
return dataMoved;
|
||||
}
|
||||
|
||||
|
||||
private static boolean handleParagraph(Node paraFirstPart, Node paraNode) {
|
||||
boolean dataMoved = false;
|
||||
int i = 0;
|
||||
NodeList paraChildNodes = paraNode.getChildNodes();
|
||||
while (paraChildNodes.getLength() > i) {
|
||||
Node paraChildNode = paraChildNodes.item(i);
|
||||
//NOT TEXT NODES
|
||||
if ((paraChildNode.getNodeType() == Node.ELEMENT_NODE)) {
|
||||
String nodeName = paraChildNode.getNodeName();
|
||||
//System.out.println(nodeName);
|
||||
//SPB FOUND
|
||||
if (checkSoftPageBreak(paraChildNode, false)){
|
||||
if (nodeName.equals(XMLString.TEXT_SOFT_PAGE_BREAK)){
|
||||
// remove inner soft page break node
|
||||
paraNode.removeChild(paraChildNode);
|
||||
|
||||
//Next node in paragraph. If it is text node go further
|
||||
Node paraNextNode = paraChildNodes.item(i);
|
||||
Node paraPrevNode = paraFirstPart.getLastChild();
|
||||
String nextText = null;
|
||||
String prevText = null;
|
||||
if (paraNextNode != null && paraPrevNode != null ){
|
||||
|
||||
if (paraNextNode.getNodeType() == Node.TEXT_NODE) {
|
||||
nextText = paraNextNode.getTextContent();
|
||||
} else if (paraNextNode.getNodeType() == Node.ELEMENT_NODE) {
|
||||
Node nextNodeFirstChild = paraNextNode.getFirstChild();
|
||||
if (nextNodeFirstChild != null && nextNodeFirstChild.getNodeType() == Node.TEXT_NODE) {
|
||||
nextText = nextNodeFirstChild.getTextContent();
|
||||
}
|
||||
}
|
||||
if (paraPrevNode.getNodeType() == Node.TEXT_NODE){
|
||||
prevText = paraPrevNode.getTextContent();
|
||||
} else if (paraPrevNode.getNodeType() == Node.ELEMENT_NODE) {
|
||||
Node prevNodeLastChild = paraPrevNode.getLastChild();
|
||||
if (prevNodeLastChild != null && prevNodeLastChild.getNodeType() == Node.TEXT_NODE) {
|
||||
prevText = prevNodeLastChild.getTextContent();
|
||||
}
|
||||
}
|
||||
//If previous and next texts exists
|
||||
if (nextText != null && prevText != null) {
|
||||
//If first character in next text is a letter
|
||||
//And if last character in previous text is a letter or soft hyphen
|
||||
if (Character.isLetter(nextText.charAt(0))
|
||||
&& (Character.isLetter(prevText.charAt(prevText.length() - 1))
|
||||
|| prevText.charAt(prevText.length() - 1) == 173)) {
|
||||
paraPrevNode.setTextContent(prevText + "\u2010");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Check if next node in para is text and first char is a letter
|
||||
* Check if last node in paraFirstPart is text and last char is a letter
|
||||
* If both true - add
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} else {
|
||||
System.out.println("ERROR: SPB INSIDE Paragraph Element in inner element " + nodeName);
|
||||
//checkSoftPageBreak(internalNode, true);
|
||||
//paraFirstPart.appendChild(internalNode);
|
||||
//dataMoved = true;
|
||||
}
|
||||
break;
|
||||
//ELEMENT WITHOUT SPB
|
||||
} else if (nodeName.equals(XMLString.TEXT_BOOKMARK_START)){
|
||||
paraFirstPart.appendChild(paraChildNode.cloneNode(true));
|
||||
i++;
|
||||
} else {
|
||||
paraFirstPart.appendChild(paraChildNode);
|
||||
dataMoved = true;
|
||||
}
|
||||
//TEXT NODES
|
||||
} else {
|
||||
paraFirstPart.appendChild(paraChildNode);
|
||||
dataMoved = true;
|
||||
}
|
||||
|
||||
}
|
||||
return dataMoved;
|
||||
}
|
||||
// Returns true if soft-page-break found. Removes it if removeFound = true
|
||||
private static boolean checkSoftPageBreak(Node node, boolean removeFound) {
|
||||
if (node.getNodeType() == Node.ELEMENT_NODE) {
|
||||
if (node.getNodeName().equals(XMLString.TEXT_SOFT_PAGE_BREAK)) {
|
||||
if (removeFound) {
|
||||
Node parent = node.getParentNode();
|
||||
parent.removeChild(node);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (node.hasChildNodes()) {
|
||||
int currentNo = 0;
|
||||
NodeList childNodes = node.getChildNodes();
|
||||
while (currentNo < childNodes.getLength()) {
|
||||
Node childNode = childNodes.item(currentNo);
|
||||
if (checkSoftPageBreak(childNode, removeFound)) {
|
||||
return true;
|
||||
}
|
||||
currentNo++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -33,7 +33,9 @@ import org.w3c.dom.Element;
|
|||
|
||||
import writer2latex.util.Misc;
|
||||
import writer2latex.office.FontDeclaration;
|
||||
import writer2latex.office.MasterPage;
|
||||
import writer2latex.office.OfficeStyle;
|
||||
import writer2latex.office.PageLayout;
|
||||
import writer2latex.office.XMLString;
|
||||
import writer2latex.office.ListCounter;
|
||||
import writer2latex.office.ListStyle;
|
||||
|
@ -94,6 +96,12 @@ public class TextConverter extends ConverterHelper {
|
|||
|
||||
// Display hidden text?
|
||||
private boolean bDisplayHiddenText = false;
|
||||
// Current page number
|
||||
int pageNum = 1;
|
||||
//Current master page name
|
||||
private String currentMasterPage = null;
|
||||
//Current master page name
|
||||
private String nextMasterPage = null;
|
||||
|
||||
public TextConverter(OfficeReader ofr, XhtmlConfig config, Converter converter) {
|
||||
super(ofr,config,converter);
|
||||
|
@ -132,14 +140,16 @@ public class TextConverter extends ConverterHelper {
|
|||
|
||||
// Add cover image
|
||||
hnode = getDrawCv().insertCoverImage(hnode);
|
||||
|
||||
//Split pages
|
||||
onode = (Element) PageSplitter.splitSoftPageBreak(onode,ofr);
|
||||
// Convert content
|
||||
hnode = (Element)traverseBlockText(onode,hnode);
|
||||
|
||||
// Add footnotes and endnotes
|
||||
footCv.insertFootnotes(hnode,true);
|
||||
addFooter(hnode);
|
||||
endCv.insertEndnotes(hnode);
|
||||
|
||||
GreenstoneTags.endDocument(hnode);
|
||||
// Generate all indexes
|
||||
bInToc = true;
|
||||
tocCv.generate();
|
||||
|
@ -186,6 +196,8 @@ public class TextConverter extends ConverterHelper {
|
|||
NodeList nList = onode.getChildNodes();
|
||||
int nLen = nList.getLength();
|
||||
int i = 0;
|
||||
//hard Break after marker
|
||||
boolean breakBeforeNextNode = false;
|
||||
while (i < nLen) {
|
||||
Node child = nList.item(i);
|
||||
|
||||
|
@ -199,6 +211,7 @@ public class TextConverter extends ConverterHelper {
|
|||
}
|
||||
else if (nodeName.equals(XMLString.TEXT_P)) {
|
||||
StyleWithProperties style = ofr.getParStyle(Misc.getAttribute(child,XMLString.TEXT_STYLE_NAME));
|
||||
breakBeforeNextNode = processPageBreaks(child, hnode,style, breakBeforeNextNode);
|
||||
hnode = maybeSplit(hnode, style);
|
||||
nCharacterCount+=OfficeReader.getCharacterCount(child);
|
||||
// is there a block element, we should use?
|
||||
|
@ -247,6 +260,8 @@ public class TextConverter extends ConverterHelper {
|
|||
StyleWithProperties style = ofr.getParStyle(Misc.getAttribute(child,XMLString.TEXT_STYLE_NAME));
|
||||
int nOutlineLevel = getOutlineLevel((Element)child);
|
||||
Node rememberNode = hnode;
|
||||
breakBeforeNextNode = processPageBreaks(child, hnode, style, breakBeforeNextNode);
|
||||
GreenstoneTags.processHeading(child, hnode, pageNum);
|
||||
hnode = maybeSplit(hnode,style,nOutlineLevel);
|
||||
nCharacterCount+=OfficeReader.getCharacterCount(child);
|
||||
handleHeading((Element)child,(Element)hnode,rememberNode!=hnode);
|
||||
|
@ -255,6 +270,7 @@ public class TextConverter extends ConverterHelper {
|
|||
nodeName.equals(XMLString.TEXT_UNORDERED_LIST) || // old
|
||||
nodeName.equals(XMLString.TEXT_ORDERED_LIST)) // old
|
||||
{
|
||||
breakBeforeNextNode = processPageBreaks(child, hnode,null, breakBeforeNextNode);
|
||||
hnode = maybeSplit(hnode,null);
|
||||
if (listIsOnlyHeadings(child)) {
|
||||
nDontSplitLevel--;
|
||||
|
@ -266,7 +282,8 @@ public class TextConverter extends ConverterHelper {
|
|||
}
|
||||
}
|
||||
else if (nodeName.equals(XMLString.TABLE_TABLE)) {
|
||||
StyleWithProperties style = ofr.getTableStyle(Misc.getAttribute(child,XMLString.TEXT_STYLE_NAME));
|
||||
StyleWithProperties style = ofr.getTableStyle(Misc.getAttribute(child, XMLString.TABLE_STYLE_NAME));
|
||||
breakBeforeNextNode = processPageBreaks(child, hnode,style, breakBeforeNextNode);
|
||||
hnode = maybeSplit(hnode,style);
|
||||
getTableCv().handleTable(child,hnode);
|
||||
}
|
||||
|
@ -306,6 +323,7 @@ public class TextConverter extends ConverterHelper {
|
|||
bibCv.handleIndex((Element)child,(Element)hnode);
|
||||
}
|
||||
else if (nodeName.equals(XMLString.TEXT_SOFT_PAGE_BREAK)) {
|
||||
breakBeforeNextNode = true;
|
||||
if (nPageBreakSplit==XhtmlConfig.ALL) { bPendingPageBreak = true; }
|
||||
}
|
||||
else if (nodeName.equals(XMLString.OFFICE_ANNOTATION)) {
|
||||
|
@ -1239,8 +1257,15 @@ public class TextConverter extends ConverterHelper {
|
|||
}
|
||||
|
||||
private void handlePageNumber(Node onode, Node hnode) {
|
||||
// doesn't make any sense...
|
||||
hnode.appendChild( converter.createTextNode("(Page number)") );
|
||||
String adjust = Misc.getAttribute(onode, XMLString.TEXT_PAGE_ADJUST);
|
||||
//Set current page number
|
||||
Integer pageNumber = pageNum;
|
||||
//If there is adjustment apply it
|
||||
if (adjust != null) {
|
||||
int pageNumberAdjust = Integer.parseInt(adjust);
|
||||
pageNumber += pageNumberAdjust;
|
||||
}
|
||||
hnode.appendChild(converter.createTextNode(pageNumber.toString()));
|
||||
}
|
||||
|
||||
private void handlePageCount(Node onode, Node hnode) {
|
||||
|
@ -1520,5 +1545,192 @@ public class TextConverter extends ConverterHelper {
|
|||
Misc.getPosInteger(node.getAttribute(XMLString.TEXT_OUTLINE_LEVEL),1):
|
||||
Misc.getPosInteger(node.getAttribute(XMLString.TEXT_LEVEL),1);
|
||||
}
|
||||
private boolean processPageBreaks(Node currentNode, Node hnode,StyleWithProperties style, boolean breakBeforeNextNode){
|
||||
Integer newPageNumber = null;
|
||||
if (style != null) {
|
||||
// If style:paragraph-properties extists and contain
|
||||
// style:page-number
|
||||
String newPageNumberProperty = style.getParProperty(XMLString.STYLE_PAGE_NUMBER, true);
|
||||
if (newPageNumberProperty != null) {
|
||||
// Truncate auto and other string values
|
||||
newPageNumberProperty = newPageNumberProperty.replaceAll("[^0-9]", "");
|
||||
if (!newPageNumberProperty.isEmpty()) {
|
||||
// Save new page number
|
||||
newPageNumber = Integer.parseInt(newPageNumberProperty);
|
||||
}
|
||||
|
||||
}
|
||||
// Set first master page name
|
||||
// If Master Page style has been already set
|
||||
}
|
||||
if (currentMasterPage == null && style != null) {
|
||||
// Looks like first page.
|
||||
if (checkMasterStylePageBreak(style)) {
|
||||
updateMasterPage(style);
|
||||
} else {
|
||||
//Set standard MP
|
||||
currentMasterPage = "Standard";
|
||||
}
|
||||
if (newPageNumber != null) {
|
||||
pageNum = newPageNumber;
|
||||
} else {
|
||||
fitPageNumberToMasterPageStyle();
|
||||
}
|
||||
|
||||
//Start tagging
|
||||
String sTitle = converter.getTitle();
|
||||
GreenstoneTags.StartDocument(hnode, sTitle);
|
||||
//Print header
|
||||
addHeader(hnode);
|
||||
|
||||
} else {
|
||||
//If old master page was defined
|
||||
|
||||
//If new master page definition found
|
||||
//Or if fo:break-before found
|
||||
//Or if soft-page-break or fo:break-after appeared before this node
|
||||
if (checkMasterStylePageBreak(style) || checkHardBreakBefore(style) || breakBeforeNextNode) {
|
||||
//Insert footnotes
|
||||
footCv.insertFootnotes(hnode, true);
|
||||
//Add previous MP footer
|
||||
addFooter(hnode);
|
||||
//Update MP
|
||||
updateMasterPage(style);
|
||||
//Set new page number if defined or increment if not
|
||||
if (newPageNumber != null) {
|
||||
pageNum = newPageNumber;
|
||||
} else {
|
||||
pageNum++;
|
||||
fitPageNumberToMasterPageStyle();
|
||||
}
|
||||
//if
|
||||
GreenstoneTags.processPageBreak(currentNode, hnode, pageNum);
|
||||
//Print new header
|
||||
addHeader(hnode);
|
||||
//breakBeforeNextNode = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
if (checkHardBreakAfter(style)) {
|
||||
|
||||
//breakBeforeNextNode = true;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void fitPageNumberToMasterPageStyle() {
|
||||
// TODO: READ master-page style
|
||||
|
||||
MasterPage masterPage = ofr.getFullMasterPage(currentMasterPage);
|
||||
if (masterPage != null) {
|
||||
String pageLayoutName = masterPage.getPageLayoutName();
|
||||
if (pageLayoutName != null) {
|
||||
PageLayout pageLayout = ofr.getPageLayout(pageLayoutName);
|
||||
if (pageLayout != null) {
|
||||
String pageUsage = pageLayout.getPageUsage();
|
||||
if (pageUsage != null) {
|
||||
int parity = pageNum % 2;
|
||||
if (parity == 1 && pageUsage.equals("left")){
|
||||
pageNum++;
|
||||
}
|
||||
if (parity == 0 && pageUsage.equals("right")){
|
||||
pageNum++;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
} else {
|
||||
}
|
||||
} else {
|
||||
}
|
||||
|
||||
} else {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean checkMasterStylePageBreak(StyleWithProperties style) {
|
||||
// Page break was found before
|
||||
if (style != null) {
|
||||
|
||||
String sMasterPage = style.getMasterPageName();
|
||||
if (sMasterPage != null && sMasterPage.length() > 0) {
|
||||
// System.out.println("GETPAGEBREAK SUCCESS MASTERPAGE STYLE FOUND " + currentMasterPage);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
private void updateMasterPage(StyleWithProperties style) {
|
||||
|
||||
if (style != null && checkMasterStylePageBreak(style)) {
|
||||
String sMasterPage = style.getMasterPageName();
|
||||
if (sMasterPage != null && sMasterPage.length() > 0) {
|
||||
currentMasterPage = sMasterPage;
|
||||
// Set next master page
|
||||
MasterPage masterPage = ofr.getFullMasterPage(currentMasterPage);
|
||||
nextMasterPage = masterPage.getProperty(XMLString.STYLE_NEXT_STYLE_NAME);
|
||||
}
|
||||
} else if (nextMasterPage != null){
|
||||
currentMasterPage = nextMasterPage;
|
||||
MasterPage masterPage = ofr.getFullMasterPage(currentMasterPage);
|
||||
nextMasterPage = masterPage.getProperty(XMLString.STYLE_NEXT_STYLE_NAME);
|
||||
// System.out.println("Next master page is " + nextMasterPage);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private boolean checkHardBreakBefore(StyleWithProperties style) {
|
||||
if (style != null && "page".equals(style.getProperty(XMLString.FO_BREAK_BEFORE))) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean checkHardBreakAfter(StyleWithProperties style) {
|
||||
if (style != null && "page".equals(style.getProperty(XMLString.FO_BREAK_AFTER))) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private Node addHeader(Node node) {
|
||||
|
||||
MasterPage masterPage = ofr.getFullMasterPage(currentMasterPage);
|
||||
if (currentMasterPage != null) {
|
||||
|
||||
Node headerNode = masterPage.getHeader();
|
||||
if (headerNode != null) {
|
||||
//Create header element
|
||||
Element headerElement = converter.createElement("header");
|
||||
node.appendChild(headerElement);
|
||||
traverseBlockText(headerNode, headerElement);
|
||||
}
|
||||
} else {
|
||||
System.out.println("ERROR MP is null");
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
private Node addFooter(Node node) {
|
||||
|
||||
MasterPage masterPage = ofr.getFullMasterPage(currentMasterPage);
|
||||
if (currentMasterPage != null) {
|
||||
|
||||
Node footerNode = masterPage.getFooter();
|
||||
if (footerNode != null) {
|
||||
//Create footer element
|
||||
Element footerElement = converter.createElement("footer");
|
||||
node.appendChild(footerElement);
|
||||
traverseBlockText(footerNode, footerElement);
|
||||
}
|
||||
} else {
|
||||
System.out.println("ERROR MP is null");
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ import writer2latex.util.Misc;
|
|||
|
||||
public class XhtmlConfig extends writer2latex.base.ConfigBase {
|
||||
// Implement configuration methods
|
||||
protected int getOptionCount() { return 59; }
|
||||
protected int getOptionCount() { return 60; }
|
||||
protected String getDefaultConfigPath() { return "/writer2latex/xhtml/config/"; }
|
||||
|
||||
// Override setOption: To be backwards compatible, we must accept options
|
||||
|
@ -158,6 +158,7 @@ public class XhtmlConfig extends writer2latex.base.ConfigBase {
|
|||
private static final int UPLINK = 56;
|
||||
private static final int DIRECTORY_ICON = 57;
|
||||
private static final int DOCUMENT_ICON = 58;
|
||||
private static final int CONVERT_HEADER_AND_FOOTER = 59;
|
||||
|
||||
protected ComplexOption xheading = addComplexOption("heading-map");
|
||||
protected ComplexOption xpar = addComplexOption("paragraph-map");
|
||||
|
@ -203,7 +204,7 @@ public class XhtmlConfig extends writer2latex.base.ConfigBase {
|
|||
else { nValue = ABSOLUTE; }
|
||||
}
|
||||
};
|
||||
options[LIST_FORMATTING] = new IntegerOption("list_formatting","css1") {
|
||||
options[LIST_FORMATTING] = new IntegerOption("list_formatting","css1_hack") {
|
||||
@Override public void setString(String sValue) {
|
||||
super.setString(sValue);
|
||||
if ("css1_hack".equals(sValue)) { nValue = CSS1_HACK; }
|
||||
|
@ -291,6 +292,7 @@ public class XhtmlConfig extends writer2latex.base.ConfigBase {
|
|||
options[UPLINK] = new Option("uplink","");
|
||||
options[DIRECTORY_ICON] = new Option("directory_icon","");
|
||||
options[DOCUMENT_ICON] = new Option("document_icon","");
|
||||
options[CONVERT_HEADER_AND_FOOTER] = new BooleanOption("convert_header_footer","false");
|
||||
}
|
||||
|
||||
protected void readInner(Element elm) {
|
||||
|
@ -433,6 +435,7 @@ public class XhtmlConfig extends writer2latex.base.ConfigBase {
|
|||
public String getXhtmlUplink() { return options[UPLINK].getString(); }
|
||||
public String getXhtmlDirectoryIcon() { return options[DIRECTORY_ICON].getString(); }
|
||||
public String getXhtmlDocumentIcon() { return options[DOCUMENT_ICON].getString(); }
|
||||
public boolean convertHeaderAndFooter() { return ((BooleanOption) options[CONVERT_HEADER_AND_FOOTER]).getValue(); }
|
||||
|
||||
public XhtmlStyleMap getXParStyleMap() { return getStyleMap(xpar); }
|
||||
public XhtmlStyleMap getXHeadingStyleMap() { return getStyleMap(xheading); }
|
||||
|
|
|
@ -594,6 +594,7 @@ public class XhtmlDocument extends DOMDocument {
|
|||
}
|
||||
}
|
||||
Element doc = getContentDOM().getDocumentElement();
|
||||
|
||||
optimize(doc,null,null);
|
||||
write(doc,bPrettyPrint ? 0 : -1,osw);
|
||||
osw.flush();
|
||||
|
@ -691,9 +692,11 @@ public class XhtmlDocument extends DOMDocument {
|
|||
write(node.getNodeValue(),osw);
|
||||
break;
|
||||
case Node.COMMENT_NODE:
|
||||
|
||||
if (nLevel>=0) { writeSpaces(nLevel,osw); }
|
||||
osw.write("<!-- ");
|
||||
write(node.getNodeValue(),osw);
|
||||
//write(node.getNodeValue(),osw);
|
||||
osw.write(node.getNodeValue());
|
||||
osw.write(" -->");
|
||||
if (nLevel>=0) { osw.write("\n"); }
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue