Fix for page content column count option

This commit is contained in:
Georgy Litvinov 2020-01-30 18:59:08 +01:00
parent b2c79c0138
commit 0926dbe218
3 changed files with 164 additions and 148 deletions

View file

@ -40,7 +40,7 @@ import writer2latex.util.Misc;
public class XhtmlConfig extends writer2latex.base.ConfigBase { public class XhtmlConfig extends writer2latex.base.ConfigBase {
// Implement configuration methods // Implement configuration methods
protected int getOptionCount() { return 63; } protected int getOptionCount() { return 64; }
protected String getDefaultConfigPath() { return "/writer2latex/xhtml/config/"; } protected String getDefaultConfigPath() { return "/writer2latex/xhtml/config/"; }
// Override setOption: To be backwards compatible, we must accept options // Override setOption: To be backwards compatible, we must accept options
@ -162,6 +162,7 @@ public class XhtmlConfig extends writer2latex.base.ConfigBase {
private static final int PAGE_TAGS = 60; private static final int PAGE_TAGS = 60;
private static final int MIN_LETTER_SPACING = 61; private static final int MIN_LETTER_SPACING = 61;
private static final int PAGE_BREAK_STYLE = 62; private static final int PAGE_BREAK_STYLE = 62;
private static final int CSS_INLINE = 63;
protected ComplexOption xheading = addComplexOption("heading-map"); protected ComplexOption xheading = addComplexOption("heading-map");
protected ComplexOption xpar = addComplexOption("paragraph-map"); protected ComplexOption xpar = addComplexOption("paragraph-map");
@ -299,6 +300,8 @@ public class XhtmlConfig extends writer2latex.base.ConfigBase {
options[PAGE_TAGS] = new Option("page_tags","div"); options[PAGE_TAGS] = new Option("page_tags","div");
options[MIN_LETTER_SPACING] = new Option("min_letter_spacing","0.15"); options[MIN_LETTER_SPACING] = new Option("min_letter_spacing","0.15");
options[PAGE_BREAK_STYLE] = new Option("page_break_style",""); options[PAGE_BREAK_STYLE] = new Option("page_break_style","");
options[CSS_INLINE] = new BooleanOption("css_inline","true");
} }
@ -457,6 +460,8 @@ public class XhtmlConfig extends writer2latex.base.ConfigBase {
public XhtmlStyleMap getXFrameStyleMap() { return getStyleMap(xframe); } public XhtmlStyleMap getXFrameStyleMap() { return getStyleMap(xframe); }
public XhtmlStyleMap getXListStyleMap() { return getStyleMap(xlist); } public XhtmlStyleMap getXListStyleMap() { return getStyleMap(xlist); }
public XhtmlStyleMap getXAttrStyleMap() { return getStyleMap(xattr); } public XhtmlStyleMap getXAttrStyleMap() { return getStyleMap(xattr); }
public boolean inlineCSS() { return ((BooleanOption) options[CSS_INLINE]).getValue(); }
private XhtmlStyleMap getStyleMap(ComplexOption co) { private XhtmlStyleMap getStyleMap(ComplexOption co) {
XhtmlStyleMap map = new XhtmlStyleMap(); XhtmlStyleMap map = new XhtmlStyleMap();

View file

@ -105,7 +105,7 @@ public class TextParser extends Parser {
private boolean bInToc = false; private boolean bInToc = false;
// Display hidden text? // Display hidden text?
private boolean bDisplayHiddenText = false; private boolean displayHiddenText = false;
// Current page number // Current page number
int pageNum = 1; int pageNum = 1;
//Current master page name //Current master page name
@ -124,6 +124,7 @@ public class TextParser extends Parser {
private boolean inFooter = false; private boolean inFooter = false;
private String endnotesContext = null; private String endnotesContext = null;
private String footnotesContext = null; private String footnotesContext = null;
private boolean inlineCSS;
PageContainer pageContainer = null; PageContainer pageContainer = null;
public TextParser(OfficeReader ofr, XhtmlConfig config, Converter converter) { public TextParser(OfficeReader ofr, XhtmlConfig config, Converter converter) {
@ -142,9 +143,10 @@ public class TextParser extends Parser {
nFloatMode = ofr.isText() && config.xhtmlFloatObjects() ? nFloatMode = ofr.isText() && config.xhtmlFloatObjects() ?
DrawParser.FLOATING : DrawParser.ABSOLUTE; DrawParser.FLOATING : DrawParser.ABSOLUTE;
outlineNumbering = new ListCounter(ofr.getOutlineStyle()); outlineNumbering = new ListCounter(ofr.getOutlineStyle());
bDisplayHiddenText = config.displayHiddenText(); displayHiddenText = config.displayHiddenText();
pageContainer = converter.pageContainer; pageContainer = converter.pageContainer;
docSep = new Separator(config, converter); docSep = new Separator(config, converter);
inlineCSS = config.inlineCSS();
} }
/** Converts an office node as a complete text document /** Converts an office node as a complete text document
@ -541,7 +543,7 @@ public class TextParser extends Parser {
boolean isLast = false; boolean isLast = false;
if (last != null && last.equals("true")) { isLast = true;} if (last != null && last.equals("true")) { isLast = true;}
if (!bDisplayHiddenText && "none".equals(Misc.getAttribute(onode,TEXT_DISPLAY))) { return hnode; } if (!displayHiddenText && "none".equals(Misc.getAttribute(onode,TEXT_DISPLAY))) { return hnode; }
if (pageWasOpened) {hnode = docSep.closePage(hnode);} if (pageWasOpened) {hnode = docSep.closePage(hnode);}
boolean removeStyleAtExit = setSectionStyle(onode); boolean removeStyleAtExit = setSectionStyle(onode);
@ -600,134 +602,138 @@ public class TextParser extends Parser {
/* /*
* Process a text:h tag * Process a text:h tag
*/ */
private void handleHeading(Element onode, Element hnode, boolean bAfterSplit, private void handleHeading(Element onode, Element hnode, boolean bAfterSplit, ListStyle listStyle, int nListLevel, boolean bUnNumbered, boolean bRestart, int nStartValue) {
ListStyle listStyle, int nListLevel, boolean bUnNumbered,
boolean bRestart, int nStartValue) {
// Note: nListLevel may in theory be different from the outline level, // Note: nListLevel may in theory be different from the outline level,
// though the ui in OOo does not allow this // though the ui in OOo does not allow this
// Numbering: It is possible to define outline numbering in CSS2 // Numbering: It is possible to define outline numbering in CSS2
// using counters; but this is not supported in all browsers // using counters; but this is not supported in all browsers
// TODO: Offer CSS2 solution as an alternative later. // TODO: Offer CSS2 solution as an alternative later.
// Note: Conditional styles are not supported // Note: Conditional styles are not supported
int nLevel = getOutlineLevel(onode); int nLevel = getOutlineLevel(onode);
if (nLevel<=6) { // Export as heading if (nLevel <= 6) { // Export as heading
String sStyleName = onode.getAttribute(TEXT_STYLE_NAME); String sStyleName = onode.getAttribute(TEXT_STYLE_NAME);
StyleWithProperties style = ofr.getParStyle(sStyleName); StyleWithProperties style = ofr.getParStyle(sStyleName);
// Check for hidden text // Check for hidden text
if (!bDisplayHiddenText && style!=null && "none".equals(style.getProperty(TEXT_DISPLAY))) { return; } if (!displayHiddenText && style != null && "none".equals(style.getProperty(TEXT_DISPLAY))) {
return;
}
// Numbering // Numbering
if (!bUnNumbered) { if (!bUnNumbered) {
// If the heading uses a paragraph style which sets an explicit empty list style name, it's unnumbered // If the heading uses a paragraph style which sets an explicit empty
if (style!=null) { // list style name, it's unnumbered
String sListStyleName = style.getListStyleName(); if (style != null) {
if (sListStyleName!=null && sListStyleName.length()==0) { String sListStyleName = style.getListStyleName();
bUnNumbered = true; if (sListStyleName != null && sListStyleName.length() == 0) {
} bUnNumbered = true;
} }
} }
ListCounter counter = null; }
String sLabel=""; ListCounter counter = null;
if (!bUnNumbered) { String sLabel = "";
counter = getListCounter(listStyle); if (!bUnNumbered) {
if (bRestart) { counter.restart(nListLevel,nStartValue); } counter = getListCounter(listStyle);
sLabel = counter.step(nListLevel).getLabel(); if (bRestart) {
} counter.restart(nListLevel, nStartValue);
}
sLabel = counter.step(nListLevel).getLabel();
}
// In EPUB export, a striked out heading will only appear in the external toc // In EPUB export, a striked out heading will only appear in the external
boolean bTocOnly = false; // toc
if (converter.isOPS() && style!=null) { boolean bTocOnly = false;
String sStrikeOut = style.getProperty(STYLE_TEXT_LINE_THROUGH_STYLE, true); if (converter.isOPS() && style != null) {
if (sStrikeOut!=null && !"none".equals(sStrikeOut)) { String sStrikeOut = style.getProperty(STYLE_TEXT_LINE_THROUGH_STYLE, true);
bTocOnly = true; if (sStrikeOut != null && !"none".equals(sStrikeOut)) {
} bTocOnly = true;
} }
}
// Export the heading // Export the heading
if (!bTocOnly) { if (!bTocOnly) {
// If split output, add headings of higher levels // If split output, add headings of higher levels
if (bAfterSplit && nSplit>0) { if (bAfterSplit && nSplit > 0) {
int nFirst = nLevel-nRepeatLevels; int nFirst = nLevel - nRepeatLevels;
if (nFirst<0) { nFirst=0; } if (nFirst < 0) {
for (int i=nFirst; i<nLevel; i++) { nFirst = 0;
if (currentHeading[i]!=null) { }
hnode.appendChild(converter.importNode(currentHeading[i],true)); for (int i = nFirst; i < nLevel; i++) {
} if (currentHeading[i] != null) {
} hnode.appendChild(converter.importNode(currentHeading[i], true));
} }
}
}
// Apply style // Apply style
StyleInfo info = new StyleInfo(); StyleInfo info = new StyleInfo();
info.sTagName = "h"+nLevel; info.sTagName = "h" + nLevel;
getHeadingSc().applyStyle(nLevel, sStyleName, info); getHeadingSc().applyStyle(nLevel, sStyleName, info);
// add root element // add root element
Element heading = converter.createElement(info.sTagName); Element heading = converter.createElement(info.sTagName);
hnode.appendChild(heading); hnode.appendChild(heading);
applyStyle(info,heading); applyStyle(info, heading);
traverseFloats(onode,hnode,heading); traverseFloats(onode, hnode, heading);
// Apply writing direction // Apply writing direction
/*String sStyleName = Misc.getAttribute(onode,TEXT_STYLE_NAME); /*
StyleWithProperties style = ofr.getParStyle(sStyleName); * String sStyleName = Misc.getAttribute(onode,TEXT_STYLE_NAME);
if (style!=null) { * StyleWithProperties style = ofr.getParStyle(sStyleName); if
StyleInfo headInfo = new StyleInfo(); * (style!=null) { StyleInfo headInfo = new StyleInfo();
StyleConverterHelper.applyDirection(style,headInfo); * StyleConverterHelper.applyDirection(style,headInfo);
getParSc().applyStyle(headInfo,heading); * getParSc().applyStyle(headInfo,heading); }
}*/ */
// Prepend asapNode // Prepend asapNode
prependAsapNode(heading); prependAsapNode(heading);
// Prepend numbering // Prepend numbering
if (!bUnNumbered) { if (!bUnNumbered) {
insertListLabel(listStyle,nListLevel,"SectionNumber",null,sLabel,heading); insertListLabel(listStyle, nListLevel, "SectionNumber", null, sLabel, heading);
} }
// Add to toc // Add to toc
if (!bInToc) { if (!bInToc) {
tocCv.handleHeading(onode,heading,sLabel); tocCv.handleHeading(onode, heading, sLabel);
} }
// Convert content // Convert content
StyleInfo innerInfo = new StyleInfo(); StyleInfo innerInfo = new StyleInfo();
getHeadingSc().applyInnerStyle(nLevel, sStyleName, innerInfo); getHeadingSc().applyInnerStyle(nLevel, sStyleName, innerInfo);
Element content = heading; Element content = heading;
if (innerInfo.sTagName!=null && innerInfo.sTagName.length()>0) { if (innerInfo.sTagName != null && innerInfo.sTagName.length() > 0) {
content = converter.createElement(innerInfo.sTagName); content = converter.createElement(innerInfo.sTagName);
heading.appendChild(content); heading.appendChild(content);
applyStyle(innerInfo, content); applyStyle(innerInfo, content);
} }
traverseInlineText(onode,content); traverseInlineText(onode, content);
// Add before/after text if required // Add before/after text if required
addBeforeAfter(heading,ofr.getParStyle(getParSc().getRealParStyleName(sStyleName)),config.getXHeadingStyleMap()); addBeforeAfter(heading, ofr.getParStyle(getParSc().getRealParStyleName(sStyleName)), config.getXHeadingStyleMap());
// Keep track of current headings for split output // Keep track of current headings for split output
currentHeading[nLevel] = heading; currentHeading[nLevel] = heading;
for (int i=nLevel+1; i<=6; i++) { for (int i = nLevel + 1; i <= 6; i++) {
currentHeading[i] = null; currentHeading[i] = null;
} }
} } else {
else { if (!bInToc) {
if (!bInToc) { tocCv.handleHeadingExternal(onode, hnode, sLabel);
tocCv.handleHeadingExternal(onode, hnode, sLabel); }
} // Keep track of current headings for split output
// Keep track of current headings for split output currentHeading[nLevel] = null;
currentHeading[nLevel] = null; for (int i = nLevel + 1; i <= 6; i++) {
for (int i=nLevel+1; i<=6; i++) { currentHeading[i] = null;
currentHeading[i] = null; }
}
} }
} } else { // beyond h6 - export as ordinary paragraph
else { // beyond h6 - export as ordinary paragraph handleParagraph(onode, hnode);
handleParagraph(onode,hnode); }
} }
}
/* /*
* Process a text:p tag * Process a text:p tag
@ -737,7 +743,7 @@ public class TextParser extends Parser {
if (config.ignoreEmptyParagraphs() && bIsEmpty) { return; } if (config.ignoreEmptyParagraphs() && bIsEmpty) { return; }
String styleName = Misc.getAttribute(onode,TEXT_STYLE_NAME); String styleName = Misc.getAttribute(onode,TEXT_STYLE_NAME);
StyleWithProperties style = ofr.getParStyle(styleName); StyleWithProperties style = ofr.getParStyle(styleName);
if (!bDisplayHiddenText && style!=null && "none".equals(style.getProperty(TEXT_DISPLAY))) { return; } if (!displayHiddenText && style!=null && "none".equals(style.getProperty(TEXT_DISPLAY))) { return; }
Element par; Element par;
if (ofr.isSpreadsheet()) { // attach inline text directly to parent (always a table cell) if (ofr.isSpreadsheet()) { // attach inline text directly to parent (always a table cell)
@ -1378,19 +1384,20 @@ public class TextParser extends Parser {
} }
} }
private void handleSpan(Node onode, Node hnode) { private void handleSpan(Node onode, Node hnode) {
StyleWithProperties style = ofr.getTextStyle(Misc.getAttribute(onode, TEXT_STYLE_NAME)); StyleWithProperties style = ofr.getTextStyle(Misc.getAttribute(onode, TEXT_STYLE_NAME));
if (!bDisplayHiddenText && style!=null && "none".equals(style.getProperty(TEXT_DISPLAY))) { return; } if (!displayHiddenText && style != null && "none".equals(style.getProperty(TEXT_DISPLAY))) {
return;
}
if (!bInToc) { if (!bInToc) {
String sStyleName = Misc.getAttribute(onode,TEXT_STYLE_NAME); String sStyleName = Misc.getAttribute(onode, TEXT_STYLE_NAME);
Element span = createInline((Element) hnode,sStyleName); Element span = createInline((Element) hnode, sStyleName);
traverseInlineText(onode,span); traverseInlineText(onode, span);
} } else {
else { traverseInlineText(onode, hnode);
traverseInlineText(onode,hnode); }
} }
}
protected void traversePCDATA(Node onode, Node hnode) { protected void traversePCDATA(Node onode, Node hnode) {
if (onode.hasChildNodes()) { if (onode.hasChildNodes()) {
@ -1814,8 +1821,10 @@ public class TextParser extends Parser {
private void setPageContainerStyle() { private void setPageContainerStyle() {
MasterPage mp = ofr.getFullMasterPage(currentMasterPage); MasterPage mp = ofr.getFullMasterPage(currentMasterPage);
PageLayout layout = ofr.getPageLayout(mp.getPageLayoutName()); PageLayout layout = ofr.getPageLayout(mp.getPageLayoutName());
String containerStyle = "column-count: " + layout.getColCount() + ";"; if (layout.getColCount() != 1) {
pageContainer.setRootStyle(containerStyle); String containerStyle = "column-count: " + layout.getColCount() + ";";
pageContainer.setRootStyle(containerStyle);
}
} }
private void fitPageNumberToMasterPageStyle() { private void fitPageNumberToMasterPageStyle() {

View file

@ -61,6 +61,7 @@ public abstract class StyleParser extends Parser {
private String sScale; private String sScale;
private String sColScale; private String sColScale;
private boolean bConvertToPx; private boolean bConvertToPx;
private boolean inlineCSS;
/** Create a new <code>StyleConverterHelper</code> /** Create a new <code>StyleConverterHelper</code>
* @param ofr an <code>OfficeReader</code> to read style information from * @param ofr an <code>OfficeReader</code> to read style information from
@ -76,6 +77,7 @@ public abstract class StyleParser extends Parser {
sScale = config.getXhtmlScaling(); sScale = config.getXhtmlScaling();
sColScale = config.getXhtmlColumnScaling(); sColScale = config.getXhtmlColumnScaling();
bConvertToPx = config.xhtmlConvertToPx(); bConvertToPx = config.xhtmlConvertToPx();
inlineCSS = config.inlineCSS();
} }
public String scale(String s) { public String scale(String s) {