Discussing the article: "Creating a Cairo-Inspired Graphics Library for MetaTrader 5 (Part 11): A Real Stroke Engine"

Check out the new article: Creating a Cairo-Inspired Graphics Library for MetaTrader 5 (Part 11): A Real Stroke Engine.

The engine learns to draw lines by stroking arbitrary paths with width, cap and join styles, miter limiting, and dashes. The stroker outputs overlapping geometry that the non-zero rule welds during fill, so no new raster code is required. In practice, you can render solid or dashed outlines with predictable caps and joins for chart series, widgets, and other UI shapes.

Our graphics library can fill arbitrary paths, but it still lacks a proper stroke operation. This limitation becomes apparent even when drawing a simple panel border: instead of outlining a rectangle directly, we have to construct its border from four separate filled rectangles.

Using four thin rectangles, as demonstrated in Part 10, works for drawing the border of an axis-aligned rectangle with integer dimensions, but it is only a limited workaround. It cannot properly handle rounded rectangles, rotated shapes, diagonal lines, or more complex paths such as price series. What should be a basic drawing operation becomes a collection of special cases.

At this stage of development, the library can fill almost any outline it can describe, but it still lacks a proper stroke operation. In Part 5, we constructed a thick line segment using two triangles, explicitly treating it as a building block rather than a complete stroking system. This article addresses that limitation by introducing a dedicated stroker that can draw lines along any path supported by the library.

The new stroke system provides control over line width, three types of end caps, three types of corner joins, miter limits, and dash patterns. These features make it possible to render everything from simple borders and straight lines to complex paths with consistent stroke behavior.

Author: Sandro Begashvili