1 17 18 19 20 package org.apache.fop.render.rtf; 21 22 import java.awt.Color ; 23 24 import org.apache.fop.apps.FOPException; 25 import org.apache.fop.fo.Constants; 26 import org.apache.fop.fo.flow.Table; 27 import org.apache.fop.fo.flow.TableBody; 28 import org.apache.fop.fo.flow.TableCell; 29 import org.apache.fop.fo.flow.TableHeader; 30 import org.apache.fop.fo.flow.TableRow; 31 import org.apache.fop.fo.properties.CommonBorderPaddingBackground; 32 import org.apache.fop.render.rtf.rtflib.rtfdoc.ITableAttributes; 33 import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfAttributes; 34 35 45 46 49 50 public final class TableAttributesConverter { 51 52 56 59 private TableAttributesConverter() { 60 } 61 62 75 static RtfAttributes convertTableAttributes(Table fobj) 76 throws FOPException { 77 FOPRtfAttributes attrib = new FOPRtfAttributes(); 78 attrib.setTwips(ITableAttributes.ATTR_ROW_LEFT_INDENT, 79 fobj.getCommonMarginBlock().marginLeft); 80 return attrib; 81 } 82 83 93 static RtfAttributes convertTableBodyAttributes(TableBody fobj) 94 throws FOPException { 95 FOPRtfAttributes attrib = new FOPRtfAttributes(); 96 return attrib; 97 } 98 99 107 static RtfAttributes convertCellAttributes(TableCell fobj) 108 throws FOPException { 109 110 113 FOPRtfAttributes attrib = new FOPRtfAttributes(); 114 115 CommonBorderPaddingBackground border = fobj.getCommonBorderPaddingBackground(); 117 118 Color color = border.backgroundColor; 120 if (color == null) { 121 CommonBorderPaddingBackground brd = null; 124 125 if (fobj.getParent() instanceof TableRow) { 126 TableRow parentRow = (TableRow)fobj.getParent(); 127 brd = parentRow.getCommonBorderPaddingBackground(); 128 color = brd.backgroundColor; 129 } else if (fobj.getParent() instanceof TableHeader) { 130 TableHeader parentHeader = (TableHeader)fobj.getParent(); 131 brd = parentHeader.getCommonBorderPaddingBackground(); 132 color = brd.backgroundColor; 133 } 134 135 if (color == null 136 && fobj.getParent() != null 137 && fobj.getParent().getParent() != null 138 && fobj.getParent().getParent().getParent() instanceof Table) { 139 140 Table table = (Table)fobj.getParent().getParent().getParent(); 141 brd = table.getCommonBorderPaddingBackground(); 142 color = brd.backgroundColor; 143 } 144 145 146 } 147 if ((color != null) 148 && (color.getAlpha() != 0 149 || color.getRed() != 0 150 || color.getGreen() != 0 151 || color.getBlue() != 0)) { 152 attrib.set(ITableAttributes.CELL_COLOR_BACKGROUND, color); 153 } 154 155 BorderAttributesConverter.makeBorder(border, CommonBorderPaddingBackground.BEFORE, 156 attrib, ITableAttributes.CELL_BORDER_TOP); 157 BorderAttributesConverter.makeBorder(border, CommonBorderPaddingBackground.AFTER, 158 attrib, ITableAttributes.CELL_BORDER_BOTTOM); 159 BorderAttributesConverter.makeBorder(border, CommonBorderPaddingBackground.START, 160 attrib, ITableAttributes.CELL_BORDER_LEFT); 161 BorderAttributesConverter.makeBorder(border, CommonBorderPaddingBackground.END, 162 attrib, ITableAttributes.CELL_BORDER_RIGHT); 163 164 int padding; 165 boolean reproduceMSWordBug = true; 166 if (reproduceMSWordBug) { 168 padding = border.getPaddingStart(false, null); if (padding != 0) { 171 attrib.setTwips(ITableAttributes.ATTR_CELL_PADDING_TOP, padding); 172 attrib.set(ITableAttributes.ATTR_CELL_U_PADDING_TOP, 3 ); 173 } 174 padding = border.getPaddingBefore(false, null); if (padding != 0) { 176 attrib.setTwips(ITableAttributes.ATTR_CELL_PADDING_LEFT, padding); 177 attrib.set(ITableAttributes.ATTR_CELL_U_PADDING_LEFT, 3 ); 178 } 179 } else { 180 padding = border.getPaddingStart(false, null); if (padding != 0) { 182 attrib.setTwips(ITableAttributes.ATTR_CELL_PADDING_LEFT, padding); 183 attrib.set(ITableAttributes.ATTR_CELL_U_PADDING_LEFT, 3 ); 184 } 185 padding = border.getPaddingBefore(false, null); if (padding != 0) { 187 attrib.setTwips(ITableAttributes.ATTR_CELL_PADDING_TOP, padding); 188 attrib.set(ITableAttributes.ATTR_CELL_U_PADDING_TOP, 3 ); 189 } 190 } 191 padding = border.getPaddingEnd(false, null); if (padding != 0) { 193 attrib.setTwips(ITableAttributes.ATTR_CELL_PADDING_RIGHT, padding); 194 attrib.set(ITableAttributes.ATTR_CELL_U_PADDING_RIGHT, 3 ); 195 } 196 padding = border.getPaddingAfter(false, null); if (padding != 0) { 198 attrib.setTwips(ITableAttributes.ATTR_CELL_PADDING_BOTTOM, padding); 199 attrib.set(ITableAttributes.ATTR_CELL_U_PADDING_BOTTOM, 3 ); 200 } 201 202 int n = fobj.getNumberColumnsSpanned(); 203 if (n > 1) { 205 attrib.set(ITableAttributes.COLUMN_SPAN, n); 206 } 207 208 return attrib; 209 } 210 211 212 221 static RtfAttributes convertRowAttributes(TableRow fobj, 222 RtfAttributes rtfatts) 223 throws FOPException { 224 225 228 RtfAttributes attrib = null; 229 230 if (rtfatts == null) { 231 attrib = new RtfAttributes(); 232 } else { 233 attrib = rtfatts; 234 } 235 236 240 242 if (fobj.getKeepTogether().getWithinPage().getEnum() == Constants.EN_ALWAYS) { 243 attrib.set(ITableAttributes.ROW_KEEP_TOGETHER); 244 } 245 246 if (fobj.getKeepWithNext().getWithinPage().getEnum() == Constants.EN_ALWAYS) { 248 attrib.set(ITableAttributes.ROW_KEEP_WITH_NEXT); 249 } 250 251 if (fobj.getKeepWithPrevious().getWithinPage().getEnum() == Constants.EN_ALWAYS) { 253 attrib.set(ITableAttributes.ROW_KEEP_WITH_PREVIOUS); 254 } 255 256 if (fobj.getHeight().getEnum() != Constants.EN_AUTO) { 258 attrib.set(ITableAttributes.ROW_HEIGHT, fobj.getHeight().getValue() / (1000 / 20)); 259 } 260 261 274 CommonBorderPaddingBackground border = fobj.getCommonBorderPaddingBackground(); 275 BorderAttributesConverter.makeBorder(border, CommonBorderPaddingBackground.BEFORE, 276 attrib, ITableAttributes.CELL_BORDER_TOP); 277 BorderAttributesConverter.makeBorder(border, CommonBorderPaddingBackground.AFTER, 278 attrib, ITableAttributes.CELL_BORDER_BOTTOM); 279 BorderAttributesConverter.makeBorder(border, CommonBorderPaddingBackground.START, 280 attrib, ITableAttributes.CELL_BORDER_LEFT); 281 BorderAttributesConverter.makeBorder(border, CommonBorderPaddingBackground.END, 282 attrib, ITableAttributes.CELL_BORDER_RIGHT); 283 284 344 return attrib; 345 } 346 347 } 348 | Popular Tags |