TMS FNC Core 4.5.0.0 - PDF: filled round rectangle without stroke is not drawn, and SVG fill-rule is ignored (screen and PDF differ)

Delphi 13.1 Florence, VCL, TMS FNC Core 4.5.0.0 (used with TMS FNC Gantt Chart 1.3.3.10).

Two issues in the PDF output of FNC Core. In both cases the PDF looks different from the screen and from a printout of the same drawing.

The attached demo draws each scene with one routine three times: into a PDF (TTMSFNCGraphicsPDFEngine), and on a TTMSFNCGraphics bitmap canvas with the default context and with the native context (GDI+). On start it runs both scenes once and writes 1.pdf / 1-screen.png / 1-screen-gdip.png and the same for 2, next to the exe. The buttons repeat it and show the scene in the window. The attached image shows the result.

1. TTMSFNCGraphicsPDFEngine.DrawRoundRectangle draws nothing when there is a fill but no stroke

VCL.TMSFNCGraphicsPDFEngine.pas, line 800 ff.:

if (Fill.Color <> gcNull) and (Fill.Kind <> gfkNone) then
begin
  if (Stroke.Kind <> gskNone) and (Stroke.Width <> 0) then
    DrawPath(pth, pdmPolygon)
  else
    DrawPath(pth, pdmPolyline)     // fill only -> DrawPolyline
end
else if (Stroke.Kind <> gskNone) and (Stroke.Width <> 0) then
  DrawPath(pth, pdmPolyline)

For a fill without a stroke, the path goes to DrawPolyline (line 771). That method only draws when a stroke is set, and only as a stroke. So a filled round rectangle without border produces no output at all: no fill operator in the content stream, no error. DrawPolygon (line 744) handles a fill with and without stroke correctly, so I think the inner else should use pdmPolygon as well.

Demo, scene 1, three red round rectangles:

  • A: fill + stroke, DrawRoundRectangle – screen and PDF: red
  • B: fill, Stroke.Kind := gskNone, DrawRoundRectangle – screen: red, PDF: missing
  • C: fill, no stroke, the same path drawn with DrawPath(..., pdmPolygon) – screen and PDF: red

How we found it: in our Gantt chart the open part of a task's progress is a pale, filled round rectangle without border. On screen and on paper it is there, in the PDF export it was missing. We now use the path of C when the target is a TTMSFNCGraphicsPDFEngine.

2. SVG fill-rule is ignored, and screen and PDF use different fill rules

VCL.TMSFNCGraphicsSVGEngine.pas does not read fill-rule. The SVG paths are drawn with pdmPath, and the result then depends on the target:

  • Screen, default context: TTMSFNCGraphicsContextGeneral.FillPath (VCL.TMSFNCGraphics.General.pas, line 2316) uses Windows.FillPath, i.e. the polygon fill mode of the DC. That is the default ALTERNATE (even-odd); SetPolyFillMode is never called.
  • Screen, native context (GDI+): TTMSFNCGraphicsContextWin.CreatePath (VCL.TMSFNCGraphics.Win.pas, line 816) creates the TGPGraphicsPath without a parameter, i.e. FillModeAlternate (even-odd).
  • PDF: TTMSFNCGraphicsPDFEngine.DrawPath (line 641 ff.) always ends with dmPathFill or dmPathFillStroke (f / B, nonzero), although the PDF library supports dmPathEOFill (f*, VCL.TMSFNCPDFGraphicsLib.General.pas, line 851).

Demo, scene 2, three SVGs – an outer square with an inner square:

<path d="M10 10H90V90H10Z M30 30H70V70H30Z"/>
  • A: fill-rule="evenodd", both subpaths in the same direction. Expected: frame with hole. Screen: hole. PDF: filled.
  • B: no fill-rule (SVG default nonzero), same path. Expected: filled square. Screen: hole. PDF: filled.
  • C: fill-rule="evenodd", inner subpath reversed (M30 30V70H70V30Z). Expected: frame with hole. Screen and PDF: hole.

So the same SVG is filled differently on screen and in the PDF, and with the default rule the screen is the one that is wrong. Our case was a warning triangle (a triangular ring with "!"), drawn via <img src="...svg"> in a task list cell: correct on screen, a solid black triangle in the PDF.

Suggestion: read fill-rule (and clip-rule) in the SVG engine and pass it on: SetPolyFillMode / FillMode on screen, f* / B* in the PDF. At least screen and PDF should use the same rule. We now reverse the direction of inner subpaths in our icons, as in C, so both rules give the same result.

Thanks!

FNCCoreIssues.zip (6.8 KB)

Hi Andreas,

Thank you for the detailed report and the excellent reproduction project.

Both issues have been confirmed and fixed for TMS FNC Core 4.5.0.1:

  1. A filled rounded rectangle without a stroke was incorrectly passed to the polyline drawing path. It is now handled as a filled polygon, so it is rendered correctly in PDF output.

  2. The VCL SVG renderer now reads and applies fill-rule. Both evenodd and the SVG default nonzero rule are supported by the standard VCL and GDI+ rendering contexts and by the PDF renderer. PDF output now uses the corresponding f*/B* operators for evenodd.

Hi Pieter,

Thanks a lot for the quick confirmation and the fixes. I'll test both with the demo as soon as 4.5.0.1 is available.

Best regards,
Andreas

Hi Pieter,

One more thing I noticed while reading the code, so please treat it as a reading, not a tested report: TTMSFNCGraphicsPDFEngine.DrawArc (VCL.TMSFNCGraphicsPDFEngine.pas, line 556 in 4.5.0.0) has the same branch, so a fill without a stroke goes to pdmPolyline. In case the fix doesn't cover it yet, it may need the same change.

Best regards,
Andreas

Thanks, Pieter. I installed FNC Core 4.5.0.1 together with Gantt 1.3.3.11 and ran the demo from this thread again: in scene 1, rectangle B is now drawn in the PDF. In scene 2, the PDF now shows A with a hole, B filled and C with a hole, and on screen B is filled as well. So both issues are fixed, thank you.

Unfortunately the SVG changes in 4.5.0.1 cause a new problem in our application, which also uses TMS VCL UI Pack 13.7.0.0 (Delphi 13.1, VCL, Win64). As soon as a Gantt task list with a summary task is painted, there is an access violation in TTMSFNCGraphicsSVGImport.InternalDraw, line 3055 (if est.DisplayValue = 'none' then), while the expand/collapse icon is drawn:

System._UStrEqual
TTMSFNCGraphicsSVGImport.InternalDraw
TTMSFNCGraphicsSVGImport.InternalDraw
TTMSFNCGraphicsSVGImport.Draw
TTMSFNCGraphics.DrawSVG
TTMSFNCGraphics.DrawBitmap
TTMSFNCGraphics.DrawBitmap
TTMSFNCCustomGanttChart.DoOnTaskListBeforeDrawNodeExpand
TTMSFNCCustomGanttList.DoBeforeDrawNodeExpand
...

With FNC Core 4.5.0.0 / Gantt 1.3.3.10 the same application works. As far as we can see, this is the cause:

  1. AdvTypes.pas (VCL UI Pack) declares IAdvSVGBitmap with the same GUID as ITMSFNCSVGBitmap in VCL.TMSFNCTypes.pas: {3A7B5F92-C4E1-4D8A-B623-0F1E7A9D4C85}.
  2. Both units declare a class named TTMSFNCSVGBitmap (in AdvTypes it is class(TAdvSVGBitmap)) and register it with RegisterClass and TPicture.RegisterFileFormat('SVG', ...), but only if no class with this name is registered yet. So the unit that is initialized first wins. In our application this is AdvTypes.
  3. TTMSFNCGraphics.DrawSVG gets the SVG with Supports(ABitmap.Graphic, ITMSFNCSVGBitmap, ISVGBitmap) and casts the result of GetSVG to TTMSFNCGraphicsSVGImport. With the UI Pack class registered, it is a TAdvGraphicsSVGImport. In the debugger, the element list being drawn belongs to AdvGraphicsSVGEngine.
  4. In VCL UI Pack 13.7.0.0, the declarations of TAdvGraphicsSVGImport and TAdvGraphicsSVGElement are identical to TTMSFNCGraphicsSVGImport and TTMSFNCGraphicsSVGElement of FNC Core 4.5.0.0 (apart from the prefix), so this worked until now. FNC Core 4.5.0.1 added five fields to TTMSFNCGraphicsSVGElement (FStrokeDashArrayValue, FStrokeDashOffsetValue, FStrokeLineCapValue, FFillRuleValue, FClipRuleValue). The FNC code now reads the UI Pack objects at the wrong offsets.

Demo (attached), built as Win64 Debug. Both projects use the same form. The first log line shows which unit registered TTMSFNCSVGBitmap, and exceptions are shown and written to the log.

  • SVGExpandIcon.dpr uses FNC only. Button 1 loads the Gantt expand icon SVG (TTMSFNCGANTTLISTEXPANDNEWSVG) into a TTMSFNCBitmap and draws it with TTMSFNCGraphics.DrawBitmap. Button 2 shows a Gantt chart with one summary task. Both work, the icons are drawn:
TTMSFNCSVGBitmap registered from unit: VCL.TMSFNCTypes
1. DrawBitmap
   loaded, graphic class: TTMSFNCSVGBitmap (unit VCL.TMSFNCTypes)
   drawing ...
   OK
2. Gantt with summary task
   OK
  • SVGExpandIconUIPack.dpr is the same, the only difference is AdvTypes as the first unit in the uses clause. Button 1 raises the access violation (German Windows):
TTMSFNCSVGBitmap registered from unit: AdvTypes
1. DrawBitmap
   loaded, graphic class: TTMSFNCSVGBitmap (unit AdvTypes)
   drawing ...
   EAccessViolation: Zugriffsverletzung bei Adresse 00007FF66D8937AD in Modul 'SVGExpandIconUIPack.exe' (Offset 137AD). Lesen von Adresse FFFFFFFFFFFFFFFF

In the debugger the call stack is the one above, from TTMSFNCGraphics.DrawBitmap down to System._UStrEqual.

Questions:

  1. Is there (or will there be) a VCL UI Pack version whose SVG engine matches FNC Core 4.5.0.1? Which versions of the two products belong together?
  2. Could the products avoid casting each other's objects (separate GUIDs and class names, or a check of the actual class before the cast)? Today an update of one product can break the other at runtime, without any compiler error.
  3. Until then: is Gantt 1.3.3.11 supported with FNC Core 4.5.0.0?

Versions: Delphi 13.1, TMS FNC Core 4.5.0.1, TMS FNC Gantt Chart 1.3.3.11, TMS VCL UI Pack 13.7.0.0, all installed with TMS Smart Setup.

Thanks!

SVGExpandIcon_Demo.zip (7.1 KB)