Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong image scaling for SVG with clipping #1173

Open
CendioOssman opened this issue Jul 11, 2023 · 1 comment
Open

Wrong image scaling for SVG with clipping #1173

CendioOssman opened this issue Jul 11, 2023 · 1 comment

Comments

@CendioOssman
Copy link

If an SVG image has clipped elements in it, rst2pdf will scale that image based on the unclipped elements, not the final result. This results in a smaller and oddly positioned image.

Description of problem
Put the following SVG in a document. It will be scaled down, and be oddly aligned to the left:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->

<svg
   width="1027"
   height="699"
   viewBox="0 0 271.72709 184.94375"
   version="1.1"
   id="svg5"
   xml:space="preserve"
   xmlns="http://www.w3.org/2000/svg"
   xmlns:svg="http://www.w3.org/2000/svg"><defs
     id="defs2"><clipPath
       clipPathUnits="userSpaceOnUse"
       id="clipPath742"><rect
         style="fill:#00ff00;stroke-width:0.396875;stroke-linecap:round;stroke-linejoin:round"
         id="rect744"
         width="272.52084"
         height="185.20833"
         x="23.010065"
         y="-40.970455"
         rx="1.3229169"
         ry="1.3229169" /></clipPath></defs><g
     id="layer1"
     transform="translate(-23.010065,40.970454)"><path
       fill-rule="nonzero"
       fill="#ffffff"
       fill-opacity="1"
       d="M 23.010065,-40.970454 H 294.64896 V 143.8851 H 23.010065 Z m 0,0"
       id="path387"
       style="stroke-width:0.352778" /><rect
       style="fill:#ff0000;stroke-width:0.396875;stroke-linecap:round;stroke-linejoin:round"
       id="rect632"
       width="2815.1667"
       height="164.04167"
       x="33.593399"
       y="-30.387121"
       rx="1.3229167"
       ry="1.3229167"
       clip-path="url(#clipPath742)" /></g><rect
     style="fill:#00ff00;stroke-width:0.396875;stroke-linecap:round;stroke-linejoin:round"
     id="rect410"
     width="187.37076"
     height="110.43581"
     x="42.14032"
     y="38.162937"
     rx="1.3229169"
     ry="1.3229169" /></svg>

What is the expected output? What do you see instead?
The SVG is rendered just like in other applications, i.e. according to the width and height of the <svg>.

🖥 Versions
Python 3.6.12
rst2pdf 0.98
reportlab 3.6.1
svglib 1.1.0
sphinx 4.2.0

Additional information
I figured this might be a svglib issue, but some quick debugging suggests the issue is elsewhere. svglib returns a ReportLab Drawing with the correct dimensions. Not sure what happens after that that results in the bad scaling. Hence why I'm reporting the issue here.

@lornajane
Copy link
Contributor

Thanks @CendioOssman, I don't think I've seen that before and I appreciate the detailed bug report. I don't use SVGs but I'm happy to test a patch if anyone does have a fix for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants