From b12dfddd519014e4a16d8fdccde0e39a1ba1bae1 Mon Sep 17 00:00:00 2001
From: Oliver Bolte
Date: Thu, 13 Jul 2006 08:25:04 +0000
Subject: [PATCH] INTEGRATION: CWS latex (1.1.2); FILE ADDED 2006/04/06
14:10:14 sus 1.1.2.1: #i24813# Adding LaTeX and BibTeX filter
---
.../latex/style/TableFormatter.java | 289 ++++++++++++++++++
1 file changed, 289 insertions(+)
create mode 100644 xmerge/source/writer2latex/source/writer2latex/latex/style/TableFormatter.java
diff --git a/xmerge/source/writer2latex/source/writer2latex/latex/style/TableFormatter.java b/xmerge/source/writer2latex/source/writer2latex/latex/style/TableFormatter.java
new file mode 100644
index 000000000000..7f6494fcf3bb
--- /dev/null
+++ b/xmerge/source/writer2latex/source/writer2latex/latex/style/TableFormatter.java
@@ -0,0 +1,289 @@
+/************************************************************************
+ *
+ * TableFormatter.java
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ * Copyright: 2002-2003 by Henrik Just
+ *
+ * All Rights Reserved.
+ *
+ * Version 0.3.3f (2004-08-26)
+ *
+ */
+
+package writer2latex.latex.style;
+
+import org.w3c.dom.Node;
+
+import writer2latex.util.*;
+import writer2latex.office.*;
+
+/**
+ * This class converts OOo table styles to LaTeX.
+ * In OOo the table style is distributed on table, column and cell styles.
+ *
In LaTeX we have to rearrange this information slightly, so this class
+ * takes care of that.
+ */
+public class TableFormatter {
+
+ private WriterStyleCollection wsc;
+ private boolean bApplyCellFormat;
+ private TableGridModel table;
+ private boolean[][] bHBorder;
+ private boolean[][] bVBorder;
+ private boolean[] bGlobalVBorder;
+ private String[] sColumnWidth;
+ private boolean bIsLongtable;
+ private boolean bIsSubtable;
+
+ /** Constructor: Create from a TableGridModel.
+ */
+ public TableFormatter(WriterStyleCollection wsc, TableGridModel table,
+ boolean bAllowLongtable, boolean bApplyCellFormat) {
+ this.wsc = wsc;
+ this.table = table;
+ this.bApplyCellFormat = bApplyCellFormat;
+ int nRowCount = table.getRowCount();
+ int nColCount = table.getColCount();
+
+ // Step 1: Initialize borders:
+ bHBorder = new boolean[nRowCount+1][nColCount];
+ for (int nRow=0; nRow<=nRowCount; nRow++) {
+ for (int nCol=0; nCol0);
+ }
+ }
+
+ // Step 3: Remove outer borders if this is a subtable
+ bIsSubtable = XMLString.TABLE_SUB_TABLE.equals(table.getTableNode().getNodeName());
+/* if (bIsSubtable) {
+ for (int nRow=0; nRow0;
+ }
+
+ // Step 5: Read column style information
+ sColumnWidth = new String[nColCount];
+ for (int nCol=0; nColCreate table environment based on table style.
+ * Returns eg. "\begin{longtable}{p{2cm}|p{4cm}}", "\end{longtable}".
+ */
+ public void applyTableStyle(BeforeAfter ba) {
+ // Read formatting info from table style
+ // Only supported properties are alignment and may-break-between-rows.
+ String sStyleName = Misc.getAttribute(table.getTableNode(),XMLString.TABLE_STYLE_NAME);
+ StyleWithProperties style = wsc.getTableStyle(sStyleName);
+ char cAlign = 'c';
+ if (style!=null && !bIsSubtable) {
+ String s = style.getProperty(XMLString.TABLE_ALIGN);
+ if ("left".equals(s)) { cAlign='l'; }
+ else if ("right".equals(s)) { cAlign='r'; }
+ }
+
+ // Create table declaration
+ if (bIsLongtable) {
+ ba.add("\\begin{longtable}["+cAlign+"]", "\\end{longtable}");
+ }
+ else if (!bIsSubtable) {
+ String s="center";
+ switch (cAlign) {
+ case 'c': s="center"; break;
+ case 'r': s="flushright"; break;
+ case 'l': s="flushleft";
+ }
+ ba.add("\\begin{"+s+"}\\begin{tabular}","\\end{tabular}\\end{"+s+"}");
+ }
+ else { // subtables should occupy the entire width, including padding!
+ ba.add("\\hspace*{-\\tabcolsep}\\begin{tabular}",
+ "\\end{tabular}\\hspace*{-\\tabcolsep}");
+ }
+
+ // columns
+ ba.add("{","");
+ if (bGlobalVBorder[0]) { ba.add("|",""); }
+ int nColCount = table.getColCount();
+ for (int nCol=0; nColCreate interrow material */
+ public String getInterrowMaterial(int nRow) {
+ int nColCount = table.getColCount();
+ int nCount = 0;
+ for (int nCol=0; nColGet material to put before and after a table cell.
+ * In case of columnspan or different borders this will contain a \multicolumn command.
+ * If bApplyCellFormat is true, there will be a minipage environment
+ */
+ public void applyCellStyle(int nRow, int nCol, BeforeAfter ba) {
+ Node cell = table.getCell(nRow,nCol);
+ int nColSpan = Misc.getPosInteger(Misc.getAttribute(cell,
+ XMLString.TABLE_NUMBER_COLUMNS_SPANNED),1);
+ // Construct column declaration as needed
+ boolean bNeedLeft = (nCol==0) && (bVBorder[nRow][0]!=bGlobalVBorder[0]);
+ boolean bNeedRight = bVBorder[nRow][nCol+1]!=bGlobalVBorder[nCol+1];
+ // calculate column width
+ String sTotalColumnWidth = sColumnWidth[nCol];
+ for (int i=nCol+1; i1) {
+ ba.add("\\multicolumn{"+nColSpan+"}{","");
+ if (nCol==0 && bVBorder[nRow][0]) { ba.add("|",""); }
+ ba.add("p{"+sTotalColumnWidth+"}","");
+ if (bVBorder[nRow][nCol+nColSpan]) { ba.add("|",""); }
+ ba.add("}{","}");
+ }
+
+ if (bApplyCellFormat) {
+ StyleWithProperties style = wsc.getCellStyle(Misc.getAttribute(cell,XMLString.TABLE_STYLE_NAME));
+ String sValign = "c";
+ if (style!=null) {
+ String s = style.getProperty(XMLString.FO_VERTICAL_ALIGN);
+ if ("".equals(s)) { sValign = "b"; } // seems that empty means top??
+ else if ("top".equals(s)) { sValign = "b"; }
+ else if ("bottom".equals(s)) { sValign = "t"; }
+ }
+
+ ba.add("\\begin{minipage}["+sValign+"]{"+sTotalColumnWidth+"}","\\end{minipage}");
+ }
+ }
+}
\ No newline at end of file