Support rendering painted layered glyphs.
Prerequisites
- I have written a descriptive pull-request title
- I have verified that there are no overlapping pull-requests open
- I have verified that I am following matches the existing coding patterns and practice as demonstrated in the repository. These follow strict Stylecop rules :cop:.
- I have provided test coverage for my change (where applicable)
Description
See https://github.com/SixLabors/Fonts/issues/462 for requirements.
This pull request introduces several improvements and updates to the ImageSharp.Drawing library, focusing on enhanced glyph filling capabilities, gradient brush flexibility, dependency updates, and minor code cleanups. The most significant changes are the addition of advanced glyph fill methods, a more flexible linear gradient brush supporting rotated gradients, and updates to package dependencies.
Glyph Filling Enhancements
- Added new overloads to
FillPathCollectionExtensionsthat allow filling and stroking multi-layer glyphs using a heuristic to decide per-layer fill or stroke, supporting advanced typography and painted glyphs. This includes support for custom layer fill decisions and improved documentation. - Refactored
RichTextGlyphRendererandBaseGlyphBuilderto support newIGlyphRendererversion fromSixLabors.Fontswhich allows rendering layered (painted) glyphs. In addition, inheritance was improved to ensure consistency with captured paths and rendered output.
Gradient Brush Improvements
- Refactored
LinearGradientBrushto support both classic two-point and three-point (rotated) gradients, allowing more flexible and expressive gradient fills. Improved constructor signatures and documentation for clarity. - Added
SweepGradientBrushto support sweep gradients required by COLRv1 Fonts. - Refactored
RadialGradientBrushto support two circle gradients to support COLRv1 and SVG Fonts
Dependency and Environment Updates
- Updated NuGet package references in
ImageSharp.Drawing.csprojto newer alpha versions ofSixLabors.FontsandSixLabors.ImageSharpfor improved compatibility and features.
Codebase Cleanups and Minor Fixes
- Removed obsolete project configuration entries from the solution file, streamlining build configuration.
- Fixed namespace usage and parameter documentation for improved code clarity and maintainability in extension files.
- Corrected blending mode enum usage in
ClearExtensions.csfor consistency with current APIs. - Simplified method calls in
EllipticGradientBrush.csby removing unnecessary class qualification.
These changes collectively improve the library's capabilities for advanced text rendering, gradient painting, and developer experience.
Examples.
The following images demonstrate the new layered glyph rendering capabilities:
The first image renders the glyphs as rich text using the full capabilities of the renderer to draw a combination of gradients and fills using the DrawText API. Pens are configured to customize the stroke lines for text decorations. Note consistency of decorations across glyphs now matches browser behaviour.
The second image demonstrates the new rendering capabilities when filling the collection of glyphs using the TextBuilder + Fill API. Heuristics are used based on captured metadata to determine areas to fill vs areas to draw on painted (layerd) glyphs. Decorations are rendered using the values captured from font metrics.