Problems with complex tables

General TRichView support forum. Please post your questions here
Post Reply
SculptureEK
Posts: 4
Joined: Wed Nov 21, 2012 3:24 pm

Problems with complex tables

Post by SculptureEK »

Hi!

I have problems with some complex tables. Originally, these tables have been designed in Libreoffice (Calc). I saved them as Html and imported them using RvHtmlImporter v0.0048. I've set rvtoIgnoreContentWidth and -Height and changed some things manually, and now the tables look quite good in RichViewEdit. But:

1. If you print the tables, a part at the bottom of the page is missing.
2. If you drag some vertical lines, the layout is destroyed completely.

Here is a .rvf with 2 of these tables:
https://www.dropbox.com/s/wjsyv2p8u7diyuu/printtest.rvf

You can open it in ActionTestUni.exe, I've tried it in the compiled version from 31.10.2013. Change Units to cm and drag the window so you have 20 cm between margins. Then you see what the form should look like.

to 1.: Set all margins to 0 in Page Setup. Click "Print Preview" and have a look at the bottom part of the pages.

to 2.: A square is in the upper right corner of the first table. Drag its left border a small amount with the mouse...

I have some tables where printing is ok, but all of them have the layout problem. Our customer who sent me the tables says that he can reproduce the layout problem also if he creates a new table in RichViewEdit and merges some cells.

Kind regards,

Hans
Sergey Tkachenko
Site Admin
Posts: 17304
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

As for layout problem, it cannot be easily fixed in the components, but there is a workaround.

In this table, almost all cells have default widths (BestWidth=0). Since no columns have priorities, the table is balanced.

When you resize a column, cells to the left and to the right of the dragged line receive assigned BestWidths (including long spanned cells), so now the table resizing algorithm tries to satisfy these widths. Size of other columns are calculated to fill the remaining space.

I can suggest to assign BestWidth of all table cells:

Code: Select all

procedure AssignCellWidths(table: TRVTableItemInfo; RVStyle: TRVStyle);
var r,c: Integer;
begin
  for r := 0 to Table.RowCount-1 do
    for c := 0 to Table.ColCount-1 do
      if table.Cells[r,c]<>nil then
        table.Cells[r,c].BestWidth := RVStyle.PixelsToUnits(table.Cells[r,c].GetWidth);
end;

// Calling for all tables
var i: Integer;
begin
  for i := 0 to RichViewEdit1.ItemCount-1 do
    if RichViewEdit1.GetItemStyle(i)=rvsTable then
      AssignCellWidths(TRVTableItemInfo(RichViewEdit1.GetItem(i)), RichViewEdit1.Style);
  RichViewEdit1.Format;
After this code, resizing will be much better.
This code must be called when RichViewEdit is already formatted. The table will stay at the specified size, it will not be resized with window any more (you can assign table.BestWidth=-100 to make it fill the whole width again)

As for printing problems - it's very strange, I need some time to find the reason.
Sergey Tkachenko
Site Admin
Posts: 17304
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

The printing problem happens because processing of rvtoIgnoreContentHeight table option is not entirely correct.

A workaround:
Open RVTable.pas, find procedure TRVTableItemInfo.Print.
1) Add Height: Integer to the list of global variables
2) Change

Code: Select all

    PaintTo(x,x2,y, Canvas, State, TCustomRVData(RVData).GetRVStyle,
      TRVTablePrintInfo(dli).Fmt, UHRC,
      Rect(x,y,x+TRVTablePrintInfo(dli).Fmt.FWidth,y+TRVTablePrintInfo(dli).Fmt.FHeight),
      ColorMode, TCustomPrintableRVData(RVData), TablePart, nil, 0, 0, PageNo);
to

Code: Select all

    if TablePart=nil then
      Height := TRVTablePrintInfo(dli).Fmt.FHeight
    else
      Height := TablePart.Height;
    PaintTo(x,x2,y, Canvas, State, TCustomRVData(RVData).GetRVStyle,
      TRVTablePrintInfo(dli).Fmt, UHRC,
      Rect(x,y,x+TRVTablePrintInfo(dli).Fmt.FWidth,y+Height),
      ColorMode, TCustomPrintableRVData(RVData), TablePart, nil, 0, 0, PageNo);
This is not a complete fix, but it removes all negative effects on printing.
Sergey Tkachenko
Site Admin
Posts: 17304
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

More about rvtoIgnoreContentHeight.

According to the help file:
If [rvtoIgnoreContentHeight is] set, heights of rows are calculated basing only on BestHeight properties of cells.
But (unlike rvtoIgnoreContentWidth), heights of cells having BestHeight=0 are still calculated basing on their content.
This rule is really used when calculating table width for printing.
However, a formatting procedure in TRichViewEdit uses a different rule:
cell content is taken into account only if there are no cells in this row having BestHeight>0 and RowSpan=1.
Because of different understanding of this option by different procedures, this problem occurred.

I think I need to correct formatting procedure to work according to the documentation (although its rule makes sense too)
SculptureEK
Posts: 4
Joined: Wed Nov 21, 2012 3:24 pm

Post by SculptureEK »

Thank you very much, your support is marvellous.

The printing problem workaround works fine.

The layout problem is much better now, but still some strange things happen. I will further investigate and come back to this.
Sergey Tkachenko
Site Admin
Posts: 17304
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

The complete fix is included in TRichView 14.12.5 (available for registered users)
Post Reply