Skip to content

Feature request: Add SVG LinearGradient and RadialGradient support #1580

@andersonhc

Description

@andersonhc

We recently added gradient support in the fpdf2 drawing API. You can now use an instance of fpdf.drawing.GradientPaint as fill_color or stroke_color in any PaintedPath or GraphicsContext.

Proposed feature

The next step is to extend this support to SVG rendering, by parsing <linearGradient> and <radialGradient> elements from SVG files.

The following methods already exist to help with the feature:

  • fpdf.pattern.shape_linear_gradient()
  • fpdf.pattern.shape_radial_gradient()

These functions take inputs that are very similar to the attributes found in SVG gradient elements and return a gradient instance compatible with fpdf.drawing.GradientPaint.

Implementing this feature involves:

  • updating the SVG parsing class to detect <linearGradient> and <radialGradient> tags
  • extract their attributes, and map them to shape_linear_gradient() or shape_radial_gradient()
  • keep a map of gradient names to their corresponding GradientPaint objects
  • apply the correct GradientPaint as fill-color or stroke-color when a gradient name is used on the svg

This issue is eligible for Hacktoberfest

By implementing this feature you, as a benevolent FLOSS developer, will provide access to the large community of fpdf2 users to a standard and useful PDF functionality.

Moreover, by working on this feature, you will learn about PDFs, fonts and the lifecycle & structure of a popular Python library.

You will also be added into the contributors list & map.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions