Added method to get first paragraph or table to get master page information

This commit is contained in:
Georgy Litvinov 2020-07-25 12:33:09 +02:00
parent 9c5be98655
commit 3f69ecc932

View file

@ -267,7 +267,7 @@ public class TextParser extends Parser {
if (child.getNodeType() == Node.ELEMENT_NODE) { if (child.getNodeType() == Node.ELEMENT_NODE) {
String nodeName = child.getNodeName(); String nodeName = child.getNodeName();
// Block splitting // Block splitting
//System.out.println(nodeName); // System.out.println("CURNODE " + nodeName);
if (OfficeReader.isDrawElement(child)) { if (OfficeReader.isDrawElement(child)) {
getDrawParser().handleDrawElement((Element)child,(Element)hnode,null,nFloatMode); getDrawParser().handleDrawElement((Element)child,(Element)hnode,null,nFloatMode);
} }
@ -326,7 +326,7 @@ public class TextParser extends Parser {
nodeName.equals(TEXT_UNORDERED_LIST) || // old nodeName.equals(TEXT_UNORDERED_LIST) || // old
nodeName.equals(TEXT_ORDERED_LIST)) // old nodeName.equals(TEXT_ORDERED_LIST)) // old
{ {
StyleWithProperties style = getListFirstParaStyle(child); StyleWithProperties style = getFirstStylePageInfo(child);
hnode = processPageBreaks(child, hnode,style); hnode = processPageBreaks(child, hnode,style);
inList = true; inList = true;
if (getListParser().listIsOnlyHeadings(child)) { if (getListParser().listIsOnlyHeadings(child)) {
@ -348,7 +348,8 @@ public class TextParser extends Parser {
getTableParser().handleTable(child,hnode); getTableParser().handleTable(child,hnode);
} }
else if (nodeName.equals(TEXT_SECTION)) { else if (nodeName.equals(TEXT_SECTION)) {
hnode = processPageBreaks(child, hnode,null); StyleWithProperties style = getFirstStylePageInfo(child);
hnode = processPageBreaks(child, hnode,style);
hnode = handleSection(child,hnode); hnode = handleSection(child,hnode);
} }
else if (nodeName.equals(TEXT_TABLE_OF_CONTENT)) { else if (nodeName.equals(TEXT_TABLE_OF_CONTENT)) {
@ -391,21 +392,29 @@ public class TextParser extends Parser {
return hnode; return hnode;
} }
private StyleWithProperties getListFirstParaStyle(Node list) { private StyleWithProperties getFirstStylePageInfo(Node node) {
StyleWithProperties style = null; StyleWithProperties style = null;
Element listItem = Misc.getChildByTagName(list, TEXT_LIST_ITEM); if (node.getNodeType() == Node.ELEMENT_NODE) {
if (listItem == null){ if (node.getNodeName().equals(TEXT_P) || node.getNodeName().equals(TEXT_H)) {
style = ofr.getParStyle(Misc.getAttribute(node,TEXT_STYLE_NAME));
return style;
} else if (node.getNodeName().equals(TABLE_TABLE)) {
style = ofr.getTableStyle(Misc.getAttribute(node, TABLE_STYLE_NAME));
return style; return style;
} }
Element itemChild = Misc.getFirstChildElement(listItem); if (node.hasChildNodes()) {
if (itemChild == null) { int currentNo = 0;
NodeList childNodes = node.getChildNodes();
while (currentNo < childNodes.getLength()) {
Node childNode = childNodes.item(currentNo);
style = getFirstStylePageInfo(childNode);
if (style != null) {
return style; return style;
} }
String itemChildName = itemChild.getNodeName(); currentNo++;
if (!itemChildName.equals(TEXT_H) && !itemChildName.equals(TEXT_P)) { }
return style; }
} }
style = ofr.getParStyle(Misc.getAttribute(itemChild,TEXT_STYLE_NAME));
return style; return style;
} }
@ -1275,6 +1284,7 @@ public class TextParser extends Parser {
private void setPageContainerStyle() { private void setPageContainerStyle() {
MasterPage mp = ofr.getFullMasterPage(currentMasterPage); MasterPage mp = ofr.getFullMasterPage(currentMasterPage);
//System.out.println(currentMasterPage);
PageLayout layout = ofr.getPageLayout(mp.getPageLayoutName()); PageLayout layout = ofr.getPageLayout(mp.getPageLayoutName());
String containerStyle = "column-count: " + layout.getColCount() + ";"; String containerStyle = "column-count: " + layout.getColCount() + ";";
pageContainer.setRootStyle(containerStyle); pageContainer.setRootStyle(containerStyle);