This guide explains how to add new features, CSS properties, or layout boxes to the PyPDFPatra engine.
- Parser Update: If the property is a shorthand, add it to
src/pypdfpatra/engine/styling/shorthand.py. - Style Resolution: If the property should follow specific inheritance rules, update
INHERITED_PROPERTIESinsrc/pypdfpatra/engine/styling/resolve.py. - Layout Logic: Implement the property handling in the relevant formatting context:
src/pypdfpatra/engine/layout/block.pyfor block boxes.src/pypdfpatra/engine/layout/inline.pyfor inline/line-wrapping.
- Rendering: Update
src/pypdfpatra/render.pyto draw the effects of the new property (e.g., shadows, gradients).
- Cython Model: Define the new Box class in
src/pypdfpatra/engine/tree.pyx. Ensure it inherits fromBoxor a relevant specialized subclass. - Box Generation: Update the factory logic in
src/pypdfpatra/engine/layout/box_generator.pyto instantiate your new box based ondisplaystyles or HTML tags. - Layout Context: Create or update a layout function in
src/pypdfpatra/engine/layout/to handle the geometry calculations for the new box. - Renderer: Update
draw_boxesinsrc/pypdfpatra/render.pyto handle the painting of the new box type.
- Add a sample HTML file in
example/or a new test case intests/. - Run the coverage script to verify the visual output:
python example/test_coverage.py