Bug 47811 - (CSSToXLSFO, html tables) Rendering table columns without fo:table-column specified
Summary: (CSSToXLSFO, html tables) Rendering table columns without fo:table-column spe...
Status: NEW
Alias: None
Product: Fop - Now in Jira
Classification: Unclassified
Component: rtf (show other bugs)
Version: all
Hardware: PC All
: P3 normal
Target Milestone: ---
Assignee: fop-dev
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-09-09 11:56 UTC by Pavel Molchanov
Modified: 2012-04-07 01:52 UTC (History)
0 users



Attachments
FO test case (5.72 KB, application/octet-stream)
2009-09-09 11:56 UTC, Pavel Molchanov
Details
Fix for RTF renderer (894 bytes, patch)
2009-09-09 11:58 UTC, Pavel Molchanov
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Pavel Molchanov 2009-09-09 11:56:17 UTC
Created attachment 24240 [details]
FO test case

I faced this bug when I tried to render table with no exact widths for the
table cells. 

FO was generated by CSSToXSLFO converter from very simple html code and it was
generated correctly.

Original html:

<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
</head>
<body>
<table><tr><td>cell 1</td><td>cell 2</td></tr></table>
</body>
</html>

CSSToXSLFO produced FO stylesheet that I attached to the bug as a test case.
It's perfectly correct and works fine with FO->PDF conversion. RTF however
produced ugly table with huge unreadable columns.

Quick fix:

Modify org.apache.fop.render.rtf.rtflib.tools.PercentContext. Replace:

    public void setTableUnit(Table table, int tableUnit) {
        tableUnitMap.put(table, new Integer(tableUnit));
    }

with:

    public void setTableUnit(Table table, int tableUnit) {
        Integer tableUnitAsInt = new Integer(tableUnit);
        tableUnitMap.put(table, tableUnitAsInt);
        // put table units for all columns
        for (Object tc : table.getColumns()) {
            tableUnitMap.put(tc, tableUnitAsInt);
        }
    }

Explanation:

Checking the source code I found that RTF render can't resolve columns widths
correctly in the startColumn(TableColumn tc) method of RTFHandler. The column
width always come out as 0 for proportional width columns.

Actual call is:

int iWidth = tc.getColumnWidth().getValue(percentManager);

Which finally comes to int getBaseLength(int lengthBase, FObj fobj) in
PercentContext class

First argument comes as LengthBase.TABLE_UNITS, second - TableColumn object to
resolve width. Length is extracted from the Map:
    Object unit = tableUnitMap.get(fobj);


However this Map is never initialized correctly for TableColumn objects.
Initialization is done only for the Table object but not for columns. All
requests for width calculation could not find width for columns specified in
TABLE_UNITS, returned 0.0.

As a result 0.0 width passed to RTF call tag and produce ugly output for
columns.

Simple fix was straight-forward. Fill tableUnitMap with correct widths for
TableColumn objects too. That fixed the problem and produce nice table output
in RTF.
Comment 1 Pavel Molchanov 2009-09-09 11:58:29 UTC
Created attachment 24241 [details]
Fix for RTF renderer
Comment 2 Glenn Adams 2012-04-07 01:37:29 UTC
resetting severity from major to normal pending further review
Comment 3 Glenn Adams 2012-04-07 01:43:42 UTC
resetting P2 open bugs to P3 pending further review