Read and apply notes' properties in section configuration

This commit is contained in:
Georgy Litvinov 2020-01-27 15:18:59 +01:00
parent 2c7fb816e6
commit 274f1089c8
3 changed files with 47 additions and 14 deletions

View file

@ -26,6 +26,7 @@
package writer2latex.office;
import org.w3c.dom.Node;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import java.util.Enumeration;
import java.util.Hashtable;
@ -102,5 +103,17 @@ public class PropertySet implements Cloneable {
}
return s;
}
public void loadNoteProperties(Node child) {
Element noteConfiguration = (Element) child;
String noteClass = noteConfiguration.getAttribute(XMLString.TEXT_NOTE_CLASS);
NamedNodeMap attrs = noteConfiguration.getAttributes();
for (int i=0;i<attrs.getLength();i++) {
Node attr = attrs.item(i);
if (attr.getNodeName().equals(XMLString.TEXT_NOTE_CLASS)) {
properties.put(noteClass, "true");
}
properties.put(attr.getNodeName()+":"+noteClass, attr.getNodeValue());
}
}
}

View file

@ -30,6 +30,7 @@ import writer2latex.util.Calc;
//import org.w3c.dom.NamedNodeMap;
//import java.util.Hashtable;
import writer2latex.util.Misc;
import writer2latex.xhtml.Debug;
/** <p> Class representing a style in OOo which contains a style:properties
* element </p>
@ -100,6 +101,7 @@ public class StyleWithProperties extends OfficeStyle {
}
else if (XMLString.STYLE_SECTION_PROPERTIES.equals(sName)) {
loadPropertiesFromDOM(SECTION,child);
}
else if (XMLString.STYLE_TABLE_PROPERTIES.equals(sName)) {
loadPropertiesFromDOM(TABLE,child);
@ -133,18 +135,20 @@ public class StyleWithProperties extends OfficeStyle {
Node child = node.getFirstChild();
while (child!=null) {
if (child.getNodeType()==Node.ELEMENT_NODE) {
String sName = child.getNodeName();
if (XMLString.STYLE_BACKGROUND_IMAGE.equals(sName)) {
String childName = child.getNodeName();
if (XMLString.STYLE_BACKGROUND_IMAGE.equals(childName)) {
backgroundImageProperties.loadFromDOM(child);
}
else if (XMLString.STYLE_COLUMNS.equals(sName)) {
else if (XMLString.STYLE_COLUMNS.equals(childName)) {
nColCount = Misc.getPosInteger(Misc.getAttribute(child, XMLString.FO_COLUMN_COUNT),1);
// TODO: read individual columns
}
else if (XMLString.STYLE_FOOTNOTE_SEP.equals(sName)) {
else if (XMLString.STYLE_FOOTNOTE_SEP.equals(childName)) {
bHasFootnoteSep = true;
footnoteSep.loadFromDOM(child);
} else if (XMLString.TEXT_NOTES_CONFIGURATION.equals(childName)) {
properties[nIndex].loadNoteProperties(child);
}
}
child = child.getNextSibling();

View file

@ -117,7 +117,8 @@ public class TextConverter extends ConverterHelper {
private boolean inEndnote = false;
private boolean inHeader = false;
private boolean inFooter = false;
private String currentSection = null;
private String endnotesContext = null;
private String footnotesContext = null;
public TextConverter(OfficeReader ofr, XhtmlConfig config, Converter converter) {
super(ofr,config,converter);
@ -530,16 +531,18 @@ public class TextConverter extends ConverterHelper {
/* 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:
String lastSection = currentSection;
String lastEndnotesContext = endnotesContext;
String lastFootnotesContext = footnotesContext;
String sectionName = Misc.getAttribute(onode,TEXT_NAME);
String last = Misc.getAttribute(onode,"last");
boolean isLast = false;
if (last != null && last.equals("true")) { isLast = true;}
String savedStyle = docSep.getPageContainerStyle();
if (!bDisplayHiddenText && "none".equals(Misc.getAttribute(onode,TEXT_DISPLAY))) { return hnode; }
hnode = docSep.closePage(hnode);
currentSection = sectionName;
setSectionStyle(onode);
hnode = docSep.openPage(hnode, pageNum);
@ -547,7 +550,9 @@ public class TextConverter extends ConverterHelper {
if (isLast) {
insertEndnotes((Element) hnode, sectionName);
}
currentSection = lastSection;
endnotesContext = lastEndnotesContext;
footnotesContext = lastFootnotesContext;
docSep.setPageContainerStyle(savedStyle);
return hnode;
@ -555,8 +560,10 @@ public class TextConverter extends ConverterHelper {
private void setSectionStyle(Node onode) {
StyleWithProperties sectionStyle;
String sStyleName = Misc.getAttribute(onode,TEXT_STYLE_NAME);
OfficeStyle ofStyle = getSectionSc().getStyles().getStyle(sStyleName);
String styleName = Misc.getAttribute(onode,TEXT_STYLE_NAME);
String sectionName = Misc.getAttribute(onode,TEXT_NAME);
OfficeStyle ofStyle = getSectionSc().getStyles().getStyle(styleName);
if (ofStyle != null) {
sectionStyle = (StyleWithProperties) ofStyle;
int colCount = sectionStyle.getColCount();
@ -564,7 +571,16 @@ public class TextConverter extends ConverterHelper {
String styleValue = "column-count: " + colCount + ";";
docSep.setPageContainerStyle(styleValue);
}
String collectEndnotes = sectionStyle.getSectionProperty("endnote", false);
if (collectEndnotes != null && collectEndnotes.equals("true")) {
endnotesContext = sectionName;
}
String collectFootnotes = sectionStyle.getSectionProperty("footnote", false);
if (collectFootnotes != null && collectFootnotes.equals("true")) {
footnotesContext = sectionName;
}
}
}
private void handleHeading(Element onode, Element hnode, boolean bAfterSplit) {
@ -1258,17 +1274,17 @@ public class TextConverter extends ConverterHelper {
handleAnchor(child,hnode);
}
else if (sName.equals(TEXT_FOOTNOTE)) {
footCv.handleNote(child,hnode,currentSection);
footCv.handleNote(child,hnode,footnotesContext);
}
else if (sName.equals(TEXT_ENDNOTE)) {
endCv.handleNote(child,hnode,currentSection);
endCv.handleNote(child,hnode,endnotesContext);
}
else if (sName.equals(TEXT_NOTE)) { // oasis
if ("endnote".equals(Misc.getAttribute(child,TEXT_NOTE_CLASS))) {
endCv.handleNote(child,hnode,currentSection);
endCv.handleNote(child,hnode,endnotesContext);
}
else {
footCv.handleNote(child,hnode,currentSection);
footCv.handleNote(child,hnode,footnotesContext);
}
}
else if (sName.equals(TEXT_SEQUENCE)) {