/************************************************************************
*
* BlockConverter.java
*
* Copyright: 2002-2015 by Henrik Just
*
* This file is part of Writer2LaTeX.
*
* Writer2LaTeX is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Writer2LaTeX is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Writer2LaTeX. If not, see
Traverse block text (eg. content of body, section, list item). * This is traversed in logical order and dedicated handlers take care of * each block element.
*(Note: As a rule, all handling of block level elements should add a * newline to the LaTeX document at the end of the block)
* @param node The element containing the block text * @param ldp theLaTeXDocumentPortion
to which
* LaTeX code should be added
* @param oc the current context
*/
public void traverseBlockText(Element node, LaTeXDocumentPortion ldp, Context oc) {
Context ic = (Context) oc.clone();
// The current paragraph block:
StyleMap blockMap = config.getParBlockStyleMap();
String sBlockName = null;
if (node.hasChildNodes()) {
NodeList list = node.getChildNodes();
int nLen = list.getLength();
for (int i = 0; i < nLen; i++) {
Node childNode = list.item(i);
if (childNode.getNodeType() == Node.ELEMENT_NODE) {
Element child = (Element)childNode;
String sTagName = child.getTagName();
// Start/End a paragraph block (not in tables)
if (!ic.isInTable()) {
if (sTagName.equals(XMLString.TEXT_P)) {
String sStyleName = ofr.getParStyles().getDisplayName(child.getAttribute(XMLString.TEXT_STYLE_NAME));
if (sBlockName!=null && !blockMap.isNext(sBlockName,sStyleName)) {
// end current block
String sAfter = blockMap.getAfter(sBlockName);
if (sAfter.length()>0) ldp.append(sAfter).nl();
sBlockName = null;
ic.setVerbatim(false);
}
if (sBlockName==null && blockMap.contains(sStyleName)) {
// start a new block
sBlockName = sStyleName;
String sBefore = blockMap.getBefore(sBlockName);
if (sBefore.length()>0) ldp.append(sBefore).nl();
ic.setVerbatim(blockMap.getVerbatim(sStyleName));
}
}
else if (sBlockName!=null) {
// non-paragraph: end current block
String sAfter = blockMap.getAfter(sBlockName);
if (sAfter.length()>0) ldp.append(sAfter).nl();
sBlockName = null;
ic.setVerbatim(false);
}
}
palette.getFieldCv().flushReferenceMarks(ldp,ic);
palette.getIndexCv().flushIndexMarks(ldp,ic);
palette.getInfo().addDebugInfo(child,ldp);
// Basic block content; handle by this class
if (sTagName.equals(XMLString.TEXT_P)) {
// is this a caption?
String sSequence = ofr.getSequenceName(child);
if (ofr.isFigureSequenceName(sSequence)) {
palette.getDrawCv().handleCaption(child,ldp,ic);
}
else if (ofr.isTableSequenceName(sSequence)) {
// Next node *should* be a table
if (i+1