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) {
String nodeName = child.getNodeName();
// Block splitting
//System.out.println(nodeName);
// System.out.println("CURNODE " + nodeName);
if (OfficeReader.isDrawElement(child)) {
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_ORDERED_LIST)) // old
{
StyleWithProperties style = getListFirstParaStyle(child);
StyleWithProperties style = getFirstStylePageInfo(child);
hnode = processPageBreaks(child, hnode,style);
inList = true;
if (getListParser().listIsOnlyHeadings(child)) {
@ -348,7 +348,8 @@ public class TextParser extends Parser {
getTableParser().handleTable(child,hnode);
}
else if (nodeName.equals(TEXT_SECTION)) {
hnode = processPageBreaks(child, hnode,null);
StyleWithProperties style = getFirstStylePageInfo(child);
hnode = processPageBreaks(child, hnode,style);
hnode = handleSection(child,hnode);
}
else if (nodeName.equals(TEXT_TABLE_OF_CONTENT)) {
@ -391,24 +392,32 @@ public class TextParser extends Parser {
return hnode;
}
private StyleWithProperties getListFirstParaStyle(Node list) {
private StyleWithProperties getFirstStylePageInfo(Node node) {
StyleWithProperties style = null;
Element listItem = Misc.getChildByTagName(list, TEXT_LIST_ITEM);
if (listItem == null){
return style;
if (node.getNodeType() == Node.ELEMENT_NODE) {
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;
}
if (node.hasChildNodes()) {
int currentNo = 0;
NodeList childNodes = node.getChildNodes();
while (currentNo < childNodes.getLength()) {
Node childNode = childNodes.item(currentNo);
style = getFirstStylePageInfo(childNode);
if (style != null) {
return style;
}
currentNo++;
}
}
}
Element itemChild = Misc.getFirstChildElement(listItem);
if (itemChild == null) {
return style;
}
String itemChildName = itemChild.getNodeName();
if (!itemChildName.equals(TEXT_H) && !itemChildName.equals(TEXT_P)) {
return style;
}
style = ofr.getParStyle(Misc.getAttribute(itemChild,TEXT_STYLE_NAME));
return style;
}
/* Process a text:section tag (returns current html node) */
private Node handleSection(Node onode, Node hnode) {
// Unlike headings, paragraphs and spans, text:display is not attached to the style:
@ -1275,6 +1284,7 @@ public class TextParser extends Parser {
private void setPageContainerStyle() {
MasterPage mp = ofr.getFullMasterPage(currentMasterPage);
//System.out.println(currentMasterPage);
PageLayout layout = ofr.getPageLayout(mp.getPageLayoutName());
String containerStyle = "column-count: " + layout.getColCount() + ";";
pageContainer.setRootStyle(containerStyle);