Uploaded image for project: 'FOP'
  1. FOP
  2. FOP-1703

(CSSToXLSFO, html tables) Rendering table columns without fo:table-column specified

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Resolution: Unresolved
    • 2.5
    • None
    • renderer/rtf
    • None
    • Operating System: All
      Platform: PC
    • 47811

    Description

      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.

      Attachments

        1. table-example.fo
          6 kB
          Pavel Molchanov
        2. PercentContext-tableUnit.patch
          0.9 kB
          Pavel Molchanov

        Activity

          People

            Unassigned Unassigned
            pmolchanov@idsk.com Pavel Molchanov
            Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: