/************************************************************************
*
* CaptionConverter.java
*
* Copyright: 2002-2008 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
This class converts captions (for figures and tables) to LaTeX.
*Packages: *
Options: *
TODO: Implement formatting of captions using the features of caption.sty * (only if formatting>=CONVERT_BASIC) */ public class CaptionConverter extends ConverterHelper { private boolean bNeedCaptionOf = false; private Element seqField = null; // the sequence field within the current caption public CaptionConverter(OfficeReader ofr, LaTeXConfig config, ConverterPalette palette) { super(ofr,config,palette); } public void appendDeclarations(LaTeXDocumentPortion pack, LaTeXDocumentPortion decl) { if (bNeedCaptionOf) { if (config.useCaption()) { pack.append("\\usepackage{caption}").nl(); } else { // use definition borrowed from capt-of.sty decl.append("% Non-floating captions").nl() .append("\\makeatletter").nl() .append("\\newcommand\\captionof[1]{\\def\\@captype{#1}\\caption}").nl() .append("\\makeatother").nl(); } } } /** *
Process content of a text:p tag as a caption body (inluding label)
* @param node The text:p element node containing the caption * @param ldp TheLaTeXDocumentPortion
to add LaTeX code to
* @param oc The current context
* @param bIsCaptionOf true if this is caption uses captionof
*/
public void handleCaptionBody(Element node,LaTeXDocumentPortion ldp, Context oc, boolean bIsCaptionOf) {
bNeedCaptionOf|=bIsCaptionOf;
// Get rid of the caption label before converting
removeCaptionLabel(node,0);
Element label = seqField;
seqField = null;
// Get the stylename of the paragraph and push the font used
String sStyleName = node.getAttribute(XMLString.TEXT_STYLE_NAME);
palette.getI18n().pushSpecialTable(palette.getCharSc().getFontName(ofr.getParStyle(sStyleName)));
if (palette.getHeadingCv().containsElements(node)) {
ldp.append("[");
palette.getInlineCv().traversePlainInlineText(node,ldp,oc);
ldp.append("]");
}
// Update context before traversing text
Context ic = (Context) oc.clone();
ldp.append("{");
palette.getInlineCv().traverseInlineText(node,ldp,ic);
ldp.append("}").nl();
// Insert label
palette.getFieldCv().handleSequence(label,ldp,oc);
// Flush any index marks
palette.getIndexCv().flushIndexMarks(ldp,oc);
// pop the font name
palette.getI18n().popSpecialTable();
}
// In OpenDocument a caption is an ordinary paragraph with a text:seqence
// element. For example
// Table