Hello everyone! I decided to share with the community the gdiplus_canvas unit – a GDI+-based canvas implementation for Free Pascal and Lazarus. The TGDIPlusCanvas class inherits from TFPCustomCanvas, ensuring high compatibility with existing LCL code.
The module implements a complete set of graphical primitives: lines, Bézier curves, rectangles, ellipses, arcs, pies, polygons, as well as advanced text operations, including precise measurement and rendering with various alignment styles. Notably, it includes built-in support for gradient fills, complex brushes (including textured), path operations (GpPath), and clipping regions. All drawing operations use anti-aliasing for lines and text by default, significantly improving visual quality.
Technically, the module provides thread safety through locking mechanisms (Lock/Unlock), resource caching (fonts, text measurement) for performance, and several initialization options: from an existing HDC, from an HBITMAP, or by creating its own off-screen buffer of a specified size. The AutoRedraw property allows automatic copying of the off-screen buffer content to the target device context. The module fully integrates into the Lazarus ecosystem, supporting standard OnChange/OnChanging events and TCanvas-compatible properties like Pen, Brush, Font, and CopyMode.
To use this module, GDI+ must be available on the system (present in all modern Windows versions) and Free Pascal/Lazarus must be installed. The module is distributed under an FPC-compatible license and can be used in both commercial and open-source projects. It is recommended for tasks requiring high-quality graphics rendering: charting, scientific visualization, custom UI elements, and any drawing where the capabilities of the standard TCanvas are insufficient.
Unit code:
https://gist.github.com/CynicRus/8b31691e88b6354710419a58a80527dbTest code:
https://gist.github.com/CynicRus/71ad086e3abf60ce5fca14a24f486a8fThe license is free, use it as you wish.