From: <pen...@pe...> - 2011-05-30 10:24:40
|
Author: tmorgner Date: 2011-05-30 06:24:33 -0400 (Mon, 30 May 2011) New Revision: 14010 Modified: engines/classic/branches/3.8/core/source/org/pentaho/reporting/engine/classic/core/modules/output/table/html/HtmlPrinter.java engines/classic/branches/3.8/core/source/org/pentaho/reporting/engine/classic/core/modules/output/table/html/HtmlTableModule.java engines/classic/branches/3.8/core/source/org/pentaho/reporting/engine/classic/core/modules/output/table/html/HtmlTextExtractor.java engines/classic/branches/3.8/core/source/org/pentaho/reporting/engine/classic/core/modules/output/table/html/configuration.properties Log: PRD-3453: Fixing the table layout to make IE happy. Modified: engines/classic/branches/3.8/core/source/org/pentaho/reporting/engine/classic/core/modules/output/table/html/HtmlPrinter.java =================================================================== --- engines/classic/branches/3.8/core/source/org/pentaho/reporting/engine/classic/core/modules/output/table/html/HtmlPrinter.java 2011-05-30 10:12:19 UTC (rev 14009) +++ engines/classic/branches/3.8/core/source/org/pentaho/reporting/engine/classic/core/modules/output/table/html/HtmlPrinter.java 2011-05-30 10:24:33 UTC (rev 14010) @@ -76,7 +76,6 @@ import org.pentaho.reporting.libraries.base.encoder.UnsupportedEncoderException; import org.pentaho.reporting.libraries.base.util.IOUtils; import org.pentaho.reporting.libraries.base.util.ObjectUtilities; -import org.pentaho.reporting.libraries.base.util.StackableRuntimeException; import org.pentaho.reporting.libraries.base.util.StringUtils; import org.pentaho.reporting.libraries.fonts.encoding.EncodingRegistry; import org.pentaho.reporting.libraries.repository.ContentCreationException; @@ -175,9 +174,9 @@ private NameGenerator dataNameGenerator; private ResourceManager resourceManager; - private HashMap knownResources; - private HashMap knownImages; - private HashSet validRawTypes; + private HashMap<ResourceKey, String> knownResources; + private HashMap<String, String> knownImages; + private HashSet<String> validRawTypes; private URLRewriter urlRewriter; private ContentItem documentContentItem; @@ -195,7 +194,7 @@ private HtmlTextExtractor textExtractor; private CellBackgroundProducer cellBackgroundProducer; private boolean safariLengthFix; - private boolean first; + private boolean useWhitespacePreWrap; protected HtmlPrinter(final ResourceManager resourceManager) { @@ -205,11 +204,11 @@ } this.resourceManager = resourceManager; - this.knownResources = new HashMap(); - this.knownImages = new HashMap(); + this.knownResources = new HashMap<ResourceKey, String>(); + this.knownImages = new HashMap<String, String>(); this.styleBuilder = new StyleBuilder(); - this.validRawTypes = new HashSet(); + this.validRawTypes = new HashSet<String>(); this.validRawTypes.add("image/gif"); this.validRawTypes.add("image/x-xbitmap"); this.validRawTypes.add("image/gi_"); @@ -236,6 +235,8 @@ safariLengthFix = ("true".equals(ClassicEngineBoot.getInstance().getGlobalConfig().getConfigProperty ("org.pentaho.reporting.engine.classic.core.modules.output.table.html.SafariLengthHack"))); + useWhitespacePreWrap = ("true".equals(ClassicEngineBoot.getInstance().getGlobalConfig().getConfigProperty + ("org.pentaho.reporting.engine.classic.core.modules.output.table.html.UseWhitespacePreWrap"))); } protected boolean isAllowRawLinkTargets() @@ -305,12 +306,6 @@ this.dataLocation = dataLocation; } - /** - * Can be set to null, but trying to use such a object will result in errors. - * - * @param contentLocation - * @param contentNameGenerator - */ public void setContentWriter(final ContentLocation contentLocation, final NameGenerator contentNameGenerator) { @@ -423,7 +418,7 @@ catch (URLRewriteException e) { HtmlPrinter.logger.warn("Rewriting the URL failed.", e); - throw new StackableRuntimeException("Failed", e); + throw new RuntimeException("Failed", e); } return null; } @@ -582,7 +577,7 @@ { final URLImageContainer uic = (URLImageContainer) image; cacheKey = uic.getSourceURLString(); - final String retval = (String) knownImages.get(cacheKey); + final String retval = knownImages.get(cacheKey); if (retval != null) { return retval; @@ -769,6 +764,11 @@ return "true".equals(getConfiguration().getConfigProperty(HtmlTableModule.EMPTY_CELLS_USE_CSS, "false")); } + private boolean isUseTableLayoutFixed() + { + return "true".equals(getConfiguration().getConfigProperty(HtmlTableModule.USE_TABLE_LAYOUT_FIXED, "true")); + } + private boolean isTableRowBorderDefinition() { return "true".equals(getConfiguration().getConfigProperty(HtmlTableModule.TABLE_ROW_BORDER_DEFINITION, "false")); @@ -793,7 +793,7 @@ } else { - styleBuilder = HtmlPrinter.produceTextStyle(styleBuilder, content, true, false, safariLengthFix); + styleBuilder = HtmlPrinter.produceTextStyle(styleBuilder, content, true, false, safariLengthFix, useWhitespacePreWrap); } // Add the extra styles @@ -1051,6 +1051,10 @@ { styleBuilder.append("empty-cells", "show"); } + if (isUseTableLayoutFixed()) + { + styleBuilder.append("table-layout", "fixed"); + } final String additionalStyleClass = getConfiguration().getConfigProperty( @@ -1177,24 +1181,57 @@ final int colCount = sheetLayout.getColumnCount(); final int fullWidth = (int) StrictGeomUtility.toExternalValue(sheetLayout.getMaxWidth()); + final String[] colWidths = new String[colCount]; final boolean proportionalColumnWidths = isProportionalColumnWidths(); + final NumberFormat pointConverter = styleBuilder.getPointConverter(); + final String unit; - final NumberFormat pointConverter = styleBuilder.getPointConverter(); - for (int col = 0; col < colCount; col++) + if (proportionalColumnWidths) { - // Print the table. - final int width = (int) StrictGeomUtility.toExternalValue(sheetLayout.getCellWidth(col, col + 1)); - styleBuilder.clear(); - if (proportionalColumnWidths) + unit = "%"; + + double totalWidth = 0; + for (int col = 0; col < colCount; col++) { - final double colWidth = width * 100.0d / fullWidth; - styleBuilder.append("width", pointConverter.format(fixLengthForSafari(colWidth)), "%"); + final int width = (int) StrictGeomUtility.toExternalValue(sheetLayout.getCellWidth(col, col + 1)); + final double colWidth = fixLengthForSafari(Math.max(1, width * 100.0d / fullWidth)); + if (col == colCount - 1) + { + colWidths[col] = pointConverter.format(100 - totalWidth); + } + else + { + totalWidth += colWidth; + colWidths[col] = pointConverter.format(colWidth); + } } - else + } + else + { + unit = "pt"; + + double totalWidth = 0; + for (int col = 0; col < colCount; col++) { - styleBuilder.append("width", pointConverter.format(fixLengthForSafari(width)), "pt"); + final int width = (int) StrictGeomUtility.toExternalValue(sheetLayout.getCellWidth(col, col + 1)); + final double colWidth = fixLengthForSafari(Math.max(1, width)); + if (col == colCount - 1) + { + colWidths[col] = pointConverter.format(fullWidth - totalWidth); + } + else + { + totalWidth += colWidth; + colWidths[col] = pointConverter.format(colWidth); + } } + } + for (int col = 0; col < colCount; col++) + { + // Print the table. + styleBuilder.clear(); + styleBuilder.append("width", colWidths[col], unit); xmlWriter.writeTag(null, "col", "style", styleBuilder.toString(), XmlWriterSupport.CLOSE); } } @@ -1737,7 +1774,8 @@ final RenderBox box, final boolean includeBorder, final boolean includeWhitespaceCollapse, - final boolean fixLength) + final boolean fixLength, + final boolean useWhitespacePreWrap) { if (box == null) { @@ -1870,7 +1908,16 @@ styleSheet.getStyleProperty(TextStyleKeys.WHITE_SPACE_COLLAPSE); if (WhitespaceCollapse.PRESERVE.equals(wsCollapse)) { - styleBuilder.append("white-space", "pre"); + if (useWhitespacePreWrap) + { + // this style does not work for IE6 and IE7, but heck, in that case they just behave as if normal mode is + // selected. In that case multiple spaces are collapsed into a single space. + styleBuilder.append("white-space", "pre-wrap"); + } + else + { + styleBuilder.append("white-space", "pre"); + } } else if (WhitespaceCollapse.PRESERVE_BREAKS.equals(wsCollapse)) { @@ -1932,7 +1979,7 @@ public void registerFailure(final ResourceKey source) { - knownResources.put(source, Boolean.FALSE); + knownResources.put(source, null); } public void registerContent(final ResourceKey source, final String name) Modified: engines/classic/branches/3.8/core/source/org/pentaho/reporting/engine/classic/core/modules/output/table/html/HtmlTableModule.java =================================================================== --- engines/classic/branches/3.8/core/source/org/pentaho/reporting/engine/classic/core/modules/output/table/html/HtmlTableModule.java 2011-05-30 10:12:19 UTC (rev 14009) +++ engines/classic/branches/3.8/core/source/org/pentaho/reporting/engine/classic/core/modules/output/table/html/HtmlTableModule.java 2011-05-30 10:24:33 UTC (rev 14010) @@ -30,6 +30,7 @@ */ public class HtmlTableModule extends AbstractModule { + public static final String USE_TABLE_LAYOUT_FIXED = "org.pentaho.reporting.engine.classic.core.modules.output.table.html.UseTableLayoutFixed"; /** * the fileencoding for the main html file. */ Modified: engines/classic/branches/3.8/core/source/org/pentaho/reporting/engine/classic/core/modules/output/table/html/HtmlTextExtractor.java =================================================================== --- engines/classic/branches/3.8/core/source/org/pentaho/reporting/engine/classic/core/modules/output/table/html/HtmlTextExtractor.java 2011-05-30 10:12:19 UTC (rev 14009) +++ engines/classic/branches/3.8/core/source/org/pentaho/reporting/engine/classic/core/modules/output/table/html/HtmlTextExtractor.java 2011-05-30 10:24:33 UTC (rev 14010) @@ -51,7 +51,6 @@ import org.pentaho.reporting.engine.classic.core.util.geom.StrictBounds; import org.pentaho.reporting.engine.classic.core.util.geom.StrictGeomUtility; import org.pentaho.reporting.libraries.base.util.FastStack; -import org.pentaho.reporting.libraries.base.util.StackableRuntimeException; import org.pentaho.reporting.libraries.base.util.StringUtils; import org.pentaho.reporting.libraries.repository.ContentIOException; import org.pentaho.reporting.libraries.resourceloader.ResourceKey; @@ -91,16 +90,6 @@ } } - private FastStack processStack; - private OutputProcessorMetaData metaData; - private XmlWriter xmlWriter; - private StyleManager styleManager; - private StyleBuilder styleBuilder; - private HtmlContentGenerator contentGenerator; - private CharacterEntityParser characterEntityParser; - private boolean result; - private boolean safariLengthFix; - private RenderBox firstElement; private static final String DIV_TAG = "div"; private static final String HREF_ATTR = "href"; private static final String TARGET_ATTR = "target"; @@ -116,6 +105,18 @@ private static final String HEIGHT_STYLE = "height"; private static final String ALT_ATTR = "alt"; + private FastStack processStack; + private OutputProcessorMetaData metaData; + private XmlWriter xmlWriter; + private StyleManager styleManager; + private StyleBuilder styleBuilder; + private HtmlContentGenerator contentGenerator; + private CharacterEntityParser characterEntityParser; + private boolean result; + private boolean safariLengthFix; + private RenderBox firstElement; + private boolean useWhitespacePreWrap; + public HtmlTextExtractor(final OutputProcessorMetaData metaData, final XmlWriter xmlWriter, final StyleManager styleManager, @@ -144,6 +145,8 @@ this.characterEntityParser = HtmlCharacterEntities.getEntityParser(); this.safariLengthFix = ("true".equals(ClassicEngineBoot.getInstance().getGlobalConfig().getConfigProperty ("org.pentaho.reporting.engine.classic.core.modules.output.table.html.SafariLengthHack"))); + this.useWhitespacePreWrap = ("true".equals(ClassicEngineBoot.getInstance().getGlobalConfig().getConfigProperty + ("org.pentaho.reporting.engine.classic.core.modules.output.table.html.UseWhitespacePreWrap"))); } public boolean performOutput(final RenderBox content, final boolean ignoreFirstElement) throws IOException @@ -344,7 +347,8 @@ linkAttr.setAttribute(HtmlPrinter.XHTML_NAMESPACE, TITLE_ATTR, title); } - styleManager.updateStyle(HtmlPrinter.produceTextStyle(styleBuilder, box, false, false, safariLengthFix), + styleManager.updateStyle(HtmlPrinter.produceTextStyle + (styleBuilder, box, false, false, safariLengthFix, useWhitespacePreWrap), linkAttr); xmlWriter.writeTag(HtmlPrinter.XHTML_NAMESPACE, A_TAG, linkAttr, XmlWriterSupport.OPEN); } @@ -413,7 +417,8 @@ if (firstElement != box) { HtmlPrinter.applyHtmlAttributes(attrs, attrList); - styleManager.updateStyle(HtmlPrinter.produceTextStyle(styleBuilder, box, true, false, safariLengthFix), attrList); + styleManager.updateStyle(HtmlPrinter.produceTextStyle + (styleBuilder, box, true, false, safariLengthFix, useWhitespacePreWrap), attrList); } xmlWriter.writeTag(HtmlPrinter.XHTML_NAMESPACE, DIV_TAG, attrList, XmlWriterSupport.OPEN); @@ -523,7 +528,8 @@ if (firstElement != box) { HtmlPrinter.applyHtmlAttributes(attrs, attrList); - styleManager.updateStyle(HtmlPrinter.produceTextStyle(styleBuilder, box, true, false, safariLengthFix), attrList); + styleManager.updateStyle(HtmlPrinter.produceTextStyle + (styleBuilder, box, true, false, safariLengthFix, useWhitespacePreWrap), attrList); } xmlWriter.writeTag(HtmlPrinter.XHTML_NAMESPACE, DIV_TAG, attrList, XmlWriterSupport.OPEN); @@ -627,7 +633,8 @@ { final AttributeList attrList = new AttributeList(); HtmlPrinter.applyHtmlAttributes(attrs, attrList); - styleManager.updateStyle(HtmlPrinter.produceTextStyle(styleBuilder, box, true, true, safariLengthFix), attrList); + styleManager.updateStyle(HtmlPrinter.produceTextStyle + (styleBuilder, box, true, true, safariLengthFix, useWhitespacePreWrap), attrList); if (attrList.isEmpty() == false) { @@ -759,7 +766,7 @@ } catch (IOException e) { - throw new StackableRuntimeException("Failed", e); + throw new RuntimeException("Failed", e); } } @@ -813,15 +820,17 @@ } catch (IOException e) { - throw new StackableRuntimeException("Failed", e); + throw new RuntimeException("Failed", e); } catch (ContentIOException e) { - throw new StackableRuntimeException("Failed", e); + throw new RuntimeException("Failed", e); } } - /** @noinspection StringConcatenation*/ + /** + * @noinspection StringConcatenation + */ private void processReplacedContent(final RenderableReplacedContentBox node) throws IOException, ContentIOException { Modified: engines/classic/branches/3.8/core/source/org/pentaho/reporting/engine/classic/core/modules/output/table/html/configuration.properties =================================================================== --- engines/classic/branches/3.8/core/source/org/pentaho/reporting/engine/classic/core/modules/output/table/html/configuration.properties 2011-05-30 10:12:19 UTC (rev 14009) +++ engines/classic/branches/3.8/core/source/org/pentaho/reporting/engine/classic/core/modules/output/table/html/configuration.properties 2011-05-30 10:24:33 UTC (rev 14010) @@ -161,3 +161,15 @@ # true, the content ends up as image. # org.pentaho.reporting.engine.classic.core.modules.output.table.html.ShapeAsContent=true + +# +# Defines whether the generated tables should have the "table-layout:fixed" style defined. +# This is safe to set to true and should be set to false only if something really weird +# happens in your browser. +org.pentaho.reporting.engine.classic.core.modules.output.table.html.UseTableLayoutFixed=true + +# +# Defines whether the reporting engine should generate "whitespace-collapse: pre-line" styles +# instead of "whitespace-collapse: pre" styles. This makes lines breakable so that they +# flow softly. See http://www.quirksmode.org/css/whitespace.html for details. +org.pentaho.reporting.engine.classic.core.modules.output.table.html.UseWhitespacePreWrap=true |