TTMSFNCGanttChart 1.3.3.10 - export: timeline checks the wrong UseCustom…Appearance flag, and OnGetHeader/OnGetFooter are never called

Delphi 13.1 Florence, VCL, TMS FNC Gantt Chart 1.3.3.10, TMS FNC Core 4.5.0.0.

We ran into two small issues while building our print and PDF layout. The attached demo shows both:

  • Button 1 writes 1a/1b/1c.pdf.
  • Button 2 writes 2.pdf.
  • The memo logs what happens.

The PDFs are written next to the exe.

1. DrawExportTimeLine checks UseCustomTaskListAppearance instead of UseCustomTimeLineAppearance

In TTMSFNCCustomGanttChart.DrawExportTimeLine (VCL.TMSFNCGanttChart.pas), six places check AExportOptions.UseCustomTaskListAppearance, but then use AExportOptions.CustomTimeLineAppearance:

Line What is drawn
9323 fill of working / non-working time units (Fill / InActiveFill)
9342 timeline header fill and stroke
9355 group font
9415 time font (HeaderFont)
9472 vertical lines
9572 dependency lines

The other checks in the same routine use UseCustomTimeLineAppearance as expected: 9293 (background), 9653 (task bars) and 9790 (horizontal lines).

The demo sets CustomTimeLineAppearance.InActiveFill to red, only to make the effect visible, and exports three times (see the attached image):

  • 1a – both flags False: this is the reference, with weekends as on screen.
  • 1b – only UseCustomTaskListAppearance = True: the weekends are red. The grid lines, the group font and the dependency lines also come from CustomTimeLineAppearance, although UseCustomTimeLineAppearance is False.
  • 1c – only UseCustomTimeLineAppearance = True: the task bars use the custom appearance, which is correct. The weekends, the vertical grid and the dependency lines don't.

How we noticed: we set UseCustomTaskListAppearance only to get our own task list grid. After that the weekends in the PDF and in the printout came out in silver (192, 192, 192), which is the default of CustomTimeLineAppearance.InActiveFill. On screen they are 230/230/240.

Suggested fix: use UseCustomTimeLineAppearance at these six lines. The routine is called from ExportView, which both the PDF and the print export use, so the printout is affected the same way. Until then we copy the screen appearance into CustomTimeLineAppearance before exporting.

2. OnGetHeader / OnGetFooter are never called

TTMSFNCCustomPDFIO.DoNewPageStarted (VCL.TMSFNCPDFIO.pas, line 629):

if Assigned(Sender) and Supports(Sender, ITMSFNCCustomPDFLib, pdflib) then

The Sender that arrives here is the component, not the backend:

  • TTMSFNCGeneralPDFLib.DoNewPageStarted passes the backend.
  • TTMSFNCCustomPDFLib.DoBackendNewPageStarted (VCL.TMSFNCPDFLib.pas, line 3120) then forwards Self.
  • Self is a TTMSFNCPDFLib. It descends from TTMSFNCCustomComponent and does not implement ITMSFNCCustomPDFLib.

So Supports is always False and DoGetHeader / DoGetFooter are never called. The header and footer can't be changed per page.

Demo log for button 2. TProbePDFIO in the demo only logs the Sender and then calls inherited:

DoNewPageStarted: Sender = TTMSFNCPDFLib, Supports(Sender, ITMSFNCCustomPDFLib) = False
OnBeforeDrawHeader page 1: header text = "Static header (Options.Header)"
Pages: 1   OnGetHeader calls: 0   OnGetFooter calls: 0   (expected: one call each per page)

2.pdf shows the static Options.Header / Options.Footer text.

A possible fix, as an untested sketch. The component already offers GetPageIndex, Header and Footer, and TTMSFNCGeneralPDFLib.NewPage calls DoNewPageStarted before DrawHeader:

procedure TTMSFNCCustomPDFIO.DoNewPageStarted(Sender: TObject; APageIndex: Integer);
var
  h, f: UnicodeString;
  lib: TTMSFNCCustomPDFLib;
begin
  if Sender is TTMSFNCCustomPDFLib then
  begin
    lib := TTMSFNCCustomPDFLib(Sender);
    h := Options.Header;
    f := Options.Footer;
    DoGetHeader(FActiveExportObject, lib.GetPageIndex, h);
    DoGetFooter(FActiveExportObject, lib.GetPageIndex, f);
    lib.Header := h;
    lib.Footer := f;
  end;
end;

A side note for anyone overriding DoBeforeDrawHeader or similar methods: the Sender there is the component as well, because DoBackendBeforeDrawHeader also passes Self.

And one question: OnRowIsPageBreak is published on both TTMSFNCGanttChartPDFIO and TTMSFNCGanttChartPrintIO, but we couldn't find a place where it is fired. Is it supposed to work already, or is it planned?

Thanks a lot!

GanttExportIssues.zip (6.2 KB)

One more export issue, found while testing our print dialog. It is in the same area, so I add it here instead of opening a new thread. The attached GanttExportIssues_v2.zip is the same demo with a new button 3; buttons 1 and 2 are unchanged.

3. DrawExportTaskList can drop the last task row

In TTMSFNCCustomGanttChart.DrawExportTaskList (VCL.TMSFNCGanttChart.pas, 1.3.3.10) the row position is accumulated in a Single:

y := y + dy;                                         // line 9247
...
if ((y + dy) > AExportTaskParams.Rect.Bottom) then   // line 9250
  Break;

Rect.Bottom is maxY from GetLastRow in ExportView, calculated in one go:

maxY := ARect.Top + dhy + (Result - AStartRow) * dy;  // line 10269

On the last row page LastRow is the task count, so after the second-to-last row both sides are mathematically equal. With a fractional top margin, e.g. 8 mm = 22.6772 pt, the accumulated y can come out one rounding step larger. Then the Break fires and the last task is missing from the task list – no exception, no warning. The timeline part still draws its bar, so task list and timeline no longer line up (see the attached image). PDF and print are both affected, since both go through ExportView.

Demo, button 3: 12 tasks, A4 portrait, all other settings default. It exports into memory for top margins of 1 … 50 mm, converted to points as an application with margins in mm does, and counts the tasks that reach OnBeforeDrawGanttListNodeText during the export. Whole points serve as a control. Log (Win32 build, German decimal separator):

3. Last task list row (12 tasks, A4 portrait, header height 52, item height 30)
  Top margin 1 .. 50 mm (mm * 72 / 25.4 pt), last row missing for mm: 2 8 14 20 39 40
  Top margin 20 .. 60 whole points (control), last row missing for pt: none
  3a.pdf  top margin 8 mm = 22,6772 pt: 11 of 12 tasks drawn
  3b.pdf  top margin 23 pt (rounded):    12 of 12 tasks drawn

3a.pdf is written with the first failing margin, 3b.pdf with the same margin rounded to a whole point.

In our own application (Win64, header height 96, item height 30, top 69.346 pt = 10 mm plus our page header) the last of 12 rows was missing as well. The row positions in that PDF show the drift: 176.066436 … 476.066466.

Suggested fix: limit the rows by StartRow/LastRow instead of the accumulated y, or compute y from the row index, or compare with a small tolerance. Until then we round our margins to whole points, which avoids it.

Thanks again!

GanttExportIssues_v2.zip (7.8 KB)

Hello

Thank you for both reports and the demo projects, this makes it a lot easier to track the issues down.

1. DrawExportTimeLine checks UseCustomTaskListAppearance
Confirmed and fixed, until the release your workaround of copying the screen appearance into CustomTimeLineAppearance before exporting is the right approach.

2. OnGetHeader / OnGetFooter are never called
Confirmed. A recent change in TMS FNC Core makes TTMSFNCPDFLib pass itself as Sender instead of the backend, so the interface check in DoNewPageStarted fails. We’re working on a fix in TMS FNC Core.

Until then, your suggested override in a descendant class is a valid workaround. As you noted, the Sender in DoBeforeDrawHeader and the related events is now the component; that part is intended.

3. DrawExportTaskList can drop the last task row
Confirmed. We reproduced exactly the failing margins from your demo: 2, 8, 14, 20, 39 and 40 mm. The task list now positions its rows exactly like the timeline and loops over the row range by count, so rounding can’t drop a row any more.

The same issue could also drop a row at the bottom of a page in the middle of a multi-page export; that’s fixed as well. Until the update, rounding the margins to whole points, as in your 3b test, avoids it.

OnRowIsPageBreak
You were right: the event was published but never fired. It’s now implemented for both PDF and print export. How it works:

  • ARow is the 0-based row index in the export. Set IsPageBreak := True to start a new page with that row.
  • The first row of a page is never asked, so you can’t get an empty page.
  • If the timeline is wider than one page, the export continues on extra pages to the right. The breaks repeat on each of those, so the rows line up.
  • With FitToPage enabled, pages with a forced break end earlier than the calculated fit.

Points 1 and 3 and OnRowIsPageBreak will be in the next TMS FNC Gantt Chart update. We’ll let you know when the TMS FNC Core fix for point 2 is available.

Thanks again for the thorough analysis.

Best regards,

Hi Gjalt,

Thank you for the detailed answer and the quick fixes, and for implementing OnRowIsPageBreak. That gives us some nice options for our print dialog. Good to know that the component as Sender in DoBeforeDrawHeader is intended, because our override relies on it. I'll run the demo against the update as soon as it is available.

Best regards,
Andreas

Thanks, Gjalt. I installed Gantt 1.3.3.11 with FNC Core 4.5.0.1 and ran the demo from this thread again, without our workarounds:

  1. Timeline appearance: with only UseCustomTaskListAppearance set (1b) the weekends now use the normal timeline colors, no red pixels left. With only UseCustomTimeLineAppearance set (1c) the custom red is used. Fixed.
  2. OnGetHeader and OnGetFooter are now called, and the PDF shows the header text from the event. Fixed.
  3. Last row: with top margins from 1 to 50 mm the last row is now present on every page, including 2, 8, 14, 20, 39 and 40 mm. Fixed.

OnRowIsPageBreak we have seen in the source, but we do not use it yet, so I cannot report on it.

Thank you for the quick fixes. We have removed our workarounds in the meantime.

One note for other Gantt users: FNC Core 4.5.0.1 together with TMS VCL UI Pack 13.7.0.0/13.7.1.0 raises an access violation as soon as a task list with a summary task draws its expand/collapse icon. TMS has fixed this for the next VCL UI Pack update. Details: VCL UI Pack 13.7.1.0 with FNC Core 4.5.0.1: access violation when an FNC control draws an SVG (both products register TTMSFNCSVGBitmap, shared interface GUID)