From aee06864b8bf068bda596f131bcc31ff092d3953 Mon Sep 17 00:00:00 2001 From: Georgy Litvinov Date: Wed, 22 Jan 2020 13:08:43 +0100 Subject: [PATCH] Created page container --- .../writer2latex/xhtml/DocumentSeparator.java | 48 ++++++++- .../writer2latex/xhtml/TextConverter.java | 99 ++++++++++--------- 2 files changed, 98 insertions(+), 49 deletions(-) diff --git a/src/main/java/writer2latex/xhtml/DocumentSeparator.java b/src/main/java/writer2latex/xhtml/DocumentSeparator.java index 0d1969e..d3f5bc3 100644 --- a/src/main/java/writer2latex/xhtml/DocumentSeparator.java +++ b/src/main/java/writer2latex/xhtml/DocumentSeparator.java @@ -29,9 +29,10 @@ public class DocumentSeparator { private static String headingSeparation = "sections"; //sections div none private static String pageSeparation = "sections"; - private Converter converter = null; + private static Converter converter = null; private XhtmlConfig config = null; private Node prevPageNode = null; + private String pageContainerStyle = null; public DocumentSeparator(XhtmlConfig config,Converter converter) { this.config = config; @@ -42,6 +43,9 @@ public class DocumentSeparator { splitByPages = pageSeparation.equals(DIV) ? true : false; } + public void setPageContainerStyle(String style) { + this.pageContainerStyle = style; + } protected Node processOutlineLevel(Node currentNode, Node hnode, int pageNum) { //Get outline level @@ -115,7 +119,7 @@ public class DocumentSeparator { /** * Opens main document section heading tag */ - protected Node StartDocument(Node hnode, String title, int pageNum){ + protected Node startDocument(Node hnode, String title, int pageNum){ if (noHeadingSeparation() && noPageSeparation()){ return hnode; @@ -129,7 +133,7 @@ public class DocumentSeparator { return hnode; } //Method to close open tags at the end of the document - protected static Node endDocument(Node hnode){ + protected Node endDocument(Node hnode){ if (noHeadingSeparation() && noPageSeparation()){ return hnode; } @@ -261,7 +265,8 @@ public class DocumentSeparator { } } } - protected static Node closePage(Node hnode){ + protected Node closePage(Node hnode){ + hnode = exitPageContainer(hnode); if (pageSeparation.equals(SECTIONS)){ //If section is empty. In case we are closing section // the last comment is opened page section @@ -285,9 +290,44 @@ public class DocumentSeparator { hnode = openPageDiv(hnode, pageNum); pageOpened = true; } + hnode = enterPageContainer(hnode); return hnode; } + + private Node exitPageContainer(Node hnode) { + + String className = ((Element) hnode).getAttribute("class"); + if (!className.equals("pageContainer")) { + System.out.println("Can't exit not my container!"); + Debug.printNode(hnode); + for (StackTraceElement ste : Thread.currentThread().getStackTrace()) { + System.out.println(ste); + } + System.exit(1); + } + Element parentNode = (Element) hnode.getParentNode(); + return parentNode; + } + private Node enterPageContainer(Node hnode) { + if (hnode == null) { + + System.out.println("Enter page container error. hnode is null"); + for (StackTraceElement ste : Thread.currentThread().getStackTrace()) { + System.out.println(ste); + } + System.exit(1); + } + Element container = converter.createElement("div"); + container.setAttribute("class", "pageContainer"); + if (pageContainerStyle != null) { + System.out.println(pageContainerStyle); + container.setAttribute("style", pageContainerStyle); + } + hnode.appendChild(container); + return container; + } + private static boolean noHeadingSeparation() { return headingSeparation.equals(NONE); } diff --git a/src/main/java/writer2latex/xhtml/TextConverter.java b/src/main/java/writer2latex/xhtml/TextConverter.java index 06ee4d8..1d3e4cb 100644 --- a/src/main/java/writer2latex/xhtml/TextConverter.java +++ b/src/main/java/writer2latex/xhtml/TextConverter.java @@ -166,17 +166,16 @@ public class TextConverter extends ConverterHelper { onode = (Element) PageSplitter.splitSoftPageBreak(onode,ofr); } - //Debug.printNode(onode); - // Convert content - hnode = (Element)traverseBlockText(onode,hnode); + hnode = (Element)traverseBlockText(onode,hnode); // Add footnotes and endnotes insertFootnotes(hnode,true); - if (!pageSeparator.equals("none")) { - addFooter(hnode); - } + + //hnode = exitPageContainer(hnode); + addFooter(hnode); + insertEndnotes(hnode, null); hnode = (Element) docSep.endDocument(hnode); // Generate all indexes @@ -192,6 +191,23 @@ public class TextConverter extends ConverterHelper { bInToc = false; } + /*private Element exitPageContainer(Element hnode) { + System.out.println("exit page container"); + + String className = ((Element) hnode).getAttribute("class"); + if (!className.equals("pageContainer")) { + System.out.println("Can't exit not my container!"); + Debug.printNode(hnode); + for (StackTraceElement ste : Thread.currentThread().getStackTrace()) { + System.out.println(ste); + } + System.exit(1); + } + Element parentNode = (Element) hnode.getParentNode(); + System.out.println("parent node name " + parentNode.getNodeName()); + return parentNode; + } +*/ private void insertEndnotes(Element hnode, String section) { inEndnote = true; endCv.insertEndnotes(hnode,section); @@ -530,50 +546,29 @@ public class TextConverter extends ConverterHelper { /* Process a text:section tag (returns current html node) */ private Node handleSection(Node onode, Node hnode) { - System.out.println("Handle section"); // Unlike headings, paragraphs and spans, text:display is not attached to the style: Node result = null; if (!bDisplayHiddenText && "none".equals(Misc.getAttribute(onode,TEXT_DISPLAY))) { return hnode; } + hnode = docSep.closePage(hnode); + String sectionName = Misc.getAttribute(onode,TEXT_NAME); String sStyleName = Misc.getAttribute(onode,TEXT_STYLE_NAME); StyleInfo sectionInfo = new StyleInfo(); getSectionSc().applyStyle(sStyleName, sectionInfo); - ////closePageSection - - hnode = docSep.closePage(hnode); - - Element div = (Element) hnode; - - -/* if (headingTags.equals("none")) { - div = converter.createElement("div"); - // close page before enter - hnode = docSep.closePage(hnode); - - hnode.appendChild(div); + docSep.setPageContainerStyle(sectionInfo.props.toString()); + hnode = docSep.openPage(hnode, pageNum); +/* hnode.appendChild(div); converter.addTarget(div, sectionName + "|region"); applyStyle(sectionInfo, div); - System.out.println("sectionInfo \n" + sectionInfo); - sections.push(onode); - //open page after enter - div = (Element) docSep.openPage(div, pageNum); - }*/ + */ - Node newhnode = traverseBlockText(onode, div); + hnode = traverseBlockText(onode, hnode); -/* if (headingTags.equals("none")) { - //close page before exit - newhnode = docSep.closePage(newhnode); - result = newhnode.getParentNode(); - //Open page after exit - result = (Element) docSep.openPage(result, pageNum); +/* sections.pop(); - } else { - result = newhnode; - }*/ - result = newhnode; - return result; + */ + return hnode; } private void handleHeading(Element onode, Element hnode, boolean bAfterSplit) { @@ -1700,12 +1695,13 @@ public class TextConverter extends ConverterHelper { Integer newPageNumber = null; newPageNumber = getPageNumber(style, newPageNumber); if (currentMasterPage == null && style != null) { - hnode = StartMasterPage(hnode, style, newPageNumber); + hnode = startDocument(hnode, style, newPageNumber); hnode = docSep.processOutlineLevel(currentNode, hnode, pageNum); } else if (checkMasterPageBreak(style) || checkHardBreakBefore(style) || breakBeforeNextNode) { // Insert footnotes insertFootnotes(hnode,false); // Add previous MP footer + //hnode = exitPageContainer((Element) hnode); addFooter(hnode); // Update MP updateMasterPage(style); @@ -1725,6 +1721,7 @@ public class TextConverter extends ConverterHelper { // Print new header addHeader(hnode); + //hnode = enterPageContainer(hnode); breakBeforeNextNode = false; return hnode; @@ -1765,7 +1762,7 @@ public class TextConverter extends ConverterHelper { return newPageNumber; } - private Node StartMasterPage(Node hnode, StyleWithProperties style, Integer newPageNumber) { + private Node startDocument(Node hnode, StyleWithProperties style, Integer newPageNumber) { if (checkMasterPageBreak(style)) { updateMasterPage(style); @@ -1780,15 +1777,25 @@ public class TextConverter extends ConverterHelper { //Start tagging String sTitle = converter.getTitle(); - hnode = docSep.StartDocument(hnode, sTitle,pageNum); + hnode = docSep.startDocument(hnode, sTitle,pageNum); //Print header - if (!pageSeparator.equals("none")) { - addHeader(hnode); - } + addHeader(hnode); + //hnode = enterPageContainer(hnode); return hnode; } + /*private Node enterPageContainer(Node hnode) { + System.out.println("enter page container " + hnode.getNodeName()); + if (hnode == null) { + System.out.println("hnode is null"); + } + Element container = converter.createElement("div"); + container.setAttribute("class", "pageContainer"); + hnode.appendChild(container); + return container; + }*/ + private void fitPageNumberToMasterPageStyle() { // TODO: READ master-page style @@ -1878,7 +1885,8 @@ public class TextConverter extends ConverterHelper { if (headerNode != null) { //Create header element Element headerElement = converter.createElement("header"); - node.appendChild(headerElement); + Node pageNode = node.getParentNode(); + pageNode.insertBefore(headerElement, node); traverseBlockText(headerNode, headerElement); } } else { @@ -1902,7 +1910,8 @@ public class TextConverter extends ConverterHelper { if (footerNode != null) { //Create footer element Element footerElement = converter.createElement("footer"); - node.appendChild(footerElement); + Node pageNode = node.getParentNode(); + pageNode.appendChild(footerElement); traverseBlockText(footerNode, footerElement); } } else {